14 #ifndef __SGVECTOR_H__
15 #define __SGVECTOR_H__
24 template <
class T>
class SGSparseVector;
25 template <
class T>
class SGMatrix;
29 template<
class T>
class SGVector :
public SGReferencedData
48 void set(SGVector<T> orig);
79 void random(T min_value, T max_value);
147 static void fill_vector(T* vec, int32_t len, T value);
153 static void random_vector(T* vec, int32_t len, T min_value, T max_value);
156 static void randperm(T* perm, int32_t n);
159 static void permute(T* vec, int32_t n);
328 static T
twonorm(
const T* x, int32_t len);
341 const T scalar,
const T* vec2, int32_t n);
347 for (int32_t i=0; i<n; i++)
348 r+=((v1[i]) ? 1 : 0) * ((v2[i]) ? 1 : 0);
356 for (int32_t i=0; i<n; i++)
370 const uint64_t* v1,
const uint64_t* v2, int32_t n)
373 for (int32_t i=0; i<n; i++)
380 const int64_t* v1,
const int64_t* v2, int32_t n)
383 for (int32_t i=0; i<n; i++)
391 const int32_t* v1,
const int32_t* v2, int32_t n)
394 for (int32_t i=0; i<n; i++)
402 const uint32_t* v1,
const uint32_t* v2, int32_t n)
405 for (int32_t i=0; i<n; i++)
413 const uint16_t* v1,
const uint16_t* v2, int32_t n)
416 for (int32_t i=0; i<n; i++)
424 const int16_t* v1,
const int16_t* v2, int32_t n)
427 for (int32_t i=0; i<n; i++)
435 const char* v1,
const char* v2, int32_t n)
438 for (int32_t i=0; i<n; i++)
446 const uint8_t* v1,
const uint8_t* v2, int32_t n)
449 for (int32_t i=0; i<n; i++)
457 const int8_t* v1,
const int8_t* v2, int32_t n)
460 for (int32_t i=0; i<n; i++)
468 const float64_t* v1,
const char* v2, int32_t n)
471 for (int32_t i=0; i<n; i++)
479 T* target,
const T* v1,
const T* v2,int32_t len)
481 for (int32_t i=0; i<len; i++)
482 target[i]=v1[i]*v2[i];
488 T* target, T alpha,
const T* v1, T beta,
const T* v2,
491 for (int32_t i=0; i<len; i++)
492 target[i]=alpha*v1[i]+beta*v2[i];
498 for (int32_t i=0; i<len; i++)
506 static inline T
sum(T* vec, int32_t len)
509 for (int32_t i=0; i<len; i++)
518 return sum(vec.vector, vec.vlen);
525 for (int32_t i=0; i<len; i++)
538 static T
min(T* vec, int32_t len);
541 static T
max_abs(T* vec, int32_t len);
544 static T
max(T* vec, int32_t len);
547 static int32_t
arg_max(T * vec, int32_t inc, int32_t len, T * maxv_ptr = NULL);
550 static int32_t
arg_max_abs(T * vec, int32_t inc, int32_t len, T * maxv_ptr = NULL);
553 static int32_t
arg_min(T * vec, int32_t inc, int32_t len, T * minv_ptr = NULL);
556 static T
sum_abs(T* vec, int32_t len);
564 static int32_t
unique(T* output, int32_t
size);
571 const char* prefix=
"")
const;
575 const T*
vector, int32_t n,
const char* name=
"vector",
576 const char* prefix=
"");
581 const char* prefix=
"");
591 template <
typename Predicate>
709 #ifndef DOXYGEN_SHOULD_SKIP_THIS
715 #endif // DOXYGEN_SHOULD_SKIP_THIS
717 #endif // __SGVECTOR_H__
void tanh()
hyperbolic tangent of vector elements
static T twonorm(const T *x, int32_t len)
|| x ||_2
void range_fill(T start=0)
void asin()
arc sine of vector elements
static void fill_vector(T *vec, int32_t len, T value)
SGVector< float64_t > get_real()
static floatmax_t dot(const floatmax_t *v1, const floatmax_t *v2, int32_t n)
compute dot product between v1 and v2 (blas optimized)
T & operator[](uint64_t index)
void pow(T q)
power of vector elements
static T min(T *vec, int32_t len)
void set(SGVector< T > orig)
bool equals(SGVector< T > &other)
SGVector< float64_t > get_imag()
void log()
natural logarithm of vector elements
static float64_t dot(const int16_t *v1, const int16_t *v2, int32_t n)
compute dot product between v1 and v2 (for 16bit unsigned ints)
void random(T min_value, T max_value)
void display_size() const
static float64_t dot(const int32_t *v1, const int32_t *v2, int32_t n)
compute dot product between v1 and v2 (for 32bit ints)
const T & operator[](int32_t index) const
void abs()
absolute value of vector elements
void cosh()
hyperbolic cosine of vector elements
void exp()
exponential of vector elements
void scale(T alpha)
scale vector inplace
void atan2(T x)
atan2 of vector elements
const T & get_element(index_t index)
static SGMatrix< T > convert_to_matrix(SGVector< T > vector, index_t nrows, index_t ncols, bool fortran_order)
static T qnorm(T *x, int32_t len, float64_t q)
|| x ||_q
static void scale_vector(T alpha, T *vec, int32_t len)
scale vector inplace
static bool fequal(T x, T y, float64_t precision=1e-6)
return sum(abs(vec))
static int32_t arg_max_abs(T *vec, int32_t inc, int32_t len, T *maxv_ptr=NULL)
return arg_max_abs(vec)
void display_vector(const char *name="vector", const char *prefix="") const
static float64_t * linspace(T start, T end, int32_t n)
static T * clone_vector(const T *vec, int32_t len)
SGVector< index_t > argsort()
void set_element(const T &p_element, index_t index)
static void permute_vector(SGVector< T > vec)
SGVector< index_t > find_if(Predicate p)
static T product(T *vec, int32_t len)
return the product of the vectors elements
void sin()
sine of vector elements
static int32_t arg_min(T *vec, int32_t inc, int32_t len, T *minv_ptr=NULL)
return arg_min(vec)
static T sum_abs(T *vec, int32_t len)
return sum(abs(vec))
const T & operator[](uint64_t index) const
void tan()
tangent of vector elements
static void vector_multiply(T *target, const T *v1, const T *v2, int32_t len)
compute vector multiplication
static void add_scalar(T alpha, T *vec, int32_t len)
add scalar to vector inplace
static SGVector< T > randperm_vec(int32_t n)
shogun reference count managed data
static float64_t dot(const uint8_t *v1, const uint8_t *v2, int32_t n)
compute dot product between v1 and v2 (for 8bit (un)signed ints)
static float64_t dot(const uint32_t *v1, const uint32_t *v2, int32_t n)
compute dot product between v1 and v2 (for 32bit unsigned ints)
static void range_fill_vector(T *vec, int32_t len, T start=0)
static float64_t dot(const int64_t *v1, const int64_t *v2, int32_t n)
compute dot product between v1 and v2 (for 64bit ints)
A File access base class.
void log10()
common logarithm of vector elements
static T sum(T *vec, int32_t len)
return sum(vec)
T & operator[](int32_t index)
SGVector< T > operator+=(SGVector< T > x)
T & operator[](uint32_t index)
static void vec1_plus_scalar_times_vec2(T *vec1, const T scalar, const T *vec2, int32_t n)
x=x+alpha*y
static T max(T *vec, int32_t len)
static T sum(SGVector< T > vec)
return sum(vec)
static SGVector< float64_t > linspace_vec(T start, T end, int32_t n)
static float64_t dot(const bool *v1, const bool *v2, int32_t n)
compute dot product between v1 and v2 (blas optimized)
index_t find_position_to_insert(T element)
static float64_t dot(const int8_t *v1, const int8_t *v2, int32_t n)
compute dot product between v1 and v2 (for 8bit (un)signed ints)
static float64_t dot(const uint16_t *v1, const uint16_t *v2, int32_t n)
compute dot product between v1 and v2 (for 16bit unsigned ints)
: Pseudo random number geneartor
all of classes and functions are contained in the shogun namespace
SGVector< T > operator+(SGVector< T > x)
static float64_t dot(const uint64_t *v1, const uint64_t *v2, int32_t n)
compute dot product between v1 and v2 (for 64bit unsigned ints)
static float64_t dot(const char *v1, const char *v2, int32_t n)
compute dot product between v1 and v2 (for 8bit (un)signed ints)
T product()
return product(vec)
static float64_t dot(const float64_t *v1, const char *v2, int32_t n)
compute dot product between v1 and v2
SGVector< T > clone() const
template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry* vector is orde...
T & operator[](int64_t index)
virtual void copy_data(const SGReferencedData &orig)
static float64_t onenorm(T *x, int32_t len)
|| x ||_1
static T max_abs(T *vec, int32_t len)
static T qsq(T *x, int32_t len, float64_t q)
|| x ||_q^q
void resize_vector(int32_t n)
static void add(T *target, T alpha, const T *v1, T beta, const T *v2, int32_t len)
target=alpha*vec1 + beta*vec2
void sinh()
hyperbolic sine of vector elements
const T & operator[](uint32_t index) const
void acos()
arc cosine of vector elements
const T & operator[](int64_t index) const
static int32_t arg_max(T *vec, int32_t inc, int32_t len, T *maxv_ptr=NULL)
return arg_max(vec)
void sqrt()
square root of vector elements
SGVector< index_t > find(T elem)
void cos()
cosine of vector elements
static int32_t unique(T *output, int32_t size)
void set_const(T const_elem)
void add(const SGVector< T > x)
void atan()
arc tangent of vector elements
static void random_vector(T *vec, int32_t len, T min_value, T max_value)