carray 3.0.7 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (275) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -1
  3. data/CHANGELOG.md +7 -1940
  4. data/README.md +38 -32
  5. data/carray.gemspec +16 -4
  6. data/docs/changelogs/CHANGELOG-3.0.md +2464 -0
  7. data/ext/ca_array_pool.c +4 -5
  8. data/ext/ca_axis_descriptor.h +45 -30
  9. data/ext/ca_axis_dispatch.c +7 -4
  10. data/ext/ca_axis_group.c +6 -9
  11. data/ext/ca_bincmp_dispatch.h +16 -38
  12. data/ext/ca_binop_dispatch.c +27 -0
  13. data/ext/ca_binop_dispatch.h +22 -47
  14. data/ext/ca_categorical_iterator.c +36 -34
  15. data/ext/ca_compare.c +0 -1
  16. data/ext/ca_compare.h +8 -1
  17. data/ext/ca_composite_dispatch.h +6 -0
  18. data/ext/ca_for_buffer.h +6 -1
  19. data/ext/ca_group_iter.c +17 -18
  20. data/ext/ca_iter_state_fields.h +196 -0
  21. data/ext/ca_iter_substrate.h +84 -103
  22. data/ext/ca_kernel_iterator.c +125 -89
  23. data/ext/ca_kernel_iterator.h +229 -1506
  24. data/ext/ca_kernel_iterator_internal.h +1167 -0
  25. data/ext/ca_moncmp_dispatch.h +17 -24
  26. data/ext/ca_monop_dispatch.h +25 -74
  27. data/ext/ca_obj_array.c +90 -163
  28. data/ext/ca_obj_bincmp.c +47 -46
  29. data/ext/ca_obj_binop.c +38 -38
  30. data/ext/ca_obj_bitarray.c +5 -17
  31. data/ext/ca_obj_bitfield.c +15 -30
  32. data/ext/ca_obj_block.c +11 -12
  33. data/ext/ca_obj_byte_swap.c +32 -30
  34. data/ext/ca_obj_const_string.c +57 -62
  35. data/ext/ca_obj_face.c +99 -91
  36. data/ext/ca_obj_face.h +32 -170
  37. data/ext/ca_obj_fake.c +15 -21
  38. data/ext/ca_obj_farray.c +7 -9
  39. data/ext/ca_obj_field.c +17 -13
  40. data/ext/ca_obj_fixlen_string.c +8 -19
  41. data/ext/ca_obj_grid.c +137 -106
  42. data/ext/ca_obj_meld.c +23 -21
  43. data/ext/ca_obj_moncmp.c +10 -21
  44. data/ext/ca_obj_monop.c +24 -35
  45. data/ext/ca_obj_object.c +51 -37
  46. data/ext/ca_obj_record.c +74 -22
  47. data/ext/ca_obj_reduce.c +8 -10
  48. data/ext/ca_obj_refer.c +42 -29
  49. data/ext/ca_obj_remap.c +11 -29
  50. data/ext/ca_obj_repeat.c +41 -23
  51. data/ext/ca_obj_roll.c +18 -24
  52. data/ext/ca_obj_select.c +10 -22
  53. data/ext/ca_obj_select_axis.c +27 -36
  54. data/ext/ca_obj_shift.c +22 -42
  55. data/ext/ca_obj_source.c +1 -5
  56. data/ext/ca_obj_stack.c +28 -24
  57. data/ext/ca_obj_stride.c +53 -54
  58. data/ext/ca_obj_string.c +6 -18
  59. data/ext/ca_obj_tile.c +12 -12
  60. data/ext/ca_obj_time.c +12 -23
  61. data/ext/ca_obj_timedelta.c +12 -23
  62. data/ext/ca_obj_transpose.c +8 -10
  63. data/ext/ca_obj_triop.c +35 -39
  64. data/ext/ca_obj_window.c +67 -86
  65. data/ext/ca_op_cmplx64.h +4 -0
  66. data/ext/ca_op_ipower.c +34 -12
  67. data/ext/ca_op_powi.h +4 -0
  68. data/ext/ca_pow5_table.h +2 -1
  69. data/ext/ca_rng_normal.h +4 -0
  70. data/ext/ca_rng_xoshiro256pp.h +3 -0
  71. data/ext/ca_sort_kernels.h +20 -26
  72. data/ext/ca_sweep_engine.c +2 -3
  73. data/ext/ca_sweep_engine.h +17 -9
  74. data/ext/ca_transform_common.c +3 -8
  75. data/ext/ca_triop_dispatch.h +20 -32
  76. data/ext/caframe_csv_reader.c +11 -11
  77. data/ext/carray.h +300 -1011
  78. data/ext/carray_access.c +234 -180
  79. data/ext/carray_address_basis.c +33 -38
  80. data/ext/carray_attribute.c +81 -104
  81. data/ext/carray_bincount.c +12 -14
  82. data/ext/carray_broadcast.c +30 -26
  83. data/ext/carray_call_cfunc.c +169 -277
  84. data/ext/carray_call_cfunc.h +36 -28
  85. data/ext/carray_cast.c +912 -346
  86. data/ext/carray_cast_func.rb +31 -3
  87. data/ext/carray_class.c +6 -11
  88. data/ext/carray_conversion.c +43 -38
  89. data/ext/carray_copy.c +28 -26
  90. data/ext/carray_core.c +217 -126
  91. data/ext/carray_count.c +27 -15
  92. data/ext/carray_element.c +40 -25
  93. data/ext/carray_factorize.c +53 -52
  94. data/ext/carray_generate.c +26 -19
  95. data/ext/carray_histogram.c +8 -10
  96. data/ext/carray_hold.c +7 -9
  97. data/ext/carray_index_classifier.c +123 -228
  98. data/ext/carray_index_classifier.h +11 -10
  99. data/ext/carray_integer_total.c +523 -0
  100. data/ext/carray_internal.h +1274 -160
  101. data/ext/carray_key_windows.c +3 -3
  102. data/ext/carray_lazy.c +21 -36
  103. data/ext/carray_loop.c +19 -22
  104. data/ext/carray_mask.c +123 -145
  105. data/ext/carray_math_kernel.h +23 -47
  106. data/ext/carray_mathfunc.c +10 -3
  107. data/ext/carray_median_percentile.c +95 -94
  108. data/ext/carray_memory_view.c +42 -47
  109. data/ext/carray_operator.c +423 -122
  110. data/ext/carray_order.c +121 -85
  111. data/ext/carray_partition.c +13 -15
  112. data/ext/carray_random.c +47 -41
  113. data/ext/carray_round.c +9 -4
  114. data/ext/carray_scatter.c +54 -40
  115. data/ext/carray_segment.c +41 -45
  116. data/ext/carray_slab.c +64 -47
  117. data/ext/carray_slab.h +44 -33
  118. data/ext/carray_sort.c +32 -29
  119. data/ext/carray_sort_kernel.c +12 -10
  120. data/ext/carray_struct.c +38 -43
  121. data/ext/carray_test.c +47 -43
  122. data/ext/carray_time_text.c +24 -31
  123. data/ext/carray_undef.c +50 -7
  124. data/ext/carray_utils.c +258 -94
  125. data/ext/extconf.rb +24 -17
  126. data/ext/mk_call_cfunc.rb +19 -20
  127. data/ext/mk_pow5_table.rb +2 -1
  128. data/ext/mkkernel.rb +782 -461
  129. data/ext/ruby_carray.c +47 -42
  130. data/ext/version.h +7 -5
  131. data/lib/carray/attribute.rb +19 -18
  132. data/lib/carray/autoload_carray.rb +20 -15
  133. data/lib/carray/autoload_method_extension.rb +64 -57
  134. data/lib/carray/axis_group.rb +264 -180
  135. data/lib/carray/basics.rb +272 -48
  136. data/lib/carray/bincount_nd.rb +33 -16
  137. data/lib/carray/block_iterator.rb +123 -102
  138. data/lib/carray/boolean_reduce.rb +7 -4
  139. data/lib/carray/categorical.rb +63 -51
  140. data/lib/carray/categorical_iterator.rb +89 -67
  141. data/lib/carray/complex.rb +61 -41
  142. data/lib/carray/conditional.rb +49 -22
  143. data/lib/carray/const_string.rb +54 -62
  144. data/lib/carray/core_extensions.rb +1 -1
  145. data/lib/carray/distance_limit.rb +7 -5
  146. data/lib/carray/factories.rb +269 -0
  147. data/lib/carray/fixlen_string.rb +25 -24
  148. data/lib/carray/frame/column_verbs.rb +20 -8
  149. data/lib/carray/frame/concat.rb +3 -3
  150. data/lib/carray/frame/convert.rb +2 -1
  151. data/lib/carray/frame/csv_parser.rb +7 -1
  152. data/lib/carray/frame/frame.rb +35 -25
  153. data/lib/carray/frame/group.rb +183 -150
  154. data/lib/carray/frame/io.rb +26 -7
  155. data/lib/carray/frame/join.rb +37 -12
  156. data/lib/carray/frame/records.rb +1 -1
  157. data/lib/carray/frame/reshape.rb +3 -3
  158. data/lib/carray/frame/sort.rb +10 -8
  159. data/lib/carray/frame/verbs.rb +148 -118
  160. data/lib/carray/frame/windows.rb +232 -21
  161. data/lib/carray/frame.rb +1 -2
  162. data/lib/carray/fuse_source.rb +24 -21
  163. data/lib/carray/fusion.rb +30 -30
  164. data/lib/carray/histogram.rb +35 -16
  165. data/lib/carray/inspect.rb +7 -7
  166. data/lib/carray/iterator.rb +97 -24
  167. data/lib/carray/key_windows.rb +83 -57
  168. data/lib/carray/lazy.rb +196 -94
  169. data/lib/carray/limits.rb +80 -0
  170. data/lib/carray/mask_gap_fill.rb +21 -16
  171. data/lib/carray/math.rb +87 -50
  172. data/lib/carray/meld_reduce.rb +30 -8
  173. data/lib/carray/methods/align_addr.rb +29 -17
  174. data/lib/carray/methods/bin.rb +5 -1
  175. data/lib/carray/methods/bincount.rb +4 -2
  176. data/lib/carray/methods/bit_string.rb +19 -31
  177. data/lib/carray/methods/broadcast.rb +8 -3
  178. data/lib/carray/methods/choose.rb +5 -5
  179. data/lib/carray/methods/composition.rb +72 -71
  180. data/lib/carray/methods/{index.rb → coordinate.rb} +13 -13
  181. data/lib/carray/methods/discovery_along.rb +3 -3
  182. data/lib/carray/methods/gather_nd.rb +106 -106
  183. data/lib/carray/methods/insert_block.rb +2 -2
  184. data/lib/carray/methods/is_between.rb +6 -4
  185. data/lib/carray/methods/is_in.rb +165 -145
  186. data/lib/carray/methods/join.rb +2 -1
  187. data/lib/carray/methods/lag.rb +6 -2
  188. data/lib/carray/methods/locate_addr.rb +150 -138
  189. data/lib/carray/methods/mask_duplicates.rb +1 -1
  190. data/lib/carray/methods/meshgrid.rb +28 -16
  191. data/lib/carray/methods/mode.rb +67 -67
  192. data/lib/carray/methods/nunique.rb +9 -7
  193. data/lib/carray/methods/repeat.rb +12 -12
  194. data/lib/carray/methods/resize.rb +1 -1
  195. data/lib/carray/methods/snap.rb +24 -20
  196. data/lib/carray/methods/string_format.rb +2 -2
  197. data/lib/carray/methods/unique.rb +4 -2
  198. data/lib/carray/methods/value_counts.rb +1 -1
  199. data/lib/carray/mkmf.rb +25 -28
  200. data/lib/carray/percentile_arguments.rb +82 -0
  201. data/lib/carray/record_order.rb +18 -17
  202. data/lib/carray/rng.rb +1 -0
  203. data/lib/carray/runtime.rb +190 -22
  204. data/lib/carray/segment_iterator.rb +251 -129
  205. data/lib/carray/serialize.rb +618 -571
  206. data/lib/carray/slab_iterator.rb +114 -114
  207. data/lib/carray/stack.rb +11 -12
  208. data/lib/carray/string.rb +16 -22
  209. data/lib/carray/string_operation_extension.rb +76 -52
  210. data/lib/carray/struct.rb +122 -164
  211. data/lib/carray/struct_builder.rb +243 -72
  212. data/lib/carray/time.rb +496 -342
  213. data/lib/carray/window_iterator.rb +191 -150
  214. data/lib/carray.rb +6 -11
  215. data/yard-stubs/ca_obj_array.rb +20 -135
  216. data/yard-stubs/ca_obj_bitarray.rb +1 -8
  217. data/yard-stubs/ca_obj_bitfield.rb +4 -3
  218. data/yard-stubs/ca_obj_byte_swap.rb +21 -7
  219. data/yard-stubs/ca_obj_fake.rb +3 -1
  220. data/yard-stubs/ca_obj_farray.rb +1 -1
  221. data/yard-stubs/ca_obj_field.rb +8 -6
  222. data/yard-stubs/ca_obj_refer.rb +7 -5
  223. data/yard-stubs/ca_obj_roll.rb +7 -6
  224. data/yard-stubs/ca_obj_shift.rb +2 -3
  225. data/yard-stubs/ca_obj_stride.rb +5 -7
  226. data/yard-stubs/ca_obj_tile.rb +1 -1
  227. data/yard-stubs/ca_obj_time.rb +43 -0
  228. data/yard-stubs/ca_obj_transpose.rb +1 -1
  229. data/yard-stubs/ca_obj_window.rb +26 -15
  230. data/yard-stubs/carray_access.rb +51 -4
  231. data/yard-stubs/carray_attribute.rb +26 -38
  232. data/yard-stubs/carray_cast.rb +118 -165
  233. data/yard-stubs/carray_class.rb +3 -4
  234. data/yard-stubs/carray_conversion.rb +6 -7
  235. data/yard-stubs/carray_copy.rb +2 -1
  236. data/yard-stubs/carray_count.rb +5 -3
  237. data/yard-stubs/carray_element.rb +4 -3
  238. data/yard-stubs/carray_limits.rb +100 -0
  239. data/yard-stubs/carray_loop.rb +0 -20
  240. data/yard-stubs/carray_mask.rb +59 -41
  241. data/yard-stubs/carray_math.rb +157 -100
  242. data/yard-stubs/carray_mathfunc.rb +415 -3
  243. data/yard-stubs/carray_median_percentile.rb +29 -11
  244. data/yard-stubs/carray_memory_view.rb +2 -2
  245. data/yard-stubs/carray_order.rb +67 -34
  246. data/yard-stubs/carray_random.rb +6 -6
  247. data/yard-stubs/carray_reduce.rb +353 -0
  248. data/yard-stubs/carray_rng.rb +92 -0
  249. data/yard-stubs/carray_scatter.rb +10 -2
  250. data/yard-stubs/carray_slab.rb +7 -4
  251. data/yard-stubs/carray_sort.rb +7 -6
  252. data/yard-stubs/carray_undef.rb +44 -5
  253. data/yard-stubs/ruby_carray.rb +75 -40
  254. metadata +62 -24
  255. data/CHANGELOG.v1.md +0 -126
  256. data/ext/carray_build_flags.h +0 -3
  257. data/ext/carray_config.h +0 -28
  258. data/ext/carray_data_type.c +0 -90
  259. data/ext/carray_kernels_bincmp.c +0 -6457
  260. data/ext/carray_kernels_binop.c +0 -31534
  261. data/ext/carray_kernels_init.c +0 -1734
  262. data/ext/carray_kernels_moncmp.c +0 -2104
  263. data/ext/carray_kernels_monop.c +0 -25337
  264. data/ext/carray_kernels_reduce_aggregate.c +0 -27545
  265. data/ext/carray_kernels_reduce_boolean.c +0 -1924
  266. data/ext/carray_kernels_reduce_cumulative.c +0 -11646
  267. data/ext/carray_kernels_reduce_extreme.c +0 -21631
  268. data/ext/carray_kernels_reduce_variance.c +0 -5981
  269. data/ext/carray_kernels_scan.c +0 -4302
  270. data/ext/carray_kernels_search.c +0 -37776
  271. data/ext/carray_kernels_sort.c +0 -10814
  272. data/ext/carray_kernels_triop.c +0 -1864
  273. data/lib/carray/construct.rb +0 -360
  274. data/lib/carray/data_type_extension.rb +0 -262
  275. data/lib/carray/data_type_limits.rb +0 -91
