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 66 #if defined(HAVE_CXX0X) || defined(HAVE_CXX11) 69 template <
typename ST>
using container_type =
SGVector<ST>;
71 #endif // define (HAVE_CXX0X) || defined(HAVE_CXX11) 81 operator EigenVectorXtMap()
const;
84 operator EigenRowVectorXtMap()
const;
92 void set_const(T const_elem);
104 #ifndef SWIG // SWIG should skip this part 115 inline int32_t
size()
const {
return vlen; }
124 operator T*() {
return vector; }
133 void range_fill(T start=0);
140 void random(T min_value, T max_value);
148 index_t find_position_to_insert(T element);
154 static T* clone_vector(
const T* vec, int32_t len);
157 static void fill_vector(T* vec, int32_t len, T value);
160 static void range_fill_vector(T* vec, int32_t len, T start=0);
163 static void random_vector(T* vec, int32_t len, T min_value, T max_value);
170 const T& get_element(
index_t index);
178 void set_element(
const T& p_element,
index_t index);
185 void resize_vector(int32_t n);
194 return vector[index];
204 return vector[index];
214 return vector[index];
224 return vector[index];
234 return vector[index];
244 return vector[index];
254 return vector[index];
264 return vector[index];
310 static T twonorm(
const T* x, int32_t len);
313 static float64_t onenorm(T* x, int32_t len);
316 static T qsq(T* x, int32_t len,
float64_t q);
319 static T qnorm(T* x, int32_t len,
float64_t q);
322 static void vec1_plus_scalar_times_vec2(T* vec1,
323 const T scalar,
const T* vec2, int32_t n);
327 T* target,
const T* v1,
const T* v2,int32_t len)
329 for (int32_t i=0; i<len; i++)
330 target[i]=v1[i]*v2[i];
336 T* target, T alpha,
const T* v1, T beta,
const T* v2,
339 for (int32_t i=0; i<len; i++)
340 target[i]=alpha*v1[i]+beta*v2[i];
346 for (int32_t i=0; i<len; i++)
351 static void scale_vector(T alpha, T* vec, int32_t len);
354 static inline T
sum(T* vec, int32_t len)
357 for (int32_t i=0; i<len; i++)
366 return sum(vec.vector, vec.vlen);
373 for (int32_t i=0; i<len; i++)
382 return product(vector, vlen);
386 static T sum_abs(T* vec, int32_t len);
391 static int32_t unique(T* output, int32_t size);
394 void display_size()
const;
397 void display_vector(
const char* name=
"vector",
398 const char* prefix=
"")
const;
401 static void display_vector(
402 const T* vector, int32_t n,
const char* name=
"vector",
403 const char* prefix=
"");
406 static void display_vector(
408 const char* prefix=
"");
418 template <
typename Predicate>
424 for (
index_t i=0; i < vlen; ++i)
439 void load(
CFile* loader);
445 void save(
CFile* saver);
478 static void convert_to_matrix(T*& matrix,
index_t nrows,
index_t ncols,
const T* vector, int32_t vlen,
bool fortran_order);
479 #endif // #ifndef SWIG // SWIG should skip this part 485 virtual void init_data();
488 virtual void free_data();
497 #ifndef DOXYGEN_SHOULD_SKIP_THIS 503 #endif // DOXYGEN_SHOULD_SKIP_THIS 505 #endif // __SGVECTOR_H__
T & operator[](uint32_t index)
T & operator[](int64_t index)
const T & operator[](uint64_t index) const
static T sum(T *vec, int32_t len)
Return sum(vec)
static void add(T *target, T alpha, const T *v1, T beta, const T *v2, int32_t len)
target=alpha*vec1 + beta*vec2
SGVector(T *m, index_t len, index_t offset)
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 add(Matrix A, Matrix B, Matrix C, typename Matrix::Scalar alpha=1.0, typename Matrix::Scalar beta=1.0)
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.
const T & operator[](int32_t index) const
const T & operator[](int64_t index) const
all of classes and functions are contained in the shogun namespace
const T & operator[](uint32_t index) const
void scale(Matrix A, Matrix B, typename Matrix::Scalar alpha)
T product()
Return product(vec)
static void add_scalar(T alpha, T *vec, int32_t len)
Add scalar to vector inplace.
T & operator[](int32_t index)
T & operator[](uint64_t index)
SGVector< index_t > find_if(Predicate p)