carray 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (231) hide show
  1. checksums.yaml +4 -4
  2. data/COPYING +56 -0
  3. data/GPL +340 -0
  4. data/Gemfile +9 -0
  5. data/Gemfile.lock +33 -0
  6. data/LEGAL +50 -0
  7. data/NOTE +73 -0
  8. data/Rakefile +20 -0
  9. data/TODO +5 -0
  10. data/ca_iter_block.c +242 -0
  11. data/ca_iter_dimension.c +287 -0
  12. data/ca_iter_window.c +202 -0
  13. data/ca_obj_array.c +1189 -0
  14. data/ca_obj_bitarray.c +523 -0
  15. data/ca_obj_bitfield.c +636 -0
  16. data/ca_obj_block.c +885 -0
  17. data/ca_obj_fake.c +405 -0
  18. data/ca_obj_farray.c +482 -0
  19. data/ca_obj_field.c +625 -0
  20. data/ca_obj_grid.c +738 -0
  21. data/ca_obj_mapping.c +614 -0
  22. data/ca_obj_object.c +777 -0
  23. data/ca_obj_reduce.c +299 -0
  24. data/ca_obj_refer.c +627 -0
  25. data/ca_obj_repeat.c +640 -0
  26. data/ca_obj_select.c +558 -0
  27. data/ca_obj_shift.c +952 -0
  28. data/ca_obj_transpose.c +582 -0
  29. data/ca_obj_unbound_repeat.c +557 -0
  30. data/ca_obj_window.c +1023 -0
  31. data/carray.h +1381 -0
  32. data/carray_access.c +1798 -0
  33. data/carray_attribute.c +903 -0
  34. data/carray_call_cfunc.c +1107 -0
  35. data/carray_cast.c +1155 -0
  36. data/carray_cast_func.rb +498 -0
  37. data/carray_class.c +132 -0
  38. data/carray_conversion.c +518 -0
  39. data/carray_copy.c +453 -0
  40. data/carray_core.c +1307 -0
  41. data/carray_element.c +572 -0
  42. data/carray_generate.c +681 -0
  43. data/carray_iterator.c +630 -0
  44. data/carray_loop.c +462 -0
  45. data/carray_mask.c +1174 -0
  46. data/carray_math.rb +834 -0
  47. data/carray_numeric.c +257 -0
  48. data/carray_operator.c +582 -0
  49. data/carray_order.c +1040 -0
  50. data/carray_random.c +529 -0
  51. data/carray_sort_addr.c +261 -0
  52. data/carray_stat.c +2102 -0
  53. data/carray_stat_proc.rb +1990 -0
  54. data/carray_test.c +602 -0
  55. data/carray_undef.c +69 -0
  56. data/carray_utils.c +740 -0
  57. data/ext/calculus/carray_calculus.c +792 -0
  58. data/ext/calculus/carray_interp.c +355 -0
  59. data/ext/calculus/extconf.rb +12 -0
  60. data/ext/calculus/lib/autoload/autoload_math_calculus.rb +2 -0
  61. data/ext/calculus/lib/math/calculus.rb +119 -0
  62. data/ext/calculus/lib/math/interp/adapter_interp1d.rb +31 -0
  63. data/ext/dataframe/API.txt +11 -0
  64. data/ext/dataframe/extconf.rb +3 -0
  65. data/ext/dataframe/lib/carray/autoload/autoload_dataframe_dataframe.rb +14 -0
  66. data/ext/dataframe/lib/carray/dataframe/dataframe.rb +1104 -0
  67. data/ext/dataframe/sample/test_uniq_sort.rb +5 -0
  68. data/ext/fortio/extconf.rb +3 -0
  69. data/ext/fortio/lib/carray/autoload/autoload_fortran_format.rb +5 -0
  70. data/ext/fortio/lib/carray/io/fortran_format.rb +43 -0
  71. data/ext/fortio/lib/fortio.rb +3 -0
  72. data/ext/fortio/lib/fortio/fortran_format.rb +603 -0
  73. data/ext/fortio/lib/fortio/fortran_format.tab.rb +536 -0
  74. data/ext/fortio/lib/fortio/fortran_format.y +215 -0
  75. data/ext/fortio/lib/fortio/fortran_namelist.rb +151 -0
  76. data/ext/fortio/lib/fortio/fortran_namelist.tab.rb +470 -0
  77. data/ext/fortio/lib/fortio/fortran_namelist.y +213 -0
  78. data/ext/fortio/lib/fortio/fortran_sequential.rb +345 -0
  79. data/ext/fortio/ruby_fortio.c +182 -0
  80. data/ext/fortio/test/test_H.rb +5 -0
  81. data/ext/fortio/test/test_T.rb +7 -0
  82. data/ext/fortio/test/test_fortran_format.rb +86 -0
  83. data/ext/fortio/test/test_namelist.rb +25 -0
  84. data/ext/fortio/test/test_sequential.rb +13 -0
  85. data/ext/fortio/test/test_sequential2.rb +13 -0
  86. data/ext/fortio/work/test.rb +10 -0
  87. data/ext/fortio/work/test_e.rb +19 -0
  88. data/ext/fortio/work/test_ep.rb +10 -0
  89. data/ext/fortio/work/test_parse.rb +12 -0
  90. data/ext/imagemap/carray_imagemap.c +495 -0
  91. data/ext/imagemap/doc/call_graph.dot +28 -0
  92. data/ext/imagemap/draw.c +567 -0
  93. data/ext/imagemap/extconf.rb +13 -0
  94. data/ext/imagemap/lib/autoload/autoload_graphics_imagemap.rb +1 -0
  95. data/ext/imagemap/lib/graphics/imagemap.rb +273 -0
  96. data/ext/imagemap/lib/image_map.rb +4 -0
  97. data/ext/imagemap/test/swath_index.rb +83 -0
  98. data/ext/imagemap/test/swath_warp.rb +99 -0
  99. data/ext/imagemap/test/test.rb +23 -0
  100. data/ext/imagemap/test/test_image.rb +42 -0
  101. data/ext/imagemap/test/test_line.rb +14 -0
  102. data/ext/imagemap/test/test_rotate.rb +17 -0
  103. data/ext/imagemap/test/test_triangle.rb +20 -0
  104. data/ext/imagemap/test/test_warp.rb +26 -0
  105. data/ext/mathfunc/carray_mathfunc.c +321 -0
  106. data/ext/mathfunc/extconf.rb +18 -0
  107. data/ext/mathfunc/lib/autoload/autoload_math_mathfunc.rb +1 -0
  108. data/ext/mathfunc/lib/math/mathfunc.rb +15 -0
  109. data/ext/mathfunc/test/test_hypot.rb +5 -0
  110. data/ext/mathfunc/test/test_j0.rb +22 -0
  111. data/ext/mathfunc/test/test_jn.rb +8 -0
  112. data/ext/mathfunc/test/test_sph.rb +9 -0
  113. data/ext/narray/README +22 -0
  114. data/ext/narray/ca_wrap_narray.c +491 -0
  115. data/ext/narray/carray_narray.c +21 -0
  116. data/ext/narray/extconf.rb +57 -0
  117. data/ext/narray/lib/autoload/autoload_math_narray.rb +1 -0
  118. data/ext/narray/lib/autoload/autoload_math_narray_miss.rb +11 -0
  119. data/ext/narray/lib/math/narray.rb +17 -0
  120. data/ext/narray/lib/math/narray_miss.rb +45 -0
  121. data/extconf.rb +3 -25
  122. data/lib/carray.rb +28 -0
  123. data/lib/carray/autoload/autoload_base.rb +23 -0
  124. data/lib/carray/autoload/autoload_graphics_gnuplot.rb +2 -0
  125. data/lib/carray/autoload/autoload_io_csv.rb +14 -0
  126. data/lib/carray/autoload/autoload_io_excel.rb +5 -0
  127. data/lib/carray/autoload/autoload_io_imagemagick.rb +6 -0
  128. data/lib/carray/autoload/autoload_io_pg.rb +6 -0
  129. data/lib/carray/autoload/autoload_io_sqlite3.rb +12 -0
  130. data/lib/carray/autoload/autoload_io_table.rb +1 -0
  131. data/lib/carray/autoload/autoload_math_histogram.rb +5 -0
  132. data/lib/carray/autoload/autoload_math_interp.rb +4 -0
  133. data/lib/carray/autoload/autoload_math_recurrence.rb +6 -0
  134. data/lib/carray/autoload/autoload_object_iterator.rb +1 -0
  135. data/lib/carray/autoload/autoload_object_link.rb +1 -0
  136. data/lib/carray/autoload/autoload_object_pack.rb +2 -0
  137. data/lib/carray/base/autoload.rb +94 -0
  138. data/lib/carray/base/basic.rb +1051 -0
  139. data/lib/carray/base/inspect.rb +252 -0
  140. data/lib/carray/base/iterator.rb +367 -0
  141. data/lib/carray/base/math.rb +403 -0
  142. data/lib/carray/base/obsolete.rb +93 -0
  143. data/lib/carray/base/serialize.rb +260 -0
  144. data/lib/carray/base/struct.rb +634 -0
  145. data/lib/carray/graphics/gnuplot.rb +2116 -0
  146. data/lib/carray/info.rb +112 -0
  147. data/lib/carray/io/csv.rb +560 -0
  148. data/lib/carray/io/excel.rb +26 -0
  149. data/lib/carray/io/imagemagick.rb +231 -0
  150. data/lib/carray/io/pg.rb +101 -0
  151. data/lib/carray/io/sqlite3.rb +202 -0
  152. data/lib/carray/io/table.rb +77 -0
  153. data/lib/carray/math/histogram.rb +179 -0
  154. data/lib/carray/math/interp.rb +57 -0
  155. data/lib/carray/math/interp/adapter_gsl_spline.rb +47 -0
  156. data/lib/carray/math/recurrence.rb +95 -0
  157. data/lib/carray/mkmf.rb +145 -0
  158. data/lib/carray/object/ca_obj_iterator.rb +52 -0
  159. data/lib/carray/object/ca_obj_link.rb +52 -0
  160. data/lib/carray/object/ca_obj_pack.rb +101 -0
  161. data/mkmath.rb +731 -0
  162. data/mt19937ar.c +182 -0
  163. data/mt19937ar.h +86 -0
  164. data/rdoc_main.rb +27 -0
  165. data/rdoc_math.rb +5 -0
  166. data/rdoc_stat.rb +31 -0
  167. data/ruby_carray.c +242 -0
  168. data/ruby_ccomplex.c +497 -0
  169. data/ruby_float_func.c +83 -0
  170. data/spec/CABlockIterator/CABlockIterator_spec.rb +113 -0
  171. data/spec/CArray/bug/store_spec.rb +27 -0
  172. data/spec/CArray/index/repeat_spec.rb +10 -0
  173. data/spec/CArray/method/eq_spec.rb +80 -0
  174. data/spec/CArray/method/is_nan_spec.rb +12 -0
  175. data/spec/CArray/method/ne_spec.rb +18 -0
  176. data/spec/CArray/method/round_spec.rb +11 -0
  177. data/spec/CArray/object/_attribute_spec.rb +32 -0
  178. data/spec/CArray/object/s_new_spec.rb +31 -0
  179. data/spec/CArray/serialize/Serialization_spec.rb +89 -0
  180. data/spec/spec_all.rb +11 -0
  181. data/test/test_ALL.rb +50 -0
  182. data/test/test_CABitfield.rb +59 -0
  183. data/test/test_CABlock.rb +208 -0
  184. data/test/test_CAField.rb +40 -0
  185. data/test/test_CAGrid.rb +76 -0
  186. data/test/test_CAMapping.rb +106 -0
  187. data/test/test_CAMmap.rb +11 -0
  188. data/test/test_CARefer.rb +94 -0
  189. data/test/test_CARepeat.rb +66 -0
  190. data/test/test_CASelect.rb +23 -0
  191. data/test/test_CAShift.rb +17 -0
  192. data/test/test_CATranspose.rb +61 -0
  193. data/test/test_CAVirtual.rb +214 -0
  194. data/test/test_CAWindow.rb +55 -0
  195. data/test/test_CAWrap.rb +9 -0
  196. data/test/test_CArray.rb +228 -0
  197. data/test/test_CComplex.rb +83 -0
  198. data/test/test_CScalar.rb +91 -0
  199. data/test/test_attribute.rb +281 -0
  200. data/test/test_block_iterator.rb +17 -0
  201. data/test/test_boolean.rb +99 -0
  202. data/test/test_cast.rb +33 -0
  203. data/test/test_class.rb +85 -0
  204. data/test/test_complex.rb +43 -0
  205. data/test/test_composite.rb +125 -0
  206. data/test/test_convert.rb +79 -0
  207. data/test/test_copy.rb +141 -0
  208. data/test/test_creation.rb +85 -0
  209. data/test/test_element.rb +146 -0
  210. data/test/test_extream.rb +55 -0
  211. data/test/test_generate.rb +75 -0
  212. data/test/test_index.rb +71 -0
  213. data/test/test_mask.rb +578 -0
  214. data/test/test_math.rb +98 -0
  215. data/test/test_narray.rb +64 -0
  216. data/test/test_order.rb +147 -0
  217. data/test/test_random.rb +15 -0
  218. data/test/test_ref_store.rb +211 -0
  219. data/test/test_stat.rb +414 -0
  220. data/test/test_struct.rb +72 -0
  221. data/test/test_virtual.rb +49 -0
  222. data/utils/ca_ase.rb +21 -0
  223. data/utils/ca_methods.rb +15 -0
  224. data/utils/cast_checker.rb +30 -0
  225. data/utils/create_rdoc.sh +9 -0
  226. data/utils/diff_method.rb +52 -0
  227. data/utils/extract_rdoc.rb +27 -0
  228. data/utils/make_tgz.sh +3 -0
  229. data/utils/remove_resource_fork.sh +5 -0
  230. data/version.h +3 -3
  231. metadata +266 -1