@@ -1,7 +1,7 @@
1
1
  /* ---------------------------------------------------------------------------
2
2
 
3
3
  Attribute and predicate accessors for CArray (obj_type / data_type
4
- / ndim / shape / dim / bytes / elements + entity? / virtual? /
4
+ / ndim / shape / dim / bytes / elements + entity? / view? /
5
5
  fixlen? / boolean? / read_only? / mask_array? / etc.) plus the
6
6
  view-chain navigators parent / root_array / ancestors.
7
7
 
@@ -13,68 +13,67 @@
13
13
 
14
14
  #include "carray.h"
15
15
  #include "ca_obj_face.h" /* CA_OBJ_RECORD + rb_ca_record_get_data_class */
16
- #include "carray_internal.h" /* rb_ca_inherit_attr */
17
16
 
18
17
  /* ------------------------------------------------------------------- */
19
18
 
20
19
  VALUE
21
- rb_ca_obj_type (VALUE self)
20
+ rb_ca_obj_type (volatile VALUE self)
22
21
  {
23
22
  CArray *ca;
24
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
23
+ GetCArray(self, ca);
25
24
  return INT2NUM(ca->obj_type);
26
25
  }
27
26
 
28
27
  VALUE
29
- rb_ca_data_type (VALUE self)
28
+ rb_ca_data_type (volatile VALUE self)
30
29
  {
31
30
  CArray *ca;
32
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
31
+ GetCArray(self, ca);
33
32
  /* Return a Symbol via the pre-computed ID cache; the C internal
34
33
  int8_t representation is unchanged. */
35
34
  return ID2SYM(ca_data_type_sym[ca->data_type]);
36
35
  }
