14 #ifndef __SGVECTOR_H__
15 #define __SGVECTOR_H__
24 template <
class,
int,
int,
int,
int,
int>
class Matrix;
25 template<
int,
int>
class Stride;
26 template <
class,
int,
class>
class Map;
31 template <
class T>
class SGSparseVector;
32 template <
class T>
class SGMatrix;
37 template<
class T>
class SGVector :
public SGReferencedData
65 #ifndef SWIG // SWIG should skip this part
74 operator EigenVectorXtMap()
const;
77 operator EigenRowVectorXtMap()
const;
97 #ifndef SWIG // SWIG should skip this part
127 void random(T min_value, T max_value);
163 static void fill_vector(T* vec, int32_t len, T value);
169 static void random_vector(T* vec, int32_t len, T min_value, T max_value);
316 static T
twonorm(
const T* x, int32_t len);
329 const T scalar,
const T* vec2, int32_t n);
335 for (int32_t i=0; i<n; i++)
336 r+=((v1[i]) ? 1 : 0) * ((v2[i]) ? 1 : 0);
344 for (int32_t i=0; i<n; i++)
358 const uint64_t* v1,
const uint64_t* v2, int32_t n)
361 for (int32_t i=0; i<n; i++)
368 const int64_t* v1,
const int64_t* v2, int32_t n)
371 for (int32_t i=0; i<n; i++)
379 const int32_t* v1,
const int32_t* v2, int32_t n)
382 for (int32_t i=0; i<n; i++)
390 const uint32_t* v1,
const uint32_t* v2, int32_t n)
393 for (int32_t i=0; i<n; i++)
401 const uint16_t* v1,
const uint16_t* v2, int32_t n)
404 for (int32_t i=0; i<n; i++)
412 const int16_t* v1,
const int16_t* v2, int32_t n)
415 for (int32_t i=0; i<n; i++)
423 const char* v1,
const char* v2, int32_t n)
426 for (int32_t i=0; i<n; i++)
434 const uint8_t* v1,
const uint8_t* v2, int32_t n)
437 for (int32_t i=0; i<n; i++)
445 const int8_t* v1,
const int8_t* v2, int32_t n)
448 for (int32_t i=0; i<n; i++)
456 const float64_t* v1,
const char* v2, int32_t n)
459 for (int32_t i=0; i<n; i++)
467 T* target,
const T* v1,
const T* v2,int32_t len)
469 for (int32_t i=0; i<len; i++)
470 target[i]=v1[i]*v2[i];
476 T* target, T alpha,
const T* v1, T beta,
const T* v2,
479 for (int32_t i=0; i<len; i++)
480 target[i]=alpha*v1[i]+beta*v2[i];
486 for (int32_t i=0; i<len; i++)
494 static inline T
sum(T* vec, int32_t len)
497 for (int32_t i=0; i<len; i++)
506 return sum(vec.vector, vec.vlen);
513 for (int32_t i=0; i<len; i++)
526 static T
sum_abs(T* vec, int32_t len);
534 static int32_t
unique(T* output, int32_t
size);
541 const char* prefix=
"")
const;
545 const T*
vector, int32_t n,
const char* name=
"vector",
546 const char* prefix=
"");
551 const char* prefix=
"");
561 template <
typename Predicate>
622 #endif // #ifndef SWIG // SWIG should skip this part
640 #ifndef DOXYGEN_SHOULD_SKIP_THIS
646 #endif // DOXYGEN_SHOULD_SKIP_THIS
648 #endif // __SGVECTOR_H__
static T twonorm(const T *x, int32_t len)
|| x ||_2
void range_fill(T start=0)
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)
SGVector(T *m, index_t len, index_t offset)
void set(SGVector< T > orig)
bool equals(SGVector< T > &other)
SGVector< float64_t > get_imag()
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 scale(T alpha)
Scale vector inplace.
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))
void display_vector(const char *name="vector", const char *prefix="") const
static T * clone_vector(const T *vec, int32_t len)
SGVector< index_t > argsort()
void set_element(const T &p_element, index_t index)
SGVector< index_t > find_if(Predicate p)
static T product(T *vec, int32_t len)
Return the product of the vectors elements.
static T sum_abs(T *vec, int32_t len)
return sum(abs(vec))
const T & operator[](uint64_t index) const
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.
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.
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 sum(SGVector< T > vec)
Return sum(vec)
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)
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 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
const T & operator[](uint32_t index) const
const T & operator[](int64_t index) const
SGVector< index_t > find(T elem)
static int32_t unique(T *output, int32_t size)
void set_const(T const_elem)
void add(const SGVector< T > x)
static void random_vector(T *vec, int32_t len, T min_value, T max_value)