16 #include <shogun/lib/config.h> 29 #define COMPLEX128_ERROR_NOARG(function) \ 31 void SGVector<complex128_t>::function() \ 33 SG_SERROR("SGVector::%s():: Not supported for complex128_t\n",\ 37 #define BOOL_ERROR_ONEARG(function) \ 39 void SGVector<bool>::function(bool a) \ 41 SG_SERROR("SGVector::%s():: Not supported for bool\n",\ 45 #define COMPLEX128_ERROR_ONEARG(function) \ 47 void SGVector<complex128_t>::function(complex128_t a) \ 49 SG_SERROR("SGVector::%s():: Not supported for complex128_t\n",\ 53 #define COMPLEX128_ERROR_TWOARGS(function) \ 55 void SGVector<complex128_t>::function(complex128_t a, complex128_t b) \ 57 SG_SERROR("SGVector::%s():: Not supported for complex128_t\n",\ 61 #define COMPLEX128_ERROR_THREEARGS(function) \ 63 void SGVector<complex128_t>::function(complex128_t a, complex128_t b,\ 66 SG_SERROR("SGVector::%s():: Not supported for complex128_t\n",\ 82 m_on_gpu.store(
false, std::memory_order_release);
89 m_on_gpu.store(
false, std::memory_order_release);
97 m_on_gpu.store(
false, std::memory_order_release);
105 m_on_gpu.store(
true, std::memory_order_release);
143 m_on_gpu.store(
false, std::memory_order_release);
150 m_on_gpu.store(
false, std::memory_order_release);
205 #endif // HAVE_CATLAS 230 for (i=0; i<
vlen; ++i)
241 SG_SERROR(
"SGVector::find_position_to_insert():: \ 242 Not supported for complex128_t\n");
258 T* result = SG_MALLOC(T, len);
259 sg_memcpy(result, vec,
sizeof(T)*len);
266 for (int32_t i=0; i<len; i++)
273 for (int32_t i=0; i<len; i++)
281 SG_SERROR(
"SGVector::range_fill_vector():: \ 282 Not supported for complex128_t\n");
302 REQUIRE(x.
vlen ==
vlen,
"Length of the two vectors to be added should be same. [V(%d) + V(%d)]\n",
vlen, x.
vlen);
314 REQUIRE(x.
vlen ==
vlen,
"Length of the two vectors to be added should be same. [V(%d) + V(%d)]\n",
vlen, x.
vlen);
316 for (int32_t i=0; i<
vlen; i++)
324 REQUIRE(
vector,
"Addition possible for only non-null vectors.\n");
325 for (int32_t i=0; i<
vlen; i++)
357 m_on_gpu.store(((
SGVector*)(&orig))->m_on_gpu.load(
358 std::memory_order_acquire), std::memory_order_release);
367 m_on_gpu.store(
false, std::memory_order_release);
397 const char* prefix)
const 413 REQUIRE(n>=0,
"Vector size can not be negative.\n");
415 for (int32_t i=0; i<n; i++)
416 SG_SPRINT(
"%s%d%s", prefix, vector[i] ? 1 : 0, i==n-1?
"" :
",")
424 REQUIRE(n>=0,
"Vector size can not be negative.\n");
426 for (int32_t i=0; i<n; i++)
427 SG_SPRINT(
"%s%c%s", prefix, vector[i], i==n-1?
"" :
",")
435 REQUIRE(n>=0,
"Vector size can not be negative.\n");
437 for (int32_t i=0; i<n; i++)
438 SG_SPRINT(
"%s%u%s", prefix, vector[i], i==n-1?
"" :
",")
446 REQUIRE(n>=0,
"Vector size can not be negative.\n");
448 for (int32_t i=0; i<n; i++)
449 SG_SPRINT(
"%s%d%s", prefix, vector[i], i==n-1?
"" :
",")
457 REQUIRE(n>=0,
"Vector size can not be negative.\n");
459 for (int32_t i=0; i<n; i++)
460 SG_SPRINT(
"%s%u%s", prefix, vector[i], i==n-1?
"" :
",")
468 REQUIRE(n>=0,
"Vector size can not be negative.\n");
470 for (int32_t i=0; i<n; i++)
471 SG_SPRINT(
"%s%d%s", prefix, vector[i], i==n-1?
"" :
",")
479 REQUIRE(n>=0,
"Vector size can not be negative.\n");
481 for (int32_t i=0; i<n; i++)
482 SG_SPRINT(
"%s%d%s", prefix, vector[i], i==n-1?
"" :
",")
490 REQUIRE(n>=0,
"Vector size can not be negative.\n");
492 for (int32_t i=0; i<n; i++)
493 SG_SPRINT(
"%s%u%s", prefix, vector[i], i==n-1?
"" :
",")
502 REQUIRE(n>=0,
"Vector size can not be negative.\n");
504 for (int32_t i=0; i<n; i++)
505 SG_SPRINT(
"%s%lld%s", prefix, vector[i], i==n-1?
"" :
",")
513 REQUIRE(n>=0,
"Vector size can not be negative.\n");
515 for (int32_t i=0; i<n; i++)
516 SG_SPRINT(
"%s%llu%s", prefix, vector[i], i==n-1?
"" :
",")
524 REQUIRE(n>=0,
"Vector size can not be negative.\n");
526 for (int32_t i=0; i<n; i++)
527 SG_SPRINT(
"%s%g%s", prefix, vector[i], i==n-1?
"" :
",")
535 REQUIRE(n>=0,
"Vector size can not be negative.\n");
537 for (int32_t i=0; i<n; i++)
538 SG_SPRINT(
"%s%.18g%s", prefix, vector[i], i==n-1?
"" :
",")
544 const char* name,
const char* prefix)
546 REQUIRE(n>=0,
"Vector size can not be negative.\n");
548 for (int32_t i=0; i<n; i++)
550 SG_SPRINT(
"%s%.36Lg%s", prefix, (
long double) vector[i],
558 const char* name,
const char* prefix)
560 REQUIRE(n>=0,
"Vector size can not be negative.\n");
562 for (int32_t i=0; i<n; i++)
564 SG_SPRINT(
"%s(%.36lg+i%.36lg)%s", prefix, vector[i].real(),
565 vector[i].imag(), i==n-1?
"" :
",");
572 const T scalar,
const T* vec2, int32_t n)
574 for (int32_t i=0; i<n; i++)
575 vec1[i]+=scalar*vec2[i];
584 cblas_daxpy(n, scalar, vec2, skip, vec1, skip);
586 for (int32_t i=0; i<n; i++)
587 vec1[i]+=scalar*vec2[i];
597 cblas_saxpy(n, scalar, vec2, skip, vec1, skip);
599 for (int32_t i=0; i<n; i++)
600 vec1[i]+=scalar*vec2[i];
607 for (int32_t i=0; i<len; i++)
636 for (int32_t i=0; i<len; i++)
646 for (int32_t i=0; i<len; i++)
656 for (int32_t i=0; i<len; i++)
666 for (int32_t i=0; i<len; i++)
676 for (int32_t i=0; i<len; i++)
686 for (int32_t i=0; i<len; i++)
696 for (int32_t i=0; i<len; i++)
706 for (int32_t i=0; i<len; i++)
716 for (int32_t i=0; i<len; i++)
727 norm = cblas_dnrm2(n, v, 1);
738 for (int32_t i=0; i<len; i++)
748 for (int32_t i=0; i<len; i++)
758 for (int32_t i=0;i<len; ++i)
769 for (int32_t i=0; i<len; i++)
786 REQUIRE(q!=0,
"Q should be non-zero for calculating qnorm\n");
802 for (int32_t i=0; i<len; i++)
813 result = cblas_dasum(len, vec, 1);
821 result = cblas_sasum(len, vec, 1);
829 CMath::qsort<T>(output,
size);
832 for (int32_t i=0; i<
size; i++)
834 if (i==0 || output[i]!=output[i-1])
835 output[j++]=output[i];
844 SG_SERROR(
"SGVector::unique():: Not supported for complex128_t\n");
865 for (int32_t i=0; i<len; i++)
873 cblas_dscal(len, alpha, vec, 1);
879 cblas_sscal(len, alpha, vec, 1);
891 REQUIRE(loader,
"Require a valid 'c FILE pointer'\n");
907 SG_SERROR(
"SGVector::load():: Not supported for complex128_t\n");
912 REQUIRE(saver,
"Requires a valid 'c FILE pointer'\n");
923 SG_SERROR(
"SGVector::save():: Not supported for complex128_t\n");
930 for (int32_t i=0; i<
vlen; i++)
939 for (int32_t i=0; i<
vlen; i++)
948 if (nrows*ncols>vector.
size())
949 SG_SERROR(
"SGVector::convert_to_matrix():: Dimensions mismatch\n");
961 if (nrows*ncols>vlen)
962 SG_SERROR(
"SGVector::convert_to_matrix():: Dimensions mismatch\n");
966 matrix=SG_MALLOC(T, nrows*ncols);
970 for (
index_t i=0; i<ncols*nrows; i++)
975 for (
index_t i=0; i<nrows; i++)
977 for (
index_t j=0; j<ncols; j++)
978 matrix[i+j*nrows]=vector[j+i*ncols];
983 #define UNDEFINED(function, type) \ 985 SGVector<float64_t> SGVector<type>::function() \ 987 SG_SERROR("SGVector::%s():: Not supported for %s\n", \ 989 SGVector<float64_t> ret(vlen); \ 1021 template class SGVector<bool>;
1022 template class SGVector<char>;
1023 template class SGVector<int8_t>;
1024 template class SGVector<uint8_t>;
1025 template class SGVector<int16_t>;
1026 template class SGVector<uint16_t>;
1027 template class SGVector<int32_t>;
1028 template class SGVector<uint32_t>;
1029 template class SGVector<int64_t>;
1030 template class SGVector<uint64_t>;
1031 template class SGVector<float32_t>;
1032 template class SGVector<float64_t>;
1033 template class SGVector<floatmax_t>;
1034 template class SGVector<complex128_t>;
1037 #undef COMPLEX128_ERROR_NOARG 1038 #undef COMPLEX128_ERROR_ONEARG 1039 #undef COMPLEX128_ERROR_TWOARGS 1040 #undef COMPLEX128_ERROR_THREEARGS 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)
static void random_vector(T *vec, int32_t len, T min_value, T max_value)
index_t find_position_to_insert(T element)
std::complex< float64_t > complex128_t
static T * clone_vector(const T *vec, int32_t len)
#define COMPLEX128_ERROR_TWOARGS(function)
virtual void copy_data(const SGReferencedData &orig)
Eigen::Map< EigenVectorXt, 0, Eigen::Stride< 0, 0 > > EigenVectorXtMap
void random(T min_value, T max_value)
#define SG_SNOTIMPLEMENTED
static float64_t onenorm(T *x, int32_t len)
|| x ||_1
void add(const SGVector< T > x)
static float64_t imag(complex128_t c)
static float64_t real(complex128_t c)
template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry<T>* vector is orde...
void scale(T alpha)
Scale vector inplace.
#define UNDEFINED(function, type)
void copy_refcount(const SGReferencedData &orig)
virtual void get_vector(bool *&vector, int32_t &len)
shogun reference count managed data
A File access base class.
void range_fill(T start=0)
SGVector< T > clone() const
static void fill_vector(T *vec, int32_t len, T value)
static float64_t dot(const bool *v1, const bool *v2, int32_t n)
Compute dot product between v1 and v2 (blas optimized)
static void scale_vector(T alpha, T *vec, int32_t len)
Scale vector inplace.
void set_const(T const_elem)
#define COMPLEX128_ERROR_ONEARG(function)
all of classes and functions are contained in the shogun namespace
SGVector< T > & operator=(const SGVector< T > &)
SGVector< float64_t > get_imag()
Interface for GPU memory libraries.
SGVector< float64_t > get_real()
void display_size() const
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
void resize_vector(int32_t n)
virtual void set_vector(const bool *vector, int32_t len)
static SGMatrix< T > convert_to_matrix(SGVector< T > vector, index_t nrows, index_t ncols, bool fortran_order)
void display_vector(const char *name="vector", const char *prefix="") const
static float32_t sqrt(float32_t x)
void set(SGVector< T > orig)
static int32_t unique(T *output, int32_t size)
static int32_t pow(bool x, int32_t n)
static T qsq(T *x, int32_t len, float64_t q)
|| x ||_q^q
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
SGSparseVectorEntry< T > * features