37
36
 
38
37
  VALUE
39
- rb_ca_ndim (VALUE self)
38
+ rb_ca_ndim (volatile VALUE self)
40
39
  {
41
40
  CArray *ca;
42
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
41
+ GetCArray(self, ca);
43
42
  return INT2NUM(ca->ndim);
44
43
  }
45
44
 
46
45
  VALUE
47
- rb_ca_bytes (VALUE self)
46
+ rb_ca_bytes (volatile VALUE self)
48
47
  {
49
48
  CArray *ca;
50
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
49
+ GetCArray(self, ca);
51
50
  return SIZE2NUM(ca->bytes);
52
51
  }
53
52
 
54
53
  VALUE
55
- rb_ca_flags (VALUE self)
54
+ rb_ca_flags (volatile VALUE self)
56
55
  {
57
56
  CArray *ca;
58
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
57
+ GetCArray(self, ca);
59
58
  return INT2NUM(ca->flags);
60
59
  }
61
60
 
62
61
  VALUE
63
- rb_ca_elements (VALUE self)
62
+ rb_ca_elements (volatile VALUE self)
64
63
  {
65
64
  CArray *ca;
66
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
65
+ GetCArray(self, ca);
67
66
  return SIZE2NUM(ca->elements);
68
67
  }
69
68
 
