20 #ifndef __MATHEMATICS_H_
21 #define __MATHEMATICS_H_
33 #ifndef _USE_MATH_DEFINES
34 #define _USE_MATH_DEFINES
39 #include <sys/types.h>
54 #define cygwin_log2 log2
59 #define M_PI 3.14159265358979323846
68 #define isfinite _isfinite
73 #define RNG_SEED_SIZE 256
76 #define RADIX_STACK_SIZE 512
79 #define radix_push(a, n, i) sp->sa = a, sp->sn = n, (sp++)->si = i
80 #define radix_pop(a, n, i) a = (--sp)->sa, n = sp->sn, i = sp->si
82 #ifndef DOXYGEN_SHOULD_SKIP_THIS
84 template <
class T>
struct radix_stack_t
95 template <
class T1,
class T2>
struct thread_qsort
105 int32_t* qsort_threads;
111 #endif // DOXYGEN_SHOULD_SKIP_THIS
113 #define COMPLEX128_ERROR_ONEARG(function) \
114 static inline complex128_t function(complex128_t a) \
116 SG_SERROR("CMath::%s():: Not supported for complex128_t\n",\
118 return complex128_t(0.0, 0.0); \
121 #define COMPLEX128_STDMATH(function) \
122 static inline complex128_t function(complex128_t a) \
124 return std::function(a); \
157 static inline T
min(T a, T b)
159 return (a<=b) ? a : b;
168 static inline T
max(T a, T b)
170 return (a>=b) ? a : b;
209 static T
min(T* vec, int32_t len)
214 for (int32_t i=1; i<len; i++)
215 minv=
min(vec[i], minv);
226 static T
max(T* vec, int32_t len)
231 for (int32_t i=1; i<len; i++)
232 maxv=
max(vec[i], maxv);
244 static inline T
clamp(T value, T lb, T ub)
262 static int32_t
arg_max(T * vec, int32_t inc, int32_t len, T * maxv_ptr = NULL)
264 ASSERT(len > 0 || inc > 0)
269 for (int32_t i = 1, j = inc ; i < len ; i++, j += inc)
272 maxv = vec[j], maxIdx = i;
275 if (maxv_ptr != NULL)
289 static int32_t
arg_min(T * vec, int32_t inc, int32_t len, T * minv_ptr = NULL)
291 ASSERT(len > 0 || inc > 0)
296 for (int32_t i = 1, j = inc ; i < len ; i++, j += inc)
299 minv = vec[j], minIdx = i;
302 if (minv_ptr != NULL)
321 const T diff = CMath::abs<T>((a-b));
335 static inline bool fequals(
const T& a,
const T& b,
336 const float64_t eps,
bool tolerant=
false)
338 const T absA = CMath::abs<T>(a);
339 const T absB = CMath::abs<T>(b);
340 const T diff = CMath::abs<T>((a-b));
349 return CMath::fequals_abs<T>(a, b, eps);
362 else if ( (a==0) || (b==0) || (diff < comp) )
363 return (diff<(eps * comp));
368 T check = ((diff/(absA + absB)) > diff)?
369 (diff/(absA + absB)):diff;
370 return (check < eps);
400 return ::floor(d+0.5);
430 else return (a<0) ? (-1) : (+1);
438 static inline void swap(T &a,T &b)
450 static inline T
sq(T x)
509 tmp.i = 0x5f3759d5 - (tmp.i >> 1);
511 x = x*(1.5f - xhalf*x*x);
529 return ::powl((
long double) x, (
long double) n);
531 return ::pow((
double) x, (
double) n);
535 static inline int32_t
pow(
bool x, int32_t n)
544 static inline int32_t
pow(int32_t x, int32_t n)
569 return ::pow((
double)x, (
double)n);
578 return ::pow((
double) x, (
double) n);
587 return std::pow(x, n);
596 return std::pow(x, n);
605 return std::pow(x, n);
614 return std::pow(x, n);
623 return ::exp((
double) x);
630 for (int32_t i=0; i<n; i++)
631 r+=((v1[i]) ? 1 : 0) * ((v2[i]) ? 1 : 0);
639 for (int32_t i=0; i<n; i++)
653 const uint64_t* v1,
const uint64_t* v2, int32_t n)
656 for (int32_t i=0; i<n; i++)
663 const int64_t* v1,
const int64_t* v2, int32_t n)
666 for (int32_t i=0; i<n; i++)
674 const int32_t* v1,
const int32_t* v2, int32_t n)
677 for (int32_t i=0; i<n; i++)
685 const uint32_t* v1,
const uint32_t* v2, int32_t n)
688 for (int32_t i=0; i<n; i++)
696 const uint16_t* v1,
const uint16_t* v2, int32_t n)
699 for (int32_t i=0; i<n; i++)
707 const int16_t* v1,
const int16_t* v2, int32_t n)
710 for (int32_t i=0; i<n; i++)
718 const char* v1,
const char* v2, int32_t n)
721 for (int32_t i=0; i<n; i++)
729 const uint8_t* v1,
const uint8_t* v2, int32_t n)
732 for (int32_t i=0; i<n; i++)
740 const int8_t* v1,
const int8_t* v2, int32_t n)
743 for (int32_t i=0; i<n; i++)
751 const float64_t* v1,
const char* v2, int32_t n)
754 for (int32_t i=0; i<n; i++)
773 return ::tan((
double) x);
785 return ::atan((
double) x);
798 return ::atan2((
double) y, (
double) x);
810 return ::tanh((
double) x);
899 return ::log(v)/
::log(10.0);
914 return ::log(v)/
::log(2.0);
933 for (i = 0; n != 0; i++)
954 for (
int i=1; i<len; i++)
955 area += 0.5*(xy[2*i]-xy[2*(i-1)])*(xy[2*i+1]+xy[2*(i-1)+1]);
959 for (
int i=1; i<len; i++)
960 area += 0.5*(xy[2*i+1]-xy[2*(i-1)+1])*(xy[2*i]+xy[2*(i-1)]);
994 for (
int i=2; i<=n; i++)
1013 sg_rand->set_seed(
seed);
1021 return sg_rand->random_64();
1027 static inline uint64_t
random(uint64_t min_value, uint64_t max_value)
1029 return sg_rand->random(min_value, max_value);
1037 static inline int64_t
random(int64_t min_value, int64_t max_value)
1039 return sg_rand->random(min_value, max_value);
1047 static inline uint32_t
random(uint32_t min_value, uint32_t max_value)
1049 return sg_rand->random(min_value, max_value);
1057 static inline int32_t
random(int32_t min_value, int32_t max_value)
1059 return sg_rand->random(min_value, max_value);
1069 return sg_rand->random(min_value, max_value);
1079 return sg_rand->random(min_value, max_value);
1089 return sg_rand->random(min_value, max_value);
1106 rand_s = rand_u*rand_u + rand_v*rand_v;
1107 }
while ((rand_s == 0) || (rand_s >= 1));
1110 ret = rand_u*
sqrt(-2.0*
log(rand_s)/rand_s);
1111 ret = std_dev*ret + mean;
1120 return sg_rand->normal_distrib(mean, std_dev);
1134 return sg_rand->std_normal_distrib();
1149 swap(v[i], v[rand->random(i, v.
vlen-1)]);
1195 for (int32_t i=n-k+1; i<=n; i++)
1245 REQUIRE(values.
vlen>0,
"number of values supplied is 0\n");
1266 for (from_idx=0; from_idx<values.
vlen; ++from_idx)
1268 if (from_idx!=min_index)
1270 values_without_X0[to_idx]=
exp(values[from_idx]-X0);
1297 static void sort(int32_t *a, int32_t cols, int32_t sort_col=0);
1313 static void qsort(T* output, int32_t size)
1320 if (output[0] > output [1])
1325 T
split=output[size/2];
1328 int32_t right=size-1;
1332 while (output[left] < split)
1334 while (output[right] > split)
1346 qsort(output,right+1);
1349 qsort(&output[left],size-left);
1360 for (int32_t i=0; i<size-1; i++)
1364 while (j >= 0 && output[j] > value)
1366 output[j+1] = output[j];
1391 static inline uint8_t
byte(T word, uint16_t p)
1393 return (word >> (
sizeof(T)-p-1) * 8) & 0xff;
1399 SG_SERROR(
"CMath::byte():: Not supported for complex128_t\n");
1411 static size_t count[256], nc, cmin;
1415 T *an, *aj, *pile[256];
1430 for (ak = array; ak < an; ak++) {
1433 if (count[c] == 1) {
1458 for (cp = count + cmin; nc > 0; cp++) {
1470 if (i <
sizeof(T)-1)
1473 pile[cp - count] = ak += *cp;
1497 for (r = *aj; aj < (ak = --pile[c =
byte(r, i)]);)
1510 SG_SERROR(
"CMath::radix_sort_helper():: Not supported for complex128_t\n");
1527 if (*vector[0]>*vector[1])
1528 swap(vector[0],vector[1]);
1531 T*
split=vector[length/2];
1534 int32_t right=length-1;
1538 while (*vector[left]<*split)
1540 while (*vector[right]>*split)
1545 swap(vector[left],vector[right]);
1552 qsort(vector,right+1);
1555 qsort(&vector[left],length-left);
1561 SG_SERROR(
"CMath::qsort():: Not supported for complex128_t\n");
1570 qsort<T>(vector, vector.
size());
1583 return abs(
data[i]-
data[j])>std::numeric_limits<T>::epsilon()
1606 std::sort(idx.vector, idx.vector+vector.
size(), cmp);
1619 if (vector.
size() < 2)
1622 for(int32_t i=1; i<vector.
size(); i++)
1624 if (vector[i-1] > vector[i])
1635 template <
class T>
static void display_bits(T word, int32_t width=8*
sizeof(T))
1638 for (
int i=0; i<width; i++)
1640 T mask = ((T) 1)<<(
sizeof(T)*8-1);
1657 SG_SERROR(
"CMath::display_bits():: Not supported for complex128_t\n");
1668 template <
class T1,
class T2>
1669 static void qsort_index(T1* output, T2* index, uint32_t size);
1675 SG_SERROR(
"CMath::qsort_index():: Not supported for complex128_t\n");
1686 template <
class T1,
class T2>
1688 T1* output, T2* index, int32_t size);
1695 SG_SERROR(
"CMath::qsort_backword_index():: \
1696 Not supported for complex128_t\n");
1710 template <
class T1,
class T2>
1711 inline static void parallel_qsort_index(T1* output, T2* index, uint32_t size, int32_t n_threads, int32_t limit=262144)
1714 thread_qsort<T1,T2> t;
1720 t.num_threads=n_threads;
1721 parallel_qsort_index<T1,T2>(&t);
1727 uint32_t size, int32_t n_threads, int32_t limit=0)
1729 SG_SERROR(
"CMath::parallel_qsort_index():: Not supported for complex128_t\n");
1733 template <
class T1,
class T2>
1744 static void min(
float64_t* output, T* index, int32_t size);
1749 SG_SERROR(
"CMath::min():: Not supported for complex128_t\n");
1757 float64_t* output, T* index, int32_t size, int32_t n);
1761 int32_t size, int32_t n)
1763 SG_SERROR(
"CMath::nmin():: Not supported for complex128_t\n");
1782 int32_t middle=(start+end)/2;
1784 if (output[middle]>elem)
1786 else if (output[middle]<elem)
1798 SG_SERROR(
"CMath::binary_search_helper():: Not supported for complex128_t\n");
1812 if (ind >= 0 && output[ind] == elem)
1820 SG_SERROR(
"CMath::binary_search():: Not supported for complex128_t\n");
1837 int32_t end=length-1;
1844 int32_t middle=(start+end)/2;
1846 if (*vector[middle]>*elem)
1848 else if (*vector[middle]<*elem)
1857 if (start>=0&&*vector[start]==*elem)
1866 SG_SERROR(
"CMath::binary_search():: Not supported for complex128_t\n");
1878 T* output, int32_t size, T elem)
1882 if (output[ind]<=elem)
1884 if (ind>0 && output[ind-1] <= elem)
1893 SG_SERROR(
"CMath::binary_search_max_lower_equal():: \
1894 Not supported for complex128_t\n");
1907 char * seq1,
char* seq2, int32_t l1, int32_t l2,
float64_t gapCost);
1943 inline static uint32_t get_log_accuracy()
1946 return CMath::LOGACCURACY;
1957 static int is_nan(
double f);
1978 SG_SWARNING(
"INVALID second operand to logsum(%f,%f) expect undefined results\n", p, q)
1983 return diff >
LOGRANGE? p : p + logtable[(
int)(diff * LOGACCURACY)];
1984 return -diff >
LOGRANGE? q : q + logtable[(
int)(-diff * LOGACCURACY)];
1988 static
void init_log_table();
1991 static int32_t determine_logrange();
1994 static int32_t determine_logaccuracy(int32_t range);
2011 #ifdef USE_LOGSUMARRAY
2017 static inline float64_t logarithmic_sum_array(
2031 if (len%2==1) pp++ ;
2032 for (int32_t j=0; j < len>>1; j++)
2035 return logarithmic_sum_array(p,len%2 + (len>>1)) ;
2037 #endif //USE_LOGSUMARRAY
2041 virtual const char*
get_name()
const {
return "Math"; }
2084 static int32_t LOGACCURACY;
2092 template <
class T1,
class T2>
2095 struct thread_qsort<T1,T2>* ps=(thread_qsort<T1,T2>*) p;
2096 T1* output=ps->output;
2097 T2* index=ps->index;
2098 int32_t size=ps->size;
2099 int32_t* qsort_threads=ps->qsort_threads;
2100 int32_t sort_limit=ps->sort_limit;
2101 int32_t num_threads=ps->num_threads;
2110 if (output[0] > output [1])
2112 swap(output[0], output[1]);
2113 swap(index[0], index[1]);
2118 T1
split=output[size/2];
2121 int32_t right=size-1;
2125 while (output[left] < split)
2127 while (output[right] > split)
2132 swap(output[left], output[right]);
2133 swap(index[left], index[right]);
2138 bool lthread_start=
false;
2139 bool rthread_start=
false;
2142 struct thread_qsort<T1,T2> t1;
2143 struct thread_qsort<T1,T2> t2;
2145 if (right+1> 1 && (right+1< sort_limit || *qsort_threads >= num_threads-1))
2147 else if (right+1> 1)
2154 t1.qsort_threads=qsort_threads;
2155 t1.sort_limit=sort_limit;
2156 t1.num_threads=num_threads;
2157 if (pthread_create(<hread, NULL, parallel_qsort_index<T1,T2>, &t1) != 0)
2159 lthread_start=
false;
2166 if (size-left> 1 && (size-left< sort_limit || *qsort_threads >= num_threads-1))
2167 qsort_index(&output[left],&index[left], size-left);
2168 else if (size-left> 1)
2172 t2.output=&output[left];
2173 t2.index=&index[left];
2175 t2.qsort_threads=qsort_threads;
2176 t2.sort_limit=sort_limit;
2177 t2.num_threads=num_threads;
2178 if (pthread_create(&rthread, NULL, parallel_qsort_index<T1,T2>, &t2) != 0)
2180 rthread_start=
false;
2182 qsort_index(&output[left],&index[left], size-left);
2188 pthread_join(lthread, NULL);
2194 pthread_join(rthread, NULL);
2201 template <
class T1,
class T2>
2209 if (output[0] > output [1])
2211 swap(output[0],output[1]);
2212 swap(index[0],index[1]);
2217 T1
split=output[size/2];
2220 int32_t right=size-1;
2224 while (output[left] < split)
2226 while (output[right] > split)
2231 swap(output[left],output[right]);
2232 swap(index[left],index[right]);
2242 qsort_index(&output[left],&index[left], size-left);
2245 template <
class T1,
class T2>
2253 if (output[0] < output [1])
2255 swap(output[0],output[1]);
2256 swap(index[0],index[1]);
2262 T1
split=output[size/2];
2265 int32_t right=size-1;
2269 while (output[left] > split)
2271 while (output[right] < split)
2276 swap(output[left],output[right]);
2277 swap(index[left],index[right]);
2294 for (int32_t i=0; i<n; i++)
2295 min(&output[i], &index[i], size-i);
2307 int32_t min_index=0;
2308 for (int32_t i=1; i<size; i++)
2310 if (output[i]<min_elem)
2316 swap(output[0], output[min_index]);
2317 swap(index[0], index[min_index]);
2324 SG_SERROR(
"SGVector::linspace():: Not supported for complex128_t\n");
2328 #define COMPLEX128_ERROR_ONEVECARG_RETURNS_T(function, return_type, return_statement) \
2330 inline return_type CMath::function<complex128_t>(SGVector<complex128_t> vector) \
2332 SG_SERROR("CMath::%s():: Not supported for complex128_t\n", \
2337 #define COMPLEX128_ERROR_ONEARG_T(function) \
2339 inline complex128_t CMath::function<complex128_t>(complex128_t a) \
2341 SG_SERROR("CMath::%s():: Not supported for complex128_t\n",\
2343 return complex128_t(0.0, 0.0); \
2346 #define COMPLEX128_ERROR_TWOARGS_T(function) \
2348 inline complex128_t CMath::function<complex128_t>(complex128_t a, complex128_t b) \
2350 SG_SERROR("CMath::%s():: Not supported for complex128_t\n",\
2352 return complex128_t(0.0, 0.0); \
2355 #define COMPLEX128_ERROR_THREEARGS_T(function) \
2357 inline complex128_t CMath::function<complex128_t>(complex128_t a, complex128_t b, complex128_t c) \
2359 SG_SERROR("CMath::%s():: Not supported for complex128_t\n",\
2361 return complex128_t(0.0, 0.0); \
2364 #define COMPLEX128_ERROR_SORT_T(function) \
2366 inline void CMath::function<complex128_t>(complex128_t* output, int32_t b) \
2368 SG_SERROR("CMath::%s():: Not supported for complex128_t\n",\
2372 #define COMPLEX128_ERROR_ARG_MAX_MIN(function) \
2374 inline int32_t CMath::function<complex128_t>(complex128_t * a, int32_t b, int32_t c, complex128_t * d) \
2377 SG_SERROR("CMath::%s():: Not supported for complex128_t\n",\
2419 #undef COMPLEX128_ERROR_ONEARG
2420 #undef COMPLEX128_ERROR_ONEARG_T
2421 #undef COMPLEX128_ERROR_TWOARGS_T
2422 #undef COMPLEX128_ERROR_THREEARGS_T
2423 #undef COMPLEX128_STDMATH
2424 #undef COMPLEX128_ERROR_SORT_T
static float64_t sin(float64_t x)
tanh(x), x being a complex128_t
static float64_t normal_random(float64_t mean, float64_t std_dev)
static const float32_t F_MAX_VAL32
static const float64_t MACHINE_EPSILON
static bool strtof(const char *str, float32_t *float_result)
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
static int is_finite(double f)
checks whether a float is finite
static float64_t Align(char *seq1, char *seq2, int32_t l1, int32_t l2, float64_t gapCost)
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)
static void linspace(float64_t *output, float64_t start, float64_t end, int32_t n=100)
static float64_t ceil(float64_t d)
static bool strtod(const char *str, float64_t *double_result)
static complex128_t pow(complex128_t x, int32_t n)
virtual ~CMath()
Destructor - frees logtable.
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 nmin(float64_t *output, T *index, int32_t size, int32_t n)
static void qsort_index(T1 *output, T2 *index, uint32_t size)
static void qsort_index(complex128_t *output, T *index, uint32_t size)
qsort_index not implemented for complex128_t
static float64_t log10(float64_t v)
#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 float64_t atan2(float64_t y, float64_t x)
atan(x), x being a complex128_t not implemented
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 float64_t atan(float64_t x)
tan(x), x being a complex128_t
static const float64_t F_MAX_VAL64
static float64_t cosh(float64_t x)
acos(x), x being a complex128_t not implemented
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)
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 float32_t invsqrt(float32_t x)
x^0.5, x being a complex128_t
static uint8_t byte(T word, uint16_t p)
static complex128_t pow(float64_t x, complex128_t n)
CMath()
Constructor - initializes log-table.
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)
bool operator()(index_t i, index_t j) const
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 cos(float64_t x)
sinh(x), x being a complex128_t
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)
static float64_t tan(float64_t x)
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
static float64_t sinh(float64_t x)
asin(x), x being a complex128_t not implemented
: Pseudo random number geneartor
static float64_t get_abs_tolerance(float64_t true_value, float64_t rel_tolerance)
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)
static int is_infinity(double f)
checks whether a float is infinity
static float64_t acos(float64_t x)
cos(x), x being a complex128_t
static float64_t abs(complex128_t a)
static float64_t log2(float64_t v)
log10(x), x being a complex128_t
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 tanh(float64_t x)
atan2(x), x being a complex128_t not implemented
static int is_nan(double f)
checks whether a float is nan
static float64_t dot(const float64_t *v1, const char *v2, int32_t n)
Compute dot product between v1 and v2.
virtual const char * get_name() const
static float64_t asin(float64_t x)
sin(x), x being a complex128_t
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 void sort(int32_t *a, int32_t cols, int32_t sort_col=0)
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)
static uint32_t generate_seed()
static index_t floor_log(index_t n)
log(x), x being a complex128_t
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)
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 bool strtold(const char *str, floatmax_t *long_double_result)
static int32_t pow(bool x, int32_t n)
static const float64_t NOT_A_NUMBER
not a number
static void qsort_backward_index(T1 *output, T2 *index, int32_t size)
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