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);
191 CMath::qsort<T>(vector, vlen);
219 for (
index_t i=0; i < vlen; ++i)
230 SG_SERROR(
"SGVector::argsort():: Not supported for complex128_t\n");
241 for(int32_t i=1; i<vlen; i++)
243 if (vector[i-1] > vector[i])
253 SG_SERROR(
"SGVector::is_sorted():: Not supported for complex128_t\n");
261 for (i=0; i<vlen; ++i)
263 if (vector[i]>element)
272 SG_SERROR(
"SGVector::find_position_to_insert():: \
273 Not supported for complex128_t\n");
280 return SGVector<T>(clone_vector(vector, vlen), vlen);
286 T* result = SG_MALLOC(T, len);
287 memcpy(result, vec,
sizeof(T)*len);
294 for (int32_t i=0; i<len; i++)
301 for (int32_t i=0; i<len; i++)
309 SG_SERROR(
"SGVector::range_fill_vector():: \
310 Not supported for complex128_t\n");
316 ASSERT(vector && (index>=0) && (index<vlen))
317 return vector[index];
323 ASSERT(vector && (index>=0) && (index<vlen))
324 vector[index]=p_element;
330 vector=SG_REALLOC(T, vector, vlen, n);
333 memset(&vector[vlen], 0, (n-vlen)*
sizeof(T));
355 for (int32_t i=0; i<vlen; i++)
364 for (int32_t i=0; i<vlen; i++)
385 SG_SPRINT(
"SGVector '%p' of size: %d\n", vector, vlen)
391 vector=((
SGVector*)(&orig))->vector;
413 if (other.
vlen!=vlen)
418 if (other.
vector[i]!=vector[i])
427 const char* prefix)
const
429 display_vector(vector, vlen, name, prefix);
445 for (int32_t i=0; i<n; i++)
446 SG_SPRINT(
"%s%d%s", prefix, vector[i] ? 1 : 0, i==n-1?
"" :
",")
456 for (int32_t i=0; i<n; i++)
457 SG_SPRINT(
"%s%c%s", prefix, vector[i], i==n-1?
"" :
",")
467 for (int32_t i=0; i<n; i++)
468 SG_SPRINT(
"%s%u%s", prefix, vector[i], i==n-1?
"" :
",")
478 for (int32_t i=0; i<n; i++)
479 SG_SPRINT(
"%s%d%s", prefix, vector[i], i==n-1?
"" :
",")
489 for (int32_t i=0; i<n; i++)
490 SG_SPRINT(
"%s%u%s", prefix, vector[i], i==n-1?
"" :
",")
500 for (int32_t i=0; i<n; i++)
501 SG_SPRINT(
"%s%d%s", prefix, vector[i], i==n-1?
"" :
",")
511 for (int32_t i=0; i<n; i++)
512 SG_SPRINT(
"%s%d%s", prefix, vector[i], i==n-1?
"" :
",")
522 for (int32_t i=0; i<n; i++)
523 SG_SPRINT(
"%s%u%s", prefix, vector[i], i==n-1?
"" :
",")
534 for (int32_t i=0; i<n; i++)
535 SG_SPRINT(
"%s%lld%s", prefix, vector[i], i==n-1?
"" :
",")
545 for (int32_t i=0; i<n; i++)
546 SG_SPRINT(
"%s%llu%s", prefix, vector[i], i==n-1?
"" :
",")
556 for (int32_t i=0; i<n; i++)
557 SG_SPRINT(
"%s%g%s", prefix, vector[i], i==n-1?
"" :
",")
567 for (int32_t i=0; i<n; i++)
568 SG_SPRINT(
"%s%.18g%s", prefix, vector[i], i==n-1?
"" :
",")
574 const char* name,
const char* prefix)
578 for (int32_t i=0; i<n; i++)
580 SG_SPRINT(
"%s%.36Lg%s", prefix, (
long double) vector[i],
588 const char* name,
const char* prefix)
592 for (int32_t i=0; i<n; i++)
594 SG_SPRINT(
"%s(%.36lg+i%.36lg)%s", prefix, vector[i].real(),
595 vector[i].imag(), i==n-1?
"" :
",");
602 const T scalar,
const T* vec2, int32_t n)
604 for (int32_t i=0; i<n; i++)
605 vec1[i]+=scalar*vec2[i];
614 cblas_daxpy(n, scalar, vec2, skip, vec1, skip);
616 for (int32_t i=0; i<n; i++)
617 vec1[i]+=scalar*vec2[i];
627 cblas_saxpy(n, scalar, vec2, skip, vec1, skip);
629 for (int32_t i=0; i<n; i++)
630 vec1[i]+=scalar*vec2[i];
644 r = cblas_ddot(n, v1, skip, v2, skip);
646 for (int32_t i=0; i<n; i++)
662 r = cblas_sdot(n, v1, skip, v2, skip);
664 for (int32_t i=0; i<n; i++)
673 for (int32_t i=0; i<len; i++)
674 vec[i]=CMath::random(min_value, max_value);
702 for (int32_t i=0; i<len; i++)
705 return CMath::sqrt(result);
712 for (int32_t i=0; i<len; i++)
715 return CMath::sqrt(result);
722 for (int32_t i=0; i<len; i++)
725 return CMath::sqrt(result);
732 for (int32_t i=0; i<len; i++)
735 return CMath::sqrt(result);
742 for (int32_t i=0; i<len; i++)
745 return CMath::sqrt(result);
752 for (int32_t i=0; i<len; i++)
755 return CMath::sqrt(result);
762 for (int32_t i=0; i<len; i++)
765 return CMath::sqrt(result);
772 for (int32_t i=0; i<len; i++)
775 return CMath::sqrt(result);
782 for (int32_t i=0; i<len; i++)
785 return CMath::sqrt(result);
793 norm = cblas_dnrm2(n, v, 1);
804 for (int32_t i=0; i<len; i++)
807 return CMath::sqrt(result);
814 for (int32_t i=0; i<len; i++)
817 return CMath::sqrt(result);
824 for (int32_t i=0;i<len; ++i)
825 result+=CMath::abs(x[i]);
835 for (int32_t i=0; i<len; i++)
836 result+=CMath::pow(fabs(x[i]), q);
853 return CMath::pow((
float64_t) qsq(x, len, q), 1.0/q);
868 for (int32_t i=0; i<len; i++)
869 result+=CMath::abs(vec[i]);
879 result = cblas_dasum(len, vec, 1);
887 result = cblas_sasum(len, vec, 1);
896 return CMath::abs(x-y)<precision;
902 CMath::qsort<T>(output, size);
905 for (int32_t i=0; i<size; i++)
907 if (i==0 || output[i]!=output[i-1])
908 output[j++]=output[i];
917 SG_SERROR(
"SGVector::unique():: Not supported for complex128_t\n");
927 for (
index_t i=0; i < vlen; ++i)
928 if (vector[i] == elem)
937 for (int32_t i=0; i<len; i++)
945 cblas_dscal(len, alpha, vec, 1);
951 cblas_sscal(len, alpha, vec, 1);
958 scale_vector(alpha, vector, vlen);
978 SG_SERROR(
"SGVector::load():: Not supported for complex128_t\n");
993 SG_SERROR(
"SGVector::save():: Not supported for complex128_t\n");
999 for (int32_t i=0; i<vlen; i++)
1000 real[i]=CMath::real(vector[i]);
1007 for (int32_t i=0; i<vlen; i++)
1008 imag[i]=CMath::imag(vector[i]);
1016 if (nrows*ncols>vector.
size())
1017 SG_SERROR(
"SGVector::convert_to_matrix():: Dimensions mismatch\n");
1029 if (nrows*ncols>vlen)
1030 SG_SERROR(
"SGVector::convert_to_matrix():: Dimensions mismatch\n");
1034 matrix=SG_MALLOC(T, nrows*ncols);
1038 for (
index_t i=0; i<ncols*nrows; i++)
1039 matrix[i]=vector[i];
1043 for (
index_t i=0; i<nrows; i++)
1045 for (
index_t j=0; j<ncols; j++)
1046 matrix[i+j*nrows]=vector[j+i*ncols];
1051 #define UNDEFINED(function, type) \
1053 SGVector<float64_t> SGVector<type>::function() \
1055 SG_SERROR("SGVector::%s():: Not supported for %s\n", \
1056 #function, #type); \
1057 SGVector<float64_t> ret(vlen); \
1089 template class SGVector<bool>;
1090 template class SGVector<char>;
1091 template class SGVector<int8_t>;
1092 template class SGVector<uint8_t>;
1093 template class SGVector<int16_t>;
1094 template class SGVector<uint16_t>;
1095 template class SGVector<int32_t>;
1096 template class SGVector<uint32_t>;
1097 template class SGVector<int64_t>;
1098 template class SGVector<uint64_t>;
1099 template class SGVector<float32_t>;
1100 template class SGVector<float64_t>;
1101 template class SGVector<floatmax_t>;
1102 template class SGVector<complex128_t>;
1105 #undef COMPLEX128_ERROR_NOARG
1106 #undef COMPLEX128_ERROR_ONEARG
1107 #undef COMPLEX128_ERROR_TWOARGS
1108 #undef COMPLEX128_ERROR_THREEARGS
double norm(double *v, double p, int n)
IndexSorter(const SGVector< T > *vec)
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
static const float64_t epsilon
#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)
#define COMPLEX128_ERROR_NOARG(function)
virtual void set_vector(const bool *vector, int32_t len)
void set_const(float32_tconst_elem)
void add(const SGVector< T > x)