70
69
  VALUE
71
- rb_ca_dim (VALUE self)
70
+ rb_ca_dim (volatile VALUE self)
72
71
  {
73
72
  volatile VALUE dim;
74
73
  CArray *ca;
75
74
  int i;
76
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
77
- dim = rb_ary_new2(ca->ndim);
75
+ GetCArray(self, ca);
76
+ dim = rb_ary_new_capa(ca->ndim);
78
77
  for (i=0; i<ca->ndim; i++) {
79
78
  rb_ary_store(dim, i, SIZE2NUM(ca->dim[i]));
80
79
  }
@@ -82,43 +81,11 @@ rb_ca_dim (VALUE self)
82
81
  }
83
82
 
84
83
  VALUE
85
- rb_ca_dim0 (VALUE self)
84
+ rb_ca_data_type_name (volatile VALUE self)
86
85
  {
87
86
  CArray *ca;
88
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
89
- return SIZE2NUM(ca->dim[0]);
90
- }
91
-
92
- VALUE
93
- rb_ca_dim1 (VALUE self)
94
- {
95
- CArray *ca;
96
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
97
- return ( ca->ndim >= 2 ) ? SIZE2NUM(ca->dim[1]) : Qnil;
98
- }
99
-
100
- VALUE
101
- rb_ca_dim2 (VALUE self)
102
- {
103
- CArray *ca;
104
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
105
- return ( ca->ndim >= 3 ) ? SIZE2NUM(ca->dim[2]) : Qnil;
106
- }
107
-
108
- VALUE
109
- rb_ca_dim3 (VALUE self)
110
- {
111
- CArray *ca;
112
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
113
- return ( ca->ndim >= 4 ) ? SIZE2NUM(ca->dim[3]) : Qnil;
114
- }
115
-
116
- VALUE
117
- rb_ca_data_type_name (VALUE self)
118
- {
119
- CArray *ca;
120
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
121
- return rb_str_new2(ca_type_name[ca->data_type]);
87
+ GetCArray(self, ca);
88
+ return rb_str_new_cstr(ca_type_name[ca->data_type]);
122
89
  }
