cumo 0.1.0
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/.gitignore +27 -0
- data/.travis.yml +5 -0
- data/3rd_party/mkmf-cu/.gitignore +36 -0
- data/3rd_party/mkmf-cu/Gemfile +3 -0
- data/3rd_party/mkmf-cu/LICENSE +21 -0
- data/3rd_party/mkmf-cu/README.md +36 -0
- data/3rd_party/mkmf-cu/Rakefile +11 -0
- data/3rd_party/mkmf-cu/bin/mkmf-cu-nvcc +4 -0
- data/3rd_party/mkmf-cu/lib/mkmf-cu.rb +32 -0
- data/3rd_party/mkmf-cu/lib/mkmf-cu/cli.rb +80 -0
- data/3rd_party/mkmf-cu/lib/mkmf-cu/nvcc.rb +157 -0
- data/3rd_party/mkmf-cu/mkmf-cu.gemspec +16 -0
- data/3rd_party/mkmf-cu/test/test_mkmf-cu.rb +67 -0
- data/CODE_OF_CONDUCT.md +46 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +82 -0
- data/README.md +252 -0
- data/Rakefile +43 -0
- data/bench/broadcast_fp32.rb +138 -0
- data/bench/cumo_bench.rb +193 -0
- data/bench/numo_bench.rb +138 -0
- data/bench/reduction_fp32.rb +117 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/cumo.gemspec +32 -0
- data/ext/cumo/cuda/cublas.c +278 -0
- data/ext/cumo/cuda/driver.c +421 -0
- data/ext/cumo/cuda/memory_pool.cpp +185 -0
- data/ext/cumo/cuda/memory_pool_impl.cpp +308 -0
- data/ext/cumo/cuda/memory_pool_impl.hpp +370 -0
- data/ext/cumo/cuda/memory_pool_impl_test.cpp +554 -0
- data/ext/cumo/cuda/nvrtc.c +207 -0
- data/ext/cumo/cuda/runtime.c +167 -0
- data/ext/cumo/cumo.c +148 -0
- data/ext/cumo/depend.erb +58 -0
- data/ext/cumo/extconf.rb +179 -0
- data/ext/cumo/include/cumo.h +25 -0
- data/ext/cumo/include/cumo/compat.h +23 -0
- data/ext/cumo/include/cumo/cuda/cublas.h +153 -0
- data/ext/cumo/include/cumo/cuda/cumo_thrust.hpp +187 -0
- data/ext/cumo/include/cumo/cuda/cumo_thrust_complex.hpp +79 -0
- data/ext/cumo/include/cumo/cuda/driver.h +22 -0
- data/ext/cumo/include/cumo/cuda/memory_pool.h +28 -0
- data/ext/cumo/include/cumo/cuda/nvrtc.h +22 -0
- data/ext/cumo/include/cumo/cuda/runtime.h +40 -0
- data/ext/cumo/include/cumo/indexer.h +238 -0
- data/ext/cumo/include/cumo/intern.h +142 -0
- data/ext/cumo/include/cumo/intern_fwd.h +38 -0
- data/ext/cumo/include/cumo/intern_kernel.h +6 -0
- data/ext/cumo/include/cumo/narray.h +429 -0
- data/ext/cumo/include/cumo/narray_kernel.h +149 -0
- data/ext/cumo/include/cumo/ndloop.h +95 -0
- data/ext/cumo/include/cumo/reduce_kernel.h +126 -0
- data/ext/cumo/include/cumo/template.h +158 -0
- data/ext/cumo/include/cumo/template_kernel.h +77 -0
- data/ext/cumo/include/cumo/types/bit.h +40 -0
- data/ext/cumo/include/cumo/types/bit_kernel.h +34 -0
- data/ext/cumo/include/cumo/types/complex.h +402 -0
- data/ext/cumo/include/cumo/types/complex_kernel.h +414 -0
- data/ext/cumo/include/cumo/types/complex_macro.h +382 -0
- data/ext/cumo/include/cumo/types/complex_macro_kernel.h +186 -0
- data/ext/cumo/include/cumo/types/dcomplex.h +46 -0
- data/ext/cumo/include/cumo/types/dcomplex_kernel.h +13 -0
- data/ext/cumo/include/cumo/types/dfloat.h +47 -0
- data/ext/cumo/include/cumo/types/dfloat_kernel.h +14 -0
- data/ext/cumo/include/cumo/types/float_def.h +34 -0
- data/ext/cumo/include/cumo/types/float_def_kernel.h +39 -0
- data/ext/cumo/include/cumo/types/float_macro.h +191 -0
- data/ext/cumo/include/cumo/types/float_macro_kernel.h +158 -0
- data/ext/cumo/include/cumo/types/int16.h +24 -0
- data/ext/cumo/include/cumo/types/int16_kernel.h +23 -0
- data/ext/cumo/include/cumo/types/int32.h +24 -0
- data/ext/cumo/include/cumo/types/int32_kernel.h +19 -0
- data/ext/cumo/include/cumo/types/int64.h +24 -0
- data/ext/cumo/include/cumo/types/int64_kernel.h +19 -0
- data/ext/cumo/include/cumo/types/int8.h +24 -0
- data/ext/cumo/include/cumo/types/int8_kernel.h +19 -0
- data/ext/cumo/include/cumo/types/int_macro.h +67 -0
- data/ext/cumo/include/cumo/types/int_macro_kernel.h +48 -0
- data/ext/cumo/include/cumo/types/real_accum.h +486 -0
- data/ext/cumo/include/cumo/types/real_accum_kernel.h +101 -0
- data/ext/cumo/include/cumo/types/robj_macro.h +80 -0
- data/ext/cumo/include/cumo/types/robj_macro_kernel.h +0 -0
- data/ext/cumo/include/cumo/types/robject.h +27 -0
- data/ext/cumo/include/cumo/types/robject_kernel.h +7 -0
- data/ext/cumo/include/cumo/types/scomplex.h +46 -0
- data/ext/cumo/include/cumo/types/scomplex_kernel.h +13 -0
- data/ext/cumo/include/cumo/types/sfloat.h +48 -0
- data/ext/cumo/include/cumo/types/sfloat_kernel.h +14 -0
- data/ext/cumo/include/cumo/types/uint16.h +25 -0
- data/ext/cumo/include/cumo/types/uint16_kernel.h +20 -0
- data/ext/cumo/include/cumo/types/uint32.h +25 -0
- data/ext/cumo/include/cumo/types/uint32_kernel.h +20 -0
- data/ext/cumo/include/cumo/types/uint64.h +25 -0
- data/ext/cumo/include/cumo/types/uint64_kernel.h +20 -0
- data/ext/cumo/include/cumo/types/uint8.h +25 -0
- data/ext/cumo/include/cumo/types/uint8_kernel.h +20 -0
- data/ext/cumo/include/cumo/types/uint_macro.h +58 -0
- data/ext/cumo/include/cumo/types/uint_macro_kernel.h +38 -0
- data/ext/cumo/include/cumo/types/xint_macro.h +169 -0
- data/ext/cumo/include/cumo/types/xint_macro_kernel.h +88 -0
- data/ext/cumo/narray/SFMT-params.h +97 -0
- data/ext/cumo/narray/SFMT-params19937.h +46 -0
- data/ext/cumo/narray/SFMT.c +620 -0
- data/ext/cumo/narray/SFMT.h +167 -0
- data/ext/cumo/narray/array.c +638 -0
- data/ext/cumo/narray/data.c +961 -0
- data/ext/cumo/narray/gen/cogen.rb +56 -0
- data/ext/cumo/narray/gen/cogen_kernel.rb +58 -0
- data/ext/cumo/narray/gen/def/bit.rb +37 -0
- data/ext/cumo/narray/gen/def/dcomplex.rb +39 -0
- data/ext/cumo/narray/gen/def/dfloat.rb +37 -0
- data/ext/cumo/narray/gen/def/int16.rb +36 -0
- data/ext/cumo/narray/gen/def/int32.rb +36 -0
- data/ext/cumo/narray/gen/def/int64.rb +36 -0
- data/ext/cumo/narray/gen/def/int8.rb +36 -0
- data/ext/cumo/narray/gen/def/robject.rb +37 -0
- data/ext/cumo/narray/gen/def/scomplex.rb +39 -0
- data/ext/cumo/narray/gen/def/sfloat.rb +37 -0
- data/ext/cumo/narray/gen/def/uint16.rb +36 -0
- data/ext/cumo/narray/gen/def/uint32.rb +36 -0
- data/ext/cumo/narray/gen/def/uint64.rb +36 -0
- data/ext/cumo/narray/gen/def/uint8.rb +36 -0
- data/ext/cumo/narray/gen/erbpp2.rb +346 -0
- data/ext/cumo/narray/gen/narray_def.rb +268 -0
- data/ext/cumo/narray/gen/spec.rb +425 -0
- data/ext/cumo/narray/gen/tmpl/accum.c +86 -0
- data/ext/cumo/narray/gen/tmpl/accum_binary.c +121 -0
- data/ext/cumo/narray/gen/tmpl/accum_binary_kernel.cu +61 -0
- data/ext/cumo/narray/gen/tmpl/accum_index.c +119 -0
- data/ext/cumo/narray/gen/tmpl/accum_index_kernel.cu +66 -0
- data/ext/cumo/narray/gen/tmpl/accum_kernel.cu +12 -0
- data/ext/cumo/narray/gen/tmpl/alloc_func.c +107 -0
- data/ext/cumo/narray/gen/tmpl/allocate.c +37 -0
- data/ext/cumo/narray/gen/tmpl/aref.c +66 -0
- data/ext/cumo/narray/gen/tmpl/aref_cpu.c +50 -0
- data/ext/cumo/narray/gen/tmpl/aset.c +56 -0
- data/ext/cumo/narray/gen/tmpl/binary.c +162 -0
- data/ext/cumo/narray/gen/tmpl/binary2.c +70 -0
- data/ext/cumo/narray/gen/tmpl/binary2_kernel.cu +15 -0
- data/ext/cumo/narray/gen/tmpl/binary_kernel.cu +31 -0
- data/ext/cumo/narray/gen/tmpl/binary_s.c +45 -0
- data/ext/cumo/narray/gen/tmpl/binary_s_kernel.cu +15 -0
- data/ext/cumo/narray/gen/tmpl/bincount.c +181 -0
- data/ext/cumo/narray/gen/tmpl/cast.c +44 -0
- data/ext/cumo/narray/gen/tmpl/cast_array.c +13 -0
- data/ext/cumo/narray/gen/tmpl/class.c +9 -0
- data/ext/cumo/narray/gen/tmpl/class_kernel.cu +6 -0
- data/ext/cumo/narray/gen/tmpl/clip.c +121 -0
- data/ext/cumo/narray/gen/tmpl/coerce_cast.c +10 -0
- data/ext/cumo/narray/gen/tmpl/complex_accum_kernel.cu +129 -0
- data/ext/cumo/narray/gen/tmpl/cond_binary.c +68 -0
- data/ext/cumo/narray/gen/tmpl/cond_binary_kernel.cu +18 -0
- data/ext/cumo/narray/gen/tmpl/cond_unary.c +46 -0
- data/ext/cumo/narray/gen/tmpl/cum.c +50 -0
- data/ext/cumo/narray/gen/tmpl/each.c +47 -0
- data/ext/cumo/narray/gen/tmpl/each_with_index.c +70 -0
- data/ext/cumo/narray/gen/tmpl/ewcomp.c +79 -0
- data/ext/cumo/narray/gen/tmpl/ewcomp_kernel.cu +19 -0
- data/ext/cumo/narray/gen/tmpl/extract.c +22 -0
- data/ext/cumo/narray/gen/tmpl/extract_cpu.c +26 -0
- data/ext/cumo/narray/gen/tmpl/extract_data.c +53 -0
- data/ext/cumo/narray/gen/tmpl/eye.c +105 -0
- data/ext/cumo/narray/gen/tmpl/eye_kernel.cu +19 -0
- data/ext/cumo/narray/gen/tmpl/fill.c +52 -0
- data/ext/cumo/narray/gen/tmpl/fill_kernel.cu +29 -0
- data/ext/cumo/narray/gen/tmpl/float_accum_kernel.cu +106 -0
- data/ext/cumo/narray/gen/tmpl/format.c +62 -0
- data/ext/cumo/narray/gen/tmpl/format_to_a.c +49 -0
- data/ext/cumo/narray/gen/tmpl/frexp.c +38 -0
- data/ext/cumo/narray/gen/tmpl/gemm.c +203 -0
- data/ext/cumo/narray/gen/tmpl/init_class.c +20 -0
- data/ext/cumo/narray/gen/tmpl/init_module.c +12 -0
- data/ext/cumo/narray/gen/tmpl/inspect.c +21 -0
- data/ext/cumo/narray/gen/tmpl/lib.c +50 -0
- data/ext/cumo/narray/gen/tmpl/lib_kernel.cu +24 -0
- data/ext/cumo/narray/gen/tmpl/logseq.c +102 -0
- data/ext/cumo/narray/gen/tmpl/logseq_kernel.cu +31 -0
- data/ext/cumo/narray/gen/tmpl/map_with_index.c +98 -0
- data/ext/cumo/narray/gen/tmpl/median.c +66 -0
- data/ext/cumo/narray/gen/tmpl/minmax.c +47 -0
- data/ext/cumo/narray/gen/tmpl/module.c +9 -0
- data/ext/cumo/narray/gen/tmpl/module_kernel.cu +1 -0
- data/ext/cumo/narray/gen/tmpl/new_dim0.c +15 -0
- data/ext/cumo/narray/gen/tmpl/new_dim0_kernel.cu +8 -0
- data/ext/cumo/narray/gen/tmpl/poly.c +50 -0
- data/ext/cumo/narray/gen/tmpl/pow.c +97 -0
- data/ext/cumo/narray/gen/tmpl/pow_kernel.cu +29 -0
- data/ext/cumo/narray/gen/tmpl/powint.c +17 -0
- data/ext/cumo/narray/gen/tmpl/qsort.c +212 -0
- data/ext/cumo/narray/gen/tmpl/rand.c +168 -0
- data/ext/cumo/narray/gen/tmpl/rand_norm.c +121 -0
- data/ext/cumo/narray/gen/tmpl/real_accum_kernel.cu +75 -0
- data/ext/cumo/narray/gen/tmpl/seq.c +112 -0
- data/ext/cumo/narray/gen/tmpl/seq_kernel.cu +43 -0
- data/ext/cumo/narray/gen/tmpl/set2.c +57 -0
- data/ext/cumo/narray/gen/tmpl/sort.c +48 -0
- data/ext/cumo/narray/gen/tmpl/sort_index.c +111 -0
- data/ext/cumo/narray/gen/tmpl/store.c +41 -0
- data/ext/cumo/narray/gen/tmpl/store_array.c +187 -0
- data/ext/cumo/narray/gen/tmpl/store_array_kernel.cu +58 -0
- data/ext/cumo/narray/gen/tmpl/store_bit.c +86 -0
- data/ext/cumo/narray/gen/tmpl/store_bit_kernel.cu +66 -0
- data/ext/cumo/narray/gen/tmpl/store_from.c +81 -0
- data/ext/cumo/narray/gen/tmpl/store_from_kernel.cu +58 -0
- data/ext/cumo/narray/gen/tmpl/store_kernel.cu +3 -0
- data/ext/cumo/narray/gen/tmpl/store_numeric.c +9 -0
- data/ext/cumo/narray/gen/tmpl/to_a.c +43 -0
- data/ext/cumo/narray/gen/tmpl/unary.c +132 -0
- data/ext/cumo/narray/gen/tmpl/unary2.c +60 -0
- data/ext/cumo/narray/gen/tmpl/unary_kernel.cu +72 -0
- data/ext/cumo/narray/gen/tmpl/unary_ret2.c +34 -0
- data/ext/cumo/narray/gen/tmpl/unary_s.c +86 -0
- data/ext/cumo/narray/gen/tmpl/unary_s_kernel.cu +58 -0
- data/ext/cumo/narray/gen/tmpl_bit/allocate.c +24 -0
- data/ext/cumo/narray/gen/tmpl_bit/aref.c +54 -0
- data/ext/cumo/narray/gen/tmpl_bit/aref_cpu.c +57 -0
- data/ext/cumo/narray/gen/tmpl_bit/aset.c +56 -0
- data/ext/cumo/narray/gen/tmpl_bit/binary.c +98 -0
- data/ext/cumo/narray/gen/tmpl_bit/bit_count.c +64 -0
- data/ext/cumo/narray/gen/tmpl_bit/bit_count_cpu.c +88 -0
- data/ext/cumo/narray/gen/tmpl_bit/bit_count_kernel.cu +76 -0
- data/ext/cumo/narray/gen/tmpl_bit/bit_reduce.c +133 -0
- data/ext/cumo/narray/gen/tmpl_bit/each.c +48 -0
- data/ext/cumo/narray/gen/tmpl_bit/each_with_index.c +70 -0
- data/ext/cumo/narray/gen/tmpl_bit/extract.c +30 -0
- data/ext/cumo/narray/gen/tmpl_bit/extract_cpu.c +29 -0
- data/ext/cumo/narray/gen/tmpl_bit/fill.c +69 -0
- data/ext/cumo/narray/gen/tmpl_bit/format.c +64 -0
- data/ext/cumo/narray/gen/tmpl_bit/format_to_a.c +51 -0
- data/ext/cumo/narray/gen/tmpl_bit/inspect.c +21 -0
- data/ext/cumo/narray/gen/tmpl_bit/mask.c +136 -0
- data/ext/cumo/narray/gen/tmpl_bit/none_p.c +14 -0
- data/ext/cumo/narray/gen/tmpl_bit/store_array.c +108 -0
- data/ext/cumo/narray/gen/tmpl_bit/store_bit.c +70 -0
- data/ext/cumo/narray/gen/tmpl_bit/store_from.c +60 -0
- data/ext/cumo/narray/gen/tmpl_bit/to_a.c +47 -0
- data/ext/cumo/narray/gen/tmpl_bit/unary.c +81 -0
- data/ext/cumo/narray/gen/tmpl_bit/where.c +90 -0
- data/ext/cumo/narray/gen/tmpl_bit/where2.c +95 -0
- data/ext/cumo/narray/index.c +880 -0
- data/ext/cumo/narray/kwargs.c +153 -0
- data/ext/cumo/narray/math.c +142 -0
- data/ext/cumo/narray/narray.c +1948 -0
- data/ext/cumo/narray/ndloop.c +2105 -0
- data/ext/cumo/narray/rand.c +45 -0
- data/ext/cumo/narray/step.c +474 -0
- data/ext/cumo/narray/struct.c +886 -0
- data/lib/cumo.rb +3 -0
- data/lib/cumo/cuda.rb +11 -0
- data/lib/cumo/cuda/compile_error.rb +36 -0
- data/lib/cumo/cuda/compiler.rb +161 -0
- data/lib/cumo/cuda/device.rb +47 -0
- data/lib/cumo/cuda/link_state.rb +31 -0
- data/lib/cumo/cuda/module.rb +40 -0
- data/lib/cumo/cuda/nvrtc_program.rb +27 -0
- data/lib/cumo/linalg.rb +12 -0
- data/lib/cumo/narray.rb +2 -0
- data/lib/cumo/narray/extra.rb +1278 -0
- data/lib/erbpp.rb +294 -0
- data/lib/erbpp/line_number.rb +137 -0
- data/lib/erbpp/narray_def.rb +381 -0
- data/numo-narray-version +1 -0
- data/run.gdb +7 -0
- metadata +353 -0
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
#ifndef CUMO_COMPLEX_KERNEL_H
|
|
2
|
+
#define CUMO_COMPLEX_KERNEL_H
|
|
3
|
+
|
|
4
|
+
__host__ __device__ static inline dtype c_new(rtype r, rtype i) {
|
|
5
|
+
dtype z;
|
|
6
|
+
REAL(z) = r;
|
|
7
|
+
IMAG(z) = i;
|
|
8
|
+
return z;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
__host__ __device__ static inline dtype c_set_real(dtype x, rtype r) {
|
|
12
|
+
REAL(x)=r;
|
|
13
|
+
return x;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
__host__ __device__ static inline dtype c_set_imag(dtype x, rtype i) {
|
|
17
|
+
IMAG(x)=i;
|
|
18
|
+
return x;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//static inline VALUE COMP2NUM(dtype x) {
|
|
22
|
+
// VALUE v;
|
|
23
|
+
// v = rb_funcall(rb_intern("Kernel"), rb_intern("Complex"), 2,
|
|
24
|
+
// rb_float_new(REAL(x)), rb_float_new(IMAG(x)));
|
|
25
|
+
// return v;
|
|
26
|
+
//}
|
|
27
|
+
//
|
|
28
|
+
//static inline dtype NUM2COMP(VALUE v) {
|
|
29
|
+
// dtype z;
|
|
30
|
+
// REAL(z) = NUM2DBL(rb_funcall(v,id_real,0));
|
|
31
|
+
// IMAG(z) = NUM2DBL(rb_funcall(v,id_imag,0));
|
|
32
|
+
// return z;
|
|
33
|
+
//}
|
|
34
|
+
|
|
35
|
+
#define c_is_zero(x) (REAL(x)==0 && IMAG(x)==0)
|
|
36
|
+
#define c_eq(x,y) (REAL(x)==REAL(y) && IMAG(x)==IMAG(y))
|
|
37
|
+
#define c_ne(x,y) (REAL(x)!=REAL(y) || IMAG(x)!=IMAG(y))
|
|
38
|
+
#define c_isnan(x) (isnan(REAL(x)) || isnan(IMAG(x)))
|
|
39
|
+
#define c_isinf(x) (isinf(REAL(x)) || isinf(IMAG(x)))
|
|
40
|
+
#define c_isposinf(x) ((isinf(REAL(x)) && signbit(REAL(x))==0) || \
|
|
41
|
+
(isinf(IMAG(x)) && signbit(IMAG(x))==0))
|
|
42
|
+
#define c_isneginf(x) ((isinf(REAL(x)) && signbit(REAL(x))) || \
|
|
43
|
+
(isinf(IMAG(x)) && signbit(IMAG(x))))
|
|
44
|
+
#define c_isfinite(x) (isfinite(REAL(x)) && isfinite(IMAG(x)))
|
|
45
|
+
|
|
46
|
+
__host__ __device__ static inline dtype c_zero() {
|
|
47
|
+
dtype z;
|
|
48
|
+
REAL(z) = 0;
|
|
49
|
+
IMAG(z) = 0;
|
|
50
|
+
return z;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
__host__ __device__ static inline dtype c_one() {
|
|
54
|
+
dtype z;
|
|
55
|
+
REAL(z) = 1;
|
|
56
|
+
IMAG(z) = 0;
|
|
57
|
+
return z;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
__host__ __device__ 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
|
+
__host__ __device__ 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
|
+
__host__ __device__ 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
|
+
__host__ __device__ 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
|
+
|
|
89
|
+
__host__ __device__ static inline dtype c_mul(dtype x, dtype y) {
|
|
90
|
+
dtype z;
|
|
91
|
+
REAL(z) = REAL(x)*REAL(y)-IMAG(x)*IMAG(y);
|
|
92
|
+
IMAG(z) = REAL(x)*IMAG(y)+IMAG(x)*REAL(y);
|
|
93
|
+
return z;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
__host__ __device__ static inline dtype c_mul_r(dtype x, rtype y) {
|
|
97
|
+
dtype z;
|
|
98
|
+
REAL(z) = REAL(x)*y;
|
|
99
|
+
IMAG(z) = IMAG(x)*y;
|
|
100
|
+
return z;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
__host__ __device__ static inline dtype c_div(dtype x, dtype y) {
|
|
104
|
+
dtype z;
|
|
105
|
+
rtype s,yr,yi;
|
|
106
|
+
s = r_hypot(REAL(y),IMAG(y));
|
|
107
|
+
yr = REAL(y)/s;
|
|
108
|
+
yi = IMAG(y)/s;
|
|
109
|
+
REAL(z) = (REAL(x)*yr+IMAG(x)*yi)/s;
|
|
110
|
+
IMAG(z) = (IMAG(x)*yr-REAL(x)*yi)/s;
|
|
111
|
+
return z;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
__host__ __device__ static inline dtype c_div_r(dtype x, rtype y) {
|
|
115
|
+
dtype z;
|
|
116
|
+
REAL(z) = REAL(x)/y;
|
|
117
|
+
IMAG(z) = IMAG(x)/y;
|
|
118
|
+
return z;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
__host__ __device__ static inline dtype c_reciprocal(dtype x) {
|
|
122
|
+
dtype z;
|
|
123
|
+
if ( r_abs(REAL(x)) > r_abs(IMAG(x)) ) {
|
|
124
|
+
IMAG(z) = IMAG(x)/REAL(x);
|
|
125
|
+
REAL(z) = (1+IMAG(z)*IMAG(z))*REAL(x);
|
|
126
|
+
IMAG(z) /= -REAL(z);
|
|
127
|
+
REAL(z) = 1/REAL(z);
|
|
128
|
+
} else {
|
|
129
|
+
REAL(z) = REAL(x)/IMAG(x);
|
|
130
|
+
IMAG(z) = (1+REAL(z)*REAL(z))*IMAG(x);
|
|
131
|
+
REAL(z) /= IMAG(z);
|
|
132
|
+
IMAG(z) = -1/IMAG(z);
|
|
133
|
+
}
|
|
134
|
+
return z;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
__host__ __device__ static inline dtype c_square(dtype x) {
|
|
138
|
+
dtype z;
|
|
139
|
+
REAL(z) = REAL(x)*REAL(x)-IMAG(x)*IMAG(x);
|
|
140
|
+
IMAG(z) = 2*REAL(x)*IMAG(x);
|
|
141
|
+
return z;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
__host__ __device__ static inline dtype c_sqrt(dtype x) {
|
|
145
|
+
dtype z;
|
|
146
|
+
rtype xr, xi, r;
|
|
147
|
+
xr = REAL(x)/2;
|
|
148
|
+
xi = IMAG(x)/2;
|
|
149
|
+
r = r_hypot(xr,xi);
|
|
150
|
+
if (xr>0) {
|
|
151
|
+
REAL(z) = sqrt(r+xr);
|
|
152
|
+
IMAG(z) = xi/REAL(z);
|
|
153
|
+
} else if ( (r-=xr)!=0 ) {
|
|
154
|
+
IMAG(z) = (xi>=0) ? sqrt(r):-sqrt(r);
|
|
155
|
+
REAL(z) = xi/IMAG(z);
|
|
156
|
+
} else {
|
|
157
|
+
REAL(z) = IMAG(z) = 0;
|
|
158
|
+
}
|
|
159
|
+
return z;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
__host__ __device__ static inline dtype c_log(dtype x) {
|
|
163
|
+
dtype z;
|
|
164
|
+
REAL(z) = r_log(r_hypot(REAL(x),IMAG(x)));
|
|
165
|
+
IMAG(z) = r_atan2(IMAG(x),REAL(x));
|
|
166
|
+
return z;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
__host__ __device__ static inline dtype c_log2(dtype x) {
|
|
170
|
+
dtype z;
|
|
171
|
+
z = c_log(x);
|
|
172
|
+
z = c_mul_r(x,M_LOG2E);
|
|
173
|
+
return z;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
__host__ __device__ static inline dtype c_log10(dtype x) {
|
|
177
|
+
dtype z;
|
|
178
|
+
z = c_log(x);
|
|
179
|
+
z = c_mul_r(x,M_LOG10E);
|
|
180
|
+
return z;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
__host__ __device__ static inline dtype c_exp(dtype x) {
|
|
184
|
+
dtype z;
|
|
185
|
+
rtype a = r_exp(REAL(x));
|
|
186
|
+
REAL(z) = a*r_cos(IMAG(x));
|
|
187
|
+
IMAG(z) = a*r_sin(IMAG(x));
|
|
188
|
+
return z;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
__host__ __device__ static inline dtype c_exp2(dtype x) {
|
|
192
|
+
dtype z;
|
|
193
|
+
rtype a = r_exp(REAL(x)*M_LN2);
|
|
194
|
+
REAL(z) = a*r_cos(IMAG(x));
|
|
195
|
+
IMAG(z) = a*r_sin(IMAG(x));
|
|
196
|
+
return z;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
__host__ __device__ static inline dtype c_exp10(dtype x) {
|
|
200
|
+
dtype z;
|
|
201
|
+
rtype a = r_exp(REAL(x)*M_LN10);
|
|
202
|
+
REAL(z) = a*r_cos(IMAG(x));
|
|
203
|
+
IMAG(z) = a*r_sin(IMAG(x));
|
|
204
|
+
return z;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
__host__ __device__ static inline dtype c_sin(dtype x) {
|
|
208
|
+
dtype z;
|
|
209
|
+
REAL(z) = r_sin(REAL(x))*r_cosh(IMAG(x));
|
|
210
|
+
IMAG(z) = r_cos(REAL(x))*r_sinh(IMAG(x));
|
|
211
|
+
return z;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
__host__ __device__ static inline dtype c_sinh(dtype x) {
|
|
215
|
+
dtype z;
|
|
216
|
+
REAL(z) = r_sinh(REAL(x))*r_cos(IMAG(x));
|
|
217
|
+
IMAG(z) = r_cosh(REAL(x))*r_sin(IMAG(x));
|
|
218
|
+
return z;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
__host__ __device__ static inline dtype c_cos(dtype x) {
|
|
222
|
+
dtype z;
|
|
223
|
+
REAL(z) = r_cos(REAL(x))*r_cosh(IMAG(x));
|
|
224
|
+
IMAG(z) = -r_sin(REAL(x))*r_sinh(IMAG(x));
|
|
225
|
+
return z;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
__host__ __device__ static inline dtype c_cosh(dtype x) {
|
|
229
|
+
dtype z;
|
|
230
|
+
REAL(z) = r_cosh(REAL(x))*r_cos(IMAG(x));
|
|
231
|
+
IMAG(z) = r_sinh(REAL(x))*r_sin(IMAG(x));
|
|
232
|
+
return z;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
__host__ __device__ static inline dtype c_tan(dtype x) {
|
|
236
|
+
dtype z;
|
|
237
|
+
rtype c, d;
|
|
238
|
+
if (r_abs(IMAG(x))<1) {
|
|
239
|
+
c = r_cos(REAL(x));
|
|
240
|
+
d = r_sinh(IMAG(x));
|
|
241
|
+
d = c*c + d*d;
|
|
242
|
+
REAL(z) = 0.5*r_sin(2*REAL(x))/d;
|
|
243
|
+
IMAG(z) = 0.5*r_sinh(2*IMAG(x))/d;
|
|
244
|
+
} else {
|
|
245
|
+
d = r_exp(-IMAG(x));
|
|
246
|
+
c = 2*d/(1-d*d);
|
|
247
|
+
c = c*c;
|
|
248
|
+
d = r_cos(REAL(x));
|
|
249
|
+
d = 1.0 + d*d*c;
|
|
250
|
+
REAL(z) = 0.5*r_sin(2*REAL(x))*c/d;
|
|
251
|
+
IMAG(z) = 1/r_tanh(IMAG(x))/d;
|
|
252
|
+
}
|
|
253
|
+
return z;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
__host__ __device__ static inline dtype c_tanh(dtype x) {
|
|
257
|
+
dtype z;
|
|
258
|
+
rtype c, d, s;
|
|
259
|
+
c = r_cos(IMAG(x));
|
|
260
|
+
s = r_sinh(REAL(x));
|
|
261
|
+
d = c*c + s*s;
|
|
262
|
+
if (r_abs(REAL(x))<1) {
|
|
263
|
+
REAL(z) = s*r_cosh(REAL(x))/d;
|
|
264
|
+
IMAG(z) = 0.5*r_sin(2*IMAG(x))/d;
|
|
265
|
+
} else {
|
|
266
|
+
c = c / s;
|
|
267
|
+
c = 1 + c*c;
|
|
268
|
+
REAL(z) = 1/(r_tanh(REAL(x))*c);
|
|
269
|
+
IMAG(z) = 0.5*r_sin(2*IMAG(x))/d;
|
|
270
|
+
}
|
|
271
|
+
return z;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
__host__ __device__ static inline dtype c_asin(dtype x) {
|
|
275
|
+
dtype z, y;
|
|
276
|
+
y = c_square(x);
|
|
277
|
+
REAL(y) = 1-REAL(y);
|
|
278
|
+
IMAG(y) = -IMAG(y);
|
|
279
|
+
y = c_sqrt(y);
|
|
280
|
+
REAL(y) -= IMAG(x);
|
|
281
|
+
IMAG(y) += REAL(x);
|
|
282
|
+
y = c_log(y);
|
|
283
|
+
REAL(z) = IMAG(y);
|
|
284
|
+
IMAG(z) = -REAL(y);
|
|
285
|
+
return z;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
__host__ __device__ static inline dtype c_asinh(dtype x) {
|
|
289
|
+
dtype z, y;
|
|
290
|
+
y = c_square(x);
|
|
291
|
+
REAL(y) += 1;
|
|
292
|
+
y = c_sqrt(y);
|
|
293
|
+
REAL(y) += REAL(x);
|
|
294
|
+
IMAG(y) += IMAG(x);
|
|
295
|
+
z = c_log(y);
|
|
296
|
+
return z;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
__host__ __device__ static inline dtype c_acos(dtype x) {
|
|
300
|
+
dtype z, y;
|
|
301
|
+
y = c_square(x);
|
|
302
|
+
REAL(y) = 1-REAL(y);
|
|
303
|
+
IMAG(y) = -IMAG(y);
|
|
304
|
+
y = c_sqrt(y);
|
|
305
|
+
REAL(z) = REAL(x)-IMAG(y);
|
|
306
|
+
IMAG(z) = IMAG(x)+REAL(y);
|
|
307
|
+
y = c_log(z);
|
|
308
|
+
REAL(z) = IMAG(y);
|
|
309
|
+
IMAG(z) = -REAL(y);
|
|
310
|
+
return z;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
__host__ __device__ static inline dtype c_acosh(dtype x) {
|
|
314
|
+
dtype z, y;
|
|
315
|
+
y = c_square(x);
|
|
316
|
+
REAL(y) -= 1;
|
|
317
|
+
y = c_sqrt(y);
|
|
318
|
+
REAL(y) += REAL(x);
|
|
319
|
+
IMAG(y) += IMAG(x);
|
|
320
|
+
z = c_log(y);
|
|
321
|
+
return z;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
__host__ __device__ static inline dtype c_atan(dtype x) {
|
|
325
|
+
dtype z, y;
|
|
326
|
+
REAL(y) = -REAL(x);
|
|
327
|
+
IMAG(y) = 1-IMAG(x);
|
|
328
|
+
REAL(z) = REAL(x);
|
|
329
|
+
IMAG(z) = 1+IMAG(x);
|
|
330
|
+
y = c_div(z,y);
|
|
331
|
+
y = c_log(y);
|
|
332
|
+
REAL(z) = -IMAG(y)/2;
|
|
333
|
+
IMAG(z) = REAL(y)/2;
|
|
334
|
+
return z;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
__host__ __device__ static inline dtype c_atanh(dtype x) {
|
|
338
|
+
dtype z, y;
|
|
339
|
+
REAL(y) = 1-REAL(x);
|
|
340
|
+
IMAG(y) = -IMAG(x);
|
|
341
|
+
REAL(z) = 1+REAL(x);
|
|
342
|
+
IMAG(z) = IMAG(x);
|
|
343
|
+
y = c_div(z,y);
|
|
344
|
+
y = c_log(y);
|
|
345
|
+
REAL(z) = REAL(y)/2;
|
|
346
|
+
IMAG(z) = IMAG(y)/2;
|
|
347
|
+
return z;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
__host__ __device__ static inline dtype c_pow(dtype x, dtype y)
|
|
351
|
+
{
|
|
352
|
+
dtype z;
|
|
353
|
+
if (c_is_zero(y)) {
|
|
354
|
+
z = c_one();
|
|
355
|
+
} else if (c_is_zero(x) && REAL(y)>0 && IMAG(y)==0) {
|
|
356
|
+
z = c_zero();
|
|
357
|
+
} else {
|
|
358
|
+
z = c_log(x);
|
|
359
|
+
z = c_mul(y,z);
|
|
360
|
+
z = c_exp(z);
|
|
361
|
+
}
|
|
362
|
+
return z;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/* only internal use (called by c_pow_int) */
|
|
366
|
+
__host__ __device__ static inline dtype c_pow_positive_int(dtype x, int p)
|
|
367
|
+
{
|
|
368
|
+
dtype z = c_one();
|
|
369
|
+
if (p==2) {return c_square(x);}
|
|
370
|
+
if (p&1) {z = x;}
|
|
371
|
+
p >>= 1;
|
|
372
|
+
while (p) {
|
|
373
|
+
x = c_square(x);
|
|
374
|
+
if (p&1) z = c_mul(z,x);
|
|
375
|
+
p >>= 1;
|
|
376
|
+
}
|
|
377
|
+
return z;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
__host__ __device__ static inline dtype c_pow_int(dtype x, int p)
|
|
381
|
+
{
|
|
382
|
+
if (p<0) {
|
|
383
|
+
x = c_pow_positive_int(x,-p);
|
|
384
|
+
return c_reciprocal(x);
|
|
385
|
+
} else {
|
|
386
|
+
return c_pow_positive_int(x,p);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
__host__ __device__ static inline dtype c_cbrt(dtype x) {
|
|
391
|
+
dtype z;
|
|
392
|
+
z = c_log(x);
|
|
393
|
+
z = c_div_r(z,3);
|
|
394
|
+
z = c_exp(z);
|
|
395
|
+
return z;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
__host__ __device__ static inline rtype c_abs(dtype x) {
|
|
399
|
+
return r_hypot(REAL(x),IMAG(x));
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
__host__ __device__ static inline rtype c_abs_square(dtype x) {
|
|
403
|
+
return REAL(x)*REAL(x)+IMAG(x)*IMAG(x);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
/*
|
|
409
|
+
static inline rtype c_hypot(dtype x, dtype y) {
|
|
410
|
+
return r_hypot(c_abs(x),c_abs(y));
|
|
411
|
+
}
|
|
412
|
+
*/
|
|
413
|
+
|
|
414
|
+
#endif // CUMO_COMPLEX_KERNEL_H
|
|
@@ -0,0 +1,382 @@
|
|
|
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_sint(x) c_new(x,0)
|
|
47
|
+
#define m_from_int32(x) c_new(x,0)
|
|
48
|
+
#define m_from_int64(x) c_new(x,0)
|
|
49
|
+
#define m_from_uint32(x) c_new(x,0)
|
|
50
|
+
#define m_from_uint64(x) c_new(x,0)
|
|
51
|
+
#define m_from_scomplex(x) c_from_scomplex(x)
|
|
52
|
+
#define m_from_dcomplex(x) c_from_dcomplex(x)
|
|
53
|
+
|
|
54
|
+
#define m_extract(x) COMP2NUM(*(dtype*)x)
|
|
55
|
+
|
|
56
|
+
#define m_real(x) REAL(x)
|
|
57
|
+
#define m_imag(x) IMAG(x)
|
|
58
|
+
#define m_set_real(x,y) c_set_real(x,y)
|
|
59
|
+
#define m_set_imag(x,y) c_set_imag(x,y)
|
|
60
|
+
|
|
61
|
+
#define m_add(x,y) c_add(x,y)
|
|
62
|
+
#define m_sub(x,y) c_sub(x,y)
|
|
63
|
+
#define m_mul(x,y) c_mul(x,y)
|
|
64
|
+
#define m_div(x,y) c_div(x,y)
|
|
65
|
+
#define m_mod(x,y) c_mod(x,y)
|
|
66
|
+
#define m_pow(x,y) c_pow(x,y)
|
|
67
|
+
#define m_pow_int(x,y) c_pow_int(x,y)
|
|
68
|
+
|
|
69
|
+
#define m_abs(x) c_abs(x)
|
|
70
|
+
#define m_minus(x) c_minus(x)
|
|
71
|
+
#define m_reciprocal(x) c_reciprocal(x)
|
|
72
|
+
#define m_square(x) c_square(x)
|
|
73
|
+
#define m_floor(x) c_new(floor(REAL(x)),floor(IMAG(x)))
|
|
74
|
+
#define m_round(x) c_new(round(REAL(x)),round(IMAG(x)))
|
|
75
|
+
#define m_ceil(x) c_new(ceil(REAL(x)),ceil(IMAG(x)))
|
|
76
|
+
#define m_trunc(x) c_new(trunc(REAL(x)),trunc(IMAG(x)))
|
|
77
|
+
#define m_rint(x) c_new(rint(REAL(x)),rint(IMAG(x)))
|
|
78
|
+
#define m_sign(x) c_new( \
|
|
79
|
+
((REAL(x)==0) ? 0.0:((REAL(x)>0) ? 1.0:((REAL(x)<0) ? -1.0:REAL(x)))), \
|
|
80
|
+
((IMAG(x)==0) ? 0.0:((IMAG(x)>0) ? 1.0:((IMAG(x)<0) ? -1.0:IMAG(x)))))
|
|
81
|
+
#define m_copysign(x,y) c_new(copysign(REAL(x),REAL(y)),copysign(IMAG(x),IMAG(y)))
|
|
82
|
+
|
|
83
|
+
#define m_im(x) c_im(x)
|
|
84
|
+
#define m_conj(x) c_new(REAL(x),-IMAG(x))
|
|
85
|
+
#define m_arg(x) atan2(IMAG(x),REAL(x))
|
|
86
|
+
|
|
87
|
+
#define m_eq(x,y) c_eq(x,y)
|
|
88
|
+
#define m_ne(x,y) c_ne(x,y)
|
|
89
|
+
#define m_nearly_eq(x,y) c_nearly_eq(x,y)
|
|
90
|
+
|
|
91
|
+
#define m_isnan(x) c_isnan(x)
|
|
92
|
+
#define m_isinf(x) c_isinf(x)
|
|
93
|
+
#define m_isposinf(x) c_isposinf(x)
|
|
94
|
+
#define m_isneginf(x) c_isneginf(x)
|
|
95
|
+
#define m_isfinite(x) c_isfinite(x)
|
|
96
|
+
|
|
97
|
+
#define m_sprintf(s,x) sprintf(s,"%g%+gi",REAL(x),IMAG(x))
|
|
98
|
+
|
|
99
|
+
#define m_sqrt(x) c_sqrt(x)
|
|
100
|
+
#define m_cbrt(x) c_cbrt(x)
|
|
101
|
+
#define m_log(x) c_log(x)
|
|
102
|
+
#define m_log2(x) c_log2(x)
|
|
103
|
+
#define m_log10(x) c_log10(x)
|
|
104
|
+
#define m_exp(x) c_exp(x)
|
|
105
|
+
#define m_exp2(x) c_exp2(x)
|
|
106
|
+
#define m_exp10(x) c_exp10(x)
|
|
107
|
+
#define m_sin(x) c_sin(x)
|
|
108
|
+
#define m_cos(x) c_cos(x)
|
|
109
|
+
#define m_tan(x) c_tan(x)
|
|
110
|
+
#define m_asin(x) c_asin(x)
|
|
111
|
+
#define m_acos(x) c_acos(x)
|
|
112
|
+
#define m_atan(x) c_atan(x)
|
|
113
|
+
#define m_sinh(x) c_sinh(x)
|
|
114
|
+
#define m_cosh(x) c_cosh(x)
|
|
115
|
+
#define m_tanh(x) c_tanh(x)
|
|
116
|
+
#define m_asinh(x) c_asinh(x)
|
|
117
|
+
#define m_acosh(x) c_acosh(x)
|
|
118
|
+
#define m_atanh(x) c_atanh(x)
|
|
119
|
+
#define m_hypot(x,y) c_hypot(x,y)
|
|
120
|
+
#define m_sinc(x) c_div(c_sin(x),x)
|
|
121
|
+
|
|
122
|
+
#define m_sum_init INT2FIX(0)
|
|
123
|
+
#define m_mulsum_init INT2FIX(0)
|
|
124
|
+
|
|
125
|
+
#define not_nan(x) (REAL(x)==REAL(x) && IMAG(x)==IMAG(x))
|
|
126
|
+
|
|
127
|
+
#define m_mulsum(x,y,z) {z = m_add(m_mul(x,y),z);}
|
|
128
|
+
#define m_mulsum_nan(x,y,z) { \
|
|
129
|
+
if(not_nan(x) && not_nan(y)) { \
|
|
130
|
+
z = m_add(m_mul(x,y),z); \
|
|
131
|
+
}}
|
|
132
|
+
|
|
133
|
+
#define m_cumsum(x,y) {(x)=m_add(x,y);}
|
|
134
|
+
#define m_cumsum_nan(x,y) { \
|
|
135
|
+
if (!not_nan(x)) { \
|
|
136
|
+
(x) = (y); \
|
|
137
|
+
} else if (not_nan(y)) { \
|
|
138
|
+
(x) = m_add(x,y); \
|
|
139
|
+
}}
|
|
140
|
+
|
|
141
|
+
#define m_cumprod(x,y) {(x)=m_mul(x,y);}
|
|
142
|
+
#define m_cumprod_nan(x,y) { \
|
|
143
|
+
if (!not_nan(x)) { \
|
|
144
|
+
(x) = (y); \
|
|
145
|
+
} else if (not_nan(y)) { \
|
|
146
|
+
(x) = m_mul(x,y); \
|
|
147
|
+
}}
|
|
148
|
+
|
|
149
|
+
static inline dtype f_sum(size_t n, char *p, ssize_t stride)
|
|
150
|
+
{
|
|
151
|
+
size_t i=n;
|
|
152
|
+
dtype x,y;
|
|
153
|
+
|
|
154
|
+
y = c_zero();
|
|
155
|
+
for (; i--;) {
|
|
156
|
+
x = *(dtype*)p;
|
|
157
|
+
y = c_add(x,y);
|
|
158
|
+
p += stride;
|
|
159
|
+
}
|
|
160
|
+
return y;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
static inline dtype f_sum_nan(size_t n, char *p, ssize_t stride)
|
|
164
|
+
{
|
|
165
|
+
size_t i=n;
|
|
166
|
+
dtype x,y;
|
|
167
|
+
|
|
168
|
+
y = c_zero();
|
|
169
|
+
for (; i--;) {
|
|
170
|
+
x = *(dtype*)p;
|
|
171
|
+
if (not_nan(x)) {
|
|
172
|
+
y = c_add(x,y);
|
|
173
|
+
}
|
|
174
|
+
p += stride;
|
|
175
|
+
}
|
|
176
|
+
return y;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
static inline dtype f_kahan_sum(size_t n, char *p, ssize_t stride)
|
|
180
|
+
{
|
|
181
|
+
size_t i=n;
|
|
182
|
+
dtype x;
|
|
183
|
+
volatile dtype y,t,r;
|
|
184
|
+
|
|
185
|
+
y = c_zero();
|
|
186
|
+
r = c_zero();
|
|
187
|
+
for (; i--;) {
|
|
188
|
+
x = *(dtype*)p;
|
|
189
|
+
if (fabs(REAL(x)) > fabs(REAL(y))) {
|
|
190
|
+
double z=REAL(x); REAL(x)=REAL(y); REAL(y)=z;
|
|
191
|
+
}
|
|
192
|
+
if (fabs(IMAG(x)) > fabs(IMAG(y))) {
|
|
193
|
+
double z=IMAG(x); IMAG(x)=IMAG(y); IMAG(y)=z;
|
|
194
|
+
}
|
|
195
|
+
r = c_add(x, r);
|
|
196
|
+
t = y;
|
|
197
|
+
y = c_add(r, y);
|
|
198
|
+
t = c_sub(y, t);
|
|
199
|
+
r = c_sub(r, t);
|
|
200
|
+
p += stride;
|
|
201
|
+
}
|
|
202
|
+
return y;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
static inline dtype f_kahan_sum_nan(size_t n, char *p, ssize_t stride)
|
|
206
|
+
{
|
|
207
|
+
size_t i=n;
|
|
208
|
+
dtype x;
|
|
209
|
+
volatile dtype y,t,r;
|
|
210
|
+
|
|
211
|
+
y = c_zero();
|
|
212
|
+
r = c_zero();
|
|
213
|
+
for (; i--;) {
|
|
214
|
+
x = *(dtype*)p;
|
|
215
|
+
if (not_nan(x)) {
|
|
216
|
+
if (fabs(REAL(x)) > fabs(REAL(y))) {
|
|
217
|
+
double z=REAL(x); REAL(x)=REAL(y); REAL(y)=z;
|
|
218
|
+
}
|
|
219
|
+
if (fabs(IMAG(x)) > fabs(IMAG(y))) {
|
|
220
|
+
double z=IMAG(x); IMAG(x)=IMAG(y); IMAG(y)=z;
|
|
221
|
+
}
|
|
222
|
+
r = c_add(x, r);
|
|
223
|
+
t = y;
|
|
224
|
+
y = c_add(r, y);
|
|
225
|
+
t = c_sub(y, t);
|
|
226
|
+
r = c_sub(r, t);
|
|
227
|
+
}
|
|
228
|
+
p += stride;
|
|
229
|
+
}
|
|
230
|
+
return y;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
static inline dtype f_prod(size_t n, char *p, ssize_t stride)
|
|
234
|
+
{
|
|
235
|
+
size_t i=n;
|
|
236
|
+
dtype x,y;
|
|
237
|
+
|
|
238
|
+
y = c_one();
|
|
239
|
+
for (; i--;) {
|
|
240
|
+
x = *(dtype*)p;
|
|
241
|
+
y = c_mul(x,y);
|
|
242
|
+
p += stride;
|
|
243
|
+
}
|
|
244
|
+
return y;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
static inline dtype f_prod_nan(size_t n, char *p, ssize_t stride)
|
|
248
|
+
{
|
|
249
|
+
size_t i=n;
|
|
250
|
+
dtype x,y;
|
|
251
|
+
|
|
252
|
+
y = c_one();
|
|
253
|
+
for (; i--;) {
|
|
254
|
+
x = *(dtype*)p;
|
|
255
|
+
if (not_nan(x)) {
|
|
256
|
+
y = c_mul(x,y);
|
|
257
|
+
}
|
|
258
|
+
p += stride;
|
|
259
|
+
}
|
|
260
|
+
return y;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
static inline dtype f_mean(size_t n, char *p, ssize_t stride)
|
|
264
|
+
{
|
|
265
|
+
size_t i=n;
|
|
266
|
+
size_t count=0;
|
|
267
|
+
dtype x,y;
|
|
268
|
+
|
|
269
|
+
y = c_zero();
|
|
270
|
+
for (; i--;) {
|
|
271
|
+
x = *(dtype*)p;
|
|
272
|
+
y = c_add(x,y);
|
|
273
|
+
count++;
|
|
274
|
+
p += stride;
|
|
275
|
+
}
|
|
276
|
+
return c_div_r(y,count);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
static inline dtype f_mean_nan(size_t n, char *p, ssize_t stride)
|
|
280
|
+
{
|
|
281
|
+
size_t i=n;
|
|
282
|
+
size_t count=0;
|
|
283
|
+
dtype x,y;
|
|
284
|
+
|
|
285
|
+
y = c_zero();
|
|
286
|
+
for (; i--;) {
|
|
287
|
+
x = *(dtype*)p;
|
|
288
|
+
if (not_nan(x)) {
|
|
289
|
+
y = c_add(x,y);
|
|
290
|
+
count++;
|
|
291
|
+
}
|
|
292
|
+
p += stride;
|
|
293
|
+
}
|
|
294
|
+
return c_div_r(y,count);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
static inline rtype f_var(size_t n, char *p, ssize_t stride)
|
|
298
|
+
{
|
|
299
|
+
size_t i=n;
|
|
300
|
+
size_t count=0;
|
|
301
|
+
dtype x,m;
|
|
302
|
+
rtype y=0;
|
|
303
|
+
|
|
304
|
+
m = f_mean(n,p,stride);
|
|
305
|
+
|
|
306
|
+
for (; i--;) {
|
|
307
|
+
x = *(dtype*)p;
|
|
308
|
+
y += c_abs_square(c_sub(x,m));
|
|
309
|
+
count++;
|
|
310
|
+
p += stride;
|
|
311
|
+
}
|
|
312
|
+
return y/(count-1);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
static inline rtype f_var_nan(size_t n, char *p, ssize_t stride)
|
|
316
|
+
{
|
|
317
|
+
size_t i=n;
|
|
318
|
+
size_t count=0;
|
|
319
|
+
dtype x,m;
|
|
320
|
+
rtype y=0;
|
|
321
|
+
|
|
322
|
+
m = f_mean_nan(n,p,stride);
|
|
323
|
+
|
|
324
|
+
for (; i--;) {
|
|
325
|
+
x = *(dtype*)p;
|
|
326
|
+
if (not_nan(x)) {
|
|
327
|
+
y += c_abs_square(c_sub(x,m));
|
|
328
|
+
count++;
|
|
329
|
+
}
|
|
330
|
+
p += stride;
|
|
331
|
+
}
|
|
332
|
+
return y/(count-1);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
static inline rtype f_stddev(size_t n, char *p, ssize_t stride)
|
|
336
|
+
{
|
|
337
|
+
return r_sqrt(f_var(n,p,stride));
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
static inline rtype f_stddev_nan(size_t n, char *p, ssize_t stride)
|
|
341
|
+
{
|
|
342
|
+
return r_sqrt(f_var_nan(n,p,stride));
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
static inline rtype f_rms(size_t n, char *p, ssize_t stride)
|
|
346
|
+
{
|
|
347
|
+
size_t i=n;
|
|
348
|
+
size_t count=0;
|
|
349
|
+
dtype x;
|
|
350
|
+
rtype y=0;
|
|
351
|
+
|
|
352
|
+
for (; i--;) {
|
|
353
|
+
x = *(dtype*)p;
|
|
354
|
+
y += c_abs_square(x);
|
|
355
|
+
count++;
|
|
356
|
+
p += stride;
|
|
357
|
+
}
|
|
358
|
+
return r_sqrt(y/count);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
static inline rtype f_rms_nan(size_t n, char *p, ssize_t stride)
|
|
362
|
+
{
|
|
363
|
+
size_t i=n;
|
|
364
|
+
size_t count=0;
|
|
365
|
+
dtype x;
|
|
366
|
+
rtype y=0;
|
|
367
|
+
|
|
368
|
+
for (; i--;) {
|
|
369
|
+
x = *(dtype*)p;
|
|
370
|
+
if (not_nan(x)) {
|
|
371
|
+
y += c_abs_square(x);
|
|
372
|
+
count++;
|
|
373
|
+
}
|
|
374
|
+
p += stride;
|
|
375
|
+
}
|
|
376
|
+
return r_sqrt(y/count);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
static inline dtype f_seq(dtype x, dtype y, double c)
|
|
380
|
+
{
|
|
381
|
+
return c_add(x,c_mul_r(y,c));
|
|
382
|
+
}
|