numo-narray 0.9.0.1-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/README.md +47 -0
- data/Rakefile +41 -0
- data/ext/numo/narray/SFMT-params.h +97 -0
- data/ext/numo/narray/SFMT-params19937.h +46 -0
- data/ext/numo/narray/SFMT.c +620 -0
- data/ext/numo/narray/SFMT.h +157 -0
- data/ext/numo/narray/array.c +525 -0
- data/ext/numo/narray/data.c +901 -0
- data/ext/numo/narray/depend.erb +33 -0
- data/ext/numo/narray/extconf.rb +117 -0
- data/ext/numo/narray/gen/bit.erb.c +811 -0
- data/ext/numo/narray/gen/cogen.rb +18 -0
- data/ext/numo/narray/gen/def/dcomplex.rb +32 -0
- data/ext/numo/narray/gen/def/dfloat.rb +30 -0
- data/ext/numo/narray/gen/def/int16.rb +29 -0
- data/ext/numo/narray/gen/def/int32.rb +29 -0
- data/ext/numo/narray/gen/def/int64.rb +29 -0
- data/ext/numo/narray/gen/def/int8.rb +29 -0
- data/ext/numo/narray/gen/def/robject.rb +30 -0
- data/ext/numo/narray/gen/def/scomplex.rb +32 -0
- data/ext/numo/narray/gen/def/sfloat.rb +30 -0
- data/ext/numo/narray/gen/def/uint16.rb +29 -0
- data/ext/numo/narray/gen/def/uint32.rb +29 -0
- data/ext/numo/narray/gen/def/uint64.rb +29 -0
- data/ext/numo/narray/gen/def/uint8.rb +29 -0
- data/ext/numo/narray/gen/dtype.erb.c +328 -0
- data/ext/numo/narray/gen/tmpl/accum.c +36 -0
- data/ext/numo/narray/gen/tmpl/accum_binary.c +75 -0
- data/ext/numo/narray/gen/tmpl/accum_index.c +58 -0
- data/ext/numo/narray/gen/tmpl/allocate.c +35 -0
- data/ext/numo/narray/gen/tmpl/aref.c +51 -0
- data/ext/numo/narray/gen/tmpl/aset.c +61 -0
- data/ext/numo/narray/gen/tmpl/binary.c +53 -0
- data/ext/numo/narray/gen/tmpl/binary2.c +55 -0
- data/ext/numo/narray/gen/tmpl/binary_s.c +34 -0
- data/ext/numo/narray/gen/tmpl/bit_binary.c +94 -0
- data/ext/numo/narray/gen/tmpl/bit_count.c +82 -0
- data/ext/numo/narray/gen/tmpl/bit_unary.c +77 -0
- data/ext/numo/narray/gen/tmpl/cast.c +37 -0
- data/ext/numo/narray/gen/tmpl/cast_array.c +79 -0
- data/ext/numo/narray/gen/tmpl/cast_numeric.c +22 -0
- data/ext/numo/narray/gen/tmpl/coerce_cast.c +8 -0
- data/ext/numo/narray/gen/tmpl/cond_binary.c +51 -0
- data/ext/numo/narray/gen/tmpl/cond_unary.c +45 -0
- data/ext/numo/narray/gen/tmpl/cum.c +42 -0
- data/ext/numo/narray/gen/tmpl/each.c +43 -0
- data/ext/numo/narray/gen/tmpl/each_with_index.c +64 -0
- data/ext/numo/narray/gen/tmpl/extract.c +23 -0
- data/ext/numo/narray/gen/tmpl/eye.c +91 -0
- data/ext/numo/narray/gen/tmpl/fill.c +38 -0
- data/ext/numo/narray/gen/tmpl/format.c +60 -0
- data/ext/numo/narray/gen/tmpl/format_to_a.c +47 -0
- data/ext/numo/narray/gen/tmpl/head.c +25 -0
- data/ext/numo/narray/gen/tmpl/inspect.c +16 -0
- data/ext/numo/narray/gen/tmpl/map_with_index.c +94 -0
- data/ext/numo/narray/gen/tmpl/median.c +44 -0
- data/ext/numo/narray/gen/tmpl/minmax.c +47 -0
- data/ext/numo/narray/gen/tmpl/poly.c +49 -0
- data/ext/numo/narray/gen/tmpl/pow.c +74 -0
- data/ext/numo/narray/gen/tmpl/powint.c +17 -0
- data/ext/numo/narray/gen/tmpl/qsort.c +149 -0
- data/ext/numo/narray/gen/tmpl/rand.c +33 -0
- data/ext/numo/narray/gen/tmpl/rand_norm.c +46 -0
- data/ext/numo/narray/gen/tmpl/robj_allocate.c +32 -0
- data/ext/numo/narray/gen/tmpl/seq.c +61 -0
- data/ext/numo/narray/gen/tmpl/set2.c +56 -0
- data/ext/numo/narray/gen/tmpl/sort.c +36 -0
- data/ext/numo/narray/gen/tmpl/sort_index.c +86 -0
- data/ext/numo/narray/gen/tmpl/store.c +31 -0
- data/ext/numo/narray/gen/tmpl/store_array.c +5 -0
- data/ext/numo/narray/gen/tmpl/store_from.c +53 -0
- data/ext/numo/narray/gen/tmpl/store_numeric.c +22 -0
- data/ext/numo/narray/gen/tmpl/to_a.c +41 -0
- data/ext/numo/narray/gen/tmpl/unary.c +58 -0
- data/ext/numo/narray/gen/tmpl/unary2.c +58 -0
- data/ext/numo/narray/gen/tmpl/unary_s.c +57 -0
- data/ext/numo/narray/index.c +822 -0
- data/ext/numo/narray/kwarg.c +79 -0
- data/ext/numo/narray/math.c +140 -0
- data/ext/numo/narray/narray.c +1539 -0
- data/ext/numo/narray/ndloop.c +1928 -0
- data/ext/numo/narray/numo/compat.h +23 -0
- data/ext/numo/narray/numo/intern.h +112 -0
- data/ext/numo/narray/numo/narray.h +411 -0
- data/ext/numo/narray/numo/ndloop.h +99 -0
- data/ext/numo/narray/numo/template.h +140 -0
- data/ext/numo/narray/numo/types/bit.h +19 -0
- data/ext/numo/narray/numo/types/complex.h +410 -0
- data/ext/numo/narray/numo/types/complex_macro.h +205 -0
- data/ext/numo/narray/numo/types/dcomplex.h +11 -0
- data/ext/numo/narray/numo/types/dfloat.h +12 -0
- data/ext/numo/narray/numo/types/float_def.h +34 -0
- data/ext/numo/narray/numo/types/float_macro.h +277 -0
- data/ext/numo/narray/numo/types/int16.h +12 -0
- data/ext/numo/narray/numo/types/int32.h +12 -0
- data/ext/numo/narray/numo/types/int64.h +12 -0
- data/ext/numo/narray/numo/types/int8.h +12 -0
- data/ext/numo/narray/numo/types/int_macro.h +34 -0
- data/ext/numo/narray/numo/types/robj_macro.h +218 -0
- data/ext/numo/narray/numo/types/robject.h +21 -0
- data/ext/numo/narray/numo/types/scomplex.h +11 -0
- data/ext/numo/narray/numo/types/sfloat.h +13 -0
- data/ext/numo/narray/numo/types/uint16.h +12 -0
- data/ext/numo/narray/numo/types/uint32.h +12 -0
- data/ext/numo/narray/numo/types/uint64.h +12 -0
- data/ext/numo/narray/numo/types/uint8.h +12 -0
- data/ext/numo/narray/numo/types/uint_macro.h +31 -0
- data/ext/numo/narray/numo/types/xint_macro.h +133 -0
- data/ext/numo/narray/rand.c +87 -0
- data/ext/numo/narray/step.c +506 -0
- data/ext/numo/narray/struct.c +872 -0
- data/lib/2.1/numo/narray.so +0 -0
- data/lib/2.2/numo/narray.so +0 -0
- data/lib/2.3/numo/narray.so +0 -0
- data/lib/erbpp.rb +286 -0
- data/lib/erbpp/line_number.rb +126 -0
- data/lib/erbpp/narray_def.rb +338 -0
- data/lib/numo/narray.rb +6 -0
- data/numo-narray.gemspec +35 -0
- data/spec/bit_spec.rb +93 -0
- data/spec/narray_spec.rb +249 -0
- metadata +238 -0
@@ -0,0 +1,205 @@
|
|
1
|
+
#include "float_def.h"
|
2
|
+
|
3
|
+
EXTERN double round(double);
|
4
|
+
EXTERN double log2(double);
|
5
|
+
EXTERN double exp2(double);
|
6
|
+
EXTERN double exp10(double);
|
7
|
+
|
8
|
+
#define r_abs(x) abs(x)
|
9
|
+
#define r_sqrt(x) sqrt(x)
|
10
|
+
#define r_exp(x) exp(x)
|
11
|
+
#define r_log(x) log(x)
|
12
|
+
#define r_sin(x) sin(x)
|
13
|
+
#define r_cos(x) cos(x)
|
14
|
+
#define r_sinh(x) sinh(x)
|
15
|
+
#define r_cosh(x) cosh(x)
|
16
|
+
#define r_tanh(x) tanh(x)
|
17
|
+
#define r_atan2(y,x) atan2(y,x)
|
18
|
+
#define r_hypot(x,y) hypot(x,y)
|
19
|
+
|
20
|
+
#include "complex.h"
|
21
|
+
|
22
|
+
static inline dtype c_from_scomplex(scomplex x) {
|
23
|
+
dtype z;
|
24
|
+
REAL(z) = REAL(x);
|
25
|
+
IMAG(z) = IMAG(x);
|
26
|
+
return z;
|
27
|
+
}
|
28
|
+
|
29
|
+
static inline dtype c_from_dcomplex(dcomplex x) {
|
30
|
+
dtype z;
|
31
|
+
REAL(z) = REAL(x);
|
32
|
+
IMAG(z) = IMAG(x);
|
33
|
+
return z;
|
34
|
+
}
|
35
|
+
|
36
|
+
/* --------------------------- */
|
37
|
+
|
38
|
+
#define m_zero c_zero()
|
39
|
+
#define m_one c_one()
|
40
|
+
|
41
|
+
#define m_num_to_data(x) NUM2COMP(x)
|
42
|
+
#define m_data_to_num(x) COMP2NUM(x)
|
43
|
+
|
44
|
+
#define m_from_double(x) c_new(x,0)
|
45
|
+
#define m_from_real(x) c_new(x,0)
|
46
|
+
#define m_from_scomplex(x) c_from_scomplex(x)
|
47
|
+
#define m_from_dcomplex(x) c_from_dcomplex(x)
|
48
|
+
|
49
|
+
#define m_extract(x) COMP2NUM(*(dtype*)x)
|
50
|
+
|
51
|
+
#define m_real(x) REAL(x)
|
52
|
+
#define m_imag(x) IMAG(x)
|
53
|
+
#define m_set_real(x,y) c_set_real(x,y)
|
54
|
+
#define m_set_imag(x,y) c_set_imag(x,y)
|
55
|
+
|
56
|
+
#define m_add(x,y) c_add(x,y)
|
57
|
+
#define m_sub(x,y) c_sub(x,y)
|
58
|
+
#define m_mul(x,y) c_mul(x,y)
|
59
|
+
#define m_div(x,y) c_div(x,y)
|
60
|
+
#define m_mod(x,y) c_mod(x,y)
|
61
|
+
#define m_pow(x,y) c_pow(x,y)
|
62
|
+
#define m_pow_int(x,y) c_pow_int(x,y)
|
63
|
+
|
64
|
+
#define m_minus(x) c_minus(x)
|
65
|
+
#define m_inverse(x) c_inverse(x)
|
66
|
+
#define m_square(x) c_square(x)
|
67
|
+
#define m_im(x) c_im(x)
|
68
|
+
|
69
|
+
#define m_conj(x) c_new(REAL(x),-IMAG(x))
|
70
|
+
#define m_abs(x) c_abs(x)
|
71
|
+
#define m_arg(x) atan2(IMAG(x),REAL(x))
|
72
|
+
|
73
|
+
#define m_eq(x,y) c_eq(x,y)
|
74
|
+
#define m_ne(x,y) c_ne(x,y)
|
75
|
+
#define m_nearly_eq(x,y) c_nearly_eq(x,y)
|
76
|
+
|
77
|
+
#define m_isnan(x) c_isnan(x)
|
78
|
+
#define m_isinf(x) c_isinf(x)
|
79
|
+
#define m_isfinite(x) c_isfinite(x)
|
80
|
+
|
81
|
+
#define m_sum(x,y) {if (!c_isnan(x)) {y=c_add(x,y);}}
|
82
|
+
#define m_sum_init INT2FIX(0)
|
83
|
+
|
84
|
+
#define m_mulsum(x,y,z) {z = c_add(c_mul(x,y),z);}
|
85
|
+
#define m_mulsum_init INT2FIX(0)
|
86
|
+
|
87
|
+
#define m_rand c_new(to_res53(gen_rand64()),to_res53(gen_rand64()))
|
88
|
+
#define m_rand_norm(a) rand_norm(a)
|
89
|
+
|
90
|
+
#define m_sprintf(s,x) sprintf(s,"%g%+gi",REAL(x),IMAG(x))
|
91
|
+
|
92
|
+
#define m_sqrt(x) c_sqrt(x)
|
93
|
+
#define m_cbrt(x) c_cbrt(x)
|
94
|
+
#define m_log(x) c_log(x)
|
95
|
+
#define m_log2(x) c_log2(x)
|
96
|
+
#define m_log10(x) c_log10(x)
|
97
|
+
#define m_exp(x) c_exp(x)
|
98
|
+
#define m_exp2(x) c_exp2(x)
|
99
|
+
#define m_exp10(x) c_exp10(x)
|
100
|
+
#define m_sin(x) c_sin(x)
|
101
|
+
#define m_cos(x) c_cos(x)
|
102
|
+
#define m_tan(x) c_tan(x)
|
103
|
+
#define m_asin(x) c_asin(x)
|
104
|
+
#define m_acos(x) c_acos(x)
|
105
|
+
#define m_atan(x) c_atan(x)
|
106
|
+
#define m_sinh(x) c_sinh(x)
|
107
|
+
#define m_cosh(x) c_cosh(x)
|
108
|
+
#define m_tanh(x) c_tanh(x)
|
109
|
+
#define m_asinh(x) c_asinh(x)
|
110
|
+
#define m_acosh(x) c_acosh(x)
|
111
|
+
#define m_atanh(x) c_atanh(x)
|
112
|
+
#define m_hypot(x,y) c_hypot(x,y)
|
113
|
+
|
114
|
+
static inline dtype f_sum(size_t n, char *p, ssize_t stride)
|
115
|
+
{
|
116
|
+
size_t i=n;
|
117
|
+
dtype x,y;
|
118
|
+
|
119
|
+
y = c_zero();
|
120
|
+
for (; i--;) {
|
121
|
+
x = *(dtype*)p;
|
122
|
+
if (!c_isnan(x)) {
|
123
|
+
y = c_add(x,y);
|
124
|
+
}
|
125
|
+
p += stride;
|
126
|
+
}
|
127
|
+
return y;
|
128
|
+
}
|
129
|
+
|
130
|
+
static inline dtype f_prod(size_t n, char *p, ssize_t stride)
|
131
|
+
{
|
132
|
+
size_t i=n;
|
133
|
+
dtype x,y;
|
134
|
+
|
135
|
+
y = c_one();
|
136
|
+
for (; i--;) {
|
137
|
+
x = *(dtype*)p;
|
138
|
+
if (!c_isnan(x)) {
|
139
|
+
y = c_mul(x,y);
|
140
|
+
}
|
141
|
+
p += stride;
|
142
|
+
}
|
143
|
+
return y;
|
144
|
+
}
|
145
|
+
|
146
|
+
static inline dtype f_mean(size_t n, char *p, ssize_t stride)
|
147
|
+
{
|
148
|
+
size_t i=n;
|
149
|
+
size_t count=0;
|
150
|
+
dtype x,y;
|
151
|
+
|
152
|
+
y = c_zero();
|
153
|
+
for (; i--;) {
|
154
|
+
x = *(dtype*)p;
|
155
|
+
if (!c_isnan(x)) {
|
156
|
+
y = c_add(x,y);
|
157
|
+
count++;
|
158
|
+
}
|
159
|
+
p += stride;
|
160
|
+
}
|
161
|
+
return c_div_r(y,count);
|
162
|
+
}
|
163
|
+
|
164
|
+
static inline rtype f_var(size_t n, char *p, ssize_t stride)
|
165
|
+
{
|
166
|
+
size_t i=n;
|
167
|
+
size_t count=0;
|
168
|
+
dtype x,m;
|
169
|
+
rtype y=0;
|
170
|
+
|
171
|
+
m = f_mean(n,p,stride);
|
172
|
+
|
173
|
+
for (; i--;) {
|
174
|
+
x = *(dtype*)p;
|
175
|
+
if (!c_isnan(x)) {
|
176
|
+
y += c_abs_square(c_sub(x,m));
|
177
|
+
count++;
|
178
|
+
}
|
179
|
+
p += stride;
|
180
|
+
}
|
181
|
+
return y/(count-1);
|
182
|
+
}
|
183
|
+
|
184
|
+
static inline rtype f_stddev(size_t n, char *p, ssize_t stride)
|
185
|
+
{
|
186
|
+
return r_sqrt(f_var(n,p,stride));
|
187
|
+
}
|
188
|
+
|
189
|
+
static inline rtype f_rms(size_t n, char *p, ssize_t stride)
|
190
|
+
{
|
191
|
+
size_t i=n;
|
192
|
+
size_t count=0;
|
193
|
+
dtype x;
|
194
|
+
rtype y=0;
|
195
|
+
|
196
|
+
for (; i--;) {
|
197
|
+
x = *(dtype*)p;
|
198
|
+
if (!c_isnan(x)) {
|
199
|
+
y += c_abs_square(x);
|
200
|
+
count++;
|
201
|
+
}
|
202
|
+
p += stride;
|
203
|
+
}
|
204
|
+
return r_sqrt(y/count);
|
205
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
typedef dcomplex dtype;
|
2
|
+
typedef double rtype;
|
3
|
+
#define cT numo_cDComplex
|
4
|
+
#define cRT numo_cDFloat
|
5
|
+
#define mTM numo_mDComplexMath
|
6
|
+
|
7
|
+
#include "complex_macro.h"
|
8
|
+
|
9
|
+
static inline bool c_nearly_eq(dtype x, dtype y) {
|
10
|
+
return c_abs(c_sub(x,y)) <= (c_abs(x)+c_abs(y))*DBL_EPSILON*2;
|
11
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
typedef double dtype;
|
2
|
+
typedef double rtype;
|
3
|
+
#define cT numo_cDFloat
|
4
|
+
#define cRT numo_cDFloat
|
5
|
+
#define mTM numo_mDFloatMath
|
6
|
+
|
7
|
+
#include "float_macro.h"
|
8
|
+
|
9
|
+
#define m_min_init numo_dfloat_new_dim0(0.0/0.0)
|
10
|
+
#define m_max_init numo_dfloat_new_dim0(0.0/0.0)
|
11
|
+
#define m_extract(x) rb_float_new(*(double*)x)
|
12
|
+
#define m_nearly_eq(x,y) (fabs(x-y)<=(fabs(x)+fabs(y))*DBL_EPSILON*2)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#ifndef DBL_EPSILON
|
2
|
+
#define DBL_EPSILON 2.2204460492503131e-16
|
3
|
+
#endif
|
4
|
+
#ifndef FLT_EPSILON
|
5
|
+
#define FLT_EPSILON 1.1920928955078125e-07
|
6
|
+
#endif
|
7
|
+
#ifndef DBL_MAX
|
8
|
+
#define DBL_MAX 1.7976931348623157e+308
|
9
|
+
#endif
|
10
|
+
#ifndef DBL_MAX
|
11
|
+
#define DBL_MAX 1.7976931348623157e+308
|
12
|
+
#endif
|
13
|
+
#ifndef FLT_MIN
|
14
|
+
#define FLT_MIN 1.1754943508222875e-38
|
15
|
+
#endif
|
16
|
+
#ifndef FLT_MAX
|
17
|
+
#define FLT_MAX 3.4028234663852886e+38
|
18
|
+
#endif
|
19
|
+
|
20
|
+
#ifndef M_PI_2
|
21
|
+
#define M_PI_2 1.57079632679489661923 /* pi/2 */
|
22
|
+
#endif
|
23
|
+
#ifndef M_LOG2E
|
24
|
+
#define M_LOG2E 1.4426950408889634074 /* log_2 e */
|
25
|
+
#endif
|
26
|
+
#ifndef M_LOG10E
|
27
|
+
#define M_LOG10E 0.43429448190325182765 /* log_10 e */
|
28
|
+
#endif
|
29
|
+
#ifndef M_LN2
|
30
|
+
#define M_LN2 0.69314718055994530942 /* log_e 2 */
|
31
|
+
#endif
|
32
|
+
#ifndef M_LN10
|
33
|
+
#define M_LN10 2.30258509299404568402 /* log_e 10 */
|
34
|
+
#endif
|
@@ -0,0 +1,277 @@
|
|
1
|
+
#include "float_def.h"
|
2
|
+
|
3
|
+
EXTERN double round(double);
|
4
|
+
EXTERN double log2(double);
|
5
|
+
EXTERN double exp2(double);
|
6
|
+
#ifdef HAVE_EXP10
|
7
|
+
EXTERN double exp10(double);
|
8
|
+
#else
|
9
|
+
EXTERN double pow(double, double);
|
10
|
+
#endif
|
11
|
+
|
12
|
+
#define m_zero 0.0
|
13
|
+
#define m_one 1.0
|
14
|
+
|
15
|
+
#define m_num_to_data(x) NUM2DBL(x)
|
16
|
+
#define m_data_to_num(x) rb_float_new(x)
|
17
|
+
|
18
|
+
#define m_from_double(x) (x)
|
19
|
+
#define m_from_real(x) (x)
|
20
|
+
|
21
|
+
#define m_add(x,y) ((x)+(y))
|
22
|
+
#define m_sub(x,y) ((x)-(y))
|
23
|
+
#define m_mul(x,y) ((x)*(y))
|
24
|
+
#define m_div(x,y) ((x)/(y))
|
25
|
+
#define m_div_check(x,y) ((y)==0)
|
26
|
+
#define m_mod(x,y) fmod(x,y)
|
27
|
+
#define m_divmod(x,y,a,b) {a=(x)/(y); b=m_mod(x,y);}
|
28
|
+
#define m_pow(x,y) pow(x,y)
|
29
|
+
#define m_pow_int(x,y) pow_int(x,y)
|
30
|
+
|
31
|
+
#define m_abs(x) fabs(x)
|
32
|
+
#define m_minus(x) (-(x))
|
33
|
+
#define m_inverse(x) (1/(x))
|
34
|
+
#define m_square(x) ((x)*(x))
|
35
|
+
#define m_floor(x) floor(x)
|
36
|
+
#define m_round(x) round(x)
|
37
|
+
#define m_ceil(x) ceil(x)
|
38
|
+
|
39
|
+
#define m_eq(x,y) ((x)==(y))
|
40
|
+
#define m_ne(x,y) ((x)!=(y))
|
41
|
+
#define m_gt(x,y) ((x)>(y))
|
42
|
+
#define m_ge(x,y) ((x)>=(y))
|
43
|
+
#define m_lt(x,y) ((x)<(y))
|
44
|
+
#define m_le(x,y) ((x)<=(y))
|
45
|
+
|
46
|
+
#define m_isnan(x) isnan(x)
|
47
|
+
#define m_isinf(x) isinf(x)
|
48
|
+
#define m_isfinite(x) isfinite(x)
|
49
|
+
|
50
|
+
#define m_mulsum(x,y,z) {z += x*y;}
|
51
|
+
#define m_mulsum_init INT2FIX(0)
|
52
|
+
|
53
|
+
#define m_rand to_res53(gen_rand64())
|
54
|
+
#define m_rand_norm(a) rand_norm(a)
|
55
|
+
|
56
|
+
#define m_sprintf(s,x) sprintf(s,"%g",x)
|
57
|
+
|
58
|
+
#define cmp(a,b) \
|
59
|
+
(m_isnan(qsort_cast(a)) ? (m_isnan(qsort_cast(b)) ? 0 : 1) : \
|
60
|
+
(m_isnan(qsort_cast(b)) ? -1 : \
|
61
|
+
((qsort_cast(a)==qsort_cast(b)) ? 0 : \
|
62
|
+
(qsort_cast(a) > qsort_cast(b)) ? 1 : -1)))
|
63
|
+
|
64
|
+
#define cmpgt(a,b) \
|
65
|
+
((m_isnan(qsort_cast(a)) && !m_isnan(qsort_cast(b))) || \
|
66
|
+
(qsort_cast(a) > qsort_cast(b)))
|
67
|
+
|
68
|
+
#define m_sqrt(x) sqrt(x)
|
69
|
+
#define m_cbrt(x) cbrt(x)
|
70
|
+
#define m_log(x) log(x)
|
71
|
+
#define m_log2(x) log2(x)
|
72
|
+
#define m_log10(x) log10(x)
|
73
|
+
#define m_exp(x) exp(x)
|
74
|
+
#define m_exp2(x) exp2(x)
|
75
|
+
#ifdef HAVE_EXP10
|
76
|
+
#define m_exp10(x) exp10(x)
|
77
|
+
#else
|
78
|
+
#define m_exp10(x) pow(10, x)
|
79
|
+
#endif
|
80
|
+
#define m_sin(x) sin(x)
|
81
|
+
#define m_cos(x) cos(x)
|
82
|
+
#define m_tan(x) tan(x)
|
83
|
+
#define m_asin(x) asin(x)
|
84
|
+
#define m_acos(x) acos(x)
|
85
|
+
#define m_atan(x) atan(x)
|
86
|
+
#define m_sinh(x) sinh(x)
|
87
|
+
#define m_cosh(x) cosh(x)
|
88
|
+
#define m_tanh(x) tanh(x)
|
89
|
+
#define m_asinh(x) asinh(x)
|
90
|
+
#define m_acosh(x) acosh(x)
|
91
|
+
#define m_atanh(x) atanh(x)
|
92
|
+
#define m_atan2(x,y) atan2(x,y)
|
93
|
+
#define m_hypot(x,y) hypot(x,y)
|
94
|
+
|
95
|
+
#define m_erf(x) erf(x)
|
96
|
+
#define m_erfc(x) erfc(x)
|
97
|
+
#define m_ldexp(x,y) ldexp(x,y)
|
98
|
+
#define m_frexp(x,exp) frexp(x,exp)
|
99
|
+
|
100
|
+
static inline dtype pow_int(dtype x, int p)
|
101
|
+
{
|
102
|
+
dtype r=1;
|
103
|
+
switch(p) {
|
104
|
+
case 0: return 1;
|
105
|
+
case 1: return x;
|
106
|
+
case 2: return x*x;
|
107
|
+
case 3: return x*x*x;
|
108
|
+
case 4: x=x*x; return x*x;
|
109
|
+
}
|
110
|
+
if (p<0) return 1/pow_int(x,-p);
|
111
|
+
if (p>64) return pow(x,p);
|
112
|
+
while (p) {
|
113
|
+
if (p&1) r *= x;
|
114
|
+
x *= x;
|
115
|
+
p >>= 1;
|
116
|
+
}
|
117
|
+
return r;
|
118
|
+
}
|
119
|
+
|
120
|
+
|
121
|
+
static inline dtype f_sum(size_t n, char *p, ssize_t stride)
|
122
|
+
{
|
123
|
+
size_t i=n;
|
124
|
+
dtype x,y=0;
|
125
|
+
|
126
|
+
for (; i--;) {
|
127
|
+
x = *(dtype*)p;
|
128
|
+
if (!m_isnan(x)) {
|
129
|
+
y += x;
|
130
|
+
}
|
131
|
+
p += stride;
|
132
|
+
}
|
133
|
+
return y;
|
134
|
+
}
|
135
|
+
|
136
|
+
static inline dtype f_prod(size_t n, char *p, ssize_t stride)
|
137
|
+
{
|
138
|
+
size_t i=n;
|
139
|
+
dtype x,y=1;
|
140
|
+
|
141
|
+
for (; i--;) {
|
142
|
+
x = *(dtype*)p;
|
143
|
+
if (!m_isnan(x)) {
|
144
|
+
y *= x;
|
145
|
+
}
|
146
|
+
p += stride;
|
147
|
+
}
|
148
|
+
return y;
|
149
|
+
}
|
150
|
+
|
151
|
+
static inline dtype f_mean(size_t n, char *p, ssize_t stride)
|
152
|
+
{
|
153
|
+
size_t i=n;
|
154
|
+
size_t count=0;
|
155
|
+
dtype x,y=0;
|
156
|
+
|
157
|
+
for (; i--;) {
|
158
|
+
x = *(dtype*)p;
|
159
|
+
if (!m_isnan(x)) {
|
160
|
+
y += x;
|
161
|
+
count++;
|
162
|
+
}
|
163
|
+
p += stride;
|
164
|
+
}
|
165
|
+
return y/count;
|
166
|
+
}
|
167
|
+
|
168
|
+
static inline dtype f_var(size_t n, char *p, ssize_t stride)
|
169
|
+
{
|
170
|
+
size_t i=n;
|
171
|
+
size_t count=0;
|
172
|
+
dtype x,y=0;
|
173
|
+
dtype a,m;
|
174
|
+
|
175
|
+
m = f_mean(n,p,stride);
|
176
|
+
|
177
|
+
for (; i--;) {
|
178
|
+
x = *(dtype*)p;
|
179
|
+
if (!m_isnan(x)) {
|
180
|
+
a = x - m;
|
181
|
+
y += a*a;
|
182
|
+
count++;
|
183
|
+
}
|
184
|
+
p += stride;
|
185
|
+
}
|
186
|
+
return y/(count-1);
|
187
|
+
}
|
188
|
+
|
189
|
+
static inline dtype f_stddev(size_t n, char *p, ssize_t stride)
|
190
|
+
{
|
191
|
+
return m_sqrt(f_var(n,p,stride));
|
192
|
+
}
|
193
|
+
|
194
|
+
static inline dtype f_rms(size_t n, char *p, ssize_t stride)
|
195
|
+
{
|
196
|
+
size_t i=n;
|
197
|
+
size_t count=0;
|
198
|
+
dtype x,y=0;
|
199
|
+
|
200
|
+
for (; i--;) {
|
201
|
+
x = *(dtype*)p;
|
202
|
+
if (!m_isnan(x)) {
|
203
|
+
y += x*x;
|
204
|
+
count++;
|
205
|
+
}
|
206
|
+
p += stride;
|
207
|
+
}
|
208
|
+
return m_sqrt(y/count);
|
209
|
+
}
|
210
|
+
|
211
|
+
static inline dtype f_min(size_t n, char *p, ssize_t stride)
|
212
|
+
{
|
213
|
+
dtype x,y;
|
214
|
+
size_t i=n;
|
215
|
+
|
216
|
+
y = *(dtype*)p;
|
217
|
+
p += stride;
|
218
|
+
i--;
|
219
|
+
for (; i--;) {
|
220
|
+
x = *(dtype*)p;
|
221
|
+
if (!m_isnan(x) && (m_isnan(y) || x<y)) {
|
222
|
+
y = x;
|
223
|
+
}
|
224
|
+
p += stride;
|
225
|
+
}
|
226
|
+
return y;
|
227
|
+
}
|
228
|
+
|
229
|
+
static inline dtype f_max(size_t n, char *p, ssize_t stride)
|
230
|
+
{
|
231
|
+
dtype x,y;
|
232
|
+
size_t i=n;
|
233
|
+
|
234
|
+
y = *(dtype*)p;
|
235
|
+
p += stride;
|
236
|
+
i--;
|
237
|
+
for (; i--;) {
|
238
|
+
x = *(dtype*)p;
|
239
|
+
if (!m_isnan(x) && (m_isnan(y) || x>y)) {
|
240
|
+
y = x;
|
241
|
+
}
|
242
|
+
p += stride;
|
243
|
+
}
|
244
|
+
return y;
|
245
|
+
}
|
246
|
+
|
247
|
+
static inline size_t f_min_index(size_t n, char *p, ssize_t stride)
|
248
|
+
{
|
249
|
+
dtype x, y;
|
250
|
+
size_t i, j=0;
|
251
|
+
|
252
|
+
y = *(dtype*)p;
|
253
|
+
for (i=1; i<n; i++) {
|
254
|
+
x = *(dtype*)(p+i*stride);
|
255
|
+
if (!m_isnan(x) && (m_isnan(y) || x<y)) {
|
256
|
+
y = x;
|
257
|
+
j = i;
|
258
|
+
}
|
259
|
+
}
|
260
|
+
return j;
|
261
|
+
}
|
262
|
+
|
263
|
+
static inline size_t f_max_index(size_t n, char *p, ssize_t stride)
|
264
|
+
{
|
265
|
+
dtype x, y;
|
266
|
+
size_t i, j=0;
|
267
|
+
|
268
|
+
y = *(dtype*)p;
|
269
|
+
for (i=1; i<n; i++) {
|
270
|
+
x = *(dtype*)(p+i*stride);
|
271
|
+
if (!m_isnan(x) && (m_isnan(y) || x>y)) {
|
272
|
+
y = x;
|
273
|
+
j = i;
|
274
|
+
}
|
275
|
+
}
|
276
|
+
return j;
|
277
|
+
}
|