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",\
155 vector[i]=const_elem ;
162 catlas_dset(vlen, const_elem, vector, 1);
168 catlas_sset(vlen, const_elem, vector, 1);
170 #endif // HAVE_CATLAS
175 range_fill_vector(vector, vlen, start);
183 random_vector(vector, vlen, min_value, max_value);
192 for (i=0; i<vlen; ++i)
194 if (vector[i]>element)
203 SG_SERROR(
"SGVector::find_position_to_insert():: \
204 Not supported for complex128_t\n");
211 return SGVector<T>(clone_vector(vector, vlen), vlen);
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);
248 return vector[index];
254 REQUIRE(vector && (index>=0) && (index<vlen),
"Provided index (%d) must be between 0 and %d.\n", index, vlen);
255 vector[index]=p_element;
261 vector=SG_REALLOC(T, vector, vlen, n);
264 memset(&vector[vlen], 0, (n-vlen)*
sizeof(T));
272 REQUIRE(x.
vector && vector,
"Addition possible for only non-null vectors.\n");
273 REQUIRE(x.
vlen == vlen,
"Length of the two vectors to be added should be same. [V(%d) + V(%d)]\n", vlen, x.
vlen);
283 REQUIRE(x.
vector && vector,
"Addition possible for only non-null vectors.\n");
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++)
306 REQUIRE(idx < vlen,
"Feature index should be less than %d.\n", vlen);
315 SG_SPRINT(
"SGVector '%p' of size: %d\n", vector, vlen)
321 vector=((
SGVector*)(&orig))->vector;
343 if (other.
vlen!=vlen)
348 if (other.
vector[i]!=vector[i])
357 const char* prefix)
const
359 display_vector(vector, vlen, name, prefix);
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++)
568 vec[i]=CMath::random(min_value, max_value);
596 for (int32_t i=0; i<len; i++)
599 return CMath::sqrt(result);
606 for (int32_t i=0; i<len; i++)
609 return CMath::sqrt(result);
616 for (int32_t i=0; i<len; i++)
619 return CMath::sqrt(result);
626 for (int32_t i=0; i<len; i++)
629 return CMath::sqrt(result);
636 for (int32_t i=0; i<len; i++)
639 return CMath::sqrt(result);
646 for (int32_t i=0; i<len; i++)
649 return CMath::sqrt(result);
656 for (int32_t i=0; i<len; i++)
659 return CMath::sqrt(result);
666 for (int32_t i=0; i<len; i++)
669 return CMath::sqrt(result);
676 for (int32_t i=0; i<len; i++)
679 return CMath::sqrt(result);
687 norm = cblas_dnrm2(n, v, 1);
698 for (int32_t i=0; i<len; i++)
701 return CMath::sqrt(result);
708 for (int32_t i=0; i<len; i++)
711 return CMath::sqrt(result);
718 for (int32_t i=0;i<len; ++i)
719 result+=CMath::abs(x[i]);
729 for (int32_t i=0; i<len; i++)
730 result+=CMath::pow(fabs(x[i]), q);
746 REQUIRE(q!=0,
"Q should be non-zero for calculating qnorm\n");
747 return CMath::pow((
float64_t) qsq(x, len, q), 1.0/q);
762 for (int32_t i=0; i<len; i++)
763 result+=CMath::abs(vec[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");
814 for (
index_t i=0; i < vlen; ++i)
815 if (vector[i] == elem)
824 for (int32_t i=0; i<len; i++)
832 cblas_dscal(len, alpha, vec, 1);
838 cblas_sscal(len, alpha, vec, 1);
845 scale_vector(alpha, vector, vlen);
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++)
887 real[i]=CMath::real(vector[i]);
894 for (int32_t i=0; i<vlen; i++)
895 imag[i]=CMath::imag(vector[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
double norm(double *v, double p, int n)
std::complex< float64_t > complex128_t
Vector::Scalar dot(Vector a, Vector b)
#define COMPLEX128_ERROR_TWOARGS(function)
void set(SGVector< T > orig)
#define SG_SNOTIMPLEMENTED
void display_vector(const char *name="vector", const char *prefix="") const
#define UNDEFINED(function, type)
virtual void get_vector(bool *&vector, int32_t &len)
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
A File access base class.
SGSparseVectorEntry< T > * features
#define COMPLEX128_ERROR_ONEARG(function)
all of classes and functions are contained in the shogun namespace
void scale(Matrix A, Matrix B, typename Matrix::Scalar alpha)
template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry* vector is orde...
virtual void copy_data(const SGReferencedData &orig)
virtual void set_vector(const bool *vector, int32_t len)
void set_const(float32_tconst_elem)
void add(const SGVector< T > x)