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",\ 142 #endif // HAVE_CATLAS 186 return data[i] < data[j];
209 SG_SERROR(
"SGVector::argsort():: Not supported for complex128_t\n");
220 for(int32_t i=1; i<
vlen; i++)
232 SG_SERROR(
"SGVector::is_sorted():: Not supported for complex128_t\n");
240 for (i=0; i<
vlen; ++i)
251 SG_SERROR(
"SGVector::find_position_to_insert():: \ 252 Not supported for complex128_t\n");
265 T* result = SG_MALLOC(T, len);
266 memcpy(result, vec,
sizeof(T)*len);
273 for (int32_t i=0; i<len; i++)
280 for (int32_t i=0; i<len; i++)
288 SG_SERROR(
"SGVector::range_fill_vector():: \ 289 Not supported for complex128_t\n");
334 for (int32_t i=0; i<
vlen; i++)
343 for (int32_t i=0; i<
vlen; i++)
406 const char* prefix)
const 424 for (int32_t i=0; i<n; i++)
425 SG_SPRINT(
"%s%d%s", prefix, vector[i] ? 1 : 0, i==n-1?
"" :
",")
435 for (int32_t i=0; i<n; i++)
436 SG_SPRINT(
"%s%c%s", prefix, vector[i], i==n-1?
"" :
",")
446 for (int32_t i=0; i<n; i++)
447 SG_SPRINT(
"%s%u%s", prefix, vector[i], i==n-1?
"" :
",")
457 for (int32_t i=0; i<n; i++)
458 SG_SPRINT(
"%s%d%s", prefix, vector[i], i==n-1?
"" :
",")
468 for (int32_t i=0; i<n; i++)
469 SG_SPRINT(
"%s%u%s", prefix, vector[i], i==n-1?
"" :
",")
479 for (int32_t i=0; i<n; i++)
480 SG_SPRINT(
"%s%d%s", prefix, vector[i], i==n-1?
"" :
",")
490 for (int32_t i=0; i<n; i++)
491 SG_SPRINT(
"%s%d%s", prefix, vector[i], i==n-1?
"" :
",")
501 for (int32_t i=0; i<n; i++)
502 SG_SPRINT(
"%s%u%s", prefix, vector[i], i==n-1?
"" :
",")
513 for (int32_t i=0; i<n; i++)
514 SG_SPRINT(
"%s%lld%s", prefix, vector[i], i==n-1?
"" :
",")
524 for (int32_t i=0; i<n; i++)
525 SG_SPRINT(
"%s%llu%s", prefix, vector[i], i==n-1?
"" :
",")
535 for (int32_t i=0; i<n; i++)
536 SG_SPRINT(
"%s%g%s", prefix, vector[i], i==n-1?
"" :
",")
546 for (int32_t i=0; i<n; i++)
547 SG_SPRINT(
"%s%.18g%s", prefix, vector[i], i==n-1?
"" :
",")
553 const char* name,
const char* prefix)
557 for (int32_t i=0; i<n; i++)
559 SG_SPRINT(
"%s%.36Lg%s", prefix, (
long double) vector[i],
567 const char* name,
const char* prefix)
571 for (int32_t i=0; i<n; i++)
573 SG_SPRINT(
"%s(%.36lg+i%.36lg)%s", prefix, vector[i].real(),
574 vector[i].imag(), i==n-1?
"" :
",");
581 const T scalar,
const T* vec2, int32_t n)
583 for (int32_t i=0; i<n; i++)
584 vec1[i]+=scalar*vec2[i];
593 cblas_daxpy(n, scalar, vec2, skip, vec1, skip);
595 for (int32_t i=0; i<n; i++)
596 vec1[i]+=scalar*vec2[i];
606 cblas_saxpy(n, scalar, vec2, skip, vec1, skip);
608 for (int32_t i=0; i<n; i++)
609 vec1[i]+=scalar*vec2[i];
618 Eigen::Map<const Eigen::VectorXd> ev1(v1,n);
619 Eigen::Map<const Eigen::VectorXd> ev2(v2,n);
623 r = cblas_ddot(n, v1, skip, v2, skip);
625 for (int32_t i=0; i<n; i++)
636 Eigen::Map<const Eigen::VectorXf> ev1(v1,n);
637 Eigen::Map<const Eigen::VectorXf> ev2(v2,n);
641 r = cblas_sdot(n, v1, skip, v2, skip);
643 for (int32_t i=0; i<n; i++)
652 for (int32_t i=0; i<len; i++)
680 T* perm = SG_MALLOC(T, n);
697 for (int32_t i = 0; i < n; i++)
712 for (int32_t i = 0; i < n; i++)
719 for (int32_t i = 0; i < n; i++)
763 for (int32_t i=0; i<len; i++)
773 for (int32_t i=0; i<len; i++)
783 for (int32_t i=0; i<len; i++)
793 for (int32_t i=0; i<len; i++)
803 for (int32_t i=0; i<len; i++)
813 for (int32_t i=0; i<len; i++)
823 for (int32_t i=0; i<len; i++)
833 for (int32_t i=0; i<len; i++)
843 for (int32_t i=0; i<len; i++)
854 norm = cblas_dnrm2(n, v, 1);
865 for (int32_t i=0; i<len; i++)
875 for (int32_t i=0; i<len; i++)
885 for (int32_t i=0;i<len; ++i)
896 for (int32_t i=0; i<len; i++)
931 for (int32_t i=1; i<len; i++)
943 int32_t idx = cblas_idamax(len, vec, skip);
953 int32_t idx = cblas_isamax(len, vec, skip);
966 for (int32_t i=1; i<len; i++)
986 for (int32_t i=1; i<len; i++)
997 int32_t idx = cblas_idamax(len, vec, inc);
999 if (maxv_ptr != NULL)
1009 int32_t idx = cblas_isamax(len, vec, inc);
1011 if (maxv_ptr != NULL)
1021 ASSERT(len > 0 || inc > 0)
1026 for (int32_t i = 1, j = inc ; i < len ; i++, j += inc)
1032 if (maxv_ptr != NULL)
1043 SG_SERROR(
"SGVector::arg_max_abs():: Not supported for complex128_t\n");
1050 ASSERT(len > 0 || inc > 0)
1055 for (int32_t i = 1, j = inc ; i < len ; i++, j += inc)
1058 maxv = vec[j], maxIdx = i;
1061 if (maxv_ptr != NULL)
1072 SG_SERROR(
"SGVector::arg_max():: Not supported for complex128_t\n");
1081 ASSERT(len > 0 || inc > 0)
1086 for (int32_t i = 1, j = inc ; i < len ; i++, j += inc)
1089 minv = vec[j], minIdx = i;
1092 if (minv_ptr != NULL)
1103 SG_SERROR(
"SGVector::arg_min():: Not supported for complex128_t\n");
1112 for (int32_t i=0; i<len; i++)
1123 result = cblas_dasum(len, vec, 1);
1131 result = cblas_sasum(len, vec, 1);
1146 CMath::qsort<T>(output,
size);
1149 for (int32_t i=0; i<
size; i++)
1151 if (i==0 || output[i]!=output[i-1])
1152 output[j++]=output[i];
1161 SG_SERROR(
"SGVector::unique():: Not supported for complex128_t\n");
1181 for (int32_t i=0; i<len; i++)
1189 cblas_dscal(len, alpha, vec, 1);
1195 cblas_sscal(len, alpha, vec, 1);
1239 SG_SERROR(
"SGVector::load():: Not supported for complex128_t\n");
1254 SG_SERROR(
"SGVector::save():: Not supported for complex128_t\n");
1258 #define MATHOP(op) \ 1259 template <class T> void SGVector<T>::op() \ 1261 for (int32_t i=0; i<vlen; i++) \ 1262 vector[i]=(T) CMath::op((double) vector[i]); \ 1281 #define COMPLEX128_MATHOP(op) \ 1283 void SGVector<complex128_t>::op() \ 1285 for (int32_t i=0; i<vlen; i++) \ 1286 vector[i]=complex128_t(CMath::op(vector[i])); \ 1300 #undef COMPLEX128_MATHOP 1302 #define COMPLEX128_MATHOP_NOTIMPLEMENTED(op) \ 1304 void SGVector<complex128_t>::op() \ 1306 SG_SERROR("SGVector::%s():: Not supported for complex128_t\n",#op);\ 1312 #undef COMPLEX128_MATHOP_NOTIMPLEMENTED 1316 for (int32_t i=0; i<
vlen; i++)
1325 for (int32_t i=0; i<
vlen; i++)
1348 SG_SERROR(
"SGVector::linspace():: Not supported for complex128_t\n");
1355 for (int32_t i=0; i<
vlen; i++)
1362 for (int32_t i=0; i<
vlen; i++)
1370 for (int32_t i=0; i<
vlen; i++)
1379 if (nrows*ncols>vector.
size())
1380 SG_SERROR(
"SGVector::convert_to_matrix():: Dimensions mismatch\n");
1392 if (nrows*ncols>vlen)
1393 SG_SERROR(
"SGVector::convert_to_matrix():: Dimensions mismatch\n");
1397 matrix=SG_MALLOC(T, nrows*ncols);
1401 for (
index_t i=0; i<ncols*nrows; i++)
1402 matrix[i]=vector[i];
1406 for (
index_t i=0; i<nrows; i++)
1408 for (
index_t j=0; j<ncols; j++)
1409 matrix[i+j*nrows]=vector[j+i*ncols];
1414 #define UNDEFINED(function, type) \ 1416 SGVector<float64_t> SGVector<type>::function() \ 1418 SG_SERROR("SGVector::%s():: Not supported for %s\n", \ 1419 #function, #type); \ 1420 SGVector<float64_t> ret(vlen); \ 1452 template class SGVector<bool>;
1453 template class SGVector<char>;
1454 template class SGVector<int8_t>;
1455 template class SGVector<uint8_t>;
1456 template class SGVector<int16_t>;
1457 template class SGVector<uint16_t>;
1458 template class SGVector<int32_t>;
1459 template class SGVector<uint32_t>;
1460 template class SGVector<int64_t>;
1461 template class SGVector<uint64_t>;
1462 template class SGVector<float32_t>;
1463 template class SGVector<float64_t>;
1464 template class SGVector<floatmax_t>;
1465 template class SGVector<complex128_t>;
1468 #undef COMPLEX128_ERROR_NOARG 1469 #undef COMPLEX128_ERROR_ONEARG 1470 #undef COMPLEX128_ERROR_TWOARGS 1471 #undef COMPLEX128_ERROR_THREEARGS #define BOOL_ERROR_ONEARG(function)
static SGVector< float64_t > linspace_vec(T start, T end, int32_t n)
void cosh()
hyperbolic cosine of vector elements
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)
static float64_t dot(const bool *v1, const bool *v2, int32_t n)
compute dot product between v1 and v2 (blas optimized)
SGVector< T > operator+(SGVector< T > x)
double norm(double *v, double p, int n)
IndexSorter(const SGVector< T > *vec)
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
uint64_t random(uint64_t min_value, uint64_t max_value)
static T * clone_vector(const T *vec, int32_t len)
static void linspace(float64_t *output, float64_t start, float64_t end, int32_t n=100)
#define COMPLEX128_ERROR_TWOARGS(function)
void atan2(T x)
atan2 of vector elements
static T max(T *vec, int32_t len)
void log()
natural logarithm of vector elements
virtual void copy_data(const SGReferencedData &orig)
static bool fequal(T x, T y, float64_t precision=1e-6)
return sum(abs(vec))
void set_element(const T &p_element, index_t index)
void exp()
exponential of vector elements
void cos()
cosine of vector elements
static int32_t arg_max(T *vec, int32_t inc, int32_t len, T *maxv_ptr=NULL)
return arg_max(vec)
void tanh()
hyperbolic tangent of vector elements
void random(T min_value, T max_value)
void sqrt()
square root of vector elements
#define SG_SNOTIMPLEMENTED
void tan()
tangent of vector elements
static float64_t onenorm(T *x, int32_t len)
|| x ||_1
void acos()
arc cosine of vector elements
void add(const SGVector< T > x)
static float64_t imag(complex128_t c)
returns imag part of a complex128_t number
static float64_t real(complex128_t c)
returns real part of a complex128_t number
static int32_t arg_max_abs(T *vec, int32_t inc, int32_t len, T *maxv_ptr=NULL)
return arg_max_abs(vec)
template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry<T>* vector is orde...
static void permute_vector(SGVector< T > vec)
void scale(T alpha)
scale vector inplace
static SGVector< T > randperm_vec(int32_t n)
#define UNDEFINED(function, type)
void atan()
arc tangent of vector elements
void copy_refcount(const SGReferencedData &orig)
virtual void get_vector(bool *&vector, int32_t &len)
static T min(T *vec, int32_t len)
shogun reference count managed data
static T max_abs(T *vec, int32_t len)
void sinh()
hyperbolic sine of vector elements
A File access base class.
void range_fill(T start=0)
void sin()
sine of vector elements
static T max(T a, T b)
return the maximum of two integers
SGVector< T > clone() const
static void fill_vector(T *vec, int32_t len, T value)
static void scale_vector(T alpha, T *vec, int32_t len)
scale vector inplace
static float64_t atan2(float64_t x, float64_t y)
atan(x), x being a complex128_t not implemented
void set_const(T const_elem)
: Pseudo random number geneartor
void asin()
arc sine of vector elements
#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 log10()
common logarithm of vector elements
static T min(T a, T b)
return the minimum of two integers
void display_size() const
SGVector< index_t > find(T elem)
static T qnorm(T *x, int32_t len, float64_t q)
|| x ||_q
void pow(T q)
power of vector elements
#define COMPLEX128_ERROR_NOARG(function)
static void swap(T &a, T &b)
swap e.g. floats a and b
void resize_vector(int32_t n)
virtual void set_vector(const bool *vector, int32_t len)
#define COMPLEX128_MATHOP(op)
#define COMPLEX128_MATHOP_NOTIMPLEMENTED(op)
SGVector< index_t > argsort()
static float64_t * linspace(T start, T end, int32_t n)
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)
x^0.5
void abs()
absolute value of vector elements
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 int32_t arg_min(T *vec, int32_t inc, int32_t len, T *minv_ptr=NULL)
return arg_min(vec)
static void vec1_plus_scalar_times_vec2(T *vec1, const T scalar, const T *vec2, int32_t n)
x=x+alpha*y
static T abs(T a)
return the absolute value of a number
static T twonorm(const T *x, int32_t len)
|| x ||_2
SGSparseVectorEntry< T > * features