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
@@ -78,7 +78,6 @@
78
78
 
79
79
  #include "carray.h"
80
80
  #include "ca_obj_face.h"
81
- #include "carray_internal.h" /* ca_object_cells_clear */
82
81
  #include <string.h>
83
82
  #include <math.h>
84
83
 
@@ -101,8 +100,7 @@
101
100
  storage's, so descending would answer the wrong question. CAConstString is
102
101
  the live example -- a cell is a (start, end) byte range, so two equal strings
103
102
  at different offsets have different storage -- and it needs its own
104
- discovery surface rather than this gate (see
105
- devel/PROPOSAL_DISCOVERY_FAMILY_FACE_GATE.md §4). */
103
+ discovery surface rather than this gate. */
106
104
 
107
105
  /* The value-hash family decides whether two cells hold the same value: every
108
106
  NaN is one value, and -0.0 is the same value as +0.0. A float cell's key
@@ -156,7 +154,7 @@ fz_canonical_float (float v)
156
154
  (-0.0 as 0.0, every NaN as one NaN), with the mask kept. The fixlen lane
157
155
  then answers equality for complex values. */
158
156
  static VALUE
159
- fz_complex_key (VALUE self)
157
+ fz_complex_key (volatile VALUE self)
160
158
  {
161
159
  volatile VALUE out;
162
160
  CArray *ca, *co;
@@ -177,14 +175,13 @@ fz_complex_key (VALUE self)
177
175
  if ( ca_has_mask(ca) ) {
178
176
  ca_copy_mask(co, ca);
179
177
  }
180
- RB_GC_GUARD(self); /* read through ca after rb_carray_new allocates */
181
178
  return out;
182
179
  }
183
180
 
184
181
  /* The members whose output carries no values (a mask, a count) read a
185
182
  complex array through its keys and need nothing back. */
186
183
  static VALUE
