numo-narray-alt 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +14 -0
- data/LICENSE +30 -0
- data/README.md +71 -0
- data/Rakefile +24 -0
- data/ext/numo/narray/SFMT-params.h +97 -0
- data/ext/numo/narray/SFMT-params19937.h +48 -0
- data/ext/numo/narray/SFMT.c +602 -0
- data/ext/numo/narray/SFMT.h +147 -0
- data/ext/numo/narray/array.c +575 -0
- data/ext/numo/narray/data.c +958 -0
- data/ext/numo/narray/extconf.rb +84 -0
- data/ext/numo/narray/index.c +1092 -0
- data/ext/numo/narray/kwargs.c +142 -0
- data/ext/numo/narray/math.c +133 -0
- data/ext/numo/narray/narray.c +1976 -0
- data/ext/numo/narray/narray.def +28 -0
- data/ext/numo/narray/ndloop.c +1840 -0
- data/ext/numo/narray/numo/compat.h +23 -0
- data/ext/numo/narray/numo/intern.h +115 -0
- data/ext/numo/narray/numo/narray.h +480 -0
- data/ext/numo/narray/numo/ndloop.h +93 -0
- data/ext/numo/narray/numo/template.h +149 -0
- data/ext/numo/narray/numo/types/bit.h +38 -0
- data/ext/numo/narray/numo/types/complex.h +404 -0
- data/ext/numo/narray/numo/types/complex_macro.h +384 -0
- data/ext/numo/narray/numo/types/dcomplex.h +42 -0
- data/ext/numo/narray/numo/types/dfloat.h +44 -0
- data/ext/numo/narray/numo/types/float_def.h +34 -0
- data/ext/numo/narray/numo/types/float_macro.h +202 -0
- data/ext/numo/narray/numo/types/int16.h +27 -0
- data/ext/numo/narray/numo/types/int32.h +23 -0
- data/ext/numo/narray/numo/types/int64.h +23 -0
- data/ext/numo/narray/numo/types/int8.h +23 -0
- data/ext/numo/narray/numo/types/int_macro.h +66 -0
- data/ext/numo/narray/numo/types/real_accum.h +481 -0
- data/ext/numo/narray/numo/types/robj_macro.h +78 -0
- data/ext/numo/narray/numo/types/robject.h +25 -0
- data/ext/numo/narray/numo/types/scomplex.h +42 -0
- data/ext/numo/narray/numo/types/sfloat.h +45 -0
- data/ext/numo/narray/numo/types/uint16.h +24 -0
- data/ext/numo/narray/numo/types/uint32.h +20 -0
- data/ext/numo/narray/numo/types/uint64.h +20 -0
- data/ext/numo/narray/numo/types/uint8.h +20 -0
- data/ext/numo/narray/numo/types/uint_macro.h +57 -0
- data/ext/numo/narray/numo/types/xint_macro.h +166 -0
- data/ext/numo/narray/rand.c +40 -0
- data/ext/numo/narray/src/t_bit.c +3236 -0
- data/ext/numo/narray/src/t_dcomplex.c +6776 -0
- data/ext/numo/narray/src/t_dfloat.c +9417 -0
- data/ext/numo/narray/src/t_int16.c +5757 -0
- data/ext/numo/narray/src/t_int32.c +5757 -0
- data/ext/numo/narray/src/t_int64.c +5759 -0
- data/ext/numo/narray/src/t_int8.c +5355 -0
- data/ext/numo/narray/src/t_robject.c +5567 -0
- data/ext/numo/narray/src/t_scomplex.c +6731 -0
- data/ext/numo/narray/src/t_sfloat.c +9374 -0
- data/ext/numo/narray/src/t_uint16.c +5753 -0
- data/ext/numo/narray/src/t_uint32.c +5753 -0
- data/ext/numo/narray/src/t_uint64.c +5755 -0
- data/ext/numo/narray/src/t_uint8.c +5351 -0
- data/ext/numo/narray/step.c +266 -0
- data/ext/numo/narray/struct.c +814 -0
- data/lib/numo/narray/extra.rb +1266 -0
- data/lib/numo/narray.rb +4 -0
- metadata +106 -0
@@ -0,0 +1,149 @@
|
|
1
|
+
/*
|
2
|
+
template.h
|
3
|
+
Ruby/Numo::NArray - Numerical Array class for Ruby
|
4
|
+
Copyright (C) 1999-2020 Masahiro TANAKA
|
5
|
+
*/
|
6
|
+
#ifndef TEMPLATE_H
|
7
|
+
#define TEMPLATE_H
|
8
|
+
|
9
|
+
#define INIT_COUNTER(lp, c) \
|
10
|
+
{ c = (lp)->n[0]; }
|
11
|
+
|
12
|
+
#define NDL_CNT(lp) ((lp)->n[0])
|
13
|
+
#define NDL_PTR(lp, i) ((lp)->args[i].ptr + (lp)->args[i].iter[0].pos)
|
14
|
+
#define NDL_STEP(lp, i) ((lp)->args[i].iter[0].step)
|
15
|
+
#define NDL_IDX(lp, i) ((lp)->args[i].iter[0].idx)
|
16
|
+
#define NDL_ESZ(lp, i) ((lp)->args[i].elmsz)
|
17
|
+
#define NDL_SHAPE(lp, i) ((lp)->args[i].shape)
|
18
|
+
|
19
|
+
#define INIT_PTR(lp, i, pt, st) \
|
20
|
+
{ \
|
21
|
+
pt = ((lp)->args[i]).ptr + ((lp)->args[i].iter[0]).pos; \
|
22
|
+
st = ((lp)->args[i].iter[0]).step; \
|
23
|
+
}
|
24
|
+
|
25
|
+
#define INIT_PTR_IDX(lp, i, pt, st, id) \
|
26
|
+
{ \
|
27
|
+
pt = ((lp)->args[i]).ptr + ((lp)->args[i].iter[0]).pos; \
|
28
|
+
st = ((lp)->args[i].iter[0]).step; \
|
29
|
+
id = ((lp)->args[i].iter[0]).idx; \
|
30
|
+
}
|
31
|
+
|
32
|
+
#define INIT_ELMSIZE(lp, i, es) \
|
33
|
+
{ es = ((lp)->args[i]).elmsz; }
|
34
|
+
|
35
|
+
#define INIT_PTR_BIT(lp, i, ad, ps, st) \
|
36
|
+
{ \
|
37
|
+
ps = ((lp)->args[i].iter[0]).pos; \
|
38
|
+
ad = (BIT_DIGIT*)(((lp)->args[i]).ptr); \
|
39
|
+
st = ((lp)->args[i].iter[0]).step; \
|
40
|
+
}
|
41
|
+
|
42
|
+
#define INIT_PTR_BIT_IDX(lp, i, ad, ps, st, id) \
|
43
|
+
{ \
|
44
|
+
ps = ((lp)->args[i].iter[0]).pos; \
|
45
|
+
ad = (BIT_DIGIT*)(((lp)->args[i]).ptr); \
|
46
|
+
st = ((lp)->args[i].iter[0]).step; \
|
47
|
+
id = ((lp)->args[i].iter[0]).idx; \
|
48
|
+
}
|
49
|
+
|
50
|
+
#define GET_DATA(ptr, type, val) \
|
51
|
+
{ val = *(type*)(ptr); }
|
52
|
+
|
53
|
+
#define SET_DATA(ptr, type, val) \
|
54
|
+
{ *(type*)(ptr) = val; }
|
55
|
+
|
56
|
+
#define GET_DATA_STRIDE(ptr, step, type, val) \
|
57
|
+
{ \
|
58
|
+
val = *(type*)(ptr); \
|
59
|
+
ptr += step; \
|
60
|
+
}
|
61
|
+
|
62
|
+
#define GET_DATA_INDEX(ptr, idx, type, val) \
|
63
|
+
{ \
|
64
|
+
val = *(type*)(ptr + *idx); \
|
65
|
+
idx++; \
|
66
|
+
}
|
67
|
+
|
68
|
+
#define SET_DATA_STRIDE(ptr, step, type, val) \
|
69
|
+
{ \
|
70
|
+
*(type*)(ptr) = val; \
|
71
|
+
ptr += step; \
|
72
|
+
}
|
73
|
+
|
74
|
+
#define SET_DATA_INDEX(ptr, idx, type, val) \
|
75
|
+
{ \
|
76
|
+
*(type*)(ptr + *idx) = val; \
|
77
|
+
idx++; \
|
78
|
+
}
|
79
|
+
|
80
|
+
#define LOAD_BIT(adr, pos, val) \
|
81
|
+
{ \
|
82
|
+
size_t dig = (pos) / NB; \
|
83
|
+
int bit = (pos) % NB; \
|
84
|
+
val = (((BIT_DIGIT*)(adr))[dig] >> (bit)) & 1u; \
|
85
|
+
}
|
86
|
+
|
87
|
+
#define LOAD_BIT_STEP(adr, pos, step, idx, val) \
|
88
|
+
{ \
|
89
|
+
size_t dig; \
|
90
|
+
int bit; \
|
91
|
+
if (idx) { \
|
92
|
+
dig = ((pos) + *(idx)) / NB; \
|
93
|
+
bit = ((pos) + *(idx)) % NB; \
|
94
|
+
idx++; \
|
95
|
+
} else { \
|
96
|
+
dig = (pos) / NB; \
|
97
|
+
bit = (pos) % NB; \
|
98
|
+
pos += step; \
|
99
|
+
} \
|
100
|
+
val = (((BIT_DIGIT*)(adr))[dig] >> bit) & 1u; \
|
101
|
+
}
|
102
|
+
|
103
|
+
#define STORE_BIT(adr, pos, val) \
|
104
|
+
{ \
|
105
|
+
size_t dig = (pos) / NB; \
|
106
|
+
int bit = (pos) % NB; \
|
107
|
+
((BIT_DIGIT*)(adr))[dig] = (((BIT_DIGIT*)(adr))[dig] & ~(1u << (bit))) | (((val) & 1u) << (bit)); \
|
108
|
+
}
|
109
|
+
|
110
|
+
#define STORE_BIT_STEP(adr, pos, step, idx, val) \
|
111
|
+
{ \
|
112
|
+
size_t dig; \
|
113
|
+
int bit; \
|
114
|
+
if (idx) { \
|
115
|
+
dig = ((pos) + *(idx)) / NB; \
|
116
|
+
bit = ((pos) + *(idx)) % NB; \
|
117
|
+
idx++; \
|
118
|
+
} else { \
|
119
|
+
dig = (pos) / NB; \
|
120
|
+
bit = (pos) % NB; \
|
121
|
+
pos += step; \
|
122
|
+
} \
|
123
|
+
((BIT_DIGIT*)(adr))[dig] = (((BIT_DIGIT*)(adr))[dig] & ~(1u << (bit))) | (((val) & 1u) << (bit)); \
|
124
|
+
}
|
125
|
+
|
126
|
+
static inline int is_aligned(const void* ptr, const size_t alignment) {
|
127
|
+
return ((size_t)(ptr) & ((alignment)-1)) == 0;
|
128
|
+
}
|
129
|
+
|
130
|
+
static inline int is_aligned_step(const ssize_t step, const size_t alignment) {
|
131
|
+
return ((step) & ((alignment)-1)) == 0;
|
132
|
+
}
|
133
|
+
|
134
|
+
static inline int get_count_of_elements_not_aligned_to_simd_size(const void* ptr, const size_t alignment,
|
135
|
+
const size_t element_size) {
|
136
|
+
size_t cnt = (size_t)(ptr) & ((alignment)-1);
|
137
|
+
return (int)(cnt == 0 ? 0 : (alignment - cnt) / element_size);
|
138
|
+
}
|
139
|
+
|
140
|
+
static inline int is_same_aligned2(const void* ptr1, const void* ptr2, const size_t alignment) {
|
141
|
+
return ((size_t)(ptr1) & ((alignment)-1)) == ((size_t)(ptr2) & ((alignment)-1));
|
142
|
+
}
|
143
|
+
|
144
|
+
static inline int is_same_aligned3(const void* ptr1, const void* ptr2, const void* ptr3, const size_t alignment) {
|
145
|
+
return (((size_t)(ptr1) & ((alignment)-1)) == ((size_t)(ptr2) & ((alignment)-1))) &&
|
146
|
+
(((size_t)(ptr1) & ((alignment)-1)) == ((size_t)(ptr3) & ((alignment)-1)));
|
147
|
+
}
|
148
|
+
|
149
|
+
#endif /* ifndef TEMPLATE_H */
|
@@ -0,0 +1,38 @@
|
|
1
|
+
typedef BIT_DIGIT dtype;
|
2
|
+
typedef BIT_DIGIT rtype;
|
3
|
+
#define cT numo_cBit
|
4
|
+
#define cRT cT
|
5
|
+
|
6
|
+
#define m_zero 0
|
7
|
+
#define m_one 1
|
8
|
+
|
9
|
+
#define m_abs(x) (x)
|
10
|
+
#define m_sign(x) (((x) == 0) ? 0 : 1)
|
11
|
+
|
12
|
+
#define m_from_double(x) (((x) == 0) ? 0 : 1)
|
13
|
+
#define m_from_real(x) (((x) == 0) ? 0 : 1)
|
14
|
+
#define m_from_sint(x) (((x) == 0) ? 0 : 1)
|
15
|
+
#define m_from_int32(x) (((x) == 0) ? 0 : 1)
|
16
|
+
#define m_from_int64(x) (((x) == 0) ? 0 : 1)
|
17
|
+
#define m_from_uint32(x) (((x) == 0) ? 0 : 1)
|
18
|
+
#define m_from_uint64(x) (((x) == 0) ? 0 : 1)
|
19
|
+
#define m_data_to_num(x) INT2FIX(x)
|
20
|
+
#define m_sprintf(s, x) sprintf(s, "%1d", (int)(x))
|
21
|
+
|
22
|
+
#define m_copy(x) (x)
|
23
|
+
#define m_not(x) (~(x))
|
24
|
+
#define m_and(x, y) ((x) & (y))
|
25
|
+
#define m_or(x, y) ((x) | (y))
|
26
|
+
#define m_xor(x, y) ((x) ^ (y))
|
27
|
+
#define m_eq(x, y) (~((x) ^ (y)))
|
28
|
+
#define m_count_true(x) ((x) != 0)
|
29
|
+
#define m_count_false(x) ((x) == 0)
|
30
|
+
|
31
|
+
static inline BIT_DIGIT m_num_to_data(VALUE num) {
|
32
|
+
if (RTEST(num)) {
|
33
|
+
if (!RTEST(rb_equal(num, INT2FIX(0)))) {
|
34
|
+
return 1;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
return 0;
|
38
|
+
}
|
@@ -0,0 +1,404 @@
|
|
1
|
+
/*
|
2
|
+
complex.h
|
3
|
+
Ruby/Numo::NArray - Numerical Array class for Ruby
|
4
|
+
Copyright (C) 1999-2020 Masahiro TANAKA
|
5
|
+
*/
|
6
|
+
|
7
|
+
static inline dtype c_new(rtype r, rtype i) {
|
8
|
+
dtype z;
|
9
|
+
REAL(z) = r;
|
10
|
+
IMAG(z) = i;
|
11
|
+
return z;
|
12
|
+
}
|
13
|
+
|
14
|
+
static inline dtype c_set_real(dtype x, rtype r) {
|
15
|
+
REAL(x) = r;
|
16
|
+
return x;
|
17
|
+
}
|
18
|
+
|
19
|
+
static inline dtype c_set_imag(dtype x, rtype i) {
|
20
|
+
IMAG(x) = i;
|
21
|
+
return x;
|
22
|
+
}
|
23
|
+
|
24
|
+
static inline VALUE COMP2NUM(dtype x) {
|
25
|
+
VALUE v;
|
26
|
+
v = rb_funcall(rb_intern("Kernel"), rb_intern("Complex"), 2, rb_float_new(REAL(x)), rb_float_new(IMAG(x)));
|
27
|
+
return v;
|
28
|
+
}
|
29
|
+
|
30
|
+
static inline dtype NUM2COMP(VALUE v) {
|
31
|
+
dtype z;
|
32
|
+
REAL(z) = NUM2DBL(rb_funcall(v, id_real, 0));
|
33
|
+
IMAG(z) = NUM2DBL(rb_funcall(v, id_imag, 0));
|
34
|
+
return z;
|
35
|
+
}
|
36
|
+
|
37
|
+
#define c_is_zero(x) (REAL(x) == 0 && IMAG(x) == 0)
|
38
|
+
#define c_eq(x, y) (REAL(x) == REAL(y) && IMAG(x) == IMAG(y))
|
39
|
+
#define c_ne(x, y) (REAL(x) != REAL(y) || IMAG(x) != IMAG(y))
|
40
|
+
#define c_isnan(x) (isnan(REAL(x)) || isnan(IMAG(x)))
|
41
|
+
#define c_isinf(x) (isinf(REAL(x)) || isinf(IMAG(x)))
|
42
|
+
#define c_isposinf(x) ((isinf(REAL(x)) && signbit(REAL(x)) == 0) || (isinf(IMAG(x)) && signbit(IMAG(x)) == 0))
|
43
|
+
#define c_isneginf(x) ((isinf(REAL(x)) && signbit(REAL(x))) || (isinf(IMAG(x)) && signbit(IMAG(x))))
|
44
|
+
#define c_isfinite(x) (isfinite(REAL(x)) && isfinite(IMAG(x)))
|
45
|
+
|
46
|
+
static inline dtype c_zero(void) {
|
47
|
+
dtype z;
|
48
|
+
REAL(z) = 0;
|
49
|
+
IMAG(z) = 0;
|
50
|
+
return z;
|
51
|
+
}
|
52
|
+
|
53
|
+
static inline dtype c_one(void) {
|
54
|
+
dtype z;
|
55
|
+
REAL(z) = 1;
|
56
|
+
IMAG(z) = 0;
|
57
|
+
return z;
|
58
|
+
}
|
59
|
+
|
60
|
+
static inline dtype c_minus(dtype x) {
|
61
|
+
dtype z;
|
62
|
+
REAL(z) = -REAL(x);
|
63
|
+
IMAG(z) = -IMAG(x);
|
64
|
+
return z;
|
65
|
+
}
|
66
|
+
|
67
|
+
static inline dtype c_im(dtype x) {
|
68
|
+
dtype z;
|
69
|
+
REAL(z) = -IMAG(x);
|
70
|
+
IMAG(z) = REAL(x);
|
71
|
+
return z;
|
72
|
+
}
|
73
|
+
|
74
|
+
static inline dtype c_add(dtype x, dtype y) {
|
75
|
+
dtype z;
|
76
|
+
REAL(z) = REAL(x) + REAL(y);
|
77
|
+
IMAG(z) = IMAG(x) + IMAG(y);
|
78
|
+
return z;
|
79
|
+
}
|
80
|
+
|
81
|
+
static inline dtype c_sub(dtype x, dtype y) {
|
82
|
+
dtype z;
|
83
|
+
REAL(z) = REAL(x) - REAL(y);
|
84
|
+
IMAG(z) = IMAG(x) - IMAG(y);
|
85
|
+
return z;
|
86
|
+
}
|
87
|
+
|
88
|
+
static inline dtype c_mul(dtype x, dtype y) {
|
89
|
+
dtype z;
|
90
|
+
REAL(z) = REAL(x) * REAL(y) - IMAG(x) * IMAG(y);
|
91
|
+
IMAG(z) = REAL(x) * IMAG(y) + IMAG(x) * REAL(y);
|
92
|
+
return z;
|
93
|
+
}
|
94
|
+
|
95
|
+
static inline dtype c_mul_r(dtype x, rtype y) {
|
96
|
+
dtype z;
|
97
|
+
REAL(z) = REAL(x) * y;
|
98
|
+
IMAG(z) = IMAG(x) * y;
|
99
|
+
return z;
|
100
|
+
}
|
101
|
+
|
102
|
+
static inline dtype c_div(dtype x, dtype y) {
|
103
|
+
dtype z;
|
104
|
+
rtype s, yr, yi;
|
105
|
+
s = r_hypot(REAL(y), IMAG(y));
|
106
|
+
yr = REAL(y) / s;
|
107
|
+
yi = IMAG(y) / s;
|
108
|
+
REAL(z) = (REAL(x) * yr + IMAG(x) * yi) / s;
|
109
|
+
IMAG(z) = (IMAG(x) * yr - REAL(x) * yi) / s;
|
110
|
+
return z;
|
111
|
+
}
|
112
|
+
|
113
|
+
static inline dtype c_div_r(dtype x, rtype y) {
|
114
|
+
dtype z;
|
115
|
+
REAL(z) = REAL(x) / y;
|
116
|
+
IMAG(z) = IMAG(x) / y;
|
117
|
+
return z;
|
118
|
+
}
|
119
|
+
|
120
|
+
static inline dtype c_reciprocal(dtype x) {
|
121
|
+
dtype z;
|
122
|
+
if (r_abs(REAL(x)) > r_abs(IMAG(x))) {
|
123
|
+
IMAG(z) = IMAG(x) / REAL(x);
|
124
|
+
REAL(z) = (1 + IMAG(z) * IMAG(z)) * REAL(x);
|
125
|
+
IMAG(z) /= -REAL(z);
|
126
|
+
REAL(z) = 1 / REAL(z);
|
127
|
+
} else {
|
128
|
+
REAL(z) = REAL(x) / IMAG(x);
|
129
|
+
IMAG(z) = (1 + REAL(z) * REAL(z)) * IMAG(x);
|
130
|
+
REAL(z) /= IMAG(z);
|
131
|
+
IMAG(z) = -1 / IMAG(z);
|
132
|
+
}
|
133
|
+
return z;
|
134
|
+
}
|
135
|
+
|
136
|
+
static inline dtype c_square(dtype x) {
|
137
|
+
dtype z;
|
138
|
+
REAL(z) = REAL(x) * REAL(x) - IMAG(x) * IMAG(x);
|
139
|
+
IMAG(z) = 2 * REAL(x) * IMAG(x);
|
140
|
+
return z;
|
141
|
+
}
|
142
|
+
|
143
|
+
static inline dtype c_sqrt(dtype x) {
|
144
|
+
dtype z;
|
145
|
+
rtype xr, xi, r;
|
146
|
+
xr = REAL(x) / 2;
|
147
|
+
xi = IMAG(x) / 2;
|
148
|
+
r = r_hypot(xr, xi);
|
149
|
+
if (xr > 0) {
|
150
|
+
REAL(z) = sqrt(r + xr);
|
151
|
+
IMAG(z) = xi / REAL(z);
|
152
|
+
} else if ((r -= xr) != 0) {
|
153
|
+
IMAG(z) = (xi >= 0) ? sqrt(r) : -sqrt(r);
|
154
|
+
REAL(z) = xi / IMAG(z);
|
155
|
+
} else {
|
156
|
+
REAL(z) = IMAG(z) = 0;
|
157
|
+
}
|
158
|
+
return z;
|
159
|
+
}
|
160
|
+
|
161
|
+
static inline dtype c_log(dtype x) {
|
162
|
+
dtype z;
|
163
|
+
REAL(z) = r_log(r_hypot(REAL(x), IMAG(x)));
|
164
|
+
IMAG(z) = r_atan2(IMAG(x), REAL(x));
|
165
|
+
return z;
|
166
|
+
}
|
167
|
+
|
168
|
+
static inline dtype c_log2(dtype x) {
|
169
|
+
dtype z;
|
170
|
+
z = c_log(x);
|
171
|
+
z = c_mul_r(x, M_LOG2E);
|
172
|
+
return z;
|
173
|
+
}
|
174
|
+
|
175
|
+
static inline dtype c_log10(dtype x) {
|
176
|
+
dtype z;
|
177
|
+
z = c_log(x);
|
178
|
+
z = c_mul_r(x, M_LOG10E);
|
179
|
+
return z;
|
180
|
+
}
|
181
|
+
|
182
|
+
static inline dtype c_exp(dtype x) {
|
183
|
+
dtype z;
|
184
|
+
rtype a = r_exp(REAL(x));
|
185
|
+
REAL(z) = a * r_cos(IMAG(x));
|
186
|
+
IMAG(z) = a * r_sin(IMAG(x));
|
187
|
+
return z;
|
188
|
+
}
|
189
|
+
|
190
|
+
static inline dtype c_exp2(dtype x) {
|
191
|
+
dtype z;
|
192
|
+
rtype a = r_exp(REAL(x) * M_LN2);
|
193
|
+
REAL(z) = a * r_cos(IMAG(x));
|
194
|
+
IMAG(z) = a * r_sin(IMAG(x));
|
195
|
+
return z;
|
196
|
+
}
|
197
|
+
|
198
|
+
static inline dtype c_exp10(dtype x) {
|
199
|
+
dtype z;
|
200
|
+
rtype a = r_exp(REAL(x) * M_LN10);
|
201
|
+
REAL(z) = a * r_cos(IMAG(x));
|
202
|
+
IMAG(z) = a * r_sin(IMAG(x));
|
203
|
+
return z;
|
204
|
+
}
|
205
|
+
|
206
|
+
static inline dtype c_sin(dtype x) {
|
207
|
+
dtype z;
|
208
|
+
REAL(z) = r_sin(REAL(x)) * r_cosh(IMAG(x));
|
209
|
+
IMAG(z) = r_cos(REAL(x)) * r_sinh(IMAG(x));
|
210
|
+
return z;
|
211
|
+
}
|
212
|
+
|
213
|
+
static inline dtype c_sinh(dtype x) {
|
214
|
+
dtype z;
|
215
|
+
REAL(z) = r_sinh(REAL(x)) * r_cos(IMAG(x));
|
216
|
+
IMAG(z) = r_cosh(REAL(x)) * r_sin(IMAG(x));
|
217
|
+
return z;
|
218
|
+
}
|
219
|
+
|
220
|
+
static inline dtype c_cos(dtype x) {
|
221
|
+
dtype z;
|
222
|
+
REAL(z) = r_cos(REAL(x)) * r_cosh(IMAG(x));
|
223
|
+
IMAG(z) = -r_sin(REAL(x)) * r_sinh(IMAG(x));
|
224
|
+
return z;
|
225
|
+
}
|
226
|
+
|
227
|
+
static inline dtype c_cosh(dtype x) {
|
228
|
+
dtype z;
|
229
|
+
REAL(z) = r_cosh(REAL(x)) * r_cos(IMAG(x));
|
230
|
+
IMAG(z) = r_sinh(REAL(x)) * r_sin(IMAG(x));
|
231
|
+
return z;
|
232
|
+
}
|
233
|
+
|
234
|
+
static inline dtype c_tan(dtype x) {
|
235
|
+
dtype z;
|
236
|
+
rtype c, d;
|
237
|
+
if (r_abs(IMAG(x)) < 1) {
|
238
|
+
c = r_cos(REAL(x));
|
239
|
+
d = r_sinh(IMAG(x));
|
240
|
+
d = c * c + d * d;
|
241
|
+
REAL(z) = 0.5 * r_sin(2 * REAL(x)) / d;
|
242
|
+
IMAG(z) = 0.5 * r_sinh(2 * IMAG(x)) / d;
|
243
|
+
} else {
|
244
|
+
d = r_exp(-IMAG(x));
|
245
|
+
c = 2 * d / (1 - d * d);
|
246
|
+
c = c * c;
|
247
|
+
d = r_cos(REAL(x));
|
248
|
+
d = 1.0 + d * d * c;
|
249
|
+
REAL(z) = 0.5 * r_sin(2 * REAL(x)) * c / d;
|
250
|
+
IMAG(z) = 1 / r_tanh(IMAG(x)) / d;
|
251
|
+
}
|
252
|
+
return z;
|
253
|
+
}
|
254
|
+
|
255
|
+
static inline dtype c_tanh(dtype x) {
|
256
|
+
dtype z;
|
257
|
+
rtype c, d, s;
|
258
|
+
c = r_cos(IMAG(x));
|
259
|
+
s = r_sinh(REAL(x));
|
260
|
+
d = c * c + s * s;
|
261
|
+
if (r_abs(REAL(x)) < 1) {
|
262
|
+
REAL(z) = s * r_cosh(REAL(x)) / d;
|
263
|
+
IMAG(z) = 0.5 * r_sin(2 * IMAG(x)) / d;
|
264
|
+
} else {
|
265
|
+
c = c / s;
|
266
|
+
c = 1 + c * c;
|
267
|
+
REAL(z) = 1 / (r_tanh(REAL(x)) * c);
|
268
|
+
IMAG(z) = 0.5 * r_sin(2 * IMAG(x)) / d;
|
269
|
+
}
|
270
|
+
return z;
|
271
|
+
}
|
272
|
+
|
273
|
+
static inline dtype c_asin(dtype x) {
|
274
|
+
dtype z, y;
|
275
|
+
y = c_square(x);
|
276
|
+
REAL(y) = 1 - REAL(y);
|
277
|
+
IMAG(y) = -IMAG(y);
|
278
|
+
y = c_sqrt(y);
|
279
|
+
REAL(y) -= IMAG(x);
|
280
|
+
IMAG(y) += REAL(x);
|
281
|
+
y = c_log(y);
|
282
|
+
REAL(z) = IMAG(y);
|
283
|
+
IMAG(z) = -REAL(y);
|
284
|
+
return z;
|
285
|
+
}
|
286
|
+
|
287
|
+
static inline dtype c_asinh(dtype x) {
|
288
|
+
dtype z, y;
|
289
|
+
y = c_square(x);
|
290
|
+
REAL(y) += 1;
|
291
|
+
y = c_sqrt(y);
|
292
|
+
REAL(y) += REAL(x);
|
293
|
+
IMAG(y) += IMAG(x);
|
294
|
+
z = c_log(y);
|
295
|
+
return z;
|
296
|
+
}
|
297
|
+
|
298
|
+
static inline dtype c_acos(dtype x) {
|
299
|
+
dtype z, y;
|
300
|
+
y = c_square(x);
|
301
|
+
REAL(y) = 1 - REAL(y);
|
302
|
+
IMAG(y) = -IMAG(y);
|
303
|
+
y = c_sqrt(y);
|
304
|
+
REAL(z) = REAL(x) - IMAG(y);
|
305
|
+
IMAG(z) = IMAG(x) + REAL(y);
|
306
|
+
y = c_log(z);
|
307
|
+
REAL(z) = IMAG(y);
|
308
|
+
IMAG(z) = -REAL(y);
|
309
|
+
return z;
|
310
|
+
}
|
311
|
+
|
312
|
+
static inline dtype c_acosh(dtype x) {
|
313
|
+
dtype z, y;
|
314
|
+
y = c_square(x);
|
315
|
+
REAL(y) -= 1;
|
316
|
+
y = c_sqrt(y);
|
317
|
+
REAL(y) += REAL(x);
|
318
|
+
IMAG(y) += IMAG(x);
|
319
|
+
z = c_log(y);
|
320
|
+
return z;
|
321
|
+
}
|
322
|
+
|
323
|
+
static inline dtype c_atan(dtype x) {
|
324
|
+
dtype z, y;
|
325
|
+
REAL(y) = -REAL(x);
|
326
|
+
IMAG(y) = 1 - IMAG(x);
|
327
|
+
REAL(z) = REAL(x);
|
328
|
+
IMAG(z) = 1 + IMAG(x);
|
329
|
+
y = c_div(z, y);
|
330
|
+
y = c_log(y);
|
331
|
+
REAL(z) = -IMAG(y) / 2;
|
332
|
+
IMAG(z) = REAL(y) / 2;
|
333
|
+
return z;
|
334
|
+
}
|
335
|
+
|
336
|
+
static inline dtype c_atanh(dtype x) {
|
337
|
+
dtype z, y;
|
338
|
+
REAL(y) = 1 - REAL(x);
|
339
|
+
IMAG(y) = -IMAG(x);
|
340
|
+
REAL(z) = 1 + REAL(x);
|
341
|
+
IMAG(z) = IMAG(x);
|
342
|
+
y = c_div(z, y);
|
343
|
+
y = c_log(y);
|
344
|
+
REAL(z) = REAL(y) / 2;
|
345
|
+
IMAG(z) = IMAG(y) / 2;
|
346
|
+
return z;
|
347
|
+
}
|
348
|
+
|
349
|
+
static inline dtype c_pow(dtype x, dtype y) {
|
350
|
+
dtype z;
|
351
|
+
if (c_is_zero(y)) {
|
352
|
+
z = c_one();
|
353
|
+
} else if (c_is_zero(x) && REAL(y) > 0 && IMAG(y) == 0) {
|
354
|
+
z = c_zero();
|
355
|
+
} else {
|
356
|
+
z = c_log(x);
|
357
|
+
z = c_mul(y, z);
|
358
|
+
z = c_exp(z);
|
359
|
+
}
|
360
|
+
return z;
|
361
|
+
}
|
362
|
+
|
363
|
+
static inline dtype c_pow_int(dtype x, int p) {
|
364
|
+
dtype z = c_one();
|
365
|
+
if (p < 0) {
|
366
|
+
x = c_pow_int(x, -p);
|
367
|
+
return c_reciprocal(x);
|
368
|
+
}
|
369
|
+
if (p == 2) {
|
370
|
+
return c_square(x);
|
371
|
+
}
|
372
|
+
if (p & 1) {
|
373
|
+
z = x;
|
374
|
+
}
|
375
|
+
p >>= 1;
|
376
|
+
while (p) {
|
377
|
+
x = c_square(x);
|
378
|
+
if (p & 1) z = c_mul(z, x);
|
379
|
+
p >>= 1;
|
380
|
+
}
|
381
|
+
return z;
|
382
|
+
}
|
383
|
+
|
384
|
+
static inline dtype c_cbrt(dtype x) {
|
385
|
+
dtype z;
|
386
|
+
z = c_log(x);
|
387
|
+
z = c_div_r(z, 3);
|
388
|
+
z = c_exp(z);
|
389
|
+
return z;
|
390
|
+
}
|
391
|
+
|
392
|
+
static inline rtype c_abs(dtype x) {
|
393
|
+
return r_hypot(REAL(x), IMAG(x));
|
394
|
+
}
|
395
|
+
|
396
|
+
static inline rtype c_abs_square(dtype x) {
|
397
|
+
return REAL(x) * REAL(x) + IMAG(x) * IMAG(x);
|
398
|
+
}
|
399
|
+
|
400
|
+
/*
|
401
|
+
static inline rtype c_hypot(dtype x, dtype y) {
|
402
|
+
return r_hypot(c_abs(x),c_abs(y));
|
403
|
+
}
|
404
|
+
*/
|