ruby-dnn 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dnn/ext/cifar10_loader/cifar10_loader.c +43 -0
- data/lib/dnn/ext/cifar10_loader/extconf.rb +3 -0
- data/lib/dnn/ext/rb_stb_image/rb_stb_image.c +18 -36
- data/lib/dnn/lib/cifar10.rb +8 -6
- data/lib/dnn/lib/image_io.rb +9 -7
- data/lib/dnn/lib/mnist.rb +3 -2
- data/lib/dnn/version.rb +1 -1
- data/ruby-dnn.gemspec +1 -1
- metadata +5 -63
- data/lib/dnn/ext/dataset_loader/dataset_loader.c +0 -90
- data/lib/dnn/ext/dataset_loader/extconf.rb +0 -3
- data/lib/dnn/ext/dataset_loader/numo/compat.h +0 -23
- data/lib/dnn/ext/dataset_loader/numo/extconf.h +0 -13
- data/lib/dnn/ext/dataset_loader/numo/intern.h +0 -117
- data/lib/dnn/ext/dataset_loader/numo/narray.h +0 -430
- data/lib/dnn/ext/dataset_loader/numo/ndloop.h +0 -94
- data/lib/dnn/ext/dataset_loader/numo/template.h +0 -149
- data/lib/dnn/ext/dataset_loader/numo/types/bit.h +0 -33
- data/lib/dnn/ext/dataset_loader/numo/types/complex.h +0 -409
- data/lib/dnn/ext/dataset_loader/numo/types/complex_macro.h +0 -377
- data/lib/dnn/ext/dataset_loader/numo/types/dcomplex.h +0 -44
- data/lib/dnn/ext/dataset_loader/numo/types/dfloat.h +0 -42
- data/lib/dnn/ext/dataset_loader/numo/types/float_def.h +0 -34
- data/lib/dnn/ext/dataset_loader/numo/types/float_macro.h +0 -186
- data/lib/dnn/ext/dataset_loader/numo/types/int16.h +0 -24
- data/lib/dnn/ext/dataset_loader/numo/types/int32.h +0 -24
- data/lib/dnn/ext/dataset_loader/numo/types/int64.h +0 -24
- data/lib/dnn/ext/dataset_loader/numo/types/int8.h +0 -24
- data/lib/dnn/ext/dataset_loader/numo/types/int_macro.h +0 -41
- data/lib/dnn/ext/dataset_loader/numo/types/real_accum.h +0 -486
- data/lib/dnn/ext/dataset_loader/numo/types/robj_macro.h +0 -75
- data/lib/dnn/ext/dataset_loader/numo/types/robject.h +0 -27
- data/lib/dnn/ext/dataset_loader/numo/types/scomplex.h +0 -44
- data/lib/dnn/ext/dataset_loader/numo/types/sfloat.h +0 -43
- data/lib/dnn/ext/dataset_loader/numo/types/uint16.h +0 -21
- data/lib/dnn/ext/dataset_loader/numo/types/uint32.h +0 -21
- data/lib/dnn/ext/dataset_loader/numo/types/uint64.h +0 -21
- data/lib/dnn/ext/dataset_loader/numo/types/uint8.h +0 -21
- data/lib/dnn/ext/dataset_loader/numo/types/uint_macro.h +0 -32
- data/lib/dnn/ext/dataset_loader/numo/types/xint_macro.h +0 -189
- data/lib/dnn/ext/rb_stb_image/numo/compat.h +0 -23
- data/lib/dnn/ext/rb_stb_image/numo/extconf.h +0 -13
- data/lib/dnn/ext/rb_stb_image/numo/intern.h +0 -117
- data/lib/dnn/ext/rb_stb_image/numo/narray.h +0 -430
- data/lib/dnn/ext/rb_stb_image/numo/ndloop.h +0 -94
- data/lib/dnn/ext/rb_stb_image/numo/template.h +0 -149
- data/lib/dnn/ext/rb_stb_image/numo/types/bit.h +0 -33
- data/lib/dnn/ext/rb_stb_image/numo/types/complex.h +0 -409
- data/lib/dnn/ext/rb_stb_image/numo/types/complex_macro.h +0 -377
- data/lib/dnn/ext/rb_stb_image/numo/types/dcomplex.h +0 -44
- data/lib/dnn/ext/rb_stb_image/numo/types/dfloat.h +0 -42
- data/lib/dnn/ext/rb_stb_image/numo/types/float_def.h +0 -34
- data/lib/dnn/ext/rb_stb_image/numo/types/float_macro.h +0 -186
- data/lib/dnn/ext/rb_stb_image/numo/types/int16.h +0 -24
- data/lib/dnn/ext/rb_stb_image/numo/types/int32.h +0 -24
- data/lib/dnn/ext/rb_stb_image/numo/types/int64.h +0 -24
- data/lib/dnn/ext/rb_stb_image/numo/types/int8.h +0 -24
- data/lib/dnn/ext/rb_stb_image/numo/types/int_macro.h +0 -41
- data/lib/dnn/ext/rb_stb_image/numo/types/real_accum.h +0 -486
- data/lib/dnn/ext/rb_stb_image/numo/types/robj_macro.h +0 -75
- data/lib/dnn/ext/rb_stb_image/numo/types/robject.h +0 -27
- data/lib/dnn/ext/rb_stb_image/numo/types/scomplex.h +0 -44
- data/lib/dnn/ext/rb_stb_image/numo/types/sfloat.h +0 -43
- data/lib/dnn/ext/rb_stb_image/numo/types/uint16.h +0 -21
- data/lib/dnn/ext/rb_stb_image/numo/types/uint32.h +0 -21
- data/lib/dnn/ext/rb_stb_image/numo/types/uint64.h +0 -21
- data/lib/dnn/ext/rb_stb_image/numo/types/uint8.h +0 -21
- data/lib/dnn/ext/rb_stb_image/numo/types/uint_macro.h +0 -32
- data/lib/dnn/ext/rb_stb_image/numo/types/xint_macro.h +0 -189
@@ -1,377 +0,0 @@
|
|
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) fabs(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_abs(x) c_abs(x)
|
65
|
-
#define m_minus(x) c_minus(x)
|
66
|
-
#define m_reciprocal(x) c_reciprocal(x)
|
67
|
-
#define m_square(x) c_square(x)
|
68
|
-
#define m_floor(x) c_new(floor(REAL(x)),floor(IMAG(x)))
|
69
|
-
#define m_round(x) c_new(round(REAL(x)),round(IMAG(x)))
|
70
|
-
#define m_ceil(x) c_new(ceil(REAL(x)),ceil(IMAG(x)))
|
71
|
-
#define m_trunc(x) c_new(trunc(REAL(x)),trunc(IMAG(x)))
|
72
|
-
#define m_rint(x) c_new(rint(REAL(x)),rint(IMAG(x)))
|
73
|
-
#define m_sign(x) c_new( \
|
74
|
-
((REAL(x)==0) ? 0.0:((REAL(x)>0) ? 1.0:((REAL(x)<0) ? -1.0:REAL(x)))), \
|
75
|
-
((IMAG(x)==0) ? 0.0:((IMAG(x)>0) ? 1.0:((IMAG(x)<0) ? -1.0:IMAG(x)))))
|
76
|
-
#define m_copysign(x,y) c_new(copysign(REAL(x),REAL(y)),copysign(IMAG(x),IMAG(y)))
|
77
|
-
|
78
|
-
#define m_im(x) c_im(x)
|
79
|
-
#define m_conj(x) c_new(REAL(x),-IMAG(x))
|
80
|
-
#define m_arg(x) atan2(IMAG(x),REAL(x))
|
81
|
-
|
82
|
-
#define m_eq(x,y) c_eq(x,y)
|
83
|
-
#define m_ne(x,y) c_ne(x,y)
|
84
|
-
#define m_nearly_eq(x,y) c_nearly_eq(x,y)
|
85
|
-
|
86
|
-
#define m_isnan(x) c_isnan(x)
|
87
|
-
#define m_isinf(x) c_isinf(x)
|
88
|
-
#define m_isposinf(x) c_isposinf(x)
|
89
|
-
#define m_isneginf(x) c_isneginf(x)
|
90
|
-
#define m_isfinite(x) c_isfinite(x)
|
91
|
-
|
92
|
-
#define m_sprintf(s,x) sprintf(s,"%g%+gi",REAL(x),IMAG(x))
|
93
|
-
|
94
|
-
#define m_sqrt(x) c_sqrt(x)
|
95
|
-
#define m_cbrt(x) c_cbrt(x)
|
96
|
-
#define m_log(x) c_log(x)
|
97
|
-
#define m_log2(x) c_log2(x)
|
98
|
-
#define m_log10(x) c_log10(x)
|
99
|
-
#define m_exp(x) c_exp(x)
|
100
|
-
#define m_exp2(x) c_exp2(x)
|
101
|
-
#define m_exp10(x) c_exp10(x)
|
102
|
-
#define m_sin(x) c_sin(x)
|
103
|
-
#define m_cos(x) c_cos(x)
|
104
|
-
#define m_tan(x) c_tan(x)
|
105
|
-
#define m_asin(x) c_asin(x)
|
106
|
-
#define m_acos(x) c_acos(x)
|
107
|
-
#define m_atan(x) c_atan(x)
|
108
|
-
#define m_sinh(x) c_sinh(x)
|
109
|
-
#define m_cosh(x) c_cosh(x)
|
110
|
-
#define m_tanh(x) c_tanh(x)
|
111
|
-
#define m_asinh(x) c_asinh(x)
|
112
|
-
#define m_acosh(x) c_acosh(x)
|
113
|
-
#define m_atanh(x) c_atanh(x)
|
114
|
-
#define m_hypot(x,y) c_hypot(x,y)
|
115
|
-
#define m_sinc(x) c_div(c_sin(x),x)
|
116
|
-
|
117
|
-
#define m_sum_init INT2FIX(0)
|
118
|
-
#define m_mulsum_init INT2FIX(0)
|
119
|
-
|
120
|
-
#define not_nan(x) (REAL(x)==REAL(x) && IMAG(x)==IMAG(x))
|
121
|
-
|
122
|
-
#define m_mulsum(x,y,z) {z = m_add(m_mul(x,y),z);}
|
123
|
-
#define m_mulsum_nan(x,y,z) { \
|
124
|
-
if(not_nan(x) && not_nan(y)) { \
|
125
|
-
z = m_add(m_mul(x,y),z); \
|
126
|
-
}}
|
127
|
-
|
128
|
-
#define m_cumsum(x,y) {(x)=m_add(x,y);}
|
129
|
-
#define m_cumsum_nan(x,y) { \
|
130
|
-
if (!not_nan(x)) { \
|
131
|
-
(x) = (y); \
|
132
|
-
} else if (not_nan(y)) { \
|
133
|
-
(x) = m_add(x,y); \
|
134
|
-
}}
|
135
|
-
|
136
|
-
#define m_cumprod(x,y) {(x)=m_mul(x,y);}
|
137
|
-
#define m_cumprod_nan(x,y) { \
|
138
|
-
if (!not_nan(x)) { \
|
139
|
-
(x) = (y); \
|
140
|
-
} else if (not_nan(y)) { \
|
141
|
-
(x) = m_mul(x,y); \
|
142
|
-
}}
|
143
|
-
|
144
|
-
static inline dtype f_sum(size_t n, char *p, ssize_t stride)
|
145
|
-
{
|
146
|
-
size_t i=n;
|
147
|
-
dtype x,y;
|
148
|
-
|
149
|
-
y = c_zero();
|
150
|
-
for (; i--;) {
|
151
|
-
x = *(dtype*)p;
|
152
|
-
y = c_add(x,y);
|
153
|
-
p += stride;
|
154
|
-
}
|
155
|
-
return y;
|
156
|
-
}
|
157
|
-
|
158
|
-
static inline dtype f_sum_nan(size_t n, char *p, ssize_t stride)
|
159
|
-
{
|
160
|
-
size_t i=n;
|
161
|
-
dtype x,y;
|
162
|
-
|
163
|
-
y = c_zero();
|
164
|
-
for (; i--;) {
|
165
|
-
x = *(dtype*)p;
|
166
|
-
if (not_nan(x)) {
|
167
|
-
y = c_add(x,y);
|
168
|
-
}
|
169
|
-
p += stride;
|
170
|
-
}
|
171
|
-
return y;
|
172
|
-
}
|
173
|
-
|
174
|
-
static inline dtype f_kahan_sum(size_t n, char *p, ssize_t stride)
|
175
|
-
{
|
176
|
-
size_t i=n;
|
177
|
-
dtype x;
|
178
|
-
volatile dtype y,t,r;
|
179
|
-
|
180
|
-
y = c_zero();
|
181
|
-
r = c_zero();
|
182
|
-
for (; i--;) {
|
183
|
-
x = *(dtype*)p;
|
184
|
-
if (fabs(REAL(x)) > fabs(REAL(y))) {
|
185
|
-
double z=REAL(x); REAL(x)=REAL(y); REAL(y)=z;
|
186
|
-
}
|
187
|
-
if (fabs(IMAG(x)) > fabs(IMAG(y))) {
|
188
|
-
double z=IMAG(x); IMAG(x)=IMAG(y); IMAG(y)=z;
|
189
|
-
}
|
190
|
-
r = c_add(x, r);
|
191
|
-
t = y;
|
192
|
-
y = c_add(r, y);
|
193
|
-
t = c_sub(y, t);
|
194
|
-
r = c_sub(r, t);
|
195
|
-
p += stride;
|
196
|
-
}
|
197
|
-
return y;
|
198
|
-
}
|
199
|
-
|
200
|
-
static inline dtype f_kahan_sum_nan(size_t n, char *p, ssize_t stride)
|
201
|
-
{
|
202
|
-
size_t i=n;
|
203
|
-
dtype x;
|
204
|
-
volatile dtype y,t,r;
|
205
|
-
|
206
|
-
y = c_zero();
|
207
|
-
r = c_zero();
|
208
|
-
for (; i--;) {
|
209
|
-
x = *(dtype*)p;
|
210
|
-
if (not_nan(x)) {
|
211
|
-
if (fabs(REAL(x)) > fabs(REAL(y))) {
|
212
|
-
double z=REAL(x); REAL(x)=REAL(y); REAL(y)=z;
|
213
|
-
}
|
214
|
-
if (fabs(IMAG(x)) > fabs(IMAG(y))) {
|
215
|
-
double z=IMAG(x); IMAG(x)=IMAG(y); IMAG(y)=z;
|
216
|
-
}
|
217
|
-
r = c_add(x, r);
|
218
|
-
t = y;
|
219
|
-
y = c_add(r, y);
|
220
|
-
t = c_sub(y, t);
|
221
|
-
r = c_sub(r, t);
|
222
|
-
}
|
223
|
-
p += stride;
|
224
|
-
}
|
225
|
-
return y;
|
226
|
-
}
|
227
|
-
|
228
|
-
static inline dtype f_prod(size_t n, char *p, ssize_t stride)
|
229
|
-
{
|
230
|
-
size_t i=n;
|
231
|
-
dtype x,y;
|
232
|
-
|
233
|
-
y = c_one();
|
234
|
-
for (; i--;) {
|
235
|
-
x = *(dtype*)p;
|
236
|
-
y = c_mul(x,y);
|
237
|
-
p += stride;
|
238
|
-
}
|
239
|
-
return y;
|
240
|
-
}
|
241
|
-
|
242
|
-
static inline dtype f_prod_nan(size_t n, char *p, ssize_t stride)
|
243
|
-
{
|
244
|
-
size_t i=n;
|
245
|
-
dtype x,y;
|
246
|
-
|
247
|
-
y = c_one();
|
248
|
-
for (; i--;) {
|
249
|
-
x = *(dtype*)p;
|
250
|
-
if (not_nan(x)) {
|
251
|
-
y = c_mul(x,y);
|
252
|
-
}
|
253
|
-
p += stride;
|
254
|
-
}
|
255
|
-
return y;
|
256
|
-
}
|
257
|
-
|
258
|
-
static inline dtype f_mean(size_t n, char *p, ssize_t stride)
|
259
|
-
{
|
260
|
-
size_t i=n;
|
261
|
-
size_t count=0;
|
262
|
-
dtype x,y;
|
263
|
-
|
264
|
-
y = c_zero();
|
265
|
-
for (; i--;) {
|
266
|
-
x = *(dtype*)p;
|
267
|
-
y = c_add(x,y);
|
268
|
-
count++;
|
269
|
-
p += stride;
|
270
|
-
}
|
271
|
-
return c_div_r(y,count);
|
272
|
-
}
|
273
|
-
|
274
|
-
static inline dtype f_mean_nan(size_t n, char *p, ssize_t stride)
|
275
|
-
{
|
276
|
-
size_t i=n;
|
277
|
-
size_t count=0;
|
278
|
-
dtype x,y;
|
279
|
-
|
280
|
-
y = c_zero();
|
281
|
-
for (; i--;) {
|
282
|
-
x = *(dtype*)p;
|
283
|
-
if (not_nan(x)) {
|
284
|
-
y = c_add(x,y);
|
285
|
-
count++;
|
286
|
-
}
|
287
|
-
p += stride;
|
288
|
-
}
|
289
|
-
return c_div_r(y,count);
|
290
|
-
}
|
291
|
-
|
292
|
-
static inline rtype f_var(size_t n, char *p, ssize_t stride)
|
293
|
-
{
|
294
|
-
size_t i=n;
|
295
|
-
size_t count=0;
|
296
|
-
dtype x,m;
|
297
|
-
rtype y=0;
|
298
|
-
|
299
|
-
m = f_mean(n,p,stride);
|
300
|
-
|
301
|
-
for (; i--;) {
|
302
|
-
x = *(dtype*)p;
|
303
|
-
y += c_abs_square(c_sub(x,m));
|
304
|
-
count++;
|
305
|
-
p += stride;
|
306
|
-
}
|
307
|
-
return y/(count-1);
|
308
|
-
}
|
309
|
-
|
310
|
-
static inline rtype f_var_nan(size_t n, char *p, ssize_t stride)
|
311
|
-
{
|
312
|
-
size_t i=n;
|
313
|
-
size_t count=0;
|
314
|
-
dtype x,m;
|
315
|
-
rtype y=0;
|
316
|
-
|
317
|
-
m = f_mean_nan(n,p,stride);
|
318
|
-
|
319
|
-
for (; i--;) {
|
320
|
-
x = *(dtype*)p;
|
321
|
-
if (not_nan(x)) {
|
322
|
-
y += c_abs_square(c_sub(x,m));
|
323
|
-
count++;
|
324
|
-
}
|
325
|
-
p += stride;
|
326
|
-
}
|
327
|
-
return y/(count-1);
|
328
|
-
}
|
329
|
-
|
330
|
-
static inline rtype f_stddev(size_t n, char *p, ssize_t stride)
|
331
|
-
{
|
332
|
-
return r_sqrt(f_var(n,p,stride));
|
333
|
-
}
|
334
|
-
|
335
|
-
static inline rtype f_stddev_nan(size_t n, char *p, ssize_t stride)
|
336
|
-
{
|
337
|
-
return r_sqrt(f_var_nan(n,p,stride));
|
338
|
-
}
|
339
|
-
|
340
|
-
static inline rtype f_rms(size_t n, char *p, ssize_t stride)
|
341
|
-
{
|
342
|
-
size_t i=n;
|
343
|
-
size_t count=0;
|
344
|
-
dtype x;
|
345
|
-
rtype y=0;
|
346
|
-
|
347
|
-
for (; i--;) {
|
348
|
-
x = *(dtype*)p;
|
349
|
-
y += c_abs_square(x);
|
350
|
-
count++;
|
351
|
-
p += stride;
|
352
|
-
}
|
353
|
-
return r_sqrt(y/count);
|
354
|
-
}
|
355
|
-
|
356
|
-
static inline rtype f_rms_nan(size_t n, char *p, ssize_t stride)
|
357
|
-
{
|
358
|
-
size_t i=n;
|
359
|
-
size_t count=0;
|
360
|
-
dtype x;
|
361
|
-
rtype y=0;
|
362
|
-
|
363
|
-
for (; i--;) {
|
364
|
-
x = *(dtype*)p;
|
365
|
-
if (not_nan(x)) {
|
366
|
-
y += c_abs_square(x);
|
367
|
-
count++;
|
368
|
-
}
|
369
|
-
p += stride;
|
370
|
-
}
|
371
|
-
return r_sqrt(y/count);
|
372
|
-
}
|
373
|
-
|
374
|
-
static inline dtype f_seq(dtype x, dtype y, double c)
|
375
|
-
{
|
376
|
-
return c_add(x,c_mul_r(y,c));
|
377
|
-
}
|
@@ -1,44 +0,0 @@
|
|
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
|
-
}
|
12
|
-
|
13
|
-
#ifdef SFMT_H
|
14
|
-
/* generates a random number on [0,1)-real-interval */
|
15
|
-
inline static dtype m_rand(dtype max)
|
16
|
-
{
|
17
|
-
dtype z;
|
18
|
-
REAL(z) = genrand_res53_mix() * REAL(max);
|
19
|
-
IMAG(z) = genrand_res53_mix() * IMAG(max);
|
20
|
-
return z;
|
21
|
-
}
|
22
|
-
|
23
|
-
/* generates random numbers from the normal distribution
|
24
|
-
using Box-Muller Transformation.
|
25
|
-
*/
|
26
|
-
inline static void m_rand_norm(dtype mu, rtype sigma, dtype *a0)
|
27
|
-
{
|
28
|
-
rtype x1, x2, w;
|
29
|
-
do {
|
30
|
-
x1 = genrand_res53_mix();
|
31
|
-
x1 = x1*2-1;
|
32
|
-
x2 = genrand_res53_mix();
|
33
|
-
x2 = x2*2-1;
|
34
|
-
w = x1 * x1 + x2 * x2;
|
35
|
-
} while (w>=1);
|
36
|
-
w = sqrt( (-2*log(w)) / w );
|
37
|
-
REAL(*a0) = x1*w * sigma + REAL(mu);
|
38
|
-
IMAG(*a0) = x2*w * sigma + IMAG(mu);
|
39
|
-
}
|
40
|
-
#endif
|
41
|
-
|
42
|
-
#define M_EPSILON rb_float_new(2.2204460492503131e-16)
|
43
|
-
#define M_MIN rb_float_new(2.2250738585072014e-308)
|
44
|
-
#define M_MAX rb_float_new(1.7976931348623157e+308)
|
@@ -1,42 +0,0 @@
|
|
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
|
-
#ifdef SFMT_H
|
10
|
-
/* generates a random number on [0,1)-real-interval */
|
11
|
-
inline static dtype m_rand(dtype max)
|
12
|
-
{
|
13
|
-
return genrand_res53_mix() * max;
|
14
|
-
}
|
15
|
-
|
16
|
-
/* generates random numbers from the normal distribution
|
17
|
-
using Box-Muller Transformation.
|
18
|
-
*/
|
19
|
-
inline static void m_rand_norm(dtype mu, dtype sigma, dtype *a0, dtype *a1)
|
20
|
-
{
|
21
|
-
dtype x1, x2, w;
|
22
|
-
do {
|
23
|
-
x1 = genrand_res53_mix();
|
24
|
-
x1 = x1*2-1;
|
25
|
-
x2 = genrand_res53_mix();
|
26
|
-
x2 = x2*2-1;
|
27
|
-
w = x1 * x1 + x2 * x2;
|
28
|
-
} while (w>=1);
|
29
|
-
w = sqrt( (-2*log(w)) / w );
|
30
|
-
if (a0) {*a0 = x1*w * sigma + mu;}
|
31
|
-
if (a1) {*a1 = x2*w * sigma + mu;}
|
32
|
-
}
|
33
|
-
#endif
|
34
|
-
|
35
|
-
#define m_min_init numo_dfloat_new_dim0(0.0/0.0)
|
36
|
-
#define m_max_init numo_dfloat_new_dim0(0.0/0.0)
|
37
|
-
#define m_extract(x) rb_float_new(*(double*)x)
|
38
|
-
#define m_nearly_eq(x,y) (fabs(x-y)<=(fabs(x)+fabs(y))*DBL_EPSILON*2)
|
39
|
-
|
40
|
-
#define M_EPSILON rb_float_new(2.2204460492503131e-16)
|
41
|
-
#define M_MIN rb_float_new(2.2250738585072014e-308)
|
42
|
-
#define M_MAX rb_float_new(1.7976931348623157e+308)
|