@@ -0,0 +1,572 @@
1
+ /* ---------------------------------------------------------------------------
2
+
3
+ carray_element.c
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
+ #include "ruby.h"
14
+ #include "carray.h"
15
+
16
+ /* ------------------------------------------------------------------- */
17
+
18
+ /* rdoc:
19
+ class CArray
20
+ def elem_swap
21
+ end
22
+ end
23
+ */
24
+
25
+ VALUE
26
+ rb_ca_elem_swap (VALUE self, VALUE ridx1, VALUE ridx2)
27
+ {
28
+ CArray *ca;
29
+ int32_t idx1[CA_RANK_MAX], idx2[CA_RANK_MAX];
30
+ int32_t addr1 = 0, addr2 = 0;
31
+ int32_t i,k;
32
+ int has_mask, has_index1, has_index2;
33
+ char _val1[32], _val2[32];
34
+ char *val1 = _val1, *val2 = _val2;
35
+ boolean8_t m1 = 0, m2 = 0;
36
+
37
+ rb_ca_modify(self);
38
+
39
+ Data_Get_Struct(self, CArray, ca);
40
+
41
+ ca_update_mask(ca);
42
+ has_mask = ( ca->mask ) ? 1 : 0;
43
+
44
+ if ( ca->bytes > 32 ) {
45
+ val1 = malloc_with_check(ca->bytes);
46
+ val2 = malloc_with_check(ca->bytes);
47
+ }
48
+
49
+ if ( TYPE(ridx1) == T_ARRAY ) {
50
+ for (i=0; i<ca->rank; i++) {
51
+ k = NUM2INT(rb_ary_entry(ridx1, i));
52
+ CA_CHECK_INDEX(k, ca->dim[i]);
53
+ idx1[i] = k;
54
+ }
55
+ has_index1 = 1;
56
+ ca_fetch_index(ca, idx1, val1);
57
+ if ( has_mask ) {
58
+ ca_fetch_index(ca->mask, idx1, &m1);
59
+ }
60
+ }
61
+ else {
62
+ k = NUM2INT(ridx1);
63
+ CA_CHECK_INDEX(k, ca->elements);
64
+ addr1 = k;
65
+ has_index1 = 0;
66
+ ca_fetch_addr(ca, addr1, val1);
67
+ if ( has_mask ) {
68
+ ca_fetch_addr(ca->mask, addr1, &m1);
69
+ }
70
+ }
71
+
72
+ if ( TYPE(ridx2) == T_ARRAY ) {
73
+ for (i=0; i<ca->rank; i++) {
74
+ k = NUM2INT(rb_ary_entry(ridx2, i));
75
+ CA_CHECK_INDEX(k, ca->dim[i]);
76
+ idx2[i] = k;
77
+ }
78
+ has_index2 = 1;
79
+ ca_fetch_index(ca, idx2, val2);
80
+ if ( has_mask ) {
81
+ ca_fetch_index(ca->mask, idx2, &m2);
82
+ }
83
+ }
84
+ else {
85
+ k = NUM2INT(ridx2);
86
+ CA_CHECK_INDEX(k, ca->elements);
87
+ addr2 = k;
88
+ has_index2 = 0;
89
+ ca_fetch_addr(ca, addr2, val2);
90
+ if ( has_mask ) {
91
+ ca_fetch_addr(ca->mask, addr2, &m2);
92
+ }
93
+ }
94
+
95
+ if ( has_index1 ) {
96
+ ca_store_index(ca, idx1, val2);
97
+ if ( has_mask ) {
98
+ ca_store_index(ca->mask, idx1, &m2);
99
+ }
100
+ }
101
+ else {
102
+ ca_store_addr(ca, addr1, val2);
103
+ if ( has_mask ) {
104
+ ca_store_addr(ca->mask, addr1, &m2);
105
+ }
106
+ }
107
+
108
+ if ( has_index2 ) {
109
+ ca_store_index(ca, idx2, val1);
110
+ if ( has_mask ) {
111
+ ca_store_index(ca->mask, idx2, &m1);
112
+ }
113
+ }
114
+ else {
115
+ ca_store_addr(ca, addr2, val1);
116
+ if ( has_mask ) {
117
+ ca_store_addr(ca->mask, addr2, &m1);
118
+ }
119
+ }
120
+
121
+ if ( ca->bytes > 32 ) {
122
+ free(val1);
123
+ free(val2);
124
+ }
125
+
126
+ return self;
127
+ }
128
+
129
+ /* rdoc:
130
+ class CArray
131
+ def elem_copy
132
+ end
133
+ end
134
+ */
135
+
136
+ VALUE
137
+ rb_ca_elem_copy (VALUE self, VALUE ridx1, VALUE ridx2)
138
+ {
139
+ CArray *ca;
140
+ int32_t idx1[CA_RANK_MAX], idx2[CA_RANK_MAX];
141
+ int32_t addr1 = 0, addr2 = 0;
142
+ int32_t i,k;
143
+ int has_mask;
144
+ char _val[32];
145
+ char *val = _val;
146
+ boolean8_t m = 0;
147
+
148
+ rb_ca_modify(self);
149
+
150
+ Data_Get_Struct(self, CArray, ca);
151
+
152
+ ca_update_mask(ca);
153
+ has_mask = ( ca->mask ) ? 1 : 0;
154
+
155
+ if ( ca->bytes > 32 ) {
156
+ val = malloc_with_check(ca->bytes);
157
+ }
158
+
159
+ if ( TYPE(ridx1) == T_ARRAY ) {
160
+ for (i=0; i<ca->rank; i++) {
161
+ k = NUM2INT(rb_ary_entry(ridx1, i));
162
+ CA_CHECK_INDEX(k, ca->dim[i]);
163
+ idx1[i] = k;
164
+ }
165
+ ca_fetch_index(ca, idx1, val);
166
+ if ( has_mask ) {
167
+ ca_fetch_index(ca->mask, idx1, &m);
168
+ }
169
+ }
170
+ else {
171
+ k = NUM2INT(ridx1);
172
+ CA_CHECK_INDEX(k, ca->elements);
173
+ addr1 = k;
174
+ ca_fetch_addr(ca, addr1, val);
175
+ if ( has_mask ) {
176
+ ca_fetch_addr(ca->mask, addr1, &m);
177
+ }
178
+ }
179
+
180
+ if ( TYPE(ridx2) == T_ARRAY ) {
181
+ for (i=0; i<ca->rank; i++) {
182
+ k = NUM2INT(rb_ary_entry(ridx2, i));
183
+ CA_CHECK_INDEX(k, ca->dim[i]);
184
+ idx2[i] = k;
185
+ }
186
+ ca_store_index(ca, idx2, val);
187
+ if ( has_mask ) {
188
+ ca_store_index(ca->mask, idx2, &m);
189
+ }
190
+ }
191
+ else {
192
+ k = NUM2INT(ridx2);
193
+ CA_CHECK_INDEX(k, ca->elements);
194
+ addr2 = k;
195
+ ca_store_addr(ca, addr2, val);
196
+ if ( has_mask ) {
197
+ ca_store_addr(ca->mask, addr2, &m);
198
+ }
199
+ }
200
+
201
+ if ( ca->bytes > 32 ) {
202
+ free(val);
203
+ }
204
+
205
+ return self;
206
+ }
207
+
208
+ /* rdoc:
209
+ class CArray
210
+ def elem_store
211
+ end
212
+ end
213
+ */
214
+
215
+ VALUE
216
+ rb_ca_elem_store (VALUE self, VALUE ridx, VALUE obj)
217
+ {
218
+ CArray *ca;
219
+ int32_t idx[CA_RANK_MAX];
220
+ int32_t addr = 0;
221
+ int32_t i,k;
222
+
223
+ rb_ca_modify(self);
224
+
225
+ Data_Get_Struct(self, CArray, ca);
226
+
227
+ if ( TYPE(ridx) == T_ARRAY ) {
228
+ for (i=0; i<ca->rank; i++) {
229
+ k = NUM2INT(rb_ary_entry(ridx, i));
230
+ CA_CHECK_INDEX(k, ca->dim[i]);
231
+ idx[i] = k;
232
+ }
233
+ rb_ca_store_index(self, idx, obj);
234
+ }
235
+ else {
236
+ k = NUM2INT(ridx);
237
+ CA_CHECK_INDEX(k, ca->elements);
238
+ addr = k;
239
+ rb_ca_store_addr(self, addr, obj);
240
+ }
241
+
242
+ return obj;
243
+ }
244
+
245
+ /* rdoc:
246
+ class CArray
247
+ def elem_fetch
248
+ end
249
+ end
250
+ */
251
+
252
+ VALUE
253
+ rb_ca_elem_fetch (VALUE self, VALUE ridx)
254
+ {
255
+ CArray *ca;
256
+ int32_t idx[CA_RANK_MAX];
257
+ int32_t addr = 0;
258
+ int32_t i,k;
259
+
260
+ Data_Get_Struct(self, CArray, ca);
261
+
262
+ if ( TYPE(ridx) == T_ARRAY ) {
263
+ for (i=0; i<ca->rank; i++) {
264
+ k = NUM2INT(rb_ary_entry(ridx, i));
265
+ CA_CHECK_INDEX(k, ca->dim[i]);
266
+ idx[i] = k;
267
+ }
268
+ return rb_ca_fetch_index(self, idx);
269
+ }
270
+ else {
271
+ k = NUM2INT(ridx);
272
+ CA_CHECK_INDEX(k, ca->elements);
273
+ addr = k;
274
+ return rb_ca_fetch_addr(self, addr);
275
+ }
276
+ }
277
+
278
+ /* rdoc:
279
+ class CArray
280
+ def elem_incr
281
+ end
282
+ end
283
+ */
284
+
285
+ VALUE
286
+ rb_ca_elem_incr (VALUE self, VALUE ridx1)
287
+ {
288
+ volatile VALUE out;
289
+ CArray *ca;
290
+ int32_t idx1[CA_RANK_MAX];
291
+ int32_t addr1 = 0;
292
+ int32_t i,k;
293
+ int has_index1 = 0;
294
+ int has_mask;
295
+ char _val[8];
296
+ char *val = _val;
297
+ boolean8_t m = 0;
298
+
299
+ rb_ca_modify(self);
300
+
301
+ Data_Get_Struct(self, CArray, ca);
302
+
303
+ if ( ! ca_is_integer_type(ca) ) {
304
+ rb_raise(rb_eCADataTypeError,
305
+ "incremented array should be an integer array");
306
+ }
307
+
308
+ ca_update_mask(ca);
309
+ has_mask = ( ca->mask ) ? 1 : 0;
310
+
311
+ if ( TYPE(ridx1) == T_ARRAY ) {
312
+ for (i=0; i<ca->rank; i++) {
313
+ k = NUM2INT(rb_ary_entry(ridx1, i));
314
+ CA_CHECK_INDEX(k, ca->dim[i]);
315
+ idx1[i] = k;
316
+ }
317
+ if ( has_mask ) {
318
+ ca_fetch_index(ca->mask, idx1, &m);
319
+ }
320
+ if ( m ) {
321
+ return Qnil;
322
+ }
323
+ else {
324
+ ca_fetch_index(ca, idx1, val);
325
+ }
326
+ has_index1 = 1;
327
+ }
328
+ else {
329
+ k = NUM2INT(ridx1);
330
+ CA_CHECK_INDEX(k, ca->elements);
331
+ addr1 = k;
332
+ if ( has_mask ) {
333
+ ca_fetch_addr(ca->mask, addr1, &m);
334
+ }
335
+ if ( m ) {
336
+ return Qnil;
337
+ }
338
+ else {
339
+ ca_fetch_addr(ca, addr1, val);
340
+ }
341
+ }
342
+
343
+ switch ( ca->data_type ) {
344
+ case CA_INT8: out = INT2NUM(++*((int8_t*) val)); break;
345
+ case CA_UINT8: out = UINT2NUM(++*((uint8_t*) val)); break;
346
+ case CA_INT16: out = INT2NUM(++*((int16_t*) val)); break;
347
+ case CA_UINT16: out = UINT2NUM(++*((uint16_t*) val)); break;
348
+ case CA_INT32: out = INT2NUM(++*((int32_t*) val)); break;
349
+ case CA_UINT32: out = UINT2NUM(++*((uint32_t*) val)); break;
350
+ case CA_INT64: out = INT2NUM(++*((int64_t*) val)); break;
351
+ case CA_UINT64: out = UINT2NUM(++*((uint64_t*) val)); break;
352
+ }
353
+
354
+ if ( has_index1 ) {
355
+ ca_store_index(ca, idx1, val);
356
+ }
357
+ else {
358
+ ca_store_addr(ca, addr1, val);
359
+ }
360
+
361
+ return out;
362
+ }
363
+
364
+ /* rdoc:
365
+ class CArray
366
+ def elem_decr
367
+ end
368
+ end
369
+ */
370
+
371
+ VALUE
372
+ rb_ca_elem_decr (VALUE self, VALUE ridx1)
373
+ {
374
+ volatile VALUE out;
375
+ CArray *ca;
376
+ int32_t idx1[CA_RANK_MAX];
377
+ int32_t addr1 = 0;
378
+ int32_t i,k;
379
+ int has_index1 = 0;
380
+ int has_mask;
381
+ char _val[8];
382
+ char *val = _val;
383
+ boolean8_t m = 0;
384
+
385
+ rb_ca_modify(self);
386
+
387
+ Data_Get_Struct(self, CArray, ca);
388
+
389
+ if ( ! ca_is_integer_type(ca) ) {
390
+ rb_raise(rb_eCADataTypeError,
391
+ "decremented array should be an integer array");
392
+ }
393
+
394
+ ca_update_mask(ca);
395
+ has_mask = ( ca->mask ) ? 1 : 0;
396
+
397
+ if ( TYPE(ridx1) == T_ARRAY ) {
398
+ for (i=0; i<ca->rank; i++) {
399
+ k = NUM2INT(rb_ary_entry(ridx1, i));
400
+ CA_CHECK_INDEX(k, ca->dim[i]);
401
+ idx1[i] = k;
402
+ }
403
+ if ( has_mask ) {
404
+ ca_fetch_index(ca->mask, idx1, &m);
405
+ }
406
+ if ( m ) {
407
+ return Qnil;
408
+ }
409
+ else {
410
+ ca_fetch_index(ca, idx1, val);
411
+ }
412
+ has_index1 = 1;
413
+ }
414
+ else {
415
+ k = NUM2INT(ridx1);
416
+ CA_CHECK_INDEX(k, ca->elements);
417
+ addr1 = k;
418
+ if ( has_mask ) {
419
+ ca_fetch_addr(ca->mask, addr1, &m);
420
+ }
421
+ if ( m ) {
422
+ return Qnil;
423
+ }
424
+ else {
425
+ ca_fetch_addr(ca, addr1, val);
426
+ }
427
+ }
428
+
429
+ switch ( ca->data_type ) {
430
+ case CA_INT8: out = INT2NUM(--*((int8_t*) val)); break;
431
+ case CA_UINT8: out = UINT2NUM(--*((uint8_t*) val)); break;
432
+ case CA_INT16: out = INT2NUM(--*((int16_t*) val)); break;
433
+ case CA_UINT16: out = UINT2NUM(--*((uint16_t*) val)); break;
434
+ case CA_INT32: out = INT2NUM(--*((int32_t*) val)); break;
435
+ case CA_UINT32: out = UINT2NUM(--*((uint32_t*) val)); break;
436
+ case CA_INT64: out = INT2NUM(--*((int64_t*) val)); break;
437
+ case CA_UINT64: out = UINT2NUM(--*((uint64_t*) val)); break;
438
+ }
439
+
440
+ if ( has_index1 ) {
441
+ ca_store_index(ca, idx1, val);
442
+ }
443
+ else {
444
+ ca_store_addr(ca, addr1, val);
445
+ }
446
+
447
+ return out;
448
+ }
449
+
450
+ /* rdoc:
451
+ class CArray
452
+ def elem_masked?
453
+ end
454
+ end
455
+ */
456
+
457
+ VALUE
458
+ rb_ca_elem_test_masked (VALUE self, VALUE ridx1)
459
+ {
460
+ CArray *ca;
461
+ int32_t idx1[CA_RANK_MAX];
462
+ int32_t addr1 = 0;
463
+ int32_t i, k;
464
+ boolean8_t m = 0;
465
+
466
+ Data_Get_Struct(self, CArray, ca);
467
+
468
+ ca_update_mask(ca);
469
+
470
+ if ( TYPE(ridx1) == T_ARRAY ) {
471
+ for (i=0; i<ca->rank; i++) {
472
+ k = NUM2INT(rb_ary_entry(ridx1, i));
473
+ CA_CHECK_INDEX(k, ca->dim[i]);
474
+ idx1[i] = k;
475
+ }
476
+ if ( ca->mask ) {
477
+ ca_fetch_index(ca->mask, idx1, &m);
478
+ }
479
+ }
480
+ else {
481
+ k = NUM2INT(ridx1);
482
+ CA_CHECK_INDEX(k, ca->elements);
483
+ addr1 = k;
484
+ if ( ca->mask ) {
485
+ ca_fetch_addr(ca->mask, addr1, &m);
486
+ }
487
+ }
488
+
489
+ return m ? Qtrue : Qfalse;
490
+ }
491
+
492
+ /* ----------------------------------------------------------------- */
493
+
494
+ /* rdoc:
495
+ class CArray
496
+ # used in CAHistogram.
497
+ def incr_addr
498
+ end
499
+ end
500
+ */
501
+
502
+ static VALUE
503
+ rb_ca_incr_addr (volatile VALUE self, volatile VALUE raddr)
504
+ {
505
+ CArray *ca, *ci;
506
+ int32_t *q, *p, k, elements;
507
+ int32_t i;
508
+ boolean8_t *m;
509
+
510
+ rb_ca_modify(self);
511
+
512
+ self = rb_ca_wrap_writable(self, INT2FIX(CA_INT32));
513
+ raddr = rb_ca_wrap_readonly(raddr, INT2FIX(CA_INT32));
514
+
515
+ Data_Get_Struct(self, CArray, ca);
516
+ Data_Get_Struct(raddr, CArray, ci);
517
+
518
+ ca_attach_n(2, ca, ci);
519
+
520
+ q = (int32_t *) ca->ptr;
521
+ p = (int32_t *) ci->ptr;
522
+ m = ( ci->mask ) ? (boolean8_t *) ci->mask->ptr : NULL;
523
+
524
+ elements = ca->elements;
525
+
526
+ if ( m ) {
527
+ #ifdef _OPENMP
528
+ #pragma omp parallel for
529
+ #endif
530
+ for (i=0; i<ci->elements; i++) {
531
+ if ( ! *(m+i) ) {
532
+ k = *(p+i);
533
+ CA_CHECK_INDEX(k, elements);
534
+ *(q + k) += 1;
535
+ }
536
+ }
537
+ }
538
+ else {
539
+ #ifdef _OPENMP
540
+ #pragma omp parallel for
541
+ #endif
542
+ for (i=0; i<ci->elements; i++) {
543
+ k = *(p+i);
544
+ CA_CHECK_INDEX(k, elements);
545
+ *(q + k) += 1;
546
+ }
547
+ }
548
+
549
+ ca_sync(ca);
550
+ ca_detach_n(2, ca, ci);
551
+
552
+ return Qnil;
553
+ }
554
+
555
+ /* ----------------------------------------------------------------- */
556
+
557
+ void
558
+ Init_carray_element ()
559
+ {
560
+ rb_define_method(rb_cCArray, "elem_swap", rb_ca_elem_swap, 2);
561
+ rb_define_method(rb_cCArray, "elem_copy", rb_ca_elem_copy, 2);
562
+ rb_define_method(rb_cCArray, "elem_store", rb_ca_elem_store, 2);
563
+ rb_define_method(rb_cCArray, "elem_fetch", rb_ca_elem_fetch, 1);
564
+
565
+ rb_define_method(rb_cCArray, "elem_incr", rb_ca_elem_incr, 1);
566
+ rb_define_method(rb_cCArray, "elem_decr", rb_ca_elem_decr, 1);
567
+
568
+ rb_define_method(rb_cCArray, "elem_masked?", rb_ca_elem_test_masked, 1);
569
+
570
+ rb_define_method(rb_cCArray, "incr_addr", rb_ca_incr_addr, 1);
571
+ }
572
+