123
90
 
124
91
  /* ------------------------------------------------------------------- */
@@ -131,19 +98,19 @@ ca_is_scalar (void *ap)
131
98
  }
132
99
 
133
100
  VALUE
134
- rb_ca_is_scalar (VALUE self)
101
+ rb_ca_is_scalar (volatile VALUE self)
135
102
  {
136
103
  CArray *ca;
137
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
104
+ GetCArray(self, ca);
138
105
  return ( ca_is_scalar(ca) ) ? Qtrue : Qfalse;
139
106
  }
140
107
 
141
108
  VALUE
142
- rb_obj_is_cscalar (VALUE obj)
109
+ rb_obj_is_cscalar (volatile VALUE obj)
143
110
  {
144
111
  CArray *ca;
145
112
  if ( rb_obj_is_carray(obj) ) {
146
- TypedData_Get_Struct(obj, CArray, &carray_data_type, ca);
113
+ GetCArray(obj, ca);
147
114
  return ( ca_is_scalar(ca) ) ? Qtrue : Qfalse;
148
115
  }
149
116
  return Qfalse;
@@ -159,38 +126,38 @@ ca_is_view (void *ap)
159
126
  }
160
127
 
161
128
  VALUE
162
- rb_ca_is_entity (VALUE self)
129
+ rb_ca_is_entity (volatile VALUE self)
163
130
  {
164
131
  CArray *ca;
165
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
132
+ GetCArray(self, ca);
166
133
  return ( ca_is_view(ca) ) ? Qfalse : Qtrue;
167
134
  }
168
135
 
169
136
  VALUE
170
- rb_ca_is_virtual (VALUE self)
137
+ rb_ca_is_virtual (volatile VALUE self)
171
138
  {
172
139
  CArray *ca;
173
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
140
+ GetCArray(self, ca);
174
141
  return ( ca_is_view(ca) ) ? Qtrue : Qfalse;
175
142
  }
176
143
 
177
144
  /* ------------------------------------------------------------------- */
178
145
 
179
146
  VALUE
180
- rb_ca_is_attached (VALUE self)
147
+ rb_ca_is_attached (volatile VALUE self)
181
148
  {
182
149
  CArray *ca;
183
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
150
+ GetCArray(self, ca);
184
151
  return ( ca_is_attached(ca) ) ? Qtrue : Qfalse;
185
152
  }
186
153
 
187
154
  /* ------------------------------------------------------------------- */
188
155
 
189
156
  VALUE
190
- rb_ca_is_empty (VALUE self)
157
+ rb_ca_is_empty (volatile VALUE self)
191
158
  {
192
159
  CArray *ca;
193
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
160
+ GetCArray(self, ca);
194
161
  return ( ca->elements == 0 ) ? Qtrue : Qfalse;
195
162
  }
196
163
 
@@ -200,6 +167,11 @@ int
200
167
  ca_is_readonly (void *ap)
201
168
  {
202
169
  CArray *ca = (CArray *) ap;
170
+ /* Asked once per cell written; an entity answers without recursing, so
171
+ only a view checks the stack. */
172
+ if ( ! ca_is_entity(ca) ) {
173
+ ca_check_stack_room();
174
+ }
203
175
  if ( ca_test_flag(ca, CA_FLAG_READ_ONLY) ) { /* test -> true */
204
176
  return 1;
205
177
  }
@@ -236,10 +208,10 @@ ca_is_readonly (void *ap)
236
208
  }
237
209
 
238
210
  VALUE
239
- rb_ca_is_read_only (VALUE self)
211
+ rb_ca_is_read_only (volatile VALUE self)
240
212
  {
241
213
  CArray *ca;
242
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
214
+ GetCArray(self, ca);
243
215
  return ( ca_is_readonly(ca) ) ? Qtrue : Qfalse;
244
216
  }
245
217
 
@@ -249,6 +221,7 @@ int
249
221
  ca_is_mask_array (void *ap)
250
222
  {
251
223
  CArray *ca = (CArray *) ap;
224
+ ca_check_stack_room();
252
225
  if ( ca_test_flag(ca, CA_FLAG_MASK_ARRAY) ) { /* test -> true */
253
226
  return 1;
254
227
  }
@@ -269,10 +242,10 @@ ca_is_mask_array (void *ap)
269
242
  }
270
243
 
271
244
  VALUE
272
- rb_ca_is_mask_array (VALUE self)
245
+ rb_ca_is_mask_array (volatile VALUE self)
273
246
  {
274
247
  CArray *ca;
275
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
248
+ GetCArray(self, ca);
276
249
  return ( ca_is_mask_array(ca) ) ? Qtrue : Qfalse;
277
250
  }
278
251
 
@@ -282,6 +255,7 @@ int
282
255
  ca_is_value_array (void *ap)
283
256
  {
284
257
  CArray *ca = (CArray *) ap;
258
+ ca_check_stack_room();
285
259
  if ( ca_test_flag(ca, CA_FLAG_VALUE_ARRAY) ) { /* test -> true */
286
260
  return 1;
287
261
  }
@@ -302,20 +276,20 @@ ca_is_value_array (void *ap)
302
276
  }
303
277
 
304
278
  VALUE
