carray 3.0.6 → 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 (277) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -1
  3. data/CHANGELOG.md +7 -1830
  4. data/README.md +62 -35
  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 +12 -15
  11. data/ext/ca_bincmp_dispatch.h +16 -38
  12. data/ext/ca_binop_dispatch.c +35 -0
  13. data/ext/ca_binop_dispatch.h +22 -46
  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 -1504
  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 +92 -165
  28. data/ext/ca_obj_bincmp.c +65 -48
  29. data/ext/ca_obj_binop.c +74 -49
  30. data/ext/ca_obj_bitarray.c +7 -21
  31. data/ext/ca_obj_bitfield.c +93 -26
  32. data/ext/ca_obj_block.c +11 -12
  33. data/ext/ca_obj_byte_swap.c +34 -34
  34. data/ext/ca_obj_const_string.c +464 -304
  35. data/ext/ca_obj_face.c +167 -121
  36. data/ext/ca_obj_face.h +32 -170
  37. data/ext/ca_obj_fake.c +127 -34
  38. data/ext/ca_obj_farray.c +13 -9
  39. data/ext/ca_obj_field.c +17 -13
  40. data/ext/ca_obj_fixlen_string.c +57 -34
  41. data/ext/ca_obj_grid.c +149 -113
  42. data/ext/ca_obj_meld.c +28 -26
  43. data/ext/ca_obj_moncmp.c +10 -21
  44. data/ext/ca_obj_monop.c +88 -73
  45. data/ext/ca_obj_object.c +60 -46
  46. data/ext/ca_obj_record.c +74 -22
  47. data/ext/ca_obj_reduce.c +10 -14
  48. data/ext/ca_obj_refer.c +146 -39
  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 +20 -28
  52. data/ext/ca_obj_select.c +17 -27
  53. data/ext/ca_obj_select_axis.c +35 -42
  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 +33 -29
  57. data/ext/ca_obj_stride.c +99 -62
  58. data/ext/ca_obj_string.c +8 -20
  59. data/ext/ca_obj_tile.c +14 -16
  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 +48 -49
  64. data/ext/ca_obj_window.c +87 -99
  65. data/ext/ca_op_cmplx64.h +4 -0
  66. data/ext/ca_op_ipower.c +97 -27
  67. data/ext/ca_op_powi.h +9 -28
  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 +23 -26
  72. data/ext/ca_sweep_engine.c +92 -26
  73. data/ext/ca_sweep_engine.h +22 -15
  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 +12 -12
  77. data/ext/carray.h +300 -1009
  78. data/ext/carray_access.c +320 -207
  79. data/ext/carray_address_basis.c +128 -59
  80. data/ext/carray_attribute.c +81 -104
  81. data/ext/carray_bincount.c +12 -14
  82. data/ext/carray_broadcast.c +31 -27
  83. data/ext/carray_call_cfunc.c +174 -285
  84. data/ext/carray_call_cfunc.h +36 -28
  85. data/ext/carray_cast.c +1191 -351
  86. data/ext/carray_cast_func.rb +68 -8
  87. data/ext/carray_class.c +6 -11
  88. data/ext/carray_conversion.c +98 -39
  89. data/ext/carray_copy.c +52 -26
  90. data/ext/carray_core.c +286 -132
  91. data/ext/carray_count.c +53 -22
  92. data/ext/carray_element.c +49 -28
  93. data/ext/carray_factorize.c +64 -63
  94. data/ext/carray_generate.c +26 -19
  95. data/ext/carray_histogram.c +9 -11
  96. data/ext/carray_hold.c +7 -9
  97. data/ext/carray_index_classifier.c +127 -230
  98. data/ext/carray_index_classifier.h +11 -10
  99. data/ext/carray_integer_total.c +523 -0
  100. data/ext/carray_internal.h +1364 -156
  101. data/ext/carray_key_windows.c +3 -3
  102. data/ext/carray_lazy.c +37 -37
  103. data/ext/carray_loop.c +27 -23
  104. data/ext/carray_mask.c +235 -150
  105. data/ext/carray_math_kernel.h +23 -47
  106. data/ext/carray_mathfunc.c +10 -3
  107. data/ext/carray_median_percentile.c +106 -100
  108. data/ext/carray_memory_view.c +83 -69
  109. data/ext/carray_operator.c +490 -128
  110. data/ext/carray_order.c +163 -84
  111. data/ext/carray_partition.c +14 -16
  112. data/ext/carray_random.c +48 -42
  113. data/ext/carray_round.c +33 -5
  114. data/ext/carray_scatter.c +57 -39
  115. data/ext/carray_segment.c +42 -46
  116. data/ext/carray_slab.c +77 -51
  117. data/ext/carray_slab.h +44 -33
  118. data/ext/carray_sort.c +37 -31
  119. data/ext/carray_sort_kernel.c +36 -10
  120. data/ext/carray_struct.c +44 -34
  121. data/ext/carray_test.c +131 -81
  122. data/ext/carray_time_text.c +30 -31
  123. data/ext/carray_undef.c +50 -7
  124. data/ext/carray_utils.c +373 -139
  125. data/ext/extconf.rb +24 -17
  126. data/ext/mk_call_cfunc.rb +25 -31
  127. data/ext/mk_pow5_table.rb +2 -1
  128. data/ext/mkkernel.rb +819 -488
  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 +272 -185
  135. data/lib/carray/basics.rb +298 -56
  136. data/lib/carray/bincount_nd.rb +41 -18
  137. data/lib/carray/block_iterator.rb +167 -119
  138. data/lib/carray/boolean_reduce.rb +7 -4
  139. data/lib/carray/categorical.rb +84 -59
  140. data/lib/carray/categorical_iterator.rb +90 -67
  141. data/lib/carray/complex.rb +61 -41
  142. data/lib/carray/conditional.rb +98 -23
  143. data/lib/carray/const_string.rb +112 -46
  144. data/lib/carray/core_extensions.rb +20 -69
  145. data/lib/carray/distance_limit.rb +7 -5
  146. data/lib/carray/factories.rb +269 -0
  147. data/lib/carray/fixlen_string.rb +95 -12
  148. data/lib/carray/frame/column_verbs.rb +76 -9
  149. data/lib/carray/frame/concat.rb +51 -7
  150. data/lib/carray/frame/convert.rb +2 -1
  151. data/lib/carray/frame/csv_parser.rb +20 -5
  152. data/lib/carray/frame/frame.rb +73 -31
  153. data/lib/carray/frame/group.rb +247 -187
  154. data/lib/carray/frame/io.rb +36 -12
  155. data/lib/carray/frame/join.rb +56 -17
  156. data/lib/carray/frame/records.rb +7 -5
  157. data/lib/carray/frame/reshape.rb +27 -7
  158. data/lib/carray/frame/sort.rb +10 -8
  159. data/lib/carray/frame/verbs.rb +217 -134
  160. data/lib/carray/frame/windows.rb +254 -19
  161. data/lib/carray/frame.rb +1 -2
  162. data/lib/carray/fuse_source.rb +28 -23
  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 +104 -23
  167. data/lib/carray/key_windows.rb +93 -61
  168. data/lib/carray/lazy.rb +208 -111
  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 +8 -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 +73 -72
  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/factorize.rb +2 -0
  183. data/lib/carray/methods/gather_nd.rb +106 -103
  184. data/lib/carray/methods/insert_block.rb +2 -2
  185. data/lib/carray/methods/is_between.rb +6 -4
  186. data/lib/carray/methods/is_in.rb +183 -143
  187. data/lib/carray/methods/join.rb +2 -1
  188. data/lib/carray/methods/lag.rb +6 -2
  189. data/lib/carray/methods/locate_addr.rb +157 -94
  190. data/lib/carray/methods/mask_duplicates.rb +1 -1
  191. data/lib/carray/methods/meshgrid.rb +28 -16
  192. data/lib/carray/methods/mode.rb +67 -67
  193. data/lib/carray/methods/nunique.rb +9 -7
  194. data/lib/carray/methods/repeat.rb +23 -13
  195. data/lib/carray/methods/resize.rb +1 -1
  196. data/lib/carray/methods/snap.rb +24 -20
  197. data/lib/carray/methods/string_format.rb +2 -2
  198. data/lib/carray/methods/unique.rb +4 -2
  199. data/lib/carray/methods/value_counts.rb +1 -1
  200. data/lib/carray/mkmf.rb +25 -28
  201. data/lib/carray/percentile_arguments.rb +82 -0
  202. data/lib/carray/record_order.rb +50 -20
  203. data/lib/carray/rng.rb +1 -0
  204. data/lib/carray/runtime.rb +195 -17
  205. data/lib/carray/segment_iterator.rb +262 -137
  206. data/lib/carray/serialize.rb +635 -566
  207. data/lib/carray/slab_iterator.rb +114 -114
  208. data/lib/carray/stack.rb +14 -15
  209. data/lib/carray/string.rb +16 -22
  210. data/lib/carray/string_operation_extension.rb +97 -52
  211. data/lib/carray/struct.rb +122 -164
  212. data/lib/carray/struct_builder.rb +247 -73
  213. data/lib/carray/time.rb +663 -365
  214. data/lib/carray/window_iterator.rb +232 -155
  215. data/lib/carray.rb +6 -11
  216. data/yard-stubs/ca_obj_array.rb +20 -135
  217. data/yard-stubs/ca_obj_bitarray.rb +1 -8
  218. data/yard-stubs/ca_obj_bitfield.rb +6 -2
  219. data/yard-stubs/ca_obj_byte_swap.rb +21 -7
  220. data/yard-stubs/ca_obj_fake.rb +3 -1
  221. data/yard-stubs/ca_obj_farray.rb +1 -1
  222. data/yard-stubs/ca_obj_field.rb +8 -6
  223. data/yard-stubs/ca_obj_refer.rb +10 -5
  224. data/yard-stubs/ca_obj_roll.rb +7 -6
  225. data/yard-stubs/ca_obj_shift.rb +2 -3
  226. data/yard-stubs/ca_obj_stride.rb +5 -7
  227. data/yard-stubs/ca_obj_tile.rb +1 -1
  228. data/yard-stubs/ca_obj_time.rb +43 -0
  229. data/yard-stubs/ca_obj_transpose.rb +1 -1
  230. data/yard-stubs/ca_obj_window.rb +28 -16
  231. data/yard-stubs/carray_access.rb +55 -6
  232. data/yard-stubs/carray_attribute.rb +26 -38
  233. data/yard-stubs/carray_cast.rb +121 -162
  234. data/yard-stubs/carray_class.rb +3 -4
  235. data/yard-stubs/carray_conversion.rb +6 -7
  236. data/yard-stubs/carray_copy.rb +2 -1
  237. data/yard-stubs/carray_count.rb +10 -5
  238. data/yard-stubs/carray_element.rb +4 -3
  239. data/yard-stubs/carray_limits.rb +100 -0
  240. data/yard-stubs/carray_loop.rb +0 -20
  241. data/yard-stubs/carray_mask.rb +59 -41
  242. data/yard-stubs/carray_math.rb +162 -100
  243. data/yard-stubs/carray_mathfunc.rb +415 -3
  244. data/yard-stubs/carray_median_percentile.rb +29 -11
  245. data/yard-stubs/carray_memory_view.rb +2 -2
  246. data/yard-stubs/carray_order.rb +72 -33
  247. data/yard-stubs/carray_random.rb +6 -6
  248. data/yard-stubs/carray_reduce.rb +353 -0
  249. data/yard-stubs/carray_rng.rb +92 -0
  250. data/yard-stubs/carray_scatter.rb +12 -3
  251. data/yard-stubs/carray_slab.rb +7 -4
  252. data/yard-stubs/carray_sort.rb +7 -6
  253. data/yard-stubs/carray_test.rb +18 -5
  254. data/yard-stubs/carray_undef.rb +44 -5
  255. data/yard-stubs/ruby_carray.rb +75 -40
  256. metadata +63 -25
  257. data/CHANGELOG.v1.md +0 -126
  258. data/ext/carray_build_flags.h +0 -3
  259. data/ext/carray_config.h +0 -28
  260. data/ext/carray_data_type.c +0 -90
  261. data/ext/carray_kernels_bincmp.c +0 -6457
  262. data/ext/carray_kernels_binop.c +0 -31534
  263. data/ext/carray_kernels_init.c +0 -1734
  264. data/ext/carray_kernels_moncmp.c +0 -2104
  265. data/ext/carray_kernels_monop.c +0 -25387
  266. data/ext/carray_kernels_reduce_aggregate.c +0 -27545
  267. data/ext/carray_kernels_reduce_boolean.c +0 -1924
  268. data/ext/carray_kernels_reduce_cumulative.c +0 -11646
  269. data/ext/carray_kernels_reduce_extreme.c +0 -21631
  270. data/ext/carray_kernels_reduce_variance.c +0 -5981
  271. data/ext/carray_kernels_scan.c +0 -4302
  272. data/ext/carray_kernels_search.c +0 -37776
  273. data/ext/carray_kernels_sort.c +0 -10814
  274. data/ext/carray_kernels_triop.c +0 -1864
  275. data/lib/carray/construct.rb +0 -360
  276. data/lib/carray/data_type_extension.rb +0 -261
  277. data/lib/carray/data_type_limits.rb +0 -91
