numo-narray 0.9.0.1-x86-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/line_number.rb +126 -0
- data/lib/erbpp/narray_def.rb +338 -0
- data/lib/erbpp.rb +286 -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,140 @@
|
|
1
|
+
/*
|
2
|
+
narray.h
|
3
|
+
Numerical Array Extension for Ruby
|
4
|
+
(C) Copyright 1999-2003 by Masahiro TANAKA
|
5
|
+
|
6
|
+
This program is free software.
|
7
|
+
You can distribute/modify this program
|
8
|
+
under the same terms as Ruby itself.
|
9
|
+
NO WARRANTY.
|
10
|
+
*/
|
11
|
+
#ifndef TEMPLATE_H
|
12
|
+
#define TEMPLATE_H
|
13
|
+
|
14
|
+
#define INIT_COUNTER( lp, c ) \
|
15
|
+
{ c = (lp)->n[0]; }
|
16
|
+
|
17
|
+
#define NDL_CNT(lp) ((lp)->n[0])
|
18
|
+
#define NDL_PTR(lp,i) (((lp)->args[i]).ptr + ((lp)->args[i].iter[0]).pos)
|
19
|
+
#define NDL_STP(lp,i) (((lp)->args[i].iter[0]).step)
|
20
|
+
#define NDL_IDX(lp,i) (((lp)->args[i].iter[0]).idx)
|
21
|
+
#define NDL_ESZ(lp,i) (((lp)->args[i]).elmsz)
|
22
|
+
|
23
|
+
#define INIT_PTR( lp, i, pt, st ) \
|
24
|
+
{ \
|
25
|
+
pt = ((lp)->args[i]).ptr + ((lp)->args[i].iter[0]).pos; \
|
26
|
+
st = ((lp)->args[i].iter[0]).step; \
|
27
|
+
}
|
28
|
+
|
29
|
+
#define INIT_PTR_IDX( lp, i, pt, st, id ) \
|
30
|
+
{ \
|
31
|
+
pt = ((lp)->args[i]).ptr + ((lp)->args[i].iter[0]).pos; \
|
32
|
+
st = ((lp)->args[i].iter[0]).step; \
|
33
|
+
id = ((lp)->args[i].iter[0]).idx; \
|
34
|
+
}
|
35
|
+
|
36
|
+
#define INIT_ELMSIZE( lp, i, es ) \
|
37
|
+
{ \
|
38
|
+
es = ((lp)->args[i]).elmsz; \
|
39
|
+
}
|
40
|
+
|
41
|
+
#define INIT_PTR_BIT( lp, i, ad, ps, st ) \
|
42
|
+
{ \
|
43
|
+
ps = ((lp)->args[i].iter[0]).pos; \
|
44
|
+
ad = (BIT_DIGIT*)(((lp)->args[i]).ptr) + ps/NB; \
|
45
|
+
ps %= NB; \
|
46
|
+
st = ((lp)->args[i].iter[0]).step; \
|
47
|
+
}
|
48
|
+
|
49
|
+
#define INIT_PTR_BIT_IDX( lp, i, ad, ps, st, id ) \
|
50
|
+
{ \
|
51
|
+
ps = ((lp)->args[i].iter[0]).pos; \
|
52
|
+
ad = (BIT_DIGIT*)(((lp)->args[i]).ptr) + ps/NB; \
|
53
|
+
ps %= NB; \
|
54
|
+
st = ((lp)->args[i].iter[0]).step; \
|
55
|
+
id = ((lp)->args[i].iter[0]).idx; \
|
56
|
+
}
|
57
|
+
|
58
|
+
#define GET_DATA( ptr, type, val ) \
|
59
|
+
{ \
|
60
|
+
val = *(type*)(ptr); \
|
61
|
+
}
|
62
|
+
|
63
|
+
#define SET_DATA( ptr, type, val ) \
|
64
|
+
{ \
|
65
|
+
*(type*)(ptr) = val; \
|
66
|
+
}
|
67
|
+
|
68
|
+
#define GET_DATA_STRIDE( ptr, step, type, val ) \
|
69
|
+
{ \
|
70
|
+
val = *(type*)(ptr); \
|
71
|
+
ptr += step; \
|
72
|
+
}
|
73
|
+
|
74
|
+
#define GET_DATA_INDEX( ptr, idx, type, val ) \
|
75
|
+
{ \
|
76
|
+
val = *(type*)(ptr + *idx); \
|
77
|
+
idx++; \
|
78
|
+
}
|
79
|
+
|
80
|
+
#define SET_DATA_STRIDE( ptr, step, type, val ) \
|
81
|
+
{ \
|
82
|
+
*(type*)(ptr) = val; \
|
83
|
+
ptr += step; \
|
84
|
+
}
|
85
|
+
|
86
|
+
#define SET_DATA_INDEX( ptr, idx, type, val ) \
|
87
|
+
{ \
|
88
|
+
*(type*)(ptr + *idx) = val; \
|
89
|
+
idx++; \
|
90
|
+
}
|
91
|
+
|
92
|
+
#define LOAD_BIT( adr, pos, val ) \
|
93
|
+
{ \
|
94
|
+
size_t dig = (pos) / NB; \
|
95
|
+
int bit = (pos) % NB; \
|
96
|
+
val = (((BIT_DIGIT*)(adr))[dig]>>(bit)) & 1u; \
|
97
|
+
}
|
98
|
+
|
99
|
+
#define LOAD_BIT_STEP( adr, pos, step, idx, val ) \
|
100
|
+
{ \
|
101
|
+
size_t dig; int bit; \
|
102
|
+
if (idx) { \
|
103
|
+
dig = ((pos) + *(idx)) / NB; \
|
104
|
+
bit = ((pos) + *(idx)) % NB; \
|
105
|
+
idx++; \
|
106
|
+
} else { \
|
107
|
+
dig = (pos) / NB; \
|
108
|
+
bit = (pos) % NB; \
|
109
|
+
pos += step; \
|
110
|
+
} \
|
111
|
+
val = (((BIT_DIGIT*)(adr))[dig]>>bit) & 1u; \
|
112
|
+
}
|
113
|
+
|
114
|
+
#define STORE_BIT(adr,pos,val) \
|
115
|
+
{ \
|
116
|
+
size_t dig = (pos) / NB; \
|
117
|
+
int bit = (pos) % NB; \
|
118
|
+
((BIT_DIGIT*)(adr))[dig] = \
|
119
|
+
(((BIT_DIGIT*)(adr))[dig] & ~(1u<<(bit))) | ((val)<<(bit)); \
|
120
|
+
}
|
121
|
+
// val -> val&1 ??
|
122
|
+
|
123
|
+
#define STORE_BIT_STEP( adr, pos, step, idx, val )\
|
124
|
+
{ \
|
125
|
+
size_t dig; int bit; \
|
126
|
+
if (idx) { \
|
127
|
+
dig = ((pos) + *(idx)) / NB; \
|
128
|
+
bit = ((pos) + *(idx)) % NB; \
|
129
|
+
idx++; \
|
130
|
+
} else { \
|
131
|
+
dig = (pos) / NB; \
|
132
|
+
bit = (pos) % NB; \
|
133
|
+
pos += step; \
|
134
|
+
} \
|
135
|
+
((BIT_DIGIT*)(adr))[dig] = \
|
136
|
+
(((BIT_DIGIT*)(adr))[dig] & ~(1u<<(bit))) | ((val)<<(bit)); \
|
137
|
+
}
|
138
|
+
// val -> val&1 ??
|
139
|
+
|
140
|
+
#endif /* ifndef NARRAY_H */
|
@@ -0,0 +1,19 @@
|
|
1
|
+
typedef int dtype;
|
2
|
+
|
3
|
+
#define m_load_data(ptr,pos) load_data(ptr,pos)
|
4
|
+
|
5
|
+
#define m_sprintf(s,x) sprintf(s,"%1d",(int)(x))
|
6
|
+
|
7
|
+
#define m_bit_not(x) (~(x))
|
8
|
+
|
9
|
+
#define m_bit_and(x,y) ((x)&(y))
|
10
|
+
#define m_bit_or(x,y) ((x)|(y))
|
11
|
+
#define m_bit_xor(x,y) ((x)^(y))
|
12
|
+
#define m_eq(x,y) (~((x)^(y)))
|
13
|
+
|
14
|
+
#define m_count_true(x) (x!=0)
|
15
|
+
#define m_count_false(x) (x==0)
|
16
|
+
|
17
|
+
static inline dtype load_data(void *ptr, size_t pos) {
|
18
|
+
return (((BIT_DIGIT*)(ptr))[(pos)/NB]>>((pos)%NB)) & 1u;
|
19
|
+
}
|
@@ -0,0 +1,410 @@
|
|
1
|
+
/*
|
2
|
+
complex.h
|
3
|
+
Numerical Array Extension for Ruby
|
4
|
+
(C) Copyright 1999-2007 by Masahiro TANAKA
|
5
|
+
|
6
|
+
This program is free software.
|
7
|
+
You can distribute/modify this program
|
8
|
+
under the same terms as Ruby itself.
|
9
|
+
NO WARRANTY.
|
10
|
+
*/
|
11
|
+
|
12
|
+
|
13
|
+
static inline dtype c_new(rtype r, rtype i) {
|
14
|
+
dtype z;
|
15
|
+
REAL(z) = r;
|
16
|
+
IMAG(z) = i;
|
17
|
+
return z;
|
18
|
+
}
|
19
|
+
|
20
|
+
static inline dtype c_set_real(dtype x, rtype r) {
|
21
|
+
REAL(x)=r;
|
22
|
+
return x;
|
23
|
+
}
|
24
|
+
|
25
|
+
static inline dtype c_set_imag(dtype x, rtype i) {
|
26
|
+
IMAG(x)=i;
|
27
|
+
return x;
|
28
|
+
}
|
29
|
+
|
30
|
+
static inline VALUE COMP2NUM(dtype x) {
|
31
|
+
VALUE v;
|
32
|
+
v = rb_funcall(rb_intern("Kernel"), rb_intern("Complex"), 2,
|
33
|
+
rb_float_new(REAL(x)), rb_float_new(IMAG(x)));
|
34
|
+
return v;
|
35
|
+
}
|
36
|
+
|
37
|
+
static inline dtype NUM2COMP(VALUE v) {
|
38
|
+
dtype z;
|
39
|
+
REAL(z) = NUM2DBL(rb_funcall(v,id_real,0));
|
40
|
+
IMAG(z) = NUM2DBL(rb_funcall(v,id_imag,0));
|
41
|
+
return z;
|
42
|
+
}
|
43
|
+
|
44
|
+
#define c_is_zero(x) (REAL(x)==0 && IMAG(x)==0)
|
45
|
+
#define c_eq(x,y) (REAL(x)==REAL(y) && IMAG(x)==IMAG(y))
|
46
|
+
#define c_ne(x,y) (REAL(x)!=REAL(y) || IMAG(x)!=IMAG(y))
|
47
|
+
#define c_isnan(x) (isnan(REAL(x))||isnan(IMAG(x)))
|
48
|
+
#define c_isinf(x) (isinf(REAL(x))||isinf(IMAG(x)))
|
49
|
+
#define c_isfinite(x) (isfinite(REAL(x))&&isfinite(IMAG(x)))
|
50
|
+
|
51
|
+
static inline dtype c_zero() {
|
52
|
+
dtype z;
|
53
|
+
REAL(z) = 0;
|
54
|
+
IMAG(z) = 0;
|
55
|
+
return z;
|
56
|
+
}
|
57
|
+
|
58
|
+
static inline dtype c_one() {
|
59
|
+
dtype z;
|
60
|
+
REAL(z) = 1;
|
61
|
+
IMAG(z) = 0;
|
62
|
+
return z;
|
63
|
+
}
|
64
|
+
|
65
|
+
static inline dtype c_minus(dtype x) {
|
66
|
+
dtype z;
|
67
|
+
REAL(z) = -REAL(x);
|
68
|
+
IMAG(z) = -IMAG(x);
|
69
|
+
return z;
|
70
|
+
}
|
71
|
+
|
72
|
+
static inline dtype c_im(dtype x) {
|
73
|
+
dtype z;
|
74
|
+
REAL(z) = -IMAG(x);
|
75
|
+
IMAG(z) = REAL(x);
|
76
|
+
return z;
|
77
|
+
}
|
78
|
+
|
79
|
+
static inline dtype c_add(dtype x, dtype y) {
|
80
|
+
dtype z;
|
81
|
+
REAL(z) = REAL(x)+REAL(y);
|
82
|
+
IMAG(z) = IMAG(x)+IMAG(y);
|
83
|
+
return z;
|
84
|
+
}
|
85
|
+
|
86
|
+
static inline dtype c_sub(dtype x, dtype y) {
|
87
|
+
dtype z;
|
88
|
+
REAL(z) = REAL(x)-REAL(y);
|
89
|
+
IMAG(z) = IMAG(x)-IMAG(y);
|
90
|
+
return z;
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
static inline dtype c_mul(dtype x, dtype y) {
|
95
|
+
dtype z;
|
96
|
+
REAL(z) = REAL(x)*REAL(y)-IMAG(x)*IMAG(y);
|
97
|
+
IMAG(z) = REAL(x)*IMAG(y)+IMAG(x)*REAL(y);
|
98
|
+
return z;
|
99
|
+
}
|
100
|
+
|
101
|
+
static inline dtype c_mul_r(dtype x, rtype y) {
|
102
|
+
dtype z;
|
103
|
+
REAL(z) = REAL(x)*y;
|
104
|
+
IMAG(z) = IMAG(x)*y;
|
105
|
+
return z;
|
106
|
+
}
|
107
|
+
|
108
|
+
static inline dtype c_div(dtype x, dtype y) {
|
109
|
+
dtype z;
|
110
|
+
rtype s,yr,yi;
|
111
|
+
s = r_hypot(REAL(y),IMAG(y));
|
112
|
+
yr = REAL(y)/s;
|
113
|
+
yi = IMAG(y)/s;
|
114
|
+
REAL(z) = (REAL(x)*yr+IMAG(x)*yi)/s;
|
115
|
+
IMAG(z) = (IMAG(x)*yr-REAL(x)*yi)/s;
|
116
|
+
return z;
|
117
|
+
}
|
118
|
+
|
119
|
+
static inline dtype c_div_r(dtype x, rtype y) {
|
120
|
+
dtype z;
|
121
|
+
REAL(z) = REAL(x)/y;
|
122
|
+
IMAG(z) = IMAG(x)/y;
|
123
|
+
return z;
|
124
|
+
}
|
125
|
+
|
126
|
+
static inline dtype c_inverse(dtype x) {
|
127
|
+
dtype z;
|
128
|
+
if ( r_abs(REAL(x)) > r_abs(IMAG(x)) ) {
|
129
|
+
IMAG(z) = IMAG(x)/REAL(x);
|
130
|
+
REAL(z) = (1+IMAG(z)*IMAG(z))*REAL(x);
|
131
|
+
IMAG(z) /= -REAL(z);
|
132
|
+
REAL(z) = 1/REAL(z);
|
133
|
+
} else {
|
134
|
+
REAL(z) = REAL(x)/IMAG(x);
|
135
|
+
IMAG(z) = (1+REAL(z)*REAL(z))*IMAG(x);
|
136
|
+
REAL(z) /= IMAG(z);
|
137
|
+
IMAG(z) = -1/IMAG(z);
|
138
|
+
}
|
139
|
+
return z;
|
140
|
+
}
|
141
|
+
|
142
|
+
static inline dtype c_square(dtype x) {
|
143
|
+
dtype z;
|
144
|
+
REAL(z) = REAL(x)*REAL(x)-IMAG(x)*IMAG(x);
|
145
|
+
IMAG(z) = 2*REAL(x)*IMAG(x);
|
146
|
+
return z;
|
147
|
+
}
|
148
|
+
|
149
|
+
static inline dtype c_sqrt(dtype x) {
|
150
|
+
dtype z;
|
151
|
+
rtype xr, xi, r;
|
152
|
+
xr = REAL(x)/2;
|
153
|
+
xi = IMAG(x)/2;
|
154
|
+
r = r_hypot(xr,xi);
|
155
|
+
if (xr>0) {
|
156
|
+
REAL(z) = sqrt(r+xr);
|
157
|
+
IMAG(z) = xi/REAL(z);
|
158
|
+
} else if ( (r-=xr)!=0 ) {
|
159
|
+
IMAG(z) = (xi>=0) ? sqrt(r):-sqrt(r);
|
160
|
+
REAL(z) = xi/IMAG(z);
|
161
|
+
} else {
|
162
|
+
REAL(z) = IMAG(z) = 0;
|
163
|
+
}
|
164
|
+
return z;
|
165
|
+
}
|
166
|
+
|
167
|
+
static inline dtype c_log(dtype x) {
|
168
|
+
dtype z;
|
169
|
+
REAL(z) = r_log(r_hypot(REAL(x),IMAG(x)));
|
170
|
+
IMAG(z) = r_atan2(IMAG(x),REAL(x));
|
171
|
+
return z;
|
172
|
+
}
|
173
|
+
|
174
|
+
static inline dtype c_log2(dtype x) {
|
175
|
+
dtype z;
|
176
|
+
z = c_log(x);
|
177
|
+
z = c_mul_r(x,M_LOG2E);
|
178
|
+
return z;
|
179
|
+
}
|
180
|
+
|
181
|
+
static inline dtype c_log10(dtype x) {
|
182
|
+
dtype z;
|
183
|
+
z = c_log(x);
|
184
|
+
z = c_mul_r(x,M_LOG10E);
|
185
|
+
return z;
|
186
|
+
}
|
187
|
+
|
188
|
+
static inline dtype c_exp(dtype x) {
|
189
|
+
dtype z;
|
190
|
+
rtype a = r_exp(REAL(x));
|
191
|
+
REAL(z) = a*r_cos(IMAG(x));
|
192
|
+
IMAG(z) = a*r_sin(IMAG(x));
|
193
|
+
return z;
|
194
|
+
}
|
195
|
+
|
196
|
+
static inline dtype c_exp2(dtype x) {
|
197
|
+
dtype z;
|
198
|
+
rtype a = r_exp(REAL(x)*M_LN2);
|
199
|
+
REAL(z) = a*r_cos(IMAG(x));
|
200
|
+
IMAG(z) = a*r_sin(IMAG(x));
|
201
|
+
return z;
|
202
|
+
}
|
203
|
+
|
204
|
+
static inline dtype c_exp10(dtype x) {
|
205
|
+
dtype z;
|
206
|
+
rtype a = r_exp(REAL(x)*M_LN10);
|
207
|
+
REAL(z) = a*r_cos(IMAG(x));
|
208
|
+
IMAG(z) = a*r_sin(IMAG(x));
|
209
|
+
return z;
|
210
|
+
}
|
211
|
+
|
212
|
+
static inline dtype c_sin(dtype x) {
|
213
|
+
dtype z;
|
214
|
+
REAL(z) = r_sin(REAL(x))*r_cosh(IMAG(x));
|
215
|
+
IMAG(z) = r_cos(REAL(x))*r_sinh(IMAG(x));
|
216
|
+
return z;
|
217
|
+
}
|
218
|
+
|
219
|
+
static inline dtype c_sinh(dtype x) {
|
220
|
+
dtype z;
|
221
|
+
REAL(z) = r_sinh(REAL(x))*r_cos(IMAG(x));
|
222
|
+
IMAG(z) = r_cosh(REAL(x))*r_sin(IMAG(x));
|
223
|
+
return z;
|
224
|
+
}
|
225
|
+
|
226
|
+
static inline dtype c_cos(dtype x) {
|
227
|
+
dtype z;
|
228
|
+
REAL(z) = r_cos(REAL(x))*r_cosh(IMAG(x));
|
229
|
+
IMAG(z) = -r_sin(REAL(x))*r_sinh(IMAG(x));
|
230
|
+
return z;
|
231
|
+
}
|
232
|
+
|
233
|
+
static inline dtype c_cosh(dtype x) {
|
234
|
+
dtype z;
|
235
|
+
REAL(z) = r_cosh(REAL(x))*r_cos(IMAG(x));
|
236
|
+
IMAG(z) = r_sinh(REAL(x))*r_sin(IMAG(x));
|
237
|
+
return z;
|
238
|
+
}
|
239
|
+
|
240
|
+
static inline dtype c_tan(dtype x) {
|
241
|
+
dtype z;
|
242
|
+
rtype c, d;
|
243
|
+
if (r_abs(IMAG(x))<1) {
|
244
|
+
c = r_cos(REAL(x));
|
245
|
+
d = r_sinh(IMAG(x));
|
246
|
+
d = c*c + d*d;
|
247
|
+
REAL(z) = 0.5*r_sin(2*REAL(x))/d;
|
248
|
+
IMAG(z) = 0.5*r_sinh(2*IMAG(x))/d;
|
249
|
+
} else {
|
250
|
+
d = r_exp(-IMAG(x));
|
251
|
+
c = 2*d/(1-d*d);
|
252
|
+
c = c*c;
|
253
|
+
d = r_cos(REAL(x));
|
254
|
+
d = 1.0 + d*d*c;
|
255
|
+
REAL(z) = 0.5*r_sin(2*REAL(x))*c/d;
|
256
|
+
IMAG(z) = 1/r_tanh(IMAG(x))/d;
|
257
|
+
}
|
258
|
+
return z;
|
259
|
+
}
|
260
|
+
|
261
|
+
static inline dtype c_tanh(dtype x) {
|
262
|
+
dtype z;
|
263
|
+
rtype c, d, s;
|
264
|
+
c = r_cos(IMAG(x));
|
265
|
+
s = r_sinh(REAL(x));
|
266
|
+
d = c*c + s*s;
|
267
|
+
if (r_abs(REAL(x))<1) {
|
268
|
+
REAL(z) = s*r_cosh(REAL(x))/d;
|
269
|
+
IMAG(z) = 0.5*r_sin(2*IMAG(x))/d;
|
270
|
+
} else {
|
271
|
+
c = c / s;
|
272
|
+
c = 1 + c*c;
|
273
|
+
REAL(z) = 1/(r_tanh(REAL(x))*c);
|
274
|
+
IMAG(z) = 0.5*r_sin(2*IMAG(x))/d;
|
275
|
+
}
|
276
|
+
return z;
|
277
|
+
}
|
278
|
+
|
279
|
+
static inline dtype c_asin(dtype x) {
|
280
|
+
dtype z, y;
|
281
|
+
y = c_square(x);
|
282
|
+
REAL(y) = 1-REAL(y);
|
283
|
+
IMAG(y) = -IMAG(y);
|
284
|
+
y = c_sqrt(y);
|
285
|
+
REAL(y) -= IMAG(x);
|
286
|
+
IMAG(y) += REAL(x);
|
287
|
+
y = c_log(y);
|
288
|
+
REAL(z) = IMAG(y);
|
289
|
+
IMAG(z) = -REAL(y);
|
290
|
+
return z;
|
291
|
+
}
|
292
|
+
|
293
|
+
static inline dtype c_asinh(dtype x) {
|
294
|
+
dtype z, y;
|
295
|
+
y = c_square(x);
|
296
|
+
REAL(y) += 1;
|
297
|
+
y = c_sqrt(y);
|
298
|
+
REAL(y) += REAL(x);
|
299
|
+
IMAG(y) += IMAG(x);
|
300
|
+
z = c_log(y);
|
301
|
+
return z;
|
302
|
+
}
|
303
|
+
|
304
|
+
static inline dtype c_acos(dtype x) {
|
305
|
+
dtype z, y;
|
306
|
+
y = c_square(x);
|
307
|
+
REAL(y) = 1-REAL(y);
|
308
|
+
IMAG(y) = -IMAG(y);
|
309
|
+
y = c_sqrt(y);
|
310
|
+
REAL(z) = REAL(x)-IMAG(y);
|
311
|
+
IMAG(z) = IMAG(x)+REAL(y);
|
312
|
+
y = c_log(z);
|
313
|
+
REAL(z) = IMAG(y);
|
314
|
+
IMAG(z) = -REAL(y);
|
315
|
+
return z;
|
316
|
+
}
|
317
|
+
|
318
|
+
static inline dtype c_acosh(dtype x) {
|
319
|
+
dtype z, y;
|
320
|
+
y = c_square(x);
|
321
|
+
REAL(y) -= 1;
|
322
|
+
y = c_sqrt(y);
|
323
|
+
REAL(y) += REAL(x);
|
324
|
+
IMAG(y) += IMAG(x);
|
325
|
+
z = c_log(y);
|
326
|
+
return z;
|
327
|
+
}
|
328
|
+
|
329
|
+
static inline dtype c_atan(dtype x) {
|
330
|
+
dtype z, y;
|
331
|
+
REAL(y) = -REAL(x);
|
332
|
+
IMAG(y) = 1-IMAG(x);
|
333
|
+
REAL(z) = REAL(x);
|
334
|
+
IMAG(z) = 1+IMAG(x);
|
335
|
+
y = c_div(z,y);
|
336
|
+
y = c_log(y);
|
337
|
+
REAL(z) = -IMAG(y)/2;
|
338
|
+
IMAG(z) = REAL(y)/2;
|
339
|
+
return z;
|
340
|
+
}
|
341
|
+
|
342
|
+
static inline dtype c_atanh(dtype x) {
|
343
|
+
dtype z, y;
|
344
|
+
REAL(y) = 1-REAL(x);
|
345
|
+
IMAG(y) = -IMAG(x);
|
346
|
+
REAL(z) = 1+REAL(x);
|
347
|
+
IMAG(z) = IMAG(x);
|
348
|
+
y = c_div(z,y);
|
349
|
+
y = c_log(y);
|
350
|
+
REAL(z) = REAL(y)/2;
|
351
|
+
IMAG(z) = IMAG(y)/2;
|
352
|
+
return z;
|
353
|
+
}
|
354
|
+
|
355
|
+
static inline dtype c_pow(dtype x, dtype y)
|
356
|
+
{
|
357
|
+
dtype z;
|
358
|
+
if (c_is_zero(y)) {
|
359
|
+
z = c_one();
|
360
|
+
} else if (c_is_zero(x) && REAL(y)>0 && IMAG(y)==0) {
|
361
|
+
z = c_zero();
|
362
|
+
} else {
|
363
|
+
z = c_log(x);
|
364
|
+
z = c_mul(y,z);
|
365
|
+
z = c_exp(z);
|
366
|
+
}
|
367
|
+
return z;
|
368
|
+
}
|
369
|
+
|
370
|
+
static inline dtype c_pow_int(dtype x, int p)
|
371
|
+
{
|
372
|
+
dtype z = c_one();
|
373
|
+
if (p<0) {
|
374
|
+
x = c_pow_int(x,-p);
|
375
|
+
return c_inverse(x);
|
376
|
+
}
|
377
|
+
if (p==2) {return c_square(x);}
|
378
|
+
if (p&1) {z = x;}
|
379
|
+
p >>= 1;
|
380
|
+
while (p) {
|
381
|
+
x = c_square(x);
|
382
|
+
if (p&1) z = c_mul(z,x);
|
383
|
+
p >>= 1;
|
384
|
+
}
|
385
|
+
return z;
|
386
|
+
}
|
387
|
+
|
388
|
+
static inline dtype c_cbrt(dtype x) {
|
389
|
+
dtype z;
|
390
|
+
z = c_log(x);
|
391
|
+
z = c_div_r(z,3);
|
392
|
+
z = c_exp(z);
|
393
|
+
return z;
|
394
|
+
}
|
395
|
+
|
396
|
+
static inline rtype c_abs(dtype x) {
|
397
|
+
return r_hypot(REAL(x),IMAG(x));
|
398
|
+
}
|
399
|
+
|
400
|
+
static inline rtype c_abs_square(dtype x) {
|
401
|
+
return REAL(x)*REAL(x)+IMAG(x)*IMAG(x);
|
402
|
+
}
|
403
|
+
|
404
|
+
|
405
|
+
|
406
|
+
/*
|
407
|
+
static inline rtype c_hypot(dtype x, dtype y) {
|
408
|
+
return r_hypot(c_abs(x),c_abs(y));
|
409
|
+
}
|
410
|
+
*/
|