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__
static SGVector< float64_t > linspace_vec(T start, T end, int32_t n)
void cosh()
hyperbolic cosine of vector elements
static T sum_abs(T *vec, int32_t len)
return sum(abs(vec))
static void range_fill_vector(T *vec, int32_t len, T start=0)
bool equals(SGVector< T > &other)
static float64_t dot(const bool *v1, const bool *v2, int32_t n)
compute dot product between v1 and v2 (blas optimized)
SGVector< T > operator+(SGVector< T > x)
T & operator[](uint32_t index)
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 random_vector(T *vec, int32_t len, T min_value, T max_value)
static float64_t dot(const float64_t *v1, const char *v2, int32_t n)
compute dot product between v1 and v2
index_t find_position_to_insert(T element)
static T * clone_vector(const T *vec, int32_t len)
T & operator[](int64_t index)
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)
const T & operator[](uint32_t index) const
void atan2(T x)
atan2 of vector elements
static T max(T *vec, int32_t len)
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 T sum(T *vec, int32_t len)
return sum(vec)
void log()
natural logarithm of vector elements
virtual void copy_data(const SGReferencedData &orig)
static bool fequal(T x, T y, float64_t precision=1e-6)
return sum(abs(vec))
void set_element(const T &p_element, index_t index)
void exp()
exponential of vector elements
void cos()
cosine of vector elements
static int32_t arg_max(T *vec, int32_t inc, int32_t len, T *maxv_ptr=NULL)
return arg_max(vec)
void tanh()
hyperbolic tangent of vector elements
void random(T min_value, T max_value)
void sqrt()
square root of vector elements
void tan()
tangent of vector elements
static void add(T *target, T alpha, const T *v1, T beta, const T *v2, int32_t len)
target=alpha*vec1 + beta*vec2
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)
static float64_t onenorm(T *x, int32_t len)
|| x ||_1
void acos()
arc cosine of vector elements
void add(const SGVector< T > x)
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)
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 void vector_multiply(T *target, const T *v1, const T *v2, int32_t len)
compute vector multiplication
static T sum(SGVector< T > vec)
return sum(vec)
static int32_t arg_max_abs(T *vec, int32_t inc, int32_t len, T *maxv_ptr=NULL)
return arg_max_abs(vec)
template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry<T>* vector is orde...
static void permute_vector(SGVector< T > vec)
void scale(T alpha)
scale vector inplace
static SGVector< T > randperm_vec(int32_t n)
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)
const T & operator[](uint64_t index) const
void atan()
arc tangent of vector elements
static T min(T *vec, int32_t len)
shogun reference count managed data
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)
static T product(T *vec, int32_t len)
return the product of the vectors elements
static T max_abs(T *vec, int32_t len)
void sinh()
hyperbolic sine of vector elements
A File access base class.
void range_fill(T start=0)
void sin()
sine of vector elements
static void fill_vector(T *vec, int32_t len, T value)
static void scale_vector(T alpha, T *vec, int32_t len)
scale vector inplace
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)
SGVector< T > operator+=(SGVector< T > x)
void set_const(T const_elem)
: Pseudo random number geneartor
const T & operator[](int32_t index) const
void asin()
arc sine of vector elements
all of classes and functions are contained in the shogun namespace
void display_size() const
SGVector< float64_t > get_imag()
SGVector< float64_t > get_real()
void log10()
common logarithm of vector elements
static floatmax_t dot(const floatmax_t *v1, const floatmax_t *v2, int32_t n)
compute dot product between v1 and v2 (blas optimized)
SGVector< index_t > find(T elem)
static T qnorm(T *x, int32_t len, float64_t q)
|| x ||_q
void pow(T q)
power of vector elements
T product()
return product(vec)
const T & operator[](int64_t index) const
void resize_vector(int32_t n)
SGVector< index_t > argsort()
static void add_scalar(T alpha, T *vec, int32_t len)
add scalar to vector inplace
static float64_t * linspace(T start, T end, int32_t n)
static SGMatrix< T > convert_to_matrix(SGVector< T > vector, index_t nrows, index_t ncols, bool fortran_order)
T & operator[](int32_t index)
void abs()
absolute value of vector elements
const T & get_element(index_t index)
T & operator[](uint64_t index)
static int32_t unique(T *output, int32_t size)
SGVector< T > clone() const
static T qsq(T *x, int32_t len, float64_t q)
|| x ||_q^q
SGVector< index_t > find_if(Predicate p)
static int32_t arg_min(T *vec, int32_t inc, int32_t len, T *minv_ptr=NULL)
return arg_min(vec)
static void vec1_plus_scalar_times_vec2(T *vec1, const T scalar, const T *vec2, int32_t n)
x=x+alpha*y
static T twonorm(const T *x, int32_t len)
|| x ||_2
void display_vector(const char *name="vector", const char *prefix="") const