data/ext/ruby_carray.c CHANGED
@@ -14,7 +14,6 @@
14
14
  ---------------------------------------------------------------------------- */
15
15
 
16
16
  #include "carray.h"
17
- #include "carray_internal.h"
18
17
  #include "carray_build_flags.h"
19
18
  #include "version.h"
20
19
 
@@ -33,7 +32,6 @@ VALUE CA_UNSPECIFIED;
33
32
  void Init_carray_core ();
34
33
  void Init_carray_undef ();
35
34
  void Init_carray_class ();
36
- void Init_carray_data_type ();
37
35
  void Init_carray_test ();
38
36
  void Init_carray_attribute ();
39
37
  void Init_carray_loop ();
@@ -47,8 +45,8 @@ void Init_carray_index_classifier ();
47
45
  void Init_carray_element ();
48
46
  void Init_carray_scatter (); /* scatter_*! family */
49
47
  void Init_carray_segment (); /* segment lengths / offsets / index */
50
- void Init_ca_axis_group (); /* devel/MEMO_AXIS_GROUP.md — axis-group reduction kernel */
51
- void Init_ca_group_iter (); /* devel/MEMO_AXIS_GROUP.md — axis-group [] surface */
48
+ void Init_ca_axis_group (); /* axis-group reduction kernel */
49
+ void Init_ca_group_iter (); /* axis-group [] surface */
52
50
  void Init_carray_bincount (); /* bincount dedicated kernel */
