14 #ifndef __SGVECTOR_H__ 15 #define __SGVECTOR_H__ 17 #include <shogun/lib/config.h> 29 template <
class,
int,
int,
int,
int,
int>
class Matrix;
30 template<
int,
int>
class Stride;
31 template <
class,
int,
class>
class Map;
36 template <
class T>
class SGSparseVector;
37 template <
class T>
class SGMatrix;
42 template<
class T>
class SGVector :
public SGReferencedData
88 #ifndef SWIG // SWIG should skip this part 89 #if defined(HAVE_CXX0X) || defined(HAVE_CXX11) 92 template <
typename ST>
using container_type =
SGVector<ST>;
94 #endif // define (HAVE_CXX0X) || defined(HAVE_CXX11) 125 #ifndef SWIG // SWIG should skip this part 164 void random(T min_value, T max_value);
181 static void fill_vector(T* vec, int32_t len, T value);
187 static void random_vector(T* vec, int32_t len, T min_value, T max_value);
188 #endif // SWIG // SWIG should skip this part 197 return (*
this)[index];
210 #ifndef SWIG // SWIG should skip this part 348 static T
twonorm(
const T* x, int32_t len);
361 const T scalar,
const T* vec2, int32_t n);
365 T* target,
const T* v1,
const T* v2,int32_t len)
367 for (int32_t i=0; i<len; i++)
368 target[i]=v1[i]*v2[i];
374 T* target, T alpha,
const T* v1, T beta,
const T* v2,
377 for (int32_t i=0; i<len; i++)
378 target[i]=alpha*v1[i]+beta*v2[i];
384 for (int32_t i=0; i<len; i++)
392 static inline T
sum(T* vec, int32_t len)
395 for (int32_t i=0; i<len; i++)
404 return sum(vec.vector, vec.vlen);
411 for (int32_t i=0; i<len; i++)
424 static T
sum_abs(T* vec, int32_t len);
429 static int32_t
unique(T* output, int32_t
size);
436 const char* prefix=
"")
const;
440 const T*
vector, int32_t n,
const char* name=
"vector",
441 const char* prefix=
"");
446 const char* prefix=
"");
456 template <
typename Predicate>
517 #endif // #ifndef SWIG // SWIG should skip this part 530 std::atomic<bool> m_on_gpu;
535 void assert_on_cpu()
const 538 SG_SERROR(
"Direct memory access not possible when data is in GPU memory.\n");
550 #ifndef DOXYGEN_SHOULD_SKIP_THIS 556 #endif // DOXYGEN_SHOULD_SKIP_THIS 558 #endif // __SGVECTOR_H__ std::shared_ptr< GPUMemoryBase< T > > gpu_ptr
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)
SGVector< T > operator+(SGVector< T > x)
T & operator[](uint32_t index)
static void random_vector(T *vec, int32_t len, T min_value, T max_value)
index_t find_position_to_insert(T element)
static T * clone_vector(const T *vec, int32_t len)
T & operator[](int64_t index)
const T & operator[](uint32_t index) const
static T sum(T *vec, int32_t len)
Return sum(vec)
virtual void copy_data(const SGReferencedData &orig)
Eigen::Map< EigenVectorXt, 0, Eigen::Stride< 0, 0 > > EigenVectorXtMap
void random(T min_value, T max_value)
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 onenorm(T *x, int32_t len)
|| x ||_1
void add(const SGVector< T > x)
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)
template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry<T>* vector is orde...
void scale(T alpha)
Scale vector inplace.
const T & operator[](uint64_t index) const
Eigen::Matrix< T, 1,-1, 0x1, 1,-1 > EigenRowVectorXt
shogun reference count managed data
static T product(T *vec, int32_t len)
Return the product of the vectors elements.
A File access base class.
void range_fill(T start=0)
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.
const T & get_element(index_t index)
SGVector< T > operator+=(SGVector< T > x)
void set_const(T const_elem)
const T & operator[](int32_t index) const
all of classes and functions are contained in the shogun namespace
SGVector< T > & operator=(const SGVector< T > &)
void display_size() const
SGVector< float64_t > get_imag()
Interface for GPU memory libraries.
SGVector< float64_t > get_real()
void set_element(const T &el, index_t index)
SGVector< index_t > find(T elem)
static T qnorm(T *x, int32_t len, float64_t q)
|| x ||_q
Eigen::Map< EigenRowVectorXt, 0, Eigen::Stride< 0, 0 > > EigenRowVectorXtMap
Linalg methods with Eigen3 backend.
T product()
Return product(vec)
const T & operator[](int64_t index) const
void resize_vector(int32_t n)
static void add_scalar(T alpha, T *vec, int32_t len)
Add scalar to vector inplace.
static SGMatrix< T > convert_to_matrix(SGVector< T > vector, index_t nrows, index_t ncols, bool fortran_order)
T & operator[](int32_t index)
Eigen::Matrix< T,-1, 1, 0,-1, 1 > EigenVectorXt
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 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