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.
- checksums.yaml +4 -4
- data/.yardopts +1 -1
- data/CHANGELOG.md +7 -1940
- data/README.md +38 -32
- data/carray.gemspec +16 -4
- data/docs/changelogs/CHANGELOG-3.0.md +2464 -0
- data/ext/ca_array_pool.c +4 -5
- data/ext/ca_axis_descriptor.h +45 -30
- data/ext/ca_axis_dispatch.c +7 -4
- data/ext/ca_axis_group.c +6 -9
- data/ext/ca_bincmp_dispatch.h +16 -38
- data/ext/ca_binop_dispatch.c +27 -0
- data/ext/ca_binop_dispatch.h +22 -47
- data/ext/ca_categorical_iterator.c +36 -34
- data/ext/ca_compare.c +0 -1
- data/ext/ca_compare.h +8 -1
- data/ext/ca_composite_dispatch.h +6 -0
- data/ext/ca_for_buffer.h +6 -1
- data/ext/ca_group_iter.c +17 -18
- data/ext/ca_iter_state_fields.h +196 -0
- data/ext/ca_iter_substrate.h +84 -103
- data/ext/ca_kernel_iterator.c +125 -89
- data/ext/ca_kernel_iterator.h +229 -1506
- data/ext/ca_kernel_iterator_internal.h +1167 -0
- data/ext/ca_moncmp_dispatch.h +17 -24
- data/ext/ca_monop_dispatch.h +25 -74
- data/ext/ca_obj_array.c +90 -163
- data/ext/ca_obj_bincmp.c +47 -46
- data/ext/ca_obj_binop.c +38 -38
- data/ext/ca_obj_bitarray.c +5 -17
- data/ext/ca_obj_bitfield.c +15 -30
- data/ext/ca_obj_block.c +11 -12
- data/ext/ca_obj_byte_swap.c +32 -30
- data/ext/ca_obj_const_string.c +57 -62
- data/ext/ca_obj_face.c +99 -91
- data/ext/ca_obj_face.h +32 -170
- data/ext/ca_obj_fake.c +15 -21
- data/ext/ca_obj_farray.c +7 -9
- data/ext/ca_obj_field.c +17 -13
- data/ext/ca_obj_fixlen_string.c +8 -19
- data/ext/ca_obj_grid.c +137 -106
- data/ext/ca_obj_meld.c +23 -21
- data/ext/ca_obj_moncmp.c +10 -21
- data/ext/ca_obj_monop.c +24 -35
- data/ext/ca_obj_object.c +51 -37
- data/ext/ca_obj_record.c +74 -22
- data/ext/ca_obj_reduce.c +8 -10
- data/ext/ca_obj_refer.c +42 -29
- data/ext/ca_obj_remap.c +11 -29
- data/ext/ca_obj_repeat.c +41 -23
- data/ext/ca_obj_roll.c +18 -24
- data/ext/ca_obj_select.c +10 -22
- data/ext/ca_obj_select_axis.c +27 -36
- data/ext/ca_obj_shift.c +22 -42
- data/ext/ca_obj_source.c +1 -5
- data/ext/ca_obj_stack.c +28 -24
- data/ext/ca_obj_stride.c +53 -54
- data/ext/ca_obj_string.c +6 -18
- data/ext/ca_obj_tile.c +12 -12
- data/ext/ca_obj_time.c +12 -23
- data/ext/ca_obj_timedelta.c +12 -23
- data/ext/ca_obj_transpose.c +8 -10
- data/ext/ca_obj_triop.c +35 -39
- data/ext/ca_obj_window.c +67 -86
- data/ext/ca_op_cmplx64.h +4 -0
- data/ext/ca_op_ipower.c +34 -12
- data/ext/ca_op_powi.h +4 -0
- data/ext/ca_pow5_table.h +2 -1
- data/ext/ca_rng_normal.h +4 -0
- data/ext/ca_rng_xoshiro256pp.h +3 -0
- data/ext/ca_sort_kernels.h +20 -26
- data/ext/ca_sweep_engine.c +2 -3
- data/ext/ca_sweep_engine.h +17 -9
- data/ext/ca_transform_common.c +3 -8
- data/ext/ca_triop_dispatch.h +20 -32
- data/ext/caframe_csv_reader.c +11 -11
- data/ext/carray.h +300 -1011
- data/ext/carray_access.c +234 -180
- data/ext/carray_address_basis.c +33 -38
- data/ext/carray_attribute.c +81 -104
- data/ext/carray_bincount.c +12 -14
- data/ext/carray_broadcast.c +30 -26
- data/ext/carray_call_cfunc.c +169 -277
- data/ext/carray_call_cfunc.h +36 -28
- data/ext/carray_cast.c +912 -346
- data/ext/carray_cast_func.rb +31 -3
- data/ext/carray_class.c +6 -11
- data/ext/carray_conversion.c +43 -38
- data/ext/carray_copy.c +28 -26
- data/ext/carray_core.c +217 -126
- data/ext/carray_count.c +27 -15
- data/ext/carray_element.c +40 -25
- data/ext/carray_factorize.c +53 -52
- data/ext/carray_generate.c +26 -19
- data/ext/carray_histogram.c +8 -10
- data/ext/carray_hold.c +7 -9
- data/ext/carray_index_classifier.c +123 -228
- data/ext/carray_index_classifier.h +11 -10
- data/ext/carray_integer_total.c +523 -0
- data/ext/carray_internal.h +1274 -160
- data/ext/carray_key_windows.c +3 -3
- data/ext/carray_lazy.c +21 -36
- data/ext/carray_loop.c +19 -22
- data/ext/carray_mask.c +123 -145
- data/ext/carray_math_kernel.h +23 -47
- data/ext/carray_mathfunc.c +10 -3
- data/ext/carray_median_percentile.c +95 -94
- data/ext/carray_memory_view.c +42 -47
- data/ext/carray_operator.c +423 -122
- data/ext/carray_order.c +121 -85
- data/ext/carray_partition.c +13 -15
- data/ext/carray_random.c +47 -41
- data/ext/carray_round.c +9 -4
- data/ext/carray_scatter.c +54 -40
- data/ext/carray_segment.c +41 -45
- data/ext/carray_slab.c +64 -47
- data/ext/carray_slab.h +44 -33
- data/ext/carray_sort.c +32 -29
- data/ext/carray_sort_kernel.c +12 -10
- data/ext/carray_struct.c +38 -43
- data/ext/carray_test.c +47 -43
- data/ext/carray_time_text.c +24 -31
- data/ext/carray_undef.c +50 -7
- data/ext/carray_utils.c +258 -94
- data/ext/extconf.rb +24 -17
- data/ext/mk_call_cfunc.rb +19 -20
- data/ext/mk_pow5_table.rb +2 -1
- data/ext/mkkernel.rb +782 -461
- data/ext/ruby_carray.c +47 -42
- data/ext/version.h +7 -5
- data/lib/carray/attribute.rb +19 -18
- data/lib/carray/autoload_carray.rb +20 -15
- data/lib/carray/autoload_method_extension.rb +64 -57
- data/lib/carray/axis_group.rb +264 -180
- data/lib/carray/basics.rb +272 -48
- data/lib/carray/bincount_nd.rb +33 -16
- data/lib/carray/block_iterator.rb +123 -102
- data/lib/carray/boolean_reduce.rb +7 -4
- data/lib/carray/categorical.rb +63 -51
- data/lib/carray/categorical_iterator.rb +89 -67
- data/lib/carray/complex.rb +61 -41
- data/lib/carray/conditional.rb +49 -22
- data/lib/carray/const_string.rb +54 -62
- data/lib/carray/core_extensions.rb +1 -1
- data/lib/carray/distance_limit.rb +7 -5
- data/lib/carray/factories.rb +269 -0
- data/lib/carray/fixlen_string.rb +25 -24
- data/lib/carray/frame/column_verbs.rb +20 -8
- data/lib/carray/frame/concat.rb +3 -3
- data/lib/carray/frame/convert.rb +2 -1
- data/lib/carray/frame/csv_parser.rb +7 -1
- data/lib/carray/frame/frame.rb +35 -25
- data/lib/carray/frame/group.rb +183 -150
- data/lib/carray/frame/io.rb +26 -7
- data/lib/carray/frame/join.rb +37 -12
- data/lib/carray/frame/records.rb +1 -1
- data/lib/carray/frame/reshape.rb +3 -3
- data/lib/carray/frame/sort.rb +10 -8
- data/lib/carray/frame/verbs.rb +148 -118
- data/lib/carray/frame/windows.rb +232 -21
- data/lib/carray/frame.rb +1 -2
- data/lib/carray/fuse_source.rb +24 -21
- data/lib/carray/fusion.rb +30 -30
- data/lib/carray/histogram.rb +35 -16
- data/lib/carray/inspect.rb +7 -7
- data/lib/carray/iterator.rb +97 -24
- data/lib/carray/key_windows.rb +83 -57
- data/lib/carray/lazy.rb +196 -94
- data/lib/carray/limits.rb +80 -0
- data/lib/carray/mask_gap_fill.rb +21 -16
- data/lib/carray/math.rb +87 -50
- data/lib/carray/meld_reduce.rb +30 -8
- data/lib/carray/methods/align_addr.rb +29 -17
- data/lib/carray/methods/bin.rb +5 -1
- data/lib/carray/methods/bincount.rb +4 -2
- data/lib/carray/methods/bit_string.rb +19 -31
- data/lib/carray/methods/broadcast.rb +8 -3
- data/lib/carray/methods/choose.rb +5 -5
- data/lib/carray/methods/composition.rb +72 -71
- data/lib/carray/methods/{index.rb → coordinate.rb} +13 -13
- data/lib/carray/methods/discovery_along.rb +3 -3
- data/lib/carray/methods/gather_nd.rb +106 -106
- data/lib/carray/methods/insert_block.rb +2 -2
- data/lib/carray/methods/is_between.rb +6 -4
- data/lib/carray/methods/is_in.rb +165 -145
- data/lib/carray/methods/join.rb +2 -1
- data/lib/carray/methods/lag.rb +6 -2
- data/lib/carray/methods/locate_addr.rb +150 -138
- data/lib/carray/methods/mask_duplicates.rb +1 -1
- data/lib/carray/methods/meshgrid.rb +28 -16
- data/lib/carray/methods/mode.rb +67 -67
- data/lib/carray/methods/nunique.rb +9 -7
- data/lib/carray/methods/repeat.rb +12 -12
- data/lib/carray/methods/resize.rb +1 -1
- data/lib/carray/methods/snap.rb +24 -20
- data/lib/carray/methods/string_format.rb +2 -2
- data/lib/carray/methods/unique.rb +4 -2
- data/lib/carray/methods/value_counts.rb +1 -1
- data/lib/carray/mkmf.rb +25 -28
- data/lib/carray/percentile_arguments.rb +82 -0
- data/lib/carray/record_order.rb +18 -17
- data/lib/carray/rng.rb +1 -0
- data/lib/carray/runtime.rb +190 -22
- data/lib/carray/segment_iterator.rb +251 -129
- data/lib/carray/serialize.rb +618 -571
- data/lib/carray/slab_iterator.rb +114 -114
- data/lib/carray/stack.rb +11 -12
- data/lib/carray/string.rb +16 -22
- data/lib/carray/string_operation_extension.rb +76 -52
- data/lib/carray/struct.rb +122 -164
- data/lib/carray/struct_builder.rb +243 -72
- data/lib/carray/time.rb +496 -342
- data/lib/carray/window_iterator.rb +191 -150
- data/lib/carray.rb +6 -11
- data/yard-stubs/ca_obj_array.rb +20 -135
- data/yard-stubs/ca_obj_bitarray.rb +1 -8
- data/yard-stubs/ca_obj_bitfield.rb +4 -3
- data/yard-stubs/ca_obj_byte_swap.rb +21 -7
- data/yard-stubs/ca_obj_fake.rb +3 -1
- data/yard-stubs/ca_obj_farray.rb +1 -1
- data/yard-stubs/ca_obj_field.rb +8 -6
- data/yard-stubs/ca_obj_refer.rb +7 -5
- data/yard-stubs/ca_obj_roll.rb +7 -6
- data/yard-stubs/ca_obj_shift.rb +2 -3
- data/yard-stubs/ca_obj_stride.rb +5 -7
- data/yard-stubs/ca_obj_tile.rb +1 -1
- data/yard-stubs/ca_obj_time.rb +43 -0
- data/yard-stubs/ca_obj_transpose.rb +1 -1
- data/yard-stubs/ca_obj_window.rb +26 -15
- data/yard-stubs/carray_access.rb +51 -4
- data/yard-stubs/carray_attribute.rb +26 -38
- data/yard-stubs/carray_cast.rb +118 -165
- data/yard-stubs/carray_class.rb +3 -4
- data/yard-stubs/carray_conversion.rb +6 -7
- data/yard-stubs/carray_copy.rb +2 -1
- data/yard-stubs/carray_count.rb +5 -3
- data/yard-stubs/carray_element.rb +4 -3
- data/yard-stubs/carray_limits.rb +100 -0
- data/yard-stubs/carray_loop.rb +0 -20
- data/yard-stubs/carray_mask.rb +59 -41
- data/yard-stubs/carray_math.rb +157 -100
- data/yard-stubs/carray_mathfunc.rb +415 -3
- data/yard-stubs/carray_median_percentile.rb +29 -11
- data/yard-stubs/carray_memory_view.rb +2 -2
- data/yard-stubs/carray_order.rb +67 -34
- data/yard-stubs/carray_random.rb +6 -6
- data/yard-stubs/carray_reduce.rb +353 -0
- data/yard-stubs/carray_rng.rb +92 -0
- data/yard-stubs/carray_scatter.rb +10 -2
- data/yard-stubs/carray_slab.rb +7 -4
- data/yard-stubs/carray_sort.rb +7 -6
- data/yard-stubs/carray_undef.rb +44 -5
- data/yard-stubs/ruby_carray.rb +75 -40
- metadata +62 -24
- data/CHANGELOG.v1.md +0 -126
- data/ext/carray_build_flags.h +0 -3
- data/ext/carray_config.h +0 -28
- data/ext/carray_data_type.c +0 -90
- data/ext/carray_kernels_bincmp.c +0 -6457
- data/ext/carray_kernels_binop.c +0 -31534
- data/ext/carray_kernels_init.c +0 -1734
- data/ext/carray_kernels_moncmp.c +0 -2104
- data/ext/carray_kernels_monop.c +0 -25337
- data/ext/carray_kernels_reduce_aggregate.c +0 -27545
- data/ext/carray_kernels_reduce_boolean.c +0 -1924
- data/ext/carray_kernels_reduce_cumulative.c +0 -11646
- data/ext/carray_kernels_reduce_extreme.c +0 -21631
- data/ext/carray_kernels_reduce_variance.c +0 -5981
- data/ext/carray_kernels_scan.c +0 -4302
- data/ext/carray_kernels_search.c +0 -37776
- data/ext/carray_kernels_sort.c +0 -10814
- data/ext/carray_kernels_triop.c +0 -1864
- data/lib/carray/construct.rb +0 -360
- data/lib/carray/data_type_extension.rb +0 -262
- 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 (); /*
|
|
51
|
-
void Init_ca_group_iter (); /*
|
|
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.
|
|
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
|
|
168
|
-
rb_cCAStrideMask
|
|
169
|
-
rb_cCAReferMask
|
|
170
|
-
rb_cCABlockMask
|
|
171
|
-
rb_cCAFieldMask
|
|
172
|
-
rb_cCASelectMask
|
|
173
|
-
rb_cCARepeatMask
|
|
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(
|
|
190
|
-
rb_define_const(rb_cCArray, "VERSION", rb_obj_freeze(
|
|
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(
|
|
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(
|
|
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.
|
|
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
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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(); /*
|
|
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(); /*
|
|
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
|
-
|
|
2
|
-
|
|
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
|
|
5
|
-
#define CA_VERSION_TEENY
|
|
6
|
-
#define CA_VERSION_DATE "2026/
|
|
6
|
+
#define CA_VERSION_MINOR 1
|
|
7
|
+
#define CA_VERSION_TEENY 0
|
|
8
|
+
#define CA_VERSION_DATE "2026/12/04"
|
data/lib/carray/attribute.rb
CHANGED
|
@@ -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` / `
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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?
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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?
|
|
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
|
|
275
|
+
def attr_normalize_key(key)
|
|
275
276
|
CArray.__send__(:attr_normalize_key, key)
|
|
276
277
|
end
|
|
277
278
|
|
|
278
|
-
def attr_validate_value
|
|
279
|
+
def attr_validate_value(v)
|
|
279
280
|
CArray.__send__(:attr_validate_value, v)
|
|
280
281
|
end
|
|
281
282
|
|
|
282
|
-
def attr_coerce_value
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
36
|
-
# which return a new array: with marshal_dump Marshal
|
|
37
|
-
# loads into an empty instance of it, which the plain
|
|
38
|
-
# holds cannot become. A record array keeps marshal_dump,
|
|
39
|
-
# already round-trips with its class.
|
|
40
|
-
[CAView, CAWrap, CScalar,
|
|
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
|
-
#
|
|
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 :
|
|
124
|
-
autoload :GroupLabels,
|
|
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
|
|
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 :
|
|
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 "
|
|
222
|
-
autoload_method "
|
|
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
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
37
|
+
private
|
|
33
38
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|