53
51
  void Init_carray_factorize (); /* single-pass integer factorization for categorize */
54
52
  void Init_carray_histogram (); /* histogram + histbin_ki */
@@ -156,7 +154,7 @@ Init_carray_ext (void)
156
154
  rb_cCAView = rb_define_class("CAView", rb_cCArray);
157
155
  /* CAREFUL: CAStride must exist before its subclasses (CARefer /
158
156
  CABlock / CAField / CARepeat / CATranspose /
159
- CAFarray) are defined or registered. See devel/CAStride.md. */
157
+ CAFarray) are defined or registered. */
160
158
  rb_cCAStride = rb_define_class("CAStride", rb_cCAView);
161
159
  rb_cCARefer = rb_define_class("CARefer", rb_cCAStride);
162
160
  rb_cCABlock = rb_define_class("CABlock", rb_cCAStride);
@@ -164,13 +162,13 @@ Init_carray_ext (void)
164
162
  rb_cCASelect = rb_define_class("CASelect", rb_cCAView);
165
163
  rb_cCAObject = rb_define_class("CAObject", rb_cCAView);
166
164
  rb_cCARepeat = rb_define_class("CARepeat", rb_cCAStride);
167
- rb_cCArrayMask = rb_define_class("CArrayMask", rb_cCArray);
168
- rb_cCAStrideMask = rb_define_class("CAStrideMask", rb_cCAStride);
169
- rb_cCAReferMask = rb_define_class("CAReferMask", rb_cCARefer);
170
- rb_cCABlockMask = rb_define_class("CABlockMask", rb_cCABlock);
171
- rb_cCAFieldMask = rb_define_class("CAFieldMask", rb_cCAField);
172
- rb_cCASelectMask = rb_define_class("CASelectMask", rb_cCASelect);
173
- rb_cCARepeatMask = rb_define_class("CARepeatMask", rb_cCARepeat);
165
+ rb_cCArrayMask = rb_define_class_under(rb_cCArray, "Mask", rb_cCArray);
166
+ rb_cCAStrideMask = rb_define_class_under(rb_cCAStride, "Mask", rb_cCAStride);
167
+ rb_cCAReferMask = rb_define_class_under(rb_cCARefer, "Mask", rb_cCARefer);
168
+ rb_cCABlockMask = rb_define_class_under(rb_cCABlock, "Mask", rb_cCABlock);
169
+ rb_cCAFieldMask = rb_define_class_under(rb_cCAField, "Mask", rb_cCAField);
170
+ rb_cCASelectMask = rb_define_class_under(rb_cCASelect, "Mask", rb_cCASelect);
171
+ rb_cCARepeatMask = rb_define_class_under(rb_cCARepeat, "Mask", rb_cCARepeat);
174
172
 
175
173
  /* -- Exception class -- */
176
174
 
@@ -186,16 +184,16 @@ Init_carray_ext (void)
186
184
  /* The flags this build's arithmetic was compiled with. Anything that
187
185
  computes what these kernels compute, somewhere other than in them, has
188
186
  to be built the same way to arrive at the same answer. */
