20 #ifndef __MATHEMATICS_H_ 21 #define __MATHEMATICS_H_ 23 #include <shogun/lib/config.h> 31 #ifndef _USE_MATH_DEFINES 32 #define _USE_MATH_DEFINES 51 #define cygwin_log2 log2 56 #define M_PI 3.14159265358979323846 65 #define isfinite _isfinite 70 #define RNG_SEED_SIZE 256 73 #define RADIX_STACK_SIZE 512 76 #define radix_push(a, n, i) sp->sa = a, sp->sn = n, (sp++)->si = i 77 #define radix_pop(a, n, i) a = (--sp)->sa, n = sp->sn, i = sp->si 79 #ifndef DOXYGEN_SHOULD_SKIP_THIS 81 template <
class T>
struct radix_stack_t
92 template <
class T1,
class T2>
struct thread_qsort
102 int32_t* qsort_threads;
108 #endif // DOXYGEN_SHOULD_SKIP_THIS 110 #define COMPLEX128_ERROR_ONEARG(function) \ 111 static inline complex128_t function(complex128_t a) \ 113 SG_SERROR("CMath::%s():: Not supported for complex128_t\n",\ 115 return complex128_t(0.0, 0.0); \ 118 #define COMPLEX128_STDMATH(function) \ 119 static inline complex128_t function(complex128_t a) \ 121 return std::function(a); \ 153 static inline T
min(T a, T b)
155 return (a<=b) ? a : b;
164 static inline T
max(T a, T b)
166 return (a>=b) ? a : b;
195 return (CMath::sqrt(a_real*a_real+a_imag*a_imag));
205 static T
min(T* vec, int32_t len)
210 for (int32_t i=1; i<len; i++)
211 minv=min(vec[i], minv);
222 static T
max(T* vec, int32_t len)
227 for (int32_t i=1; i<len; i++)
228 maxv=
max(vec[i], maxv);
240 static inline T
clamp(T value, T lb, T ub)
258 static int32_t
arg_max(T * vec, int32_t inc, int32_t len, T * maxv_ptr = NULL)
260 ASSERT(len > 0 || inc > 0)
265 for (int32_t i = 1, j = inc ; i < len ; i++, j += inc)
268 maxv = vec[j], maxIdx = i;
271 if (maxv_ptr != NULL)
285 static int32_t
arg_min(T * vec, int32_t inc, int32_t len, T * minv_ptr = NULL)
287 ASSERT(len > 0 || inc > 0)
292 for (int32_t i = 1, j = inc ; i < len ; i++, j += inc)
295 minv = vec[j], minIdx = i;
298 if (minv_ptr != NULL)
317 const T diff = CMath::abs<T>((a-b));
331 static inline bool fequals(
const T& a,
const T& b,
332 const float64_t eps,
bool tolerant=
false)
334 const T absA = CMath::abs<T>(a);
335 const T absB = CMath::abs<T>(b);
336 const T diff = CMath::abs<T>((a-b));
345 return CMath::fequals_abs<T>(a, b, eps);
349 comp = CMath::F_MIN_NORM_VAL32;
352 comp = CMath::F_MIN_NORM_VAL64;
358 else if ((a == 0) || (b == 0) || (diff < comp))
359 return (diff < (eps * comp));
363 T check = ((diff/(absA + absB)) > diff)?
364 (diff/(absA + absB)):diff;
365 return (check < eps);
395 return ::floor(d+0.5);
425 else return (a<0) ? (-1) : (+1);
433 static inline void swap(T &a,T &b)
445 static inline T
sq(T x)
504 tmp.i = 0x5f3759d5 - (tmp.i >> 1);
506 x = x*(1.5f - xhalf*x*x);
524 return ::powl((
long double) x, (
long double) n);
526 return ::pow((
double) x, (
double) n);
530 static inline int32_t
pow(
bool x, int32_t n)
539 static inline int32_t
pow(int32_t x, int32_t n)
564 return ::pow((
double)x, (
double)n);
573 return ::pow((
double) x, (
double) n);
582 return std::pow(x, n);
591 return std::pow(x, n);
600 return std::pow(x, n);
609 return std::pow(x, n);
618 return ::exp((
double) x);
625 for (int32_t i=0; i<n; i++)
626 r+=((v1[i]) ? 1 : 0) * ((v2[i]) ? 1 : 0);
634 for (int32_t i=0; i<n; i++)
648 const uint64_t* v1,
const uint64_t* v2, int32_t n)
651 for (int32_t i=0; i<n; i++)
658 const int64_t* v1,
const int64_t* v2, int32_t n)
661 for (int32_t i=0; i<n; i++)
669 const int32_t* v1,
const int32_t* v2, int32_t n)
672 for (int32_t i=0; i<n; i++)
680 const uint32_t* v1,
const uint32_t* v2, int32_t n)
683 for (int32_t i=0; i<n; i++)
691 const uint16_t* v1,
const uint16_t* v2, int32_t n)
694 for (int32_t i=0; i<n; i++)
702 const int16_t* v1,
const int16_t* v2, int32_t n)
705 for (int32_t i=0; i<n; i++)
713 const char* v1,
const char* v2, int32_t n)
716 for (int32_t i=0; i<n; i++)
724 const uint8_t* v1,
const uint8_t* v2, int32_t n)
727 for (int32_t i=0; i<n; i++)
735 const int8_t* v1,
const int8_t* v2, int32_t n)
738 for (int32_t i=0; i<n; i++)
746 const float64_t* v1,
const char* v2, int32_t n)
749 for (int32_t i=0; i<n; i++)
768 return ::tan((
double) x);
780 return ::atan((
double) x);
793 return ::atan2((
double) y, (
double) x);
805 return ::tanh((
double) x);
894 return ::log(v)/::log(10.0);
909 return ::log(v)/::log(2.0);
928 for (i = 0; n != 0; i++)
949 for (
int i=1; i<len; i++)
950 area += 0.5*(xy[2*i]-xy[2*(i-1)])*(xy[2*i+1]+xy[2*(i-1)+1]);
954 for (
int i=1; i<len; i++)
955 area += 0.5*(xy[2*i+1]-xy[2*(i-1)+1])*(xy[2*i]+xy[2*(i-1)]);
966 static bool strtof(
const char* str,
float32_t* float_result);
973 static bool strtod(
const char* str,
float64_t* double_result);
980 static bool strtold(
const char* str,
floatmax_t* long_double_result);
989 for (
int i=2; i<=n; i++)
1004 seed = CRandom::generate_seed();
1022 static inline uint64_t
random(uint64_t min_value, uint64_t max_value)
1032 static inline int64_t
random(int64_t min_value, int64_t max_value)
1042 static inline uint32_t
random(uint32_t min_value, uint32_t max_value)
1052 static inline int32_t
random(int32_t min_value, int32_t max_value)
1099 rand_u =
static_cast<float32_t>(CMath::random(-1.0, 1.0));
1100 rand_v =
static_cast<float32_t>(CMath::random(-1.0, 1.0));
1101 rand_s = rand_u*rand_u + rand_v*rand_v;
1102 }
while ((rand_s == 0) || (rand_s >= 1));
1105 ret =
static_cast<float32_t>(rand_u*CMath::sqrt(-2.0*CMath::log(rand_s)/rand_s));
1106 ret = std_dev*ret +
mean;
1122 return static_cast<float32_t>(normal_random(0.0, 1.0));
1140 static int32_t
gcd(int32_t a, int32_t b)
1142 REQUIRE((a>=0 && b>0) || (b>=0 && a>0),
"gcd(%d,%d) is not defined.\n",
1145 if (1 == a || 1 == b)
1148 while (0 < a && 0 < b)
1156 return 0 == a ? b : a;
1170 swap(v[i], v[rand->random(i, v.
vlen-1)]);
1175 swap(v[i], v[random(i, v.
vlen-1)]);
1216 for (int32_t i=n-k+1; i<=n; i++)
1219 return res/factorial(k);
1240 linspace(output, start, end, n);
1266 REQUIRE(values.
vlen>0,
"number of values supplied is 0\n");
1287 for (from_idx=0; from_idx<values.
vlen; ++from_idx)
1289 if (from_idx!=min_index)
1291 values_without_X0[to_idx]=exp(values[from_idx]-X0);
1308 return log_sum_exp(values) - log(values.
vlen);
1318 static void sort(int32_t *a, int32_t cols, int32_t sort_col=0);
1326 static void sort(
float64_t *a, int32_t*idx, int32_t N);
1334 static void qsort(T* output, int32_t size)
1341 if (output[0] > output [1])
1342 CMath::swap(output[0],output[1]);
1346 T
split=output[size/2];
1349 int32_t right=size-1;
1353 while (output[left] < split)
1355 while (output[right] > split)
1360 CMath::swap(output[left],output[right]);
1367 qsort(output,right+1);
1370 qsort(&output[left],size-left);
1381 for (int32_t i=0; i<size-1; i++)
1385 while (j >= 0 && output[j] > value)
1387 output[j+1] = output[j];
1401 radix_sort_helper(array,size,0);
1412 static inline uint8_t
byte(T word, uint16_t p)
1414 return (word >> (
sizeof(T)-p-1) * 8) & 0xff;
1420 SG_SERROR(
"CMath::byte():: Not supported for complex128_t\n");
1432 static size_t count[256], nc, cmin;
1436 T *an, *aj, *pile[256];
1451 for (ak = array; ak < an; ak++) {
1454 if (count[c] == 1) {
1464 radix_sort_helper(array, size, i);
1479 for (cp = count + cmin; nc > 0; cp++) {
1491 if (i <
sizeof(T)-1)
1494 pile[cp - count] = ak += *cp;
1518 for (r = *aj; aj < (ak = --pile[c = byte(r, i)]);)
1531 SG_SERROR(
"CMath::radix_sort_helper():: Not supported for complex128_t\n");
1548 if (*vector[0]>*vector[1])
1549 swap(vector[0],vector[1]);
1552 T*
split=vector[length/2];
1555 int32_t right=length-1;
1559 while (*vector[left]<*split)
1561 while (*vector[right]>*split)
1566 swap(vector[left],vector[right]);
1573 qsort(vector,right+1);
1576 qsort(&vector[left],length-left);
1582 SG_SERROR(
"CMath::qsort():: Not supported for complex128_t\n");
1591 qsort<T>(vector, vector.
size());
1604 return abs(data[i]-data[j])>std::numeric_limits<T>::epsilon()
1627 std::sort(idx.vector, idx.vector+vector.
size(), cmp);
1640 if (vector.
size() < 2)
1643 for(int32_t i=1; i<vector.
size(); i++)
1645 if (vector[i-1] > vector[i])
1656 template <
class T>
static void display_bits(T word, int32_t width=8*
sizeof(T))
1659 for (
int i=0; i<width; i++)
1661 T mask = ((T) 1)<<(
sizeof(T)*8-1);
1678 SG_SERROR(
"CMath::display_bits():: Not supported for complex128_t\n");
1689 template <
class T1,
class T2>
1690 static void qsort_index(T1* output, T2* index, uint32_t size);
1696 SG_SERROR(
"CMath::qsort_index():: Not supported for complex128_t\n");
1707 template <
class T1,
class T2>
1708 static void qsort_backward_index(
1709 T1* output, T2* index, int32_t size);
1716 SG_SERROR(
"CMath::qsort_backword_index():: \ 1717 Not supported for complex128_t\n");
1731 template <
class T1,
class T2>
1732 inline static void parallel_qsort_index(T1* output, T2* index, uint32_t size, int32_t n_threads, int32_t limit=262144)
1735 thread_qsort<T1,T2> t;
1741 t.num_threads=n_threads;
1742 parallel_qsort_index<T1,T2>(&t);
1748 uint32_t size, int32_t n_threads, int32_t limit=0)
1750 SG_SERROR(
"CMath::parallel_qsort_index():: Not supported for complex128_t\n");
1754 template <
class T1,
class T2>
1755 static void* parallel_qsort_index(
void* p);
1765 static void min(
float64_t* output, T* index, int32_t size);
1770 SG_SERROR(
"CMath::min():: Not supported for complex128_t\n");
1778 float64_t* output, T* index, int32_t size, int32_t n);
1782 int32_t size, int32_t n)
1784 SG_SERROR(
"CMath::nmin():: Not supported for complex128_t\n");
1803 int32_t middle=(start+end)/2;
1805 if (output[middle]>elem)
1807 else if (output[middle]<elem)
1819 SG_SERROR(
"CMath::binary_search_helper():: Not supported for complex128_t\n");
1832 int32_t ind = binary_search_helper(output, size, elem);
1833 if (ind >= 0 && output[ind] == elem)
1841 SG_SERROR(
"CMath::binary_search():: Not supported for complex128_t\n");
1858 int32_t end=length-1;
1865 int32_t middle=(start+end)/2;
1867 if (*vector[middle]>*elem)
1869 else if (*vector[middle]<*elem)
1878 if (start>=0&&*vector[start]==*elem)
1887 SG_SERROR(
"CMath::binary_search():: Not supported for complex128_t\n");
1899 T* output, int32_t size, T elem)
1901 int32_t ind = binary_search_helper(output, size, elem);
1903 if (output[ind]<=elem)
1905 if (ind>0 && output[ind-1] <= elem)
1914 SG_SERROR(
"CMath::binary_search_max_lower_equal():: \ 1915 Not supported for complex128_t\n");
1928 char * seq1,
char* seq2, int32_t l1, int32_t l2,
float64_t gapCost);
1960 return CMath::LOGRANGE;
1964 inline static uint32_t get_log_accuracy()
1967 return CMath::LOGACCURACY;
1972 static int is_finite(
double f);
1975 static int is_infinity(
double f);
1978 static int is_nan(
double f);
1994 if (!CMath::is_finite(p))
1997 if (!CMath::is_finite(q))
1999 SG_SWARNING(
"INVALID second operand to logsum(%f,%f) expect undefined results\n", p, q)
2000 return NOT_A_NUMBER;
2004 return diff > LOGRANGE? p : p + logtable[(int)(diff * LOGACCURACY)];
2005 return -diff > LOGRANGE? q : q + logtable[(int)(-diff * LOGACCURACY)];
2009 static void init_log_table();
2012 static int32_t determine_logrange();
2015 static int32_t determine_logaccuracy(int32_t range);
2022 if (!CMath::is_finite(p))
2024 if (!CMath::is_finite(q))
2028 return diff > LOGRANGE? p : p + log(1 + exp(-diff));
2029 return -diff > LOGRANGE? q : q + log(1 + exp(diff));
2032 #ifdef USE_LOGSUMARRAY 2038 static inline float64_t logarithmic_sum_array(
2044 return logarithmic_sum(p[0],p[1]) ;
2052 if (len%2==1) pp++ ;
2053 for (int32_t j=0; j < len>>1; j++)
2054 pp[j]=logarithmic_sum(pp[j<<1], pp[1+(j<<1)]) ;
2056 return logarithmic_sum_array(p,len%2 + (len>>1)) ;
2058 #endif //USE_LOGSUMARRAY 2062 virtual const char*
get_name()
const {
return "Math"; }
2105 static int32_t LOGACCURACY;
2113 template <
class T1,
class T2>
2114 void* CMath::parallel_qsort_index(
void* p)
2116 struct thread_qsort<T1,T2>* ps=(thread_qsort<T1,T2>*) p;
2117 T1* output=ps->output;
2118 T2* index=ps->index;
2119 int32_t size=ps->size;
2120 int32_t* qsort_threads=ps->qsort_threads;
2121 int32_t sort_limit=ps->sort_limit;
2122 int32_t num_threads=ps->num_threads;
2131 if (output[0] > output [1])
2133 swap(output[0], output[1]);
2134 swap(index[0], index[1]);
2139 T1
split=output[size/2];
2142 int32_t right=size-1;
2146 while (output[left] < split)
2148 while (output[right] > split)
2153 swap(output[left], output[right]);
2154 swap(index[left], index[right]);
2159 bool lthread_start=
false;
2160 bool rthread_start=
false;
2163 struct thread_qsort<T1,T2> t1;
2164 struct thread_qsort<T1,T2> t2;
2166 if (right+1> 1 && (right+1< sort_limit || *qsort_threads >= num_threads-1))
2167 qsort_index(output,index,right+1);
2168 else if (right+1> 1)
2175 t1.qsort_threads=qsort_threads;
2176 t1.sort_limit=sort_limit;
2177 t1.num_threads=num_threads;
2178 if (pthread_create(<hread, NULL, parallel_qsort_index<T1,T2>, &t1) != 0)
2180 lthread_start=
false;
2182 qsort_index(output,index,right+1);
2187 if (size-left> 1 && (size-left< sort_limit || *qsort_threads >= num_threads-1))
2188 qsort_index(&output[left],&index[left], size-left);
2189 else if (size-left> 1)
2193 t2.output=&output[left];
2194 t2.index=&index[left];
2196 t2.qsort_threads=qsort_threads;
2197 t2.sort_limit=sort_limit;
2198 t2.num_threads=num_threads;
2199 if (pthread_create(&rthread, NULL, parallel_qsort_index<T1,T2>, &t2) != 0)
2201 rthread_start=
false;
2203 qsort_index(&output[left],&index[left], size-left);
2209 pthread_join(lthread, NULL);
2215 pthread_join(rthread, NULL);
2222 template <
class T1,
class T2>
2223 void CMath::qsort_index(T1* output, T2* index, uint32_t size)
2230 if (output[0] > output [1])
2232 swap(output[0],output[1]);
2233 swap(index[0],index[1]);
2238 T1
split=output[size/2];
2241 int32_t right=size-1;
2245 while (output[left] < split)
2247 while (output[right] > split)
2252 swap(output[left],output[right]);
2253 swap(index[left],index[right]);
2260 qsort_index(output,index,right+1);
2263 qsort_index(&output[left],&index[left], size-left);
2266 template <
class T1,
class T2>
2267 void CMath::qsort_backward_index(T1* output, T2* index, int32_t size)
2274 if (output[0] < output [1])
2276 swap(output[0],output[1]);
2277 swap(index[0],index[1]);
2283 T1
split=output[size/2];
2286 int32_t right=size-1;
2290 while (output[left] > split)
2292 while (output[right] < split)
2297 swap(output[left],output[right]);
2298 swap(index[left],index[right]);
2305 qsort_backward_index(output,index,right+1);
2308 qsort_backward_index(&output[left],&index[left], size-left);
2312 void CMath::nmin(
float64_t* output, T* index, int32_t size, int32_t n)
2314 if (6*n*size<13*size*CMath::log(size))
2315 for (int32_t i=0; i<n; i++)
2316 min(&output[i], &index[i], size-i);
2318 qsort_index(output, index, size);
2328 int32_t min_index=0;
2329 for (int32_t i=1; i<size; i++)
2331 if (output[i]<min_elem)
2337 swap(output[0], output[min_index]);
2338 swap(index[0], index[min_index]);
2345 SG_SERROR(
"SGVector::linspace():: Not supported for complex128_t\n");
2349 #define COMPLEX128_ERROR_ONEVECARG_RETURNS_T(function, return_type, return_statement) \ 2351 inline return_type CMath::function<complex128_t>(SGVector<complex128_t> vector) \ 2353 SG_SERROR("CMath::%s():: Not supported for complex128_t\n", \ 2358 #define COMPLEX128_ERROR_ONEARG_T(function) \ 2360 inline complex128_t CMath::function<complex128_t>(complex128_t a) \ 2362 SG_SERROR("CMath::%s():: Not supported for complex128_t\n",\ 2364 return complex128_t(0.0, 0.0); \ 2367 #define COMPLEX128_ERROR_TWOARGS_T(function) \ 2369 inline complex128_t CMath::function<complex128_t>(complex128_t a, complex128_t b) \ 2371 SG_SERROR("CMath::%s():: Not supported for complex128_t\n",\ 2373 return complex128_t(0.0, 0.0); \ 2376 #define COMPLEX128_ERROR_THREEARGS_T(function) \ 2378 inline complex128_t CMath::function<complex128_t>(complex128_t a, complex128_t b, complex128_t c) \ 2380 SG_SERROR("CMath::%s():: Not supported for complex128_t\n",\ 2382 return complex128_t(0.0, 0.0); \ 2385 #define COMPLEX128_ERROR_SORT_T(function) \ 2387 inline void CMath::function<complex128_t>(complex128_t* output, int32_t b) \ 2389 SG_SERROR("CMath::%s():: Not supported for complex128_t\n",\ 2393 #define COMPLEX128_ERROR_ARG_MAX_MIN(function) \ 2395 inline int32_t CMath::function<complex128_t>(complex128_t * a, int32_t b, int32_t c, complex128_t * d) \ 2398 SG_SERROR("CMath::%s():: Not supported for complex128_t\n",\ 2440 #undef COMPLEX128_ERROR_ONEARG 2441 #undef COMPLEX128_ERROR_ONEARG_T 2442 #undef COMPLEX128_ERROR_TWOARGS_T 2443 #undef COMPLEX128_ERROR_THREEARGS_T 2444 #undef COMPLEX128_STDMATH 2445 #undef COMPLEX128_ERROR_SORT_T static float64_t normal_random(float64_t mean, float64_t std_dev)
float64_t std_normal_distrib() const
static const float32_t F_MAX_VAL32
static const float64_t MACHINE_EPSILON
static int32_t gcd(int32_t a, int32_t b)
static void permute(SGVector< T > v, CRandom *rand=NULL)
static int32_t binary_search(complex128_t *output, int32_t size, complex128_t elem)
binary_search not implemented for complex128_t
static void parallel_qsort_index(T1 *output, T2 *index, uint32_t size, int32_t n_threads, int32_t limit=262144)
static floatmax_t dot(const floatmax_t *v1, const floatmax_t *v2, int32_t n)
Compute dot product between v1 and v2 (blas optimized)
static uint32_t seed
random generator seed
std::complex< float64_t > complex128_t
uint64_t random(uint64_t min_value, uint64_t max_value)
static int32_t arg_max(T *vec, int32_t inc, int32_t len, T *maxv_ptr=NULL)
static float64_t sqrt(float64_t x)
static floatmax_t random(floatmax_t min_value, floatmax_t max_value)
static floatmax_t sqrt(floatmax_t x)
float64_t normal_distrib(float64_t mu, float64_t sigma) const
static float64_t ceil(float64_t d)
static complex128_t pow(complex128_t x, int32_t n)
static const float64_t INFTY
infinity
static SGVector< float64_t > linspace_vec(T start, T end, int32_t n)
static int32_t binary_search_helper(T *output, int32_t size, T elem)
#define COMPLEX128_ERROR_THREEARGS_T(function)
static void qsort_index(complex128_t *output, T *index, uint32_t size)
qsort_index not implemented for complex128_t
#define COMPLEX128_ERROR_TWOARGS_T(function)
static void qsort(SGVector< T > vector)
#define COMPLEX128_ERROR_ONEVECARG_RETURNS_T(function, return_type, return_statement)
static float32_t normal_random(float32_t mean, float32_t std_dev)
static float64_t random(float64_t min_value, float64_t max_value)
static int32_t binary_search(T *output, int32_t size, T elem)
static uint32_t get_seed()
returns number generator seed
#define COMPLEX128_ERROR_ARG_MAX_MIN(function)
static float32_t randn_float()
static const float64_t MIN_REAL_NUMBER
static float64_t dot(const char *v1, const char *v2, int32_t n)
Compute dot product between v1 and v2 (for 8bit (un)signed ints)
static float64_t randn_double()
static int32_t binary_search_max_lower_equal(T *output, int32_t size, T elem)
static const float64_t F_MAX_VAL64
T dot(const SGVector< T > &a, const SGVector< T > &b)
static uint32_t get_log_range()
returns range of logtable
void split(v_array< ds_node< P > > &point_set, v_array< ds_node< P > > &far_set, int max_scale)
static float32_t random(float32_t min_value, float32_t max_value)
static const float32_t F_MIN_VAL32
static float64_t dot(const int8_t *v1, const int8_t *v2, int32_t n)
Compute dot product between v1 and v2 (for 8bit (un)signed ints)
std::enable_if<!std::is_same< T, complex128_t >::value, float64_t >::type mean(const Container< T > &a)
IndexSorter(const SGVector< T > *vec)
static bool fequals_abs(const T &a, const T &b, const float64_t eps)
static float64_t imag(complex128_t c)
static float64_t floor(float64_t d)
static float64_t * linspace(T start, T end, int32_t n)
static int32_t get_num_nonzero(complex128_t *vec, int32_t len)
static const float32_t F_MIN_NORM_VAL32
static float64_t real(complex128_t c)
static uint8_t byte(complex128_t word, uint16_t p)
byte not implemented for complex128_t
static void qsort(T *output, int32_t size)
static int32_t LOGRANGE
range for logtable: log(1+exp(x)) -LOGRANGE <= x <= 0
static const float64_t ALMOST_NEG_INFTY
almost neg (log) infinity
static bool fequals(const T &a, const T &b, const float64_t eps, bool tolerant=false)
static complex128_t pow(complex128_t x, complex128_t n)
static uint8_t byte(T word, uint16_t p)
static complex128_t pow(float64_t x, complex128_t n)
static float64_t pow(float64_t x, int32_t n)
Class SGObject is the base class of all shogun objects.
static int32_t random(int32_t min_value, int32_t max_value)
static float64_t pow(float64_t x, float64_t n)
static float64_t dot(const uint8_t *v1, const uint8_t *v2, int32_t n)
Compute dot product between v1 and v2 (for 8bit (un)signed ints)
static void qsort(T **vector, index_t length)
static void init_random(uint32_t initseed=0)
static int32_t pow(int32_t x, int32_t n)
#define radix_pop(a, n, i)
static float64_t dot(const uint16_t *v1, const uint16_t *v2, int32_t n)
Compute dot product between v1 and v2 (for 16bit unsigned ints)
static void parallel_qsort_index(complex128_t *output, T *index, uint32_t size, int32_t n_threads, int32_t limit=0)
parallel_qsort_index not implemented for complex128_t
static void min(float64_t *output, complex128_t *index, int32_t size)
complex128_t cannot be used as index
static float64_t dot(const int16_t *v1, const int16_t *v2, int32_t n)
Compute dot product between v1 and v2 (for 16bit unsigned ints)
#define COMPLEX128_ERROR_ONEARG(function)
static SGVector< index_t > argsort(SGVector< T > vector)
static float64_t dot(const uint32_t *v1, const uint32_t *v2, int32_t n)
Compute dot product between v1 and v2 (for 32bit unsigned ints)
static void qsort_backword_index(complex128_t *output, T *index, uint32_t size)
qsort_backword_index not implemented for complex128_t
static int32_t get_num_nonzero(T *vec, int32_t len)
static T log_sum_exp(SGVector< T > values)
static float64_t area_under_curve(float64_t *xy, int32_t len, bool reversed)
static float64_t dot(const bool *v1, const bool *v2, int32_t n)
Compute dot product between v1 and v2 (blas optimized)
static void display_bits(T word, int32_t width=8 *sizeof(T))
static uint64_t random(uint64_t min_value, uint64_t max_value)
static int64_t factorial(int32_t n)
static void qsort(complex128_t **vector, index_t length)
qsort not implemented for complex128_t
static int32_t arg_min(T *vec, int32_t inc, int32_t len, T *minv_ptr=NULL)
virtual const char * get_name() const
static int32_t binary_search_max_lower_equal(complex128_t *output, int32_t size, complex128_t elem)
binary_search_max_lower_equal not implemented for complex128_t
: Pseudo random number geneartor
static int64_t nchoosek(int32_t n, int32_t k)
static T min(T *vec, int32_t len)
all of classes and functions are contained in the shogun namespace
static float64_t dot(const int32_t *v1, const int32_t *v2, int32_t n)
Compute dot product between v1 and v2 (for 32bit ints)
static int32_t binary_search(T **vector, index_t length, T *elem)
void set_seed(uint32_t seed)
static float64_t abs(complex128_t a)
static void display_bits(complex128_t word, int32_t width=8 *sizeof(complex128_t))
disply_bits not implemented for complex128_t
#define COMPLEX128_STDMATH(function)
static void radix_sort_helper(T *array, int32_t size, uint16_t i)
static float64_t dot(const float64_t *v1, const char *v2, int32_t n)
Compute dot product between v1 and v2.
static float64_t exp(float64_t x)
static const float64_t F_MIN_VAL64
static const float64_t F_MIN_NORM_VAL64
static float64_t log(float64_t v)
static void radix_sort_helper(complex128_t *array, int32_t size, uint16_t i)
radix_sort_helper not implemented for complex128_t
static const float64_t ALMOST_INFTY
Class which collects generic mathematical functions.
static T log_mean_exp(SGVector< T > values)
static void insertion_sort(T *output, int32_t size)
static void swap(T &a, T &b)
static complex128_t pow(complex128_t x, float64_t n)
static T max(T *vec, int32_t len)
static int32_t binary_search_helper(complex128_t *output, int32_t size, complex128_t elem)
binary_search_helper not implemented for complex128_t
static float64_t round(float64_t d)
static bool is_sorted(SGVector< T > vector)
static float32_t sqrt(float32_t x)
T max(const Container< T > &a)
static float64_t dot(const int64_t *v1, const int64_t *v2, int32_t n)
Compute dot product between v1 and v2 (for 64bit ints)
static void radix_sort(T *array, int32_t size)
uint64_t random_64() const
static uint32_t random(uint32_t min_value, uint32_t max_value)
static floatmax_t powl(floatmax_t x, floatmax_t n)
static float64_t dot(const uint64_t *v1, const uint64_t *v2, int32_t n)
compute dot product between v1 and v2 (for 64bit unsigned ints)
static float64_t logarithmic_sum(float64_t p, float64_t q)
#define radix_push(a, n, i)
static T clamp(T value, T lb, T ub)
static int32_t binary_search(complex128_t **vector, index_t length, complex128_t *elem)
binary_search not implemented for complex128_t
#define COMPLEX128_ERROR_SORT_T(function)
static int32_t pow(bool x, int32_t n)
static const float64_t MAX_REAL_NUMBER
static void nmin(float64_t *output, complex128_t *index, int32_t size, int32_t n)
complex128_t cannot be used as index
static int64_t random(int64_t min_value, int64_t max_value)
static const float64_t PI