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/ca_obj_refer.c
CHANGED
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
---------------------------------------------------------------------------- */
|
|
15
15
|
|
|
16
16
|
#include "carray.h"
|
|
17
|
-
#include "carray_internal.h" /* per-obj_type view constructors */
|
|
18
17
|
#include "ca_obj_face.h" /* CA_FACE_LIFT_IF_FACE for CARecord parent */
|
|
19
18
|
#include "ruby/thread_native.h"
|
|
20
19
|
|
|
@@ -52,7 +51,7 @@ const rb_data_type_t carefer_data_type = {
|
|
|
52
51
|
|
|
53
52
|
const rb_data_type_t carefer_mask_data_type = {
|
|
54
53
|
.parent = &carefer_data_type,
|
|
55
|
-
.wrap_struct_name = "
|
|
54
|
+
.wrap_struct_name = "CARefer::Mask",
|
|
56
55
|
.function = {
|
|
57
56
|
.dmark = NULL,
|
|
58
57
|
.dfree = ca_free_nop,
|
|
@@ -75,10 +74,10 @@ ca_refer_setup (CARefer *ca, CArray *parent,
|
|
|
75
74
|
ca_size_t s;
|
|
76
75
|
int8_t i;
|
|
77
76
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
CA_CHECK_DATA_TYPE(data_type);
|
|
78
|
+
CA_CHECK_RANK(ndim);
|
|
79
|
+
CA_CHECK_DIM(ndim, dim);
|
|
80
|
+
CA_CHECK_BYTES(data_type, bytes);
|
|
82
81
|
|
|
83
82
|
/* An object cell is a VALUE the GC marks: reading other bytes as one
|
|
84
83
|
marks garbage, and reading one as bytes exposes an address. */
|
|
@@ -261,7 +260,7 @@ rb_ca_refer_s_allocate (VALUE klass)
|
|
|
261
260
|
}
|
|
262
261
|
|
|
263
262
|
static VALUE
|
|
264
|
-
rb_ca_refer_initialize_copy (VALUE self, VALUE other)
|
|
263
|
+
rb_ca_refer_initialize_copy (volatile VALUE self, volatile VALUE other)
|
|
265
264
|
{
|
|
266
265
|
CARefer *ca, *cs;
|
|
267
266
|
TypedData_Get_Struct(self, CARefer, &carefer_data_type, ca);
|
|
@@ -601,7 +600,7 @@ ca_reshape_try_strides (CArray *parent,
|
|
|
601
600
|
build the options themselves (a Hash at the end of argv is read as
|
|
602
601
|
options only when the Ruby caller passed keywords). */
|
|
603
602
|
static VALUE
|
|
604
|
-
rb_ca_refer_kw (int argc, VALUE *argv, VALUE ropt, VALUE self)
|
|
603
|
+
rb_ca_refer_kw (int argc, VALUE *argv, VALUE ropt, volatile VALUE self)
|
|
605
604
|
{
|
|
606
605
|
volatile VALUE obj = Qnil;
|
|
607
606
|
CArray *ca;
|
|
@@ -612,7 +611,7 @@ rb_ca_refer_kw (int argc, VALUE *argv, VALUE ropt, VALUE self)
|
|
|
612
611
|
ca_size_t bytes, offset = 0;
|
|
613
612
|
int8_t i;
|
|
614
613
|
|
|
615
|
-
|
|
614
|
+
GetCArray(self, ca);
|
|
616
615
|
|
|
617
616
|
if (argc == 0 && NIL_P(ropt)) {
|
|
618
617
|
data_type = ca->data_type;
|
|
@@ -624,10 +623,15 @@ rb_ca_refer_kw (int argc, VALUE *argv, VALUE ropt, VALUE self)
|
|
|
624
623
|
rb_ca_set_parent(obj, self);
|
|
625
624
|
}
|
|
626
625
|
else {
|
|
627
|
-
|
|
628
|
-
rb_scan_args(argc, argv, "11",
|
|
626
|
+
VALUE rtype, rdim, rbytes = Qnil, roffset = Qnil;
|
|
627
|
+
rb_scan_args(argc, argv, "11", &rtype, &rdim);
|
|
629
628
|
rb_scan_options(ropt, "bytes,offset", &rbytes, &roffset);
|
|
630
|
-
|
|
629
|
+
ca_refuse_type_number(rtype);
|
|
630
|
+
/* A :fixlen refer without bytes: is as wide as self. */
|
|
631
|
+
if ( NIL_P(rbytes) && TYPE(rtype) != T_CLASS &&
|
|
632
|
+
rb_ca_guess_type(rtype) == CA_FIXLEN ) {
|
|
633
|
+
rbytes = rb_ca_bytes(self);
|
|
634
|
+
}
|
|
631
635
|
rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
|
|
632
636
|
if (NIL_P(rdim)) {
|
|
633
637
|
if (ca->bytes != bytes) {
|
|
@@ -652,7 +656,7 @@ rb_ca_refer_kw (int argc, VALUE *argv, VALUE ropt, VALUE self)
|
|
|
652
656
|
}
|
|
653
657
|
}
|
|
654
658
|
Check_Type(rdim, T_ARRAY);
|
|
655
|
-
|
|
659
|
+
CA_CHECK_RANK(RARRAY_LEN(rdim)); /* before dim[] is filled */
|
|
656
660
|
ndim = RARRAY_LEN(rdim);
|
|
657
661
|
for (i = 0; i < ndim; i++) dim[i] = ca_integer_arg(rb_ary_entry(rdim, i), "a dimension", NULL);
|
|
658
662
|
if (! NIL_P(roffset)) offset = ca_integer_arg(roffset, "the offset", NULL);
|
|
@@ -663,7 +667,7 @@ rb_ca_refer_kw (int argc, VALUE *argv, VALUE ropt, VALUE self)
|
|
|
663
667
|
if ( rb_obj_is_data_class(rtype) ) {
|
|
664
668
|
volatile VALUE base = rb_ca_strip_face_value(self);
|
|
665
669
|
CArray *base_ca;
|
|
666
|
-
|
|
670
|
+
GetCArray(base, base_ca);
|
|
667
671
|
cr = ca_refer_new(base_ca, data_type, ndim, dim, bytes, offset);
|
|
668
672
|
obj = ca_wrap_struct(cr);
|
|
669
673
|
rb_ca_set_parent(obj, base);
|
|
@@ -697,16 +701,16 @@ rb_ca_refer_new (VALUE self,
|
|
|
697
701
|
volatile VALUE list, rdim, ropt;
|
|
698
702
|
int8_t i;
|
|
699
703
|
|
|
700
|
-
rdim =
|
|
704
|
+
rdim = rb_ary_new_capa(ndim);
|
|
701
705
|
for (i = 0; i < ndim; i++) {
|
|
702
706
|
rb_ary_store(rdim, i, SIZE2NUM(dim[i]));
|
|
703
707
|
}
|
|
704
708
|
|
|
705
|
-
list =
|
|
709
|
+
list = rb_ary_new_capa(3);
|
|
706
710
|
if (data_type == CA_FIXLEN && rb_ca_has_data_class(self)) {
|
|
707
711
|
rb_ary_store(list, 0, rb_ca_data_class(self));
|
|
708
712
|
} else {
|
|
709
|
-
rb_ary_store(list, 0,
|
|
713
|
+
rb_ary_store(list, 0, ID2SYM(ca_data_type_sym[data_type]));
|
|
710
714
|
}
|
|
711
715
|
rb_ary_store(list, 1, rdim);
|
|
712
716
|
ropt = rb_hash_new();
|
|
@@ -732,7 +736,7 @@ rb_ca_refer_new (VALUE self,
|
|
|
732
736
|
|
|
733
737
|
Faces stay lifted: rb_ca_value_array depends on that and says so
|
|
734
738
|
where it marks the storage level. */
|
|
735
|
-
|
|
739
|
+
GetCArray(obj, co);
|
|
736
740
|
if ( ca_is_lazy_marker(co) ) {
|
|
737
741
|
obj = rb_ca_parent(obj);
|
|
738
742
|
}
|
|
@@ -760,7 +764,7 @@ rb_ca_refer_new (VALUE self,
|
|
|
760
764
|
For typed-dim usage (bypassing the placeholder vocabulary) call
|
|
761
765
|
rb_ca_refer_new(self, ca->data_type, ndim, dim, ca->bytes, 0). */
|
|
762
766
|
VALUE
|
|
763
|
-
rb_ca_reshape (int argc, VALUE *argv, VALUE self)
|
|
767
|
+
rb_ca_reshape (int argc, VALUE *argv, volatile VALUE self)
|
|
764
768
|
{
|
|
765
769
|
CArray *ca;
|
|
766
770
|
CARefer *cr;
|
|
@@ -772,7 +776,8 @@ rb_ca_reshape (int argc, VALUE *argv, VALUE self)
|
|
|
772
776
|
volatile VALUE obj;
|
|
773
777
|
VALUE sym_tilde = ID2SYM(rb_intern("~")); /* :~ = infer-placeholder alias for -1 */
|
|
774
778
|
|
|
775
|
-
|
|
779
|
+
rb_reject_options(rb_pop_options(&argc, &argv));
|
|
780
|
+
GetCArray(self, ca);
|
|
776
781
|
|
|
777
782
|
if ( argc == 0 ) {
|
|
778
783
|
rb_raise(rb_eArgError, "reshape: give at least one axis");
|
|
@@ -851,10 +856,18 @@ rb_ca_reshape (int argc, VALUE *argv, VALUE self)
|
|
|
851
856
|
a subset), and on non-contiguous parents the compose-fold
|
|
852
857
|
path corrupts data outright — hence the raise. */
|
|
853
858
|
if (prod != ca->elements) {
|
|
859
|
+
/* Name the shape with each nil replaced by the axis it copied, so
|
|
860
|
+
the reader sees where the element count comes from. */
|
|
861
|
+
volatile VALUE shape = rb_str_new_cstr("[");
|
|
862
|
+
for (i = 0; i < argc; i++) {
|
|
863
|
+
rb_str_catf(shape, (i ? ", %lld" : "%lld"), (long long) new_dim[i]);
|
|
864
|
+
}
|
|
865
|
+
rb_str_cat_cstr(shape, "]");
|
|
854
866
|
rb_raise(rb_eArgError,
|
|
855
|
-
"reshape: cannot reshape array of %lld elements into
|
|
856
|
-
"of %lld elements (use -1 / :~ to infer a dim)",
|
|
857
|
-
(long long) ca->elements, (
|
|
867
|
+
"reshape: cannot reshape array of %lld elements into the shape "
|
|
868
|
+
"%s of %lld elements (use -1 / :~ to infer a dim)",
|
|
869
|
+
(long long) ca->elements, StringValueCStr(shape),
|
|
870
|
+
(long long) prod);
|
|
858
871
|
}
|
|
859
872
|
}
|
|
860
873
|
|
|
@@ -887,14 +900,14 @@ rb_ca_reshape (int argc, VALUE *argv, VALUE self)
|
|
|
887
900
|
(a CAStride when ca_reshape_try_strides succeeds, otherwise a
|
|
888
901
|
CARefer). Also exported (declared in carray.h). */
|
|
889
902
|
VALUE
|
|
890
|
-
rb_ca_flatten (VALUE self)
|
|
903
|
+
rb_ca_flatten (volatile VALUE self)
|
|
891
904
|
{
|
|
892
905
|
CArray *ca;
|
|
893
906
|
CARefer *cr;
|
|
894
907
|
ca_size_t dim[1];
|
|
895
908
|
volatile VALUE obj;
|
|
896
909
|
|
|
897
|
-
|
|
910
|
+
GetCArray(self, ca);
|
|
898
911
|
dim[0] = ca->elements;
|
|
899
912
|
|
|
900
913
|
{
|
|
@@ -935,7 +948,7 @@ rb_ca_flatten (VALUE self)
|
|
|
935
948
|
carray_median_percentile.c) can call directly; they pass a single axis,
|
|
936
949
|
for which the source and output frames coincide. */
|
|
937
950
|
VALUE
|
|
938
|
-
rb_ca_insert_axis (int argc, VALUE *argv, VALUE self)
|
|
951
|
+
rb_ca_insert_axis (int argc, VALUE *argv, volatile VALUE self)
|
|
939
952
|
{
|
|
940
953
|
CArray *ca;
|
|
941
954
|
VALUE new_argv[CA_RANK_MAX];
|
|
@@ -943,7 +956,8 @@ rb_ca_insert_axis (int argc, VALUE *argv, VALUE self)
|
|
|
943
956
|
int ndim, new_ndim, ngap;
|
|
944
957
|
int i, c, k;
|
|
945
958
|
|
|
946
|
-
|
|
959
|
+
rb_reject_options(rb_pop_options(&argc, &argv));
|
|
960
|
+
GetCArray(self, ca);
|
|
947
961
|
|
|
948
962
|
ndim = (int) ca->ndim;
|
|
949
963
|
new_ndim = ndim + argc;
|
|
@@ -957,7 +971,7 @@ rb_ca_insert_axis (int argc, VALUE *argv, VALUE self)
|
|
|
957
971
|
gap_count[i] = 0;
|
|
958
972
|
}
|
|
959
973
|
for (i = 0; i < argc; i++) {
|
|
960
|
-
int g =
|
|
974
|
+
int g = rb_ca_normalize_axis_arg(argv[i], ngap, "insert_axis");
|
|
961
975
|
gap_count[g]++;
|
|
962
976
|
}
|
|
963
977
|
|
|
@@ -996,7 +1010,6 @@ Init_ca_obj_refer (void)
|
|
|
996
1010
|
ca_refer_func.struct_size = sizeof(CARefer);
|
|
997
1011
|
ca_func[CA_OBJ_REFER] = ca_refer_func;
|
|
998
1012
|
|
|
999
|
-
rb_define_const(rb_cObject, "CA_OBJ_REFER", INT2NUM(CA_OBJ_REFER));
|
|
1000
1013
|
|
|
1001
1014
|
rb_define_method(rb_cCArray, "refer", rb_ca_refer, -1);
|
|
1002
1015
|
rb_define_method(rb_cCArray, "reshape", rb_ca_reshape, -1);
|
data/ext/ca_obj_remap.c
CHANGED
|
@@ -18,19 +18,9 @@
|
|
|
18
18
|
---------------------------------------------------------------------------- */
|
|
19
19
|
|
|
20
20
|
#include "carray.h"
|
|
21
|
-
#include "carray_internal.h"
|
|
22
21
|
|
|
23
22
|
typedef struct {
|
|
24
|
-
|
|
25
|
-
int8_t data_type;
|
|
26
|
-
int8_t ndim;
|
|
27
|
-
int32_t flags;
|
|
28
|
-
ca_size_t bytes;
|
|
29
|
-
ca_size_t elements;
|
|
30
|
-
ca_size_t *dim;
|
|
31
|
-
char *ptr;
|
|
32
|
-
CArray *mask;
|
|
33
|
-
char *_pool; /* framework-managed pool buffer (NULL = legacy ALLOC_N path). */
|
|
23
|
+
CA_ARRAY_HEADER
|
|
34
24
|
CArray *parent; /* = ref */
|
|
35
25
|
uint32_t attach;
|
|
36
26
|
uint8_t nosync;
|
|
@@ -38,7 +28,7 @@ typedef struct {
|
|
|
38
28
|
CArray *idx; /* shared reference; data_type = CA_SIZE, same shape as parent */
|
|
39
29
|
} CARemap;
|
|
40
30
|
|
|
41
|
-
static
|
|
31
|
+
static int16_t CA_OBJ_REMAP;
|
|
42
32
|
|
|
43
33
|
/* Ruby classes — rb_define_class'd in Init so users see the right
|
|
44
34
|
class name on .class inspection. No constructor is bound (no
|
|
@@ -83,7 +73,7 @@ const rb_data_type_t caremap_data_type = {
|
|
|
83
73
|
|
|
84
74
|
const rb_data_type_t caremap_mask_data_type = {
|
|
85
75
|
.parent = &caremap_data_type,
|
|
86
|
-
.wrap_struct_name = "
|
|
76
|
+
.wrap_struct_name = "CARemap::Mask",
|
|
87
77
|
.function = {
|
|
88
78
|
.dmark = NULL,
|
|
89
79
|
.dfree = ca_free_nop,
|
|
@@ -476,7 +466,7 @@ ca_operation_function_t ca_remap_func = {
|
|
|
476
466
|
keep their indices where Ruby cannot reach them; this is the same
|
|
477
467
|
promise for an index array that stays visible. */
|
|
478
468
|
VALUE
|
|
479
|
-
rb_ca_remap_new (VALUE cary, VALUE rmapper)
|
|
469
|
+
rb_ca_remap_new (volatile VALUE cary, volatile VALUE rmapper)
|
|
480
470
|
{
|
|
481
471
|
volatile VALUE obj;
|
|
482
472
|
CArray *ref, *idx;
|
|
@@ -484,8 +474,8 @@ rb_ca_remap_new (VALUE cary, VALUE rmapper)
|
|
|
484
474
|
|
|
485
475
|
rb_check_carray_object(cary);
|
|
486
476
|
rb_check_carray_object(rmapper);
|
|
487
|
-
|
|
488
|
-
|
|
477
|
+
GetCArray(cary, ref);
|
|
478
|
+
GetCArray(rmapper, idx);
|
|
489
479
|
|
|
490
480
|
ca = ca_remap_new(ref, idx);
|
|
491
481
|
obj = ca_wrap_struct(ca);
|
|
@@ -516,7 +506,7 @@ rb_ca_remap_mapper (VALUE self)
|
|
|
516
506
|
Object#dup cannot copy it; these build the copy the way the indexer
|
|
517
507
|
does: a new view over the same parent and the same index array. */
|
|
518
508
|
static VALUE
|
|
519
|
-
rb_ca_remap_dup (VALUE self)
|
|
509
|
+
rb_ca_remap_dup (volatile VALUE self)
|
|
520
510
|
{
|
|
521
511
|
volatile VALUE rmapper = rb_ivar_get(self, rb_intern("remap_idx"));
|
|
522
512
|
if ( NIL_P(rmapper) ) {
|
|
@@ -525,7 +515,7 @@ rb_ca_remap_dup (VALUE self)
|
|
|
525
515
|
of keeps both alive, so the copy holds that array too. */
|
|
526
516
|
volatile VALUE obj;
|
|
527
517
|
CArray *ca, *cp;
|
|
528
|
-
|
|
518
|
+
GetCArray(self, ca);
|
|
529
519
|
cp = (CArray *) ca_remap_func_clone(ca);
|
|
530
520
|
ca_keep_chain_flags(cp, ca);
|
|
531
521
|
obj = TypedData_Wrap_Struct(rb_obj_class(self), &caremap_data_type, cp);
|
|
@@ -542,16 +532,8 @@ rb_ca_remap_clone (int argc, VALUE *argv, VALUE self)
|
|
|
542
532
|
VALUE opts = Qnil, vfreeze = Qnil;
|
|
543
533
|
volatile VALUE obj;
|
|
544
534
|
rb_scan_args(argc, argv, "0:", &opts);
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
ID kw[1];
|
|
548
|
-
VALUE val[1];
|
|
549
|
-
kw[0] = rb_intern("freeze");
|
|
550
|
-
rb_get_kwargs(opts, kw, 0, 1, val);
|
|
551
|
-
if ( val[0] != Qundef ) {
|
|
552
|
-
vfreeze = val[0];
|
|
553
|
-
}
|
|
554
|
-
}
|
|
535
|
+
/* Any key but freeze: is refused, as Kernel#clone does. */
|
|
536
|
+
rb_scan_options(opts, "freeze", &vfreeze);
|
|
555
537
|
obj = rb_ca_remap_dup(self);
|
|
556
538
|
if ( RTEST(vfreeze) || ( NIL_P(vfreeze) && OBJ_FROZEN(self) ) ) {
|
|
557
539
|
rb_obj_freeze(obj);
|
|
@@ -569,7 +551,7 @@ Init_ca_obj_remap (void)
|
|
|
569
551
|
integer remains unexported (it's an internal type tag, not
|
|
570
552
|
user-meaningful). */
|
|
571
553
|
rb_cCARemap = rb_define_class("CARemap", rb_cCAView);
|
|
572
|
-
rb_cCARemapMask =
|
|
554
|
+
rb_cCARemapMask = rb_define_class_under(rb_cCARemap, "Mask", rb_cCARemap);
|
|
573
555
|
rb_undef_alloc_func(rb_cCARemap);
|
|
574
556
|
rb_undef_alloc_func(rb_cCARemapMask);
|
|
575
557
|
rb_define_method(rb_cCARemap, "dup", rb_ca_remap_dup, 0);
|
data/ext/ca_obj_repeat.c
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
---------------------------------------------------------------------------- */
|
|
11
11
|
|
|
12
12
|
#include "carray.h"
|
|
13
|
-
#include "carray_internal.h" /* per-obj_type view constructors */
|
|
14
13
|
#include "ca_obj_face.h" /* CA_FACE_LIFT_IF_FACE */
|
|
15
14
|
|
|
16
15
|
extern ca_operation_function_t ca_stride_func;
|
|
@@ -109,13 +108,13 @@ ca_repeat_new (CArray *parent, int8_t ndim, ca_size_t *count)
|
|
|
109
108
|
/* ------------------------------------------------------------------- */
|
|
110
109
|
|
|
111
110
|
VALUE
|
|
112
|
-
rb_ca_repeat_new (VALUE cary, int8_t ndim, ca_size_t *count)
|
|
111
|
+
rb_ca_repeat_new (volatile VALUE cary, int8_t ndim, ca_size_t *count)
|
|
113
112
|
{
|
|
114
113
|
volatile VALUE obj;
|
|
115
114
|
CArray *parent;
|
|
116
115
|
CAStride *ca;
|
|
117
116
|
rb_check_carray_object(cary);
|
|
118
|
-
|
|
117
|
+
GetCArray(cary, parent);
|
|
119
118
|
ca = ca_repeat_new(parent, ndim, count);
|
|
120
119
|
obj = ca_wrap_struct(ca);
|
|
121
120
|
rb_ca_set_parent(obj, cary);
|
|
@@ -138,8 +137,9 @@ rb_ca_repeat_new (VALUE cary, int8_t ndim, ca_size_t *count)
|
|
|
138
137
|
|
|
139
138
|
Called by carray_access.c indexer dispatch when the index includes
|
|
140
139
|
the :% symbol (e.g. `a[:%, nil, :%, 3]`). */
|
|
140
|
+
/* recursion: re-enters once, with the arguments rewritten */
|
|
141
141
|
VALUE
|
|
142
|
-
rb_ca_repeat (int argc, VALUE *argv, VALUE self)
|
|
142
|
+
rb_ca_repeat (int argc, VALUE *argv, volatile VALUE self)
|
|
143
143
|
{
|
|
144
144
|
volatile VALUE obj;
|
|
145
145
|
CArray *ca;
|
|
@@ -147,7 +147,7 @@ rb_ca_repeat (int argc, VALUE *argv, VALUE self)
|
|
|
147
147
|
ca_size_t repeat;
|
|
148
148
|
ca_size_t i;
|
|
149
149
|
|
|
150
|
-
|
|
150
|
+
GetCArray(self, ca);
|
|
151
151
|
|
|
152
152
|
if ( argc == 2 &&
|
|
153
153
|
(
|
|
@@ -159,13 +159,18 @@ rb_ca_repeat (int argc, VALUE *argv, VALUE self)
|
|
|
159
159
|
ca_size_t ndim, dim[CA_RANK_MAX];
|
|
160
160
|
int k;
|
|
161
161
|
if ( argv[0] == ID2SYM(rb_intern("%") ) ) {
|
|
162
|
-
|
|
162
|
+
/* gc: argv holds it for the call */
|
|
163
|
+
GetCArray(argv[1], ct);
|
|
163
164
|
}
|
|
164
165
|
else {
|
|
165
|
-
|
|
166
|
+
/* gc: argv holds it for the call */
|
|
167
|
+
GetCArray(argv[0], ct);
|
|
166
168
|
}
|
|
167
169
|
if ( ct->ndim < ca->ndim ) {
|
|
168
|
-
rb_raise(rb_eArgError,
|
|
170
|
+
rb_raise(rb_eArgError,
|
|
171
|
+
"%s: a template of %d axes for an array of %d axes; the "
|
|
172
|
+
"template beside :%% needs at least the array's axes",
|
|
173
|
+
ca_calling_method_name(), (int) ct->ndim, (int) ca->ndim);
|
|
169
174
|
}
|
|
170
175
|
args = rb_ary_new();
|
|
171
176
|
ndim = 0;
|
|
@@ -216,29 +221,43 @@ rb_ca_repeat (int argc, VALUE *argv, VALUE self)
|
|
|
216
221
|
}
|
|
217
222
|
}
|
|
218
223
|
self = rb_ca_repeat((int)RARRAY_LEN(args), (VALUE *)RARRAY_CONST_PTR(args), self);
|
|
219
|
-
RB_GC_GUARD(args); /* the repeat reads its arguments out of args */
|
|
220
224
|
return self;
|
|
221
225
|
}
|
|
222
226
|
|
|
223
227
|
ca_check_rank_fits(argc, NULL); /* count[] and dim[] hold CA_RANK_MAX */
|
|
224
228
|
|
|
225
229
|
repeat = 1;
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
+
{
|
|
231
|
+
int ndata = 0;
|
|
232
|
+
for (i=0; i<argc; i++) {
|
|
233
|
+
if ( rb_obj_is_kind_of(argv[i], rb_cSymbol) ) {
|
|
234
|
+
if ( argv[i] == ID2SYM(rb_intern("%")) ) {
|
|
235
|
+
count[i] = 0;
|
|
236
|
+
ndata++;
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
rb_raise(rb_eArgError,
|
|
240
|
+
"%s: symbol :%"PRIsVALUE" is not a repeat count (:%% "
|
|
241
|
+
"stands for an axis of the array, an Integer repeats)",
|
|
242
|
+
ca_calling_method_name(), rb_sym2str(argv[i]));
|
|
243
|
+
}
|
|
230
244
|
}
|
|
231
245
|
else {
|
|
232
|
-
|
|
246
|
+
count[i] = ca_integer_arg(argv[i], "a repeat count",
|
|
247
|
+
ca_calling_method_name());
|
|
248
|
+
if ( count[i] <= 0 ) {
|
|
249
|
+
rb_raise(rb_eArgError,
|
|
250
|
+
"%s: a repeat count must be 1 or more (got %"PRId64")",
|
|
251
|
+
ca_calling_method_name(), (int64_t) count[i]);
|
|
252
|
+
}
|
|
253
|
+
repeat *= count[i];
|
|
233
254
|
}
|
|
234
255
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
repeat *= count[i];
|
|
256
|
+
if ( ndata != ca->ndim ) {
|
|
257
|
+
rb_raise(rb_eArgError,
|
|
258
|
+
"%s: %d :%% given for an array of %d axes (one :%% stands "
|
|
259
|
+
"for each axis of the array)",
|
|
260
|
+
ca_calling_method_name(), ndata, (int) ca->ndim);
|
|
242
261
|
}
|
|
243
262
|
}
|
|
244
263
|
|
|
@@ -265,7 +284,7 @@ rb_ca_repeat (int argc, VALUE *argv, VALUE self)
|
|
|
265
284
|
}
|
|
266
285
|
|
|
267
286
|
static VALUE
|
|
268
|
-
rb_ca_repeat_initialize_copy (VALUE self, VALUE other)
|
|
287
|
+
rb_ca_repeat_initialize_copy (volatile VALUE self, volatile VALUE other)
|
|
269
288
|
{
|
|
270
289
|
CAStride *ca, *cs;
|
|
271
290
|
TypedData_Get_Struct(self, CAStride, &castride_data_type, ca);
|
|
@@ -287,7 +306,6 @@ Init_ca_obj_repeat (void)
|
|
|
287
306
|
{
|
|
288
307
|
/* rb_cCARepeat, CA_OBJ_REPEAT are defined in ruby_carray.c / carray_core.c */
|
|
289
308
|
|
|
290
|
-
rb_define_const(rb_cObject, "CA_OBJ_REPEAT", INT2NUM(CA_OBJ_REPEAT));
|
|
291
309
|
|
|
292
310
|
rb_define_method(rb_cCARepeat, "initialize_copy",
|
|
293
311
|
rb_ca_repeat_initialize_copy, 1);
|
data/ext/ca_obj_roll.c
CHANGED
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
---------------------------------------------------------------------------- */
|
|
18
18
|
|
|
19
19
|
#include "carray.h"
|
|
20
|
-
#include "carray_internal.h"
|
|
21
20
|
#include "ca_composite_dispatch.h"
|
|
22
21
|
#include "ca_obj_face.h"
|
|
23
22
|
|
|
@@ -55,7 +54,7 @@ const rb_data_type_t caroll_data_type = {
|
|
|
55
54
|
|
|
56
55
|
const rb_data_type_t caroll_mask_data_type = {
|
|
57
56
|
.parent = &caroll_data_type,
|
|
58
|
-
.wrap_struct_name = "
|
|
57
|
+
.wrap_struct_name = "CARoll::Mask",
|
|
59
58
|
.function = {
|
|
60
59
|
.dmark = ca_mark,
|
|
61
60
|
.dfree = ca_free_nop,
|
|
@@ -65,7 +64,7 @@ const rb_data_type_t caroll_mask_data_type = {
|
|
|
65
64
|
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
66
65
|
};
|
|
67
66
|
|
|
68
|
-
|
|
67
|
+
int16_t CA_OBJ_ROLL;
|
|
69
68
|
|
|
70
69
|
VALUE rb_cCARoll;
|
|
71
70
|
VALUE rb_cCARollMask;
|
|
@@ -80,7 +79,7 @@ ca_operation_function_t ca_roll_func;
|
|
|
80
79
|
shift[k] > 0 : shift right (last shift[k] elements wrap to front)
|
|
81
80
|
shift[k] < 0 : shift left
|
|
82
81
|
shift[k] is normalised into [0, parent.dim[k]) modulo dim[k].
|
|
83
|
-
|
|
82
|
+
Ruby's roll takes one shift for each axis. */
|
|
84
83
|
int
|
|
85
84
|
ca_roll_setup (CARoll *ca, CArray *parent, ca_size_t *shift)
|
|
86
85
|
{
|
|
@@ -609,48 +608,43 @@ ca_roll_func_create_mask (void *ap)
|
|
|
609
608
|
/* ------------------------------------------------------------------- */
|
|
610
609
|
|
|
611
610
|
VALUE
|
|
612
|
-
rb_ca_roll_new (VALUE cary, ca_size_t *shift)
|
|
611
|
+
rb_ca_roll_new (volatile VALUE cary, ca_size_t *shift)
|
|
613
612
|
{
|
|
614
613
|
volatile VALUE obj;
|
|
615
614
|
CArray *parent;
|
|
616
615
|
CARoll *ca;
|
|
617
616
|
rb_check_carray_object(cary);
|
|
618
|
-
|
|
617
|
+
GetCArray(cary, parent);
|
|
619
618
|
ca = ca_roll_new(parent, shift);
|
|
620
619
|
obj = ca_wrap_struct(ca);
|
|
621
620
|
rb_ca_set_parent(obj, cary);
|
|
622
621
|
return obj;
|
|
623
622
|
}
|
|
624
623
|
|
|
625
|
-
/* CArray#roll(*shifts) — cyclic shift along each axis
|
|
626
|
-
|
|
627
|
-
argc > ndim : ArgumentError. */
|
|
624
|
+
/* CArray#roll(*shifts) — cyclic shift along each axis, one shift per
|
|
625
|
+
axis (ndim of them); any other number is an ArgumentError. */
|
|
628
626
|
static VALUE
|
|
629
|
-
rb_ca_roll (int argc, VALUE *argv, VALUE self)
|
|
627
|
+
rb_ca_roll (int argc, VALUE *argv, volatile VALUE self)
|
|
630
628
|
{
|
|
631
629
|
CArray *ca;
|
|
632
630
|
volatile VALUE ropt;
|
|
633
631
|
ca_size_t shift[CA_RANK_MAX];
|
|
634
632
|
int8_t i;
|
|
635
633
|
|
|
636
|
-
|
|
634
|
+
GetCArray(self, ca);
|
|
637
635
|
|
|
638
636
|
/* Shifts are positional only. A trailing Hash is a keyword argument
|
|
639
637
|
that would otherwise reach NUM2SIZE and surface as a TypeError. */
|
|
640
638
|
ropt = rb_pop_options(&argc, &argv);
|
|
641
639
|
rb_reject_options(ropt);
|
|
642
640
|
|
|
643
|
-
if ( argc
|
|
641
|
+
if ( argc != ca->ndim ) {
|
|
644
642
|
rb_raise(rb_eArgError,
|
|
645
|
-
"roll:
|
|
646
|
-
|
|
643
|
+
"roll: give one shift per axis (%d for this array, got %d)",
|
|
644
|
+
(int) ca->ndim, argc);
|
|
647
645
|
}
|
|
648
646
|
for ( i = 0; i < ca->ndim; i++ ) {
|
|
649
|
-
|
|
650
|
-
shift[i] = ca_integer_arg(argv[i], "a shift", NULL);
|
|
651
|
-
} else {
|
|
652
|
-
shift[i] = 0;
|
|
653
|
-
}
|
|
647
|
+
shift[i] = ca_integer_arg(argv[i], "a shift", NULL);
|
|
654
648
|
}
|
|
655
649
|
{
|
|
656
650
|
VALUE obj = rb_ca_roll_new(self, shift);
|
|
@@ -670,7 +664,7 @@ rb_ca_roll_s_allocate (VALUE klass)
|
|
|
670
664
|
}
|
|
671
665
|
|
|
672
666
|
static VALUE
|
|
673
|
-
rb_ca_roll_initialize_copy (VALUE self, VALUE other)
|
|
667
|
+
rb_ca_roll_initialize_copy (volatile VALUE self, volatile VALUE other)
|
|
674
668
|
{
|
|
675
669
|
CARoll *ca, *cs;
|
|
676
670
|
TypedData_Get_Struct(self, CARoll, &caroll_data_type, ca);
|
|
@@ -685,12 +679,13 @@ rb_ca_roll_initialize_copy (VALUE self, VALUE other)
|
|
|
685
679
|
/* Debug-only accessor returning the roll descriptor as a Hash
|
|
686
680
|
(`shifts`, `n_regions`, `ndim`). Not part of the public surface. */
|
|
687
681
|
static VALUE
|
|
688
|
-
rb_ca_roll_descriptor (VALUE self)
|
|
682
|
+
rb_ca_roll_descriptor (volatile VALUE self)
|
|
689
683
|
{
|
|
690
|
-
CARoll *ca
|
|
684
|
+
CARoll *ca;
|
|
691
685
|
VALUE hash, shifts_ary;
|
|
692
686
|
int8_t k;
|
|
693
687
|
int n_shifted = 0;
|
|
688
|
+
TypedData_Get_Struct(self, CARoll, &caroll_data_type, ca);
|
|
694
689
|
|
|
695
690
|
shifts_ary = rb_ary_new_capa(ca->ndim);
|
|
696
691
|
for ( k = 0; k < ca->ndim; k++ ) {
|
|
@@ -725,14 +720,13 @@ Init_ca_obj_roll (void)
|
|
|
725
720
|
ca_roll_func.xfer_all = ca_roll_func_xfer_all;
|
|
726
721
|
|
|
727
722
|
rb_cCARoll = rb_define_class("CARoll", rb_cCATile);
|
|
728
|
-
rb_cCARollMask =
|
|
723
|
+
rb_cCARollMask = rb_define_class_under(rb_cCARoll, "Mask", rb_cCARoll);
|
|
729
724
|
|
|
730
725
|
CA_OBJ_ROLL = ca_install_obj_type(rb_cCARoll,
|
|
731
726
|
&caroll_data_type,
|
|
732
727
|
rb_cCARollMask,
|
|
733
728
|
&caroll_mask_data_type, &ca_roll_func, sizeof(ca_roll_func));
|
|
734
729
|
ca_register_cell_moving_view(CA_OBJ_ROLL);
|
|
735
|
-
rb_define_const(rb_cObject, "CA_OBJ_ROLL", INT2NUM(CA_OBJ_ROLL));
|
|
736
730
|
|
|
737
731
|
rb_define_method(rb_cCArray, "roll", rb_ca_roll, -1);
|
|
738
732
|
|
data/ext/ca_obj_select.c
CHANGED
|
@@ -15,20 +15,10 @@
|
|
|
15
15
|
---------------------------------------------------------------------------- */
|
|
16
16
|
|
|
17
17
|
#include "carray.h"
|
|
18
|
-
#include "carray_internal.h" /* per-obj_type view constructors */
|
|
19
18
|
#include "ca_obj_face.h"
|
|
20
19
|
|
|
21
20
|
typedef struct {
|
|
22
|
-
|
|
23
|
-
int8_t data_type;
|
|
24
|
-
int8_t ndim;
|
|
25
|
-
int32_t flags;
|
|
26
|
-
ca_size_t bytes;
|
|
27
|
-
ca_size_t elements;
|
|
28
|
-
ca_size_t *dim; /* point to _dim */
|
|
29
|
-
char *ptr;
|
|
30
|
-
CArray *mask;
|
|
31
|
-
char *_pool; /* framework-managed pool buffer (NULL = legacy ALLOC_N path). */
|
|
21
|
+
CA_ARRAY_HEADER
|
|
32
22
|
CArray *parent;
|
|
33
23
|
uint32_t attach;
|
|
34
24
|
uint8_t nosync;
|
|
@@ -67,7 +57,7 @@ const rb_data_type_t caselect_data_type = {
|
|
|
67
57
|
|
|
68
58
|
const rb_data_type_t caselect_mask_data_type = {
|
|
69
59
|
.parent = &caselect_data_type,
|
|
70
|
-
.wrap_struct_name = "
|
|
60
|
+
.wrap_struct_name = "CASelect::Mask",
|
|
71
61
|
.function = {
|
|
72
62
|
.dmark = NULL,
|
|
73
63
|
.dfree = ca_free_nop,
|
|
@@ -556,8 +546,7 @@ ca_select_func_fill_data (void *ap, void *ptr)
|
|
|
556
546
|
the unselected cells make the round trip for nothing -- and through a
|
|
557
547
|
lossy transform layer they do not come back the same. Descend per cell
|
|
558
548
|
instead; the cost then follows the selection. Kept in step with the
|
|
559
|
-
CAStride form, so both spellings of a partial fill behave alike.
|
|
560
|
-
(PROPOSAL_PARTIAL_FILL_WHOLE_ROOT_WRITEBACK.md sections 3.3 / 6.2) */
|
|
549
|
+
CAStride form, so both spellings of a partial fill behave alike. */
|
|
561
550
|
if ( !ca_is_attached(ca->parent) && !ca_attach_is_alias(ca->parent) ) {
|
|
562
551
|
/* indices[] are already the selected positions in the parent's flat
|
|
563
552
|
space, so the selection passes down as it stands -- one hop, no
|
|
@@ -602,15 +591,15 @@ ca_operation_function_t ca_select_func = {
|
|
|
602
591
|
/* ------------------------------------------------------------------- */
|
|
603
592
|
|
|
604
593
|
VALUE
|
|
605
|
-
rb_ca_select_new (VALUE cary, volatile VALUE select)
|
|
594
|
+
rb_ca_select_new (volatile VALUE cary, volatile VALUE select)
|
|
606
595
|
{
|
|
607
596
|
volatile VALUE obj;
|
|
608
597
|
CArray *parent, *cselect;
|
|
609
598
|
CASelect *ca;
|
|
610
599
|
rb_check_carray_object(cary);
|
|
611
600
|
rb_check_carray_object(select);
|
|
612
|
-
|
|
613
|
-
|
|
601
|
+
GetCArray(cary, parent);
|
|
602
|
+
GetCArray(select, cselect);
|
|
614
603
|
ca = (CASelect *) ca_select_new(parent, cselect);
|
|
615
604
|
if ( ! ca ) {
|
|
616
605
|
return Qnil;
|
|
@@ -622,7 +611,7 @@ rb_ca_select_new (VALUE cary, volatile VALUE select)
|
|
|
622
611
|
}
|
|
623
612
|
|
|
624
613
|
VALUE
|
|
625
|
-
rb_ca_select_new_share (VALUE cary, VALUE select)
|
|
614
|
+
rb_ca_select_new_share (volatile VALUE cary, volatile VALUE select)
|
|
626
615
|
{
|
|
627
616
|
/* Alias of the snapshot constructor. The `referred_index` ivar is
|
|
628
617
|
set so consumers that expect the original selector to be
|
|
@@ -632,8 +621,8 @@ rb_ca_select_new_share (VALUE cary, VALUE select)
|
|
|
632
621
|
CASelect *ca;
|
|
633
622
|
rb_check_carray_object(cary);
|
|
634
623
|
rb_check_carray_object(select);
|
|
635
|
-
|
|
636
|
-
|
|
624
|
+
GetCArray(cary, parent);
|
|
625
|
+
GetCArray(select, cselect);
|
|
637
626
|
ca = (CASelect *) ca_select_new_share(parent, cselect);
|
|
638
627
|
if ( ! ca ) {
|
|
639
628
|
return Qnil;
|
|
@@ -654,7 +643,7 @@ rb_cm_s_allocate (VALUE klass)
|
|
|
654
643
|
}
|
|
655
644
|
|
|
656
645
|
static VALUE
|
|
657
|
-
rb_cm_initialize_copy (VALUE self, VALUE other)
|
|
646
|
+
rb_cm_initialize_copy (volatile VALUE self, volatile VALUE other)
|
|
658
647
|
{
|
|
659
648
|
CASelect *ca, *cs;
|
|
660
649
|
|
|
@@ -675,7 +664,6 @@ Init_ca_obj_select (void)
|
|
|
675
664
|
ca_register_cell_moving_view(CA_OBJ_SELECT);
|
|
676
665
|
/* rb_cCASelect and CA_OBJ_SELECT are defined in ruby_carray.c;
|
|
677
666
|
this file only registers the constant + allocator. */
|
|
678
|
-
rb_define_const(rb_cObject, "CA_OBJ_SELECT", INT2NUM(CA_OBJ_SELECT));
|
|
679
667
|
|
|
680
668
|
rb_define_alloc_func(rb_cCASelect, rb_cm_s_allocate);
|
|
681
669
|
rb_define_method(rb_cCASelect, "initialize_copy", rb_cm_initialize_copy, 1);
|