189
- rb_define_const(rb_cCArray, "BUILD_FLAGS", rb_obj_freeze(rb_str_new2(CA_BUILD_FLAGS)));
190
- rb_define_const(rb_cCArray, "VERSION", rb_obj_freeze(rb_str_new2(CA_VERSION)));
187
+ rb_define_const(rb_cCArray, "BUILD_FLAGS", rb_obj_freeze(rb_str_new_cstr(CA_BUILD_FLAGS)));
188
+ rb_define_const(rb_cCArray, "VERSION", rb_obj_freeze(rb_str_new_cstr(CA_VERSION)));
191
189
  rb_define_const(rb_cCArray, "VERSION_CODE", INT2NUM(CA_VERSION_CODE));
192
190
  rb_define_const(rb_cCArray, "VERSION_MAJOR", INT2NUM(CA_VERSION_MAJOR));
193
191
  rb_define_const(rb_cCArray, "VERSION_MINOR", INT2NUM(CA_VERSION_MINOR));
194
192
  rb_define_const(rb_cCArray, "VERSION_TEENY", INT2NUM(CA_VERSION_TEENY));
195
- rb_define_const(rb_cCArray, "VERSION_DATE", rb_obj_freeze(rb_str_new2(CA_VERSION_DATE)));
193
+ rb_define_const(rb_cCArray, "VERSION_DATE", rb_obj_freeze(rb_str_new_cstr(CA_VERSION_DATE)));
196
194
 
197
195
  /* -- system -- */
198
- rb_define_const(rb_cObject, "CA_RANK_MAX", INT2NUM(CA_RANK_MAX));
196
+ rb_define_const(rb_cCArray, "RANK_MAX", INT2NUM(CA_RANK_MAX));
199
197
  /* Sentinel meaning "the caller did not give this argument". It is
200
198
  distinct from nil because nil is itself a legal fill value (a
201
199
  CA_OBJECT array can be filled with nil), so nil cannot mark
@@ -204,6 +202,8 @@ Init_carray_ext (void)
204
202
  anchor the object against the GC. */
205
203
  CA_UNSPECIFIED = rb_obj_freeze(rb_funcall(rb_cObject, rb_intern("new"), 0));
206
204
  rb_define_const(rb_cCArray, "UNSPECIFIED", CA_UNSPECIFIED);
205
+ rb_funcall(rb_cCArray, rb_intern("private_constant"), 1,
206
+ ID2SYM(rb_intern("UNSPECIFIED")));
207
207
  /* Compared by identity in C, so it must not move. */
208
208
  rb_gc_register_mark_object(CA_UNSPECIFIED);
209
209
 
@@ -235,9 +235,7 @@ Init_carray_ext (void)
235
235
  /* The Ruby-surface CA_* data_type constants are Symbols (the C
236
236
  internal `#define CA_INT64 8` etc. is unchanged); both sides flip
237
237
  to Symbol together so `case when CA_INT64` over `ca.data_type`
238
- stays transparent. Alias constants (CA_DOUBLE etc.) share the
239
- canonical Symbol via Symbol identity, so `CA_DOUBLE ==
240
- CA_FLOAT64` evaluates true. */
238
+ stays transparent. */
241
239
 
242
240
  rb_define_const(rb_cObject, "CA_FIXLEN", ID2SYM(ca_data_type_sym[CA_FIXLEN]));
243
241
  rb_define_const(rb_cObject, "CA_BOOLEAN", ID2SYM(ca_data_type_sym[CA_BOOLEAN]));
@@ -255,35 +253,42 @@ Init_carray_ext (void)
255
253
  rb_define_const(rb_cObject, "CA_CMPLX128", ID2SYM(ca_data_type_sym[CA_CMPLX128]));
256
254
  rb_define_const(rb_cObject, "CA_OBJECT", ID2SYM(ca_data_type_sym[CA_OBJECT]));
257
255
 
258
- /* Aliases share the canonical Symbol: CA_BYTE == CA_UINT8, etc. */
259
- rb_define_const(rb_cObject, "CA_BYTE", ID2SYM(ca_data_type_sym[CA_BYTE]));
260
- rb_define_const(rb_cObject, "CA_SHORT", ID2SYM(ca_data_type_sym[CA_INT16]));
261
- rb_define_const(rb_cObject, "CA_INT", ID2SYM(ca_data_type_sym[CA_INT32]));
262
- rb_define_const(rb_cObject, "CA_FLOAT", ID2SYM(ca_data_type_sym[CA_FLOAT]));
263
- rb_define_const(rb_cObject, "CA_DOUBLE", ID2SYM(ca_data_type_sym[CA_DOUBLE]));
264
- rb_define_const(rb_cObject, "CA_COMPLEX", ID2SYM(ca_data_type_sym[CA_COMPLEX]));
265
- rb_define_const(rb_cObject, "CA_DCOMPLEX", ID2SYM(ca_data_type_sym[CA_DCOMPLEX]));
266
256
  rb_define_const(rb_cObject, "CA_SIZE", ID2SYM(ca_data_type_sym[CA_SIZE]));
267
257
 