187
- fz_complex_as_key (VALUE self)
184
+ fz_complex_as_key (volatile VALUE self)
188
185
  {
189
186
  CArray *ca;
190
187
  GetCArray(self, ca);
@@ -199,7 +196,7 @@ fz_complex_as_key (VALUE self)
199
196
  is turned into hash keys (fz_complex_key) and *pface keeps it, so the
200
197
  re-lift reads the values back as complex. */
201
198
  static VALUE
202
- fz_face_descend (VALUE self, volatile VALUE *pface, const char *name)
199
+ fz_face_descend (volatile VALUE self, volatile VALUE *pface, const char *name)
203
200
  {
204
201
  CArray *ca;
205
202
  GetCArray(self, ca);
@@ -232,7 +229,7 @@ fz_face_descend (VALUE self, volatile VALUE *pface, const char *name)
232
229
  (ca_face_reconcile_operand). A complex reference instead turns the
233
230
  operand into keys of its own complex type. */
234
231
  static VALUE
235
- fz_face_reconcile (VALUE reference, VALUE operand, const char *name)
232
+ fz_face_reconcile (volatile VALUE reference, volatile VALUE operand, const char *name)
236
233
  {
237
234
  CArray *ca;
238
235
  if ( NIL_P(reference) ) {
@@ -259,7 +256,7 @@ fz_face_reconcile (VALUE reference, VALUE operand, const char *name)
259
256
  /* Put the Face back on a value-carrying output, or read complex keys back
260
257
  as complex values. */
261
258
  static VALUE
262
- fz_face_relift (VALUE out, VALUE face)
259
+ fz_face_relift (volatile VALUE out, volatile VALUE face)
263
260
  {
264
261
  CArray *cf, *co;
265
262
  if ( NIL_P(face) ) {
@@ -344,18 +341,20 @@ fz_tmp_alloc (VALUE *store, size_t bytes)
344
341
  }
345
342
 
346
343
  static void *
347
- fz_tmp_realloc (VALUE store, size_t bytes)
344
+ fz_tmp_realloc (volatile VALUE store, size_t bytes)
348
345
  {
349
- fz_buffer *b = (fz_buffer *) DATA_PTR(store);
346
+ fz_buffer *b;
347
+ TypedData_Get_Struct(store, fz_buffer, &fz_buffer_type, b);
350
348
  b->buf = (char *) xrealloc(b->buf, bytes);
351
349
  return b->buf;
352
350
  }
353
351
 
354
352
  /* Mark the n VALUEs at vals (inside store's buffer); they must be valid. */
355
353
  static void
356
- fz_tmp_values (VALUE store, void *vals, ca_size_t n)
354
+ fz_tmp_values (volatile VALUE store, void *vals, ca_size_t n)
357
355
  {
358
- fz_buffer *b = (fz_buffer *) DATA_PTR(store);
356
+ fz_buffer *b;
357
+ TypedData_Get_Struct(store, fz_buffer, &fz_buffer_type, b);
359
358
  b->voff = (ca_size_t) ((char *) vals - b->buf);
360
359
  b->nvals = n;
361
360
  }
@@ -364,7 +363,9 @@ static void
364
363
  fz_tmp_free (VALUE *store)
365
364
  {
366
365
  if ( *store ) {
367
- fz_buffer *b = (fz_buffer *) DATA_PTR(*store);
366
+ /* gc: the caller holds the store */
367
+ fz_buffer *b;
368
+ TypedData_Get_Struct(*store, fz_buffer, &fz_buffer_type, b);
368
369
  b->nvals = 0;
369
370
  xfree(b->buf);
370
371
  b->buf = NULL;
@@ -822,7 +823,7 @@ fz_factorize_appearance_body (VALUE arg)
822
823
  CArray *ca;
823
824
  volatile VALUE face;
824
825
  fr->self = self = fz_face_descend(self, &face, "categorize");
825
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
826
+ GetCArray(self, ca);
826
827
 
827
828
  int8_t dt = ca->data_type;
828
829
  switch ( dt ) {
@@ -845,7 +846,7 @@ fz_factorize_appearance_body (VALUE arg)
845
846
  /* uint32 code scratch, same shape as self; narrowed once k is known. */
846
847
  volatile VALUE vu32 = rb_carray_new(CA_UINT32, ca->ndim, ca->dim, 0, NULL);
847
848
  CArray *cu32;
848
- TypedData_Get_Struct(vu32, CArray, &carray_data_type, cu32);
849
+ GetCArray(vu32, cu32);
849
850
 
850
851
  fz_hash h;
851
852
  fz_levels lv;
@@ -960,14 +961,14 @@ fz_factorize_appearance_body (VALUE arg)
960
961
  else if ( k <= 0xFFFF ) { code_dt = CA_UINT16; }
961
962
  else { code_dt = CA_UINT32; }
962
963
 
963
- VALUE vcodes;
964
+ volatile VALUE vcodes;
964
965
  if ( code_dt == CA_UINT32 ) {
965
966
  vcodes = vu32; /* sentinel already 0xFFFFFFFF */
966
967
  }
967
968
  else {
968
969
  vcodes = rb_carray_new(code_dt, ca->ndim, ca->dim, 0, NULL);
969
970
  CArray *cco;
970
- TypedData_Get_Struct(vcodes, CArray, &carray_data_type, cco);
971
+ GetCArray(vcodes, cco);
971
972
  const uint32_t *up = (const uint32_t *) cu32->ptr;
972
973
  if ( code_dt == CA_UINT8 ) {
973
974
  uint8_t *cp = (uint8_t *) cco->ptr;
@@ -987,16 +988,16 @@ fz_factorize_appearance_body (VALUE arg)
987
988
  element width; numeric / object use bytes = 0. */
988
989
  ca_size_t ldim[1];
989
990
  ldim[0] = k;
990
- VALUE vlev = rb_carray_new(dt, 1, ldim, (dt == CA_FIXLEN) ? ca->bytes : 0, NULL);
991
+ volatile VALUE vlev = rb_carray_new(dt, 1, ldim, (dt == CA_FIXLEN) ? ca->bytes : 0, NULL);
991
992
  CArray *clev;
992
- TypedData_Get_Struct(vlev, CArray, &carray_data_type, clev);
993
+ GetCArray(vlev, clev);
993
994
  if ( k > 0 ) {
994
995
  memcpy(clev->ptr, lv.p, (size_t) k * (size_t) ca->bytes);
995
996
  }
996
997
  fz_levels_free(&lv);
997
998
 
998
999
  /* codes stay plain; levels are *values* and become categorize's labels */
999
- return rb_ary_new3(2, vcodes, fz_face_relift(vlev, face));
1000
+ return rb_ary_new_from_args(2, vcodes, fz_face_relift(vlev, face));
1000
1001
  }
1001
1002
 
1002
1003
  static VALUE
@@ -1031,7 +1032,7 @@ fz_mask_duplicates_body (VALUE arg)
1031
1032
  volatile VALUE self = fr->self;
1032
1033
  VALUE vaxis = fr->a;
1033
1034
  CArray *ca;
1034
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
1035
+ GetCArray(self, ca);
1035
1036
 
1036
1037
  int8_t dt = ca->data_type;
1037
1038
  switch ( dt ) {
@@ -1054,9 +1055,9 @@ fz_mask_duplicates_body (VALUE arg)
1054
1055
  rb_raise(rb_eArgError, "__mask_duplicates__: axis %d out of range", axis);
1055
1056
  }
1056
1057
 
1057
- VALUE vout = rb_carray_new(CA_BOOLEAN, ca->ndim, ca->dim, 0, NULL);
1058
+ volatile VALUE vout = rb_carray_new(CA_BOOLEAN, ca->ndim, ca->dim, 0, NULL);
1058
1059
  CArray *cout;
1059
- TypedData_Get_Struct(vout, CArray, &carray_data_type, cout);
1060
+ GetCArray(vout, cout);
1060
1061
 
1061
1062
  fz_hash h;
1062
1063
  if ( dt == CA_OBJECT ) { fz_hash_init_obj(&h); }
@@ -1193,7 +1194,7 @@ fz_unique_flat_body (VALUE arg)
1193
1194
  CArray *ca;
1194
1195
  volatile VALUE face;
1195
1196
  fr->self = self = fz_face_descend(self, &face, "unique");
1196
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
1197
+ GetCArray(self, ca);
1197
1198
 
1198
1199
  int8_t dt = ca->data_type;
1199
1200
  switch ( dt ) {
@@ -1305,9 +1306,9 @@ fz_unique_flat_body (VALUE arg)
1305
1306
  ca_size_t ldim[1];
1306
1307
  ldim[0] = k;
1307
1308
  /* CA_FIXLEN carries its element width; numeric / object use bytes = 0. */
1308
- VALUE vlev = rb_carray_new(dt, 1, ldim, (dt == CA_FIXLEN) ? ca->bytes : 0, NULL);
1309
+ volatile VALUE vlev = rb_carray_new(dt, 1, ldim, (dt == CA_FIXLEN) ? ca->bytes : 0, NULL);
1309
1310
  CArray *clev;
1310
- TypedData_Get_Struct(vlev, CArray, &carray_data_type, clev);
1311
+ GetCArray(vlev, clev);
1311
1312
  if ( k > 0 ) {
1312
1313
  memcpy(clev->ptr, lv.p, (size_t) k * (size_t) ca->bytes);
1313
1314
  }
@@ -1430,7 +1431,7 @@ fz_is_in_body (VALUE arg)
1430
1431
  {
1431
1432
  fz_frame *fr = (fz_frame *) arg;
1432
1433
  volatile VALUE self = fr->self;
1433
- VALUE rvalues = fr->a;
1434
+ volatile VALUE rvalues = fr->a;
1434
1435
  CArray *ca, *cv;
1435
1436
  volatile VALUE face;
1436
1437
  fr->self = self = fz_face_descend(self, &face, "is_in");
@@ -1481,7 +1482,7 @@ fz_is_in_body (VALUE arg)
1481
1482
  fz_intern_all(&fr->st[2], &h, cv, NULL);
1482
1483
 
1483
1484
  /* ---- Phase 2: probe every cell of self, writing the boolean membership. */
1484
- VALUE vout = rb_carray_new(CA_BOOLEAN, ca->ndim, ca->dim, 0, NULL);
1485
+ volatile VALUE vout = rb_carray_new(CA_BOOLEAN, ca->ndim, ca->dim, 0, NULL);
1485
1486
  CArray *cout;
1486
1487
  GetCArray(vout, cout);
1487
1488
  {
@@ -1593,7 +1594,7 @@ fz_locate_addr_body (VALUE arg)
1593
1594
  {
1594
1595
  fz_frame *fr = (fz_frame *) arg;
1595
1596
  volatile VALUE self = fr->self;
1596
- VALUE rref = fr->a;
1597
+ volatile VALUE rref = fr->a;
1597
1598
  CArray *ca, *cr;
1598
1599
  /* Here the *reference* is the argument (self is the query being placed on
1599
1600
  rref), so the gate runs the other way round: rref reconciles self. The
@@ -1734,7 +1735,7 @@ fz_locate_addr_body (VALUE arg)
1734
1735
  }
1735
1736
 
1736
1737
  /* ---- Phase 2: probe every cell of self, writing the int64 address + UNDEF. */
1737
- VALUE vout = rb_carray_new(CA_INT64, ca->ndim, ca->dim, 0, NULL);
1738
+ volatile VALUE vout = rb_carray_new(CA_INT64, ca->ndim, ca->dim, 0, NULL);
1738
1739
  CArray *cout;
1739
1740
  GetCArray(vout, cout);
1740
1741
  int64_t *out = (int64_t *) cout->ptr;
@@ -1860,7 +1861,7 @@ fz_set_relation_body (VALUE arg)
1860
1861
  {
1861
1862
  fz_frame *fr = (fz_frame *) arg;
1862
1863
  volatile VALUE self = fr->self;
1863
- VALUE rother = fr->a;
1864
+ volatile VALUE rother = fr->a;
1864
1865
  int keep_when_hit = fr->i;
1865
1866
  CArray *ca, *co;
1866
1867
  volatile VALUE face;
@@ -2010,7 +2011,7 @@ fz_set_relation_body (VALUE arg)
2010
2011
 
2011
2012
  ca_size_t ldim[1];
2012
2013
  ldim[0] = k;
2013
- VALUE vlev = rb_carray_new(dt, 1, ldim, (dt == CA_FIXLEN) ? ca->bytes : 0, NULL);
2014
+ volatile VALUE vlev = rb_carray_new(dt, 1, ldim, (dt == CA_FIXLEN) ? ca->bytes : 0, NULL);
2014
2015
  CArray *clev;
2015
2016
  GetCArray(vlev, clev);
2016
2017
  if ( k > 0 ) {
@@ -2056,7 +2057,7 @@ fz_set_union_body (VALUE arg)
2056
2057
  {
2057
2058
  fz_frame *fr = (fz_frame *) arg;
2058
2059
  volatile VALUE self = fr->self;
2059
- VALUE rother = fr->a;
2060
+ volatile VALUE rother = fr->a;
2060
2061
  CArray *ca, *co;
2061
2062
  volatile VALUE face;
2062
2063
  fr->self = self = fz_face_descend(self, &face, "union");
@@ -2113,7 +2114,7 @@ fz_set_union_body (VALUE arg)
2113
2114
 
2114
2115
  ca_size_t ldim[1];
2115
2116
  ldim[0] = k;
2116
- VALUE vlev = rb_carray_new(dt, 1, ldim, (dt == CA_FIXLEN) ? ca->bytes : 0, NULL);
2117
+ volatile VALUE vlev = rb_carray_new(dt, 1, ldim, (dt == CA_FIXLEN) ? ca->bytes : 0, NULL);
2117
2118
  CArray *clev;
2118
2119
  GetCArray(vlev, clev);
2119
2120
  if ( k > 0 ) {
@@ -2153,7 +2154,7 @@ fz_value_counts_flat_body (VALUE arg)
2153
2154
  CArray *ca;
2154
2155
  volatile VALUE face;
2155
2156
  fr->self = self = fz_face_descend(self, &face, "value_counts");
2156
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
2157
+ GetCArray(self, ca);
2157
2158
 
2158
2159
  int8_t dt = ca->data_type;
2159
2160
  switch ( dt ) {
@@ -2287,12 +2288,12 @@ fz_value_counts_flat_body (VALUE arg)
2287
2288
  ca_size_t ldim[1];
2288
2289
  ldim[0] = k;
2289
2290
  /* CA_FIXLEN carries its element width; numeric / object use bytes = 0. */
2290
- VALUE vlev = rb_carray_new(dt, 1, ldim, (dt == CA_FIXLEN) ? ca->bytes : 0, NULL);
2291
+ volatile VALUE vlev = rb_carray_new(dt, 1, ldim, (dt == CA_FIXLEN) ? ca->bytes : 0, NULL);
2291
2292
  CArray *clev;
2292
- TypedData_Get_Struct(vlev, CArray, &carray_data_type, clev);
2293
- VALUE vcnt = rb_carray_new(CA_INT64, 1, ldim, 0, NULL);
2293
+ GetCArray(vlev, clev);
2294
+ volatile VALUE vcnt = rb_carray_new(CA_INT64, 1, ldim, 0, NULL);
2294
2295
  CArray *ccnt;
2295
- TypedData_Get_Struct(vcnt, CArray, &carray_data_type, ccnt);
2296
+ GetCArray(vcnt, ccnt);
2296
2297
  if ( k > 0 ) {
2297
2298
  memcpy(clev->ptr, lv.p, (size_t) k * (size_t) ca->bytes);
2298
2299
  memcpy(ccnt->ptr, ct.p, (size_t) k * sizeof(int64_t));
@@ -2301,7 +2302,7 @@ fz_value_counts_flat_body (VALUE arg)
2301
2302
  fz_levels_free(&ct);
2302
2303
 
2303
2304
  /* values carry the Face, counts stay plain int64 */
2304
- return rb_ary_new3(2, fz_face_relift(vlev, face), vcnt);
2305
+ return rb_ary_new_from_args(2, fz_face_relift(vlev, face), vcnt);
2305
2306
  }
2306
2307
 
2307
2308
  static VALUE
@@ -2329,7 +2330,7 @@ fz_nunique_body (VALUE arg)
2329
2330
  VALUE vaxis = fr->a;
2330
2331
  VALUE vkeep = fr->b;
2331
2332
  CArray *ca;
2332
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
2333
+ GetCArray(self, ca);
2333
2334
 
2334
2335
  int8_t dt = ca->data_type;
2335
2336
  switch ( dt ) {
@@ -2349,11 +2350,11 @@ fz_nunique_body (VALUE arg)
2349
2350
 
2350
2351
  int8_t axes[CA_RANK_MAX];
2351
2352
  int8_t naxes = rb_ca_parse_reduce_axes_kw_ctx(vaxis, ca, axes, "nunique");
2352
- int keep_axis = RTEST(vkeep);
2353
+ int keep_axis = ca_bool_arg(vkeep, "keep_axis");
2353
2354
 
2354
- VALUE vout = rb_ca_new_reduced(self, axes, naxes, CA_INT64, keep_axis);
2355
+ volatile VALUE vout = rb_ca_new_reduced(self, axes, naxes, CA_INT64, keep_axis);
2355
2356
  CArray *cout;
2356
- TypedData_Get_Struct(vout, CArray, &carray_data_type, cout);
2357
+ GetCArray(vout, cout);
2357
2358
  int64_t *op = (int64_t *) cout->ptr;
2358
2359
 
2359
2360
  fz_hash h;
@@ -2475,7 +2476,7 @@ fz_is_mode_body (VALUE arg)
2475
2476
  volatile VALUE self = fr->self;
2476
2477
  VALUE vaxis = fr->a;
2477
2478
  CArray *ca;
2478
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
2479
+ GetCArray(self, ca);
2479
2480
 
2480
2481
  int8_t dt = ca->data_type;
2481
2482
  switch ( dt ) {
@@ -2497,9 +2498,9 @@ fz_is_mode_body (VALUE arg)
2497
2498
  rb_raise(rb_eArgError, "__is_mode__: axis %d out of range", axis);
2498
2499
  }
2499
2500
 
2500
- VALUE vout = rb_carray_new(CA_BOOLEAN, ca->ndim, ca->dim, 0, NULL);
2501
+ volatile VALUE vout = rb_carray_new(CA_BOOLEAN, ca->ndim, ca->dim, 0, NULL);
2501
2502
  CArray *cout;
2502
- TypedData_Get_Struct(vout, CArray, &carray_data_type, cout);
2503
+ GetCArray(vout, cout);
2503
2504
 
2504
2505
  fz_hash h;
2505
2506
  fz_levels ct; /* int64 count per code (code == push index), reset per fiber */
@@ -2691,12 +2692,12 @@ static VALUE
2691
2692
  fz_mode_axis_body (VALUE arg)
2692
2693
  {
2693
2694
  fz_frame *fr = (fz_frame *) arg;
2694
- VALUE self = fr->self;
2695
+ volatile VALUE self = fr->self;
2695
2696
  VALUE vaxis = fr->a;
2696
2697
  CArray *ca;
2697
2698
  volatile VALUE face;
2698
2699
  fr->self = self = fz_face_descend(self, &face, "mode");
2699
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
2700
+ GetCArray(self, ca);
2700
2701
 
2701
2702
  int8_t dt = ca->data_type;
2702
2703
  switch ( dt ) {
@@ -2849,9 +2850,9 @@ fz_mode_axis_body (VALUE arg)
2849
2850
  UNDEF when r has fewer than j+1 modes. K == 0 -> empty Array. */
2850
2851
  VALUE result = rb_ary_new_capa((long) Kmax);
2851
2852
  for ( ca_size_t j = 0; j < Kmax; j++ ) {
2852
- VALUE col = rb_ca_new_reduced(self, &ax, 1, dt, 0);
2853
+ volatile VALUE col = rb_ca_new_reduced(self, &ax, 1, dt, 0);
2853
2854
  CArray *cc;
2854
- TypedData_Get_Struct(col, CArray, &carray_data_type, cc);
2855
+ GetCArray(col, cc);
2855
2856
  ca_create_mask(cc);
2856
2857
  boolean8_t *cm = (boolean8_t *) cc->mask->ptr;
2857
2858
  char *dst = cc->ptr;
@@ -9,7 +9,6 @@
9
9
 
10
10
  #include "ruby.h"
11
11
  #include "carray.h"
12
- #include "carray_internal.h" /* ca_attach_window, ca_normalize_axis_arg */
13
12
  #include "ca_obj_face.h" /* ca_face_element_to_storage */
14
13
 
15
14
  /* ----------------------------------------------------------------- */
@@ -23,7 +22,7 @@
23
22
  Also used internally by ext/ca_obj_grid.c when it needs to extract
24
23
  the addresses of true cells from a boolean axis selector. */
25
24
  VALUE
26
- rb_ca_where (VALUE self)
25
+ rb_ca_where (volatile VALUE self)
27
26
  {
28
27
  volatile VALUE bool0, obj;
29
28
  CArray *ca, *co;
@@ -31,7 +30,7 @@ rb_ca_where (VALUE self)
31
30
  ca_size_t *q;
32
31
  ca_size_t i, j, n, last, count;
33
32
 
34
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
33
+ GetCArray(self, ca);
35
34
  if ( ca_is_boolean_type(ca) ) {
36
35
  bool0 = self;
37
36
  }
@@ -40,13 +39,19 @@ rb_ca_where (VALUE self)
40
39
  ca_is_complex_type(ca) ) ) {
41
40
  bool0 = rb_funcall(self, rb_intern("ne"), 1, INT2FIX(0));
42
41
  }
42
+ else if ( ! ca_is_face(ca) && ca_is_object_type(ca) ) {
43
+ /* each cell read as a boolean cell reads a value it is given, so a cell
44
+ that is no truth value raises (to_type would make it UNDEF) */
45
+ bool0 = rb_ca_copy(rb_funcall(self, rb_intern("as_type"), 1,
46
+ ID2SYM(rb_intern("boolean"))));
47
+ }
43
48
  else {
44
49
  bool0 = rb_ca_to_boolean(self);
45
50
  }
46
51
 
47
- TypedData_Get_Struct(bool0, CArray, &carray_data_type, ca);
52
+ GetCArray(bool0, ca);
48
53
 
49
- ca_attach(ca); /* window: nothing raises inside */
54
+ ca_attach(ca); /* attach: nothing raises before the detach */
50
55
 
51
56
  /* calculate elements of output array, and the last selected cell */
52
57
  p = (boolean8_t *) ca->ptr;
@@ -72,7 +77,7 @@ rb_ca_where (VALUE self)
72
77
 
73
78
  /* create output array */
74
79
  obj = rb_carray_new(CA_SIZE, 1, &count, 0, NULL);
75
- TypedData_Get_Struct(obj, CArray, &carray_data_type, co);
80
+ GetCArray(obj, co);
76
81
 
77
82
  /* Store the address of each selected cell. Every cell up to the last
78
83
  selected one is written and the output position advances only on a
@@ -215,7 +220,7 @@ ca_seq_resolve_axis (CArray *ca, VALUE raxis)
215
220
  "%s: axis must be a single Integer (a seq over several axes is not supported)",
216
221
  ca_calling_method_name());
217
222
  }
218
- axis = ca_normalize_axis_arg(raxis, ca->ndim, NULL);
223
+ axis = rb_ca_normalize_axis_arg(raxis, ca->ndim, NULL);
219
224
  return axis;
220
225
  }
221
226
 
@@ -236,7 +241,8 @@ ca_seq_geometry (CArray *ca, int axis,
236
241
  }
237
242
 
238
243
  /* The object fill calls Ruby per cell (`+`, or the method given as the
239
- step), which can raise part way, so it runs in a window that attaches:
244
+ step), which can raise part way, so it runs while the array is attached
245
+ (not allocated):
240
246
  the cells filled before the raise then reach the parent with the rest
241
247
  left as they were, as they would for an entity. */
242
248
 
@@ -371,11 +377,11 @@ ca_seq_bang_object_body (VALUE arg)
371
377
  }
372
378
 
373
379
  static VALUE
374
- rb_ca_seq_bang_object (VALUE self, VALUE roffset, VALUE rstep, int axis)
380
+ rb_ca_seq_bang_object (volatile VALUE self, VALUE roffset, VALUE rstep, int axis)
375
381
  {
376
382
  ca_seq_ctx_t c;
377
383
 
378
- TypedData_Get_Struct(self, CArray, &carray_data_type, c.ca);
384
+ GetCArray(self, c.ca);
379
385
 
380
386
  c.self = self;
381
387
  c.rmethod = Qnil;
@@ -392,9 +398,10 @@ rb_ca_seq_bang_object (VALUE self, VALUE roffset, VALUE rstep, int axis)
392
398
  return self;
393
399
  }
394
400
 
395
- /* The numeric fill runs in an allocate window, which clears an entity's
396
- mask as it opens (an entity has no separate buffer), so nothing in it may
397
- raise: offset and step are checked to be numbers before it opens. */
401
+ /* The numeric fill runs while the array is allocated (ca_allocate), which
402
+ clears an entity's mask (an entity has no separate buffer), so nothing
403
+ in it may raise: offset and step are checked to be numbers before the
404
+ allocate. */
398
405
  static VALUE
399
406
  ca_seq_bang_numeric_body (VALUE arg)
400
407
  {
@@ -496,18 +503,18 @@ ca_seq_check_real_run (CArray *ca, VALUE roffset, VALUE rstep, ca_size_t n)
496
503
  per-element method calls like `:succ`). Mutates self and clears any
497
504
  existing mask. */
498
505
  static VALUE
499
- rb_ca_seq_bang_method (int argc, VALUE *argv, VALUE self)
506
+ rb_ca_seq_bang_method (int argc, VALUE *argv, volatile VALUE self)
500
507
  {
501
- volatile VALUE roffset = Qnil, rstep = Qnil, rkw = Qnil, raxis = Qnil;
508
+ VALUE roffset = Qnil, rstep = Qnil, rkw = Qnil, raxis = Qnil;
502
509
  CArray *ca;
503
510
  int axis;
504
511
 
505
512
  rb_ca_modify(self);
506
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
513
+ GetCArray(self, ca);
507
514
 
508
- rb_scan_args(argc, argv, "02:", (VALUE *) &roffset, (VALUE *) &rstep,
509
- (VALUE *) &rkw);
510
- rb_scan_options(rkw, "axis", (VALUE *) &raxis);
515
+ rb_scan_args(argc, argv, "02:", &roffset, &rstep,
516
+ &rkw);
517
+ rb_scan_options(rkw, "axis", &raxis);
511
518
 
512
519
  axis = ca_seq_resolve_axis(ca, raxis); /* -1 = flat; validates */
513
520
 
@@ -23,7 +23,6 @@
23
23
  ---------------------------------------------------------------------------- */
24
24
 
25
25
  #include "carray.h"
26
- #include "carray_internal.h" /* ca_attach_window */
27
26
  #include <math.h>
28
27
  #include <float.h>
29
28
 
@@ -59,7 +58,7 @@ histbin_check_edge_order (const double *ep, ca_size_t n, const char *name)
59
58
  buffer) rather than attaching them: the walk that follows reads the
60
59
  caller's array, and a raise there must not leave the edges attached. */
61
60
  static VALUE
62
- histbin_resolve_edges (VALUE self, VALUE redges)
61
+ histbin_resolve_edges (VALUE self, volatile VALUE redges)
63
62
  {
64
63
  CArray *ce;
65
64
 
@@ -179,10 +178,10 @@ histbin_axis_setup (histbin_axis_t *ax, const double *ep, ca_size_t ne,
179
178
  }
180
179
 
181
180
  static VALUE
182
- rb_ca_histbin_ki (VALUE self, VALUE redges, VALUE rinclude_max)
181
+ rb_ca_histbin_ki (volatile VALUE self, volatile VALUE redges, VALUE rinclude_max)
183
182
  {
184
183
  CArray *ca, *co, *ce;
185
- VALUE vout;
184
+ volatile VALUE vout;
186
185
  volatile VALUE hedges = 0;
187
186
  double *ep;
188
187
  histbin_axis_t ax;
@@ -199,8 +198,7 @@ rb_ca_histbin_ki (VALUE self, VALUE redges, VALUE rinclude_max)
199
198
  ep = ALLOCV_N(double, hedges, ce->elements);
200
199
  ca_xfer_all(ce, ep, CA_XFER_GET);
201
200
  histbin_check_edge_order(ep, ce->elements, "bin_to");
202
- histbin_axis_setup(&ax, ep, ce->elements, RTEST(rinclude_max));
203
- RB_GC_GUARD(redges); /* a view made by histbin_resolve_edges is read through ce */
201
+ histbin_axis_setup(&ax, ep, ce->elements, ca_bool_arg(rinclude_max, "include_max"));
204
202
 
205
203
  /* output: fresh contiguous int64, same shape as self. */
206
204
  vout = rb_carray_new(CA_INT64, ca->ndim, ca->dim, 0, NULL);
@@ -259,7 +257,7 @@ rb_ca_histbin_ki (VALUE self, VALUE redges, VALUE rinclude_max)
259
257
  off = fiber_base + Σ_k histbin_index(axis_k, v_{a,k}) * ext_stride[k]
260
258
  counts[off] += 1 (or += weight when weighted)
261
259
  =========================================================================== */
262
- /* histogram_scatter_ki reads its edges inside an attach window and walks
260
+ /* histogram_scatter_ki reads its edges while they are attached and walks
263
261
  the samples (and the weights) with two kernel iterators, whose states
264
262
  live here, outside the walk: a sample view that raises as it is read --
265
263
  a lazy source meeting a cell it cannot compute -- leaves neither the
@@ -383,8 +381,8 @@ histogram_scatter_edges (VALUE arg)
383
381
  }
384
382
 
385
383
  static VALUE
386
- rb_ca_histogram_scatter_ki (VALUE self, VALUE rcounts, VALUE redges,
387
- VALUE rincmax, VALUE rweights)
384
+ rb_ca_histogram_scatter_ki (volatile VALUE self, volatile VALUE rcounts, VALUE redges,
385
+ VALUE rincmax, volatile VALUE rweights)
388
386
  {
389
387
  CArray *ca, *cc, *cw = NULL;
390
388
  long M, nf, k;
@@ -528,7 +526,7 @@ bincount_nd_label_u64 (uint64_t x)
528
526
  } while (0)
529
527
 
530
528
  static VALUE
531
- rb_ca_bincount_nd_count_ki (VALUE self, VALUE rcounts, volatile VALUE rweights)
529
+ rb_ca_bincount_nd_count_ki (volatile VALUE self, volatile VALUE rcounts, volatile VALUE rweights)
532
530
  {
533
531
  CArray *ca, *cc, *cw = NULL;
534
532
  long M, nf, k;
data/ext/carray_hold.c CHANGED
@@ -1,8 +1,7 @@
1
1
  /* ---------------------------------------------------------------------------
2
2
 
3
3
  Mask gap-fill hold: carry the last valid value forward into masked cells
4
- along one axis. Backing primitive for `unmask(method:)` / `strip_mask(method:)`
5
- (see devel/PROPOSAL_UNMASK_FILL_METHOD.md).
4
+ along one axis. Backing primitive for `unmask(method:)` / `strip_mask(method:)`.
6
5
 
7
6
  Hold copies a cell's bytes into masked cells with no arithmetic and no
8
7
  per-type behavior, so a single ca->bytes-width memcpy walk covers every
@@ -20,7 +19,6 @@
20
19
  #include "carray.h"
21
20
  #include "ca_kernel_iterator.h"
22
21
  #include "ca_obj_face.h"
23
- #include "carray_internal.h" /* ca_normalize_axis_arg */
24
22
 
25
23
  /* Forward hold along `axis`. Per fiber along the scan axis:
26
24
  - present cell -> output = cell value, becomes the held value;
@@ -28,7 +26,7 @@
28
26
  - masked before any value (leading run) -> output stays masked (UNDEF),
29
27
  since there is no value to carry (hold has no identity). */
30
28
  static VALUE
31
- rb_ca_hold_forward (VALUE self, int axis)
29
+ rb_ca_hold_forward (volatile VALUE self, int axis)
32
30
  {
33
31
  CArray *ca, *co;
34
32
  GetCArray(self, ca);
@@ -111,11 +109,11 @@ rb_ca_hold_forward (VALUE self, int axis)
111
109
  Integer (negative counts from the end). The Ruby wrapper composes
112
110
  backward / flatten / linear on top of this. */
113
111
  static VALUE
114
- rb_ca_hold_method (VALUE self, VALUE raxis)
112
+ rb_ca_hold_method (volatile VALUE self, VALUE raxis)
115
113
  {
116
114
  CArray *ca;
117
115
  GetCArray(self, ca);
118
- return rb_ca_hold_forward(self, ca_normalize_axis_arg(raxis, ca->ndim, NULL));
116
+ return rb_ca_hold_forward(self, rb_ca_normalize_axis_arg(raxis, ca->ndim, NULL));
119
117
  }
120
118
 
121
119
  /* first / last: the reduction sibling of hold. Reduce each fiber to its
@@ -124,13 +122,13 @@ rb_ca_hold_method (VALUE self, VALUE raxis)
124
122
  (all masked, or empty) yields UNDEF. A user who wants a default instead
125
123
  of UNDEF completes at the call site: `a.first(axis: 0).strip_mask(v)`. */
126
124
  static VALUE
127
- rb_ca_first_last_reduce (VALUE self, int argc, VALUE *argv, int backward)
125
+ rb_ca_first_last_reduce (volatile VALUE self, int argc, VALUE *argv, int backward)
128
126
  {
129
127
  CArray *ca, *co;
130
128
  GetCArray(self, ca);
131
129
 
132
130
  volatile VALUE ropt = rb_pop_options(&argc, &argv);
133
- volatile VALUE raxis = Qnil, rkeep_axis = Qnil;
131
+ VALUE raxis = Qnil, rkeep_axis = Qnil;
134
132
  rb_scan_options(ropt, "axis,keep_axis", &raxis, &rkeep_axis);
135
133
  if ( argc > 0 ) {
136
134
  rb_raise(rb_eArgError,
@@ -139,7 +137,7 @@ rb_ca_first_last_reduce (VALUE self, int argc, VALUE *argv, int backward)
139
137
  backward ? "last" : "first", argc,
140
138
  backward ? "last" : "first", backward ? "last" : "first");
141
139
  }
142
- int keep_axis = RTEST(rkeep_axis);
140
+ int keep_axis = ca_bool_arg(rkeep_axis, "keep_axis");
143
141
  int8_t slab_axes[CA_RANK_MAX];
144
142
  int8_t naxes = rb_ca_parse_reduce_axes_kw(raxis, ca, slab_axes);
145
143