305
- rb_ca_is_value_array (VALUE self)
279
+ rb_ca_is_value_array (volatile VALUE self)
306
280
  {
307
281
  CArray *ca;
308
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
282
+ GetCArray(self, ca);
309
283
  return ( ca_is_value_array(ca) ) ? Qtrue : Qfalse;
310
284
  }
311
285
 
312
286
  /* ------------------------------------------------------------------- */
313
287
 
314
288
  VALUE
315
- rb_ca_is_face (VALUE self)
289
+ rb_ca_is_face (volatile VALUE self)
316
290
  {
317
291
  CArray *ca;
318
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
292
+ GetCArray(self, ca);
319
293
  return ( ca_is_face(ca) ) ? Qtrue : Qfalse;
320
294
  }
321
295
 
@@ -329,10 +303,10 @@ ca_is_fixlen_type (void *ap)
329
303
  }
330
304
 
331
305
  VALUE
332
- rb_ca_is_fixlen_type (VALUE self)
306
+ rb_ca_is_fixlen_type (volatile VALUE self)
333
307
  {
334
308
  CArray *ca;
335
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
309
+ GetCArray(self, ca);
336
310
  return ca_is_fixlen_type(ca) ? Qtrue : Qfalse;
337
311
  }
338
312
 
@@ -346,10 +320,10 @@ ca_is_boolean_type (void *ap)
346
320
  }
347
321
 
348
322
  VALUE
349
- rb_ca_is_boolean_type (VALUE self)
323
+ rb_ca_is_boolean_type (volatile VALUE self)
350
324
  {
351
325
  CArray *ca;
352
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
326
+ GetCArray(self, ca);
353
327
  return ca_is_boolean_type(ca) ? Qtrue : Qfalse;
354
328
  }
355
329
 
@@ -364,10 +338,10 @@ ca_is_numeric_type (void *ap)
364
338
  }
365
339
 
366
340
  VALUE
367
- rb_ca_is_numeric_type (VALUE self)
341
+ rb_ca_is_numeric_type (volatile VALUE self)
368
342
  {
369
343
  CArray *ca;
370
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
344
+ GetCArray(self, ca);
371
345
  return ca_is_numeric_type(ca) ? Qtrue : Qfalse;
372
346
  }
373
347
 
@@ -382,10 +356,10 @@ ca_is_integer_type (void *ap)
382
356
  }
383
357
 
384
358
  VALUE
385
- rb_ca_is_integer_type (VALUE self)
359
+ rb_ca_is_integer_type (volatile VALUE self)
386
360
  {
387
361
  CArray *ca;
388
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
362
+ GetCArray(self, ca);
389
363
  return ca_is_integer_type(ca) ? Qtrue : Qfalse;
390
364
  }
391
365
 
@@ -400,10 +374,10 @@ ca_is_float_type (void *ap)
400
374
  }
401
375
 
402
376
  VALUE
403
- rb_ca_is_float_type (VALUE self)
377
+ rb_ca_is_float_type (volatile VALUE self)
404
378
  {
405
379
  CArray *ca;
406
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
380
+ GetCArray(self, ca);
407
381
  return ca_is_float_type(ca) ? Qtrue : Qfalse;
408
382
  }
409
383
 
@@ -418,10 +392,10 @@ ca_is_complex_type (void *ap)
418
392
  }
419
393
 
420
394
  VALUE
421
- rb_ca_is_complex_type (VALUE self)
395
+ rb_ca_is_complex_type (volatile VALUE self)
422
396
  {
423
397
  CArray *ca;
424
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
398
+ GetCArray(self, ca);
425
399
  return ca_is_complex_type(ca) ? Qtrue : Qfalse;
426
400
  }
427
401
 
@@ -435,10 +409,10 @@ ca_is_object_type (void *ap)
435
409
  }
436
410
 
437
411
  VALUE
438
- rb_ca_is_object_type (VALUE self)
412
+ rb_ca_is_object_type (volatile VALUE self)
439
413
  {
440
414
  CArray *ca;
441
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
415
+ GetCArray(self, ca);
442
416
  return ca_is_object_type(ca) ? Qtrue : Qfalse;
443
417
  }
444
418
 
@@ -537,17 +511,20 @@ ca_note_view_of_lent (CArray *p)
537
511
  }
538
512
 
539
513
  VALUE