268
- rb_define_const(rb_cObject, "CA_ALIGN_VOIDP", INT2NUM(CA_ALIGN_VOIDP));
269
- rb_define_const(rb_cObject, "CA_ALIGN_FIXLEN", INT2NUM(CA_ALIGN_INT8));
270
- rb_define_const(rb_cObject, "CA_ALIGN_BOOLEAN", INT2NUM(CA_ALIGN_INT8));
271
- rb_define_const(rb_cObject, "CA_ALIGN_INT8", INT2NUM(CA_ALIGN_INT8));
272
- rb_define_const(rb_cObject, "CA_ALIGN_INT16", INT2NUM(CA_ALIGN_INT16));
273
- rb_define_const(rb_cObject, "CA_ALIGN_INT32", INT2NUM(CA_ALIGN_INT32));
274
- rb_define_const(rb_cObject, "CA_ALIGN_INT64", INT2NUM(CA_ALIGN_INT64));
275
- rb_define_const(rb_cObject, "CA_ALIGN_FLOAT32", INT2NUM(CA_ALIGN_FLOAT32));
276
- rb_define_const(rb_cObject, "CA_ALIGN_FLOAT64", INT2NUM(CA_ALIGN_FLOAT64));
277
- rb_define_const(rb_cObject, "CA_ALIGN_CMPLX64", INT2NUM(CA_ALIGN_CMPLX64));
278
- rb_define_const(rb_cObject, "CA_ALIGN_CMPLX128", INT2NUM(CA_ALIGN_CMPLX128));
279
- rb_define_const(rb_cObject, "CA_ALIGN_OBJECT", INT2NUM(CA_ALIGN_OBJECT));
258
+ /* The alignment of each member type of a struct, which only the C
259
+ compiler knows. CAStruct::Builder reads it when it loads; nothing
260
+ else should, so it is private. */
261
+ {
262
+ volatile VALUE align = rb_hash_new();
263
+ #define CA_SET_ALIGN(name, value) \
264
+ rb_hash_aset(align, ID2SYM(rb_intern(name)), INT2NUM(value))
265
+ CA_SET_ALIGN("voidp", CA_ALIGN_VOIDP);
266
+ CA_SET_ALIGN("fixlen", CA_ALIGN_INT8);
267
+ CA_SET_ALIGN("boolean", CA_ALIGN_INT8);
268
+ CA_SET_ALIGN("int8", CA_ALIGN_INT8);
269
+ CA_SET_ALIGN("uint8", CA_ALIGN_INT8);
270
+ CA_SET_ALIGN("int16", CA_ALIGN_INT16);
271
+ CA_SET_ALIGN("uint16", CA_ALIGN_INT16);
272
+ CA_SET_ALIGN("int32", CA_ALIGN_INT32);
273
+ CA_SET_ALIGN("uint32", CA_ALIGN_INT32);
274
+ CA_SET_ALIGN("int64", CA_ALIGN_INT64);
275
+ CA_SET_ALIGN("uint64", CA_ALIGN_INT64);
276
+ CA_SET_ALIGN("float32", CA_ALIGN_FLOAT32);
277
+ CA_SET_ALIGN("float64", CA_ALIGN_FLOAT64);
278
+ CA_SET_ALIGN("cmplx64", CA_ALIGN_FLOAT32);
279
+ CA_SET_ALIGN("cmplx128", CA_ALIGN_FLOAT64);
280
+ #undef CA_SET_ALIGN
281
+ rb_obj_freeze(align);
282
+ rb_define_const(rb_cCArray, "STRUCT_ALIGNMENT", align);
283
+ rb_funcall(rb_cCArray, rb_intern("private_constant"), 1,
284
+ ID2SYM(rb_intern("STRUCT_ALIGNMENT")));
285
+ }
280
286
 
281
287
  /* load modules in external files */
282
288
 
283
289
  Init_carray_core(); /* Init_carray_core should be called first*/
284
290
 
285
291
  Init_carray_class();
286
- Init_carray_data_type();
287
292
  Init_carray_test();
288
293
  Init_carray_attribute();
289
294
  Init_carray_undef();
@@ -296,7 +301,7 @@ Init_carray_ext (void)
296
301
  Init_carray_element();
297
302
  Init_carray_scatter();
298
303
  Init_carray_segment();
299
- Init_ca_axis_group(); /* devel/MEMO_AXIS_GROUP.md — axis-group reduction kernel */
304
+ Init_ca_axis_group(); /* axis-group reduction kernel */
300
305
  Init_carray_bincount();
301
306
  Init_carray_factorize();
302
307
  Init_carray_histogram();
@@ -378,7 +383,7 @@ Init_carray_ext (void)
378
383
  CASlabIterator by name, so the class object must exist here. */
379
384
  rb_cCAIterator = rb_define_class("CAIterator", rb_cObject);
380
385
 
381
- Init_ca_group_iter(); /* devel/MEMO_AXIS_GROUP.md — axis-group [] surface
386
+ Init_ca_group_iter(); /* axis-group [] surface
382
387
  (CAGroupIterator); after CAIterator is defined
383
388
  (CAGroupIterator subclasses it). */
384
389
 
data/ext/version.h CHANGED
@@ -1,6 +1,8 @@
1
- #define CA_VERSION "3.0.6"
2
- #define CA_VERSION_CODE 30006
1
+ /* carray's version, internal to carray and not installed. The Ruby side
2
+ reads it through ext/version.rb. */
3
+ #define CA_VERSION "3.1.0"
4
+ #define CA_VERSION_CODE 30100
3
5
  #define CA_VERSION_MAJOR 3
4
- #define CA_VERSION_MINOR 0
5
- #define CA_VERSION_TEENY 6
6
- #define CA_VERSION_DATE "2026/10/28"
6
+ #define CA_VERSION_MINOR 1
7
+ #define CA_VERSION_TEENY 0
8
+ #define CA_VERSION_DATE "2026/12/04"
@@ -59,7 +59,7 @@
59
59
  # source shows, as its own Hash; `concatenate`, `mosaic` and `tabulate`
60
60
  # give it the keys every piece shows with the same value, as the views
61
61
  # do. A conversion to another type or representation (`to_type`,
62
- # `categorize`, a CAFrame `cast` / `parse_to_time` / `to_time`) carries
62
+ # `categorize`, a CAFrame `cast` / `parse_time` / `to_time`) carries
63
63
  # them. Arithmetic and reductions do not -- the result is a different
64
64
  # quantity -- including those that pick a value (`first`, `last`, `min`,
65
65
  # `max`, `unique`) and the element-wise ones that keep the unit (`abs`,
@@ -77,7 +77,7 @@ class CArray
77
77
  # that has an entry for `key` wins.
78
78
  # @param key [Symbol, String] attribute key.
79
79
  # @return [Object, nil]
80
- def attr (key)
80
+ def attr(key)
81
81
  k = attr_normalize_key(key)
82
82
  attr_each_chain do |h|
83
83
  return h[k] if h.key?(k)
@@ -100,7 +100,7 @@ class CArray
100
100
  # @raise [ArgumentError] when `value` nests more than 32 levels.
101
101
  # @raise [FrozenError] when `self` is frozen.
102
102
  # @raise [TypeError] when `self` is a mask array.
103
- def set_attr (key, value)
103
+ def set_attr(key, value)
104
104
  attr_check_writable
105
105
  attr_validate_value(value)
106
106
  (@attr ||= {})[attr_normalize_key(key)] = attr_coerce_value(value)
