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
85 return gpu_ptr != NULL;
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) 103 operator EigenVectorXtMap()
const;
106 operator EigenRowVectorXtMap()
const;
125 #ifndef SWIG // SWIG should skip this part 136 inline int32_t
size()
const {
return vlen; }
148 operator T*() {
return vector; }
164 void random(T min_value, T max_value);
172 index_t find_position_to_insert(T element);
178 static T* clone_vector(
const T* vec, int32_t len);
181 static void fill_vector(T* vec, int32_t len, T value);
184 static void range_fill_vector(T* vec, int32_t len, T start=0);
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 215 void resize_vector(int32_t n);
225 return vector[index];
236 return vector[index];
247 return vector[index];
258 return vector[index];
269 return vector[index];
280 return vector[index];
291 return vector[index];
302 return vector[index];
348 static T twonorm(
const T* x, int32_t len);
351 static float64_t onenorm(T* x, int32_t len);
354 static T qsq(T* x, int32_t len,
float64_t q);
357 static T qnorm(T* x, int32_t len,
float64_t q);
360 static void vec1_plus_scalar_times_vec2(T* vec1,
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++)
389 static void scale_vector(T alpha, T* vec, int32_t len);
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++)
420 return product(vector, vlen);
424 static T sum_abs(T* vec, int32_t len);
429 static int32_t unique(T* output, int32_t size);
432 void display_size()
const;
435 void display_vector(
const char* name=
"vector",
436 const char* prefix=
"")
const;
439 static void display_vector(
440 const T* vector, int32_t n,
const char* name=
"vector",
441 const char* prefix=
"");
444 static void display_vector(
446 const char* prefix=
"");
456 template <
typename Predicate>
462 for (
index_t i=0; i < vlen; ++i)
477 void load(
CFile* loader);
483 void save(
CFile* saver);
516 static void convert_to_matrix(T*& matrix,
index_t nrows,
index_t ncols,
const T* vector, int32_t vlen,
bool fortran_order);
517 #endif // #ifndef SWIG // SWIG should skip this part 523 virtual void init_data();
526 virtual void free_data();
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
T & operator[](uint32_t index)
T & operator[](int64_t index)
const T & operator[](uint32_t index) const
static T sum(T *vec, int32_t len)
Return sum(vec)
void scale(SGVector< T > &a, SGVector< T > &result, T alpha=1)
void add(SGVector< T > &a, SGVector< T > &b, SGVector< T > &result, T alpha=1, T beta=1)
Eigen::Map< EigenVectorXt, 0, Eigen::Stride< 0, 0 > > EigenVectorXtMap
void set_const(Container< T > &a, T 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 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...
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.
void range_fill(Container< T > &a, const T start=0)
A File access base class.
const T & get_element(index_t index)
const T & operator[](int32_t index) const
all of classes and functions are contained in the shogun namespace
T sum(const Container< T > &a, bool no_diag=false)
Interface for GPU memory libraries.
void set_element(const T &el, index_t index)
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
static void add_scalar(T alpha, T *vec, int32_t len)
Add scalar to vector inplace.
T & operator[](int32_t index)
Eigen::Matrix< T,-1, 1, 0,-1, 1 > EigenVectorXt
T & operator[](uint64_t index)
SGVector< index_t > find_if(Predicate p)