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,75 +0,0 @@
|
|
1
|
-
#define m_zero INT2FIX(0)
|
2
|
-
#define m_one INT2FIX(1)
|
3
|
-
|
4
|
-
#define m_num_to_data(x) (x)
|
5
|
-
#define m_data_to_num(x) (x)
|
6
|
-
|
7
|
-
#define m_from_double(x) rb_float_new(x)
|
8
|
-
#define m_from_real(x) rb_float_new(x)
|
9
|
-
|
10
|
-
#define m_add(x,y) rb_funcall(x,'+',1,y)
|
11
|
-
#define m_sub(x,y) rb_funcall(x,'-',1,y)
|
12
|
-
#define m_mul(x,y) rb_funcall(x,'*',1,y)
|
13
|
-
#define m_div(x,y) rb_funcall(x,'/',1,y)
|
14
|
-
#define m_mod(x,y) rb_funcall(x,'%',1,y)
|
15
|
-
#define m_divmod(x,y,a,b) \
|
16
|
-
{x = rb_funcall(x,id_divmod,1,y); \
|
17
|
-
a = RARRAY_PTR(x)[0]; b = RARRAY_PTR(x)[0];}
|
18
|
-
#define m_pow(x,y) rb_funcall(x,id_pow,1,y)
|
19
|
-
#define m_pow_int(x,y) rb_funcall(x,id_pow,1,y)
|
20
|
-
|
21
|
-
#define m_abs(x) rb_funcall(x,id_abs,0)
|
22
|
-
#define m_minus(x) rb_funcall(x,id_minus,0)
|
23
|
-
#define m_reciprocal(x) rb_funcall(x,id_reciprocal,0)
|
24
|
-
#define m_square(x) rb_funcall(x,'*',1,x)
|
25
|
-
#define m_floor(x) rb_funcall(x,id_floor,0)
|
26
|
-
#define m_round(x) rb_funcall(x,id_round,0)
|
27
|
-
#define m_ceil(x) rb_funcall(x,id_ceil,0)
|
28
|
-
#define m_trunc(x) rb_funcall(x,id_truncate,0)
|
29
|
-
#define m_sign(x) rb_funcall(x,id_ufo,1,INT2FIX(0))
|
30
|
-
|
31
|
-
#define m_eq(x,y) RTEST(rb_funcall(x,id_eq,1,y))
|
32
|
-
#define m_ne(x,y) RTEST(rb_funcall(x,id_ne,1,y))
|
33
|
-
#define m_gt(x,y) RTEST(rb_funcall(x,id_gt,1,y))
|
34
|
-
#define m_ge(x,y) RTEST(rb_funcall(x,id_ge,1,y))
|
35
|
-
#define m_lt(x,y) RTEST(rb_funcall(x,id_lt,1,y))
|
36
|
-
#define m_le(x,y) RTEST(rb_funcall(x,id_le,1,y))
|
37
|
-
|
38
|
-
#define m_bit_and(x,y) rb_funcall(x,id_bit_and,1,y)
|
39
|
-
#define m_bit_or(x,y) rb_funcall(x,id_bit_or, 1,y)
|
40
|
-
#define m_bit_xor(x,y) rb_funcall(x,id_bit_xor,1,y)
|
41
|
-
#define m_bit_not(x) rb_funcall(x,id_bit_not,0)
|
42
|
-
|
43
|
-
#define m_left_shift(x,y) rb_funcall(x,id_left_shift,1,y)
|
44
|
-
#define m_right_shift(x,y) rb_funcall(x,id_right_shift,1,y)
|
45
|
-
|
46
|
-
#define m_isnan(x) ((rb_respond_to(x,id_nan_p)) ? RTEST(rb_funcall(x,id_nan_p,0)) : 0)
|
47
|
-
#define m_isinf(x) ((rb_respond_to(x,id_infinite_p)) ? RTEST(rb_funcall(x,id_infinite_p,0)) : 0)
|
48
|
-
#define m_isposinf(x) ((rb_respond_to(x,id_infinite_p)) ? \
|
49
|
-
((RTEST(rb_funcall(x,id_infinite_p,0))) ? \
|
50
|
-
m_gt(x,INT2FIX(0)) : 0) : 0)
|
51
|
-
#define m_isneginf(x) ((rb_respond_to(x,id_infinite_p)) ? \
|
52
|
-
((RTEST(rb_funcall(x,id_infinite_p,0))) ? \
|
53
|
-
m_lt(x,INT2FIX(0)) : 0) : 0)
|
54
|
-
#define m_isfinite(x) ((rb_respond_to(x,id_finite_p)) ? RTEST(rb_funcall(x,id_finite_p,0)) : 0)
|
55
|
-
|
56
|
-
#define m_mulsum_init INT2FIX(0)
|
57
|
-
|
58
|
-
#define m_sprintf(s,x) robj_sprintf(s,x)
|
59
|
-
|
60
|
-
static inline int robj_sprintf(char *s, VALUE x) {
|
61
|
-
VALUE v = rb_funcall(x,rb_intern("to_s"),0);
|
62
|
-
return sprintf(s,"%s",StringValuePtr(v));
|
63
|
-
}
|
64
|
-
|
65
|
-
#define m_sqrt(x) \
|
66
|
-
rb_funcall(rb_const_get(rb_mKernel,rb_intern("Math")), \
|
67
|
-
rb_intern("sqrt"),1,x);
|
68
|
-
|
69
|
-
static inline dtype f_seq(dtype x, dtype y, size_t c)
|
70
|
-
{
|
71
|
-
y = m_mul(y,SIZET2NUM(c));
|
72
|
-
return m_add(x,y);
|
73
|
-
}
|
74
|
-
|
75
|
-
#include "real_accum.h"
|
@@ -1,27 +0,0 @@
|
|
1
|
-
typedef VALUE dtype;
|
2
|
-
typedef VALUE rtype;
|
3
|
-
#define cT numo_cRObject
|
4
|
-
#define cRT cT
|
5
|
-
//#define mTM mRObjectMath
|
6
|
-
|
7
|
-
#include "float_def.h"
|
8
|
-
#include "robj_macro.h"
|
9
|
-
|
10
|
-
#define m_min_init (0.0/0.0)
|
11
|
-
#define m_max_init (0.0/0.0)
|
12
|
-
#define m_extract(x) (*(VALUE*)x)
|
13
|
-
#define m_nearly_eq(x,y) robj_nearly_eq(x,y)
|
14
|
-
|
15
|
-
inline static int robj_nearly_eq(VALUE vx, VALUE vy)
|
16
|
-
{
|
17
|
-
double x, y;
|
18
|
-
x = NUM2DBL(vx);
|
19
|
-
y = NUM2DBL(vy);
|
20
|
-
return (fabs(x-y)<=(fabs(x)+fabs(y))*DBL_EPSILON*2);
|
21
|
-
}
|
22
|
-
|
23
|
-
/* generates a random number on [0,1)-real-interval */
|
24
|
-
inline static dtype m_rand(dtype max)
|
25
|
-
{
|
26
|
-
return DBL2NUM(genrand_res53_mix() * max);
|
27
|
-
}
|
@@ -1,44 +0,0 @@
|
|
1
|
-
typedef scomplex dtype;
|
2
|
-
typedef float rtype;
|
3
|
-
#define cT numo_cSComplex
|
4
|
-
#define cRT numo_cSFloat
|
5
|
-
#define mTM numo_mSComplexMath
|
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))*FLT_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) = to_real2(gen_rand32()) * REAL(max);
|
19
|
-
IMAG(z) = to_real2(gen_rand32()) * 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 = to_real2(gen_rand32());
|
31
|
-
x1 = x1*2-1;
|
32
|
-
x2 = to_real2(gen_rand32());
|
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(1.1920928955078125e-07)
|
43
|
-
#define M_MIN rb_float_new(1.1754943508222875e-38)
|
44
|
-
#define M_MAX rb_float_new(3.4028234663852886e+38)
|
@@ -1,43 +0,0 @@
|
|
1
|
-
typedef float dtype;
|
2
|
-
typedef float rtype;
|
3
|
-
#define cT numo_cSFloat
|
4
|
-
#define cRT numo_cSFloat
|
5
|
-
#define mTM numo_mSFloatMath
|
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 to_real2(gen_rand32()) * 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 = to_real2(gen_rand32());
|
24
|
-
x1 = x1*2-1;
|
25
|
-
x2 = to_real2(gen_rand32());
|
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_sfloat_new_dim0(0.0/0.0)
|
36
|
-
#define m_max_init numo_sfloat_new_dim0(0.0/0.0)
|
37
|
-
|
38
|
-
#define m_extract(x) rb_float_new(*(float*)x)
|
39
|
-
#define m_nearly_eq(x,y) (fabs(x-y)<=(fabs(x)+fabs(y))*FLT_EPSILON*2)
|
40
|
-
|
41
|
-
#define M_EPSILON rb_float_new(1.1920928955078125e-07)
|
42
|
-
#define M_MIN rb_float_new(1.1754943508222875e-38)
|
43
|
-
#define M_MAX rb_float_new(3.4028234663852886e+38)
|
@@ -1,21 +0,0 @@
|
|
1
|
-
typedef u_int16_t dtype;
|
2
|
-
typedef u_int16_t rtype;
|
3
|
-
#define cT numo_cUInt16
|
4
|
-
#define cRT cT
|
5
|
-
|
6
|
-
#define m_num_to_data(x) ((dtype)NUM2UINT(x))
|
7
|
-
#define m_data_to_num(x) UINT2NUM((unsigned int)(x))
|
8
|
-
#define m_extract(x) UINT2NUM((unsigned int)*(dtype*)(x))
|
9
|
-
#define m_sprintf(s,x) sprintf(s,"%u",(unsigned int)(x))
|
10
|
-
|
11
|
-
#ifndef UINT16_MAX
|
12
|
-
#define UINT16_MAX (65535)
|
13
|
-
#endif
|
14
|
-
|
15
|
-
#define DATA_MIN UINT16_MIN
|
16
|
-
#define DATA_MAX UINT16_MAX
|
17
|
-
|
18
|
-
#define M_MIN INT2FIX(0)
|
19
|
-
#define M_MAX m_data_to_num(UINT16_MAX)
|
20
|
-
|
21
|
-
#include "uint_macro.h"
|
@@ -1,21 +0,0 @@
|
|
1
|
-
typedef u_int32_t dtype;
|
2
|
-
typedef u_int32_t rtype;
|
3
|
-
#define cT numo_cUInt32
|
4
|
-
#define cRT cT
|
5
|
-
|
6
|
-
#define m_num_to_data(x) ((dtype)NUM2UINT32(x))
|
7
|
-
#define m_data_to_num(x) UINT322NUM((u_int32_t)(x))
|
8
|
-
#define m_extract(x) UINT322NUM((u_int32_t)*(dtype*)(x))
|
9
|
-
#define m_sprintf(s,x) sprintf(s,"%"PRIu32,(u_int32_t)(x))
|
10
|
-
|
11
|
-
#ifndef UINT32_MAX
|
12
|
-
#define UINT32_MAX (4294967295u)
|
13
|
-
#endif
|
14
|
-
|
15
|
-
#define DATA_MIN UINT32_MIN
|
16
|
-
#define DATA_MAX UINT32_MAX
|
17
|
-
|
18
|
-
#define M_MIN INT2FIX(0)
|
19
|
-
#define M_MAX m_data_to_num(UINT32_MAX)
|
20
|
-
|
21
|
-
#include "uint_macro.h"
|
@@ -1,21 +0,0 @@
|
|
1
|
-
typedef u_int64_t dtype;
|
2
|
-
typedef u_int64_t rtype;
|
3
|
-
#define cT numo_cUInt64
|
4
|
-
#define cRT cT
|
5
|
-
|
6
|
-
#define m_num_to_data(x) ((dtype)NUM2UINT64(x))
|
7
|
-
#define m_data_to_num(x) UINT642NUM((u_int64_t)(x))
|
8
|
-
#define m_extract(x) UINT642NUM((u_int64_t)*(dtype*)(x))
|
9
|
-
#define m_sprintf(s,x) sprintf(s,"%"PRIu64,(u_int64_t)(x))
|
10
|
-
|
11
|
-
#ifndef UINT64_MAX
|
12
|
-
#define UINT64_MAX (18446744073709551615ul)
|
13
|
-
#endif
|
14
|
-
|
15
|
-
#define DATA_MIN UINT64_MIN
|
16
|
-
#define DATA_MAX UINT64_MAX
|
17
|
-
|
18
|
-
#define M_MIN INT2FIX(0)
|
19
|
-
#define M_MAX m_data_to_num(UINT64_MAX)
|
20
|
-
|
21
|
-
#include "uint_macro.h"
|
@@ -1,21 +0,0 @@
|
|
1
|
-
typedef u_int8_t dtype;
|
2
|
-
typedef u_int8_t rtype;
|
3
|
-
#define cT numo_cUInt8
|
4
|
-
#define cRT cT
|
5
|
-
|
6
|
-
#define m_num_to_data(x) ((dtype)NUM2UINT(x))
|
7
|
-
#define m_data_to_num(x) UINT2NUM((unsigned int)(x))
|
8
|
-
#define m_extract(x) UINT2NUM((unsigned int)*(dtype*)(x))
|
9
|
-
#define m_sprintf(s,x) sprintf(s,"%u",(unsigned int)(x))
|
10
|
-
|
11
|
-
#ifndef UINT8_MAX
|
12
|
-
#define UINT8_MAX (255)
|
13
|
-
#endif
|
14
|
-
|
15
|
-
#define DATA_MIN UINT8_MIN
|
16
|
-
#define DATA_MAX UINT8_MAX
|
17
|
-
|
18
|
-
#define M_MIN INT2FIX(0)
|
19
|
-
#define M_MAX m_data_to_num(UINT8_MAX)
|
20
|
-
|
21
|
-
#include "uint_macro.h"
|
@@ -1,32 +0,0 @@
|
|
1
|
-
#include "xint_macro.h"
|
2
|
-
|
3
|
-
#define m_abs(x) (x)
|
4
|
-
#define m_sign(x) (((x)==0) ? 0:1)
|
5
|
-
|
6
|
-
static inline dtype int_reciprocal(dtype x) {
|
7
|
-
switch (x) {
|
8
|
-
case 1:
|
9
|
-
return 1;
|
10
|
-
case 0:
|
11
|
-
rb_raise(rb_eZeroDivError, "divided by 0");
|
12
|
-
default:
|
13
|
-
return 0;
|
14
|
-
}
|
15
|
-
}
|
16
|
-
|
17
|
-
static dtype pow_int(dtype x, int p)
|
18
|
-
{
|
19
|
-
dtype r = m_one;
|
20
|
-
switch(p) {
|
21
|
-
case 0: return 1;
|
22
|
-
case 1: return x;
|
23
|
-
case 2: return x*x;
|
24
|
-
case 3: return x*x*x;
|
25
|
-
}
|
26
|
-
while (p) {
|
27
|
-
if (p&1) r *= x;
|
28
|
-
x *= x;
|
29
|
-
p >>= 1;
|
30
|
-
}
|
31
|
-
return r;
|
32
|
-
}
|
@@ -1,189 +0,0 @@
|
|
1
|
-
#define m_zero 0
|
2
|
-
#define m_one 1
|
3
|
-
|
4
|
-
#define m_from_double(x) (x)
|
5
|
-
#define m_from_real(x) (x)
|
6
|
-
|
7
|
-
#define m_add(x,y) ((x)+(y))
|
8
|
-
#define m_sub(x,y) ((x)-(y))
|
9
|
-
#define m_mul(x,y) ((x)*(y))
|
10
|
-
#define m_div(x,y) ((x)/(y))
|
11
|
-
#define m_mod(x,y) ((x)%(y))
|
12
|
-
#define m_divmod(x,y,a,b) {a=(x)/(y); b=m_mod(x,y);}
|
13
|
-
#define m_pow(x,y) pow_int(x,y)
|
14
|
-
#define m_pow_int(x,y) pow_int(x,y)
|
15
|
-
|
16
|
-
#define m_bit_and(x,y) ((x)&(y))
|
17
|
-
#define m_bit_or(x,y) ((x)|(y))
|
18
|
-
#define m_bit_xor(x,y) ((x)^(y))
|
19
|
-
#define m_bit_not(x) (~(x))
|
20
|
-
|
21
|
-
#define m_minus(x) (-(x))
|
22
|
-
#define m_reciprocal(x) int_reciprocal(x)
|
23
|
-
#define m_square(x) ((x)*(x))
|
24
|
-
|
25
|
-
#define m_eq(x,y) ((x)==(y))
|
26
|
-
#define m_ne(x,y) ((x)!=(y))
|
27
|
-
#define m_gt(x,y) ((x)>(y))
|
28
|
-
#define m_ge(x,y) ((x)>=(y))
|
29
|
-
#define m_lt(x,y) ((x)<(y))
|
30
|
-
#define m_le(x,y) ((x)<=(y))
|
31
|
-
#define m_left_shift(x,y) ((x)<<(y))
|
32
|
-
#define m_right_shift(x,y) ((x)>>(y))
|
33
|
-
|
34
|
-
#define m_isnan(x) 0
|
35
|
-
|
36
|
-
#define m_mulsum(x,y,z) {z += x*y;}
|
37
|
-
#define m_mulsum_init INT2FIX(0)
|
38
|
-
#define m_cumsum(x,y) {x += y;}
|
39
|
-
#define m_cumprod(x,y) {x *= y;}
|
40
|
-
|
41
|
-
#define cmp(a,b) \
|
42
|
-
((qsort_cast(a)==qsort_cast(b)) ? 0 : \
|
43
|
-
(qsort_cast(a) > qsort_cast(b)) ? 1 : -1)
|
44
|
-
#define cmpgt(a,b) \
|
45
|
-
(qsort_cast(a) > qsort_cast(b))
|
46
|
-
|
47
|
-
|
48
|
-
static inline dtype f_sum(size_t n, char *p, ssize_t stride)
|
49
|
-
{
|
50
|
-
dtype x,y=0;
|
51
|
-
size_t i=n;
|
52
|
-
for (; i--;) {
|
53
|
-
x = *(dtype*)p;
|
54
|
-
y += x;
|
55
|
-
p += stride;
|
56
|
-
}
|
57
|
-
return y;
|
58
|
-
}
|
59
|
-
|
60
|
-
static inline dtype f_prod(size_t n, char *p, ssize_t stride)
|
61
|
-
{
|
62
|
-
dtype x,y=1;
|
63
|
-
size_t i=n;
|
64
|
-
for (; i--;) {
|
65
|
-
x = *(dtype*)p;
|
66
|
-
y *= x;
|
67
|
-
p += stride;
|
68
|
-
}
|
69
|
-
return y;
|
70
|
-
}
|
71
|
-
|
72
|
-
static inline dtype f_min(size_t n, char *p, ssize_t stride)
|
73
|
-
{
|
74
|
-
dtype x,y;
|
75
|
-
size_t i=n;
|
76
|
-
|
77
|
-
y = *(dtype*)p;
|
78
|
-
p += stride;
|
79
|
-
i--;
|
80
|
-
for (; i--;) {
|
81
|
-
x = *(dtype*)p;
|
82
|
-
if (x < y) {
|
83
|
-
y = x;
|
84
|
-
}
|
85
|
-
p += stride;
|
86
|
-
}
|
87
|
-
return y;
|
88
|
-
}
|
89
|
-
|
90
|
-
static inline dtype f_max(size_t n, char *p, ssize_t stride)
|
91
|
-
{
|
92
|
-
dtype x,y;
|
93
|
-
size_t i=n;
|
94
|
-
|
95
|
-
y = *(dtype*)p;
|
96
|
-
p += stride;
|
97
|
-
i--;
|
98
|
-
for (; i--;) {
|
99
|
-
x = *(dtype*)p;
|
100
|
-
if (x > y) {
|
101
|
-
y = x;
|
102
|
-
}
|
103
|
-
p += stride;
|
104
|
-
}
|
105
|
-
return y;
|
106
|
-
}
|
107
|
-
|
108
|
-
static inline size_t f_min_index(size_t n, char *p, ssize_t stride)
|
109
|
-
{
|
110
|
-
dtype x, y;
|
111
|
-
size_t i, j=0;
|
112
|
-
|
113
|
-
y = *(dtype*)p;
|
114
|
-
for (i=1; i<n; i++) {
|
115
|
-
x = *(dtype*)(p+i*stride);
|
116
|
-
if (x < y) {
|
117
|
-
y = x;
|
118
|
-
j = i;
|
119
|
-
}
|
120
|
-
}
|
121
|
-
return j;
|
122
|
-
}
|
123
|
-
|
124
|
-
static inline size_t f_max_index(size_t n, char *p, ssize_t stride)
|
125
|
-
{
|
126
|
-
dtype x, y;
|
127
|
-
size_t i, j=0;
|
128
|
-
|
129
|
-
y = *(dtype*)p;
|
130
|
-
for (i=1; i<n; i++) {
|
131
|
-
x = *(dtype*)(p+i*stride);
|
132
|
-
if (x > y) {
|
133
|
-
y = x;
|
134
|
-
j = i;
|
135
|
-
}
|
136
|
-
}
|
137
|
-
return j;
|
138
|
-
}
|
139
|
-
|
140
|
-
static inline void
|
141
|
-
f_minmax(size_t n, char *p, ssize_t stride, dtype* amin, dtype* amax)
|
142
|
-
{
|
143
|
-
dtype x,min,max;
|
144
|
-
size_t i=n;
|
145
|
-
|
146
|
-
min = max = *(dtype*)p;
|
147
|
-
p += stride;
|
148
|
-
for (i--; i--;) {
|
149
|
-
x = *(dtype*)p;
|
150
|
-
if (m_gt(x,max)) {
|
151
|
-
max = x;
|
152
|
-
}
|
153
|
-
if (m_lt(x,min)) {
|
154
|
-
min = x;
|
155
|
-
}
|
156
|
-
p += stride;
|
157
|
-
}
|
158
|
-
*amin = min;
|
159
|
-
*amax = max;
|
160
|
-
return;
|
161
|
-
}
|
162
|
-
|
163
|
-
static inline dtype f_ptp(size_t n, char *p, ssize_t stride)
|
164
|
-
{
|
165
|
-
dtype min,max;
|
166
|
-
f_minmax(n,p,stride,&min,&max);
|
167
|
-
return m_sub(max,min);
|
168
|
-
}
|
169
|
-
|
170
|
-
static inline double f_seq(double x, double y, double c)
|
171
|
-
{
|
172
|
-
return x + y * c;
|
173
|
-
}
|
174
|
-
|
175
|
-
static inline dtype f_maximum(dtype x, dtype y)
|
176
|
-
{
|
177
|
-
if (m_ge(x,y)) {
|
178
|
-
return x;
|
179
|
-
}
|
180
|
-
return y;
|
181
|
-
}
|
182
|
-
|
183
|
-
static inline dtype f_minimum(dtype x, dtype y)
|
184
|
-
{
|
185
|
-
if (m_le(x,y)) {
|
186
|
-
return x;
|
187
|
-
}
|
188
|
-
return y;
|
189
|
-
}
|