@@ -118,7 +118,7 @@ class CArray
118
118
  # @raise [ArgumentError] when a value nests more than 32 levels.
119
119
  # @raise [FrozenError] when `self` is frozen.
120
120
  # @raise [TypeError] when `self` is a mask array.
121
- def set_attrs (hash)
121
+ def set_attrs(hash)
122
122
  attr_check_writable
123
123
  unless hash.is_a?(Hash)
124
124
  raise TypeError, "set_attrs takes a Hash (got #{hash.class})"
@@ -142,7 +142,7 @@ class CArray
142
142
  # @param key [Symbol, String] attribute key.
143
143
  # @return [Object, nil] the removed value.
144
144
  # @raise [FrozenError] when `self` is frozen.
145
- def delete_attr (key)
145
+ def delete_attr(key)
146
146
  k = attr_normalize_key(key)
147
147
  return nil unless instance_variable_defined?(:@attr) && @attr
148
148
  attr_check_not_frozen
@@ -181,7 +181,7 @@ class CArray
181
181
  # set.
182
182
  # @param key [Symbol, String] attribute key.
183
183
  # @return [Boolean]
184
- def has_attr? (key = nil)
184
+ def has_attr?(key = nil)
185
185
  if key.nil?
186
186
  attr_each_chain do |h|
187
187
  return true unless h.empty?
@@ -209,7 +209,8 @@ class CArray
209
209
  yield(h) if h
210
210
  end
211
211
  return nil if attr_computing_view?(ca)
212
- if ca.is_a?(CAStack) || ca.is_a?(CAMeld)
212
+ # The mask of a stack or meld is one too, and holds no parents.
213
+ if (ca.is_a?(CAStack) || ca.is_a?(CAMeld)) && !ca.mask_array?
213
214
  shared = CArray.__send__(:attrs_shared_by, ca.parents)
214
215
  yield(shared) unless shared.empty?
215
216
  return nil
@@ -235,7 +236,7 @@ class CArray
235
236
  # Give `out`, a new array holding self's values in another type or
236
237
  # representation, the attributes self shows; returns `out`. A view of
237
238
  # self that already shows them is left alone.
238
- def carry_attrs (out)
239
+ def carry_attrs(out)
239
240
  return out if out.equal?(self)
240
241
  shown = attrs
241
242
  out.set_attrs(shown) unless shown.empty? || out.attrs == shown
@@ -244,7 +245,7 @@ class CArray
244
245
 
245
246
  # Remove what `out`, a new array a reduction made, holds of self's
246
247
  # attributes; returns `out`.
247
- def drop_carried_attrs (out)
248
+ def drop_carried_attrs(out)
248
249
  out.remove_instance_variable(:@attr) if out.instance_variable_defined?(:@attr)
249
250
  out
250
251
  end
@@ -253,7 +254,7 @@ class CArray
253
254
  # An array with no cells holds no values for the attributes to describe,
254
255
  # so it has no say (unless every one is empty), as CAFrame leaves a frame
255
256
  # with no rows out of a meld.
256
- def self.attrs_shared_by (list)
257
+ def self.attrs_shared_by(list)
257
258
  with_cells = list.reject { |a| a.elements == 0 }
258
259
  list = with_cells unless with_cells.empty?
259
260
  first, *rest = list.map(&:attrs)
@@ -262,7 +263,7 @@ class CArray
262
263
  end
263
264
  private_class_method :attrs_shared_by
264
265
 
265
- def attr_computing_view? (ca)
266
+ def attr_computing_view?(ca)
266
267
  if ca.is_a?(CAMonOp)
267
268
  op = ca.__op_id__
268
269
  return op < CAMonOp::CAST_BASE && op != CAMonOp::OP_BYTE_SWAP
@@ -271,21 +272,21 @@ class CArray
271
272
  ca.is_a?(CAMonCmp) || ca.is_a?(CABinCmp)
272
273
  end
273
274
 
274
- def attr_normalize_key (key)
275
+ def attr_normalize_key(key)
275
276
  CArray.__send__(:attr_normalize_key, key)
276
277
  end
277
278
 
278
- def attr_validate_value (v)
279
+ def attr_validate_value(v)
279
280
  CArray.__send__(:attr_validate_value, v)
280
281
  end
281
282
 
282
- def attr_coerce_value (v)
283
+ def attr_coerce_value(v)
283
284
  CArray.__send__(:attr_coerce_value, v)
284
285
  end
285
286
 
286
287
  # The key and value rules, as class methods so that CAFrame's attributes
287
288
  # follow the same ones.
288
- def self.attr_normalize_key (key)
289
+ def self.attr_normalize_key(key)
289
290
  case key
290
291
  when String then key
291
292
  when Symbol then key.to_s
@@ -294,7 +295,7 @@ class CArray
294
295
  end
295
296
  end
296
297
 
297
- def self.attr_validate_value (v, depth = 0)
298
+ def self.attr_validate_value(v, depth = 0)
298
299
  raise ArgumentError, "attribute value nests too deep" if depth > 32
299
300
  case v
300
301
  when String, Integer, Float, true, false, nil, Symbol
@@ -314,7 +315,7 @@ class CArray
314
315
  end
315
316
  end
316
317
 
317
- def self.attr_coerce_value (v)
318
+ def self.attr_coerce_value(v)
318
319
  case v
319
320
  when Symbol then v.to_s.freeze
320
321
  when String then v.frozen? ? v : v.dup.freeze
@@ -329,7 +330,7 @@ class CArray
329
330
  end
330
331
  # A stored value with the keys of every Hash in it as Symbols, frozen
331
332
  # as the stored value is.
332
- def self.attr_symbolize_keys (v)
333
+ def self.attr_symbolize_keys(v)
333
334
  case v
334
335
  when Array then v.map { |e| attr_symbolize_keys(e) }.freeze
335
336
  when Hash
@@ -25,28 +25,33 @@
25
25
  class CArray
26
26
  serialize_rb = "carray/serialize"
27
27
  autoload :Serializer, serialize_rb
28
+ private_constant :Serializer
28
29
  autoload_method "self.save", serialize_rb
