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",\
153 vector[i]=const_elem ;
160 catlas_dset(vlen, const_elem, vector, 1);
166 catlas_sset(vlen, const_elem, vector, 1);
168 #endif // HAVE_CATLAS
173 range_fill_vector(vector, vlen, start);
181 random_vector(vector, vlen, min_value, max_value);
190 for (i=0; i<vlen; ++i)
192 if (vector[i]>element)
201 SG_SERROR(
"SGVector::find_position_to_insert():: \
202 Not supported for complex128_t\n");
209 return SGVector<T>(clone_vector(vector, vlen), vlen);
215 T* result = SG_MALLOC(T, len);
216 memcpy(result, vec,
sizeof(T)*len);
223 for (int32_t i=0; i<len; i++)
230 for (int32_t i=0; i<len; i++)
238 SG_SERROR(
"SGVector::range_fill_vector():: \
239 Not supported for complex128_t\n");
245 REQUIRE(vector && (index>=0) && (index<vlen),
"Provided index (%d) must be between 0 and %d.\n", index, vlen);
246 return vector[index];
252 REQUIRE(vector && (index>=0) && (index<vlen),
"Provided index (%d) must be between 0 and %d.\n", index, vlen);
253 vector[index]=p_element;
259 vector=SG_REALLOC(T, vector, vlen, n);
262 memset(&vector[vlen], 0, (n-vlen)*
sizeof(T));
270 REQUIRE(x.
vector && vector,
"Addition possible for only non-null vectors.\n");
271 REQUIRE(x.
vlen == vlen,
"Length of the two vectors to be added should be same. [V(%d) + V(%d)]\n", vlen, x.
vlen);
281 REQUIRE(x.
vector && vector,
"Addition possible for only non-null vectors.\n");
282 REQUIRE(x.
vlen == vlen,
"Length of the two vectors to be added should be same. [V(%d) + V(%d)]\n", vlen, x.
vlen);
284 for (int32_t i=0; i<vlen; i++)
291 REQUIRE(vector,
"Addition possible for only non-null vectors.\n");
292 for (int32_t i=0; i<vlen; i++)
304 REQUIRE(idx < vlen,
"Feature index should be less than %d.\n", vlen);
313 SG_SPRINT(
"SGVector '%p' of size: %d\n", vector, vlen)
319 vector=((
SGVector*)(&orig))->vector;
341 if (other.
vlen!=vlen)
346 if (other.
vector[i]!=vector[i])
355 const char* prefix)
const
357 display_vector(vector, vlen, name, prefix);
371 REQUIRE(n>=0,
"Vector size can not be negative.\n");
373 for (int32_t i=0; i<n; i++)
374 SG_SPRINT(
"%s%d%s", prefix, vector[i] ? 1 : 0, i==n-1?
"" :
",")
382 REQUIRE(n>=0,
"Vector size can not be negative.\n");
384 for (int32_t i=0; i<n; i++)
385 SG_SPRINT(
"%s%c%s", prefix, vector[i], i==n-1?
"" :
",")
393 REQUIRE(n>=0,
"Vector size can not be negative.\n");
395 for (int32_t i=0; i<n; i++)
396 SG_SPRINT(
"%s%u%s", prefix, vector[i], i==n-1?
"" :
",")
404 REQUIRE(n>=0,
"Vector size can not be negative.\n");
406 for (int32_t i=0; i<n; i++)
407 SG_SPRINT(
"%s%d%s", prefix, vector[i], i==n-1?
"" :
",")
415 REQUIRE(n>=0,
"Vector size can not be negative.\n");
417 for (int32_t i=0; i<n; i++)
418 SG_SPRINT(
"%s%u%s", prefix, vector[i], i==n-1?
"" :
",")
426 REQUIRE(n>=0,
"Vector size can not be negative.\n");
428 for (int32_t i=0; i<n; i++)
429 SG_SPRINT(
"%s%d%s", prefix, vector[i], i==n-1?
"" :
",")
437 REQUIRE(n>=0,
"Vector size can not be negative.\n");
439 for (int32_t i=0; i<n; i++)
440 SG_SPRINT(
"%s%d%s", prefix, vector[i], i==n-1?
"" :
",")
448 REQUIRE(n>=0,
"Vector size can not be negative.\n");
450 for (int32_t i=0; i<n; i++)
451 SG_SPRINT(
"%s%u%s", prefix, vector[i], i==n-1?
"" :
",")
460 REQUIRE(n>=0,
"Vector size can not be negative.\n");
462 for (int32_t i=0; i<n; i++)
463 SG_SPRINT(
"%s%lld%s", prefix, vector[i], i==n-1?
"" :
",")
471 REQUIRE(n>=0,
"Vector size can not be negative.\n");
473 for (int32_t i=0; i<n; i++)
474 SG_SPRINT(
"%s%llu%s", prefix, vector[i], i==n-1?
"" :
",")
482 REQUIRE(n>=0,
"Vector size can not be negative.\n");
484 for (int32_t i=0; i<n; i++)
485 SG_SPRINT(
"%s%g%s", prefix, vector[i], i==n-1?
"" :
",")
493 REQUIRE(n>=0,
"Vector size can not be negative.\n");
495 for (int32_t i=0; i<n; i++)
496 SG_SPRINT(
"%s%.18g%s", prefix, vector[i], i==n-1?
"" :
",")
502 const char* name,
const char* prefix)
504 REQUIRE(n>=0,
"Vector size can not be negative.\n");
506 for (int32_t i=0; i<n; i++)
508 SG_SPRINT(
"%s%.36Lg%s", prefix, (
long double) vector[i],
516 const char* name,
const char* prefix)
518 REQUIRE(n>=0,
"Vector size can not be negative.\n");
520 for (int32_t i=0; i<n; i++)
522 SG_SPRINT(
"%s(%.36lg+i%.36lg)%s", prefix, vector[i].real(),
523 vector[i].imag(), i==n-1?
"" :
",");
530 const T scalar,
const T* vec2, int32_t n)
532 for (int32_t i=0; i<n; i++)
533 vec1[i]+=scalar*vec2[i];
542 cblas_daxpy(n, scalar, vec2, skip, vec1, skip);
544 for (int32_t i=0; i<n; i++)
545 vec1[i]+=scalar*vec2[i];
555 cblas_saxpy(n, scalar, vec2, skip, vec1, skip);
557 for (int32_t i=0; i<n; i++)
558 vec1[i]+=scalar*vec2[i];
565 for (int32_t i=0; i<len; i++)
566 vec[i]=CMath::random(min_value, max_value);
594 for (int32_t i=0; i<len; i++)
597 return CMath::sqrt(result);
604 for (int32_t i=0; i<len; i++)
607 return CMath::sqrt(result);
614 for (int32_t i=0; i<len; i++)
617 return CMath::sqrt(result);
624 for (int32_t i=0; i<len; i++)
627 return CMath::sqrt(result);
634 for (int32_t i=0; i<len; i++)
637 return CMath::sqrt(result);
644 for (int32_t i=0; i<len; i++)
647 return CMath::sqrt(result);
654 for (int32_t i=0; i<len; i++)
657 return CMath::sqrt(result);
664 for (int32_t i=0; i<len; i++)
667 return CMath::sqrt(result);
674 for (int32_t i=0; i<len; i++)
677 return CMath::sqrt(result);
685 norm = cblas_dnrm2(n, v, 1);
696 for (int32_t i=0; i<len; i++)
699 return CMath::sqrt(result);
706 for (int32_t i=0; i<len; i++)
709 return CMath::sqrt(result);
716 for (int32_t i=0;i<len; ++i)
717 result+=CMath::abs(x[i]);
727 for (int32_t i=0; i<len; i++)
728 result+=CMath::pow(fabs(x[i]), q);
744 REQUIRE(q!=0,
"Q should be non-zero for calculating qnorm\n");
745 return CMath::pow((
float64_t) qsq(x, len, q), 1.0/q);
760 for (int32_t i=0; i<len; i++)
761 result+=CMath::abs(vec[i]);
771 result = cblas_dasum(len, vec, 1);
779 result = cblas_sasum(len, vec, 1);
787 CMath::qsort<T>(output, size);
790 for (int32_t i=0; i<size; i++)
792 if (i==0 || output[i]!=output[i-1])
793 output[j++]=output[i];
802 SG_SERROR(
"SGVector::unique():: Not supported for complex128_t\n");
812 for (
index_t i=0; i < vlen; ++i)
813 if (vector[i] == elem)
822 for (int32_t i=0; i<len; i++)
830 cblas_dscal(len, alpha, vec, 1);
836 cblas_sscal(len, alpha, vec, 1);
843 scale_vector(alpha, vector, vlen);
848 REQUIRE(loader,
"Require a valid 'c FILE pointer'\n");
863 SG_SERROR(
"SGVector::load():: Not supported for complex128_t\n");
868 REQUIRE(saver,
"Requires a valid 'c FILE pointer'\n");
878 SG_SERROR(
"SGVector::save():: Not supported for complex128_t\n");
884 for (int32_t i=0; i<vlen; i++)
885 real[i]=CMath::real(vector[i]);
892 for (int32_t i=0; i<vlen; i++)
893 imag[i]=CMath::imag(vector[i]);
901 if (nrows*ncols>vector.
size())
902 SG_SERROR(
"SGVector::convert_to_matrix():: Dimensions mismatch\n");
914 if (nrows*ncols>vlen)
915 SG_SERROR(
"SGVector::convert_to_matrix():: Dimensions mismatch\n");
919 matrix=SG_MALLOC(T, nrows*ncols);
923 for (
index_t i=0; i<ncols*nrows; i++)
928 for (
index_t i=0; i<nrows; i++)
930 for (
index_t j=0; j<ncols; j++)
931 matrix[i+j*nrows]=vector[j+i*ncols];
936 #define UNDEFINED(function, type) \
938 SGVector<float64_t> SGVector<type>::function() \
940 SG_SERROR("SGVector::%s():: Not supported for %s\n", \
942 SGVector<float64_t> ret(vlen); \
974 template class SGVector<bool>;
975 template class SGVector<char>;
976 template class SGVector<int8_t>;
977 template class SGVector<uint8_t>;
978 template class SGVector<int16_t>;
979 template class SGVector<uint16_t>;
980 template class SGVector<int32_t>;
981 template class SGVector<uint32_t>;
982 template class SGVector<int64_t>;
983 template class SGVector<uint64_t>;
984 template class SGVector<float32_t>;
985 template class SGVector<float64_t>;
986 template class SGVector<floatmax_t>;
987 template class SGVector<complex128_t>;
990 #undef COMPLEX128_ERROR_NOARG
991 #undef COMPLEX128_ERROR_ONEARG
992 #undef COMPLEX128_ERROR_TWOARGS
993 #undef COMPLEX128_ERROR_THREEARGS
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 range_fill(Matrix A, typename Matrix::Scalar start=0.0)
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)