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
@@ -18,20 +18,10 @@
18
18
  ---------------------------------------------------------------------------- */
19
19
 
20
20
  #include "carray.h"
21
- #include "carray_internal.h" /* ca_select_snapshot */
22
21
 
23
22
  typedef struct {
24
23
  /* CAView prefix (mirrors carray.h ca_virtual layout) */
25
- int16_t obj_type;
26
- int8_t data_type;
27
- int8_t ndim;
28
- int32_t flags;
29
- ca_size_t bytes;
30
- ca_size_t elements;
31
- ca_size_t *dim;
32
- char *ptr;
33
- CArray *mask;
34
- char *_pool; /* framework-managed pool buffer (NULL = legacy ALLOC_N path). */
24
+ CA_ARRAY_HEADER
35
25
  CArray *parent;
36
26
  uint32_t attach;
37
27
  uint8_t nosync;
@@ -99,7 +89,7 @@ const rb_data_type_t caselectaxis_data_type = {
99
89
 
100
90
  const rb_data_type_t caselectaxis_mask_data_type = {
101
91
  .parent = &caselectaxis_data_type,
102
- .wrap_struct_name = "CASelectAxisMask",
92
+ .wrap_struct_name = "CASelectAxis::Mask",
103
93
  .function = {
104
94
  .dmark = NULL,
105
95
  .dfree = ca_free_nop,
@@ -109,7 +99,7 @@ const rb_data_type_t caselectaxis_mask_data_type = {
109
99
  .flags = RUBY_TYPED_FREE_IMMEDIATELY
110
100
  };
111
101
 
112
- static int8_t CA_OBJ_SELECT_AXIS;
102
+ static int16_t CA_OBJ_SELECT_AXIS;
113
103
 
114
104
  /* Benchmark-only bypass flag: when non-zero, rb_ca_grid skips the
115
105
  CASelectAxis dispatch hook and falls through to the pre-CSA CAGrid path.
@@ -174,7 +164,9 @@ ca_select_axis_setup (CASelectAxis *ca, CArray *parent, int8_t indirect_axis,
174
164
  }
175
165
  if ( selector->dim[0] != parent->dim[indirect_axis] ) {
176
166
  rb_raise(rb_eArgError,
177
- "CASelectAxis: selector length (%lld) != parent dim[%d] (%lld)",
167
+ "%s: boolean selector of %lld elements for axis %d of length %lld "
168
+ "(one element per index along the axis)",
169
+ ca_calling_method_name(),
178
170
  (long long) selector->dim[0],
179
171
  (int) indirect_axis,
180
172
  (long long) parent->dim[indirect_axis]);
@@ -819,14 +811,14 @@ ca_select_axis_func_fill_data (void *ap, void *val)
819
811
  sync. Where that attach is a gather rather than an alias, the cells this
820
812
  view did not select make the round trip for nothing -- and through a
821
813
  lossy layer they do not come back the same. Hand each slab to the parent
822
- as a region instead. (PROPOSAL_PARTIAL_FILL_WHOLE_ROOT_WRITEBACK.md) */
814
+ as a region instead. */
823
815
  if ( !ca_is_attached(ca->parent) && !ca_attach_is_alias(ca->parent) ) {
824
816
  ca_axis_dispatch_fill_value_via_parent(ca->parent, pdims, desc, ca->ndim,
825
817
  ca->bytes, ca->elements, val);
826
818
  return;
827
819
  }
828
820
 
829
- ca_attach(ca->parent); /* window: nothing raises inside */
821
+ ca_attach(ca->parent); /* attach: nothing raises before the detach */
830
822
  ca_axis_dispatch_fill_value(ca->parent, pdims, desc, ca->ndim, ca->bytes,
831
823
  ca->elements, val);
832
824
  ca_sync_detach(ca->parent);
@@ -872,7 +864,7 @@ rb_ca_select_axis_s_allocate (VALUE klass)
872
864
  }
873
865
 
874
866
  static VALUE
875
- rb_ca_select_axis_initialize_copy (VALUE self, VALUE other)
867
+ rb_ca_select_axis_initialize_copy (volatile VALUE self, volatile VALUE other)
876
868
  {
877
869
  CASelectAxis *ca, *cs;
878
870
  TypedData_Get_Struct(self, CASelectAxis, &caselectaxis_data_type, ca);
@@ -895,8 +887,8 @@ rb_ca_select_axis_initialize_copy (VALUE self, VALUE other)
895
887
  are ignored. Intended for testing only; production dispatch runs
896
888
  through rb_ca_select_axis (from the `[]` indexer in carray_access.c). */
897
889
  static VALUE
898
- rb_ca_select_axis_s_new_debug (VALUE klass, VALUE rparent, VALUE rindirect,
899
- VALUE rselector, VALUE rap_start,
890
+ rb_ca_select_axis_s_new_debug (VALUE klass, volatile VALUE rparent, VALUE rindirect,
891
+ volatile VALUE rselector, VALUE rap_start,
900
892
  VALUE rap_count, VALUE rap_step)
901
893
  {
902
894
  CArray *parent, *selector;
@@ -911,8 +903,8 @@ rb_ca_select_axis_s_new_debug (VALUE klass, VALUE rparent, VALUE rindirect,
911
903
  Check_Type(rap_count, T_ARRAY);
912
904
  Check_Type(rap_step, T_ARRAY);
913
905
 
914
- TypedData_Get_Struct(rparent, CArray, &carray_data_type, parent);
915
- TypedData_Get_Struct(rselector, CArray, &carray_data_type, selector);
906
+ GetCArray(rparent, parent);
907
+ GetCArray(rselector, selector);
916
908
 
917
909
  ndim = parent->ndim;
918
910
  if ( RARRAY_LEN(rap_start) != ndim ||
@@ -955,7 +947,7 @@ rb_ca_select_axis_s_new_debug (VALUE klass, VALUE rparent, VALUE rindirect,
955
947
  Other configurations (interleaved AP+INDIRECT, indirect inner, AP with
956
948
  step != 1) are routed to CAGrid to avoid regressions. */
957
949
  int
958
- rb_ca_select_axis_eligible_p (int argc, VALUE *argv, VALUE self)
950
+ rb_ca_select_axis_eligible_p (int argc, VALUE *argv, volatile VALUE self)
959
951
  {
960
952
  CArray *ca;
961
953
  int i;
@@ -969,7 +961,7 @@ rb_ca_select_axis_eligible_p (int argc, VALUE *argv, VALUE self)
969
961
  if ( ! rb_obj_is_carray(argv[0]) ) return 0;
970
962
  if ( ! rb_ca_is_boolean_type(argv[0]) ) return 0;
971
963
 
972
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
964
+ GetCArray(self, ca);
973
965
  if ( argc != ca->ndim ) return 0;
974
966
 
975
967
  /* axis 0 is the boolean (indirect). The rest are read as the indexer
@@ -989,7 +981,7 @@ rb_ca_select_axis_eligible_p (int argc, VALUE *argv, VALUE self)
989
981
  /* Construct a CASelectAxis from the indexer's argc/argv. Assumes
990
982
  rb_ca_select_axis_eligible_p has already returned 1. */
991
983
  VALUE
992
- rb_ca_select_axis (int argc, VALUE *argv, VALUE self)
984
+ rb_ca_select_axis (int argc, VALUE *argv, volatile VALUE self)
993
985
  {
994
986
  CArray *parent;
995
987
  CArray *selector = NULL;
@@ -1002,7 +994,7 @@ rb_ca_select_axis (int argc, VALUE *argv, VALUE self)
1002
994
  CASelectAxis *ca;
1003
995
  int i;
1004
996
 
1005
- TypedData_Get_Struct(self, CArray, &carray_data_type, parent);
997
+ GetCArray(self, parent);
1006
998
 
1007
999
  if ( argc != parent->ndim ) {
1008
1000
  rb_raise(rb_eArgError,
@@ -1017,7 +1009,7 @@ rb_ca_select_axis (int argc, VALUE *argv, VALUE self)
1017
1009
  &ap_start[i], &ap_count[i], &ap_step[i]);
1018
1010
  }
1019
1011
  else if ( rb_obj_is_carray(arg) && rb_ca_is_boolean_type(arg) ) {
1020
- TypedData_Get_Struct(arg, CArray, &carray_data_type, selector);
1012
+ GetCArray(arg, selector);
1021
1013
  indirect_axis = (int8_t) i;
1022
1014
  rselector_keep = arg;
1023
1015
  ap_start[i] = 0;
@@ -1097,14 +1089,14 @@ ca_select_axis_describe_axes (void *ap, ca_axis_desc_t *out,
1097
1089
  * or `CARRAY_DEV=1 rake build_ext`). They expose the per-axis descriptor
1098
1090
  * and the engine's raw output to Ruby so spec_ai can pin them; nothing in
1099
1091
  * lib/ or the rest of ext/ consumes them. CAGrid carries the same four
1100
- * under the same fence.
1092
+ * under the same #ifdef.
1101
1093
  * ============================================================ */
1102
1094
 
1103
1095
  /* Returns an Array of per-axis Arrays:
1104
1096
  STRIDE axis -> [:stride, count, start, step]
1105
1097
  INDEX axis -> [:index, count, [indices...]] */
1106
1098
  static VALUE
1107
- rb_ca_select_axis_describe_axes (VALUE self)
1099
+ rb_ca_select_axis_describe_axes (volatile VALUE self)
1108
1100
  {
1109
1101
  CASelectAxis *ca;
1110
1102
  ca_axis_desc_t desc[CA_RANK_MAX];
@@ -1143,7 +1135,7 @@ rb_ca_select_axis_describe_axes (VALUE self)
1143
1135
  Compared against `view.to_ca.dump_binary` in tests to verify binary
1144
1136
  equality with the existing attach path. */
1145
1137
  static VALUE
1146
- rb_ca_select_axis_dispatch_attach_debug (VALUE self)
1138
+ rb_ca_select_axis_dispatch_attach_debug (volatile VALUE self)
1147
1139
  {
1148
1140
  CASelectAxis *ca;
1149
1141
  ca_axis_desc_t desc[CA_RANK_MAX];
@@ -1154,7 +1146,7 @@ rb_ca_select_axis_dispatch_attach_debug (VALUE self)
1154
1146
  TypedData_Get_Struct(self, CASelectAxis, &caselectaxis_data_type, ca);
1155
1147
  ca_select_axis_describe_axes(ca, desc, pdims);
1156
1148
 
1157
- ca_attach(ca->parent); /* window: nothing raises inside */
1149
+ ca_attach(ca->parent); /* attach: nothing raises before the detach */
1158
1150
  buf = ca_axis_dispatch_attach(ca->parent, pdims, desc, ca->ndim, ca->bytes,
1159
1151
  ca->elements, NULL);
1160
1152
  ca_detach(ca->parent);
@@ -1169,7 +1161,7 @@ rb_ca_select_axis_dispatch_attach_debug (VALUE self)
1169
1161
  compare the resulting parent state against the same scatter performed
1170
1162
  through the view's sync path. */
1171
1163
  static VALUE
1172
- rb_ca_select_axis_dispatch_scatter_debug (VALUE self, VALUE in_str)
1164
+ rb_ca_select_axis_dispatch_scatter_debug (volatile VALUE self, volatile VALUE in_str)
1173
1165
  {
1174
1166
  CASelectAxis *ca;
1175
1167
  ca_axis_desc_t desc[CA_RANK_MAX];
@@ -1188,7 +1180,7 @@ rb_ca_select_axis_dispatch_scatter_debug (VALUE self, VALUE in_str)
1188
1180
  ca_size_t pdims[CA_RANK_MAX];
1189
1181
  ca_select_axis_describe_axes(ca, desc, pdims);
1190
1182
 
1191
- ca_attach(ca->parent); /* window: nothing raises inside */
1183
+ ca_attach(ca->parent); /* attach: nothing raises before the detach */
1192
1184
  ca_axis_dispatch_scatter(ca->parent, pdims, desc, ca->ndim, ca->bytes,
1193
1185
  ca->elements, RSTRING_PTR(in_str));
1194
1186
  ca_sync_detach(ca->parent);
@@ -1198,7 +1190,7 @@ rb_ca_select_axis_dispatch_scatter_debug (VALUE self, VALUE in_str)
1198
1190
  /* Broadcasts a String of length == bytes (one value) into every selected
1199
1191
  parent cell through ca_axis_dispatch_fill_value. */
1200
1192
  static VALUE
1201
- rb_ca_select_axis_dispatch_fill_value_debug (VALUE self, VALUE val_str)
1193
+ rb_ca_select_axis_dispatch_fill_value_debug (volatile VALUE self, volatile VALUE val_str)
1202
1194
  {
1203
1195
  CASelectAxis *ca;
1204
1196
  ca_axis_desc_t desc[CA_RANK_MAX];
@@ -1215,7 +1207,7 @@ rb_ca_select_axis_dispatch_fill_value_debug (VALUE self, VALUE val_str)
1215
1207
  ca_size_t pdims[CA_RANK_MAX];
1216
1208
  ca_select_axis_describe_axes(ca, desc, pdims);
1217
1209
 
1218
- ca_attach(ca->parent); /* window: nothing raises inside */
1210
+ ca_attach(ca->parent); /* attach: nothing raises before the detach */
1219
1211
  ca_axis_dispatch_fill_value(ca->parent, pdims, desc, ca->ndim, ca->bytes,
1220
1212
  ca->elements, RSTRING_PTR(val_str));
1221
1213
  ca_sync_detach(ca->parent);
@@ -1229,7 +1221,7 @@ void
1229
1221
  Init_ca_obj_select_axis (void)
1230
1222
  {
1231
1223
  rb_cCASelectAxis = rb_define_class("CASelectAxis", rb_cCAView);
1232
- rb_cCASelectAxisMask = rb_define_class("CASelectAxisMask", rb_cCASelectAxis);
1224
+ rb_cCASelectAxisMask = rb_define_class_under(rb_cCASelectAxis, "Mask", rb_cCASelectAxis);
1233
1225
 
1234
1226
  ca_select_axis_func.struct_size = sizeof(CASelectAxis);
1235
1227
  ca_select_axis_func.pool_bytes = ca_select_axis_pool_bytes;
@@ -1241,7 +1233,6 @@ Init_ca_obj_select_axis (void)
1241
1233
  &caselectaxis_mask_data_type,
1242
1234
  &ca_select_axis_func, sizeof(ca_select_axis_func));
1243
1235
  ca_register_cell_moving_view(CA_OBJ_SELECT_AXIS);
1244
- rb_define_const(rb_cObject, "CA_OBJ_SELECT_AXIS", INT2NUM(CA_OBJ_SELECT_AXIS));
1245
1236
 
1246
1237
  rb_define_alloc_func(rb_cCASelectAxis, rb_ca_select_axis_s_allocate);
1247
1238
  rb_define_method(rb_cCASelectAxis, "initialize_copy",
data/ext/ca_obj_shift.c CHANGED
@@ -16,7 +16,6 @@
16
16
  ---------------------------------------------------------------------------- */
17
17
 
18
18
  #include "carray.h"
19
- #include "carray_internal.h" /* ca_window_create_bounds_mask */
20
19
  #include "ca_obj_face.h" /* CA_FACE_LIFT_IF_FACE */
21
20
 
22
21
  /* External: CAWindow's operation table + setup are the basis for CAShift. */
@@ -53,7 +52,7 @@ const rb_data_type_t cashift_data_type = {
53
52
  double-free that explodes under GC stress. */
54
53
  const rb_data_type_t cashift_mask_data_type = {
55
54
  .parent = &cashift_data_type,
56
- .wrap_struct_name = "CAShiftMask",
55
+ .wrap_struct_name = "CAShift::Mask",
57
56
  .function = {
58
57
  .dmark = ca_mark,
59
58
  .dfree = ca_free_nop,
@@ -63,7 +62,7 @@ const rb_data_type_t cashift_mask_data_type = {
63
62
  .flags = RUBY_TYPED_FREE_IMMEDIATELY
64
63
  };
65
64
 
66
- static int8_t CA_OBJ_SHIFT;
65
+ static int16_t CA_OBJ_SHIFT;
67
66
 
68
67
  VALUE rb_cCAShift;
69
68
  VALUE rb_cCAShiftMask;
@@ -189,14 +188,14 @@ ca_shift_func_clone (void *ap)
189
188
  /* ------------------------------------------------------------------- */
190
189
 
191
190
  VALUE
192
- rb_ca_shift_new (VALUE cary, ca_size_t *shift, char *fill, int8_t *roll,
191
+ rb_ca_shift_new (volatile VALUE cary, ca_size_t *shift, char *fill, int8_t *roll,
193
192
  int fill_mask)
194
193
  {
195
194
  volatile VALUE obj;
196
195
  CArray *parent;
197
196
  CAShift *ca;
198
197
  rb_check_carray_object(cary);
199
- TypedData_Get_Struct(cary, CArray, &carray_data_type, parent);
198
+ GetCArray(cary, parent);
200
199
  ca = ca_shift_new(parent, shift, fill, roll, fill_mask);
201
200
  obj = ca_wrap_struct(ca);
202
201
  rb_ca_set_parent(obj, cary);
@@ -204,15 +203,17 @@ rb_ca_shift_new (VALUE cary, ca_size_t *shift, char *fill, int8_t *roll,
204
203
  }
205
204
 
206
205
  /* CArray#shift(*shifts, fill_value:) — returns a CAShift view translated
207
- * by `shifts` along each axis (one shift per dimension).
206
+ * by `shifts` along each axis (one shift per axis, ndim of them).
208
207
  *
209
208
  * Out-of-range cells take fill_value (default 0); fill_value: UNDEF masks
210
- * them instead. Raises ArgumentError on argument-count mismatch, on the
211
- * removed :roll option, and on the removed block form. */
209
+ * them instead. Raises ArgumentError when the number of shifts is not
210
+ * ndim, and when a block is given. */
212
211
  VALUE
213
- rb_ca_shift (int argc, VALUE *argv, VALUE self)
212
+ rb_ca_shift (int argc, VALUE *argv, volatile VALUE self)
214
213
  {
215
- volatile VALUE obj, ropt, rfval = CA_UNSPECIFIED, rroll = Qnil, rcs;
214
+ volatile VALUE obj, ropt;
215
+ VALUE rfval = CA_UNSPECIFIED;
216
+ volatile VALUE rcs;
216
217
  CArray *ca;
217
218
  CScalar *cs;
218
219
  ca_size_t shift[CA_RANK_MAX];
@@ -221,22 +222,15 @@ rb_ca_shift (int argc, VALUE *argv, VALUE self)
221
222
  int fill_mask = 0;
222
223
  int8_t i;
223
224
 
224
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
225
+ GetCArray(self, ca);
225
226
 
226
227
  ropt = rb_pop_options(&argc, &argv);
227
- rb_scan_options(ropt, "roll,fill_value", &rroll, &rfval);
228
-
229
- /* The :roll option was removed in 3.0. Cyclic shift is now CArray#roll
230
- (returns a CARoll view, ca_obj_roll.c). Mixed per-axis roll is
231
- expressed via chain: a.roll(1, 0) followed by .shift(...). */
232
- if ( ! NIL_P(rroll) ) {
233
- rb_raise(rb_eArgError,
234
- "shift: :roll option removed in 3.0; "
235
- "use CArray#roll(...) for cyclic shift (returns CARoll view)");
236
- }
228
+ rb_scan_options(ropt, "fill_value", &rfval);
237
229
 
238
230
  if ( argc != ca->ndim ) {
239
- rb_raise(rb_eArgError, "# of arguments mismatch with ndim");
231
+ rb_raise(rb_eArgError,
232
+ "shift: give one shift per axis (%d for this array, got %d)",
233
+ (int) ca->ndim, argc);
240
234
  }
241
235
 
242
236
  for (i=0; i<ca->ndim; i++) {
@@ -245,8 +239,8 @@ rb_ca_shift (int argc, VALUE *argv, VALUE self)
245
239
 
246
240
  if ( rb_block_given_p() ) {
247
241
  rb_raise(rb_eArgError,
248
- "shift: block form for fill value removed in 3.0; "
249
- "use fill_value: kwarg (e.g. shift(1, fill_value: -2))");
242
+ "shift: does not take a block; "
243
+ "give the value for the cells outside as fill_value:");
250
244
  }
251
245
 
252
246
  if ( rfval == CA_UNSPECIFIED ) {
@@ -275,21 +269,8 @@ rb_ca_shift (int argc, VALUE *argv, VALUE self)
275
269
  rb_ca_obj2ptr(self, rfval, fill);
276
270
  }
277
271
 
278
- if ( NIL_P(rroll) ) {
279
- for (i=0; i<ca->ndim; i++) {
280
- roll[i] = 0;
281
- }
282
- }
283
- else {
284
- Check_Type(rroll, T_ARRAY);
285
-
286
- if ( RARRAY_LEN(rroll) != ca->ndim ) {
287
- rb_raise(rb_eArgError, "# of arguments mismatch with ndim");
288
- }
289
-
290
- for (i=0; i<ca->ndim; i++) {
291
- roll[i] = ca_integer_arg(rb_ary_entry(rroll, i), "a shift", NULL);
292
- }
272
+ for (i=0; i<ca->ndim; i++) {
273
+ roll[i] = 0;
293
274
  }
294
275
 
295
276
  obj = rb_ca_shift_new(self, shift, fill, roll, fill_mask);
@@ -308,7 +289,7 @@ rb_ca_shift_s_allocate (VALUE klass)
308
289
  }
309
290
 
310
291
  static VALUE
311
- rb_ca_shift_initialize_copy (VALUE self, VALUE other)
292
+ rb_ca_shift_initialize_copy (volatile VALUE self, volatile VALUE other)
312
293
  {
313
294
  CAShift *ca, *cs;
314
295
  ca_size_t shift[CA_RANK_MAX];
@@ -357,14 +338,13 @@ Init_ca_obj_shift (void)
357
338
  ca_shift_func.clone = ca_shift_func_clone;
358
339
 
359
340
  rb_cCAShift = rb_define_class("CAShift", rb_cCAWindow);
360
- rb_cCAShiftMask = rb_define_class("CAShiftMask", rb_cCAShift);
341
+ rb_cCAShiftMask = rb_define_class_under(rb_cCAShift, "Mask", rb_cCAShift);
361
342
 
362
343
  CA_OBJ_SHIFT = ca_install_obj_type(rb_cCAShift,
363
344
  &cashift_data_type,
364
345
  rb_cCAShiftMask,
365
346
  &cashift_mask_data_type, &ca_shift_func, sizeof(ca_shift_func));
366
347
  ca_register_cell_moving_view(CA_OBJ_SHIFT);
367
- rb_define_const(rb_cObject, "CA_OBJ_SHIFT", INT2NUM(CA_OBJ_SHIFT));
368
348
 
369
349
  rb_define_method(rb_cCArray, "shift", rb_ca_shift, -1);
370
350
  /* "shift!" removed in 3.0; "roll" defined in Init_ca_obj_roll. */
data/ext/ca_obj_source.c CHANGED
@@ -29,11 +29,7 @@
29
29
  CA_VIEW_ARRAY — born cold (values must be produced on demand).
30
30
  The struct takes the CAView prefix with parent
31
31
  left NULL, and the engine's parent-walking paths
32
- must be taught to stop (see PROPOSAL_CASOURCE §7).
33
-
34
- See devel/PROPOSAL_CASOURCE.md (§2.1 empty base, §2.2 subclass writes
35
- every slot, §2.5 struct prefix vs class placement) and
36
- devel/MEMO_CASOURCE.md §9 (parentless safety audit).
32
+ must be taught to stop.
37
33
 
38
34
  ---------------------------------------------------------------------------- */
39
35
 
data/ext/ca_obj_stack.c CHANGED
@@ -18,7 +18,6 @@
18
18
  ---------------------------------------------------------------------------- */
19
19
 
20
20
  #include "carray.h"
21
- #include "carray_internal.h" /* ca_attach_all / ca_sync_all */
22
21
  #include <ruby/ractor.h>
23
22
  #include "ca_composite_dispatch.h"
24
23
  #include "ca_obj_face.h"
@@ -50,7 +49,7 @@ const rb_data_type_t castack_data_type = {
50
49
 
51
50
  const rb_data_type_t castack_mask_data_type = {
52
51
  .parent = &castack_data_type,
53
- .wrap_struct_name = "CAStackMask",
52
+ .wrap_struct_name = "CAStack::Mask",
54
53
  .function = {
55
54
  .dmark = ca_mark,
56
55
  .dfree = ca_free_nop,
@@ -60,7 +59,7 @@ const rb_data_type_t castack_mask_data_type = {
60
59
  .flags = RUBY_TYPED_FREE_IMMEDIATELY
61
60
  };
62
61
 
63
- int8_t CA_OBJ_STACK;
62
+ int16_t CA_OBJ_STACK;
64
63
 
65
64
  VALUE rb_cCAStack;
66
65
  VALUE rb_cCAStackMask;
@@ -146,7 +145,7 @@ ca_stack_setup_with_axis (CAStack *ca, int32_t n_parents, CArray **parents,
146
145
  return 0;
147
146
  }
148
147
 
149
- /* §8.3 / MEMO_FACE_DOUBLE_LIFT §15.3: pre-strip Face parents one level to
148
+ /* Pre-strip Face parents one level to
150
149
  storage so a stacked Face lifts to a single-Face chain
151
150
  (CATime[CAStack[entity, ...]]) instead of a Face on top of Face parents.
152
151
  One level (not a full walk) preserves any distinct Face a parent stacked
@@ -1024,7 +1023,7 @@ ca_stack_func_fold_stride (void *ap, ca_fold_t *f, void **next_parent)
1024
1023
  /* operation table */
1025
1024
  /* ------------------------------------------------------------------- */
1026
1025
 
1027
- extern int8_t CA_OBJ_MELD;
1026
+ extern int16_t CA_OBJ_MELD;
1028
1027
  CAMeld *ca_meld_new (int32_t n_parents, CArray **parents, int8_t meld_axis);
1029
1028
 
1030
1029
  /* For a stack or meld holding data (not the mask of one): its parts. */
@@ -1063,6 +1062,7 @@ ca_value_trial_target (CArray *q)
1063
1062
  return -1;
1064
1063
  }
1065
1064
 
1065
+ /* recursion: stops at a depth of 64 */
1066
1066
  static int
1067
1067
  ca_value_trial_needed (CArray *ca, int depth)
1068
1068
  {
@@ -1098,20 +1098,24 @@ ca_value_trial_standin (CArray *q, VALUE keep, int depth)
1098
1098
  int32_t n;
1099
1099
  int t = ca_value_trial_target(q);
1100
1100
  if ( t >= 0 ) {
1101
- VALUE z = rb_carray_new((int8_t) t, q->ndim, q->dim, 0, NULL);
1101
+ volatile VALUE z = rb_carray_new((int8_t) t, q->ndim, q->dim, 0, NULL);
1102
1102
  /* coerce: the stand-in converts as the part's own cast does */
1103
- VALUE w = rb_ca_wrap_writable(z, INT2NUM(q->data_type));
1103
+ volatile VALUE w = rb_ca_wrap_writable(z, INT2NUM(q->data_type));
1104
+ CArray *cw;
1104
1105
  rb_ary_push(keep, z);
1105
1106
  rb_ary_push(keep, w);
1106
- return (CArray *) DATA_PTR(w);
1107
+ GetCArray(w, cw);
1108
+ return cw;
1107
1109
  }
1108
1110
  if ( ca_value_trial_parts(q, &parts, &n) && ca_value_trial_needed(q, depth) ) {
1109
1111
  return ca_value_trial_like(q, keep, depth);
1110
1112
  }
1111
1113
  {
1112
- VALUE z = rb_carray_new(q->data_type, q->ndim, q->dim, q->bytes, NULL);
1114
+ volatile VALUE z = rb_carray_new(q->data_type, q->ndim, q->dim, q->bytes, NULL);
1115
+ CArray *cz;
1113
1116
  rb_ary_push(keep, z);
1114
- return (CArray *) DATA_PTR(z);
1117
+ GetCArray(z, cz);
1118
+ return cz;
1115
1119
  }
1116
1120
  }
1117
1121
 
@@ -1249,7 +1253,6 @@ ca_multi_parent_value_trial_through (CArray *m, VALUE (*body)(VALUE), VALUE arg)
1249
1253
  rb_ensure(ca_value_trial_swap_body, (VALUE) &t,
1250
1254
  ca_value_trial_swap_restore, (VALUE) &t);
1251
1255
  ALLOCV_END(holder);
1252
- RB_GC_GUARD(keep);
1253
1256
  }
1254
1257
 
1255
1258
  /* The table's write slots: after a write that may have put a true into a
@@ -1384,7 +1387,7 @@ ca_operation_function_t ca_stack_func = {
1384
1387
  beyond ca_stack_check_uniform (data_type + shape uniformity).
1385
1388
  Returns a fresh CAStack VALUE (not a Face-wrapped lift).
1386
1389
 
1387
- The Face dance (= homogeneity check + lift) lives in the high-level
1390
+ The Face handling (= homogeneity check + lift) lives in the high-level
1388
1391
  Ruby `CArray.stack` defined in lib/carray/compose.rb, which calls
1389
1392
  `CArray.promote_list` for the homogeneity + state / portability
1390
1393
  verdict and `ca.face_lift(face_parent)` (= rb_ca_face_lift_method)
@@ -1410,7 +1413,7 @@ rb_ca_stack_new_with_axis (VALUE parents_ary, int8_t k_axis)
1410
1413
  for ( i = 0; i < n; i++ ) {
1411
1414
  volatile VALUE p = rb_ary_entry(parents_ary, i);
1412
1415
  rb_check_carray_object(p);
1413
- TypedData_Get_Struct(p, CArray, &carray_data_type, parents[i]);
1416
+ GetCArray(p, parents[i]);
1414
1417
  ca_multi_parent_check_part(parents[i], "stack");
1415
1418
  }
1416
1419
  ca = ca_stack_new_with_axis((int32_t) n, parents, k_axis);
@@ -1440,7 +1443,7 @@ rb_ca_stack_s_allocate (VALUE klass)
1440
1443
  }
1441
1444
 
1442
1445
  static VALUE
1443
- rb_ca_stack_initialize_copy (VALUE self, VALUE other)
1446
+ rb_ca_stack_initialize_copy (volatile VALUE self, volatile VALUE other)
1444
1447
  {
1445
1448
  CAStack *ca, *cs;
1446
1449
  TypedData_Get_Struct(self, CAStack, &castack_data_type, ca);
@@ -1465,7 +1468,7 @@ rb_ca_stack_initialize_copy (VALUE self, VALUE other)
1465
1468
  by the high-level CArray.stack Ruby method (= lib/carray/compose.rb)
1466
1469
  which calls CAStack.new then ca.face_lift(face_parent). */
1467
1470
  static VALUE
1468
- rb_ca_stack_initialize (int argc, VALUE *argv, VALUE self)
1471
+ rb_ca_stack_initialize (int argc, VALUE *argv, volatile VALUE self)
1469
1472
  {
1470
1473
  CAStack *ca;
1471
1474
  CArray **parents;
@@ -1487,8 +1490,8 @@ rb_ca_stack_initialize (int argc, VALUE *argv, VALUE self)
1487
1490
  CArray *ref;
1488
1491
  volatile VALUE first = rb_ary_entry(list, 0);
1489
1492
  rb_check_carray_object(first);
1490
- TypedData_Get_Struct(first, CArray, &carray_data_type, ref);
1491
- k_axis = (int8_t) ca_normalize_axis_arg(
1493
+ GetCArray(first, ref);
1494
+ k_axis = (int8_t) rb_ca_normalize_axis_arg(
1492
1495
  axis_val, (int) ref->ndim + 1, "CAStack.new");
1493
1496
  }
1494
1497
  TypedData_Get_Struct(self, CAStack, &castack_data_type, ca);
@@ -1497,7 +1500,7 @@ rb_ca_stack_initialize (int argc, VALUE *argv, VALUE self)
1497
1500
  for ( i = 0; i < n; i++ ) {
1498
1501
  volatile VALUE p = rb_ary_entry(list, i);
1499
1502
  rb_check_carray_object(p);
1500
- TypedData_Get_Struct(p, CArray, &carray_data_type, parents[i]);
1503
+ GetCArray(p, parents[i]);
1501
1504
  ca_multi_parent_check_part(parents[i], "stack");
1502
1505
  }
1503
1506
  ca_stack_setup_with_axis(ca, (int32_t) n, parents, k_axis);
@@ -1551,9 +1554,10 @@ rb_ca_stack_s_new (int argc, VALUE *argv, VALUE klass)
1551
1554
 
1552
1555
  /* Public Ruby accessor: stack.n_parents → K */
1553
1556
  static VALUE
1554
- rb_ca_stack_n_parents (VALUE self)
1557
+ rb_ca_stack_n_parents (volatile VALUE self)
1555
1558
  {
1556
- CAStack *ca = (CAStack *) DATA_PTR(self);
1559
+ CAStack *ca;
1560
+ TypedData_Get_Struct(self, CAStack, &castack_data_type, ca);
1557
1561
  return INT2NUM(ca->n_parents);
1558
1562
  }
1559
1563
 
@@ -1567,9 +1571,10 @@ rb_ca_stack_parents (VALUE self)
1567
1571
 
1568
1572
  /* Public Ruby accessor: stack.k_axis → K axis insertion position [0, parent_ndim]. */
1569
1573
  static VALUE
1570
- rb_ca_stack_k_axis (VALUE self)
1574
+ rb_ca_stack_k_axis (volatile VALUE self)
1571
1575
  {
1572
- CAStack *ca = (CAStack *) DATA_PTR(self);
1576
+ CAStack *ca;
1577
+ TypedData_Get_Struct(self, CAStack, &castack_data_type, ca);
1573
1578
  return INT2NUM((int) ca->k_axis);
1574
1579
  }
1575
1580
 
@@ -1586,7 +1591,7 @@ Init_ca_obj_stack (void)
1586
1591
  }
1587
1592
 
1588
1593
  rb_cCAStack = rb_define_class("CAStack", rb_cCAView);
1589
- rb_cCAStackMask = rb_define_class("CAStackMask", rb_cCAStack);
1594
+ rb_cCAStackMask = rb_define_class_under(rb_cCAStack, "Mask", rb_cCAStack);
1590
1595
 
1591
1596
  ca_stack_func.fill_addrs = ca_stack_put_fill_addrs;
1592
1597
  ca_stack_func.fill_stride = ca_stack_put_fill_stride;
@@ -1596,7 +1601,6 @@ Init_ca_obj_stack (void)
1596
1601
  rb_cCAStackMask,
1597
1602
  &castack_mask_data_type, &ca_stack_func, sizeof(ca_stack_func));
1598
1603
  ca_register_cell_moving_view(CA_OBJ_STACK);
1599
- rb_define_const(rb_cObject, "CA_OBJ_STACK", INT2NUM(CA_OBJ_STACK));
1600
1604
 
1601
1605
  id_parents = rb_intern("parents");
1602
1606