29
30
  autoload_method "self.load", serialize_rb
30
31
  autoload_method "self.dump", serialize_rb
31
32
  autoload_method "marshal_dump", serialize_rb
32
33
  autoload_method "marshal_load", serialize_rb
34
+ # Marshal calls these; nothing else should.
35
+ private :marshal_dump, :marshal_load
33
36
  end
34
37
 
35
- # A view, a mask, a wrap and a scalar are marshalled through _dump / self._load,
36
- # which return a new array: with marshal_dump Marshal records the class and
37
- # loads into an empty instance of it, which the plain array the payload
38
- # holds cannot become. A record array keeps marshal_dump, under which it
39
- # already round-trips with its class.
40
- [CAView, CAWrap, CScalar, CArrayMask, CAObjectMask].each do |klass|
38
+ # A view, a mask, a wrap, a source and a scalar are marshalled through
39
+ # _dump / self._load, which return a new array: with marshal_dump Marshal
40
+ # records the class and loads into an empty instance of it, which the plain
41
+ # array the payload holds cannot become. A record array keeps marshal_dump,
42
+ # under which it already round-trips with its class.
43
+ [CAView, CAWrap, CASource, CScalar, CArray::Mask, CAObject::Mask].each do |klass|
41
44
  klass.class_eval do
42
45
  undef_method :marshal_dump
43
46
  autoload_method "_dump", "carray/serialize"
44
47
  autoload_method "self._load", "carray/serialize"
48
+ private :_dump
45
49
  end
46
50
  end
47
51
 
48
52
  class CARecord
49
53
  autoload_method "marshal_dump", "carray/serialize"
54
+ private :marshal_dump
50
55
  end
51
56
 
52
57
  # ---- Fusion (reading a lazy expression as a plan) --------------------------
@@ -65,6 +70,7 @@ end
65
70
 
66
71
  class CArray
67
72
  autoload :FuseSource, "carray/fuse_source"
73
+ private_constant :FuseSource
68
74
  end
69
75
 
70
76
  # ---- Iterators (class / slab) ----------------------------------------------
@@ -96,7 +102,7 @@ end
96
102
  # ---- Categorical / Axis-group reduction ------------------------------------
97
103
  #
98
104
  # Classifier is CACategorical; axis_group builds the reduction spec.
99
- # AxisGroup / GroupLabels are top-level;
105
+ # CAAxisGroup is top-level, CArray::GroupLabels sits under CArray;
100
106
  # CAGroupIterator is C-defined (ext/ca_group_iter.c), no autoload.
101
107
  # The C `[]` type gate (ext/ca_group_iter.c) arms itself lazily the first
102
108
  # time a fixlen-surface CArray index appears, so a categorical from any
@@ -120,8 +126,8 @@ end
120
126
  autoload :CACategorical, "carray/categorical"
121
127
  autoload :CACategoricalIterator, "carray/categorical_iterator"
122
128
  autoload :CASegmentIterator, "carray/segment_iterator"
123
- autoload :AxisGroup, "carray/axis_group"
124
- autoload :GroupLabels, "carray/axis_group"
129
+ autoload :CAAxisGroup, "carray/axis_group"
130
+ CArray.autoload :GroupLabels, "carray/axis_group"
125
131
 
126
132
 
127
133
  # ---- CAStruct / CAUnion (fixlen data_class DSL) ----------------------------
@@ -137,13 +143,13 @@ autoload :CAUnion, "carray/struct"
137
143
  # ---- CAFrame (DataFrame over CArray columns) -------------------------------
138
144
  #
139
145
  # The frame is only reached through the CAFrame constant (CAFrame.new /
140
- # .read_csv / subclassing) or GroupedFrame (obtained from CAFrame#group_by,
146
+ # .read_csv / subclassing) or CAGroupedFrame (obtained from CAFrame#group_by,
141
147
  # by which point CAFrame is already loaded). Both constants live in the same
142
148
  # require bundle (carray/frame.rb), so autoloading either loads the whole
143
149
  # frame. Nothing in the eager core references them, so it loads on first use.
144
150
 
145
151
  autoload :CAFrame, "carray/frame"
146
- autoload :GroupedFrame, "carray/frame"
152
+ autoload :CAGroupedFrame, "carray/frame"
147
153
 
148
154
  class CArray
149
155
  autoload_method "to_frame", "carray/frame"
@@ -175,7 +181,7 @@ class CArray
175
181
  end
176
182
 
177
183
  class CAStack
178
- extend AutoloadMethodExtension
184
+ extend CArray.const_get(:AutoloadMethodExtension)
179
185
  autoload_method "append", "carray/stack"
180
186
  end
181
187
 
@@ -218,10 +224,9 @@ class CArray
218
224
  autoload_method "snap_to", "carray/methods/snap"
219
225
  autoload_method "bin", "carray/methods/bin"
220
226
  autoload_method "bin_to", "carray/methods/bin"
221
- autoload_method "index", "carray/methods/index"
222
- autoload_method "indices", "carray/methods/index"
227
+ autoload_method "coordinate", "carray/methods/coordinate"
228
+ autoload_method "coordinates", "carray/methods/coordinate"
223
229
  autoload_method "to_bit_string", "carray/methods/bit_string"
224
- autoload_method "from_bit_string", "carray/methods/bit_string"
225
230
  autoload_method "self.from_bit_string", "carray/methods/bit_string"
226
231
  autoload_method "pack_bits", "carray/methods/bit_string"
227
232
  autoload_method "validity_bits", "carray/methods/bit_string"
@@ -1,7 +1,7 @@
1
1
  # Mixin that adds a small `autoload_method` DSL to a class:
2
2
  #
3
3
  # class Foo
4
- # extend AutoloadMethodExtension
4
+ # extend CArray::AutoloadMethodExtension
5
5
  # autoload_method "self.bar", "libfoo" # singleton method stub
6
6
  # autoload_method "baz", "libfoo" # instance method stub
7
7
  # end
@@ -10,65 +10,72 @@
10
10
  # real definition (which the library must install) replaces the stub
11
11
  # and the original call is forwarded.
