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.
- checksums.yaml +4 -4
- data/.yardopts +1 -1
- data/CHANGELOG.md +7 -1830
- data/README.md +62 -35
- 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 +12 -15
- data/ext/ca_bincmp_dispatch.h +16 -38
- data/ext/ca_binop_dispatch.c +35 -0
- data/ext/ca_binop_dispatch.h +22 -46
- 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 -1504
- 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 +92 -165
- data/ext/ca_obj_bincmp.c +65 -48
- data/ext/ca_obj_binop.c +74 -49
- data/ext/ca_obj_bitarray.c +7 -21
- data/ext/ca_obj_bitfield.c +93 -26
- data/ext/ca_obj_block.c +11 -12
- data/ext/ca_obj_byte_swap.c +34 -34
- data/ext/ca_obj_const_string.c +464 -304
- data/ext/ca_obj_face.c +167 -121
- data/ext/ca_obj_face.h +32 -170
- data/ext/ca_obj_fake.c +127 -34
- data/ext/ca_obj_farray.c +13 -9
- data/ext/ca_obj_field.c +17 -13
- data/ext/ca_obj_fixlen_string.c +57 -34
- data/ext/ca_obj_grid.c +149 -113
- data/ext/ca_obj_meld.c +28 -26
- data/ext/ca_obj_moncmp.c +10 -21
- data/ext/ca_obj_monop.c +88 -73
- data/ext/ca_obj_object.c +60 -46
- data/ext/ca_obj_record.c +74 -22
- data/ext/ca_obj_reduce.c +10 -14
- data/ext/ca_obj_refer.c +146 -39
- data/ext/ca_obj_remap.c +11 -29
- data/ext/ca_obj_repeat.c +41 -23
- data/ext/ca_obj_roll.c +20 -28
- data/ext/ca_obj_select.c +17 -27
- data/ext/ca_obj_select_axis.c +35 -42
- data/ext/ca_obj_shift.c +22 -42
- data/ext/ca_obj_source.c +1 -5
- data/ext/ca_obj_stack.c +33 -29
- data/ext/ca_obj_stride.c +99 -62
- data/ext/ca_obj_string.c +8 -20
- data/ext/ca_obj_tile.c +14 -16
- 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 +48 -49
- data/ext/ca_obj_window.c +87 -99
- data/ext/ca_op_cmplx64.h +4 -0
- data/ext/ca_op_ipower.c +97 -27
- data/ext/ca_op_powi.h +9 -28
- 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 +23 -26
- data/ext/ca_sweep_engine.c +92 -26
- data/ext/ca_sweep_engine.h +22 -15
- data/ext/ca_transform_common.c +3 -8
- data/ext/ca_triop_dispatch.h +20 -32
- data/ext/caframe_csv_reader.c +12 -12
- data/ext/carray.h +300 -1009
- data/ext/carray_access.c +320 -207
- data/ext/carray_address_basis.c +128 -59
- data/ext/carray_attribute.c +81 -104
- data/ext/carray_bincount.c +12 -14
- data/ext/carray_broadcast.c +31 -27
- data/ext/carray_call_cfunc.c +174 -285
- data/ext/carray_call_cfunc.h +36 -28
- data/ext/carray_cast.c +1191 -351
- data/ext/carray_cast_func.rb +68 -8
- data/ext/carray_class.c +6 -11
- data/ext/carray_conversion.c +98 -39
- data/ext/carray_copy.c +52 -26
- data/ext/carray_core.c +286 -132
- data/ext/carray_count.c +53 -22
- data/ext/carray_element.c +49 -28
- data/ext/carray_factorize.c +64 -63
- data/ext/carray_generate.c +26 -19
- data/ext/carray_histogram.c +9 -11
- data/ext/carray_hold.c +7 -9
- data/ext/carray_index_classifier.c +127 -230
- data/ext/carray_index_classifier.h +11 -10
- data/ext/carray_integer_total.c +523 -0
- data/ext/carray_internal.h +1364 -156
- data/ext/carray_key_windows.c +3 -3
- data/ext/carray_lazy.c +37 -37
- data/ext/carray_loop.c +27 -23
- data/ext/carray_mask.c +235 -150
- data/ext/carray_math_kernel.h +23 -47
- data/ext/carray_mathfunc.c +10 -3
- data/ext/carray_median_percentile.c +106 -100
- data/ext/carray_memory_view.c +83 -69
- data/ext/carray_operator.c +490 -128
- data/ext/carray_order.c +163 -84
- data/ext/carray_partition.c +14 -16
- data/ext/carray_random.c +48 -42
- data/ext/carray_round.c +33 -5
- data/ext/carray_scatter.c +57 -39
- data/ext/carray_segment.c +42 -46
- data/ext/carray_slab.c +77 -51
- data/ext/carray_slab.h +44 -33
- data/ext/carray_sort.c +37 -31
- data/ext/carray_sort_kernel.c +36 -10
- data/ext/carray_struct.c +44 -34
- data/ext/carray_test.c +131 -81
- data/ext/carray_time_text.c +30 -31
- data/ext/carray_undef.c +50 -7
- data/ext/carray_utils.c +373 -139
- data/ext/extconf.rb +24 -17
- data/ext/mk_call_cfunc.rb +25 -31
- data/ext/mk_pow5_table.rb +2 -1
- data/ext/mkkernel.rb +819 -488
- 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 +272 -185
- data/lib/carray/basics.rb +298 -56
- data/lib/carray/bincount_nd.rb +41 -18
- data/lib/carray/block_iterator.rb +167 -119
- data/lib/carray/boolean_reduce.rb +7 -4
- data/lib/carray/categorical.rb +84 -59
- data/lib/carray/categorical_iterator.rb +90 -67
- data/lib/carray/complex.rb +61 -41
- data/lib/carray/conditional.rb +98 -23
- data/lib/carray/const_string.rb +112 -46
- data/lib/carray/core_extensions.rb +20 -69
- data/lib/carray/distance_limit.rb +7 -5
- data/lib/carray/factories.rb +269 -0
- data/lib/carray/fixlen_string.rb +95 -12
- data/lib/carray/frame/column_verbs.rb +76 -9
- data/lib/carray/frame/concat.rb +51 -7
- data/lib/carray/frame/convert.rb +2 -1
- data/lib/carray/frame/csv_parser.rb +20 -5
- data/lib/carray/frame/frame.rb +73 -31
- data/lib/carray/frame/group.rb +247 -187
- data/lib/carray/frame/io.rb +36 -12
- data/lib/carray/frame/join.rb +56 -17
- data/lib/carray/frame/records.rb +7 -5
- data/lib/carray/frame/reshape.rb +27 -7
- data/lib/carray/frame/sort.rb +10 -8
- data/lib/carray/frame/verbs.rb +217 -134
- data/lib/carray/frame/windows.rb +254 -19
- data/lib/carray/frame.rb +1 -2
- data/lib/carray/fuse_source.rb +28 -23
- 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 +104 -23
- data/lib/carray/key_windows.rb +93 -61
- data/lib/carray/lazy.rb +208 -111
- 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 +8 -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 +73 -72
- data/lib/carray/methods/{index.rb → coordinate.rb} +13 -13
- data/lib/carray/methods/discovery_along.rb +3 -3
- data/lib/carray/methods/factorize.rb +2 -0
- data/lib/carray/methods/gather_nd.rb +106 -103
- 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 +183 -143
- data/lib/carray/methods/join.rb +2 -1
- data/lib/carray/methods/lag.rb +6 -2
- data/lib/carray/methods/locate_addr.rb +157 -94
- 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 +23 -13
- 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 +50 -20
- data/lib/carray/rng.rb +1 -0
- data/lib/carray/runtime.rb +195 -17
- data/lib/carray/segment_iterator.rb +262 -137
- data/lib/carray/serialize.rb +635 -566
- data/lib/carray/slab_iterator.rb +114 -114
- data/lib/carray/stack.rb +14 -15
- data/lib/carray/string.rb +16 -22
- data/lib/carray/string_operation_extension.rb +97 -52
- data/lib/carray/struct.rb +122 -164
- data/lib/carray/struct_builder.rb +247 -73
- data/lib/carray/time.rb +663 -365
- data/lib/carray/window_iterator.rb +232 -155
- 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 +6 -2
- 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 +10 -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 +28 -16
- data/yard-stubs/carray_access.rb +55 -6
- data/yard-stubs/carray_attribute.rb +26 -38
- data/yard-stubs/carray_cast.rb +121 -162
- 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 +10 -5
- 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 +162 -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 +72 -33
- 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 +12 -3
- data/yard-stubs/carray_slab.rb +7 -4
- data/yard-stubs/carray_sort.rb +7 -6
- data/yard-stubs/carray_test.rb +18 -5
- data/yard-stubs/carray_undef.rb +44 -5
- data/yard-stubs/ruby_carray.rb +75 -40
- metadata +63 -25
- 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 -25387
- 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 -261
- data/lib/carray/data_type_limits.rb +0 -91
|
@@ -14,15 +14,14 @@
|
|
|
14
14
|
- a single negative-index normaliser used by all handlers
|
|
15
15
|
- fast paths (POINT / ADDRESS, ndim == argc, all-FIXNUM) at
|
|
16
16
|
the top of the entry point
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
- a one-character Symbol other than :_ / :% / :~ / :> has no
|
|
18
|
+
meaning as an index; the classifier raises IndexError on it,
|
|
19
|
+
which keeps those Symbols free for later index forms.
|
|
20
20
|
|
|
21
21
|
--------------------------------------------------------------------------- */
|
|
22
22
|
|
|
23
23
|
#include "carray.h"
|
|
24
24
|
#include <math.h>
|
|
25
|
-
#include "carray_internal.h" /* ca_index_in_range_at */
|
|
26
25
|
#include "carray_index_classifier.h"
|
|
27
26
|
|
|
28
27
|
/* Range accessor macros — carray_access.c keeps a private cache
|
|
@@ -140,8 +139,7 @@ static void
|
|
|
140
139
|
ca_classifier_invalid_key (VALUE v, int axis)
|
|
141
140
|
{
|
|
142
141
|
volatile VALUE s = rb_inspect(v);
|
|
143
|
-
rb_raise(rb_eIndexError,
|
|
144
|
-
"%s: object '%s' is invalid for the index for reference at %i-dim",
|
|
142
|
+
rb_raise(rb_eIndexError, "%s: %s is not an index for axis %i",
|
|
145
143
|
ca_calling_method_name(), StringValueCStr(s), axis);
|
|
146
144
|
}
|
|
147
145
|
|
|
@@ -194,8 +192,8 @@ ca_index_key_position (VALUE v, ca_size_t *out)
|
|
|
194
192
|
return 0;
|
|
195
193
|
}
|
|
196
194
|
|
|
197
|
-
/* A key that has to name a position: a scalar key, or one inside a Range
|
|
198
|
-
|
|
195
|
+
/* A key that has to name a position: a scalar key, or one inside a Range
|
|
196
|
+
or a step. `where` follows the value in the out-of-range
|
|
199
197
|
message. */
|
|
200
198
|
static ca_size_t
|
|
201
199
|
ca_classifier_key_int_where (VALUE v, int axis, const char *where)
|
|
@@ -310,30 +308,6 @@ ca_classifier_try_address_fast_path (ca_classifier_ctx_t *ctx)
|
|
|
310
308
|
return 1;
|
|
311
309
|
}
|
|
312
310
|
|
|
313
|
-
/* -------------------------------------------------------------------- */
|
|
314
|
-
/* Single-character alphabetic Symbols (`:a`-`:z` / `:A`-`:Z`) are
|
|
315
|
-
reserved: no index form gives them a meaning, and none should
|
|
316
|
-
until one is decided. Raises IndexError saying so, rather than
|
|
317
|
-
the generic "invalid as the index" message. The caller passes
|
|
318
|
-
any Symbol that is not `:_` / `:%`; a non-reserved Symbol
|
|
319
|
-
returns without action. */
|
|
320
|
-
static inline void
|
|
321
|
-
ca_classifier_check_reserved_symbol (VALUE sym)
|
|
322
|
-
{
|
|
323
|
-
const char *name;
|
|
324
|
-
if ( ! SYMBOL_P(sym) ) return;
|
|
325
|
-
name = rb_id2name(SYM2ID(sym));
|
|
326
|
-
if ( name != NULL
|
|
327
|
-
&& name[0] != '\0' && name[1] == '\0'
|
|
328
|
-
&& ( ( name[0] >= 'a' && name[0] <= 'z' )
|
|
329
|
-
|| ( name[0] >= 'A' && name[0] <= 'Z' ) )
|
|
330
|
-
&& name[0] != '_' /* :_ is iterator marker, handled separately */ ) {
|
|
331
|
-
rb_raise(rb_eIndexError,
|
|
332
|
-
"symbol :%s is reserved",
|
|
333
|
-
name);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
311
|
/* -------------------------------------------------------------------- */
|
|
338
312
|
/* Per-axis BLOCK builders.
|
|
339
313
|
*
|
|
@@ -414,8 +388,8 @@ ca_classifier_block_stepped (ca_classifier_ctx_t *ctx, int axis,
|
|
|
414
388
|
ca_size_t dim = ctx->ca_dim[axis];
|
|
415
389
|
|
|
416
390
|
if ( step == 0 ) {
|
|
417
|
-
rb_raise(rb_eArgError,
|
|
418
|
-
|
|
391
|
+
rb_raise(rb_eArgError, "%s: step in index equals to 0 in block reference",
|
|
392
|
+
ca_calling_method_name());
|
|
419
393
|
}
|
|
420
394
|
start = NIL_P(iv_beg) ? ( step < 0 ? dim - 1 : 0 )
|
|
421
395
|
: ca_classifier_key_int(iv_beg, axis);
|
|
@@ -483,140 +457,6 @@ ca_classifier_axis_from_arithseq (ca_classifier_ctx_t *ctx, int axis, VALUE arg)
|
|
|
483
457
|
}
|
|
484
458
|
#endif
|
|
485
459
|
|
|
486
|
-
/* T_ARRAY → BLOCK. Accepts [nil] / [Range] / [Integer] (len 1),
|
|
487
|
-
[nil, step] / [Range, step] / [start, count] (len 2), or
|
|
488
|
-
[start, count, step] (len 3). */
|
|
489
|
-
static void
|
|
490
|
-
ca_classifier_axis_from_array (ca_classifier_ctx_t *ctx, int axis, VALUE arg)
|
|
491
|
-
{
|
|
492
|
-
CAIndexInfo *info = ctx->info;
|
|
493
|
-
ca_size_t dim = ctx->ca_dim[axis];
|
|
494
|
-
long len = RARRAY_LEN(arg);
|
|
495
|
-
|
|
496
|
-
info->index_type[axis] = CA_IDX_BLOCK;
|
|
497
|
-
|
|
498
|
-
if ( len == 1 ) {
|
|
499
|
-
VALUE a0 = rb_ary_entry(arg, 0);
|
|
500
|
-
if ( NIL_P(a0) ) { /* [nil] → ALL */
|
|
501
|
-
info->index_type[axis] = CA_IDX_ALL;
|
|
502
|
-
return;
|
|
503
|
-
}
|
|
504
|
-
if ( rb_obj_is_kind_of(a0, rb_cRange) ) { /* [Range] → recurse */
|
|
505
|
-
ca_classifier_axis_from_range(ctx, axis, a0);
|
|
506
|
-
return;
|
|
507
|
-
}
|
|
508
|
-
/* [Integer] */
|
|
509
|
-
{
|
|
510
|
-
ca_size_t given = ca_classifier_key_int(a0, axis);
|
|
511
|
-
ca_size_t start = given;
|
|
512
|
-
start = ca_index_in_range_at(start, dim, axis);
|
|
513
|
-
info->index[axis].block.start = start;
|
|
514
|
-
info->index[axis].block.count = 1;
|
|
515
|
-
info->index[axis].block.step = 1;
|
|
516
|
-
return;
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
if ( len == 2 ) {
|
|
521
|
-
VALUE a0 = rb_ary_entry(arg, 0);
|
|
522
|
-
VALUE a1 = rb_ary_entry(arg, 1);
|
|
523
|
-
|
|
524
|
-
if ( NIL_P(a0) ) { /* [nil, step] */
|
|
525
|
-
ca_size_t start = 0, count, step;
|
|
526
|
-
step = ca_classifier_key_step(a1, axis);
|
|
527
|
-
if ( step == 0 ) {
|
|
528
|
-
rb_raise(rb_eArgError,
|
|
529
|
-
"step in index equals to 0 in block reference");
|
|
530
|
-
}
|
|
531
|
-
/* every cell of the axis from the first at that step: none of an
|
|
532
|
-
axis of length 0. A negative step from the first cell reaches only
|
|
533
|
-
it. */
|
|
534
|
-
if ( dim == 0 ) {
|
|
535
|
-
count = 0;
|
|
536
|
-
step = 1;
|
|
537
|
-
}
|
|
538
|
-
else if ( step < 0 ) {
|
|
539
|
-
count = 1;
|
|
540
|
-
}
|
|
541
|
-
else {
|
|
542
|
-
count = (dim - 1) / step + 1;
|
|
543
|
-
}
|
|
544
|
-
info->index[axis].block.start = start;
|
|
545
|
-
info->index[axis].block.count = count;
|
|
546
|
-
info->index[axis].block.step = step;
|
|
547
|
-
return;
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
if ( rb_obj_is_kind_of(a0, rb_cRange) ) { /* [Range, step] */
|
|
551
|
-
ca_classifier_block_stepped(ctx, axis,
|
|
552
|
-
CA_CLASSIFIER_RANGE_BEG(a0),
|
|
553
|
-
CA_CLASSIFIER_RANGE_END(a0),
|
|
554
|
-
RTEST(CA_CLASSIFIER_RANGE_EXCL(a0)),
|
|
555
|
-
ca_classifier_key_step(a1, axis));
|
|
556
|
-
return;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
/* [start, count] */
|
|
560
|
-
{
|
|
561
|
-
ca_size_t start, count, bound;
|
|
562
|
-
ca_size_t given;
|
|
563
|
-
given = ca_classifier_key_int(a0, axis);
|
|
564
|
-
count = ca_classifier_key_int(a1, axis);
|
|
565
|
-
/* The start counts from the end when negative; the last cell is
|
|
566
|
-
counted from that start and has to be inside as it is. A count
|
|
567
|
-
of 0 may start at the end of the axis. */
|
|
568
|
-
start = ca_classifier_run_start(given, dim, axis, count == 0);
|
|
569
|
-
if ( count > 0 &&
|
|
570
|
-
( __builtin_add_overflow(start, count - 1, &bound) || bound >= dim ) ) {
|
|
571
|
-
rb_raise(rb_eIndexError,
|
|
572
|
-
"%s: index [%" PRId64 ", %" PRId64 "] is out of range for "
|
|
573
|
-
"length %" PRId64 " on axis %i",
|
|
574
|
-
ca_calling_method_name(), (ca_size_t) given, (ca_size_t) count,
|
|
575
|
-
(ca_size_t) dim, axis);
|
|
576
|
-
}
|
|
577
|
-
info->index[axis].block.start = start;
|
|
578
|
-
info->index[axis].block.count = count;
|
|
579
|
-
info->index[axis].block.step = 1;
|
|
580
|
-
return;
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
if ( len == 3 ) { /* [start, count, step] */
|
|
585
|
-
ca_size_t given, start, count, step, bound;
|
|
586
|
-
given = ca_classifier_key_int(rb_ary_entry(arg, 0), axis);
|
|
587
|
-
count = ca_classifier_key_int(rb_ary_entry(arg, 1), axis);
|
|
588
|
-
step = ca_classifier_key_step(rb_ary_entry(arg, 2), axis);
|
|
589
|
-
if ( step == 0 ) {
|
|
590
|
-
rb_raise(rb_eArgError,
|
|
591
|
-
"step in index equals to 0 in block reference");
|
|
592
|
-
}
|
|
593
|
-
/* The start counts from the end when negative; the last cell is
|
|
594
|
-
counted from that start and has to be inside as it is, not a bound
|
|
595
|
-
that wraps back in from either end. A count of 0 may start at the
|
|
596
|
-
end of the axis. */
|
|
597
|
-
start = ca_classifier_run_start(given, dim, axis, count == 0);
|
|
598
|
-
if ( count > 0 &&
|
|
599
|
-
( __builtin_mul_overflow(count - 1, step, &bound) ||
|
|
600
|
-
__builtin_add_overflow(start, bound, &bound) ||
|
|
601
|
-
bound < 0 || bound >= dim ) ) {
|
|
602
|
-
rb_raise(rb_eIndexError,
|
|
603
|
-
"%s: index [%" PRId64 ", %" PRId64 ", %" PRId64 "] is out of "
|
|
604
|
-
"range for length %" PRId64 " on axis %i",
|
|
605
|
-
ca_calling_method_name(), (ca_size_t) given, (ca_size_t) count,
|
|
606
|
-
(ca_size_t) step, (ca_size_t) dim, axis);
|
|
607
|
-
}
|
|
608
|
-
info->index[axis].block.start = start;
|
|
609
|
-
info->index[axis].block.count = count;
|
|
610
|
-
info->index[axis].block.step = step;
|
|
611
|
-
return;
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
rb_raise(rb_eIndexError,
|
|
615
|
-
"invalid form of index range at %i-dim "
|
|
616
|
-
"(should be [start[,count[,step]]], [range, step])",
|
|
617
|
-
axis);
|
|
618
|
-
}
|
|
619
|
-
|
|
620
460
|
/* -------------------------------------------------------------------- */
|
|
621
461
|
/* Per-axis dispatcher — main-loop body.
|
|
622
462
|
*
|
|
@@ -626,7 +466,7 @@ ca_classifier_axis_from_array (ca_classifier_ctx_t *ctx, int axis, VALUE arg)
|
|
|
626
466
|
* returns 0. Sets *out_is_grid when the GRID short-circuit
|
|
627
467
|
* fires; out_is_grid must not be NULL. */
|
|
628
468
|
static int
|
|
629
|
-
ca_classifier_dispatch_axis_arg (ca_classifier_ctx_t *ctx, int axis, VALUE arg,
|
|
469
|
+
ca_classifier_dispatch_axis_arg (ca_classifier_ctx_t *ctx, int axis, volatile VALUE arg,
|
|
630
470
|
int *out_is_grid)
|
|
631
471
|
{
|
|
632
472
|
CAIndexInfo *info = ctx->info;
|
|
@@ -655,9 +495,21 @@ ca_classifier_dispatch_axis_arg (ca_classifier_ctx_t *ctx, int axis, VALUE arg,
|
|
|
655
495
|
return 0;
|
|
656
496
|
}
|
|
657
497
|
#endif
|
|
498
|
+
/* The first rubber marker was expanded before the keys are read, so one
|
|
499
|
+
reaching here is a second one. */
|
|
500
|
+
if ( arg == Qfalse || arg == ca_classifier_sym_tilde ) {
|
|
501
|
+
rb_raise(rb_eIndexError,
|
|
502
|
+
"%s: only one rubber marker (false or :~) may stand in an index",
|
|
503
|
+
ca_calling_method_name());
|
|
504
|
+
}
|
|
658
505
|
if ( TYPE(arg) == T_ARRAY ) {
|
|
659
|
-
|
|
660
|
-
|
|
506
|
+
/* A Ruby Array is not an index: a run of cells is a Range (with % for a
|
|
507
|
+
step) and a list of positions is a CArray of integers. */
|
|
508
|
+
rb_raise(rb_eTypeError,
|
|
509
|
+
"%s: a Ruby Array is not an index; give a run of cells as a "
|
|
510
|
+
"Range, e.g. start...start + count or (start..) %% step, and a "
|
|
511
|
+
"list of positions as a CArray, e.g. CA_INT64(ary)",
|
|
512
|
+
ca_calling_method_name());
|
|
661
513
|
}
|
|
662
514
|
if ( SYMBOL_P(arg) ) {
|
|
663
515
|
/* :> is the slab-iterator marker. :_ is newaxis, intercepted
|
|
@@ -673,29 +525,35 @@ ca_classifier_dispatch_axis_arg (ca_classifier_ctx_t *ctx, int axis, VALUE arg,
|
|
|
673
525
|
/* :_ reached here because it slipped past the [] / []=
|
|
674
526
|
newaxis hook (typically CArray.scan_index called directly). */
|
|
675
527
|
rb_raise(rb_eIndexError,
|
|
676
|
-
"symbol :_ (newaxis) is handled at the [] / []= level, "
|
|
677
|
-
"not valid in scan_index");
|
|
528
|
+
"%s: symbol :_ (newaxis) is handled at the [] / []= level, "
|
|
529
|
+
"not valid in scan_index", ca_calling_method_name());
|
|
678
530
|
}
|
|
679
|
-
|
|
531
|
+
if ( arg == ca_classifier_sym_perc ) {
|
|
532
|
+
rb_raise(rb_eIndexError,
|
|
533
|
+
"%s: :%% (repeat) is read only by [] and []=, not as the key "
|
|
534
|
+
"of one axis", ca_calling_method_name());
|
|
535
|
+
}
|
|
536
|
+
/* Every other Symbol is refused, and the one-character ones are kept
|
|
537
|
+
free for index forms that may come later. */
|
|
680
538
|
rb_raise(rb_eIndexError,
|
|
681
|
-
"symbol :%"PRIsVALUE"
|
|
682
|
-
"(
|
|
683
|
-
rb_sym2str(arg));
|
|
539
|
+
"%s: symbol :%"PRIsVALUE" has no meaning as an index "
|
|
540
|
+
"(an index takes :_, :%%, :~ and :>)",
|
|
541
|
+
ca_calling_method_name(), rb_sym2str(arg));
|
|
684
542
|
}
|
|
685
543
|
if ( rb_obj_is_carray(arg) ) {
|
|
686
544
|
/* CArray (boolean / integer) at an axis position → GRID.
|
|
687
545
|
Signal the caller to stop populating later axes; the
|
|
688
546
|
main-loop caller breaks out after this axis. */
|
|
689
547
|
CArray *ci;
|
|
690
|
-
|
|
548
|
+
GetCArray(arg, ci);
|
|
691
549
|
if ( ca_is_boolean_type(ci) || ca_is_integer_type(ci) ) {
|
|
692
550
|
if ( out_is_grid ) *out_is_grid = 1;
|
|
693
551
|
return 1; /* signal caller: stop main loop, REG = GRID */
|
|
694
552
|
}
|
|
695
553
|
rb_raise(rb_eIndexError,
|
|
696
|
-
"
|
|
697
|
-
"(
|
|
698
|
-
ca_type_name[ci->data_type], axis);
|
|
554
|
+
"%s: an index of data type %s is not allowed for axis %i "
|
|
555
|
+
"(it must be boolean or integer)",
|
|
556
|
+
ca_calling_method_name(), ca_type_name[ci->data_type], axis);
|
|
699
557
|
}
|
|
700
558
|
ca_classifier_invalid_key(arg, axis);
|
|
701
559
|
}
|
|
@@ -731,7 +589,8 @@ ca_index_expand_rubber (int ndim, long argc, const VALUE *argv, VALUE *out)
|
|
|
731
589
|
}
|
|
732
590
|
if ( argc > ndim + 1 ) {
|
|
733
591
|
rb_raise(rb_eIndexError,
|
|
734
|
-
"index specification exceeds the ndim of carray (%i)",
|
|
592
|
+
"%s: index specification exceeds the ndim of carray (%i)",
|
|
593
|
+
ca_calling_method_name(), ndim);
|
|
735
594
|
}
|
|
736
595
|
/* CAREFUL: rndim == 0 is a valid outcome -- the rubber consumes nothing
|
|
737
596
|
when argc == ndim + 1 (e.g. `[false, 0, 1]` on ndim = 2 collapses to
|
|
@@ -761,8 +620,8 @@ ca_classifier_expand_rubber_dim (ca_classifier_ctx_t *ctx)
|
|
|
761
620
|
/* No rubber dim -- validate argc == ndim and pass through. */
|
|
762
621
|
if ( ctx->argc != ctx->ca_ndim ) {
|
|
763
622
|
rb_raise(rb_eIndexError,
|
|
764
|
-
"%i indices given for a carray of ndim %i",
|
|
765
|
-
(int) ctx->argc, ctx->ca_ndim);
|
|
623
|
+
"%s: %i indices given for a carray of ndim %i",
|
|
624
|
+
ca_calling_method_name(), (int) ctx->argc, ctx->ca_ndim);
|
|
766
625
|
}
|
|
767
626
|
return;
|
|
768
627
|
}
|
|
@@ -771,10 +630,10 @@ ca_classifier_expand_rubber_dim (ca_classifier_ctx_t *ctx)
|
|
|
771
630
|
}
|
|
772
631
|
|
|
773
632
|
/* Read one key along an axis of length dim, as the indexer reads it when
|
|
774
|
-
the key is not a CArray: an Integer, nil, a Range
|
|
775
|
-
ArithmeticSequence
|
|
776
|
-
|
|
777
|
-
|
|
633
|
+
the key is not a CArray: an Integer, nil, a Range or an
|
|
634
|
+
ArithmeticSequence. Fills *start / *count / *step and returns
|
|
635
|
+
CA_IDX_SCALAR (count 1), CA_IDX_ALL (the whole axis) or CA_IDX_BLOCK.
|
|
636
|
+
A Ruby Array raises TypeError, anything else IndexError. grid and CASelectAxis
|
|
778
637
|
read their non-CArray keys through this, so a key means the same cells
|
|
779
638
|
whichever view the indexer builds. */
|
|
780
639
|
int
|
|
@@ -867,7 +726,7 @@ ca_classifier_finalize_reg (ca_classifier_ctx_t *ctx, int is_grid)
|
|
|
867
726
|
static int
|
|
868
727
|
ca_classifier_try_argc1_special (ca_classifier_ctx_t *ctx)
|
|
869
728
|
{
|
|
870
|
-
VALUE arg = ctx->argv[0];
|
|
729
|
+
volatile VALUE arg = ctx->argv[0];
|
|
871
730
|
CAIndexInfo *info = ctx->info;
|
|
872
731
|
|
|
873
732
|
/* A single Qfalse / :~ means ALL, so `ca[:~]` and `ca[false]`
|
|
@@ -887,15 +746,15 @@ ca_classifier_try_argc1_special (ca_classifier_ctx_t *ctx)
|
|
|
887
746
|
return 1;
|
|
888
747
|
}
|
|
889
748
|
|
|
890
|
-
/* argc == 1 CArray → GRID /
|
|
749
|
+
/* argc == 1 CArray → GRID / ADDRESS_ARRAY / SELECT. */
|
|
891
750
|
if ( rb_obj_is_carray(arg) ) {
|
|
892
751
|
CArray *cs;
|
|
893
|
-
|
|
752
|
+
GetCArray(arg, cs);
|
|
894
753
|
if ( ca_is_integer_type(cs) ) {
|
|
895
754
|
if ( ctx->ca_ndim == 1 && cs->ndim == 1 ) {
|
|
896
755
|
info->type = CA_REG_GRID;
|
|
897
756
|
} else {
|
|
898
|
-
info->type =
|
|
757
|
+
info->type = CA_REG_ADDRESS_ARRAY;
|
|
899
758
|
}
|
|
900
759
|
return 1;
|
|
901
760
|
}
|
|
@@ -913,16 +772,18 @@ ca_classifier_try_argc1_special (ca_classifier_ctx_t *ctx)
|
|
|
913
772
|
for (k = 0; k < cs->ndim; k++) rb_ary_push(sshape, SIZE2NUM(cs->dim[k]));
|
|
914
773
|
for (k = 0; k < ctx->ca_ndim; k++) rb_ary_push(ashape, SIZE2NUM(ctx->ca_dim[k]));
|
|
915
774
|
rb_raise(rb_eArgError,
|
|
916
|
-
"boolean selector of shape %"PRIsVALUE" for an array of
|
|
917
|
-
"%"PRIsVALUE" (a selector states its shape; use .flatten
|
|
918
|
-
"select by position)",
|
|
775
|
+
"%s: boolean selector of shape %"PRIsVALUE" for an array of "
|
|
776
|
+
"shape %"PRIsVALUE" (a selector states its shape; use .flatten "
|
|
777
|
+
"to select by position)",
|
|
778
|
+
ca_calling_method_name(), sshape, ashape);
|
|
919
779
|
}
|
|
920
780
|
}
|
|
921
781
|
if ( ctx->ca_elements != cs->elements ) {
|
|
922
782
|
rb_raise(rb_eArgError,
|
|
923
|
-
"
|
|
924
|
-
"
|
|
925
|
-
|
|
783
|
+
"%s: boolean selector of %" PRId64 " elements for an array of "
|
|
784
|
+
"%" PRId64 " elements (a 1-D selector picks by position, one "
|
|
785
|
+
"element per cell)",
|
|
786
|
+
ca_calling_method_name(), (ca_size_t) cs->elements,
|
|
926
787
|
(ca_size_t) ctx->ca_elements);
|
|
927
788
|
}
|
|
928
789
|
info->type = CA_REG_SELECT;
|
|
@@ -930,9 +791,9 @@ ca_classifier_try_argc1_special (ca_classifier_ctx_t *ctx)
|
|
|
930
791
|
return 1;
|
|
931
792
|
}
|
|
932
793
|
rb_raise(rb_eIndexError,
|
|
933
|
-
"
|
|
934
|
-
"(
|
|
935
|
-
ca_type_name[cs->data_type]);
|
|
794
|
+
"%s: a selector of data type %s is not allowed "
|
|
795
|
+
"(it must be boolean or integer)",
|
|
796
|
+
ca_calling_method_name(), ca_type_name[cs->data_type]);
|
|
936
797
|
}
|
|
937
798
|
|
|
938
799
|
/* ndim > 1 with an integer key → ADDRESS. Fixnum was caught by the
|
|
@@ -955,7 +816,16 @@ ca_classifier_try_argc1_special (ca_classifier_ctx_t *ctx)
|
|
|
955
816
|
return 1;
|
|
956
817
|
}
|
|
957
818
|
|
|
958
|
-
/*
|
|
819
|
+
/* :% stands for an axis of self, so a single :% is a repeat that names
|
|
820
|
+
one axis, and the repeat refuses it for a self of more axes. Read as
|
|
821
|
+
an address it would flatten self, which is the role of nil. */
|
|
822
|
+
if ( arg == ca_classifier_sym_perc ) {
|
|
823
|
+
info->type = CA_REG_REPEAT;
|
|
824
|
+
return 1;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
/* ndim > 1 with Range / ArithSeq → ADDRESS_COMPLEX (a Ruby Array is
|
|
828
|
+
refused when argv is re-scanned).
|
|
959
829
|
The classifier only sets info->type here; the actual
|
|
960
830
|
[start, count, step] triple is built by re-scanning argv
|
|
961
831
|
against a flat dim = [elements] at the Ruby surface
|
|
@@ -1001,11 +871,11 @@ rb_ca_scan_index_v2 (int ca_ndim, ca_size_t *ca_dim, ca_size_t ca_elements,
|
|
|
1001
871
|
/* argv[0] = multi-char Symbol → METHOD_CALL. Single-char
|
|
1002
872
|
specials (:_ / :%) fall through the strlen check and are
|
|
1003
873
|
handled downstream (argc == 1 special / fast paths / main
|
|
1004
|
-
loop).
|
|
1005
|
-
|
|
1006
|
-
|
|
874
|
+
loop). Any other single-char Symbol also falls through here
|
|
875
|
+
and is refused later by the per-axis dispatcher's SYMBOL_P
|
|
876
|
+
branch. */
|
|
1007
877
|
if ( SYMBOL_P(argv[0]) ) {
|
|
1008
|
-
const char *name = rb_id2name(SYM2ID(argv[0]));
|
|
878
|
+
const char *name = rb_id2name(SYM2ID(argv[0])); /* name: read at once by strlen */
|
|
1009
879
|
if ( name != NULL && strlen(name) > 1 ) {
|
|
1010
880
|
info->type = CA_REG_METHOD_CALL;
|
|
1011
881
|
info->symbol = argv[0];
|
|
@@ -1053,23 +923,48 @@ rb_ca_scan_index_v2 (int ca_ndim, ca_size_t *ca_dim, ca_size_t ca_elements,
|
|
|
1053
923
|
here would raise on legitimate grid regions. */
|
|
1054
924
|
if ( ! is_grid && ctx.ca_ndim != info->ndim ) {
|
|
1055
925
|
rb_raise(rb_eIndexError,
|
|
1056
|
-
"%i indices given for a carray of ndim %i",
|
|
1057
|
-
info->ndim, ctx.ca_ndim);
|
|
926
|
+
"%s: %i indices given for a carray of ndim %i",
|
|
927
|
+
ca_calling_method_name(), info->ndim, ctx.ca_ndim);
|
|
1058
928
|
}
|
|
1059
929
|
|
|
1060
930
|
ca_classifier_finalize_reg(&ctx, is_grid);
|
|
1061
931
|
}
|
|
1062
932
|
}
|
|
1063
933
|
|
|
934
|
+
/* The kind of index scan_index found, as the Symbol IndexInfo#type holds:
|
|
935
|
+
the region type name in lower case (CA_REG_BLOCK is :block). */
|
|
936
|
+
VALUE
|
|
937
|
+
ca_region_type_symbol (int type)
|
|
938
|
+
{
|
|
939
|
+
switch ( type ) {
|
|
940
|
+
case CA_REG_NONE: return ID2SYM(rb_intern("none"));
|
|
941
|
+
case CA_REG_ALL: return ID2SYM(rb_intern("all"));
|
|
942
|
+
case CA_REG_ADDRESS: return ID2SYM(rb_intern("address"));
|
|
943
|
+
case CA_REG_FLATTEN: return ID2SYM(rb_intern("flatten"));
|
|
944
|
+
case CA_REG_ADDRESS_COMPLEX: return ID2SYM(rb_intern("address_complex"));
|
|
945
|
+
case CA_REG_POINT: return ID2SYM(rb_intern("point"));
|
|
946
|
+
case CA_REG_BLOCK: return ID2SYM(rb_intern("block"));
|
|
947
|
+
case CA_REG_SELECT: return ID2SYM(rb_intern("select"));
|
|
948
|
+
case CA_REG_ITERATOR: return ID2SYM(rb_intern("iterator"));
|
|
949
|
+
case CA_REG_REPEAT: return ID2SYM(rb_intern("repeat"));
|
|
950
|
+
case CA_REG_GRID: return ID2SYM(rb_intern("grid"));
|
|
951
|
+
case CA_REG_ADDRESS_ARRAY: return ID2SYM(rb_intern("address_array"));
|
|
952
|
+
case CA_REG_METHOD_CALL: return ID2SYM(rb_intern("method_call"));
|
|
953
|
+
case CA_REG_MEMBER: return ID2SYM(rb_intern("member"));
|
|
954
|
+
case CA_REG_ATTRIBUTE: return ID2SYM(rb_intern("attribute"));
|
|
955
|
+
}
|
|
956
|
+
rb_bug("unknown index region type %d", type);
|
|
957
|
+
}
|
|
958
|
+
|
|
1064
959
|
#ifdef CARRAY_DEV_BUILD
|
|
1065
960
|
/* -------------------------------------------------------------------- */
|
|
1066
961
|
/* Debug / test surface: CArray._scan_index_v2(dim_array, idx_array)
|
|
1067
|
-
returns a plain [
|
|
962
|
+
returns a plain [type, index_array] pair rather than the
|
|
1068
963
|
full CAIndexInfo struct. Kept for spec regression checks and
|
|
1069
964
|
downstream introspection. */
|
|
1070
965
|
|
|
1071
966
|
static VALUE
|
|
1072
|
-
rb_ca_s_scan_index_v2 (VALUE self, VALUE rdim, VALUE ridx)
|
|
967
|
+
rb_ca_s_scan_index_v2 (VALUE self, VALUE rdim, volatile VALUE ridx)
|
|
1073
968
|
{
|
|
1074
969
|
CAIndexInfo info;
|
|
1075
970
|
ca_size_t dim[CA_RANK_MAX];
|
|
@@ -1079,6 +974,8 @@ rb_ca_s_scan_index_v2 (VALUE self, VALUE rdim, VALUE ridx)
|
|
|
1079
974
|
|
|
1080
975
|
Check_Type(rdim, T_ARRAY);
|
|
1081
976
|
Check_Type(ridx, T_ARRAY);
|
|
977
|
+
/* Converting an entry can run Ruby that changes the Array: read a copy. */
|
|
978
|
+
ridx = rb_ary_dup(ridx);
|
|
1082
979
|
|
|
1083
980
|
ndim = (int) RARRAY_LEN(rdim);
|
|
1084
981
|
elements = 1;
|
|
@@ -1087,8 +984,8 @@ rb_ca_s_scan_index_v2 (VALUE self, VALUE rdim, VALUE ridx)
|
|
|
1087
984
|
elements *= dim[i];
|
|
1088
985
|
}
|
|
1089
986
|
|
|
1090
|
-
|
|
1091
|
-
|
|
987
|
+
CA_CHECK_RANK(ndim);
|
|
988
|
+
CA_CHECK_DIM(ndim, dim);
|
|
1092
989
|
|
|
1093
990
|
info.range_check = 1;
|
|
1094
991
|
rb_ca_scan_index_v2(ndim, dim, elements,
|
|
@@ -1102,7 +999,7 @@ rb_ca_s_scan_index_v2 (VALUE self, VALUE rdim, VALUE ridx)
|
|
|
1102
999
|
case CA_REG_SELECT:
|
|
1103
1000
|
case CA_REG_REPEAT:
|
|
1104
1001
|
case CA_REG_GRID:
|
|
1105
|
-
case
|
|
1002
|
+
case CA_REG_ADDRESS_ARRAY:
|
|
1106
1003
|
case CA_REG_METHOD_CALL:
|
|
1107
1004
|
case CA_REG_MEMBER:
|
|
1108
1005
|
case CA_REG_ATTRIBUTE:
|
|
@@ -1127,10 +1024,10 @@ rb_ca_s_scan_index_v2 (VALUE self, VALUE rdim, VALUE ridx)
|
|
|
1127
1024
|
depending on which per-axis kind the flat re-scan produced. */
|
|
1128
1025
|
switch ( flat_info.index_type[0] ) {
|
|
1129
1026
|
case CA_IDX_BLOCK:
|
|
1130
|
-
inner =
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1027
|
+
inner = rb_ary_new_from_args(3,
|
|
1028
|
+
SIZE2NUM(flat_info.index[0].block.start),
|
|
1029
|
+
SIZE2NUM(flat_info.index[0].block.count),
|
|
1030
|
+
SIZE2NUM(flat_info.index[0].block.step));
|
|
1134
1031
|
rb_ary_push(rindex, inner);
|
|
1135
1032
|
break;
|
|
1136
1033
|
case CA_IDX_SCALAR:
|
|
@@ -1138,8 +1035,8 @@ rb_ca_s_scan_index_v2 (VALUE self, VALUE rdim, VALUE ridx)
|
|
|
1138
1035
|
break;
|
|
1139
1036
|
case CA_IDX_ALL:
|
|
1140
1037
|
rb_ary_push(rindex,
|
|
1141
|
-
|
|
1142
|
-
|
|
1038
|
+
rb_ary_new_from_args(3, INT2NUM(0), SIZE2NUM(elements),
|
|
1039
|
+
INT2NUM(1)));
|
|
1143
1040
|
break;
|
|
1144
1041
|
default: break;
|
|
1145
1042
|
}
|
|
@@ -1159,22 +1056,22 @@ rb_ca_s_scan_index_v2 (VALUE self, VALUE rdim, VALUE ridx)
|
|
|
1159
1056
|
break;
|
|
1160
1057
|
case CA_IDX_ALL:
|
|
1161
1058
|
rb_ary_push(rindex,
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1059
|
+
rb_ary_new_from_args(3, INT2NUM(0),
|
|
1060
|
+
rb_ary_entry(rdim, i),
|
|
1061
|
+
INT2NUM(1)));
|
|
1165
1062
|
break;
|
|
1166
1063
|
case CA_IDX_BLOCK:
|
|
1167
1064
|
rb_ary_push(rindex,
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1065
|
+
rb_ary_new_from_args(3,
|
|
1066
|
+
SIZE2NUM(info.index[i].block.start),
|
|
1067
|
+
SIZE2NUM(info.index[i].block.count),
|
|
1068
|
+
SIZE2NUM(info.index[i].block.step)));
|
|
1172
1069
|
break;
|
|
1173
1070
|
case CA_IDX_SYMBOL:
|
|
1174
1071
|
rb_ary_push(rindex,
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1072
|
+
rb_ary_new_from_args(2,
|
|
1073
|
+
ID2SYM(info.index[i].symbol.id),
|
|
1074
|
+
info.index[i].symbol.spec));
|
|
1178
1075
|
break;
|
|
1179
1076
|
default:
|
|
1180
1077
|
rb_raise(rb_eIndexError, "unknown index spec");
|
|
@@ -1185,7 +1082,7 @@ rb_ca_s_scan_index_v2 (VALUE self, VALUE rdim, VALUE ridx)
|
|
|
1185
1082
|
rb_raise(rb_eArgError, "unknown index specification");
|
|
1186
1083
|
}
|
|
1187
1084
|
|
|
1188
|
-
return
|
|
1085
|
+
return rb_ary_new_from_args(2, ca_region_type_symbol(info.type), rindex);
|
|
1189
1086
|
}
|
|
1190
1087
|
#endif
|
|
1191
1088
|
|
|
@@ -2,15 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
carray_index_classifier.h
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The index classifier behind rb_ca_scan_index: rb_ca_scan_index (in
|
|
6
|
+
ext/carray_access.c) forwards to rb_ca_scan_index_v2, defined in
|
|
7
|
+
ext/carray_index_classifier.c. It reads CAIndexInfo, which carray_internal.h
|
|
8
|
+
declares.
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
After I.6, rb_ca_scan_index forwards here.
|
|
11
|
-
|
|
12
|
-
The public C API signature (= void rb_ca_scan_index(...)) is
|
|
13
|
-
unchanged; this header is internal and intentionally not exported.
|
|
10
|
+
This header is internal to carray and carries no contract. It is not
|
|
11
|
+
installed; it ships in the gem's ext/ directory only because carray is
|
|
12
|
+
built from it there.
|
|
14
13
|
|
|
15
14
|
--------------------------------------------------------------------------- */
|
|
16
15
|
|
|
@@ -19,9 +18,11 @@
|
|
|
19
18
|
|
|
20
19
|
#include "carray.h"
|
|
21
20
|
|
|
22
|
-
/*
|
|
23
|
-
the I.6 swap is a single-line forward call. */
|
|
21
|
+
/* The classifier's entry point, with the signature of rb_ca_scan_index. */
|
|
24
22
|
void rb_ca_scan_index_v2 (int ca_ndim, ca_size_t *ca_dim, ca_size_t ca_elements,
|
|
25
23
|
long argc, VALUE *argv, CAIndexInfo *info);
|
|
26
24
|
|
|
25
|
+
/* The Symbol CArray::IndexInfo#type holds for a CA_REG_* region type. */
|
|
26
|
+
VALUE ca_region_type_symbol (int type);
|
|
27
|
+
|
|
27
28
|
#endif /* CARRAY_INDEX_CLASSIFIER_H */
|