cumo 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/3rd_party/LICENSE.txt +60 -0
- data/3rd_party/mkmf-cu/lib/mkmf-cu/cli.rb +13 -1
- data/LICENSE.txt +1 -62
- data/README.md +33 -29
- data/bench/cumo_bench.rb +47 -25
- data/bench/numo_bench.rb +27 -25
- data/docs/src-tree.md +16 -0
- data/ext/cumo/cuda/cublas.c +69 -219
- data/ext/cumo/cuda/memory_pool_impl.hpp +1 -0
- data/ext/cumo/cuda/runtime.c +2 -14
- data/ext/cumo/cumo.c +16 -16
- data/ext/cumo/include/cumo.h +2 -2
- data/ext/cumo/include/cumo/cuda/cublas.h +6 -129
- data/ext/cumo/include/cumo/cuda/runtime.h +16 -0
- data/ext/cumo/include/cumo/indexer.h +46 -63
- data/ext/cumo/include/cumo/intern.h +58 -112
- data/ext/cumo/include/cumo/narray.h +214 -185
- data/ext/cumo/include/cumo/narray_kernel.h +66 -37
- data/ext/cumo/include/cumo/ndloop.h +42 -42
- data/ext/cumo/include/cumo/reduce_kernel.h +55 -71
- data/ext/cumo/include/cumo/template.h +56 -51
- data/ext/cumo/include/cumo/template_kernel.h +31 -31
- data/ext/cumo/include/cumo/types/bit.h +3 -3
- data/ext/cumo/include/cumo/types/bit_kernel.h +2 -2
- data/ext/cumo/include/cumo/types/complex.h +126 -126
- data/ext/cumo/include/cumo/types/complex_kernel.h +126 -126
- data/ext/cumo/include/cumo/types/complex_macro.h +28 -28
- data/ext/cumo/include/cumo/types/complex_macro_kernel.h +20 -20
- data/ext/cumo/include/cumo/types/dcomplex.h +5 -5
- data/ext/cumo/include/cumo/types/dcomplex_kernel.h +1 -1
- data/ext/cumo/include/cumo/types/int_macro.h +1 -1
- data/ext/cumo/include/cumo/types/int_macro_kernel.h +1 -1
- data/ext/cumo/include/cumo/types/robj_macro.h +30 -30
- data/ext/cumo/include/cumo/types/scomplex.h +5 -5
- data/ext/cumo/include/cumo/types/scomplex_kernel.h +1 -1
- data/ext/cumo/narray/array.c +143 -143
- data/ext/cumo/narray/data.c +184 -184
- data/ext/cumo/narray/gen/cogen.rb +5 -2
- data/ext/cumo/narray/gen/cogen_kernel.rb +5 -2
- data/ext/cumo/narray/gen/def/dcomplex.rb +1 -1
- data/ext/cumo/narray/gen/def/scomplex.rb +1 -1
- data/ext/cumo/narray/gen/erbln.rb +132 -0
- data/ext/cumo/narray/gen/erbpp2.rb +18 -13
- data/ext/cumo/narray/gen/narray_def.rb +3 -3
- data/ext/cumo/narray/gen/spec.rb +2 -2
- data/ext/cumo/narray/gen/tmpl/accum.c +15 -15
- data/ext/cumo/narray/gen/tmpl/accum_binary.c +22 -22
- data/ext/cumo/narray/gen/tmpl/accum_binary_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/accum_index.c +30 -30
- data/ext/cumo/narray/gen/tmpl/accum_index_kernel.cu +2 -2
- data/ext/cumo/narray/gen/tmpl/accum_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/alloc_func.c +14 -14
- data/ext/cumo/narray/gen/tmpl/allocate.c +11 -11
- data/ext/cumo/narray/gen/tmpl/aref.c +2 -2
- data/ext/cumo/narray/gen/tmpl/aref_cpu.c +4 -4
- data/ext/cumo/narray/gen/tmpl/aset.c +2 -2
- data/ext/cumo/narray/gen/tmpl/binary.c +28 -28
- data/ext/cumo/narray/gen/tmpl/binary2.c +18 -18
- data/ext/cumo/narray/gen/tmpl/binary2_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/binary_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/binary_s.c +13 -13
- data/ext/cumo/narray/gen/tmpl/binary_s_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/bincount.c +23 -23
- data/ext/cumo/narray/gen/tmpl/cast.c +7 -7
- data/ext/cumo/narray/gen/tmpl/cast_array.c +3 -3
- data/ext/cumo/narray/gen/tmpl/clip.c +38 -38
- data/ext/cumo/narray/gen/tmpl/complex_accum_kernel.cu +2 -2
- data/ext/cumo/narray/gen/tmpl/cond_binary.c +19 -19
- data/ext/cumo/narray/gen/tmpl/cond_binary_kernel.cu +7 -7
- data/ext/cumo/narray/gen/tmpl/cond_unary.c +15 -15
- data/ext/cumo/narray/gen/tmpl/cum.c +15 -15
- data/ext/cumo/narray/gen/tmpl/each.c +9 -9
- data/ext/cumo/narray/gen/tmpl/each_with_index.c +9 -9
- data/ext/cumo/narray/gen/tmpl/ewcomp.c +15 -15
- data/ext/cumo/narray/gen/tmpl/ewcomp_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/extract_cpu.c +5 -5
- data/ext/cumo/narray/gen/tmpl/extract_data.c +12 -12
- data/ext/cumo/narray/gen/tmpl/eye.c +9 -9
- data/ext/cumo/narray/gen/tmpl/eye_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/fill.c +9 -9
- data/ext/cumo/narray/gen/tmpl/fill_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/float_accum_kernel.cu +1 -1
- data/ext/cumo/narray/gen/tmpl/format.c +11 -11
- data/ext/cumo/narray/gen/tmpl/format_to_a.c +8 -8
- data/ext/cumo/narray/gen/tmpl/frexp.c +13 -13
- data/ext/cumo/narray/gen/tmpl/gemm.c +252 -108
- data/ext/cumo/narray/gen/tmpl/inspect.c +1 -1
- data/ext/cumo/narray/gen/tmpl/lib.c +2 -2
- data/ext/cumo/narray/gen/tmpl/logseq.c +7 -7
- data/ext/cumo/narray/gen/tmpl/logseq_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/map_with_index.c +17 -17
- data/ext/cumo/narray/gen/tmpl/median.c +10 -10
- data/ext/cumo/narray/gen/tmpl/minmax.c +10 -10
- data/ext/cumo/narray/gen/tmpl/new_dim0.c +3 -3
- data/ext/cumo/narray/gen/tmpl/poly.c +6 -6
- data/ext/cumo/narray/gen/tmpl/pow.c +28 -28
- data/ext/cumo/narray/gen/tmpl/pow_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/rand.c +10 -10
- data/ext/cumo/narray/gen/tmpl/rand_norm.c +7 -7
- data/ext/cumo/narray/gen/tmpl/real_accum_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/seq.c +7 -7
- data/ext/cumo/narray/gen/tmpl/seq_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/set2.c +20 -20
- data/ext/cumo/narray/gen/tmpl/sort.c +11 -11
- data/ext/cumo/narray/gen/tmpl/sort_index.c +18 -18
- data/ext/cumo/narray/gen/tmpl/store.c +6 -6
- data/ext/cumo/narray/gen/tmpl/store_array.c +19 -19
- data/ext/cumo/narray/gen/tmpl/store_array_kernel.cu +12 -12
- data/ext/cumo/narray/gen/tmpl/store_bit.c +23 -23
- data/ext/cumo/narray/gen/tmpl/store_bit_kernel.cu +28 -28
- data/ext/cumo/narray/gen/tmpl/store_from.c +16 -16
- data/ext/cumo/narray/gen/tmpl/store_from_kernel.cu +12 -12
- data/ext/cumo/narray/gen/tmpl/to_a.c +10 -10
- data/ext/cumo/narray/gen/tmpl/unary.c +25 -25
- data/ext/cumo/narray/gen/tmpl/unary2.c +17 -17
- data/ext/cumo/narray/gen/tmpl/unary_kernel.cu +15 -15
- data/ext/cumo/narray/gen/tmpl/unary_ret2.c +13 -13
- data/ext/cumo/narray/gen/tmpl/unary_s.c +17 -17
- data/ext/cumo/narray/gen/tmpl/unary_s_kernel.cu +12 -12
- data/ext/cumo/narray/gen/tmpl_bit/allocate.c +9 -9
- data/ext/cumo/narray/gen/tmpl_bit/aref.c +2 -2
- data/ext/cumo/narray/gen/tmpl_bit/aref_cpu.c +5 -5
- data/ext/cumo/narray/gen/tmpl_bit/aset.c +2 -2
- data/ext/cumo/narray/gen/tmpl_bit/binary.c +29 -29
- data/ext/cumo/narray/gen/tmpl_bit/bit_count.c +14 -14
- data/ext/cumo/narray/gen/tmpl_bit/bit_count_cpu.c +21 -21
- data/ext/cumo/narray/gen/tmpl_bit/bit_count_kernel.cu +28 -28
- data/ext/cumo/narray/gen/tmpl_bit/bit_reduce.c +29 -29
- data/ext/cumo/narray/gen/tmpl_bit/each.c +10 -10
- data/ext/cumo/narray/gen/tmpl_bit/each_with_index.c +10 -10
- data/ext/cumo/narray/gen/tmpl_bit/extract.c +8 -8
- data/ext/cumo/narray/gen/tmpl_bit/extract_cpu.c +8 -8
- data/ext/cumo/narray/gen/tmpl_bit/fill.c +17 -17
- data/ext/cumo/narray/gen/tmpl_bit/format.c +14 -14
- data/ext/cumo/narray/gen/tmpl_bit/format_to_a.c +11 -11
- data/ext/cumo/narray/gen/tmpl_bit/inspect.c +3 -3
- data/ext/cumo/narray/gen/tmpl_bit/mask.c +33 -33
- data/ext/cumo/narray/gen/tmpl_bit/store_array.c +19 -19
- data/ext/cumo/narray/gen/tmpl_bit/store_bit.c +22 -22
- data/ext/cumo/narray/gen/tmpl_bit/store_from.c +18 -18
- data/ext/cumo/narray/gen/tmpl_bit/to_a.c +12 -12
- data/ext/cumo/narray/gen/tmpl_bit/unary.c +24 -24
- data/ext/cumo/narray/gen/tmpl_bit/where.c +16 -16
- data/ext/cumo/narray/gen/tmpl_bit/where2.c +20 -20
- data/ext/cumo/narray/index.c +213 -213
- data/ext/cumo/narray/math.c +27 -27
- data/ext/cumo/narray/narray.c +484 -484
- data/ext/cumo/narray/ndloop.c +259 -258
- data/ext/cumo/narray/rand.c +3 -3
- data/ext/cumo/narray/step.c +70 -70
- data/ext/cumo/narray/struct.c +139 -139
- metadata +6 -7
- data/ext/cumo/include/cumo/intern_fwd.h +0 -38
- data/lib/erbpp.rb +0 -294
- data/lib/erbpp/line_number.rb +0 -137
- data/lib/erbpp/narray_def.rb +0 -381
@@ -3,166 +3,166 @@
|
|
3
3
|
|
4
4
|
__host__ __device__ static inline dtype c_new(rtype r, rtype i) {
|
5
5
|
dtype z;
|
6
|
-
|
7
|
-
|
6
|
+
CUMO_REAL(z) = r;
|
7
|
+
CUMO_IMAG(z) = i;
|
8
8
|
return z;
|
9
9
|
}
|
10
10
|
|
11
11
|
__host__ __device__ static inline dtype c_set_real(dtype x, rtype r) {
|
12
|
-
|
12
|
+
CUMO_REAL(x)=r;
|
13
13
|
return x;
|
14
14
|
}
|
15
15
|
|
16
16
|
__host__ __device__ static inline dtype c_set_imag(dtype x, rtype i) {
|
17
|
-
|
17
|
+
CUMO_IMAG(x)=i;
|
18
18
|
return x;
|
19
19
|
}
|
20
20
|
|
21
21
|
//static inline VALUE COMP2NUM(dtype x) {
|
22
22
|
// VALUE v;
|
23
23
|
// v = rb_funcall(rb_intern("Kernel"), rb_intern("Complex"), 2,
|
24
|
-
// rb_float_new(
|
24
|
+
// rb_float_new(CUMO_REAL(x)), rb_float_new(CUMO_IMAG(x)));
|
25
25
|
// return v;
|
26
26
|
//}
|
27
27
|
//
|
28
28
|
//static inline dtype NUM2COMP(VALUE v) {
|
29
29
|
// dtype z;
|
30
|
-
//
|
31
|
-
//
|
30
|
+
// CUMO_REAL(z) = NUM2DBL(rb_funcall(v,cumo_id_real,0));
|
31
|
+
// CUMO_IMAG(z) = NUM2DBL(rb_funcall(v,cumo_id_imag,0));
|
32
32
|
// return z;
|
33
33
|
//}
|
34
34
|
|
35
|
-
#define c_is_zero(x) (
|
36
|
-
#define c_eq(x,y) (
|
37
|
-
#define c_ne(x,y) (
|
38
|
-
#define c_isnan(x) (isnan(
|
39
|
-
#define c_isinf(x) (isinf(
|
40
|
-
#define c_isposinf(x) ((isinf(
|
41
|
-
(isinf(
|
42
|
-
#define c_isneginf(x) ((isinf(
|
43
|
-
(isinf(
|
44
|
-
#define c_isfinite(x) (isfinite(
|
35
|
+
#define c_is_zero(x) (CUMO_REAL(x)==0 && CUMO_IMAG(x)==0)
|
36
|
+
#define c_eq(x,y) (CUMO_REAL(x)==CUMO_REAL(y) && CUMO_IMAG(x)==CUMO_IMAG(y))
|
37
|
+
#define c_ne(x,y) (CUMO_REAL(x)!=CUMO_REAL(y) || CUMO_IMAG(x)!=CUMO_IMAG(y))
|
38
|
+
#define c_isnan(x) (isnan(CUMO_REAL(x)) || isnan(CUMO_IMAG(x)))
|
39
|
+
#define c_isinf(x) (isinf(CUMO_REAL(x)) || isinf(CUMO_IMAG(x)))
|
40
|
+
#define c_isposinf(x) ((isinf(CUMO_REAL(x)) && signbit(CUMO_REAL(x))==0) || \
|
41
|
+
(isinf(CUMO_IMAG(x)) && signbit(CUMO_IMAG(x))==0))
|
42
|
+
#define c_isneginf(x) ((isinf(CUMO_REAL(x)) && signbit(CUMO_REAL(x))) || \
|
43
|
+
(isinf(CUMO_IMAG(x)) && signbit(CUMO_IMAG(x))))
|
44
|
+
#define c_isfinite(x) (isfinite(CUMO_REAL(x)) && isfinite(CUMO_IMAG(x)))
|
45
45
|
|
46
46
|
__host__ __device__ static inline dtype c_zero() {
|
47
47
|
dtype z;
|
48
|
-
|
49
|
-
|
48
|
+
CUMO_REAL(z) = 0;
|
49
|
+
CUMO_IMAG(z) = 0;
|
50
50
|
return z;
|
51
51
|
}
|
52
52
|
|
53
53
|
__host__ __device__ static inline dtype c_one() {
|
54
54
|
dtype z;
|
55
|
-
|
56
|
-
|
55
|
+
CUMO_REAL(z) = 1;
|
56
|
+
CUMO_IMAG(z) = 0;
|
57
57
|
return z;
|
58
58
|
}
|
59
59
|
|
60
60
|
__host__ __device__ static inline dtype c_minus(dtype x) {
|
61
61
|
dtype z;
|
62
|
-
|
63
|
-
|
62
|
+
CUMO_REAL(z) = -CUMO_REAL(x);
|
63
|
+
CUMO_IMAG(z) = -CUMO_IMAG(x);
|
64
64
|
return z;
|
65
65
|
}
|
66
66
|
|
67
67
|
__host__ __device__ static inline dtype c_im(dtype x) {
|
68
68
|
dtype z;
|
69
|
-
|
70
|
-
|
69
|
+
CUMO_REAL(z) = -CUMO_IMAG(x);
|
70
|
+
CUMO_IMAG(z) = CUMO_REAL(x);
|
71
71
|
return z;
|
72
72
|
}
|
73
73
|
|
74
74
|
__host__ __device__ static inline dtype c_add(dtype x, dtype y) {
|
75
75
|
dtype z;
|
76
|
-
|
77
|
-
|
76
|
+
CUMO_REAL(z) = CUMO_REAL(x)+CUMO_REAL(y);
|
77
|
+
CUMO_IMAG(z) = CUMO_IMAG(x)+CUMO_IMAG(y);
|
78
78
|
return z;
|
79
79
|
}
|
80
80
|
|
81
81
|
__host__ __device__ static inline dtype c_sub(dtype x, dtype y) {
|
82
82
|
dtype z;
|
83
|
-
|
84
|
-
|
83
|
+
CUMO_REAL(z) = CUMO_REAL(x)-CUMO_REAL(y);
|
84
|
+
CUMO_IMAG(z) = CUMO_IMAG(x)-CUMO_IMAG(y);
|
85
85
|
return z;
|
86
86
|
}
|
87
87
|
|
88
88
|
|
89
89
|
__host__ __device__ static inline dtype c_mul(dtype x, dtype y) {
|
90
90
|
dtype z;
|
91
|
-
|
92
|
-
|
91
|
+
CUMO_REAL(z) = CUMO_REAL(x)*CUMO_REAL(y)-CUMO_IMAG(x)*CUMO_IMAG(y);
|
92
|
+
CUMO_IMAG(z) = CUMO_REAL(x)*CUMO_IMAG(y)+CUMO_IMAG(x)*CUMO_REAL(y);
|
93
93
|
return z;
|
94
94
|
}
|
95
95
|
|
96
96
|
__host__ __device__ static inline dtype c_mul_r(dtype x, rtype y) {
|
97
97
|
dtype z;
|
98
|
-
|
99
|
-
|
98
|
+
CUMO_REAL(z) = CUMO_REAL(x)*y;
|
99
|
+
CUMO_IMAG(z) = CUMO_IMAG(x)*y;
|
100
100
|
return z;
|
101
101
|
}
|
102
102
|
|
103
103
|
__host__ __device__ static inline dtype c_div(dtype x, dtype y) {
|
104
104
|
dtype z;
|
105
105
|
rtype s,yr,yi;
|
106
|
-
s = r_hypot(
|
107
|
-
yr =
|
108
|
-
yi =
|
109
|
-
|
110
|
-
|
106
|
+
s = r_hypot(CUMO_REAL(y),CUMO_IMAG(y));
|
107
|
+
yr = CUMO_REAL(y)/s;
|
108
|
+
yi = CUMO_IMAG(y)/s;
|
109
|
+
CUMO_REAL(z) = (CUMO_REAL(x)*yr+CUMO_IMAG(x)*yi)/s;
|
110
|
+
CUMO_IMAG(z) = (CUMO_IMAG(x)*yr-CUMO_REAL(x)*yi)/s;
|
111
111
|
return z;
|
112
112
|
}
|
113
113
|
|
114
114
|
__host__ __device__ static inline dtype c_div_r(dtype x, rtype y) {
|
115
115
|
dtype z;
|
116
|
-
|
117
|
-
|
116
|
+
CUMO_REAL(z) = CUMO_REAL(x)/y;
|
117
|
+
CUMO_IMAG(z) = CUMO_IMAG(x)/y;
|
118
118
|
return z;
|
119
119
|
}
|
120
120
|
|
121
121
|
__host__ __device__ static inline dtype c_reciprocal(dtype x) {
|
122
122
|
dtype z;
|
123
|
-
if ( r_abs(
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
123
|
+
if ( r_abs(CUMO_REAL(x)) > r_abs(CUMO_IMAG(x)) ) {
|
124
|
+
CUMO_IMAG(z) = CUMO_IMAG(x)/CUMO_REAL(x);
|
125
|
+
CUMO_REAL(z) = (1+CUMO_IMAG(z)*CUMO_IMAG(z))*CUMO_REAL(x);
|
126
|
+
CUMO_IMAG(z) /= -CUMO_REAL(z);
|
127
|
+
CUMO_REAL(z) = 1/CUMO_REAL(z);
|
128
128
|
} else {
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
129
|
+
CUMO_REAL(z) = CUMO_REAL(x)/CUMO_IMAG(x);
|
130
|
+
CUMO_IMAG(z) = (1+CUMO_REAL(z)*CUMO_REAL(z))*CUMO_IMAG(x);
|
131
|
+
CUMO_REAL(z) /= CUMO_IMAG(z);
|
132
|
+
CUMO_IMAG(z) = -1/CUMO_IMAG(z);
|
133
133
|
}
|
134
134
|
return z;
|
135
135
|
}
|
136
136
|
|
137
137
|
__host__ __device__ static inline dtype c_square(dtype x) {
|
138
138
|
dtype z;
|
139
|
-
|
140
|
-
|
139
|
+
CUMO_REAL(z) = CUMO_REAL(x)*CUMO_REAL(x)-CUMO_IMAG(x)*CUMO_IMAG(x);
|
140
|
+
CUMO_IMAG(z) = 2*CUMO_REAL(x)*CUMO_IMAG(x);
|
141
141
|
return z;
|
142
142
|
}
|
143
143
|
|
144
144
|
__host__ __device__ static inline dtype c_sqrt(dtype x) {
|
145
145
|
dtype z;
|
146
146
|
rtype xr, xi, r;
|
147
|
-
xr =
|
148
|
-
xi =
|
147
|
+
xr = CUMO_REAL(x)/2;
|
148
|
+
xi = CUMO_IMAG(x)/2;
|
149
149
|
r = r_hypot(xr,xi);
|
150
150
|
if (xr>0) {
|
151
|
-
|
152
|
-
|
151
|
+
CUMO_REAL(z) = sqrt(r+xr);
|
152
|
+
CUMO_IMAG(z) = xi/CUMO_REAL(z);
|
153
153
|
} else if ( (r-=xr)!=0 ) {
|
154
|
-
|
155
|
-
|
154
|
+
CUMO_IMAG(z) = (xi>=0) ? sqrt(r):-sqrt(r);
|
155
|
+
CUMO_REAL(z) = xi/CUMO_IMAG(z);
|
156
156
|
} else {
|
157
|
-
|
157
|
+
CUMO_REAL(z) = CUMO_IMAG(z) = 0;
|
158
158
|
}
|
159
159
|
return z;
|
160
160
|
}
|
161
161
|
|
162
162
|
__host__ __device__ static inline dtype c_log(dtype x) {
|
163
163
|
dtype z;
|
164
|
-
|
165
|
-
|
164
|
+
CUMO_REAL(z) = r_log(r_hypot(CUMO_REAL(x),CUMO_IMAG(x)));
|
165
|
+
CUMO_IMAG(z) = r_atan2(CUMO_IMAG(x),CUMO_REAL(x));
|
166
166
|
return z;
|
167
167
|
}
|
168
168
|
|
@@ -182,73 +182,73 @@ __host__ __device__ static inline dtype c_log10(dtype x) {
|
|
182
182
|
|
183
183
|
__host__ __device__ static inline dtype c_exp(dtype x) {
|
184
184
|
dtype z;
|
185
|
-
rtype a = r_exp(
|
186
|
-
|
187
|
-
|
185
|
+
rtype a = r_exp(CUMO_REAL(x));
|
186
|
+
CUMO_REAL(z) = a*r_cos(CUMO_IMAG(x));
|
187
|
+
CUMO_IMAG(z) = a*r_sin(CUMO_IMAG(x));
|
188
188
|
return z;
|
189
189
|
}
|
190
190
|
|
191
191
|
__host__ __device__ static inline dtype c_exp2(dtype x) {
|
192
192
|
dtype z;
|
193
|
-
rtype a = r_exp(
|
194
|
-
|
195
|
-
|
193
|
+
rtype a = r_exp(CUMO_REAL(x)*M_LN2);
|
194
|
+
CUMO_REAL(z) = a*r_cos(CUMO_IMAG(x));
|
195
|
+
CUMO_IMAG(z) = a*r_sin(CUMO_IMAG(x));
|
196
196
|
return z;
|
197
197
|
}
|
198
198
|
|
199
199
|
__host__ __device__ static inline dtype c_exp10(dtype x) {
|
200
200
|
dtype z;
|
201
|
-
rtype a = r_exp(
|
202
|
-
|
203
|
-
|
201
|
+
rtype a = r_exp(CUMO_REAL(x)*M_LN10);
|
202
|
+
CUMO_REAL(z) = a*r_cos(CUMO_IMAG(x));
|
203
|
+
CUMO_IMAG(z) = a*r_sin(CUMO_IMAG(x));
|
204
204
|
return z;
|
205
205
|
}
|
206
206
|
|
207
207
|
__host__ __device__ static inline dtype c_sin(dtype x) {
|
208
208
|
dtype z;
|
209
|
-
|
210
|
-
|
209
|
+
CUMO_REAL(z) = r_sin(CUMO_REAL(x))*r_cosh(CUMO_IMAG(x));
|
210
|
+
CUMO_IMAG(z) = r_cos(CUMO_REAL(x))*r_sinh(CUMO_IMAG(x));
|
211
211
|
return z;
|
212
212
|
}
|
213
213
|
|
214
214
|
__host__ __device__ static inline dtype c_sinh(dtype x) {
|
215
215
|
dtype z;
|
216
|
-
|
217
|
-
|
216
|
+
CUMO_REAL(z) = r_sinh(CUMO_REAL(x))*r_cos(CUMO_IMAG(x));
|
217
|
+
CUMO_IMAG(z) = r_cosh(CUMO_REAL(x))*r_sin(CUMO_IMAG(x));
|
218
218
|
return z;
|
219
219
|
}
|
220
220
|
|
221
221
|
__host__ __device__ static inline dtype c_cos(dtype x) {
|
222
222
|
dtype z;
|
223
|
-
|
224
|
-
|
223
|
+
CUMO_REAL(z) = r_cos(CUMO_REAL(x))*r_cosh(CUMO_IMAG(x));
|
224
|
+
CUMO_IMAG(z) = -r_sin(CUMO_REAL(x))*r_sinh(CUMO_IMAG(x));
|
225
225
|
return z;
|
226
226
|
}
|
227
227
|
|
228
228
|
__host__ __device__ static inline dtype c_cosh(dtype x) {
|
229
229
|
dtype z;
|
230
|
-
|
231
|
-
|
230
|
+
CUMO_REAL(z) = r_cosh(CUMO_REAL(x))*r_cos(CUMO_IMAG(x));
|
231
|
+
CUMO_IMAG(z) = r_sinh(CUMO_REAL(x))*r_sin(CUMO_IMAG(x));
|
232
232
|
return z;
|
233
233
|
}
|
234
234
|
|
235
235
|
__host__ __device__ static inline dtype c_tan(dtype x) {
|
236
236
|
dtype z;
|
237
237
|
rtype c, d;
|
238
|
-
if (r_abs(
|
239
|
-
c = r_cos(
|
240
|
-
d = r_sinh(
|
238
|
+
if (r_abs(CUMO_IMAG(x))<1) {
|
239
|
+
c = r_cos(CUMO_REAL(x));
|
240
|
+
d = r_sinh(CUMO_IMAG(x));
|
241
241
|
d = c*c + d*d;
|
242
|
-
|
243
|
-
|
242
|
+
CUMO_REAL(z) = 0.5*r_sin(2*CUMO_REAL(x))/d;
|
243
|
+
CUMO_IMAG(z) = 0.5*r_sinh(2*CUMO_IMAG(x))/d;
|
244
244
|
} else {
|
245
|
-
d = r_exp(-
|
245
|
+
d = r_exp(-CUMO_IMAG(x));
|
246
246
|
c = 2*d/(1-d*d);
|
247
247
|
c = c*c;
|
248
|
-
d = r_cos(
|
248
|
+
d = r_cos(CUMO_REAL(x));
|
249
249
|
d = 1.0 + d*d*c;
|
250
|
-
|
251
|
-
|
250
|
+
CUMO_REAL(z) = 0.5*r_sin(2*CUMO_REAL(x))*c/d;
|
251
|
+
CUMO_IMAG(z) = 1/r_tanh(CUMO_IMAG(x))/d;
|
252
252
|
}
|
253
253
|
return z;
|
254
254
|
}
|
@@ -256,17 +256,17 @@ __host__ __device__ static inline dtype c_tan(dtype x) {
|
|
256
256
|
__host__ __device__ static inline dtype c_tanh(dtype x) {
|
257
257
|
dtype z;
|
258
258
|
rtype c, d, s;
|
259
|
-
c = r_cos(
|
260
|
-
s = r_sinh(
|
259
|
+
c = r_cos(CUMO_IMAG(x));
|
260
|
+
s = r_sinh(CUMO_REAL(x));
|
261
261
|
d = c*c + s*s;
|
262
|
-
if (r_abs(
|
263
|
-
|
264
|
-
|
262
|
+
if (r_abs(CUMO_REAL(x))<1) {
|
263
|
+
CUMO_REAL(z) = s*r_cosh(CUMO_REAL(x))/d;
|
264
|
+
CUMO_IMAG(z) = 0.5*r_sin(2*CUMO_IMAG(x))/d;
|
265
265
|
} else {
|
266
266
|
c = c / s;
|
267
267
|
c = 1 + c*c;
|
268
|
-
|
269
|
-
|
268
|
+
CUMO_REAL(z) = 1/(r_tanh(CUMO_REAL(x))*c);
|
269
|
+
CUMO_IMAG(z) = 0.5*r_sin(2*CUMO_IMAG(x))/d;
|
270
270
|
}
|
271
271
|
return z;
|
272
272
|
}
|
@@ -274,24 +274,24 @@ __host__ __device__ static inline dtype c_tanh(dtype x) {
|
|
274
274
|
__host__ __device__ static inline dtype c_asin(dtype x) {
|
275
275
|
dtype z, y;
|
276
276
|
y = c_square(x);
|
277
|
-
|
278
|
-
|
277
|
+
CUMO_REAL(y) = 1-CUMO_REAL(y);
|
278
|
+
CUMO_IMAG(y) = -CUMO_IMAG(y);
|
279
279
|
y = c_sqrt(y);
|
280
|
-
|
281
|
-
|
280
|
+
CUMO_REAL(y) -= CUMO_IMAG(x);
|
281
|
+
CUMO_IMAG(y) += CUMO_REAL(x);
|
282
282
|
y = c_log(y);
|
283
|
-
|
284
|
-
|
283
|
+
CUMO_REAL(z) = CUMO_IMAG(y);
|
284
|
+
CUMO_IMAG(z) = -CUMO_REAL(y);
|
285
285
|
return z;
|
286
286
|
}
|
287
287
|
|
288
288
|
__host__ __device__ static inline dtype c_asinh(dtype x) {
|
289
289
|
dtype z, y;
|
290
290
|
y = c_square(x);
|
291
|
-
|
291
|
+
CUMO_REAL(y) += 1;
|
292
292
|
y = c_sqrt(y);
|
293
|
-
|
294
|
-
|
293
|
+
CUMO_REAL(y) += CUMO_REAL(x);
|
294
|
+
CUMO_IMAG(y) += CUMO_IMAG(x);
|
295
295
|
z = c_log(y);
|
296
296
|
return z;
|
297
297
|
}
|
@@ -299,51 +299,51 @@ __host__ __device__ static inline dtype c_asinh(dtype x) {
|
|
299
299
|
__host__ __device__ static inline dtype c_acos(dtype x) {
|
300
300
|
dtype z, y;
|
301
301
|
y = c_square(x);
|
302
|
-
|
303
|
-
|
302
|
+
CUMO_REAL(y) = 1-CUMO_REAL(y);
|
303
|
+
CUMO_IMAG(y) = -CUMO_IMAG(y);
|
304
304
|
y = c_sqrt(y);
|
305
|
-
|
306
|
-
|
305
|
+
CUMO_REAL(z) = CUMO_REAL(x)-CUMO_IMAG(y);
|
306
|
+
CUMO_IMAG(z) = CUMO_IMAG(x)+CUMO_REAL(y);
|
307
307
|
y = c_log(z);
|
308
|
-
|
309
|
-
|
308
|
+
CUMO_REAL(z) = CUMO_IMAG(y);
|
309
|
+
CUMO_IMAG(z) = -CUMO_REAL(y);
|
310
310
|
return z;
|
311
311
|
}
|
312
312
|
|
313
313
|
__host__ __device__ static inline dtype c_acosh(dtype x) {
|
314
314
|
dtype z, y;
|
315
315
|
y = c_square(x);
|
316
|
-
|
316
|
+
CUMO_REAL(y) -= 1;
|
317
317
|
y = c_sqrt(y);
|
318
|
-
|
319
|
-
|
318
|
+
CUMO_REAL(y) += CUMO_REAL(x);
|
319
|
+
CUMO_IMAG(y) += CUMO_IMAG(x);
|
320
320
|
z = c_log(y);
|
321
321
|
return z;
|
322
322
|
}
|
323
323
|
|
324
324
|
__host__ __device__ static inline dtype c_atan(dtype x) {
|
325
325
|
dtype z, y;
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
326
|
+
CUMO_REAL(y) = -CUMO_REAL(x);
|
327
|
+
CUMO_IMAG(y) = 1-CUMO_IMAG(x);
|
328
|
+
CUMO_REAL(z) = CUMO_REAL(x);
|
329
|
+
CUMO_IMAG(z) = 1+CUMO_IMAG(x);
|
330
330
|
y = c_div(z,y);
|
331
331
|
y = c_log(y);
|
332
|
-
|
333
|
-
|
332
|
+
CUMO_REAL(z) = -CUMO_IMAG(y)/2;
|
333
|
+
CUMO_IMAG(z) = CUMO_REAL(y)/2;
|
334
334
|
return z;
|
335
335
|
}
|
336
336
|
|
337
337
|
__host__ __device__ static inline dtype c_atanh(dtype x) {
|
338
338
|
dtype z, y;
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
339
|
+
CUMO_REAL(y) = 1-CUMO_REAL(x);
|
340
|
+
CUMO_IMAG(y) = -CUMO_IMAG(x);
|
341
|
+
CUMO_REAL(z) = 1+CUMO_REAL(x);
|
342
|
+
CUMO_IMAG(z) = CUMO_IMAG(x);
|
343
343
|
y = c_div(z,y);
|
344
344
|
y = c_log(y);
|
345
|
-
|
346
|
-
|
345
|
+
CUMO_REAL(z) = CUMO_REAL(y)/2;
|
346
|
+
CUMO_IMAG(z) = CUMO_IMAG(y)/2;
|
347
347
|
return z;
|
348
348
|
}
|
349
349
|
|
@@ -352,7 +352,7 @@ __host__ __device__ static inline dtype c_pow(dtype x, dtype y)
|
|
352
352
|
dtype z;
|
353
353
|
if (c_is_zero(y)) {
|
354
354
|
z = c_one();
|
355
|
-
} else if (c_is_zero(x) &&
|
355
|
+
} else if (c_is_zero(x) && CUMO_REAL(y)>0 && CUMO_IMAG(y)==0) {
|
356
356
|
z = c_zero();
|
357
357
|
} else {
|
358
358
|
z = c_log(x);
|
@@ -396,11 +396,11 @@ __host__ __device__ static inline dtype c_cbrt(dtype x) {
|
|
396
396
|
}
|
397
397
|
|
398
398
|
__host__ __device__ static inline rtype c_abs(dtype x) {
|
399
|
-
return r_hypot(
|
399
|
+
return r_hypot(CUMO_REAL(x),CUMO_IMAG(x));
|
400
400
|
}
|
401
401
|
|
402
402
|
__host__ __device__ static inline rtype c_abs_square(dtype x) {
|
403
|
-
return
|
403
|
+
return CUMO_REAL(x)*CUMO_REAL(x)+CUMO_IMAG(x)*CUMO_IMAG(x);
|
404
404
|
}
|
405
405
|
|
406
406
|
|