12
12
  #
13
- # Defined at the top level instead of nested under CArray so companion
14
- # gems can extend their own classes with the same DSL. Module-wide
15
- # monkey patching is avoided -- only classes that explicitly `extend
16
- # AutoloadMethodExtension` gain the method.
13
+ # Companion gems can extend their own classes with the same DSL.
14
+ # Module-wide monkey patching is avoided -- only classes that explicitly
15
+ # `extend CArray::AutoloadMethodExtension` gain the method.
17
16
 
18
- # @private
19
- module AutoloadMethodExtension
20
- # @!visibility private
21
- def autoload_method (method, library)
22
- if method.to_s =~ /\Aself\.(.+)\z/
23
- name = $1.to_sym
24
- target = singleton_class
25
- else
26
- name = method.to_sym
27
- target = self
17
+ class CArray
18
+ # @private
19
+ module AutoloadMethodExtension
20
+ # Ruby 3.x can deadlock when Ractors require files at the same time, so a
21
+ # stub loads its library only in the main Ractor there. Ruby 4.0 and later
22
+ # load from any Ractor.
23
+ LOAD_IN_MAIN_RACTOR_ONLY = RUBY_VERSION.split(".").first.to_i < 4
24
+
25
+ # @!visibility private
26
+ def autoload_method(method, library)
27
+ if method.to_s =~ /\Aself\.(.+)\z/
28
+ name = $1.to_sym
29
+ target = singleton_class
30
+ else
31
+ name = method.to_sym
32
+ target = self
33
+ end
34
+ autoload_define(target, name, library, method)
28
35
  end
29
- autoload_define(target, name, library, method)
30
- end
31
36
 
32
- private
37
+ private
33
38
 
34
- def autoload_define (target, name, library_given, spec_given)
35
- # The stub reads these two, so they are never assigned again: Ruby 4.0
36
- # refuses to make a Proc shareable when a variable it reads may be.
37
- library = Ractor.make_shareable(library_given.to_s.dup)
38
- original_spec = Ractor.make_shareable(spec_given.to_s.dup)
39
- # Shareable, so the stub answers in any Ractor. Only the main Ractor
40
- # loads the library: Ractors that require at the same time can deadlock
41
- # (Ruby 3.4), so another Ractor is told what to load there instead.
42
- target.define_method(name, &Ractor.make_shareable(proc do |*args, **kwargs, &block|
43
- unless Ractor.current == Ractor.main
44
- raise Ractor::IsolationError,
45
- "'#{original_spec}' is loaded on first use from '#{library}'; " \
46
- "require it in the main Ractor before other Ractors use it"
47
- end
48
- stub_location = target.instance_method(name).source_location
49
- begin
50
- require library
51
- rescue LoadError
52
- raise "error in autoloading '#{library}' hooked by method " \
53
- "'#{original_spec}', check gem installation."
54
- end
55
- # The require is supposed to have replaced this stub with the real
56
- # definition. If it has not, the method does not exist anywhere, and
57
- # forwarding would land straight back here and keep doing so until the
58
- # stack gave out -- naming neither the method nor the library. Say
59
- # which, once.
60
- if target.instance_method(name).source_location == stub_location
61
- raise NoMethodError,
62
- "'#{original_spec}' is registered for autoload from " \
63
- "'#{library}', but that library defines no such method"
64
- end
65
- send(name, *args, **kwargs, &block)
66
- end))
67
- # The library replaces the stub with a plain `def`, which `ruby -w`
68
- # reports as a redefinition. Replacing is what the stub is for, so mark
69
- # it as aliased: Ruby does not warn when the old definition has an alias.
70
- tmp = :"__autoload_stub_#{name}__"
71
- target.send(:alias_method, tmp, name)
72
- target.send(:remove_method, tmp)
39
+ def autoload_define(target, name, library_given, spec_given)
40
+ # The stub reads these two, so they are never assigned again: Ruby 4.0
41
+ # refuses to make a Proc shareable when a variable it reads may be.
42
+ library = Ractor.make_shareable(library_given.to_s.dup)
43
+ original_spec = Ractor.make_shareable(spec_given.to_s.dup)
44
+ # Shareable, so the stub answers in any Ractor. Where only the main
45
+ # Ractor may load (LOAD_IN_MAIN_RACTOR_ONLY), another Ractor is told what
46
+ # to load there instead.
47
+ target.define_method(name, &Ractor.make_shareable(proc do |*args, **kwargs, &block|
48
+ if LOAD_IN_MAIN_RACTOR_ONLY and Ractor.current != Ractor.main
49
+ raise Ractor::IsolationError,
50
+ "'#{original_spec}' is loaded on first use from '#{library}'; " \
51
+ "require it in the main Ractor before other Ractors use it"
52
+ end
53
+ begin
54
+ require library
55
+ rescue LoadError
56
+ raise "error in autoloading '#{library}' hooked by method " \
57
+ "'#{original_spec}', check gem installation."
58
+ end
59
+ # The require is supposed to have replaced this stub with the real
60
+ # definition. If it has not, the method does not exist anywhere, and
61
+ # forwarding would land straight back here and keep doing so until the
62
+ # stack gave out -- naming neither the method nor the library. Say
63
+ # which, once. The stub is told by its file: another Ractor may have
64
+ # replaced it before this call read where the method was defined.
65
+ if target.instance_method(name).source_location&.first == __FILE__
66
+ raise NoMethodError,
67
+ "'#{original_spec}' is registered for autoload from " \
68
+ "'#{library}', but that library defines no such method"
69
+ end
70
+ send(name, *args, **kwargs, &block)
71
+ end))
72
+ # The library replaces the stub with a plain `def`, which `ruby -w`
73
+ # reports as a redefinition. Replacing is what the stub is for, so mark
74
+ # it as aliased: Ruby does not warn when the old definition has an alias.
75
+ tmp = :"__autoload_stub_#{name}__"
76
+ target.send(:alias_method, tmp, name)
77
+ target.send(:remove_method, tmp)
78
+ end
73
79
  end
80
+ private_constant :AutoloadMethodExtension
74
81
  end