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 ASSERT(vector && (index>=0) && (index<vlen))
248 return vector[index];
254 ASSERT(vector && (index>=0) && (index<vlen))
255 vector[index]=p_element;
261 vector=SG_REALLOC(T, vector, vlen, n);
264 memset(&vector[vlen], 0, (n-vlen)*
sizeof(T));
286 for (int32_t i=0; i<vlen; i++)
295 for (int32_t i=0; i<vlen; i++)
316 SG_SPRINT(
"SGVector '%p' of size: %d\n", vector, vlen)
322 vector=((
SGVector*)(&orig))->vector;
344 if (other.
vlen!=vlen)
349 if (other.
vector[i]!=vector[i])
358 const char* prefix)
const
360 display_vector(vector, vlen, name, prefix);
376 for (int32_t i=0; i<n; i++)
377 SG_SPRINT(
"%s%d%s", prefix, vector[i] ? 1 : 0, i==n-1?
"" :
",")
387 for (int32_t i=0; i<n; i++)
388 SG_SPRINT(
"%s%c%s", prefix, vector[i], i==n-1?
"" :
",")
398 for (int32_t i=0; i<n; i++)
399 SG_SPRINT(
"%s%u%s", prefix, vector[i], i==n-1?
"" :
",")
409 for (int32_t i=0; i<n; i++)
410 SG_SPRINT(
"%s%d%s", prefix, vector[i], i==n-1?
"" :
",")
420 for (int32_t i=0; i<n; i++)
421 SG_SPRINT(
"%s%u%s", prefix, vector[i], i==n-1?
"" :
",")
431 for (int32_t i=0; i<n; i++)
432 SG_SPRINT(
"%s%d%s", prefix, vector[i], i==n-1?
"" :
",")
442 for (int32_t i=0; i<n; i++)
443 SG_SPRINT(
"%s%d%s", prefix, vector[i], i==n-1?
"" :
",")
453 for (int32_t i=0; i<n; i++)
454 SG_SPRINT(
"%s%u%s", prefix, vector[i], i==n-1?
"" :
",")
465 for (int32_t i=0; i<n; i++)
466 SG_SPRINT(
"%s%lld%s", prefix, vector[i], i==n-1?
"" :
",")
476 for (int32_t i=0; i<n; i++)
477 SG_SPRINT(
"%s%llu%s", prefix, vector[i], i==n-1?
"" :
",")
487 for (int32_t i=0; i<n; i++)
488 SG_SPRINT(
"%s%g%s", prefix, vector[i], i==n-1?
"" :
",")
498 for (int32_t i=0; i<n; i++)
499 SG_SPRINT(
"%s%.18g%s", prefix, vector[i], i==n-1?
"" :
",")
505 const char* name,
const char* prefix)
509 for (int32_t i=0; i<n; i++)
511 SG_SPRINT(
"%s%.36Lg%s", prefix, (
long double) vector[i],
519 const char* name,
const char* prefix)
523 for (int32_t i=0; i<n; i++)
525 SG_SPRINT(
"%s(%.36lg+i%.36lg)%s", prefix, vector[i].real(),
526 vector[i].imag(), i==n-1?
"" :
",");
533 const T scalar,
const T* vec2, int32_t n)
535 for (int32_t i=0; i<n; i++)
536 vec1[i]+=scalar*vec2[i];
545 cblas_daxpy(n, scalar, vec2, skip, vec1, skip);
547 for (int32_t i=0; i<n; i++)
548 vec1[i]+=scalar*vec2[i];
558 cblas_saxpy(n, scalar, vec2, skip, vec1, skip);
560 for (int32_t i=0; i<n; i++)
561 vec1[i]+=scalar*vec2[i];
568 for (int32_t i=0; i<len; i++)
569 vec[i]=CMath::random(min_value, max_value);
597 for (int32_t i=0; i<len; i++)
600 return CMath::sqrt(result);
607 for (int32_t i=0; i<len; i++)
610 return CMath::sqrt(result);
617 for (int32_t i=0; i<len; i++)
620 return CMath::sqrt(result);
627 for (int32_t i=0; i<len; i++)
630 return CMath::sqrt(result);
637 for (int32_t i=0; i<len; i++)
640 return CMath::sqrt(result);
647 for (int32_t i=0; i<len; i++)
650 return CMath::sqrt(result);
657 for (int32_t i=0; i<len; i++)
660 return CMath::sqrt(result);
667 for (int32_t i=0; i<len; i++)
670 return CMath::sqrt(result);
677 for (int32_t i=0; i<len; i++)
680 return CMath::sqrt(result);
688 norm = cblas_dnrm2(n, v, 1);
699 for (int32_t i=0; i<len; i++)
702 return CMath::sqrt(result);
709 for (int32_t i=0; i<len; i++)
712 return CMath::sqrt(result);
719 for (int32_t i=0;i<len; ++i)
720 result+=CMath::abs(x[i]);
730 for (int32_t i=0; i<len; i++)
731 result+=CMath::pow(fabs(x[i]), q);
748 return CMath::pow((
float64_t) qsq(x, len, q), 1.0/q);
763 for (int32_t i=0; i<len; i++)
764 result+=CMath::abs(vec[i]);
774 result = cblas_dasum(len, vec, 1);
782 result = cblas_sasum(len, vec, 1);
790 CMath::qsort<T>(output, size);
793 for (int32_t i=0; i<size; i++)
795 if (i==0 || output[i]!=output[i-1])
796 output[j++]=output[i];
805 SG_SERROR(
"SGVector::unique():: Not supported for complex128_t\n");
815 for (
index_t i=0; i < vlen; ++i)
816 if (vector[i] == elem)
825 for (int32_t i=0; i<len; i++)
833 cblas_dscal(len, alpha, vec, 1);
839 cblas_sscal(len, alpha, vec, 1);
846 scale_vector(alpha, vector, vlen);
866 SG_SERROR(
"SGVector::load():: Not supported for complex128_t\n");
881 SG_SERROR(
"SGVector::save():: Not supported for complex128_t\n");
887 for (int32_t i=0; i<vlen; i++)
888 real[i]=CMath::real(vector[i]);
895 for (int32_t i=0; i<vlen; i++)
896 imag[i]=CMath::imag(vector[i]);
904 if (nrows*ncols>vector.
size())
905 SG_SERROR(
"SGVector::convert_to_matrix():: Dimensions mismatch\n");
917 if (nrows*ncols>vlen)
918 SG_SERROR(
"SGVector::convert_to_matrix():: Dimensions mismatch\n");
922 matrix=SG_MALLOC(T, nrows*ncols);
926 for (
index_t i=0; i<ncols*nrows; i++)
931 for (
index_t i=0; i<nrows; i++)
933 for (
index_t j=0; j<ncols; j++)
934 matrix[i+j*nrows]=vector[j+i*ncols];
939 #define UNDEFINED(function, type) \
941 SGVector<float64_t> SGVector<type>::function() \
943 SG_SERROR("SGVector::%s():: Not supported for %s\n", \
945 SGVector<float64_t> ret(vlen); \
977 template class SGVector<bool>;
978 template class SGVector<char>;
979 template class SGVector<int8_t>;
980 template class SGVector<uint8_t>;
981 template class SGVector<int16_t>;
982 template class SGVector<uint16_t>;
983 template class SGVector<int32_t>;
984 template class SGVector<uint32_t>;
985 template class SGVector<int64_t>;
986 template class SGVector<uint64_t>;
987 template class SGVector<float32_t>;
988 template class SGVector<float64_t>;
989 template class SGVector<floatmax_t>;
990 template class SGVector<complex128_t>;
993 #undef COMPLEX128_ERROR_NOARG
994 #undef COMPLEX128_ERROR_ONEARG
995 #undef COMPLEX128_ERROR_TWOARGS
996 #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)
virtual void copy_data(const SGReferencedData &orig)
#define SG_SNOTIMPLEMENTED
void add(const SGVector< T > x)
template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry* vector is orde...
#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.
void set_const(float32_tconst_elem)
#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)
virtual void set_vector(const bool *vector, int32_t len)
void display_vector(const char *name="vector", const char *prefix="") const
void set(SGVector< T > orig)
SGSparseVectorEntry< T > * features