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",\ 170 #endif // HAVE_CATLAS 192 for (i=0; i<
vlen; ++i)
203 SG_SERROR(
"SGVector::find_position_to_insert():: \ 204 Not supported for complex128_t\n");
217 T* result = SG_MALLOC(T, len);
218 memcpy(result, vec,
sizeof(T)*len);
225 for (int32_t i=0; i<len; i++)
232 for (int32_t i=0; i<len; i++)
240 SG_SERROR(
"SGVector::range_fill_vector():: \ 241 Not supported for complex128_t\n");
247 REQUIRE(
vector && (index>=0) && (index<
vlen),
"Provided index (%d) must be between 0 and %d.\n", index,
vlen);
254 REQUIRE(
vector && (index>=0) && (index<
vlen),
"Provided index (%d) must be between 0 and %d.\n", index,
vlen);
273 REQUIRE(x.
vlen ==
vlen,
"Length of the two vectors to be added should be same. [V(%d) + V(%d)]\n",
vlen, x.
vlen);
284 REQUIRE(x.
vlen ==
vlen,
"Length of the two vectors to be added should be same. [V(%d) + V(%d)]\n",
vlen, x.
vlen);
286 for (int32_t i=0; i<
vlen; i++)
293 REQUIRE(
vector,
"Addition possible for only non-null vectors.\n");
294 for (int32_t i=0; i<
vlen; i++)
357 const char* prefix)
const 373 REQUIRE(n>=0,
"Vector size can not be negative.\n");
375 for (int32_t i=0; i<n; i++)
376 SG_SPRINT(
"%s%d%s", prefix, vector[i] ? 1 : 0, i==n-1?
"" :
",")
384 REQUIRE(n>=0,
"Vector size can not be negative.\n");
386 for (int32_t i=0; i<n; i++)
387 SG_SPRINT(
"%s%c%s", prefix, vector[i], i==n-1?
"" :
",")
395 REQUIRE(n>=0,
"Vector size can not be negative.\n");
397 for (int32_t i=0; i<n; i++)
398 SG_SPRINT(
"%s%u%s", prefix, vector[i], i==n-1?
"" :
",")
406 REQUIRE(n>=0,
"Vector size can not be negative.\n");
408 for (int32_t i=0; i<n; i++)
409 SG_SPRINT(
"%s%d%s", prefix, vector[i], i==n-1?
"" :
",")
417 REQUIRE(n>=0,
"Vector size can not be negative.\n");
419 for (int32_t i=0; i<n; i++)
420 SG_SPRINT(
"%s%u%s", prefix, vector[i], i==n-1?
"" :
",")
428 REQUIRE(n>=0,
"Vector size can not be negative.\n");
430 for (int32_t i=0; i<n; i++)
431 SG_SPRINT(
"%s%d%s", prefix, vector[i], i==n-1?
"" :
",")
439 REQUIRE(n>=0,
"Vector size can not be negative.\n");
441 for (int32_t i=0; i<n; i++)
442 SG_SPRINT(
"%s%d%s", prefix, vector[i], i==n-1?
"" :
",")
450 REQUIRE(n>=0,
"Vector size can not be negative.\n");
452 for (int32_t i=0; i<n; i++)
453 SG_SPRINT(
"%s%u%s", prefix, vector[i], i==n-1?
"" :
",")
462 REQUIRE(n>=0,
"Vector size can not be negative.\n");
464 for (int32_t i=0; i<n; i++)
465 SG_SPRINT(
"%s%lld%s", prefix, vector[i], i==n-1?
"" :
",")
473 REQUIRE(n>=0,
"Vector size can not be negative.\n");
475 for (int32_t i=0; i<n; i++)
476 SG_SPRINT(
"%s%llu%s", prefix, vector[i], i==n-1?
"" :
",")
484 REQUIRE(n>=0,
"Vector size can not be negative.\n");
486 for (int32_t i=0; i<n; i++)
487 SG_SPRINT(
"%s%g%s", prefix, vector[i], i==n-1?
"" :
",")
495 REQUIRE(n>=0,
"Vector size can not be negative.\n");
497 for (int32_t i=0; i<n; i++)
498 SG_SPRINT(
"%s%.18g%s", prefix, vector[i], i==n-1?
"" :
",")
504 const char* name,
const char* prefix)
506 REQUIRE(n>=0,
"Vector size can not be negative.\n");
508 for (int32_t i=0; i<n; i++)
510 SG_SPRINT(
"%s%.36Lg%s", prefix, (
long double) vector[i],
518 const char* name,
const char* prefix)
520 REQUIRE(n>=0,
"Vector size can not be negative.\n");
522 for (int32_t i=0; i<n; i++)
524 SG_SPRINT(
"%s(%.36lg+i%.36lg)%s", prefix, vector[i].real(),
525 vector[i].imag(), i==n-1?
"" :
",");
532 const T scalar,
const T* vec2, int32_t n)
534 for (int32_t i=0; i<n; i++)
535 vec1[i]+=scalar*vec2[i];
544 cblas_daxpy(n, scalar, vec2, skip, vec1, skip);
546 for (int32_t i=0; i<n; i++)
547 vec1[i]+=scalar*vec2[i];
557 cblas_saxpy(n, scalar, vec2, skip, vec1, skip);
559 for (int32_t i=0; i<n; i++)
560 vec1[i]+=scalar*vec2[i];
567 for (int32_t i=0; i<len; i++)
596 for (int32_t i=0; i<len; i++)
606 for (int32_t i=0; i<len; i++)
616 for (int32_t i=0; i<len; i++)
626 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++)
687 norm = cblas_dnrm2(n, v, 1);
698 for (int32_t i=0; i<len; i++)
708 for (int32_t i=0; i<len; i++)
718 for (int32_t i=0;i<len; ++i)
729 for (int32_t i=0; i<len; i++)
746 REQUIRE(q!=0,
"Q should be non-zero for calculating qnorm\n");
762 for (int32_t i=0; i<len; i++)
773 result = cblas_dasum(len, vec, 1);
781 result = cblas_sasum(len, vec, 1);
789 CMath::qsort<T>(output,
size);
792 for (int32_t i=0; i<
size; i++)
794 if (i==0 || output[i]!=output[i-1])
795 output[j++]=output[i];
804 SG_SERROR(
"SGVector::unique():: Not supported for complex128_t\n");
824 for (int32_t i=0; i<len; i++)
832 cblas_dscal(len, alpha, vec, 1);
838 cblas_sscal(len, alpha, vec, 1);
850 REQUIRE(loader,
"Require a valid 'c FILE pointer'\n");
865 SG_SERROR(
"SGVector::load():: Not supported for complex128_t\n");
870 REQUIRE(saver,
"Requires a valid 'c FILE pointer'\n");
880 SG_SERROR(
"SGVector::save():: Not supported for complex128_t\n");
886 for (int32_t i=0; i<
vlen; i++)
894 for (int32_t i=0; i<
vlen; i++)
903 if (nrows*ncols>vector.
size())
904 SG_SERROR(
"SGVector::convert_to_matrix():: Dimensions mismatch\n");
916 if (nrows*ncols>vlen)
917 SG_SERROR(
"SGVector::convert_to_matrix():: Dimensions mismatch\n");
921 matrix=SG_MALLOC(T, nrows*ncols);
925 for (
index_t i=0; i<ncols*nrows; i++)
930 for (
index_t i=0; i<nrows; i++)
932 for (
index_t j=0; j<ncols; j++)
933 matrix[i+j*nrows]=vector[j+i*ncols];
938 #define UNDEFINED(function, type) \ 940 SGVector<float64_t> SGVector<type>::function() \ 942 SG_SERROR("SGVector::%s():: Not supported for %s\n", \ 944 SGVector<float64_t> ret(vlen); \ 976 template class SGVector<bool>;
977 template class SGVector<char>;
978 template class SGVector<int8_t>;
979 template class SGVector<uint8_t>;
980 template class SGVector<int16_t>;
981 template class SGVector<uint16_t>;
982 template class SGVector<int32_t>;
983 template class SGVector<uint32_t>;
984 template class SGVector<int64_t>;
985 template class SGVector<uint64_t>;
986 template class SGVector<float32_t>;
987 template class SGVector<float64_t>;
988 template class SGVector<floatmax_t>;
989 template class SGVector<complex128_t>;
992 #undef COMPLEX128_ERROR_NOARG 993 #undef COMPLEX128_ERROR_ONEARG 994 #undef COMPLEX128_ERROR_TWOARGS 995 #undef COMPLEX128_ERROR_THREEARGS
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)
double norm(double *v, double p, int n)
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)
void set_element(const T &p_element, index_t index)
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< float64_t > get_imag()
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
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)
const T & get_element(index_t index)
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