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_stat_proc.rb
ADDED
@@ -0,0 +1,1990 @@
|
|
1
|
+
# -*- Mode: C; tab-width: 2; -*-
|
2
|
+
# ----------------------------------------------------------------------------
|
3
|
+
#
|
4
|
+
# carray_stat_proc.rb
|
5
|
+
#
|
6
|
+
# This file is part of Ruby/CArray extension library.
|
7
|
+
# You can redistribute it and/or modify it under the terms of
|
8
|
+
# the Ruby Licence.
|
9
|
+
#
|
10
|
+
# Copyright (C) 2005 Hiroki Motoyoshi
|
11
|
+
#
|
12
|
+
# ----------------------------------------------------------------------------
|
13
|
+
|
14
|
+
def macro_expand (text, values)
|
15
|
+
text = text.clone
|
16
|
+
values.each do |key, val|
|
17
|
+
text.gsub!("<"+key+">", val)
|
18
|
+
end
|
19
|
+
return text
|
20
|
+
end
|
21
|
+
|
22
|
+
TYPEINFO = {
|
23
|
+
'boolean8_t' => {
|
24
|
+
'type' => "boolean8_t",
|
25
|
+
'zero' => '0',
|
26
|
+
'dat2type' => '',
|
27
|
+
'obj2type' => 'NUM2LONG',
|
28
|
+
'type2obj' => 'LONG2NUM',
|
29
|
+
'type2dbl' => '(float64_t)',
|
30
|
+
'int2type' => '',
|
31
|
+
'atype' => 'double',
|
32
|
+
'azero' => '0.0',
|
33
|
+
'aone' => '1.0',
|
34
|
+
'atype2obj' => 'rb_float_new',
|
35
|
+
'eql' => "GEQ",
|
36
|
+
'op_type' => "c",
|
37
|
+
},
|
38
|
+
'int8_t' => {
|
39
|
+
'type' => "int8_t",
|
40
|
+
'zero' => '0',
|
41
|
+
'dat2type' => '',
|
42
|
+
'obj2type' => 'NUM2LONG',
|
43
|
+
'type2obj' => 'LONG2NUM',
|
44
|
+
'type2dbl' => '(float64_t)',
|
45
|
+
'int2type' => '',
|
46
|
+
'atype' => 'double',
|
47
|
+
'azero' => '0.0',
|
48
|
+
'aone' => '1.0',
|
49
|
+
'atype2obj' => 'rb_float_new',
|
50
|
+
'eql' => "GEQ",
|
51
|
+
'op_type' => "c",
|
52
|
+
},
|
53
|
+
'uint8_t' => {
|
54
|
+
'type' => "uint8_t",
|
55
|
+
'zero' => '0',
|
56
|
+
'dat2type' => '',
|
57
|
+
'obj2type' => 'NUM2ULONG',
|
58
|
+
'type2obj' => 'ULONG2NUM',
|
59
|
+
'type2dbl' => '(float64_t)',
|
60
|
+
'int2type' => '',
|
61
|
+
'atype' => 'double',
|
62
|
+
'azero' => '0.0',
|
63
|
+
'aone' => '1.0',
|
64
|
+
'atype2obj' => 'rb_float_new',
|
65
|
+
'eql' => "GEQ",
|
66
|
+
'op_type' => "c",
|
67
|
+
},
|
68
|
+
'int16_t' => {
|
69
|
+
'type' => "int16_t",
|
70
|
+
'zero' => '0',
|
71
|
+
'dat2type' => '',
|
72
|
+
'obj2type' => 'NUM2LONG',
|
73
|
+
'type2obj' => 'LONG2NUM',
|
74
|
+
'type2dbl' => '(float64_t)',
|
75
|
+
'int2type' => '',
|
76
|
+
'atype' => 'double',
|
77
|
+
'azero' => '0.0',
|
78
|
+
'aone' => '1.0',
|
79
|
+
'atype2obj' => 'rb_float_new',
|
80
|
+
'eql' => "GEQ",
|
81
|
+
'op_type' => "c",
|
82
|
+
},
|
83
|
+
'uint16_t' => {
|
84
|
+
'type' => "uint16_t",
|
85
|
+
'zero' => '0',
|
86
|
+
'dat2type' => '',
|
87
|
+
'obj2type' => 'NUM2ULONG',
|
88
|
+
'type2obj' => 'ULONG2NUM',
|
89
|
+
'type2dbl' => '(float64_t)',
|
90
|
+
'int2type' => '',
|
91
|
+
'atype' => 'double',
|
92
|
+
'azero' => '0.0',
|
93
|
+
'aone' => '1.0',
|
94
|
+
'atype2obj' => 'rb_float_new',
|
95
|
+
'eql' => "GEQ",
|
96
|
+
'op_type' => "c",
|
97
|
+
},
|
98
|
+
'int32_t' => {
|
99
|
+
'type' => "int32_t",
|
100
|
+
'zero' => '0',
|
101
|
+
'dat2type' => '',
|
102
|
+
'obj2type' => 'NUM2LONG',
|
103
|
+
'type2obj' => 'LONG2NUM',
|
104
|
+
'type2dbl' => '(float64_t)',
|
105
|
+
'int2type' => '',
|
106
|
+
'atype' => 'double',
|
107
|
+
'azero' => '0.0',
|
108
|
+
'aone' => '1.0',
|
109
|
+
'atype2obj' => 'rb_float_new',
|
110
|
+
'eql' => "GEQ",
|
111
|
+
'op_type' => "c",
|
112
|
+
},
|
113
|
+
'uint32_t' => {
|
114
|
+
'type' => "uint32_t",
|
115
|
+
'zero' => '0',
|
116
|
+
'dat2type' => '',
|
117
|
+
'obj2type' => 'NUM2ULONG',
|
118
|
+
'type2obj' => 'ULONG2NUM',
|
119
|
+
'type2dbl' => '(float64_t)',
|
120
|
+
'int2type' => '',
|
121
|
+
'atype' => 'double',
|
122
|
+
'azero' => '0.0',
|
123
|
+
'aone' => '1.0',
|
124
|
+
'atype2obj' => 'rb_float_new',
|
125
|
+
'eql' => "GEQ",
|
126
|
+
'op_type' => "c",
|
127
|
+
},
|
128
|
+
'int64_t' => {
|
129
|
+
'type' => "int64_t",
|
130
|
+
'zero' => '0',
|
131
|
+
'dat2type' => '',
|
132
|
+
'obj2type' => 'NUM2LL',
|
133
|
+
'type2obj' => 'LL2NUM',
|
134
|
+
'type2dbl' => '(float64_t)',
|
135
|
+
'int2type' => '',
|
136
|
+
'atype' => 'double',
|
137
|
+
'azero' => '0.0',
|
138
|
+
'aone' => '1.0',
|
139
|
+
'atype2obj' => 'rb_float_new',
|
140
|
+
'eql' => "GEQ",
|
141
|
+
'op_type' => "c",
|
142
|
+
},
|
143
|
+
'uint64_t' => {
|
144
|
+
'type' => "uint64_t",
|
145
|
+
'zero' => '0',
|
146
|
+
'dat2type' => '',
|
147
|
+
'obj2type' => 'NUM2ULL',
|
148
|
+
'type2obj' => 'ULL2NUM',
|
149
|
+
'type2dbl' => '(float64_t)',
|
150
|
+
'int2type' => '',
|
151
|
+
'atype' => 'double',
|
152
|
+
'azero' => '0.0',
|
153
|
+
'aone' => '1.0',
|
154
|
+
'atype2obj' => 'rb_float_new',
|
155
|
+
'eql' => "GEQ",
|
156
|
+
'op_type' => "c",
|
157
|
+
},
|
158
|
+
'float32_t' => {
|
159
|
+
'type' => "float32_t",
|
160
|
+
'zero' => '0.0',
|
161
|
+
'dat2type' => '',
|
162
|
+
'obj2type' => 'NUM2DBL',
|
163
|
+
'type2obj' => 'rb_float_new',
|
164
|
+
'type2dbl' => '(float64_t)',
|
165
|
+
'int2type' => '',
|
166
|
+
'atype' => 'double',
|
167
|
+
'azero' => '0.0',
|
168
|
+
'aone' => '1.0',
|
169
|
+
'atype2obj' => 'rb_float_new',
|
170
|
+
'eql' => "GEQ",
|
171
|
+
'op_type' => "c",
|
172
|
+
},
|
173
|
+
'float64_t' => {
|
174
|
+
'type' => "float64_t",
|
175
|
+
'zero' => '0.0',
|
176
|
+
'dat2type' => '',
|
177
|
+
'obj2type' => 'NUM2DBL',
|
178
|
+
'type2obj' => 'rb_float_new',
|
179
|
+
'type2dbl' => '',
|
180
|
+
'int2type' => '',
|
181
|
+
'atype' => 'double',
|
182
|
+
'azero' => '0.0',
|
183
|
+
'aone' => '1.0',
|
184
|
+
'atype2obj' => 'rb_float_new',
|
185
|
+
'eql' => "GEQ",
|
186
|
+
'op_type' => "c",
|
187
|
+
},
|
188
|
+
'float128_t' => {
|
189
|
+
'type' => "float128_t",
|
190
|
+
'zero' => '0.0',
|
191
|
+
'dat2type' => '',
|
192
|
+
'obj2type' => 'NUM2DBL',
|
193
|
+
'type2obj' => 'rb_float_new',
|
194
|
+
'type2dbl' => '',
|
195
|
+
'int2type' => '',
|
196
|
+
'atype' => 'double',
|
197
|
+
'azero' => '0.0',
|
198
|
+
'aone' => '1.0',
|
199
|
+
'atype2obj' => 'rb_float_new',
|
200
|
+
'eql' => "GEQ",
|
201
|
+
'op_type' => "c",
|
202
|
+
},
|
203
|
+
'cmplx64_t' => {
|
204
|
+
'type' => "cmplx64_t",
|
205
|
+
'zero' => '0.0',
|
206
|
+
'dat2type' => '',
|
207
|
+
'obj2type' => 'NUM2CC',
|
208
|
+
'type2obj' => 'rb_ccomplex_new',
|
209
|
+
'type2dbl' => '',
|
210
|
+
'int2type' => '',
|
211
|
+
'atype' => 'cmplx128_t',
|
212
|
+
'azero' => '0.0',
|
213
|
+
'aone' => '1.0',
|
214
|
+
'atype2obj' => 'rb_ccomplex_new',
|
215
|
+
'eql' => "GEQ",
|
216
|
+
'op_type' => "c",
|
217
|
+
},
|
218
|
+
'cmplx128_t' => {
|
219
|
+
'type' => "cmplx128_t",
|
220
|
+
'zero' => '0.0',
|
221
|
+
'dat2type' => '',
|
222
|
+
'obj2type' => 'NUM2CC',
|
223
|
+
'type2obj' => 'rb_ccomplex_new',
|
224
|
+
'type2dbl' => '',
|
225
|
+
'int2type' => '',
|
226
|
+
'atype' => 'cmplx128_t',
|
227
|
+
'azero' => '0.0',
|
228
|
+
'aone' => '1.0',
|
229
|
+
'atype2obj' => 'rb_ccomplex_new',
|
230
|
+
'eql' => "GEQ",
|
231
|
+
'op_type' => "c",
|
232
|
+
},
|
233
|
+
'cmplx256_t' => {
|
234
|
+
'type' => "cmplx256_t",
|
235
|
+
'zero' => '0.0',
|
236
|
+
'dat2type' => '',
|
237
|
+
'obj2type' => 'NUM2CC',
|
238
|
+
'type2obj' => 'rb_ccomplex_new',
|
239
|
+
'type2dbl' => '',
|
240
|
+
'int2type' => '',
|
241
|
+
'atype' => 'cmplx128_t',
|
242
|
+
'azero' => '0.0',
|
243
|
+
'aone' => '1.0',
|
244
|
+
'atype2obj' => 'rb_ccomplex_new',
|
245
|
+
'eql' => "GEQ",
|
246
|
+
'op_type' => "c",
|
247
|
+
},
|
248
|
+
'VALUE' => {
|
249
|
+
'type' => "VALUE",
|
250
|
+
'zero' => 'INT2FIX(0)',
|
251
|
+
'dat2type' => '',
|
252
|
+
'obj2type' => '',
|
253
|
+
'type2obj' => '',
|
254
|
+
'type2dbl' => 'NUM2DBL',
|
255
|
+
'int2type' => 'INT2NUM',
|
256
|
+
'atype' => 'VALUE',
|
257
|
+
'azero' => 'rb_float_new(0.0)',
|
258
|
+
'aone' => 'rb_float_new(1.0)',
|
259
|
+
'atype2obj' => '',
|
260
|
+
'eql' => "OEQ",
|
261
|
+
'op_type' => "VALUE",
|
262
|
+
},
|
263
|
+
|
264
|
+
}
|
265
|
+
|
266
|
+
# --------------------------------------------------------------------------
|
267
|
+
#
|
268
|
+
# HEADER
|
269
|
+
#
|
270
|
+
# --------------------------------------------------------------------------
|
271
|
+
|
272
|
+
header = <<HERE_END
|
273
|
+
/* ---------------------------------------------------------------------------
|
274
|
+
|
275
|
+
carray_stat_proc.c
|
276
|
+
|
277
|
+
This file is part of Ruby/CArray extension library.
|
278
|
+
You can redistribute it and/or modify it under the terms of
|
279
|
+
the Ruby Licence.
|
280
|
+
|
281
|
+
This file is automatically generated from carray_stat_proc.rb
|
282
|
+
|
283
|
+
Copyright (C) 2005 Hiroki Motoyoshi
|
284
|
+
|
285
|
+
---------------------------------------------------------------------------- */
|
286
|
+
|
287
|
+
#include <math.h>
|
288
|
+
#include "ruby.h"
|
289
|
+
#include "carray.h"
|
290
|
+
|
291
|
+
typedef struct {
|
292
|
+
int32_t offset;
|
293
|
+
int32_t count;
|
294
|
+
int32_t step;
|
295
|
+
int32_t *addr;
|
296
|
+
} CAStatIterator;
|
297
|
+
|
298
|
+
typedef void (*ca_stat_proc_t)();
|
299
|
+
|
300
|
+
#define iterator_rewind(it) \
|
301
|
+
{ \
|
302
|
+
if ( (it)->step ) { \
|
303
|
+
(it)->count = 0; \
|
304
|
+
(it)->offset = (it)->addr[((it)->count)++]; \
|
305
|
+
} \
|
306
|
+
else { \
|
307
|
+
(it)->offset = 0; \
|
308
|
+
} \
|
309
|
+
}
|
310
|
+
|
311
|
+
#define iterator_succ(it) \
|
312
|
+
{ \
|
313
|
+
if ( (it)->step ) { \
|
314
|
+
(it)->offset = (it)->addr[((it)->count)++]; \
|
315
|
+
} \
|
316
|
+
else { \
|
317
|
+
((it)->offset)++; \
|
318
|
+
} \
|
319
|
+
}
|
320
|
+
|
321
|
+
static ID id_lt, id_gt, id_plus, id_minus, id_star, id_quo;
|
322
|
+
|
323
|
+
#define GEQ(x,y) ( (x) == (y) )
|
324
|
+
#define OEQ(x,y) rb_equal((x),(y))
|
325
|
+
|
326
|
+
#define lt_c(x, y) ( (x) < (y) )
|
327
|
+
#define lt_VALUE(x, y) rb_funcall((x), id_lt, 1, (y))
|
328
|
+
|
329
|
+
#define gt_c(x, y) ( (x) > (y) )
|
330
|
+
#define gt_VALUE(x, y) rb_funcall((x), id_gt, 1, (y))
|
331
|
+
|
332
|
+
#define add_c(x, y) ( (x) + (y) )
|
333
|
+
#define add_VALUE(x, y) rb_funcall((x), id_plus, 1, (y))
|
334
|
+
|
335
|
+
#define sub_c(x, y) ( (x) - (y) )
|
336
|
+
#define sub_VALUE(x, y) rb_funcall((x), id_minus, 1, (y))
|
337
|
+
|
338
|
+
#define mul_c(x, y) ( (x) * (y) )
|
339
|
+
#define mul_VALUE(x, y) rb_funcall((x), id_star, 1, (y))
|
340
|
+
|
341
|
+
#define div_c(x, y) ( (x) / (y) )
|
342
|
+
#define div_VALUE(x, y) rb_funcall((x), id_quo, 1, (y))
|
343
|
+
|
344
|
+
#define sqrt_c(x) sqrt(x)
|
345
|
+
#define sqrt_VALUE(x) rb_funcall((x), rb_intern("sqrt"), 0)
|
346
|
+
|
347
|
+
HERE_END
|
348
|
+
|
349
|
+
puts header
|
350
|
+
|
351
|
+
|
352
|
+
# --------------------------------------------------------------------------
|
353
|
+
#
|
354
|
+
# STAT Part 1
|
355
|
+
#
|
356
|
+
# --------------------------------------------------------------------------
|
357
|
+
|
358
|
+
|
359
|
+
text = <<'HERE_END'
|
360
|
+
|
361
|
+
/* ============================= */
|
362
|
+
/* ca_proc_prod */
|
363
|
+
/* ============================= */
|
364
|
+
|
365
|
+
static void
|
366
|
+
ca_proc_prod_<type> (int32_t elements, int32_t min_count,
|
367
|
+
boolean8_t *m, void *ptr, CAStatIterator *it,
|
368
|
+
int return_object, VALUE *retobj,
|
369
|
+
boolean8_t *retmask, <atype> *retval)
|
370
|
+
{
|
371
|
+
volatile <atype> prod = <aone>;
|
372
|
+
<type> *p = (<type> *) ptr;
|
373
|
+
int32_t *a = (int32_t *) it;
|
374
|
+
int32_t count = 0;
|
375
|
+
int32_t i;
|
376
|
+
iterator_rewind(it);
|
377
|
+
if ( m ) {
|
378
|
+
for (i=0; i<elements; i++) {
|
379
|
+
if ( *(m + *a) ) {
|
380
|
+
count++;
|
381
|
+
}
|
382
|
+
else {
|
383
|
+
prod = mul_<op_type>(prod, (<atype>)<dat2type>(*(p + *a)));
|
384
|
+
}
|
385
|
+
iterator_succ(it);
|
386
|
+
}
|
387
|
+
}
|
388
|
+
else {
|
389
|
+
for (i=0; i<elements; i++) {
|
390
|
+
prod = mul_<op_type>(prod, (<atype>)<dat2type>(*(p + *a)));
|
391
|
+
iterator_succ(it);
|
392
|
+
}
|
393
|
+
}
|
394
|
+
if ( return_object ) {
|
395
|
+
*retobj = ( count > min_count ) ? CA_UNDEF : <atype2obj>(prod);
|
396
|
+
}
|
397
|
+
else {
|
398
|
+
if ( retmask ) {
|
399
|
+
*retmask = ( count > min_count ) ? 1 : 0;
|
400
|
+
}
|
401
|
+
*retval = prod;
|
402
|
+
}
|
403
|
+
}
|
404
|
+
|
405
|
+
/* ============================= */
|
406
|
+
/* ca_proc_count */
|
407
|
+
/* ============================= */
|
408
|
+
|
409
|
+
static void
|
410
|
+
ca_proc_count_<type> (int32_t elements, int32_t min_count,
|
411
|
+
boolean8_t *m, void *ptr, CAStatIterator *it,
|
412
|
+
int return_object, VALUE *retobj,
|
413
|
+
boolean8_t *retmask, int32_t *retval)
|
414
|
+
{
|
415
|
+
int32_t *a = (int32_t *) it;
|
416
|
+
int32_t count = 0;
|
417
|
+
int32_t i;
|
418
|
+
iterator_rewind(it);
|
419
|
+
if ( m ) {
|
420
|
+
for (i=0; i<elements; i++) {
|
421
|
+
if ( *(m + *a) ) {
|
422
|
+
count++;
|
423
|
+
}
|
424
|
+
iterator_succ(it);
|
425
|
+
}
|
426
|
+
}
|
427
|
+
if ( return_object ) {
|
428
|
+
*retobj = ( count > min_count ) ? CA_UNDEF : LONG2NUM(elements - count);
|
429
|
+
}
|
430
|
+
else {
|
431
|
+
if ( retmask ) {
|
432
|
+
*retmask = ( count > min_count ) ? 1 : 0;
|
433
|
+
}
|
434
|
+
*retval = elements - count;
|
435
|
+
}
|
436
|
+
}
|
437
|
+
|
438
|
+
static void
|
439
|
+
ca_proc_sum_<type> (int32_t elements, int32_t min_count,
|
440
|
+
boolean8_t *m, void *ptr, CAStatIterator *it,
|
441
|
+
int return_object, VALUE *retobj,
|
442
|
+
boolean8_t *retmask, float64_t *retval)
|
443
|
+
{
|
444
|
+
volatile <atype> sum = <azero>;
|
445
|
+
<type> *p = (<type> *) ptr;
|
446
|
+
int32_t *a = (int32_t *)it;
|
447
|
+
int32_t count = 0;
|
448
|
+
int32_t i;
|
449
|
+
iterator_rewind(it);
|
450
|
+
if ( m ) {
|
451
|
+
for (i=0; i<elements; i++) {
|
452
|
+
if ( *(m + *a) ) {
|
453
|
+
count++;
|
454
|
+
}
|
455
|
+
else {
|
456
|
+
sum = add_<op_type>(sum, (<atype>)<dat2type>(*(p + *a)));
|
457
|
+
}
|
458
|
+
iterator_succ(it);
|
459
|
+
}
|
460
|
+
}
|
461
|
+
else {
|
462
|
+
for (i=0; i<elements; i++) {
|
463
|
+
sum = add_<op_type>(sum, (<atype>)<dat2type>(*(p + *a)));
|
464
|
+
iterator_succ(it);
|
465
|
+
}
|
466
|
+
}
|
467
|
+
if ( return_object ) {
|
468
|
+
*retobj = ( count > min_count ) ? CA_UNDEF : <atype2obj>(sum);
|
469
|
+
}
|
470
|
+
else {
|
471
|
+
if ( retmask ) {
|
472
|
+
*retmask = ( count > min_count ) ? 1 : 0;
|
473
|
+
}
|
474
|
+
*retval = <type2dbl>(sum);
|
475
|
+
}
|
476
|
+
}
|
477
|
+
|
478
|
+
|
479
|
+
/* ============================= */
|
480
|
+
/* ca_proc_mean */
|
481
|
+
/* ============================= */
|
482
|
+
|
483
|
+
static void
|
484
|
+
ca_proc_mean_<type> (int32_t elements, int32_t min_count,
|
485
|
+
boolean8_t *m, void *ptr, CAStatIterator *it,
|
486
|
+
int return_object, VALUE *retobj,
|
487
|
+
boolean8_t *retmask, float64_t *retval)
|
488
|
+
{
|
489
|
+
volatile <atype> sum = <azero>, ave;
|
490
|
+
<type> *p = (<type> *) ptr;
|
491
|
+
int32_t *a = (int32_t *) it;
|
492
|
+
int32_t count = 0;
|
493
|
+
int32_t i;
|
494
|
+
iterator_rewind(it);
|
495
|
+
if ( m ) {
|
496
|
+
for (i=0; i<elements; i++) {
|
497
|
+
if ( *(m + *a) ) {
|
498
|
+
count++;
|
499
|
+
}
|
500
|
+
else {
|
501
|
+
sum = add_<op_type>(sum, (<atype>)<dat2type>(*(p + *a)));
|
502
|
+
}
|
503
|
+
iterator_succ(it);
|
504
|
+
}
|
505
|
+
}
|
506
|
+
else {
|
507
|
+
for (i=0; i<elements; i++) {
|
508
|
+
sum = add_<op_type>(sum, (<atype>)<dat2type>(*(p + *a)));
|
509
|
+
iterator_succ(it);
|
510
|
+
}
|
511
|
+
}
|
512
|
+
ave = div_<op_type>(sum, (<atype>)<int2type>(elements-count));
|
513
|
+
if ( return_object ) {
|
514
|
+
*retobj = ( count > min_count ) ? CA_UNDEF : <atype2obj>(ave);
|
515
|
+
}
|
516
|
+
else {
|
517
|
+
if ( retmask ) {
|
518
|
+
*retmask = ( count > min_count ) ? 1 : 0;
|
519
|
+
}
|
520
|
+
*retval = <type2dbl>(ave);
|
521
|
+
}
|
522
|
+
}
|
523
|
+
|
524
|
+
/* ============================= */
|
525
|
+
/* ca_proc_variancep */
|
526
|
+
/* ============================= */
|
527
|
+
|
528
|
+
static void
|
529
|
+
ca_proc_variancep_<type> (int32_t elements, int32_t min_count,
|
530
|
+
boolean8_t *m, void *ptr, CAStatIterator *it,
|
531
|
+
int return_object, VALUE *retobj,
|
532
|
+
boolean8_t *retmask, float64_t *retval)
|
533
|
+
{
|
534
|
+
volatile <atype> sum = <azero>, sum2 = <azero>, ave, var, diff;
|
535
|
+
<type> *p = (<type> *) ptr;
|
536
|
+
int32_t *a = (int32_t *) it;
|
537
|
+
int32_t count = 0;
|
538
|
+
int32_t i;
|
539
|
+
iterator_rewind(it);
|
540
|
+
if ( m ) {
|
541
|
+
for (i=0; i<elements; i++) {
|
542
|
+
if ( *(m + *a) ) {
|
543
|
+
count++;
|
544
|
+
}
|
545
|
+
else {
|
546
|
+
sum = add_<op_type>(sum, (<atype>)<dat2type>(*(p + *a)));
|
547
|
+
}
|
548
|
+
iterator_succ(it);
|
549
|
+
}
|
550
|
+
}
|
551
|
+
else {
|
552
|
+
for (i=0; i<elements; i++) {
|
553
|
+
sum = add_<op_type>(sum, (<atype>)<dat2type>(*(p + *a)));
|
554
|
+
iterator_succ(it);
|
555
|
+
}
|
556
|
+
}
|
557
|
+
ave = div_<op_type>(sum, (<atype>)<int2type>(elements-count));
|
558
|
+
|
559
|
+
iterator_rewind(it);
|
560
|
+
if ( m ) {
|
561
|
+
for (i=0; i<elements; i++) {
|
562
|
+
if ( *(m + *a) ) {
|
563
|
+
;
|
564
|
+
}
|
565
|
+
else {
|
566
|
+
diff = sub_<op_type>((<atype>)<dat2type>(*(p + *a)), ave);
|
567
|
+
sum2 = add_<op_type>(sum2, mul_<op_type>(diff,diff));
|
568
|
+
}
|
569
|
+
iterator_succ(it);
|
570
|
+
}
|
571
|
+
}
|
572
|
+
else {
|
573
|
+
for (i=0; i<elements; i++) {
|
574
|
+
diff = sub_<op_type>((<atype>)<dat2type>(*(p + *a)), ave);
|
575
|
+
sum2 = add_<op_type>(sum2, mul_<op_type>(diff,diff));
|
576
|
+
iterator_succ(it);
|
577
|
+
}
|
578
|
+
}
|
579
|
+
|
580
|
+
var = div_<op_type>(sum2, (<atype>)<int2type>(elements-count));
|
581
|
+
|
582
|
+
if ( return_object ) {
|
583
|
+
*retobj = ( count > min_count ) ? CA_UNDEF : <atype2obj>(var);
|
584
|
+
}
|
585
|
+
else {
|
586
|
+
if ( retmask ) {
|
587
|
+
*retmask = ( count > min_count ) ? 1 : 0;
|
588
|
+
}
|
589
|
+
*retval = <type2dbl>(var);
|
590
|
+
}
|
591
|
+
}
|
592
|
+
|
593
|
+
/* ============================= */
|
594
|
+
/* ca_proc_stddevp */
|
595
|
+
/* ============================= */
|
596
|
+
|
597
|
+
static void
|
598
|
+
ca_proc_stddevp_<type> (int32_t elements, int32_t min_count,
|
599
|
+
boolean8_t *m, void *ptr, CAStatIterator *it,
|
600
|
+
int return_object, VALUE *retobj,
|
601
|
+
boolean8_t *retmask, float64_t *retval)
|
602
|
+
{
|
603
|
+
volatile <atype> sum = <azero>, sum2 = <azero>, ave, var, diff;
|
604
|
+
<type> *p = (<type> *) ptr;
|
605
|
+
int32_t *a = (int32_t *) it;
|
606
|
+
int32_t count = 0;
|
607
|
+
int32_t i;
|
608
|
+
iterator_rewind(it);
|
609
|
+
if ( m ) {
|
610
|
+
for (i=0; i<elements; i++) {
|
611
|
+
if ( *(m + *a) ) {
|
612
|
+
count++;
|
613
|
+
}
|
614
|
+
else {
|
615
|
+
sum = add_<op_type>(sum, (<atype>)<dat2type>(*(p + *a)));
|
616
|
+
}
|
617
|
+
iterator_succ(it);
|
618
|
+
}
|
619
|
+
}
|
620
|
+
else {
|
621
|
+
for (i=0; i<elements; i++) {
|
622
|
+
sum = add_<op_type>(sum, (<atype>)<dat2type>(*(p + *a)));
|
623
|
+
iterator_succ(it);
|
624
|
+
}
|
625
|
+
}
|
626
|
+
ave = div_<op_type>(sum, (<atype>)<int2type>(elements-count));
|
627
|
+
|
628
|
+
iterator_rewind(it);
|
629
|
+
if ( m ) {
|
630
|
+
for (i=0; i<elements; i++) {
|
631
|
+
if ( *(m + *a) ) {
|
632
|
+
;
|
633
|
+
}
|
634
|
+
else {
|
635
|
+
diff = sub_<op_type>((<atype>)<dat2type>(*(p + *a)), ave);
|
636
|
+
sum2 = add_<op_type>(sum2, mul_<op_type>(diff,diff));
|
637
|
+
}
|
638
|
+
iterator_succ(it);
|
639
|
+
}
|
640
|
+
}
|
641
|
+
else {
|
642
|
+
for (i=0; i<elements; i++) {
|
643
|
+
diff = sub_<op_type>((<atype>)<dat2type>(*(p + *a)), ave);
|
644
|
+
sum2 = add_<op_type>(sum2, mul_<op_type>(diff,diff));
|
645
|
+
iterator_succ(it);
|
646
|
+
}
|
647
|
+
}
|
648
|
+
|
649
|
+
var = div_<op_type>(sum2, (<atype>)<int2type>(elements-count));
|
650
|
+
|
651
|
+
if ( return_object ) {
|
652
|
+
*retobj = ( count > min_count ) ? CA_UNDEF : <atype2obj>(sqrt_<op_type>(var));
|
653
|
+
}
|
654
|
+
else {
|
655
|
+
if ( retmask ) {
|
656
|
+
*retmask = ( count > min_count ) ? 1 : 0;
|
657
|
+
}
|
658
|
+
*retval = <type2dbl>(sqrt_<op_type>(var));
|
659
|
+
}
|
660
|
+
}
|
661
|
+
|
662
|
+
/* ============================= */
|
663
|
+
/* ca_proc_variance */
|
664
|
+
/* ============================= */
|
665
|
+
|
666
|
+
static void
|
667
|
+
ca_proc_variance_<type> (int32_t elements, int32_t min_count,
|
668
|
+
boolean8_t *m, void *ptr, CAStatIterator *it,
|
669
|
+
int return_object, VALUE *retobj,
|
670
|
+
boolean8_t *retmask, float64_t *retval)
|
671
|
+
{
|
672
|
+
volatile <atype> sum = <azero>, sum2 = <azero>, ave, var, diff;
|
673
|
+
<type> *p = (<type> *) ptr;
|
674
|
+
int32_t *a = (int32_t *) it;
|
675
|
+
int32_t count = 0;
|
676
|
+
int32_t i;
|
677
|
+
iterator_rewind(it);
|
678
|
+
if ( m ) {
|
679
|
+
for (i=0; i<elements; i++) {
|
680
|
+
if ( *(m + *a) ) {
|
681
|
+
count++;
|
682
|
+
}
|
683
|
+
else {
|
684
|
+
sum = add_<op_type>(sum, (<atype>)<dat2type>(*(p + *a)));
|
685
|
+
}
|
686
|
+
iterator_succ(it);
|
687
|
+
}
|
688
|
+
}
|
689
|
+
else {
|
690
|
+
for (i=0; i<elements; i++) {
|
691
|
+
sum = add_<op_type>(sum, (<atype>)<dat2type>(*(p + *a)));
|
692
|
+
iterator_succ(it);
|
693
|
+
}
|
694
|
+
}
|
695
|
+
ave = div_<op_type>(sum, (<atype>)<int2type>(elements-count));
|
696
|
+
|
697
|
+
iterator_rewind(it);
|
698
|
+
if ( m ) {
|
699
|
+
for (i=0; i<elements; i++) {
|
700
|
+
if ( *(m + *a) ) {
|
701
|
+
;
|
702
|
+
}
|
703
|
+
else {
|
704
|
+
diff = sub_<op_type>((<atype>)<dat2type>(*(p + *a)), ave);
|
705
|
+
sum2 = add_<op_type>(sum2, mul_<op_type>(diff,diff));
|
706
|
+
}
|
707
|
+
iterator_succ(it);
|
708
|
+
}
|
709
|
+
}
|
710
|
+
else {
|
711
|
+
for (i=0; i<elements; i++) {
|
712
|
+
diff = sub_<op_type>((<atype>)<dat2type>(*(p + *a)), ave);
|
713
|
+
sum2 = add_<op_type>(sum2, mul_<op_type>(diff,diff));
|
714
|
+
iterator_succ(it);
|
715
|
+
}
|
716
|
+
}
|
717
|
+
|
718
|
+
var = div_<op_type>(sum2, (<atype>)<int2type>(elements-count-1));
|
719
|
+
|
720
|
+
if ( return_object ) {
|
721
|
+
*retobj = ( count > min_count ) ? CA_UNDEF : <atype2obj>(var);
|
722
|
+
}
|
723
|
+
else {
|
724
|
+
if ( retmask ) {
|
725
|
+
*retmask = ( count > min_count ) ? 1 : 0;
|
726
|
+
}
|
727
|
+
*retval = <type2dbl>(var);
|
728
|
+
}
|
729
|
+
}
|
730
|
+
|
731
|
+
/* ============================= */
|
732
|
+
/* ca_proc_stddev */
|
733
|
+
/* ============================= */
|
734
|
+
|
735
|
+
static void
|
736
|
+
ca_proc_stddev_<type> (int32_t elements, int32_t min_count,
|
737
|
+
boolean8_t *m, void *ptr, CAStatIterator *it,
|
738
|
+
int return_object, VALUE *retobj,
|
739
|
+
boolean8_t *retmask, <atype> *retval)
|
740
|
+
{
|
741
|
+
volatile <atype> sum = <azero>, sum2 = <azero>, ave, var, diff;
|
742
|
+
<type> *p = (<type> *) ptr;
|
743
|
+
int32_t *a = (int32_t *) it;
|
744
|
+
int32_t count = 0;
|
745
|
+
int32_t i;
|
746
|
+
iterator_rewind(it);
|
747
|
+
if ( m ) {
|
748
|
+
for (i=0; i<elements; i++) {
|
749
|
+
if ( *(m + *a) ) {
|
750
|
+
count++;
|
751
|
+
}
|
752
|
+
else {
|
753
|
+
sum = add_<op_type>(sum, (<atype>)<dat2type>(*(p + *a)));
|
754
|
+
}
|
755
|
+
iterator_succ(it);
|
756
|
+
}
|
757
|
+
}
|
758
|
+
else {
|
759
|
+
for (i=0; i<elements; i++) {
|
760
|
+
sum = add_<op_type>(sum, (<atype>)<dat2type>(*(p + *a)));
|
761
|
+
iterator_succ(it);
|
762
|
+
}
|
763
|
+
}
|
764
|
+
ave = div_<op_type>(sum, (<atype>)<int2type>(elements-count));
|
765
|
+
|
766
|
+
iterator_rewind(it);
|
767
|
+
if ( m ) {
|
768
|
+
for (i=0; i<elements; i++) {
|
769
|
+
if ( *(m + *a) ) {
|
770
|
+
;
|
771
|
+
}
|
772
|
+
else {
|
773
|
+
diff = sub_<op_type>((<atype>)<dat2type>(*(p + *a)), ave);
|
774
|
+
sum2 = add_<op_type>(sum2, mul_<op_type>(diff,diff));
|
775
|
+
}
|
776
|
+
iterator_succ(it);
|
777
|
+
}
|
778
|
+
}
|
779
|
+
else {
|
780
|
+
for (i=0; i<elements; i++) {
|
781
|
+
diff = sub_<op_type>((<atype>)<dat2type>(*(p + *a)), ave);
|
782
|
+
sum2 = add_<op_type>(sum2, mul_<op_type>(diff,diff));
|
783
|
+
iterator_succ(it);
|
784
|
+
}
|
785
|
+
}
|
786
|
+
|
787
|
+
var = div_<op_type>(sum2, (<atype>)<int2type>(elements-count-1));
|
788
|
+
|
789
|
+
if ( return_object ) {
|
790
|
+
*retobj = ( count > min_count ) ? CA_UNDEF : <atype2obj>(sqrt_<op_type>(var));
|
791
|
+
}
|
792
|
+
else {
|
793
|
+
if ( retmask ) {
|
794
|
+
*retmask = ( count > min_count ) ? 1 : 0;
|
795
|
+
}
|
796
|
+
*retval = sqrt_<op_type>(var);
|
797
|
+
}
|
798
|
+
}
|
799
|
+
|
800
|
+
/* ============================= */
|
801
|
+
/* ca_proc_min */
|
802
|
+
/* ============================= */
|
803
|
+
|
804
|
+
static void
|
805
|
+
ca_proc_min_<type> (int32_t elements, int32_t min_count,
|
806
|
+
boolean8_t *m, void *ptr, CAStatIterator *it,
|
807
|
+
int return_object, VALUE *retobj,
|
808
|
+
boolean8_t *retmask, <type> *retval)
|
809
|
+
{
|
810
|
+
<type> min = <zero>;
|
811
|
+
<type> *p = (<type> *) ptr;
|
812
|
+
int32_t *a = (int32_t *) it;
|
813
|
+
int32_t count = 0;
|
814
|
+
int32_t addr;
|
815
|
+
int32_t i;
|
816
|
+
iterator_rewind(it);
|
817
|
+
if ( m ) {
|
818
|
+
addr = -1;
|
819
|
+
for (i=0; i<elements; i++) {
|
820
|
+
if ( *(m + *a) ) {
|
821
|
+
count++;
|
822
|
+
}
|
823
|
+
else {
|
824
|
+
min = *(p + *a);
|
825
|
+
addr = i;
|
826
|
+
break;
|
827
|
+
}
|
828
|
+
iterator_succ(it);
|
829
|
+
}
|
830
|
+
iterator_succ(it);
|
831
|
+
if ( addr >= 0 ) {
|
832
|
+
for (i=addr+1; i<elements; i++) {
|
833
|
+
if ( *(m + *a) ) {
|
834
|
+
count++;
|
835
|
+
}
|
836
|
+
else {
|
837
|
+
if ( lt_<op_type>(*(p + *a), min) ) {
|
838
|
+
min = *(p + *a);
|
839
|
+
addr = i;
|
840
|
+
}
|
841
|
+
}
|
842
|
+
iterator_succ(it);
|
843
|
+
}
|
844
|
+
}
|
845
|
+
}
|
846
|
+
else {
|
847
|
+
min = *(p + *a);
|
848
|
+
addr = 0;
|
849
|
+
for (i=addr; i<elements; i++) {
|
850
|
+
if ( lt_<op_type>(*(p + *a), min) ) {
|
851
|
+
min = *(p + *a);
|
852
|
+
addr = i;
|
853
|
+
}
|
854
|
+
iterator_succ(it);
|
855
|
+
}
|
856
|
+
}
|
857
|
+
if ( return_object ) {
|
858
|
+
*retobj = ( count > min_count ) ? CA_UNDEF : <type2obj>(min);
|
859
|
+
}
|
860
|
+
else {
|
861
|
+
if ( retmask ) {
|
862
|
+
*retmask = ( count > min_count ) ? 1 : 0;
|
863
|
+
}
|
864
|
+
*retval = min;
|
865
|
+
}
|
866
|
+
}
|
867
|
+
|
868
|
+
/* ============================= */
|
869
|
+
/* ca_proc_min_addr */
|
870
|
+
/* ============================= */
|
871
|
+
|
872
|
+
static void
|
873
|
+
ca_proc_min_addr_<type> (int32_t elements, int32_t min_count,
|
874
|
+
boolean8_t *m, void *ptr, CAStatIterator *it,
|
875
|
+
int return_object, VALUE *retobj,
|
876
|
+
boolean8_t *retmask, int32_t *retval)
|
877
|
+
{
|
878
|
+
<type> min = <zero>;
|
879
|
+
<type> *p = (<type> *) ptr;
|
880
|
+
int32_t *a = (int32_t *) it;
|
881
|
+
int32_t count = 0;
|
882
|
+
int32_t addr;
|
883
|
+
int32_t i;
|
884
|
+
iterator_rewind(it);
|
885
|
+
if ( m ) {
|
886
|
+
addr = -1;
|
887
|
+
for (i=0; i<elements; i++) {
|
888
|
+
if ( *(m + *a) ) {
|
889
|
+
count++;
|
890
|
+
}
|
891
|
+
else {
|
892
|
+
min = *(p + *a);
|
893
|
+
addr = i;
|
894
|
+
break;
|
895
|
+
}
|
896
|
+
iterator_succ(it);
|
897
|
+
}
|
898
|
+
iterator_succ(it);
|
899
|
+
if ( addr >= 0 ) {
|
900
|
+
for (i=addr+1; i<elements; i++) {
|
901
|
+
if ( *(m + *a) ) {
|
902
|
+
count++;
|
903
|
+
}
|
904
|
+
else {
|
905
|
+
if ( lt_<op_type>(*(p + *a), min) ) {
|
906
|
+
min = *(p + *a);
|
907
|
+
addr = i;
|
908
|
+
}
|
909
|
+
}
|
910
|
+
iterator_succ(it);
|
911
|
+
}
|
912
|
+
}
|
913
|
+
}
|
914
|
+
else {
|
915
|
+
min = *(p + *a);
|
916
|
+
addr = 0;
|
917
|
+
for (i=addr; i<elements; i++) {
|
918
|
+
if ( lt_<op_type>(*(p + *a), min) ) {
|
919
|
+
min = *(p + *a);
|
920
|
+
addr = i;
|
921
|
+
}
|
922
|
+
iterator_succ(it);
|
923
|
+
}
|
924
|
+
}
|
925
|
+
if ( return_object ) {
|
926
|
+
*retobj = ( count > min_count ) ? CA_UNDEF
|
927
|
+
: ( addr < 0 ) ? Qnil : LONG2NUM(addr);
|
928
|
+
}
|
929
|
+
else {
|
930
|
+
if ( retmask ) {
|
931
|
+
*retmask = ( count > min_count ) ? 1 : 0;
|
932
|
+
}
|
933
|
+
*retval = addr;
|
934
|
+
}
|
935
|
+
}
|
936
|
+
|
937
|
+
/* ============================= */
|
938
|
+
/* ca_proc_max */
|
939
|
+
/* ============================= */
|
940
|
+
|
941
|
+
static void
|
942
|
+
ca_proc_max_<type> (int32_t elements, int32_t min_count,
|
943
|
+
boolean8_t *m, void *ptr, CAStatIterator *it,
|
944
|
+
int return_object, VALUE *retobj,
|
945
|
+
boolean8_t *retmask, <type> *retval)
|
946
|
+
{
|
947
|
+
<type> max = 0;
|
948
|
+
<type> *p = (<type> *) ptr;
|
949
|
+
int32_t *a = (int32_t *) it;
|
950
|
+
int32_t count = 0;
|
951
|
+
int32_t addr;
|
952
|
+
int32_t i;
|
953
|
+
iterator_rewind(it);
|
954
|
+
if ( m ) {
|
955
|
+
addr = -1;
|
956
|
+
for (i=0; i<elements; i++) {
|
957
|
+
if ( *(m + *a) ) {
|
958
|
+
count++;
|
959
|
+
}
|
960
|
+
else {
|
961
|
+
max = *(p + *a);
|
962
|
+
addr = i;
|
963
|
+
break;
|
964
|
+
}
|
965
|
+
iterator_succ(it);
|
966
|
+
}
|
967
|
+
iterator_succ(it);
|
968
|
+
if ( addr >= 0 ) {
|
969
|
+
for (i=addr+1; i<elements; i++) {
|
970
|
+
if ( *(m + *a) ) {
|
971
|
+
count++;
|
972
|
+
}
|
973
|
+
else {
|
974
|
+
if ( gt_<op_type>(*(p + *a), max) ) {
|
975
|
+
max = *(p + *a);
|
976
|
+
addr = i;
|
977
|
+
}
|
978
|
+
}
|
979
|
+
iterator_succ(it);
|
980
|
+
}
|
981
|
+
}
|
982
|
+
}
|
983
|
+
else {
|
984
|
+
max = *(p + *a);
|
985
|
+
addr = 0;
|
986
|
+
for (i=addr; i<elements; i++) {
|
987
|
+
if ( gt_<op_type>(*(p + *a), max) ) {
|
988
|
+
max = *(p + *a);
|
989
|
+
addr = i;
|
990
|
+
}
|
991
|
+
iterator_succ(it);
|
992
|
+
}
|
993
|
+
}
|
994
|
+
if ( return_object ) {
|
995
|
+
*retobj = ( count > min_count ) ? CA_UNDEF : <type2obj>(max);
|
996
|
+
}
|
997
|
+
else {
|
998
|
+
if ( retmask ) {
|
999
|
+
*retmask = ( count > min_count ) ? 1 : 0;
|
1000
|
+
}
|
1001
|
+
*retval = max;
|
1002
|
+
}
|
1003
|
+
}
|
1004
|
+
|
1005
|
+
/* ============================= */
|
1006
|
+
/* ca_proc_max_addr */
|
1007
|
+
/* ============================= */
|
1008
|
+
|
1009
|
+
static void
|
1010
|
+
ca_proc_max_addr_<type> (int32_t elements, int32_t min_count,
|
1011
|
+
boolean8_t *m, void *ptr, CAStatIterator *it,
|
1012
|
+
int return_object, VALUE *retobj,
|
1013
|
+
boolean8_t *retmask, int32_t *retval)
|
1014
|
+
{
|
1015
|
+
<type> max = 0;
|
1016
|
+
<type> *p = (<type> *) ptr;
|
1017
|
+
int32_t *a = (int32_t *) it;
|
1018
|
+
int32_t count = 0;
|
1019
|
+
int32_t addr;
|
1020
|
+
int32_t i;
|
1021
|
+
iterator_rewind(it);
|
1022
|
+
if ( m ) {
|
1023
|
+
addr = -1;
|
1024
|
+
for (i=0; i<elements; i++) {
|
1025
|
+
if ( *(m + *a) ) {
|
1026
|
+
count++;
|
1027
|
+
}
|
1028
|
+
else {
|
1029
|
+
max = *(p + *a);
|
1030
|
+
addr = i;
|
1031
|
+
break;
|
1032
|
+
}
|
1033
|
+
iterator_succ(it);
|
1034
|
+
}
|
1035
|
+
iterator_succ(it);
|
1036
|
+
if ( addr >= 0 ) {
|
1037
|
+
for (i=addr+1; i<elements; i++) {
|
1038
|
+
if ( *(m + *a) ) {
|
1039
|
+
count++;
|
1040
|
+
}
|
1041
|
+
else {
|
1042
|
+
if ( gt_<op_type>(*(p + *a), max) ) {
|
1043
|
+
max = *(p + *a);
|
1044
|
+
addr = i;
|
1045
|
+
}
|
1046
|
+
}
|
1047
|
+
iterator_succ(it);
|
1048
|
+
}
|
1049
|
+
}
|
1050
|
+
}
|
1051
|
+
else {
|
1052
|
+
max = *(p + *a);
|
1053
|
+
addr = 0;
|
1054
|
+
for (i=addr; i<elements; i++) {
|
1055
|
+
if ( gt_<op_type>(*(p + *a), max) ) {
|
1056
|
+
max = *(p + *a);
|
1057
|
+
addr = i;
|
1058
|
+
}
|
1059
|
+
iterator_succ(it);
|
1060
|
+
}
|
1061
|
+
}
|
1062
|
+
if ( return_object ) {
|
1063
|
+
*retobj = ( count > min_count ) ? CA_UNDEF
|
1064
|
+
: ( addr < 0 ) ? Qnil : LONG2NUM(addr);
|
1065
|
+
}
|
1066
|
+
else {
|
1067
|
+
if ( retmask ) {
|
1068
|
+
*retmask = ( count > min_count ) ? 1 : 0;
|
1069
|
+
}
|
1070
|
+
*retval = addr;
|
1071
|
+
}
|
1072
|
+
}
|
1073
|
+
|
1074
|
+
|
1075
|
+
/* ============================= */
|
1076
|
+
/* ca_proc_cumcount */
|
1077
|
+
/* ============================= */
|
1078
|
+
|
1079
|
+
static void
|
1080
|
+
ca_proc_cumcount_<type> (int32_t elements, int32_t min_count,
|
1081
|
+
boolean8_t *m, void *ptr, CAStatIterator *it,
|
1082
|
+
boolean8_t *retmask, int32_t *retval)
|
1083
|
+
{
|
1084
|
+
int32_t *a = (int32_t *) it;
|
1085
|
+
int32_t count = 0;
|
1086
|
+
int32_t i;
|
1087
|
+
iterator_rewind(it);
|
1088
|
+
if ( m ) {
|
1089
|
+
for (i=0; i<elements; i++) {
|
1090
|
+
if ( *(m + *a) ) {
|
1091
|
+
count++;
|
1092
|
+
}
|
1093
|
+
if ( retmask ) {
|
1094
|
+
if ( count > min_count ) {
|
1095
|
+
*retmask = 1;
|
1096
|
+
}
|
1097
|
+
else {
|
1098
|
+
*retmask = 0;
|
1099
|
+
}
|
1100
|
+
}
|
1101
|
+
*retval = i + 1 - count;
|
1102
|
+
retmask++; retval++;
|
1103
|
+
iterator_succ(it);
|
1104
|
+
}
|
1105
|
+
}
|
1106
|
+
else {
|
1107
|
+
for (i=0; i<elements; i++) {
|
1108
|
+
*retval = i+1;
|
1109
|
+
retval++;
|
1110
|
+
}
|
1111
|
+
}
|
1112
|
+
}
|
1113
|
+
|
1114
|
+
|
1115
|
+
/* ============================= */
|
1116
|
+
/* ca_proc_cumsum */
|
1117
|
+
/* ============================= */
|
1118
|
+
|
1119
|
+
static void
|
1120
|
+
ca_proc_cumsum_<type> (int32_t elements, int32_t min_count,
|
1121
|
+
boolean8_t *m, void *ptr, CAStatIterator *it,
|
1122
|
+
boolean8_t *retmask, float64_t *retval)
|
1123
|
+
{
|
1124
|
+
volatile <atype> sum = <azero>;
|
1125
|
+
<type> *p = (<type> *) ptr;
|
1126
|
+
int32_t *a = (int32_t *) it;
|
1127
|
+
int32_t count = 0;
|
1128
|
+
int32_t i;
|
1129
|
+
iterator_rewind(it);
|
1130
|
+
if ( m ) {
|
1131
|
+
for (i=0; i<elements; i++) {
|
1132
|
+
if ( *(m + *a) ) {
|
1133
|
+
count++;
|
1134
|
+
}
|
1135
|
+
else {
|
1136
|
+
sum = add_<op_type>(sum, (<atype>)<dat2type>(*(p + *a)));
|
1137
|
+
}
|
1138
|
+
if ( retmask ) {
|
1139
|
+
if ( count > min_count ) {
|
1140
|
+
*retmask = 1;
|
1141
|
+
}
|
1142
|
+
else {
|
1143
|
+
*retmask = 0;
|
1144
|
+
}
|
1145
|
+
}
|
1146
|
+
*retval = <type2dbl>(sum);
|
1147
|
+
retmask++; retval++;
|
1148
|
+
iterator_succ(it);
|
1149
|
+
}
|
1150
|
+
}
|
1151
|
+
else {
|
1152
|
+
for (i=0; i<elements; i++) {
|
1153
|
+
sum = add_<op_type>(sum, (<atype>)<dat2type>(*(p + *a)));
|
1154
|
+
*retval = <type2dbl>(sum);
|
1155
|
+
retval++;
|
1156
|
+
iterator_succ(it);
|
1157
|
+
}
|
1158
|
+
}
|
1159
|
+
}
|
1160
|
+
|
1161
|
+
HERE_END
|
1162
|
+
|
1163
|
+
puts macro_expand(text, TYPEINFO['boolean8_t'])
|
1164
|
+
puts macro_expand(text, TYPEINFO['int8_t'])
|
1165
|
+
puts macro_expand(text, TYPEINFO['uint8_t'])
|
1166
|
+
puts macro_expand(text, TYPEINFO['int16_t'])
|
1167
|
+
puts macro_expand(text, TYPEINFO['uint16_t'])
|
1168
|
+
puts macro_expand(text, TYPEINFO['int32_t'])
|
1169
|
+
puts macro_expand(text, TYPEINFO['uint32_t'])
|
1170
|
+
puts macro_expand(text, TYPEINFO['int64_t'])
|
1171
|
+
puts macro_expand(text, TYPEINFO['uint64_t'])
|
1172
|
+
puts macro_expand(text, TYPEINFO['float32_t'])
|
1173
|
+
puts macro_expand(text, TYPEINFO['float64_t'])
|
1174
|
+
puts macro_expand(text, TYPEINFO['float128_t'])
|
1175
|
+
# puts macro_expand(text, TYPEINFO['cmplx64_t'])
|
1176
|
+
# puts macro_expand(text, TYPEINFO['cmplx128_t'])
|
1177
|
+
# puts macro_expand(text, TYPEINFO['cmplx256_t'])
|
1178
|
+
puts macro_expand(text, TYPEINFO['VALUE'])
|
1179
|
+
|
1180
|
+
text = <<'HERE_END'
|
1181
|
+
static ca_stat_proc_t
|
1182
|
+
ca_proc_<name>[CA_NTYPE] = {
|
1183
|
+
NULL,
|
1184
|
+
ca_proc_<name>_boolean8_t,
|
1185
|
+
ca_proc_<name>_int8_t,
|
1186
|
+
ca_proc_<name>_uint8_t,
|
1187
|
+
ca_proc_<name>_int16_t,
|
1188
|
+
ca_proc_<name>_uint16_t,
|
1189
|
+
ca_proc_<name>_int32_t,
|
1190
|
+
ca_proc_<name>_uint32_t,
|
1191
|
+
ca_proc_<name>_int64_t,
|
1192
|
+
ca_proc_<name>_uint64_t,
|
1193
|
+
ca_proc_<name>_float32_t,
|
1194
|
+
ca_proc_<name>_float64_t,
|
1195
|
+
ca_proc_<name>_float128_t,
|
1196
|
+
NULL, /* ca_proc_<name>_cmplx64_t, */
|
1197
|
+
NULL, /* ca_proc_<name>_cmplx128_t, */
|
1198
|
+
NULL, /* ca_proc_<name>_cmplx256_t, */
|
1199
|
+
ca_proc_<name>_VALUE,
|
1200
|
+
};
|
1201
|
+
|
1202
|
+
HERE_END
|
1203
|
+
|
1204
|
+
puts macro_expand(text, "name" => "count")
|
1205
|
+
puts macro_expand(text, "name" => "sum")
|
1206
|
+
puts macro_expand(text, "name" => "mean")
|
1207
|
+
puts macro_expand(text, "name" => "variancep")
|
1208
|
+
puts macro_expand(text, "name" => "stddevp")
|
1209
|
+
puts macro_expand(text, "name" => "variance")
|
1210
|
+
puts macro_expand(text, "name" => "stddev")
|
1211
|
+
puts macro_expand(text, "name" => "prod")
|
1212
|
+
puts macro_expand(text, "name" => "min")
|
1213
|
+
puts macro_expand(text, "name" => "min_addr")
|
1214
|
+
puts macro_expand(text, "name" => "max")
|
1215
|
+
puts macro_expand(text, "name" => "max_addr")
|
1216
|
+
|
1217
|
+
puts macro_expand(text, "name" => "cumcount")
|
1218
|
+
puts macro_expand(text, "name" => "cumsum")
|
1219
|
+
|
1220
|
+
# --------------------------------------------------------------------------
|
1221
|
+
#
|
1222
|
+
# STAT Part 2
|
1223
|
+
#
|
1224
|
+
# --------------------------------------------------------------------------
|
1225
|
+
|
1226
|
+
text = <<'HERE_END'
|
1227
|
+
|
1228
|
+
/* ============================= */
|
1229
|
+
/* ca_proc_accum */
|
1230
|
+
/* ============================= */
|
1231
|
+
|
1232
|
+
static void
|
1233
|
+
ca_proc_accum_<type> (int32_t elements, int32_t min_count,
|
1234
|
+
boolean8_t *m, void *ptr, CAStatIterator *it,
|
1235
|
+
int return_object, VALUE *retobj,
|
1236
|
+
boolean8_t *retmask, <type> *retval)
|
1237
|
+
{
|
1238
|
+
<type> sum = <zero>;
|
1239
|
+
<type> *p = (<type> *) ptr;
|
1240
|
+
int32_t *a = (int32_t *) it;
|
1241
|
+
int32_t count = 0;
|
1242
|
+
int32_t i;
|
1243
|
+
iterator_rewind(it);
|
1244
|
+
if ( m ) {
|
1245
|
+
for (i=0; i<elements; i++) {
|
1246
|
+
if ( *(m + *a) ) {
|
1247
|
+
count++;
|
1248
|
+
}
|
1249
|
+
else {
|
1250
|
+
sum = add_<op_type>(sum, (<type>)<dat2type>(*(p + *a)));
|
1251
|
+
}
|
1252
|
+
iterator_succ(it);
|
1253
|
+
}
|
1254
|
+
}
|
1255
|
+
else {
|
1256
|
+
for (i=0; i<elements; i++) {
|
1257
|
+
sum = add_<op_type>(sum, (<type>)<dat2type>(*(p + *a)));
|
1258
|
+
iterator_succ(it);
|
1259
|
+
}
|
1260
|
+
}
|
1261
|
+
if ( return_object ) {
|
1262
|
+
*retobj = ( count > min_count ) ? CA_UNDEF : <type2obj>(sum);
|
1263
|
+
}
|
1264
|
+
else {
|
1265
|
+
if ( retmask ) {
|
1266
|
+
*retmask = ( count > min_count ) ? 1 : 0;
|
1267
|
+
}
|
1268
|
+
*retval = sum;
|
1269
|
+
}
|
1270
|
+
}
|
1271
|
+
|
1272
|
+
HERE_END
|
1273
|
+
|
1274
|
+
puts macro_expand(text, TYPEINFO['boolean8_t'])
|
1275
|
+
puts macro_expand(text, TYPEINFO['int8_t'])
|
1276
|
+
puts macro_expand(text, TYPEINFO['uint8_t'])
|
1277
|
+
puts macro_expand(text, TYPEINFO['int16_t'])
|
1278
|
+
puts macro_expand(text, TYPEINFO['uint16_t'])
|
1279
|
+
puts macro_expand(text, TYPEINFO['int32_t'])
|
1280
|
+
puts macro_expand(text, TYPEINFO['uint32_t'])
|
1281
|
+
puts macro_expand(text, TYPEINFO['int64_t'])
|
1282
|
+
puts macro_expand(text, TYPEINFO['uint64_t'])
|
1283
|
+
puts macro_expand(text, TYPEINFO['float32_t'])
|
1284
|
+
puts macro_expand(text, TYPEINFO['float64_t'])
|
1285
|
+
puts macro_expand(text, TYPEINFO['float128_t'])
|
1286
|
+
puts macro_expand(text, TYPEINFO['cmplx64_t'])
|
1287
|
+
puts macro_expand(text, TYPEINFO['cmplx128_t'])
|
1288
|
+
puts macro_expand(text, TYPEINFO['cmplx256_t'])
|
1289
|
+
puts macro_expand(text, TYPEINFO['VALUE'])
|
1290
|
+
|
1291
|
+
text = <<'HERE_END'
|
1292
|
+
static ca_stat_proc_t
|
1293
|
+
ca_proc_<name>[CA_NTYPE] = {
|
1294
|
+
NULL,
|
1295
|
+
ca_proc_<name>_boolean8_t,
|
1296
|
+
ca_proc_<name>_int8_t,
|
1297
|
+
ca_proc_<name>_uint8_t,
|
1298
|
+
ca_proc_<name>_int16_t,
|
1299
|
+
ca_proc_<name>_uint16_t,
|
1300
|
+
ca_proc_<name>_int32_t,
|
1301
|
+
ca_proc_<name>_uint32_t,
|
1302
|
+
ca_proc_<name>_int64_t,
|
1303
|
+
ca_proc_<name>_uint64_t,
|
1304
|
+
ca_proc_<name>_float32_t,
|
1305
|
+
ca_proc_<name>_float64_t,
|
1306
|
+
ca_proc_<name>_float128_t,
|
1307
|
+
ca_proc_<name>_cmplx64_t,
|
1308
|
+
ca_proc_<name>_cmplx128_t,
|
1309
|
+
ca_proc_<name>_cmplx256_t,
|
1310
|
+
ca_proc_<name>_VALUE,
|
1311
|
+
};
|
1312
|
+
|
1313
|
+
HERE_END
|
1314
|
+
|
1315
|
+
puts macro_expand(text, "name" => "accum")
|
1316
|
+
|
1317
|
+
# --------------------------------------------------------------------------
|
1318
|
+
#
|
1319
|
+
# METHOD DEFINITIONS (after __END__)
|
1320
|
+
#
|
1321
|
+
# --------------------------------------------------------------------------
|
1322
|
+
|
1323
|
+
puts DATA.read
|
1324
|
+
|
1325
|
+
__END__
|
1326
|
+
|
1327
|
+
static VALUE
|
1328
|
+
rb_ca_stat_1d (VALUE self, VALUE rmc, VALUE vfval,
|
1329
|
+
ca_stat_proc_t *ca_proc)
|
1330
|
+
{
|
1331
|
+
volatile VALUE out;
|
1332
|
+
CArray *ca;
|
1333
|
+
CAStatIterator it;
|
1334
|
+
boolean8_t *m;
|
1335
|
+
int32_t mc;
|
1336
|
+
|
1337
|
+
Data_Get_Struct(self, CArray, ca);
|
1338
|
+
|
1339
|
+
if ( ! ca_proc[ca->data_type] ) {
|
1340
|
+
rb_raise(rb_eCADataTypeError,
|
1341
|
+
"this method is not implemented for data_type %s",
|
1342
|
+
ca_type_name[ca->data_type]);
|
1343
|
+
}
|
1344
|
+
|
1345
|
+
if ( ca->elements == 0 ) {
|
1346
|
+
out = CA_UNDEF;
|
1347
|
+
}
|
1348
|
+
else {
|
1349
|
+
ca_attach(ca);
|
1350
|
+
m = ( ca->mask ) ? (boolean8_t *)ca->mask->ptr : NULL;
|
1351
|
+
mc = ( ( ! ca_has_mask(ca) ) || NIL_P(rmc)) ? ca->elements - 1 : NUM2LONG(rmc);
|
1352
|
+
if ( mc < 0 ) {
|
1353
|
+
mc += ca->elements;
|
1354
|
+
}
|
1355
|
+
it.step = 0;
|
1356
|
+
ca_proc[ca->data_type](ca->elements, mc, m, ca->ptr, &it, 1, &out, NULL, NULL);
|
1357
|
+
ca_detach(ca);
|
1358
|
+
}
|
1359
|
+
|
1360
|
+
if ( out == CA_UNDEF && ( vfval != CA_NIL ) ) {
|
1361
|
+
out = vfval;
|
1362
|
+
}
|
1363
|
+
|
1364
|
+
return out;
|
1365
|
+
}
|
1366
|
+
|
1367
|
+
static void
|
1368
|
+
ca_stat_nd_contig_loop (CArray *ca, CArray *co, int32_t mc,
|
1369
|
+
ca_stat_proc_t *ca_proc,
|
1370
|
+
int level, int32_t *idx, char **op, boolean8_t **om)
|
1371
|
+
{
|
1372
|
+
void *p;
|
1373
|
+
boolean8_t *m;
|
1374
|
+
int32_t i, n;
|
1375
|
+
if ( level == co->rank ) {
|
1376
|
+
CAStatIterator it;
|
1377
|
+
n = ca->elements/co->elements;
|
1378
|
+
idx[level] = 0;
|
1379
|
+
p = ca_ptr_at_index(ca, idx);
|
1380
|
+
m = ( ca->mask && ca->mask->ptr ) ?
|
1381
|
+
(boolean8_t *)ca_ptr_at_index(ca->mask, idx) : NULL;
|
1382
|
+
it.step = 0;
|
1383
|
+
ca_proc[ca->data_type](n, mc, m, p, &it, 0, NULL, *om, *op);
|
1384
|
+
if ( *om ) {
|
1385
|
+
*om += 1;
|
1386
|
+
}
|
1387
|
+
*op += co->bytes;
|
1388
|
+
}
|
1389
|
+
else {
|
1390
|
+
for (i=0; i<ca->dim[level]; i++) {
|
1391
|
+
idx[level] = i;
|
1392
|
+
ca_stat_nd_contig_loop(ca, co, mc, ca_proc, level+1, idx, op, om);
|
1393
|
+
}
|
1394
|
+
}
|
1395
|
+
}
|
1396
|
+
|
1397
|
+
static VALUE
|
1398
|
+
rb_ca_stat_nd_contig (VALUE self, VALUE vaxis, VALUE rmc, VALUE vfval,
|
1399
|
+
int8_t data_type, ca_stat_proc_t *ca_proc)
|
1400
|
+
{
|
1401
|
+
volatile VALUE out;
|
1402
|
+
CArray *ca, *co;
|
1403
|
+
int32_t mc, ndim;
|
1404
|
+
|
1405
|
+
Data_Get_Struct(self, CArray, ca);
|
1406
|
+
|
1407
|
+
if ( ! ca_proc[ca->data_type] ) {
|
1408
|
+
rb_raise(rb_eCADataTypeError,
|
1409
|
+
"this method is not implemented for data_type %s",
|
1410
|
+
ca_type_name[ca->data_type]);
|
1411
|
+
}
|
1412
|
+
|
1413
|
+
ndim = ca->rank - RARRAY_LEN(vaxis);
|
1414
|
+
if ( ndim <= 0 || ndim > ca->rank ) {
|
1415
|
+
rb_raise(rb_eRuntimeError, "invalid dimension specified");
|
1416
|
+
}
|
1417
|
+
|
1418
|
+
out = rb_carray_new(data_type, ndim, ca->dim, 0, NULL);
|
1419
|
+
Data_Get_Struct(out, CArray, co);
|
1420
|
+
|
1421
|
+
if ( ca_has_mask(ca) ) {
|
1422
|
+
ca_create_mask(co);
|
1423
|
+
}
|
1424
|
+
|
1425
|
+
if ( NIL_P(rmc) ) {
|
1426
|
+
mc = ca->elements/co->elements - 1;
|
1427
|
+
}
|
1428
|
+
else {
|
1429
|
+
mc = NUM2LONG(rmc);
|
1430
|
+
}
|
1431
|
+
|
1432
|
+
if ( mc < 0 ) {
|
1433
|
+
mc += ca->elements;
|
1434
|
+
}
|
1435
|
+
|
1436
|
+
{
|
1437
|
+
int32_t idx[CA_RANK_MAX];
|
1438
|
+
char *op;
|
1439
|
+
boolean8_t *om;
|
1440
|
+
int32_t i;
|
1441
|
+
for (i=0; i<ca->rank; i++) {
|
1442
|
+
idx[i] = 0;
|
1443
|
+
}
|
1444
|
+
ca_attach_n(2, ca, co);
|
1445
|
+
op = co->ptr;
|
1446
|
+
om = ( co->mask && co->mask->ptr ) ? (boolean8_t *)co->mask->ptr : NULL;
|
1447
|
+
ca_stat_nd_contig_loop(ca, co, mc, ca_proc, 0, idx, &op, &om);
|
1448
|
+
ca_sync(co);
|
1449
|
+
ca_detach_n(2, ca, co);
|
1450
|
+
}
|
1451
|
+
|
1452
|
+
if ( ca_has_mask(co) && ( vfval != CA_NIL ) ) {
|
1453
|
+
out = rb_ca_mask_fill_copy(out, vfval);
|
1454
|
+
}
|
1455
|
+
|
1456
|
+
return out;
|
1457
|
+
}
|
1458
|
+
|
1459
|
+
static void
|
1460
|
+
ca_stat_get_offset_loop (CArray *ca, int32_t *dm,
|
1461
|
+
int level, int32_t *idx,
|
1462
|
+
int level1, int32_t *idx1,
|
1463
|
+
CArray *offset)
|
1464
|
+
{
|
1465
|
+
int32_t i;
|
1466
|
+
if ( level == ca->rank - 1 ) {
|
1467
|
+
if ( dm[level] == 0 ) {
|
1468
|
+
idx[level] = 0;
|
1469
|
+
*(int32_t *)ca_ptr_at_index(offset, idx1) = ca_index2addr(ca, idx);
|
1470
|
+
}
|
1471
|
+
else {
|
1472
|
+
for (i=0; i<ca->dim[level]; i++) {
|
1473
|
+
idx[level] = i;
|
1474
|
+
idx1[level1] = i;
|
1475
|
+
*(int32_t *)ca_ptr_at_index(offset, idx1) = ca_index2addr(ca, idx);
|
1476
|
+
}
|
1477
|
+
}
|
1478
|
+
}
|
1479
|
+
else {
|
1480
|
+
if ( dm[level] == 0 ) {
|
1481
|
+
idx[level] = 0;
|
1482
|
+
ca_stat_get_offset_loop(ca, dm, level+1, idx, level1, idx1, offset);
|
1483
|
+
}
|
1484
|
+
else {
|
1485
|
+
for (i=0; i<ca->dim[level]; i++) {
|
1486
|
+
idx[level] = i;
|
1487
|
+
idx1[level1] = i;
|
1488
|
+
ca_stat_get_offset_loop(ca, dm, level+1, idx, level1+1, idx1, offset);
|
1489
|
+
}
|
1490
|
+
}
|
1491
|
+
}
|
1492
|
+
}
|
1493
|
+
|
1494
|
+
static VALUE
|
1495
|
+
rb_ca_stat_nd_discrete (VALUE self, VALUE vaxis, VALUE rmc, VALUE vfval,
|
1496
|
+
int8_t data_type, ca_stat_proc_t *ca_proc)
|
1497
|
+
{
|
1498
|
+
volatile VALUE out;
|
1499
|
+
int32_t idx[CA_RANK_MAX];
|
1500
|
+
int32_t idx1[CA_RANK_MAX];
|
1501
|
+
int32_t out_dim[CA_RANK_MAX];
|
1502
|
+
int32_t loop_dim[CA_RANK_MAX];
|
1503
|
+
int32_t dm[CA_RANK_MAX], dn[CA_RANK_MAX];
|
1504
|
+
CArray *ca, *co, *first, *offset;
|
1505
|
+
int32_t out_rank, loop_rank;
|
1506
|
+
int32_t mc;
|
1507
|
+
int32_t i, k;
|
1508
|
+
|
1509
|
+
Data_Get_Struct(self, CArray, ca);
|
1510
|
+
|
1511
|
+
for (i=0; i<ca->rank; i++) {
|
1512
|
+
dm[i] = 0;
|
1513
|
+
dn[i] = 1;
|
1514
|
+
}
|
1515
|
+
|
1516
|
+
for (i=0; i<RARRAY_LEN(vaxis); i++) {
|
1517
|
+
k = NUM2INT(rb_ary_entry(vaxis, i));
|
1518
|
+
dm[k] = 1;
|
1519
|
+
dn[k] = 0;
|
1520
|
+
}
|
1521
|
+
|
1522
|
+
out_rank = 0;
|
1523
|
+
loop_rank = 0;
|
1524
|
+
for (i=0; i<ca->rank; i++) {
|
1525
|
+
if ( dm[i] ) {
|
1526
|
+
loop_dim[loop_rank] = ca->dim[i];
|
1527
|
+
loop_rank += 1;
|
1528
|
+
}
|
1529
|
+
else {
|
1530
|
+
out_dim[out_rank] = ca->dim[i];
|
1531
|
+
out_rank += 1;
|
1532
|
+
}
|
1533
|
+
}
|
1534
|
+
|
1535
|
+
out = rb_carray_new(data_type, out_rank, out_dim, 0, NULL);
|
1536
|
+
Data_Get_Struct(out, CArray, co);
|
1537
|
+
|
1538
|
+
first = carray_new(CA_INT32, out_rank, out_dim, 0, NULL);
|
1539
|
+
first->ptr = realloc(first->ptr, first->bytes*(first->elements+1));
|
1540
|
+
|
1541
|
+
offset = carray_new(CA_INT32, loop_rank, loop_dim, 0, NULL);
|
1542
|
+
offset->ptr = realloc(offset->ptr, offset->bytes*(offset->elements+1));
|
1543
|
+
|
1544
|
+
ca_stat_get_offset_loop(ca, dn, 0, idx, 0, idx1, first);
|
1545
|
+
ca_stat_get_offset_loop(ca, dm, 0, idx, 0, idx1, offset);
|
1546
|
+
|
1547
|
+
if ( ca_has_mask(ca) ) {
|
1548
|
+
ca_create_mask(co);
|
1549
|
+
}
|
1550
|
+
|
1551
|
+
if ( NIL_P(rmc) ) {
|
1552
|
+
mc = offset->elements - 1;
|
1553
|
+
}
|
1554
|
+
else {
|
1555
|
+
mc = NUM2LONG(rmc);
|
1556
|
+
}
|
1557
|
+
|
1558
|
+
if ( mc < 0 ) {
|
1559
|
+
mc += offset->elements;
|
1560
|
+
}
|
1561
|
+
|
1562
|
+
ca_attach_n(2, ca, co);
|
1563
|
+
|
1564
|
+
{
|
1565
|
+
CAStatIterator it, jt;
|
1566
|
+
int32_t *a = (int32_t *) (&it);
|
1567
|
+
boolean8_t *m0, *m, *om;
|
1568
|
+
char *p, *op;
|
1569
|
+
|
1570
|
+
it.step = 1;
|
1571
|
+
it.addr = (int32_t *)first->ptr;
|
1572
|
+
jt.step = 1;
|
1573
|
+
jt.addr = (int32_t *)offset->ptr;
|
1574
|
+
|
1575
|
+
m0 = ( ca->mask && ca->mask->ptr ) ? (boolean8_t *)ca->mask->ptr : NULL;
|
1576
|
+
om = ( co->mask && co->mask->ptr ) ? (boolean8_t *)co->mask->ptr : NULL;
|
1577
|
+
op = co->ptr;
|
1578
|
+
|
1579
|
+
iterator_rewind(&it);
|
1580
|
+
for (i=0; i<co->elements; i++) {
|
1581
|
+
m = ( m0 ) ? m0 + (*a) : NULL;
|
1582
|
+
p = ca->ptr + (*a) * ca->bytes;
|
1583
|
+
ca_proc[ca->data_type](offset->elements, mc, m, p, &jt, 0, NULL, om, op);
|
1584
|
+
if ( om ) {
|
1585
|
+
om += 1;
|
1586
|
+
}
|
1587
|
+
op += co->bytes;
|
1588
|
+
iterator_succ(&it);
|
1589
|
+
}
|
1590
|
+
}
|
1591
|
+
|
1592
|
+
ca_sync(co);
|
1593
|
+
ca_detach_n(2, ca, co);
|
1594
|
+
|
1595
|
+
if ( ca_has_mask(co) && ( vfval != CA_NIL ) ) {
|
1596
|
+
out = rb_ca_mask_fill_copy(out, vfval);
|
1597
|
+
}
|
1598
|
+
|
1599
|
+
ca_free(first);
|
1600
|
+
ca_free(offset);
|
1601
|
+
|
1602
|
+
return out;
|
1603
|
+
}
|
1604
|
+
|
1605
|
+
static VALUE
|
1606
|
+
rb_ca_stat_general (int argc, VALUE *argv, VALUE self,
|
1607
|
+
int8_t data_type, ca_stat_proc_t *ca_proc)
|
1608
|
+
{
|
1609
|
+
volatile VALUE ropt, rmc = Qnil, rmask_limit = Qnil, rmin_count = Qnil,
|
1610
|
+
vfval = CA_NIL, vaxis;
|
1611
|
+
CArray *ca;
|
1612
|
+
|
1613
|
+
Data_Get_Struct(self, CArray, ca);
|
1614
|
+
|
1615
|
+
ropt = rb_pop_options(&argc, &argv);
|
1616
|
+
rb_scan_options(ropt,
|
1617
|
+
"mask_limit,fill_value,min_count",
|
1618
|
+
&rmask_limit, &vfval, &rmin_count);
|
1619
|
+
|
1620
|
+
if ( ( ! NIL_P(rmask_limit) ) && ( ! NIL_P(rmin_count) ) ) {
|
1621
|
+
rb_raise(rb_eArgError,
|
1622
|
+
"don't specify mask_limit and min_count simaltaniously");
|
1623
|
+
}
|
1624
|
+
else if ( ! NIL_P(rmin_count) ) {
|
1625
|
+
int min_count = NUM2LONG(rmin_count);
|
1626
|
+
if ( min_count == 0 ) {
|
1627
|
+
rmc = Qnil;
|
1628
|
+
}
|
1629
|
+
else {
|
1630
|
+
rmc = LONG2NUM(-min_count);
|
1631
|
+
}
|
1632
|
+
}
|
1633
|
+
else if ( ! NIL_P(rmask_limit) ) {
|
1634
|
+
int mask_limit = NUM2LONG(rmask_limit);
|
1635
|
+
if ( mask_limit == 0 ) {
|
1636
|
+
rmc = Qnil;
|
1637
|
+
}
|
1638
|
+
else {
|
1639
|
+
rmc = LONG2NUM(mask_limit-1);
|
1640
|
+
}
|
1641
|
+
}
|
1642
|
+
else {
|
1643
|
+
rmc = Qnil;
|
1644
|
+
}
|
1645
|
+
|
1646
|
+
if ( argc > 0 ) {
|
1647
|
+
vaxis = rb_ary_new4(argc, argv);
|
1648
|
+
}
|
1649
|
+
else {
|
1650
|
+
vaxis = Qnil;
|
1651
|
+
}
|
1652
|
+
|
1653
|
+
if ( NIL_P(vaxis) ) {
|
1654
|
+
return rb_ca_stat_1d(self, rmc, vfval, ca_proc);
|
1655
|
+
}
|
1656
|
+
else {
|
1657
|
+
int is_contig = 1;
|
1658
|
+
int i, k;
|
1659
|
+
|
1660
|
+
vaxis = rb_funcall(vaxis, rb_intern("sort"), 0);
|
1661
|
+
vaxis = rb_funcall(vaxis, rb_intern("uniq"), 0);
|
1662
|
+
|
1663
|
+
for (i=0; i<RARRAY_LEN(vaxis); i++) {
|
1664
|
+
k = NUM2INT(rb_ary_entry(vaxis, RARRAY_LEN(vaxis)-1-i));
|
1665
|
+
CA_CHECK_INDEX(k, ca->rank);
|
1666
|
+
if ( k != ca->rank-1-i ) {
|
1667
|
+
is_contig = 0;
|
1668
|
+
}
|
1669
|
+
}
|
1670
|
+
|
1671
|
+
if ( is_contig ) {
|
1672
|
+
if ( RARRAY_LEN(vaxis) == ca->rank ) {
|
1673
|
+
return rb_ca_stat_1d(self, rmc, vfval, ca_proc);
|
1674
|
+
}
|
1675
|
+
else {
|
1676
|
+
return rb_ca_stat_nd_contig(self, vaxis, rmc, vfval,
|
1677
|
+
data_type, ca_proc);
|
1678
|
+
}
|
1679
|
+
}
|
1680
|
+
else {
|
1681
|
+
return rb_ca_stat_nd_discrete(self, vaxis, rmc, vfval,
|
1682
|
+
data_type, ca_proc);
|
1683
|
+
}
|
1684
|
+
}
|
1685
|
+
}
|
1686
|
+
|
1687
|
+
|
1688
|
+
static VALUE
|
1689
|
+
rb_ca_prod (int argc, VALUE *argv, VALUE self)
|
1690
|
+
{
|
1691
|
+
return rb_ca_stat_general(argc, argv, self, CA_FLOAT64, ca_proc_prod);
|
1692
|
+
}
|
1693
|
+
|
1694
|
+
static VALUE
|
1695
|
+
rb_ca_count (int argc, VALUE *argv, VALUE self)
|
1696
|
+
{
|
1697
|
+
return rb_ca_stat_general(argc, argv, self, CA_INT32, ca_proc_count);
|
1698
|
+
}
|
1699
|
+
|
1700
|
+
static VALUE
|
1701
|
+
rb_ca_sum (int argc, VALUE *argv, VALUE self)
|
1702
|
+
{
|
1703
|
+
return rb_ca_stat_general(argc, argv, self, CA_FLOAT64, ca_proc_sum);
|
1704
|
+
}
|
1705
|
+
|
1706
|
+
static VALUE
|
1707
|
+
rb_ca_mean (int argc, VALUE *argv, VALUE self)
|
1708
|
+
{
|
1709
|
+
return rb_ca_stat_general(argc, argv, self, CA_FLOAT64, ca_proc_mean);
|
1710
|
+
}
|
1711
|
+
|
1712
|
+
static VALUE
|
1713
|
+
rb_ca_variancep (int argc, VALUE *argv, VALUE self)
|
1714
|
+
{
|
1715
|
+
return rb_ca_stat_general(argc, argv, self, CA_FLOAT64, ca_proc_variancep);
|
1716
|
+
}
|
1717
|
+
|
1718
|
+
static VALUE
|
1719
|
+
rb_ca_stddevp (int argc, VALUE *argv, VALUE self)
|
1720
|
+
{
|
1721
|
+
return rb_ca_stat_general(argc, argv, self, CA_FLOAT64, ca_proc_stddevp);
|
1722
|
+
}
|
1723
|
+
|
1724
|
+
static VALUE
|
1725
|
+
rb_ca_variance (int argc, VALUE *argv, VALUE self)
|
1726
|
+
{
|
1727
|
+
return rb_ca_stat_general(argc, argv, self, CA_FLOAT64, ca_proc_variance);
|
1728
|
+
}
|
1729
|
+
|
1730
|
+
static VALUE
|
1731
|
+
rb_ca_stddev (int argc, VALUE *argv, VALUE self)
|
1732
|
+
{
|
1733
|
+
return rb_ca_stat_general(argc, argv, self, CA_FLOAT64, ca_proc_stddev);
|
1734
|
+
}
|
1735
|
+
|
1736
|
+
static VALUE
|
1737
|
+
rb_ca_min (int argc, VALUE *argv, VALUE self)
|
1738
|
+
{
|
1739
|
+
CArray *ca;
|
1740
|
+
Data_Get_Struct(self, CArray, ca);
|
1741
|
+
return rb_ca_stat_general(argc, argv, self, ca->data_type, ca_proc_min);
|
1742
|
+
}
|
1743
|
+
|
1744
|
+
static VALUE
|
1745
|
+
rb_ca_min_addr (int argc, VALUE *argv, VALUE self)
|
1746
|
+
{
|
1747
|
+
return rb_ca_stat_general(argc, argv, self, CA_INT32, ca_proc_min_addr);
|
1748
|
+
}
|
1749
|
+
|
1750
|
+
static VALUE
|
1751
|
+
rb_ca_max (int argc, VALUE *argv, VALUE self)
|
1752
|
+
{
|
1753
|
+
CArray *ca;
|
1754
|
+
Data_Get_Struct(self, CArray, ca);
|
1755
|
+
return rb_ca_stat_general(argc, argv, self, ca->data_type, ca_proc_max);
|
1756
|
+
}
|
1757
|
+
|
1758
|
+
static VALUE
|
1759
|
+
rb_ca_max_addr (int argc, VALUE *argv, VALUE self)
|
1760
|
+
{
|
1761
|
+
return rb_ca_stat_general(argc, argv, self, CA_INT32, ca_proc_max_addr);
|
1762
|
+
}
|
1763
|
+
|
1764
|
+
static VALUE
|
1765
|
+
rb_ca_accum (int argc, VALUE *argv, VALUE self)
|
1766
|
+
{
|
1767
|
+
CArray *ca;
|
1768
|
+
Data_Get_Struct(self, CArray, ca);
|
1769
|
+
return rb_ca_stat_general(argc, argv, self, ca->data_type, ca_proc_accum);
|
1770
|
+
}
|
1771
|
+
|
1772
|
+
static VALUE
|
1773
|
+
rb_ca_stat_type2 (int argc, VALUE *argv, VALUE self,
|
1774
|
+
int8_t data_type, ca_stat_proc_t *ca_proc)
|
1775
|
+
{
|
1776
|
+
VALUE out, rmc, rfval;
|
1777
|
+
CArray *ca, *co;
|
1778
|
+
int32_t mc;
|
1779
|
+
|
1780
|
+
rb_scan_args(argc, argv, "02", &rmc, &rfval);
|
1781
|
+
|
1782
|
+
Data_Get_Struct(self, CArray, ca);
|
1783
|
+
|
1784
|
+
if ( ! ca_proc[ca->data_type] ) {
|
1785
|
+
rb_raise(rb_eCADataTypeError,
|
1786
|
+
"this method is not implemented for data_type %s",
|
1787
|
+
ca_type_name[ca->data_type]);
|
1788
|
+
}
|
1789
|
+
|
1790
|
+
out = rb_carray_new(data_type, 1, &ca->elements, 0, NULL);
|
1791
|
+
Data_Get_Struct(out, CArray, co);
|
1792
|
+
|
1793
|
+
if ( ca->elements == 0 ) {
|
1794
|
+
;
|
1795
|
+
}
|
1796
|
+
else {
|
1797
|
+
CAStatIterator it;
|
1798
|
+
boolean8_t *m = NULL;
|
1799
|
+
boolean8_t *om = NULL;
|
1800
|
+
ca_attach(ca);
|
1801
|
+
if ( ca->mask ) {
|
1802
|
+
m = (boolean8_t *)ca->mask->ptr;
|
1803
|
+
}
|
1804
|
+
mc = ( (! ca->mask) || NIL_P(rmc) ) ? ca->elements - 1 : NUM2LONG(rmc);
|
1805
|
+
if ( mc < 0 ) {
|
1806
|
+
mc += ca->elements;
|
1807
|
+
}
|
1808
|
+
if ( m ) {
|
1809
|
+
ca_create_mask(co);
|
1810
|
+
om = (boolean8_t *) co->mask->ptr;
|
1811
|
+
}
|
1812
|
+
it.step = 0;
|
1813
|
+
ca_proc[ca->data_type](ca->elements, mc, m, ca->ptr, &it,
|
1814
|
+
om, co->ptr);
|
1815
|
+
ca_detach(ca);
|
1816
|
+
}
|
1817
|
+
|
1818
|
+
if ( ca_has_mask(co) && ( ! NIL_P(rfval) ) ) {
|
1819
|
+
out = rb_ca_mask_fill_copy(out, rfval);
|
1820
|
+
}
|
1821
|
+
|
1822
|
+
return out;
|
1823
|
+
}
|
1824
|
+
|
1825
|
+
static void
|
1826
|
+
ca_dimstat_type2_loop (CArray *ca, CArray *co, int32_t mc,
|
1827
|
+
ca_stat_proc_t *ca_proc,
|
1828
|
+
int level, int32_t *idx, char **op, boolean8_t **om)
|
1829
|
+
{
|
1830
|
+
void *p;
|
1831
|
+
boolean8_t *m;
|
1832
|
+
int32_t i, n;
|
1833
|
+
if ( level == co->rank ) {
|
1834
|
+
CAStatIterator it;
|
1835
|
+
n = ca->elements/co->elements;
|
1836
|
+
idx[level] = 0;
|
1837
|
+
p = ca_ptr_at_index(ca, idx);
|
1838
|
+
m = ( ca->mask && ca->mask->ptr ) ?
|
1839
|
+
(boolean8_t *)ca_ptr_at_index(ca->mask, idx) : NULL;
|
1840
|
+
it.step = 0;
|
1841
|
+
ca_proc[ca->data_type](n, mc, m, p, &it, 0, NULL, *om, *op);
|
1842
|
+
printf("world\n");
|
1843
|
+
if ( *om ) {
|
1844
|
+
*om += n;
|
1845
|
+
}
|
1846
|
+
*op += n*co->bytes;
|
1847
|
+
}
|
1848
|
+
else {
|
1849
|
+
for (i=0; i<ca->dim[level]; i++) {
|
1850
|
+
idx[level] = i;
|
1851
|
+
ca_dimstat_type2_loop(ca, co, mc, ca_proc, level+1, idx, op, om);
|
1852
|
+
}
|
1853
|
+
}
|
1854
|
+
}
|
1855
|
+
|
1856
|
+
static void
|
1857
|
+
ca_dimstat_type2 (CArray *ca, CArray *co, int32_t mc, ca_stat_proc_t *ca_proc)
|
1858
|
+
{
|
1859
|
+
int32_t idx[CA_RANK_MAX];
|
1860
|
+
char *op;
|
1861
|
+
boolean8_t *om;
|
1862
|
+
int32_t i;
|
1863
|
+
for (i=0; i<ca->rank; i++) {
|
1864
|
+
idx[i] = 0;
|
1865
|
+
}
|
1866
|
+
ca_attach_n(2, ca, co);
|
1867
|
+
op = co->ptr;
|
1868
|
+
om = ( co->mask && co->mask->ptr ) ? (boolean8_t *)co->mask->ptr : NULL;
|
1869
|
+
ca_dimstat_type2_loop(ca, co, mc, ca_proc, 0, idx, &op, &om);
|
1870
|
+
ca_sync(co);
|
1871
|
+
ca_detach_n(2, ca, co);
|
1872
|
+
}
|
1873
|
+
|
1874
|
+
static VALUE
|
1875
|
+
rb_ca_dimstat_type2 (int argc, VALUE *argv, VALUE self,
|
1876
|
+
int8_t data_type, ca_stat_proc_t *ca_proc)
|
1877
|
+
{
|
1878
|
+
volatile VALUE rndim, rmc, rfval;
|
1879
|
+
volatile VALUE out;
|
1880
|
+
CArray *ca, *co;
|
1881
|
+
int32_t odim[CA_RANK_MAX], n;
|
1882
|
+
int32_t mc, ndim;
|
1883
|
+
int32_t i;
|
1884
|
+
|
1885
|
+
rb_scan_args(argc, argv, "12", &rndim, &rmc, &rfval);
|
1886
|
+
|
1887
|
+
Data_Get_Struct(self, CArray, ca);
|
1888
|
+
|
1889
|
+
if ( ! ca_proc[ca->data_type] ) {
|
1890
|
+
rb_raise(rb_eCADataTypeError,
|
1891
|
+
"this method is not implemented for data_type %s",
|
1892
|
+
ca_type_name[ca->data_type]);
|
1893
|
+
}
|
1894
|
+
|
1895
|
+
ndim = NUM2INT(rndim);
|
1896
|
+
if ( ndim <= 0 || ndim > ca->rank ) {
|
1897
|
+
rb_raise(rb_eRuntimeError, "invalid dimension specified");
|
1898
|
+
}
|
1899
|
+
|
1900
|
+
n = 1;
|
1901
|
+
for (i=0; i<ndim; i++) {
|
1902
|
+
odim[i] = ca->dim[i];
|
1903
|
+
n *= odim[i];
|
1904
|
+
}
|
1905
|
+
odim[ndim] = ca->elements/n;
|
1906
|
+
|
1907
|
+
out = rb_carray_new(data_type, ndim+1, odim, 0, NULL);
|
1908
|
+
Data_Get_Struct(out, CArray, co);
|
1909
|
+
|
1910
|
+
if ( ca_has_mask(ca) ) {
|
1911
|
+
ca_create_mask(co);
|
1912
|
+
}
|
1913
|
+
|
1914
|
+
if ( NIL_P(rmc) ) {
|
1915
|
+
mc = ca->elements/co->elements - 1;
|
1916
|
+
}
|
1917
|
+
else {
|
1918
|
+
mc = NUM2LONG(rmc);
|
1919
|
+
}
|
1920
|
+
|
1921
|
+
if ( mc < 0 ) {
|
1922
|
+
mc += ca->elements;
|
1923
|
+
}
|
1924
|
+
|
1925
|
+
ca_dimstat_type2(ca, co, mc, ca_proc);
|
1926
|
+
|
1927
|
+
if ( ca_has_mask(co) && ( ! NIL_P(rfval) ) ) {
|
1928
|
+
out = rb_ca_mask_fill_copy(out, rfval);
|
1929
|
+
}
|
1930
|
+
|
1931
|
+
return out;
|
1932
|
+
}
|
1933
|
+
|
1934
|
+
static VALUE
|
1935
|
+
rb_ca_cumcount (int argc, VALUE *argv, VALUE self)
|
1936
|
+
{
|
1937
|
+
return rb_ca_stat_type2(argc, argv, self, CA_INT32, ca_proc_cumcount);
|
1938
|
+
}
|
1939
|
+
|
1940
|
+
static VALUE
|
1941
|
+
rb_ca_dimcumcount (int argc, VALUE *argv, VALUE self)
|
1942
|
+
{
|
1943
|
+
return rb_ca_dimstat_type2(argc, argv, self, CA_INT32, ca_proc_cumcount);
|
1944
|
+
}
|
1945
|
+
|
1946
|
+
static VALUE
|
1947
|
+
rb_ca_cumsum (int argc, VALUE *argv, VALUE self)
|
1948
|
+
{
|
1949
|
+
return rb_ca_stat_type2(argc, argv, self, CA_FLOAT64, ca_proc_cumsum);
|
1950
|
+
}
|
1951
|
+
|
1952
|
+
static VALUE
|
1953
|
+
rb_ca_dimcumsum (int argc, VALUE *argv, VALUE self)
|
1954
|
+
{
|
1955
|
+
return rb_ca_dimstat_type2(argc, argv, self, CA_FLOAT64, ca_proc_cumsum);
|
1956
|
+
}
|
1957
|
+
|
1958
|
+
void
|
1959
|
+
Init_carray_stat_proc ()
|
1960
|
+
{
|
1961
|
+
id_lt = rb_intern("<");
|
1962
|
+
id_gt = rb_intern(">");
|
1963
|
+
id_plus = rb_intern("+");
|
1964
|
+
id_minus = rb_intern("-");
|
1965
|
+
id_star = rb_intern("*");
|
1966
|
+
id_quo = rb_intern("quo");
|
1967
|
+
|
1968
|
+
rb_define_method(rb_cCArray, "prod", rb_ca_prod, -1);
|
1969
|
+
rb_define_method(rb_cCArray, "count_valid", rb_ca_count, -1);
|
1970
|
+
rb_define_method(rb_cCArray, "sum", rb_ca_sum, -1);
|
1971
|
+
rb_define_method(rb_cCArray, "mean", rb_ca_mean, -1);
|
1972
|
+
rb_define_method(rb_cCArray, "variancep", rb_ca_variancep, -1);
|
1973
|
+
rb_define_method(rb_cCArray, "stddevp", rb_ca_stddevp, -1);
|
1974
|
+
rb_define_method(rb_cCArray, "variance", rb_ca_variance, -1);
|
1975
|
+
rb_define_method(rb_cCArray, "stddev", rb_ca_stddev, -1);
|
1976
|
+
rb_define_method(rb_cCArray, "min", rb_ca_min, -1);
|
1977
|
+
rb_define_method(rb_cCArray, "max", rb_ca_max, -1);
|
1978
|
+
rb_define_method(rb_cCArray, "min_addr", rb_ca_min_addr, -1);
|
1979
|
+
rb_define_method(rb_cCArray, "max_addr", rb_ca_max_addr, -1);
|
1980
|
+
|
1981
|
+
rb_define_method(rb_cCArray, "accumulate", rb_ca_accum, -1);
|
1982
|
+
|
1983
|
+
rb_define_method(rb_cCArray, "cumcount", rb_ca_cumcount, -1);
|
1984
|
+
rb_define_method(rb_cCArray, "dimcumcount", rb_ca_dimcumcount, -1);
|
1985
|
+
rb_define_method(rb_cCArray, "cumsum", rb_ca_cumsum, -1);
|
1986
|
+
rb_define_method(rb_cCArray, "dimcumsum", rb_ca_dimcumsum, -1);
|
1987
|
+
}
|
1988
|
+
|
1989
|
+
|
1990
|
+
|