carray 1.1.4 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/COPYING +56 -0
- data/GPL +340 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +33 -0
- data/LEGAL +50 -0
- data/NOTE +73 -0
- data/Rakefile +20 -0
- data/TODO +5 -0
- data/ca_iter_block.c +242 -0
- data/ca_iter_dimension.c +287 -0
- data/ca_iter_window.c +202 -0
- data/ca_obj_array.c +1189 -0
- data/ca_obj_bitarray.c +523 -0
- data/ca_obj_bitfield.c +636 -0
- data/ca_obj_block.c +885 -0
- data/ca_obj_fake.c +405 -0
- data/ca_obj_farray.c +482 -0
- data/ca_obj_field.c +625 -0
- data/ca_obj_grid.c +738 -0
- data/ca_obj_mapping.c +614 -0
- data/ca_obj_object.c +777 -0
- data/ca_obj_reduce.c +299 -0
- data/ca_obj_refer.c +627 -0
- data/ca_obj_repeat.c +640 -0
- data/ca_obj_select.c +558 -0
- data/ca_obj_shift.c +952 -0
- data/ca_obj_transpose.c +582 -0
- data/ca_obj_unbound_repeat.c +557 -0
- data/ca_obj_window.c +1023 -0
- data/carray.h +1381 -0
- data/carray_access.c +1798 -0
- data/carray_attribute.c +903 -0
- data/carray_call_cfunc.c +1107 -0
- data/carray_cast.c +1155 -0
- data/carray_cast_func.rb +498 -0
- data/carray_class.c +132 -0
- data/carray_conversion.c +518 -0
- data/carray_copy.c +453 -0
- data/carray_core.c +1307 -0
- data/carray_element.c +572 -0
- data/carray_generate.c +681 -0
- data/carray_iterator.c +630 -0
- data/carray_loop.c +462 -0
- data/carray_mask.c +1174 -0
- data/carray_math.rb +834 -0
- data/carray_numeric.c +257 -0
- data/carray_operator.c +582 -0
- data/carray_order.c +1040 -0
- data/carray_random.c +529 -0
- data/carray_sort_addr.c +261 -0
- data/carray_stat.c +2102 -0
- data/carray_stat_proc.rb +1990 -0
- data/carray_test.c +602 -0
- data/carray_undef.c +69 -0
- data/carray_utils.c +740 -0
- data/ext/calculus/carray_calculus.c +792 -0
- data/ext/calculus/carray_interp.c +355 -0
- data/ext/calculus/extconf.rb +12 -0
- data/ext/calculus/lib/autoload/autoload_math_calculus.rb +2 -0
- data/ext/calculus/lib/math/calculus.rb +119 -0
- data/ext/calculus/lib/math/interp/adapter_interp1d.rb +31 -0
- data/ext/dataframe/API.txt +11 -0
- data/ext/dataframe/extconf.rb +3 -0
- data/ext/dataframe/lib/carray/autoload/autoload_dataframe_dataframe.rb +14 -0
- data/ext/dataframe/lib/carray/dataframe/dataframe.rb +1104 -0
- data/ext/dataframe/sample/test_uniq_sort.rb +5 -0
- data/ext/fortio/extconf.rb +3 -0
- data/ext/fortio/lib/carray/autoload/autoload_fortran_format.rb +5 -0
- data/ext/fortio/lib/carray/io/fortran_format.rb +43 -0
- data/ext/fortio/lib/fortio.rb +3 -0
- data/ext/fortio/lib/fortio/fortran_format.rb +603 -0
- data/ext/fortio/lib/fortio/fortran_format.tab.rb +536 -0
- data/ext/fortio/lib/fortio/fortran_format.y +215 -0
- data/ext/fortio/lib/fortio/fortran_namelist.rb +151 -0
- data/ext/fortio/lib/fortio/fortran_namelist.tab.rb +470 -0
- data/ext/fortio/lib/fortio/fortran_namelist.y +213 -0
- data/ext/fortio/lib/fortio/fortran_sequential.rb +345 -0
- data/ext/fortio/ruby_fortio.c +182 -0
- data/ext/fortio/test/test_H.rb +5 -0
- data/ext/fortio/test/test_T.rb +7 -0
- data/ext/fortio/test/test_fortran_format.rb +86 -0
- data/ext/fortio/test/test_namelist.rb +25 -0
- data/ext/fortio/test/test_sequential.rb +13 -0
- data/ext/fortio/test/test_sequential2.rb +13 -0
- data/ext/fortio/work/test.rb +10 -0
- data/ext/fortio/work/test_e.rb +19 -0
- data/ext/fortio/work/test_ep.rb +10 -0
- data/ext/fortio/work/test_parse.rb +12 -0
- data/ext/imagemap/carray_imagemap.c +495 -0
- data/ext/imagemap/doc/call_graph.dot +28 -0
- data/ext/imagemap/draw.c +567 -0
- data/ext/imagemap/extconf.rb +13 -0
- data/ext/imagemap/lib/autoload/autoload_graphics_imagemap.rb +1 -0
- data/ext/imagemap/lib/graphics/imagemap.rb +273 -0
- data/ext/imagemap/lib/image_map.rb +4 -0
- data/ext/imagemap/test/swath_index.rb +83 -0
- data/ext/imagemap/test/swath_warp.rb +99 -0
- data/ext/imagemap/test/test.rb +23 -0
- data/ext/imagemap/test/test_image.rb +42 -0
- data/ext/imagemap/test/test_line.rb +14 -0
- data/ext/imagemap/test/test_rotate.rb +17 -0
- data/ext/imagemap/test/test_triangle.rb +20 -0
- data/ext/imagemap/test/test_warp.rb +26 -0
- data/ext/mathfunc/carray_mathfunc.c +321 -0
- data/ext/mathfunc/extconf.rb +18 -0
- data/ext/mathfunc/lib/autoload/autoload_math_mathfunc.rb +1 -0
- data/ext/mathfunc/lib/math/mathfunc.rb +15 -0
- data/ext/mathfunc/test/test_hypot.rb +5 -0
- data/ext/mathfunc/test/test_j0.rb +22 -0
- data/ext/mathfunc/test/test_jn.rb +8 -0
- data/ext/mathfunc/test/test_sph.rb +9 -0
- data/ext/narray/README +22 -0
- data/ext/narray/ca_wrap_narray.c +491 -0
- data/ext/narray/carray_narray.c +21 -0
- data/ext/narray/extconf.rb +57 -0
- data/ext/narray/lib/autoload/autoload_math_narray.rb +1 -0
- data/ext/narray/lib/autoload/autoload_math_narray_miss.rb +11 -0
- data/ext/narray/lib/math/narray.rb +17 -0
- data/ext/narray/lib/math/narray_miss.rb +45 -0
- data/extconf.rb +3 -25
- data/lib/carray.rb +28 -0
- data/lib/carray/autoload/autoload_base.rb +23 -0
- data/lib/carray/autoload/autoload_graphics_gnuplot.rb +2 -0
- data/lib/carray/autoload/autoload_io_csv.rb +14 -0
- data/lib/carray/autoload/autoload_io_excel.rb +5 -0
- data/lib/carray/autoload/autoload_io_imagemagick.rb +6 -0
- data/lib/carray/autoload/autoload_io_pg.rb +6 -0
- data/lib/carray/autoload/autoload_io_sqlite3.rb +12 -0
- data/lib/carray/autoload/autoload_io_table.rb +1 -0
- data/lib/carray/autoload/autoload_math_histogram.rb +5 -0
- data/lib/carray/autoload/autoload_math_interp.rb +4 -0
- data/lib/carray/autoload/autoload_math_recurrence.rb +6 -0
- data/lib/carray/autoload/autoload_object_iterator.rb +1 -0
- data/lib/carray/autoload/autoload_object_link.rb +1 -0
- data/lib/carray/autoload/autoload_object_pack.rb +2 -0
- data/lib/carray/base/autoload.rb +94 -0
- data/lib/carray/base/basic.rb +1051 -0
- data/lib/carray/base/inspect.rb +252 -0
- data/lib/carray/base/iterator.rb +367 -0
- data/lib/carray/base/math.rb +403 -0
- data/lib/carray/base/obsolete.rb +93 -0
- data/lib/carray/base/serialize.rb +260 -0
- data/lib/carray/base/struct.rb +634 -0
- data/lib/carray/graphics/gnuplot.rb +2116 -0
- data/lib/carray/info.rb +112 -0
- data/lib/carray/io/csv.rb +560 -0
- data/lib/carray/io/excel.rb +26 -0
- data/lib/carray/io/imagemagick.rb +231 -0
- data/lib/carray/io/pg.rb +101 -0
- data/lib/carray/io/sqlite3.rb +202 -0
- data/lib/carray/io/table.rb +77 -0
- data/lib/carray/math/histogram.rb +179 -0
- data/lib/carray/math/interp.rb +57 -0
- data/lib/carray/math/interp/adapter_gsl_spline.rb +47 -0
- data/lib/carray/math/recurrence.rb +95 -0
- data/lib/carray/mkmf.rb +145 -0
- data/lib/carray/object/ca_obj_iterator.rb +52 -0
- data/lib/carray/object/ca_obj_link.rb +52 -0
- data/lib/carray/object/ca_obj_pack.rb +101 -0
- data/mkmath.rb +731 -0
- data/mt19937ar.c +182 -0
- data/mt19937ar.h +86 -0
- data/rdoc_main.rb +27 -0
- data/rdoc_math.rb +5 -0
- data/rdoc_stat.rb +31 -0
- data/ruby_carray.c +242 -0
- data/ruby_ccomplex.c +497 -0
- data/ruby_float_func.c +83 -0
- data/spec/CABlockIterator/CABlockIterator_spec.rb +113 -0
- data/spec/CArray/bug/store_spec.rb +27 -0
- data/spec/CArray/index/repeat_spec.rb +10 -0
- data/spec/CArray/method/eq_spec.rb +80 -0
- data/spec/CArray/method/is_nan_spec.rb +12 -0
- data/spec/CArray/method/ne_spec.rb +18 -0
- data/spec/CArray/method/round_spec.rb +11 -0
- data/spec/CArray/object/_attribute_spec.rb +32 -0
- data/spec/CArray/object/s_new_spec.rb +31 -0
- data/spec/CArray/serialize/Serialization_spec.rb +89 -0
- data/spec/spec_all.rb +11 -0
- data/test/test_ALL.rb +50 -0
- data/test/test_CABitfield.rb +59 -0
- data/test/test_CABlock.rb +208 -0
- data/test/test_CAField.rb +40 -0
- data/test/test_CAGrid.rb +76 -0
- data/test/test_CAMapping.rb +106 -0
- data/test/test_CAMmap.rb +11 -0
- data/test/test_CARefer.rb +94 -0
- data/test/test_CARepeat.rb +66 -0
- data/test/test_CASelect.rb +23 -0
- data/test/test_CAShift.rb +17 -0
- data/test/test_CATranspose.rb +61 -0
- data/test/test_CAVirtual.rb +214 -0
- data/test/test_CAWindow.rb +55 -0
- data/test/test_CAWrap.rb +9 -0
- data/test/test_CArray.rb +228 -0
- data/test/test_CComplex.rb +83 -0
- data/test/test_CScalar.rb +91 -0
- data/test/test_attribute.rb +281 -0
- data/test/test_block_iterator.rb +17 -0
- data/test/test_boolean.rb +99 -0
- data/test/test_cast.rb +33 -0
- data/test/test_class.rb +85 -0
- data/test/test_complex.rb +43 -0
- data/test/test_composite.rb +125 -0
- data/test/test_convert.rb +79 -0
- data/test/test_copy.rb +141 -0
- data/test/test_creation.rb +85 -0
- data/test/test_element.rb +146 -0
- data/test/test_extream.rb +55 -0
- data/test/test_generate.rb +75 -0
- data/test/test_index.rb +71 -0
- data/test/test_mask.rb +578 -0
- data/test/test_math.rb +98 -0
- data/test/test_narray.rb +64 -0
- data/test/test_order.rb +147 -0
- data/test/test_random.rb +15 -0
- data/test/test_ref_store.rb +211 -0
- data/test/test_stat.rb +414 -0
- data/test/test_struct.rb +72 -0
- data/test/test_virtual.rb +49 -0
- data/utils/ca_ase.rb +21 -0
- data/utils/ca_methods.rb +15 -0
- data/utils/cast_checker.rb +30 -0
- data/utils/create_rdoc.sh +9 -0
- data/utils/diff_method.rb +52 -0
- data/utils/extract_rdoc.rb +27 -0
- data/utils/make_tgz.sh +3 -0
- data/utils/remove_resource_fork.sh +5 -0
- data/version.h +3 -3
- metadata +266 -1
data/carray_math.rb
ADDED
@@ -0,0 +1,834 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# carray_math.rb
|
4
|
+
#
|
5
|
+
# This file is part of Ruby/CArray extension library.
|
6
|
+
# You can redistribute it and/or modify it under the terms of
|
7
|
+
# the Ruby Licence.
|
8
|
+
#
|
9
|
+
# Copyright (C) 2005 Hiroki Motoyoshi
|
10
|
+
#
|
11
|
+
# ----------------------------------------------------------------------------
|
12
|
+
|
13
|
+
require './mkmath.rb'
|
14
|
+
|
15
|
+
HEADERS << <<HERE_END
|
16
|
+
/* ---------------------------------------------------------------------------
|
17
|
+
|
18
|
+
carray_math.c
|
19
|
+
|
20
|
+
This file is part of Ruby/CArray extension library.
|
21
|
+
You can redistribute it and/or modify it under the terms of
|
22
|
+
the Ruby Licence.
|
23
|
+
|
24
|
+
This file is automatically generated from carray_math.rb.
|
25
|
+
|
26
|
+
Copyright (C) 2005 Hiroki Motoyoshi
|
27
|
+
|
28
|
+
---------------------------------------------------------------------------- */
|
29
|
+
|
30
|
+
#ifdef HAVE_TGMATH_H
|
31
|
+
#include <tgmath.h>
|
32
|
+
#endif
|
33
|
+
|
34
|
+
#include "ruby.h"
|
35
|
+
|
36
|
+
static ID id_equal, id_lt, id_le, id_gt, id_ge;
|
37
|
+
static ID id_uminus, id_utilda;
|
38
|
+
static ID id_plus, id_minus, id_star, id_slash, id_percent, id_star_star;
|
39
|
+
static ID id_and, id_or, id_xor, id_lshift, id_rshift;
|
40
|
+
|
41
|
+
HERE_END
|
42
|
+
|
43
|
+
monop("zero", "zero",
|
44
|
+
BOOL_TYPES => "(#2) = 0;",
|
45
|
+
ALL_TYPES => "(#2) = 0;",
|
46
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = 0.0;" : nil,
|
47
|
+
OBJ_TYPES => '(#2) = 1;')
|
48
|
+
|
49
|
+
monop("one", "one",
|
50
|
+
BOOL_TYPES => "(#2) = 1;",
|
51
|
+
ALL_TYPES => "(#2) = 1;",
|
52
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = 1.0;" : nil,
|
53
|
+
OBJ_TYPES => '(#2) = 3;')
|
54
|
+
|
55
|
+
monop("frac", "frac",
|
56
|
+
INT_TYPES =>
|
57
|
+
%{(#2) = 0; },
|
58
|
+
FLOAT_TYPES =>
|
59
|
+
%{(#2) = ((#1)>0.0) ? (#1)-floor(#1) : ((#1)<0.0) ? (#1)-ceil(#1) : 0.0; },
|
60
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("frac"), 0);')
|
61
|
+
|
62
|
+
monop("neg", "neg",
|
63
|
+
ALL_TYPES => "(#2) = -(#1);",
|
64
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = -(#1);" : nil,
|
65
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), id_uminus, 0);')
|
66
|
+
|
67
|
+
monop("bit_neg", "bit_neg",
|
68
|
+
BOOL_TYPES => "(#2) = (#1) ? 0 : 1;",
|
69
|
+
INT_TYPES => "(#2) = ~(#1);",
|
70
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), id_utilda, 0);')
|
71
|
+
|
72
|
+
alias_op("-@", "neg")
|
73
|
+
alias_op("~", "bit_neg")
|
74
|
+
|
75
|
+
monop("abs_i", "abs_i",
|
76
|
+
INT_TYPES => "(#2) = abs(#1);",
|
77
|
+
FLOAT_TYPES => "(#2) = fabs((float64_t)#1);",
|
78
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = cabs((cmplx128_t)#1);" : nil,
|
79
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("abs"), 0);')
|
80
|
+
|
81
|
+
DEFINITIONS << %{
|
82
|
+
|
83
|
+
static VALUE
|
84
|
+
rb_ca_abs (VALUE self)
|
85
|
+
{
|
86
|
+
CArray *ca;
|
87
|
+
|
88
|
+
Data_Get_Struct(self, CArray, ca);
|
89
|
+
if ( ca_is_complex_type(ca) ) {
|
90
|
+
VALUE ret = rb_ca_abs_i(self);
|
91
|
+
return rb_ca_copy(rb_funcall(ret, rb_intern("real"), 0));
|
92
|
+
}
|
93
|
+
else {
|
94
|
+
return rb_ca_abs_i(self);
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
static VALUE
|
99
|
+
rb_ca_abs_bang (VALUE self)
|
100
|
+
{
|
101
|
+
CArray *ca;
|
102
|
+
rb_ca_modify(self);
|
103
|
+
Data_Get_Struct(self, CArray, ca);
|
104
|
+
if ( ca_is_complex_type(ca) ) {
|
105
|
+
VALUE ret = rb_ca_abs_i(self);
|
106
|
+
return rb_funcall(self, rb_intern("[]="), 1, ret);
|
107
|
+
}
|
108
|
+
else {
|
109
|
+
return rb_ca_abs_i_bang(self);
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
static VALUE rb_cmath_abs (VALUE mod, VALUE arg)
|
114
|
+
{ return rb_ca_abs(arg); }
|
115
|
+
|
116
|
+
}
|
117
|
+
|
118
|
+
METHODS << %{
|
119
|
+
rb_define_method(rb_cCArray, "abs", rb_ca_abs, 0);
|
120
|
+
rb_define_method(rb_cCArray, "abs!", rb_ca_abs_bang, 0);
|
121
|
+
rb_define_module_function(rb_mCAMath, "abs", rb_cmath_abs, 1);
|
122
|
+
}
|
123
|
+
|
124
|
+
monop("conj", "conj",
|
125
|
+
ALL_TYPES => "(#2) = (#1);",
|
126
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = conj(#1);" : nil,
|
127
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("conj"), 0);')
|
128
|
+
|
129
|
+
monfunc("rad", "rad",
|
130
|
+
FLOAT_TYPES => "(#2) = (0.0174532925199433*(#1));",
|
131
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("rad"), 0);')
|
132
|
+
monfunc("deg", "deg",
|
133
|
+
FLOAT_TYPES => "(#2) = (57.2957795130823*(#1));",
|
134
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("deg"), 0);')
|
135
|
+
monfunc("ceil", "ceil",
|
136
|
+
INT_TYPES => "(#2) = (#1);",
|
137
|
+
FLOAT_TYPES => "(#2) = ceil(#1);",
|
138
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("ceil"), 0);')
|
139
|
+
monfunc("floor", "floor",
|
140
|
+
INT_TYPES => "(#2) = (#1);",
|
141
|
+
FLOAT_TYPES => "(#2) = floor(#1);",
|
142
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("floor"), 0);')
|
143
|
+
monfunc("round", "round",
|
144
|
+
INT_TYPES => "(#2) = (#1);",
|
145
|
+
FLOAT_TYPES => %{(#2) = ((#1)>0.0) ? floor((#1)+0.5) : ((#1)<0.0) ? ceil((#1)-0.5) : 0.0; },
|
146
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("round"), 0);')
|
147
|
+
monfunc("rcp", "rcp",
|
148
|
+
INT_TYPES => "if ((#1)==0) {ca_zerodiv();}; (#2) = 1/(#1);",
|
149
|
+
FLOAT_TYPES => "(#2) = 1/(#1);",
|
150
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = 1/(#1);" : nil,
|
151
|
+
OBJ_TYPES => '(#2) = rb_funcall(INT2FIX(1), id_slash, 1, (#1));')
|
152
|
+
monfunc("sqrt", "sqrt",
|
153
|
+
FLOAT_TYPES => "(#2) = sqrt(#1);",
|
154
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = csqrt(#1);" : nil,
|
155
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("sqrt"), 0);')
|
156
|
+
monfunc("exp", "exp",
|
157
|
+
FLOAT_TYPES => "(#2) = exp(#1);",
|
158
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = cexp(#1);" : nil,
|
159
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("exp"), 0);')
|
160
|
+
monfunc("exp10", "exp10",
|
161
|
+
FLOAT_TYPES => "(#2) = pow(10, (#1));",
|
162
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = cpow(10, (#1));" : nil,
|
163
|
+
OBJ_TYPES => '(#2) = rb_funcall(INT2NUM(10), id_star_star, 1, (#1));')
|
164
|
+
monfunc("log", "log",
|
165
|
+
FLOAT_TYPES => "(#2) = log(#1);",
|
166
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = clog(#1);" : nil,
|
167
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("log"), 0);')
|
168
|
+
monfunc("log10", "log10",
|
169
|
+
FLOAT_TYPES => "(#2) = log10(#1);",
|
170
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("log10"), 0);')
|
171
|
+
monfunc("sin", "sin",
|
172
|
+
FLOAT_TYPES => "(#2) = sin(#1);",
|
173
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = csin(#1);" : nil,
|
174
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("sin"), 0);')
|
175
|
+
monfunc("cos", "cos",
|
176
|
+
FLOAT_TYPES => "(#2) = cos(#1);",
|
177
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = ccos(#1);" : nil,
|
178
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("cos"), 0);')
|
179
|
+
monfunc("tan", "tan",
|
180
|
+
FLOAT_TYPES => "(#2) = tan(#1);",
|
181
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = ctan(#1);" : nil,
|
182
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("tan"), 0);')
|
183
|
+
monfunc("asin", "asin",
|
184
|
+
FLOAT_TYPES => "(#2) = asin(#1);",
|
185
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = casin(#1);" : nil,
|
186
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("asin"), 0);')
|
187
|
+
monfunc("acos", "acos",
|
188
|
+
FLOAT_TYPES => "(#2) = acos(#1);",
|
189
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = cacos(#1);" : nil,
|
190
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("acos"), 0);')
|
191
|
+
monfunc("atan", "atan",
|
192
|
+
FLOAT_TYPES => "(#2) = atan(#1);",
|
193
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = catan(#1);" : nil,
|
194
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("atan"), 0);')
|
195
|
+
monfunc("sinh", "sinh",
|
196
|
+
FLOAT_TYPES => "(#2) = sinh(#1);",
|
197
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = sinh(#1);" : nil,
|
198
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("sinh"), 0);')
|
199
|
+
monfunc("cosh", "cosh",
|
200
|
+
FLOAT_TYPES => "(#2) = cosh(#1);",
|
201
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = cosh(#1);" : nil,
|
202
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("cosh"), 0);')
|
203
|
+
monfunc("tanh", "tanh",
|
204
|
+
FLOAT_TYPES => "(#2) = tanh(#1);",
|
205
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = tanh(#1);" : nil,
|
206
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("tanh"), 0);')
|
207
|
+
monfunc("asinh", "asinh",
|
208
|
+
FLOAT_TYPES => "(#2) = asinh(#1);",
|
209
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = asinh(#1);" : nil,
|
210
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("asinh"), 0);')
|
211
|
+
monfunc("acosh", "acosh",
|
212
|
+
FLOAT_TYPES => "(#2) = acosh(#1);",
|
213
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = acosh(#1);" : nil,
|
214
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("acosh"), 0);')
|
215
|
+
monfunc("atanh", "atanh",
|
216
|
+
FLOAT_TYPES => "(#2) = atanh(#1);",
|
217
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = atanh(#1);" : nil,
|
218
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("atanh"), 0);')
|
219
|
+
|
220
|
+
|
221
|
+
binop("pmax", "pmax",
|
222
|
+
ALL_TYPES =>"(#3) = (#1) > (#2) ? (#1) : (#2);",
|
223
|
+
CMPLX_TYPES => nil,
|
224
|
+
OBJ_TYPES =>'(#3) = rb_funcall(rb_assoc_new((#1),(#2)), rb_intern("max"), 0);')
|
225
|
+
|
226
|
+
binop("pmin", "pmin",
|
227
|
+
ALL_TYPES =>"(#3) = (#1) < (#2) ? (#1) : (#2);",
|
228
|
+
CMPLX_TYPES => nil,
|
229
|
+
OBJ_TYPES =>'(#3) = rb_funcall(rb_assoc_new((#1),(#2)), rb_intern("min"), 0);')
|
230
|
+
|
231
|
+
binop("add", "add",
|
232
|
+
ALL_TYPES =>"(#3) = (#1) + (#2);",
|
233
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#3) = (#1) + (#2);" : nil,
|
234
|
+
OBJ_TYPES =>'(#3) = rb_funcall((#1), id_plus, 1, (#2));')
|
235
|
+
|
236
|
+
binop("sub", "sub",
|
237
|
+
ALL_TYPES => "(#3) = (#1) - (#2);",
|
238
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#3) = (#1) - (#2);" : nil,
|
239
|
+
OBJ_TYPES => '(#3) = rb_funcall((#1), id_minus, 1, (#2));')
|
240
|
+
|
241
|
+
binop("mul", "mul",
|
242
|
+
ALL_TYPES => "(#3) = (#1) * (#2);",
|
243
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#3) = (#1) * (#2);" : nil,
|
244
|
+
OBJ_TYPES => '(#3) = rb_funcall((#1), id_star, 1, (#2));')
|
245
|
+
|
246
|
+
binop("div", "div",
|
247
|
+
INT_TYPES => "if ((#2)==0) {ca_zerodiv();}; (#3) = (#1) / (#2);",
|
248
|
+
FLOAT_TYPES => "(#3) = (#1) / (#2);",
|
249
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#3) = (#1) / (#2);" : nil,
|
250
|
+
OBJ_TYPES => '(#3) = rb_funcall((#1), id_slash, 1, (#2));')
|
251
|
+
|
252
|
+
binop("quo_i", nil,
|
253
|
+
OBJ_TYPES => '(#3) = rb_funcall((#1), rb_intern("quo"), 1, (#2));')
|
254
|
+
|
255
|
+
binop("rcp_mul", "rcp_mul",
|
256
|
+
INT_TYPES => "if ((#1)==0) {ca_zerodiv();}; (#3) = (#2) / (#1);",
|
257
|
+
FLOAT_TYPES => "(#3) = (#2) / (#1);",
|
258
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#3) = (#2) / (#1);" : nil,
|
259
|
+
OBJ_TYPES => '(#3) = rb_funcall((#2), id_slash, 1, (#1));')
|
260
|
+
|
261
|
+
binop("mod", "mod",
|
262
|
+
INT_TYPES => "if ((#2)==0) {ca_zerodiv();}; (#3) = (#1) % (#2);",
|
263
|
+
OBJ_TYPES => '(#3) = rb_funcall((#1), id_percent, 1, (#2));')
|
264
|
+
|
265
|
+
binop("bit_and", "bit_and_i",
|
266
|
+
BOOL_TYPES => "(#3) = (#1) & (#2);",
|
267
|
+
INT_TYPES => "(#3) = (#1) & (#2);",
|
268
|
+
OBJ_TYPES => '(#3) = rb_funcall((#1), id_and, 1, (#2));')
|
269
|
+
|
270
|
+
binop("bit_or", "bit_or_i",
|
271
|
+
BOOL_TYPES => "(#3) = (#1) | (#2);",
|
272
|
+
INT_TYPES => "(#3) = (#1) | (#2);",
|
273
|
+
OBJ_TYPES => '(#3) = rb_funcall((#1), id_or, 1, (#2));')
|
274
|
+
|
275
|
+
binop("bit_xor", "bit_xor_i",
|
276
|
+
BOOL_TYPES => "(#3) = ((#1) != (#2)) ? 1 : 0;",
|
277
|
+
INT_TYPES => "(#3) = (#1) ^ (#2);",
|
278
|
+
OBJ_TYPES => '(#3) = rb_funcall((#1), id_xor, 1, (#2));')
|
279
|
+
|
280
|
+
DEFINITIONS << %q{
|
281
|
+
|
282
|
+
static VALUE
|
283
|
+
rb_ca_bit_and (VALUE self, VALUE other)
|
284
|
+
{
|
285
|
+
if ( rb_ca_is_boolean_type(self) ) {
|
286
|
+
return rb_ca_bit_and_i(self, rb_ca_wrap_readonly(other, INT2FIX(CA_BOOLEAN)));
|
287
|
+
}
|
288
|
+
else if ( rb_obj_is_carray(other) && rb_ca_is_boolean_type(other) ) {
|
289
|
+
return rb_ca_bit_and_i(rb_ca_wrap_readonly(self, INT2FIX(CA_BOOLEAN)), other);
|
290
|
+
}
|
291
|
+
else {
|
292
|
+
return rb_ca_bit_and_i(self, other);
|
293
|
+
}
|
294
|
+
}
|
295
|
+
|
296
|
+
static VALUE
|
297
|
+
rb_ca_bit_or (VALUE self, VALUE other)
|
298
|
+
{
|
299
|
+
if ( rb_ca_is_boolean_type(self) ) {
|
300
|
+
return rb_ca_bit_or_i(self, rb_ca_wrap_readonly(other, INT2FIX(CA_BOOLEAN)));
|
301
|
+
}
|
302
|
+
else if ( rb_obj_is_carray(other) && rb_ca_is_boolean_type(other) ) {
|
303
|
+
return rb_ca_bit_or_i(rb_ca_wrap_readonly(self, INT2FIX(CA_BOOLEAN)), other);
|
304
|
+
}
|
305
|
+
else {
|
306
|
+
return rb_ca_bit_or_i(self, other);
|
307
|
+
}
|
308
|
+
}
|
309
|
+
|
310
|
+
static VALUE
|
311
|
+
rb_ca_bit_xor (VALUE self, VALUE other)
|
312
|
+
{
|
313
|
+
if ( rb_ca_is_boolean_type(self) ) {
|
314
|
+
return rb_ca_bit_xor_i(self, rb_ca_wrap_readonly(other, INT2FIX(CA_BOOLEAN)));
|
315
|
+
}
|
316
|
+
else if ( rb_obj_is_carray(other) && rb_ca_is_boolean_type(other) ) {
|
317
|
+
return rb_ca_bit_xor_i(rb_ca_wrap_readonly(self, INT2FIX(CA_BOOLEAN)), other);
|
318
|
+
}
|
319
|
+
else {
|
320
|
+
return rb_ca_bit_xor_i(self, other);
|
321
|
+
}
|
322
|
+
}
|
323
|
+
|
324
|
+
}
|
325
|
+
|
326
|
+
METHODS << %{
|
327
|
+
rb_define_method(rb_cCArray, "bit_and", rb_ca_bit_and, 1);
|
328
|
+
rb_define_method(rb_cCArray, "bit_or", rb_ca_bit_or, 1);
|
329
|
+
rb_define_method(rb_cCArray, "bit_xor", rb_ca_bit_xor, 1);
|
330
|
+
}
|
331
|
+
|
332
|
+
binop("bit_lshift", "bit_lshift",
|
333
|
+
INT_TYPES => "(#3) = (#1) << (#2);",
|
334
|
+
OBJ_TYPES => '(#3) = rb_funcall((#1), id_lshift, 1, (#2));')
|
335
|
+
|
336
|
+
binop("bit_rshift", "bit_rshift",
|
337
|
+
INT_TYPES => "(#3) = (#1) >> (#2);",
|
338
|
+
OBJ_TYPES => '(#3) = rb_funcall((#1), id_rshift, 1, (#2));')
|
339
|
+
|
340
|
+
bincmp("feq", "feq",
|
341
|
+
FLOAT_TYPES => %{
|
342
|
+
<type> f1a = fabs((float64_t) #1);
|
343
|
+
<type> f2a = fabs((float64_t) #2);
|
344
|
+
<type> fmax = (f1a > f2a) ? f1a : f2a;
|
345
|
+
(#3) = ( fabs(((float64_t) #1)-( (float64_t) #2)) <= fmax * <epsilon> ) ? 1 : 0;
|
346
|
+
}
|
347
|
+
)
|
348
|
+
|
349
|
+
bincmp("eq", "eq",
|
350
|
+
FIXLEN_TYPES => "(#3) = ( b1 == b2 && (! memcmp(p1, p2, b1)) );",
|
351
|
+
BOOL_TYPES => "(#3) = ( (#1) == (#2) );",
|
352
|
+
ALL_TYPES => "(#3) = ( (#1) == (#2) );",
|
353
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#3) = (#1) == (#2);" : nil,
|
354
|
+
OBJ_TYPES => '(#3) = rb_funcall((#1), id_equal, 1, (#2)) ? 1 : 0;')
|
355
|
+
|
356
|
+
bincmp("ne", "ne",
|
357
|
+
FIXLEN_TYPES => "(#3) = ( b1 != b2 || memcmp(p1, p2, b1) );",
|
358
|
+
BOOL_TYPES => "(#3) = ( (#1) != (#2) );",
|
359
|
+
ALL_TYPES => "(#3) = ( (#1) != (#2) );",
|
360
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#3) = (#1) != (#2);" : nil,
|
361
|
+
OBJ_TYPES => '(#3) = rb_funcall((#1), id_equal, 1, (#2)) ? 0 : 1;')
|
362
|
+
|
363
|
+
bincmp("gt", "gt",
|
364
|
+
FIXLEN_TYPES => %Q{
|
365
|
+
int cmp = memcmp(p1, p2, b1 < b2 ? b1 : b2) ;
|
366
|
+
(#3) = ( cmp > 0 || ( cmp == 0 && b1 > b2 ) );
|
367
|
+
},
|
368
|
+
ALL_TYPES => "(#3) = ( (#1) > (#2) );",
|
369
|
+
OBJ_TYPES => '(#3) = rb_funcall((#1), id_gt, 1, (#2)) ? 1 : 0;')
|
370
|
+
|
371
|
+
bincmp("lt", "lt",
|
372
|
+
FIXLEN_TYPES => %Q{
|
373
|
+
int cmp = memcmp(p1, p2, b1 < b2 ? b1 : b2) ;
|
374
|
+
(#3) = ( cmp < 0 || ( cmp == 0 && b1 < b2 ) );
|
375
|
+
},
|
376
|
+
ALL_TYPES => "(#3) = ( (#1) < (#2) );",
|
377
|
+
OBJ_TYPES => '(#3) = rb_funcall((#1), id_lt, 1, (#2)) ? 1 : 0;')
|
378
|
+
|
379
|
+
bincmp("ge", "ge",
|
380
|
+
FIXLEN_TYPES => %Q{
|
381
|
+
int cmp = memcmp(p1, p2, b1 < b2 ? b1 : b2) ;
|
382
|
+
(#3) = ( cmp > 0 || ( cmp == 0 && b1 >= b2 ) );
|
383
|
+
},
|
384
|
+
ALL_TYPES => "(#3) = ( (#1) >= (#2) );",
|
385
|
+
OBJ_TYPES => '(#3) = rb_funcall((#1), id_ge, 1, (#2)) ? 1 : 0;')
|
386
|
+
|
387
|
+
bincmp("le", "le",
|
388
|
+
FIXLEN_TYPES => %Q{
|
389
|
+
int cmp = memcmp(p1, p2, b1 < b2 ? b1 : b2) ;
|
390
|
+
(#3) = ( cmp < 0 || ( cmp == 0 && b1 <= b2 ) );
|
391
|
+
},
|
392
|
+
ALL_TYPES => "(#3) = ( (#1) <= (#2) );",
|
393
|
+
OBJ_TYPES => '(#3) = rb_funcall((#1), id_le, 1, (#2)) ? 1 : 0;')
|
394
|
+
|
395
|
+
monop("not", "not",
|
396
|
+
BOOL_TYPES => "(#2) = (#1) ? 0 : 1;",
|
397
|
+
OBJ_TYPES => "(#2) = (RTEST(#1)) ? Qfalse : Qtrue;")
|
398
|
+
|
399
|
+
binop("and", "and_i",
|
400
|
+
BOOL_TYPES => "(#3) = (#1) && (#2);",
|
401
|
+
OBJ_TYPES => '(#3) = ((RTEST(#1)!=0) && (RTEST(#2)!=0)) ? Qtrue : Qfalse;')
|
402
|
+
|
403
|
+
binop("or", "or_i" ,
|
404
|
+
BOOL_TYPES => "(#3) = (#1) || (#2);",
|
405
|
+
OBJ_TYPES => '(#3) = ((RTEST(#1)!=0) || (RTEST(#2)!=0)) ? Qtrue : Qfalse;')
|
406
|
+
|
407
|
+
binop("xor", "xor_i",
|
408
|
+
BOOL_TYPES => "(#3) = (((#1)==0) == ((#2)==0)) ? 0 : 1;",
|
409
|
+
OBJ_TYPES => "(#3) = ((RTEST(#1)) == (RTEST(#2))) ? Qfalse : Qtrue;")
|
410
|
+
|
411
|
+
|
412
|
+
DEFINITIONS << %q{
|
413
|
+
|
414
|
+
static VALUE
|
415
|
+
rb_ca_and (VALUE self, VALUE other)
|
416
|
+
{
|
417
|
+
if ( rb_ca_is_boolean_type(self) ) {
|
418
|
+
return rb_ca_and_i(self, rb_ca_wrap_readonly(other, INT2FIX(CA_BOOLEAN)));
|
419
|
+
}
|
420
|
+
else if ( rb_obj_is_carray(other) && rb_ca_is_boolean_type(other) ) {
|
421
|
+
return rb_ca_and_i(rb_ca_wrap_readonly(self, INT2FIX(CA_BOOLEAN)), other);
|
422
|
+
}
|
423
|
+
else {
|
424
|
+
return rb_ca_and_i(self, other);
|
425
|
+
}
|
426
|
+
}
|
427
|
+
|
428
|
+
static VALUE
|
429
|
+
rb_ca_or (VALUE self, VALUE other)
|
430
|
+
{
|
431
|
+
if ( rb_ca_is_boolean_type(self) ) {
|
432
|
+
return rb_ca_or_i(self, rb_ca_wrap_readonly(other, INT2FIX(CA_BOOLEAN)));
|
433
|
+
}
|
434
|
+
else if ( rb_obj_is_carray(other) && rb_ca_is_boolean_type(other) ) {
|
435
|
+
return rb_ca_or_i(rb_ca_wrap_readonly(self, INT2FIX(CA_BOOLEAN)), other);
|
436
|
+
}
|
437
|
+
else {
|
438
|
+
return rb_ca_or_i(self, other);
|
439
|
+
}
|
440
|
+
}
|
441
|
+
|
442
|
+
static VALUE
|
443
|
+
rb_ca_xor (VALUE self, VALUE other)
|
444
|
+
{
|
445
|
+
if ( rb_ca_is_boolean_type(self) ) {
|
446
|
+
return rb_ca_xor_i(self, rb_ca_wrap_readonly(other, INT2FIX(CA_BOOLEAN)));
|
447
|
+
}
|
448
|
+
else if ( rb_obj_is_carray(other) && rb_ca_is_boolean_type(other) ) {
|
449
|
+
return rb_ca_xor_i(rb_ca_wrap_readonly(self, INT2FIX(CA_BOOLEAN)), other);
|
450
|
+
}
|
451
|
+
else {
|
452
|
+
return rb_ca_xor_i(self, other);
|
453
|
+
}
|
454
|
+
}
|
455
|
+
|
456
|
+
}
|
457
|
+
|
458
|
+
METHODS << %{
|
459
|
+
rb_define_method(rb_cCArray, "and", rb_ca_and, 1);
|
460
|
+
rb_define_method(rb_cCArray, "or", rb_ca_or, 1);
|
461
|
+
rb_define_method(rb_cCArray, "xor", rb_ca_xor, 1);
|
462
|
+
}
|
463
|
+
|
464
|
+
alias_op("+", "add")
|
465
|
+
alias_op("-", "sub")
|
466
|
+
alias_op("*", "mul")
|
467
|
+
alias_op("/", "div")
|
468
|
+
alias_op("%", "mod")
|
469
|
+
alias_op("&", "bit_and")
|
470
|
+
alias_op("|", "bit_or")
|
471
|
+
alias_op("^", "bit_xor")
|
472
|
+
alias_op("<<", "bit_lshift")
|
473
|
+
alias_op(">>", "bit_rshift")
|
474
|
+
|
475
|
+
#alias_op("==", "eq")
|
476
|
+
#alias_op("!=", "ne")
|
477
|
+
alias_op(">", "gt")
|
478
|
+
alias_op("<", "lt")
|
479
|
+
alias_op(">=", "ge")
|
480
|
+
alias_op("<=", "le")
|
481
|
+
|
482
|
+
moncmp("is_nan", "is_nan",
|
483
|
+
INT_TYPES => "(#2) = 0;",
|
484
|
+
FLOAT_TYPES => "(#2) = isnan(#1);",
|
485
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("nan?"), 0);')
|
486
|
+
|
487
|
+
moncmp("is_inf", "is_inf",
|
488
|
+
INT_TYPES => "(#2) = 0;",
|
489
|
+
FLOAT_TYPES => "(#2) = isinf(#1);",
|
490
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("infinite?"), 0);')
|
491
|
+
|
492
|
+
moncmp("is_finite", "is_finite",
|
493
|
+
INT_TYPES => "(#2) = 1;",
|
494
|
+
FLOAT_TYPES => "(#2) = isfinite(#1);",
|
495
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("finite?"), 0);')
|
496
|
+
|
497
|
+
bincmp("match", "match",
|
498
|
+
FIXLEN_TYPES => %Q{
|
499
|
+
(#3) = RTEST(rb_funcall(rb_str_new(p1,b1), rb_intern("=~"), 1, (#2)));
|
500
|
+
},
|
501
|
+
OBJ_TYPES => '(#3) = RTEST(rb_funcall((#1), rb_intern("=~"), 1, (#2)));')
|
502
|
+
|
503
|
+
bincmp("is_kind_of", "is_kind_of",
|
504
|
+
OBJ_TYPES => '(#3) = RTEST(rb_obj_is_kind_of((#1), (#2)));')
|
505
|
+
|
506
|
+
alias_op("=~", "match")
|
507
|
+
|
508
|
+
DEFINITIONS << %q{
|
509
|
+
|
510
|
+
#define op_powi(type) \
|
511
|
+
static type \
|
512
|
+
op_powi_## type (type x, int32_t p) \
|
513
|
+
{ \
|
514
|
+
type r=1; \
|
515
|
+
\
|
516
|
+
switch(p) { \
|
517
|
+
case 2: return x*x; \
|
518
|
+
case 3: return x*x*x; \
|
519
|
+
case 0: return 1; \
|
520
|
+
case 1: return x; \
|
521
|
+
} \
|
522
|
+
if (p<0) { \
|
523
|
+
type den = op_powi_## type(x, -p); \
|
524
|
+
if (den==0) ca_zerodiv(); \
|
525
|
+
return 1/den; \
|
526
|
+
}\
|
527
|
+
while (p) { \
|
528
|
+
if ( (p%2) == 1 ) r *= x; \
|
529
|
+
x *= x; \
|
530
|
+
p /= 2; \
|
531
|
+
} \
|
532
|
+
return r; \
|
533
|
+
}
|
534
|
+
|
535
|
+
#define op_powi_fc(type) \
|
536
|
+
static type \
|
537
|
+
op_powi_## type (type x, int32_t p) \
|
538
|
+
{ \
|
539
|
+
type r=1; \
|
540
|
+
\
|
541
|
+
switch(p) { \
|
542
|
+
case 2: return x*x; \
|
543
|
+
case 3: return x*x*x; \
|
544
|
+
case 0: return 1; \
|
545
|
+
case 1: return x; \
|
546
|
+
} \
|
547
|
+
if (p<0) { \
|
548
|
+
type den = op_powi_## type(x, -p); \
|
549
|
+
return 1/den; \
|
550
|
+
}\
|
551
|
+
while (p) { \
|
552
|
+
if ( (p%2) == 1 ) r *= x; \
|
553
|
+
x *= x; \
|
554
|
+
p /= 2; \
|
555
|
+
} \
|
556
|
+
return r; \
|
557
|
+
}
|
558
|
+
|
559
|
+
op_powi(int8_t);
|
560
|
+
op_powi(uint8_t);
|
561
|
+
op_powi(int16_t);
|
562
|
+
op_powi(uint16_t);
|
563
|
+
op_powi(int32_t);
|
564
|
+
op_powi(uint32_t);
|
565
|
+
op_powi(int64_t);
|
566
|
+
op_powi(uint64_t);
|
567
|
+
op_powi_fc(float32_t);
|
568
|
+
op_powi_fc(float64_t);
|
569
|
+
op_powi_fc(float128_t);
|
570
|
+
op_powi_fc(cmplx64_t);
|
571
|
+
op_powi_fc(cmplx128_t);
|
572
|
+
|
573
|
+
static void
|
574
|
+
ca_ipower_float32_t (int32_t n, boolean8_t *m,
|
575
|
+
char *ptr1, int32_t ipow, char *ptr2)
|
576
|
+
{
|
577
|
+
float32_t *p1 = (float32_t *) ptr1, *p2 = (float32_t *) ptr2;
|
578
|
+
if ( m ) {
|
579
|
+
while (n--) {
|
580
|
+
if ( ! *m++ ) { *p2 = op_powi_float32_t(*p1, ipow); }
|
581
|
+
p1++; p2++;
|
582
|
+
}
|
583
|
+
}
|
584
|
+
else
|
585
|
+
while (n--) { (*p2) = op_powi_float32_t(*p1, ipow); p1++; p2++; }
|
586
|
+
}
|
587
|
+
|
588
|
+
static void
|
589
|
+
ca_ipower_float64_t (int32_t n, boolean8_t *m,
|
590
|
+
char *ptr1, int32_t ipow, char *ptr2)
|
591
|
+
{
|
592
|
+
float64_t *p1 = (float64_t *) ptr1, *p2 = (float64_t *) ptr2;
|
593
|
+
if ( m ) {
|
594
|
+
while (n--) {
|
595
|
+
if ( ! *m++ ) { *p2 = op_powi_float64_t(*p1, ipow); }
|
596
|
+
p1++; p2++;
|
597
|
+
}
|
598
|
+
}
|
599
|
+
else
|
600
|
+
while (n--) { (*p2) = op_powi_float64_t(*p1, ipow); p1++; p2++; }
|
601
|
+
}
|
602
|
+
|
603
|
+
static void
|
604
|
+
ca_ipower_float128_t (int32_t n, boolean8_t *m,
|
605
|
+
char *ptr1, int32_t ipow, char *ptr2)
|
606
|
+
{
|
607
|
+
float128_t *p1 = (float128_t *) ptr1, *p2 = (float128_t *) ptr2;
|
608
|
+
if ( m ) {
|
609
|
+
while (n--) {
|
610
|
+
if ( ! *m++ ) { *p2 = op_powi_float128_t(*p1, ipow); }
|
611
|
+
p1++; p2++;
|
612
|
+
}
|
613
|
+
}
|
614
|
+
else
|
615
|
+
while (n--) { (*p2) = op_powi_float128_t(*p1, ipow); p1++; p2++; }
|
616
|
+
}
|
617
|
+
|
618
|
+
static void
|
619
|
+
ca_ipower_cmplx64_t (int32_t n, boolean8_t *m,
|
620
|
+
char *ptr1, int32_t ipow, char *ptr2)
|
621
|
+
{
|
622
|
+
cmplx64_t *p1 = (cmplx64_t *) ptr1, *p2 = (cmplx64_t *) ptr2;
|
623
|
+
if ( m ) {
|
624
|
+
while (n--) {
|
625
|
+
if ( ! *m++ ) { *p2 = op_powi_cmplx64_t(*p1, ipow); }
|
626
|
+
p1++; p2++;
|
627
|
+
}
|
628
|
+
}
|
629
|
+
else
|
630
|
+
while (n--) { (*p2) = op_powi_cmplx64_t(*p1, ipow); p1++; p2++; }
|
631
|
+
}
|
632
|
+
|
633
|
+
static void
|
634
|
+
ca_ipower_cmplx128_t (int32_t n, boolean8_t *m,
|
635
|
+
char *ptr1, int32_t ipow, char *ptr2)
|
636
|
+
{
|
637
|
+
cmplx128_t *p1 = (cmplx128_t *) ptr1, *p2 = (cmplx128_t *) ptr2;
|
638
|
+
if ( m ) {
|
639
|
+
while (n--) {
|
640
|
+
if ( ! *m++ ) { *p2 = op_powi_cmplx128_t(*p1, ipow); }
|
641
|
+
p1++; p2++;
|
642
|
+
}
|
643
|
+
}
|
644
|
+
else
|
645
|
+
while (n--) { (*p2) = op_powi_cmplx128_t(*p1, ipow); p1++; p2++; }
|
646
|
+
}
|
647
|
+
|
648
|
+
|
649
|
+
static VALUE
|
650
|
+
rb_ca_ipower (VALUE self, VALUE other)
|
651
|
+
{
|
652
|
+
volatile VALUE obj;
|
653
|
+
CArray *ca, *co;
|
654
|
+
int32_t ipow;
|
655
|
+
boolean8_t *m;
|
656
|
+
|
657
|
+
ipow = NUM2INT(other);
|
658
|
+
|
659
|
+
Data_Get_Struct(self, CArray, ca);
|
660
|
+
|
661
|
+
co = ca_template(ca);
|
662
|
+
obj = ca_wrap_struct(co);
|
663
|
+
|
664
|
+
ca_attach(ca);
|
665
|
+
|
666
|
+
ca_copy_mask_overlay(co, co->elements, 1, ca);
|
667
|
+
m = ( co->mask ) ? (boolean8_t *)co->mask->ptr : NULL;
|
668
|
+
|
669
|
+
switch ( ca->data_type ) {
|
670
|
+
case CA_FLOAT32: {
|
671
|
+
ca_ipower_float32_t(ca->elements, m, ca->ptr, ipow, co->ptr);
|
672
|
+
break;
|
673
|
+
}
|
674
|
+
case CA_FLOAT64: {
|
675
|
+
ca_ipower_float64_t(ca->elements, m, ca->ptr, ipow, co->ptr);
|
676
|
+
break;
|
677
|
+
}
|
678
|
+
case CA_FLOAT128: {
|
679
|
+
ca_ipower_float128_t(ca->elements, m, ca->ptr, ipow, co->ptr);
|
680
|
+
break;
|
681
|
+
}
|
682
|
+
case CA_CMPLX64: {
|
683
|
+
ca_ipower_cmplx64_t(ca->elements, m, ca->ptr, ipow, co->ptr);
|
684
|
+
break;
|
685
|
+
}
|
686
|
+
case CA_CMPLX128: {
|
687
|
+
ca_ipower_cmplx128_t(ca->elements, m, ca->ptr, ipow, co->ptr);
|
688
|
+
break;
|
689
|
+
}
|
690
|
+
default:
|
691
|
+
rb_raise(rb_eCADataTypeError, "invalid data type for ipower");
|
692
|
+
break;
|
693
|
+
}
|
694
|
+
|
695
|
+
ca_detach(ca);
|
696
|
+
|
697
|
+
/* unresolved unbound repeat array generates unbound repeat array again */
|
698
|
+
if ( ca->obj_type == CA_OBJ_UNBOUND_REPEAT ) {
|
699
|
+
CAUnboundRepeat *cx = (CAUnboundRepeat *) ca;
|
700
|
+
obj = rb_ca_ubrep_new(obj, cx->rep_rank, cx->rep_dim);
|
701
|
+
}
|
702
|
+
|
703
|
+
return obj;
|
704
|
+
}
|
705
|
+
|
706
|
+
static VALUE
|
707
|
+
rb_ca_ipower_bang (VALUE self, VALUE other)
|
708
|
+
{
|
709
|
+
CArray *ca;
|
710
|
+
int32_t ipow;
|
711
|
+
boolean8_t *m;
|
712
|
+
|
713
|
+
ipow = NUM2INT(other);
|
714
|
+
|
715
|
+
Data_Get_Struct(self, CArray, ca);
|
716
|
+
|
717
|
+
ca_attach(ca);
|
718
|
+
|
719
|
+
m = ( ca->mask ) ? (boolean8_t *)ca->mask->ptr : NULL;
|
720
|
+
|
721
|
+
switch ( ca->data_type ) {
|
722
|
+
case CA_FLOAT32: {
|
723
|
+
ca_ipower_float32_t(ca->elements, m, ca->ptr, ipow, ca->ptr);
|
724
|
+
break;
|
725
|
+
}
|
726
|
+
case CA_FLOAT64: {
|
727
|
+
ca_ipower_float64_t(ca->elements, m, ca->ptr, ipow, ca->ptr);
|
728
|
+
break;
|
729
|
+
}
|
730
|
+
case CA_FLOAT128: {
|
731
|
+
ca_ipower_float128_t(ca->elements, m, ca->ptr, ipow, ca->ptr);
|
732
|
+
break;
|
733
|
+
}
|
734
|
+
case CA_CMPLX64: {
|
735
|
+
ca_ipower_cmplx64_t(ca->elements, m, ca->ptr, ipow, ca->ptr);
|
736
|
+
break;
|
737
|
+
}
|
738
|
+
case CA_CMPLX128: {
|
739
|
+
ca_ipower_cmplx128_t(ca->elements, m, ca->ptr, ipow, ca->ptr);
|
740
|
+
break;
|
741
|
+
}
|
742
|
+
default:
|
743
|
+
rb_raise(rb_eRuntimeError, "invalid data type for ipower");
|
744
|
+
break;
|
745
|
+
}
|
746
|
+
|
747
|
+
ca_sync(ca);
|
748
|
+
ca_detach(ca);
|
749
|
+
|
750
|
+
return self;
|
751
|
+
}
|
752
|
+
|
753
|
+
}
|
754
|
+
|
755
|
+
binop("power", "power",
|
756
|
+
INT_TYPES => "(#3) = op_powi_<type>((#1), (#2));",
|
757
|
+
FLOAT_TYPES => "(#3) = pow((#1), (#2));",
|
758
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#3) = cpow((#1), (#2));" : nil,
|
759
|
+
OBJ_TYPES => '(#3) = rb_funcall((#1), id_star_star, 1, (#2));')
|
760
|
+
|
761
|
+
DEFINITIONS << %{
|
762
|
+
|
763
|
+
static VALUE rb_ca_pow (VALUE self, VALUE other)
|
764
|
+
{
|
765
|
+
volatile VALUE obj;
|
766
|
+
CArray *ca;
|
767
|
+
|
768
|
+
Data_Get_Struct(self, CArray, ca);
|
769
|
+
if ( ( ca_is_float_type(ca) || ca_is_complex_type(ca) ) &&
|
770
|
+
rb_obj_is_kind_of(other, rb_cInteger) ) {
|
771
|
+
return rb_ca_ipower(self, other);
|
772
|
+
}
|
773
|
+
else {
|
774
|
+
obj = rb_ca_power(self, other);
|
775
|
+
|
776
|
+
/* unresolved unbound repeat array generates unbound repeat array again */
|
777
|
+
if ( ca->obj_type == CA_OBJ_UNBOUND_REPEAT ) {
|
778
|
+
CAUnboundRepeat *cx = (CAUnboundRepeat *) ca;
|
779
|
+
obj = rb_ca_ubrep_new(obj, cx->rep_rank, cx->rep_dim);
|
780
|
+
}
|
781
|
+
|
782
|
+
return obj;
|
783
|
+
}
|
784
|
+
}
|
785
|
+
|
786
|
+
static VALUE rb_ca_pow_bang (VALUE self, VALUE other)
|
787
|
+
{
|
788
|
+
CArray *ca;
|
789
|
+
Data_Get_Struct(self, CArray, ca);
|
790
|
+
if ( ( ca_is_float_type(ca) || ca_is_complex_type(ca) ) &&
|
791
|
+
rb_obj_is_kind_of(other, rb_cInteger) ) {
|
792
|
+
return rb_ca_ipower_bang(self, other);
|
793
|
+
}
|
794
|
+
else {
|
795
|
+
return rb_ca_power_bang(self, other);
|
796
|
+
}
|
797
|
+
}
|
798
|
+
|
799
|
+
}
|
800
|
+
|
801
|
+
METHODS << %{
|
802
|
+
rb_define_method(rb_cCArray, "pow", rb_ca_pow, 1);
|
803
|
+
rb_define_method(rb_cCArray, "pow!", rb_ca_pow_bang, 1);
|
804
|
+
}
|
805
|
+
|
806
|
+
alias_op("**", "pow")
|
807
|
+
|
808
|
+
METHODS << %{
|
809
|
+
id_equal = rb_intern("==");
|
810
|
+
id_lt = rb_intern("<");
|
811
|
+
id_le = rb_intern("<=");
|
812
|
+
id_gt = rb_intern(">");
|
813
|
+
id_ge = rb_intern(">=");
|
814
|
+
|
815
|
+
id_uminus = rb_intern("-@");
|
816
|
+
id_utilda = rb_intern("~@");
|
817
|
+
|
818
|
+
id_plus = rb_intern("+");
|
819
|
+
id_minus = rb_intern("-");
|
820
|
+
id_star = rb_intern("*");
|
821
|
+
id_slash = rb_intern("/");
|
822
|
+
id_percent = rb_intern("%");
|
823
|
+
id_star_star = rb_intern("**");
|
824
|
+
|
825
|
+
id_and = rb_intern("&");
|
826
|
+
id_or = rb_intern("|");
|
827
|
+
id_xor = rb_intern("^");
|
828
|
+
id_lshift = rb_intern("<<");
|
829
|
+
id_rshift = rb_intern(">>");
|
830
|
+
|
831
|
+
}
|
832
|
+
|
833
|
+
create_code("carray_math", "carray_math.c")
|
834
|
+
|