540
- rb_ca_set_parent (VALUE self, VALUE obj)
514
+ rb_ca_set_parent (volatile VALUE self, volatile VALUE obj)
541
515
  {
542
516
  rb_ivar_set(self, id_parent, obj);
543
517
  /* A view of an array lent to a CAObject hook outlives the hook: tell the
544
518
  array, so that it keeps its cells when the hook returns. A view of
545
519
  several arrays names one here and holds the rest in parents[]. */
546
520
  if ( rb_obj_is_carray(obj) ) {
547
- ca_note_view_of_lent((CArray *) DATA_PTR(obj));
521
+ CArray *cp;
522
+ GetCArray(obj, cp);
523
+ ca_note_view_of_lent(cp);
548
524
  }
549
525
  if ( rb_obj_is_carray(self) ) {
550
- CArray *ca = (CArray *) DATA_PTR(self);
526
+ CArray *ca;
527
+ GetCArray(self, ca);
551
528
  if ( ca_test_flag(ca, CA_FLAG_MULTI_PARENTS) ) {
552
529
  CAMultiParent *mp = (CAMultiParent *) ca;
553
530
  int32_t k;
@@ -562,10 +539,10 @@ rb_ca_set_parent (VALUE self, VALUE obj)
562
539
  /* ------------------------------------------------------------------- */
563
540
 
564
541
  VALUE
565
- rb_ca_data_class (VALUE self)
542
+ rb_ca_data_class (volatile VALUE self)
566
543
  {
567
544
  CArray *ca;
568
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
545
+ GetCArray(self, ca);
569
546
  /* Only a Face carries data_class; a non-Face CArray is always
570
547
  Qnil. CARecord stores it in its tail (reached directly via
571
548
  obj_type, no Ruby roundtrip); numeric Faces such as
@@ -607,6 +584,7 @@ CArray *
607
584
  ca_root_array (void *ap)
608
585
  {
609
586
  CArray *ca = (CArray *)ap;
587
+ ca_check_stack_room();
610
588
  if ( ca_is_entity(ca) ) {
611
589
  return ca;
612
590
  }
@@ -638,6 +616,7 @@ ca_shares_root (void *ap, void *aq)
638
616
  {
639
617
  CArray *ra = ca_root_array(ap);
640
618
  CArray *rb = ca_root_array(aq);
619
+ ca_check_stack_room();
641
620
  if ( ra == rb ) {
642
621
  return 1;
643
622
  }
@@ -665,21 +644,22 @@ ca_shares_root (void *ap, void *aq)
665
644
  /* Whether self and other may share memory (ca_shares_root), for the plan
666
645
  reader that keeps an evaluator off a store reading what it writes. */
667
646
  static VALUE
668
- rb_ca_storage_overlaps (VALUE self, VALUE other)
647
+ rb_ca_storage_overlaps (volatile VALUE self, volatile VALUE other)
669
648
  {
670
649
  CArray *ca, *cb;
671
650
  rb_check_carray_object(other);
672
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
673
- TypedData_Get_Struct(other, CArray, &carray_data_type, cb);
651
+ GetCArray(self, ca);
652
+ GetCArray(other, cb);
674
653
  return ca_shares_root(ca, cb) ? Qtrue : Qfalse;
675
654
  }
676
655
 
677
656
  static VALUE
678
- rb_ca_root_array (VALUE self)
657
+ rb_ca_root_array (volatile VALUE self)
679
658
  {
680
659
  volatile VALUE refary;
681
660
  CArray *ca;
682
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
661
+ ca_check_stack_room();
662
+ GetCArray(self, ca);
683
663
  if ( ca_is_entity(ca) ) {
684
664
  return self;
685
665
  }
@@ -700,11 +680,12 @@ rb_ca_root_array (VALUE self)
700
680
  /* ------------------------------------------------------------------- */
701
681
 
702
682
  static VALUE
703
- rb_ca_ancestors_loop (VALUE self, VALUE list)
683
+ rb_ca_ancestors_loop (volatile VALUE self, VALUE list)
704
684
  {
705
685
  volatile VALUE refary;
706
686
  CArray *ca;
707
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
687
+ ca_check_stack_room();
688
+ GetCArray(self, ca);
708
689
  rb_ary_unshift(list, self);
709
690
  if ( ca_is_entity(ca) ) {
710
691
  return list;
@@ -748,17 +729,13 @@ Init_carray_attribute (void)
748
729
  rb_define_method(rb_cCArray, "ndim", rb_ca_ndim, 0);
749
730
  rb_define_method(rb_cCArray, "shape", rb_ca_dim, 0);
750
731
  rb_define_method(rb_cCArray, "dim", rb_ca_dim, 0);
751
- rb_define_method(rb_cCArray, "dim0", rb_ca_dim0, 0);
752
- rb_define_method(rb_cCArray, "dim1", rb_ca_dim1, 0);
753
- rb_define_method(rb_cCArray, "dim2", rb_ca_dim2, 0);
754
- rb_define_method(rb_cCArray, "dim3", rb_ca_dim3, 0);
755
732
  rb_define_method(rb_cCArray, "elements", rb_ca_elements, 0);
756
733
  rb_define_method(rb_cCArray, "length", rb_ca_elements, 0);
757
734
  rb_define_method(rb_cCArray, "size", rb_ca_elements, 0);
758
735
 
759
736
  rb_define_method(rb_cCArray, "data_type_name", rb_ca_data_type_name, 0);
760
737
 
761
- rb_define_method(rb_cCArray, "parent", rb_ca_parent, 0);
738
+ rb_define_method(rb_cCArray, "parent", rb_ca_parent_method, 0);
762
739
  rb_define_private_method(rb_cCArray, "attribute_parent", rb_ca_attribute_parent, 0);
763
740
 
764
741
  rb_define_method(rb_cCArray, "data_class", rb_ca_data_class, 0);
@@ -767,7 +744,7 @@ Init_carray_attribute (void)
767
744
  rb_define_method(rb_cCArray, "scalar?", rb_ca_is_scalar, 0);
768
745
 
769
746
  rb_define_method(rb_cCArray, "entity?", rb_ca_is_entity, 0);
770
- rb_define_method(rb_cCArray, "virtual?", rb_ca_is_virtual, 0);
747
+ rb_define_method(rb_cCArray, "view?", rb_ca_is_virtual, 0);
771
748
  rb_define_method(rb_cCArray, "value_array?", rb_ca_is_value_array, 0);
772
749
  rb_define_method(rb_cCArray, "mask_array?", rb_ca_is_mask_array, 0);
773
750
  rb_define_method(rb_cCArray, "face?", rb_ca_is_face, 0);
@@ -24,8 +24,6 @@
24
24
  kernels __bincount_count__(length) and
25
25
  __bincount_weighted__(weights, length).
26
26
 
27
- Design: devel/PROPOSAL_BINCOUNT_DEDICATED_KERNEL.md.
28
-
29
27
  --------------------------------------------------------------------------- */
30
28
 
31
29
  #include "carray.h"
@@ -72,7 +70,7 @@
72
70
  } \
73
71
  } while (0)
74
72
 
75
- /* Checked before a window opens: the dispatches above raise on a type
73
+ /* Checked before anything is attached: the dispatches above raise on a type
76
74
  they do not cover, which would leave the labels (and weights) attached. */
77
75
  static void
78
76
  bincount_check_types (CArray *cl, CArray *cw)
@@ -105,16 +103,16 @@ bincount_check_types (CArray *cl, CArray *cw)
105
103
  self. Allocates a zero-filled UInt32 (or UInt64 if length >= 2^32)
106
104
  output of size `length`, then runs the 8-way label dispatch. */
107
105
  static VALUE
108
- rb_ca_bincount_count_kernel (VALUE self, VALUE rlength)
106
+ rb_ca_bincount_count_kernel (volatile VALUE self, VALUE rlength)
109
107
  {
110
108
  CArray *cl, *co;
111
- VALUE vout;
109
+ volatile VALUE vout;
112
110
  ca_size_t i, n, length;
113
111
  ca_size_t shape_out[1];
114
112
  boolean8_t *mlabel;
115
113
  int out_type;
116
114
 
117
- TypedData_Get_Struct(self, CArray, &carray_data_type, cl);
115
+ GetCArray(self, cl);
118
116
  length = (ca_size_t) NUM2SIZET(rlength);
119
117
  if ( length < 0 ) {
120
118
  rb_raise(rb_eArgError, "bincount: length must be non-negative");
@@ -124,7 +122,7 @@ rb_ca_bincount_count_kernel (VALUE self, VALUE rlength)
124
122
  out_type = (length > 0xFFFFFFFFLL) ? CA_UINT64 : CA_UINT32;
125
123
  shape_out[0] = length;
126
124
  vout = rb_carray_new(out_type, 1, shape_out, 0, NULL);
127
- TypedData_Get_Struct(vout, CArray, &carray_data_type, co);
125
+ GetCArray(vout, co);
128
126
 
129
127
  /* Zero-fill output (we own it, just allocated). */
130
128
  memset(co->ptr, 0, (size_t) co->bytes * (size_t) co->elements);
@@ -134,7 +132,7 @@ rb_ca_bincount_count_kernel (VALUE self, VALUE rlength)
134
132
  }
135
133
 
136
134
  bincount_check_types(cl, NULL);
137
- ca_attach(cl); /* window: nothing raises inside */
135
+ ca_attach(cl); /* attach: nothing raises before the detach */
138
136
  n = cl->elements;
139
137
  mlabel = cl->mask ? (boolean8_t *) cl->mask->ptr : NULL;
140
138
 
@@ -211,17 +209,17 @@ rb_ca_bincount_count_kernel (VALUE self, VALUE rlength)
211
209
  (integer + float; the inner WEIGHTED_KERNEL macro branches over the
212
210
  four mask combinations). */
213
211
  static VALUE
214
- rb_ca_bincount_weighted_kernel (VALUE self, VALUE rweights, VALUE rlength)
212
+ rb_ca_bincount_weighted_kernel (volatile VALUE self, volatile VALUE rweights, VALUE rlength)
215
213
  {
216
214
  CArray *cl, *cw, *co;
217
- VALUE vout;
215
+ volatile VALUE vout;
218
216
  ca_size_t i, n, length;
219
217
  ca_size_t shape_out[1];
220
218
  boolean8_t *mlabel, *mweight;
221
219
  int w_type;
222
220
 
223
- TypedData_Get_Struct(self, CArray, &carray_data_type, cl);
224
- TypedData_Get_Struct(rweights, CArray, &carray_data_type, cw);
221
+ GetCArray(self, cl);
222
+ GetCArray(rweights, cw);
225
223
  length = (ca_size_t) NUM2SIZET(rlength);
226
224
  if ( length < 0 ) {
227
225
  rb_raise(rb_eArgError, "bincount: length must be non-negative");
@@ -235,7 +233,7 @@ rb_ca_bincount_weighted_kernel (VALUE self, VALUE rweights, VALUE rlength)
235
233
  w_type = cw->data_type;
236
234
  shape_out[0] = length;
237
235
  vout = rb_carray_new(w_type, 1, shape_out, 0, NULL);
238
- TypedData_Get_Struct(vout, CArray, &carray_data_type, co);
236
+ GetCArray(vout, co);
239
237
 
240
238
  memset(co->ptr, 0, (size_t) co->bytes * (size_t) co->elements);
241
239
 
@@ -244,7 +242,7 @@ rb_ca_bincount_weighted_kernel (VALUE self, VALUE rweights, VALUE rlength)
244
242
  }
245
243
 
246
244
  bincount_check_types(cl, cw);
247
- ca_attach_n(2, cl, cw); /* window: nothing raises inside */
245
+ ca_attach_n(2, cl, cw); /* attach: nothing raises before the detach */
248
246
  n = cl->elements;
249
247
  mlabel = cl->mask ? (boolean8_t *) cl->mask->ptr : NULL;
250
248
  mweight = cw->mask ? (boolean8_t *) cw->mask->ptr : NULL;