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,903 @@
1
+ /* ---------------------------------------------------------------------------
2
+
3
+ carray_attribute.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 "carray.h"
14
+
15
+ /* ------------------------------------------------------------------- */
16
+
17
+ /* rdoc
18
+ class CArray
19
+ # returns the object type (e.g. CA_OBJ_ARRAY, CA_OBJ_BLOCK, ...).
20
+ # Because the object type can be known from the class of the object,
21
+ # this attribute method is rarely used.
22
+ def obj_type
23
+ end
24
+ end
25
+ */
26
+
27
+ VALUE
28
+ rb_ca_obj_type (VALUE self)
29
+ {
30
+ CArray *ca;
31
+ Data_Get_Struct(self, CArray, ca);
32
+ return LONG2NUM(ca->obj_type);
33
+ }
34
+
35
+ /* rdoc
36
+ class CArray
37
+ # returns the data type of each element (e.g. CA_INT32, CA_FLOAT64, ...).
38
+ def data_type
39
+ end
40
+ end
41
+ */
42
+
43
+ VALUE
44
+ rb_ca_data_type (VALUE self)
45
+ {
46
+ CArray *ca;
47
+ Data_Get_Struct(self, CArray, ca);
48
+ return LONG2NUM(ca->data_type);
49
+ }
50
+
51
+ /* rdoc
52
+ class CArray
53
+ # returns the rank (e.g. 1 for 1D array, 3 for 3D array, ...).
54
+ def rank
55
+ end
56
+ end
57
+ */
58
+
59
+ VALUE
60
+ rb_ca_rank (VALUE self)
61
+ {
62
+ CArray *ca;
63
+ Data_Get_Struct(self, CArray, ca);
64
+ return LONG2NUM(ca->rank);
65
+ }
66
+
67
+ /* rdoc
68
+ class CArray
69
+ # returns the byte size of each element (e.g. 4 for CA_INT32, 8 for CA_FLOAT64).
70
+ # The byte size can be known using CArray.sizeof(data_type)
71
+ # for the numerical data types, but
72
+ # the byte size of fixed-length data type can be known
73
+ # only by this method.
74
+ def bytes
75
+ end
76
+ end
77
+ */
78
+
79
+ VALUE
80
+ rb_ca_bytes (VALUE self)
81
+ {
82
+ CArray *ca;
83
+ Data_Get_Struct(self, CArray, ca);
84
+ return LONG2NUM(ca->bytes);
85
+ }
86
+
87
+ /* rdoc:
88
+ class CArray
89
+ # returns the number of elements
90
+ def elements
91
+ end
92
+
93
+ # alias of `CArray#elements`
94
+ alias length elements
95
+
96
+ # alias of `CArray#elements`
97
+ alias size elements
98
+ end
99
+ */
100
+
101
+ VALUE
102
+ rb_ca_elements (VALUE self)
103
+ {
104
+ CArray *ca;
105
+ Data_Get_Struct(self, CArray, ca);
106
+ return LONG2NUM(ca->elements);
107
+ }
108
+
109
+ /* rdoc:
110
+ class CArray
111
+ # returns the Array object contains the dimensional shape of array
112
+ # (e.g. [2,3] for 2D 2x3 array, ...).
113
+ def dim
114
+ end
115
+
116
+ # short-hand for dim[0]
117
+ def dim0
118
+ end
119
+
120
+ # short-hand for dim[1]
121
+ def dim1
122
+ end
123
+
124
+ # short-hand for dim[2]
125
+ def dim2
126
+ end
127
+
128
+ # short-hand for dim[3]
129
+ def dim3
130
+ end
131
+ end
132
+ */
133
+
134
+ VALUE
135
+ rb_ca_dim (VALUE self)
136
+ {
137
+ volatile VALUE dim;
138
+ CArray *ca;
139
+ int i;
140
+ Data_Get_Struct(self, CArray, ca);
141
+ dim = rb_ary_new2(ca->rank);
142
+ for (i=0; i<ca->rank; i++) {
143
+ rb_ary_store(dim, i, LONG2NUM(ca->dim[i]));
144
+ }
145
+ return dim;
146
+ }
147
+
148
+ VALUE
149
+ rb_ca_dim0 (VALUE self)
150
+ {
151
+ CArray *ca;
152
+ Data_Get_Struct(self, CArray, ca);
153
+ return INT2NUM(ca->dim[0]);
154
+ }
155
+
156
+ VALUE
157
+ rb_ca_dim1 (VALUE self)
158
+ {
159
+ CArray *ca;
160
+ Data_Get_Struct(self, CArray, ca);
161
+ return ( ca->rank >= 2 ) ? INT2NUM(ca->dim[1]) : Qnil;
162
+ }
163
+
164
+ VALUE
165
+ rb_ca_dim2 (VALUE self)
166
+ {
167
+ CArray *ca;
168
+ Data_Get_Struct(self, CArray, ca);
169
+ return ( ca->rank >= 3 ) ? INT2NUM(ca->dim[2]) : Qnil;
170
+ }
171
+
172
+ VALUE
173
+ rb_ca_dim3 (VALUE self)
174
+ {
175
+ CArray *ca;
176
+ Data_Get_Struct(self, CArray, ca);
177
+ return ( ca->rank >= 4 ) ? INT2NUM(ca->dim[3]) : Qnil;
178
+ }
179
+
180
+ /* rdoc:
181
+ class CArray
182
+ # returns the string representaion of the data_type (e.g. "int32", "fixlen")
183
+ def data_type_name
184
+ end
185
+ end
186
+ */
187
+
188
+ VALUE
189
+ rb_ca_data_type_name (VALUE self)
190
+ {
191
+ CArray *ca;
192
+ Data_Get_Struct(self, CArray, ca);
193
+ return rb_str_new2(ca_type_name[ca->data_type]);
194
+ }
195
+
196
+ /* ------------------------------------------------------------------- */
197
+
198
+ int
199
+ ca_is_scalar (void *ap)
200
+ {
201
+ CArray *ca = (CArray *) ap;
202
+ return ca_test_flag(ca, CA_FLAG_SCALAR);
203
+ }
204
+
205
+ /* rdoc:
206
+ class CArray
207
+ # returns true if `self` is a CScalar object
208
+ def scalar?
209
+ end
210
+ end
211
+ */
212
+
213
+ VALUE
214
+ rb_ca_is_scalar (VALUE self)
215
+ {
216
+ CArray *ca;
217
+ Data_Get_Struct(self, CArray, ca);
218
+ return ( ca_is_scalar(ca) ) ? Qtrue : Qfalse;
219
+ }
220
+
221
+ /* api: rb_obj_is_cscalar */
222
+
223
+ VALUE
224
+ rb_obj_is_cscalar (VALUE obj)
225
+ {
226
+ CArray *ca;
227
+ if ( rb_obj_is_carray(obj) ) {
228
+ Data_Get_Struct(obj, CArray, ca);
229
+ return ( ca_is_scalar(ca) ) ? Qtrue : Qfalse;
230
+ }
231
+ return Qfalse;
232
+ }
233
+
234
+ /* ------------------------------------------------------------------- */
235
+
236
+ int
237
+ ca_is_virtual (void *ap)
238
+ {
239
+ CArray *ca = (CArray *) ap;
240
+ return ( ca_func[ca->obj_type].entity_type == CA_VIRTUAL_ARRAY ) ? 1 : 0;
241
+ }
242
+
243
+ /* rdoc:
244
+ class CArray
245
+ # returns true if `self` is an entity array (not a virtual array).
246
+ def entity?
247
+ end
248
+
249
+ # returns true if `self` is a virtural array (not an entity array).
250
+ def virtual?
251
+ end
252
+ end
253
+ */
254
+
255
+ VALUE
256
+ rb_ca_is_entity (VALUE self)
257
+ {
258
+ CArray *ca;
259
+ Data_Get_Struct(self, CArray, ca);
260
+ return ( ca_is_virtual(ca) ) ? Qfalse : Qtrue;
261
+ }
262
+
263
+ VALUE
264
+ rb_ca_is_virtual (VALUE self)
265
+ {
266
+ CArray *ca;
267
+ Data_Get_Struct(self, CArray, ca);
268
+ return ( ca_is_virtual(ca) ) ? Qtrue : Qfalse;
269
+ }
270
+
271
+ /* ------------------------------------------------------------------- */
272
+
273
+ /* rdoc
274
+ class CArray
275
+ # returns true if `self` is attached.
276
+ def attached?
277
+ end
278
+ end
279
+ */
280
+
281
+ VALUE
282
+ rb_ca_is_attached (VALUE self)
283
+ {
284
+ CArray *ca;
285
+ Data_Get_Struct(self, CArray, ca);
286
+ return ( ca_is_attached(ca) ) ? Qtrue : Qfalse;
287
+ }
288
+
289
+ /* ------------------------------------------------------------------- */
290
+
291
+ /* rdoc
292
+ class CArray
293
+ # returns true if `self` is empty.
294
+ def empty?
295
+ end
296
+ end
297
+ */
298
+
299
+ VALUE
300
+ rb_ca_is_empty (VALUE self)
301
+ {
302
+ CArray *ca;
303
+ Data_Get_Struct(self, CArray, ca);
304
+ return ( ca->elements == 0 ) ? Qtrue : Qfalse;
305
+ }
306
+
307
+ /* ------------------------------------------------------------------- */
308
+
309
+ int
310
+ ca_is_readonly (void *ap)
311
+ {
312
+ CArray *ca = (CArray *) ap;
313
+ if ( ca_test_flag(ca, CA_FLAG_READ_ONLY) ) { /* test -> true */
314
+ return 1;
315
+ }
316
+ else { /* test -> false */
317
+ if ( ca_is_virtual(ca) && CAVIRTUAL(ca)->parent ) {
318
+ if ( ca_is_readonly(CAVIRTUAL(ca)->parent) ) { /* test -> true */
319
+ ca_set_flag(ca, CA_FLAG_READ_ONLY);
320
+ return 1;
321
+ }
322
+ }
323
+ return 0; /* all test -> false */
324
+ }
325
+ }
326
+
327
+ /* rdoc
328
+ class CArray
329
+ # returns true if `self` is read-only carray
330
+ def read_only?
331
+ end
332
+ end
333
+ */
334
+
335
+ VALUE
336
+ rb_ca_is_read_only (VALUE self)
337
+ {
338
+ CArray *ca;
339
+ Data_Get_Struct(self, CArray, ca);
340
+ return ( ca_is_readonly(ca) ) ? Qtrue : Qfalse;
341
+ }
342
+
343
+ /* ------------------------------------------------------------------- */
344
+
345
+ int
346
+ ca_is_mask_array (void *ap)
347
+ {
348
+ CArray *ca = (CArray *) ap;
349
+ if ( ca_test_flag(ca, CA_FLAG_MASK_ARRAY) ) { /* test -> true */
350
+ return 1;
351
+ }
352
+ else { /* test -> false */
353
+ if ( ca_is_virtual(ca) && CAVIRTUAL(ca)->parent ) {
354
+ if ( ca_is_mask_array(CAVIRTUAL(ca)->parent) ) { /* test -> true */
355
+ ca_set_flag(ca, CA_FLAG_MASK_ARRAY);
356
+ return 1;
357
+ }
358
+ }
359
+ return 0; /* all test -> false */
360
+ }
361
+ }
362
+
363
+ /* rdoc
364
+ class CArray
365
+ # returns true if `self` is mask array (don't confuse with "masked array")
366
+ def mask_array?
367
+ end
368
+ end
369
+ */
370
+
371
+ VALUE
372
+ rb_ca_is_mask_array (VALUE self)
373
+ {
374
+ CArray *ca;
375
+ Data_Get_Struct(self, CArray, ca);
376
+ return ( ca_is_mask_array(ca) ) ? Qtrue : Qfalse;
377
+ }
378
+
379
+ /* ------------------------------------------------------------------- */
380
+
381
+ int
382
+ ca_is_value_array (void *ap)
383
+ {
384
+ CArray *ca = (CArray *) ap;
385
+ if ( ca_test_flag(ca, CA_FLAG_VALUE_ARRAY) ) { /* test -> true */
386
+ return 1;
387
+ }
388
+ else { /* test -> false */
389
+ if ( ca_is_virtual(ca) && CAVIRTUAL(ca)->parent ) {
390
+ if ( ca_is_value_array(CAVIRTUAL(ca)->parent) ) { /* test -> true */
391
+ ca_set_flag(ca, CA_FLAG_VALUE_ARRAY);
392
+ return 1;
393
+ }
394
+ }
395
+ return 0; /* all test -> false */
396
+ }
397
+ }
398
+
399
+ /* rdoc
400
+ class CArray
401
+ # returns true if `self` is a value array
402
+ def value_array?
403
+ end
404
+ end
405
+ */
406
+
407
+ VALUE
408
+ rb_ca_is_value_array (VALUE self)
409
+ {
410
+ CArray *ca;
411
+ Data_Get_Struct(self, CArray, ca);
412
+ return ( ca_is_value_array(ca) ) ? Qtrue : Qfalse;
413
+ }
414
+
415
+ /* ------------------------------------------------------------------- */
416
+
417
+ int
418
+ ca_is_fixlen_type (void *ap)
419
+ {
420
+ CArray *ca = (CArray *) ap;
421
+ return ( ca->data_type == CA_FIXLEN );
422
+ }
423
+
424
+ /* rdoc
425
+ class CArray
426
+ # return true if `self` is fixed-length type array
427
+ def filxen?
428
+ end
429
+ end
430
+ */
431
+
432
+ VALUE
433
+ rb_ca_is_fixlen_type (VALUE self)
434
+ {
435
+ CArray *ca;
436
+ Data_Get_Struct(self, CArray, ca);
437
+ return ca_is_fixlen_type(ca) ? Qtrue : Qfalse;
438
+ }
439
+
440
+ /* ------------------------------------------------------------------- */
441
+
442
+ int
443
+ ca_is_boolean_type (void *ap)
444
+ {
445
+ CArray *ca = (CArray *) ap;
446
+ return ( ca->data_type == CA_BOOLEAN );
447
+ }
448
+
449
+ /* rdoc
450
+ class CArray
451
+ # return true if `self` is boolean type array
452
+ def boolean?
453
+ end
454
+ end
455
+ */
456
+
457
+ VALUE
458
+ rb_ca_is_boolean_type (VALUE self)
459
+ {
460
+ CArray *ca;
461
+ Data_Get_Struct(self, CArray, ca);
462
+ return ca_is_boolean_type(ca) ? Qtrue : Qfalse;
463
+ }
464
+
465
+ /* ------------------------------------------------------------------- */
466
+
467
+ int
468
+ ca_is_numeric_type (void *ap)
469
+ {
470
+ CArray *ca = (CArray *) ap;
471
+ return ( ( ca->data_type >= CA_INT8 ) &&
472
+ ( ca->data_type <= CA_CMPLX256 ) );
473
+ }
474
+
475
+ /* rdoc
476
+ class CArray
477
+ # return true if `self` is numeric type array
478
+ def numeric?
479
+ end
480
+ end
481
+ */
482
+
483
+ VALUE
484
+ rb_ca_is_numeric_type (VALUE self)
485
+ {
486
+ CArray *ca;
487
+ Data_Get_Struct(self, CArray, ca);
488
+ return ca_is_numeric_type(ca) ? Qtrue : Qfalse;
489
+ }
490
+
491
+ /* ------------------------------------------------------------------- */
492
+
493
+ int
494
+ ca_is_integer_type (void *ap)
495
+ {
496
+ CArray *ca = (CArray *) ap;
497
+ return ( ( ca->data_type >= CA_INT8 ) &&
498
+ ( ca->data_type <= CA_UINT64 ) );
499
+ }
500
+
501
+ /* rdoc
502
+ class CArray
503
+ # return true if `self` is integer type array
504
+ def integer?
505
+ end
506
+ end
507
+ */
508
+
509
+ VALUE
510
+ rb_ca_is_integer_type (VALUE self)
511
+ {
512
+ CArray *ca;
513
+ Data_Get_Struct(self, CArray, ca);
514
+ return ca_is_integer_type(ca) ? Qtrue : Qfalse;
515
+ }
516
+
517
+ /* ------------------------------------------------------------------- */
518
+
519
+ int
520
+ ca_is_unsigned_type (void *ap)
521
+ {
522
+ CArray *ca = (CArray *) ap;
523
+ switch ( ca->data_type ) {
524
+ case CA_UINT8:
525
+ case CA_UINT16:
526
+ case CA_UINT32:
527
+ case CA_UINT64:
528
+ return 1;
529
+ default:
530
+ return 0;
531
+ }
532
+ }
533
+
534
+ /* rdoc
535
+ class CArray
536
+ # return true if `self` is unsigned integer type array
537
+ def unsigned?
538
+ end
539
+ end
540
+ */
541
+
542
+ VALUE
543
+ rb_ca_is_unsigned_type (VALUE self)
544
+ {
545
+ CArray *ca;
546
+ Data_Get_Struct(self, CArray, ca);
547
+ return ca_is_unsigned_type(ca) ? Qtrue : Qfalse;
548
+ }
549
+
550
+ /* ------------------------------------------------------------------- */
551
+
552
+ int
553
+ ca_is_float_type (void *ap)
554
+ {
555
+ CArray *ca = (CArray *) ap;
556
+ return ( ( ca->data_type >= CA_FLOAT32 ) &&
557
+ ( ca->data_type <= CA_FLOAT128 ) );
558
+ }
559
+
560
+ /* rdoc
561
+ class CArray
562
+ # return true if `self` is float type array
563
+ def float?
564
+ end
565
+ end
566
+ */
567
+
568
+ VALUE
569
+ rb_ca_is_float_type (VALUE self)
570
+ {
571
+ CArray *ca;
572
+ Data_Get_Struct(self, CArray, ca);
573
+ return ca_is_float_type(ca) ? Qtrue : Qfalse;
574
+ }
575
+
576
+ /* ------------------------------------------------------------------- */
577
+
578
+ int
579
+ ca_is_complex_type (void *ap)
580
+ {
581
+ CArray *ca = (CArray *) ap;
582
+ return ( ( ca->data_type >= CA_CMPLX64 ) &&
583
+ ( ca->data_type <= CA_CMPLX256 ) );
584
+ }
585
+
586
+ /* rdoc
587
+ class CArray
588
+ # return true if `self` is complex type array
589
+ def complex?
590
+ end
591
+ end
592
+ */
593
+
594
+ VALUE
595
+ rb_ca_is_complex_type (VALUE self)
596
+ {
597
+ CArray *ca;
598
+ Data_Get_Struct(self, CArray, ca);
599
+ return ca_is_complex_type(ca) ? Qtrue : Qfalse;
600
+ }
601
+
602
+ /* ------------------------------------------------------------------- */
603
+
604
+ int
605
+ ca_is_object_type (void *ap)
606
+ {
607
+ CArray *ca = (CArray *) ap;
608
+ return ( ca->data_type == CA_OBJECT );
609
+ }
610
+
611
+ /* rdoc
612
+ class CArray
613
+ # return true if `self` is object type array
614
+ def object?
615
+ end
616
+ end
617
+ */
618
+
619
+ VALUE
620
+ rb_ca_is_object_type (VALUE self)
621
+ {
622
+ CArray *ca;
623
+ Data_Get_Struct(self, CArray, ca);
624
+ return ca_is_object_type(ca) ? Qtrue : Qfalse;
625
+ }
626
+
627
+ /* ------------------------------------------------------------------- */
628
+
629
+ static ID id_parent;
630
+
631
+ /* rdoc
632
+ class CArray
633
+ # returns the parent carray if `self` has parent,
634
+ # or returns nil if `self` has no parent.
635
+ def parent
636
+ end
637
+ end
638
+ */
639
+
640
+ VALUE
641
+ rb_ca_parent (VALUE self)
642
+ {
643
+ return rb_ivar_get(self, id_parent);
644
+ }
645
+
646
+ VALUE
647
+ rb_ca_set_parent (VALUE self, VALUE obj)
648
+ {
649
+ OBJ_INFECT(self, obj);
650
+ rb_ivar_set(self, id_parent, obj);
651
+ if ( OBJ_FROZEN(obj) ) {
652
+ rb_ca_freeze(self);
653
+ }
654
+ return obj;
655
+ }
656
+
657
+ /* ------------------------------------------------------------------- */
658
+
659
+ static ID id_data_class;
660
+
661
+ /* rdoc
662
+ class CArray
663
+ # returns data_class if `self` is fixed-length type and it
664
+ # has the data class.
665
+ def data_class
666
+ end
667
+ end
668
+ */
669
+
670
+ VALUE
671
+ rb_ca_data_class (VALUE self)
672
+ {
673
+ volatile VALUE parent, data_class;
674
+ CArray *ca;
675
+ Data_Get_Struct(self, CArray, ca);
676
+ if ( ca_test_flag(ca, CA_FLAG_NOT_DATA_CLASS) ) {
677
+ return Qnil;
678
+ }
679
+ if ( ! ca_is_fixlen_type(ca) ) { /* not a fixlen array */
680
+ ca_set_flag(ca, CA_FLAG_NOT_DATA_CLASS);
681
+ return Qnil;
682
+ }
683
+ data_class = rb_ivar_get(self, id_data_class);
684
+ if ( ! NIL_P(data_class) ) {
685
+ return data_class;
686
+ }
687
+ else {
688
+ return Qnil;
689
+ if ( ca_is_entity(ca) ) { /* no further parent */
690
+ ca_set_flag(ca, CA_FLAG_NOT_DATA_CLASS);
691
+ return Qnil;
692
+ }
693
+ else {
694
+ parent = rb_ca_parent(self);
695
+ if ( NIL_P(parent) ) { /* no parent */
696
+ ca_set_flag(ca, CA_FLAG_NOT_DATA_CLASS);
697
+ return Qnil;
698
+ }
699
+ else {
700
+ CArray *cr;
701
+ Data_Get_Struct(parent, CArray, cr);
702
+ if ( cr->bytes != ca->bytes ) { /* byte size mismatch */
703
+ ca_set_flag(ca, CA_FLAG_NOT_DATA_CLASS);
704
+ return Qnil;
705
+ }
706
+ else {
707
+ data_class = rb_ca_data_class(parent); /* parent's data class */
708
+ if ( ! NIL_P(data_class) ) {
709
+ return data_class;
710
+ }
711
+ else {
712
+ ca_set_flag(ca, CA_FLAG_NOT_DATA_CLASS);
713
+ return Qnil;
714
+ }
715
+ }
716
+ }
717
+ }
718
+ }
719
+ }
720
+
721
+ /* rdoc
722
+ class CArray
723
+ # return true if `self` is fixed-length type and has the data class.
724
+ def has_data_class?
725
+ end
726
+ end
727
+ */
728
+
729
+ VALUE
730
+ rb_ca_has_data_class (VALUE self)
731
+ {
732
+ CArray *ca;
733
+ Data_Get_Struct(self, CArray, ca);
734
+ if ( ca_test_flag(ca, CA_FLAG_NOT_DATA_CLASS) ) {
735
+ return Qfalse;
736
+ }
737
+ else {
738
+ if ( ca_is_fixlen_type(ca) ) {
739
+ if ( RTEST(rb_ca_data_class(self)) ) {
740
+ return Qtrue;
741
+ }
742
+ }
743
+ ca_set_flag(ca, CA_FLAG_NOT_DATA_CLASS);
744
+ return Qfalse;
745
+ }
746
+ }
747
+
748
+ /* ------------------------------------------------------------------- */
749
+
750
+ VALUE
751
+ rb_ca_data_type_inherit (VALUE self, VALUE other)
752
+ {
753
+ if ( RTEST(rb_ca_is_fixlen_type(self)) ) {
754
+ VALUE data_class = rb_ca_data_class(other);
755
+ if ( RTEST(data_class) ) {
756
+ rb_ivar_set(self, rb_intern("member"), rb_hash_new());
757
+ return rb_ivar_set(self, id_data_class, data_class);
758
+ }
759
+ }
760
+ return Qnil;
761
+ }
762
+
763
+ VALUE
764
+ rb_ca_data_type_import (VALUE self, VALUE data_type)
765
+ {
766
+ if ( RTEST(rb_ca_is_fixlen_type(self)) &&
767
+ rb_obj_is_data_class(data_type) ) {
768
+ rb_ivar_set(self, rb_intern("member"), rb_hash_new());
769
+ return rb_ivar_set(self, id_data_class, data_type);
770
+ }
771
+ return Qnil;
772
+ }
773
+
774
+ /* ------------------------------------------------------------------- */
775
+
776
+ CArray *
777
+ ca_root_array (void *ap)
778
+ {
779
+ CArray *ca = (CArray *)ap;
780
+ if ( ca_is_entity(ca) ) {
781
+ return ca;
782
+ }
783
+ else {
784
+ CAVirtual *cr = (CAVirtual *)ca;
785
+ if ( ! cr->parent ) {
786
+ return ca;
787
+ }
788
+ else {
789
+ return ca_root_array(cr->parent);
790
+ }
791
+ }
792
+ }
793
+
794
+ /* CArray#root_array */
795
+
796
+ static VALUE
797
+ rb_ca_root_array (VALUE self)
798
+ {
799
+ volatile VALUE refary;
800
+ CArray *ca;
801
+ Data_Get_Struct(self, CArray, ca);
802
+ if ( ca_is_entity(ca) ) {
803
+ return self;
804
+ }
805
+ else {
806
+ refary = rb_ca_parent(self);
807
+ if ( NIL_P(refary) ) {
808
+ return self;
809
+ }
810
+ else {
811
+ return rb_ca_root_array(refary);
812
+ }
813
+ }
814
+ }
815
+
816
+ /* ------------------------------------------------------------------- */
817
+
818
+ static VALUE
819
+ rb_ca_ancestors_loop (VALUE self, VALUE list)
820
+ {
821
+ volatile VALUE refary;
822
+ CArray *ca;
823
+ Data_Get_Struct(self, CArray, ca);
824
+ rb_ary_unshift(list, self);
825
+ if ( ca_is_entity(ca) ) {
826
+ return list;
827
+ }
828
+ else {
829
+ refary = rb_ca_parent(self);
830
+ if ( rb_obj_is_carray(refary) ) {
831
+ return rb_ca_ancestors_loop(refary, list);
832
+ }
833
+ else {
834
+ return list;
835
+ }
836
+ }
837
+ }
838
+
839
+ /* CArray#ancesters */
840
+
841
+ static VALUE
842
+ rb_ca_ancestors (VALUE self)
843
+ {
844
+ volatile VALUE list;
845
+ CArray *ca;
846
+ Data_Get_Struct(self, CArray, ca);
847
+ list = rb_ary_new();
848
+ return rb_ca_ancestors_loop(self, list);
849
+ }
850
+
851
+ /* ------------------------------------------------------------------- */
852
+
853
+ void
854
+ Init_carray_attribute ()
855
+ {
856
+ id_parent = rb_intern("parent");
857
+ id_data_class = rb_intern("data_class");
858
+
859
+ rb_define_method(rb_cCArray, "obj_type", rb_ca_obj_type, 0);
860
+ rb_define_method(rb_cCArray, "data_type", rb_ca_data_type, 0);
861
+ rb_define_method(rb_cCArray, "bytes", rb_ca_bytes, 0);
862
+ rb_define_method(rb_cCArray, "rank", rb_ca_rank, 0);
863
+ rb_define_method(rb_cCArray, "dim", rb_ca_dim, 0);
864
+ rb_define_method(rb_cCArray, "dim0", rb_ca_dim0, 0);
865
+ rb_define_method(rb_cCArray, "dim1", rb_ca_dim1, 0);
866
+ rb_define_method(rb_cCArray, "dim2", rb_ca_dim2, 0);
867
+ rb_define_method(rb_cCArray, "dim3", rb_ca_dim3, 0);
868
+ rb_define_method(rb_cCArray, "elements", rb_ca_elements, 0);
869
+ rb_define_method(rb_cCArray, "length", rb_ca_elements, 0);
870
+ rb_define_method(rb_cCArray, "size", rb_ca_elements, 0);
871
+
872
+ rb_define_method(rb_cCArray, "data_type_name", rb_ca_data_type_name, 0);
873
+
874
+ rb_define_method(rb_cCArray, "parent", rb_ca_parent, 0);
875
+
876
+ rb_define_method(rb_cCArray, "data_class", rb_ca_data_class, 0);
877
+
878
+ rb_define_method(rb_cCArray, "scalar?", rb_ca_is_scalar, 0);
879
+
880
+ rb_define_method(rb_cCArray, "entity?", rb_ca_is_entity, 0);
881
+ rb_define_method(rb_cCArray, "virtual?", rb_ca_is_virtual, 0);
882
+ rb_define_method(rb_cCArray, "value_array?", rb_ca_is_value_array, 0);
883
+ rb_define_method(rb_cCArray, "mask_array?", rb_ca_is_mask_array, 0);
884
+
885
+ rb_define_method(rb_cCArray, "empty?", rb_ca_is_empty, 0);
886
+ rb_define_method(rb_cCArray, "read_only?", rb_ca_is_read_only, 0);
887
+ rb_define_method(rb_cCArray, "attached?", rb_ca_is_attached, 0);
888
+
889
+ rb_define_method(rb_cCArray, "has_data_class?", rb_ca_has_data_class, 0);
890
+
891
+ rb_define_method(rb_cCArray, "fixlen?", rb_ca_is_fixlen_type, 0);
892
+ rb_define_method(rb_cCArray, "boolean?", rb_ca_is_boolean_type, 0);
893
+ rb_define_method(rb_cCArray, "numeric?", rb_ca_is_numeric_type, 0);
894
+ rb_define_method(rb_cCArray, "integer?", rb_ca_is_integer_type, 0);
895
+ rb_define_method(rb_cCArray, "unsigned?", rb_ca_is_unsigned_type, 0);
896
+ rb_define_method(rb_cCArray, "float?", rb_ca_is_float_type, 0);
897
+ rb_define_method(rb_cCArray, "complex?", rb_ca_is_complex_type, 0);
898
+ rb_define_method(rb_cCArray, "object?", rb_ca_is_object_type, 0);
899
+
900
+ rb_define_method(rb_cCArray, "root_array", rb_ca_root_array, 0);
901
+ rb_define_method(rb_cCArray, "ancestors", rb_ca_ancestors, 0);
902
+ }
903
+