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/carray_cast_func.rb
CHANGED
|
@@ -197,7 +197,6 @@ puts %{
|
|
|
197
197
|
---------------------------------------------------------------------------- */
|
|
198
198
|
|
|
199
199
|
#include "carray.h"
|
|
200
|
-
#include "carray_internal.h" /* ca_decimal_string_to / _store */
|
|
201
200
|
|
|
202
201
|
static void __attribute__((noreturn))
|
|
203
202
|
ca_cast_not_implemented(ca_size_t n, CArray *a1, void *ptr1, CArray *a2, void *ptr2, boolean8_t *m)
|
|
@@ -503,7 +502,7 @@ OBJECT.each do |type1|
|
|
|
503
502
|
if ( m ) {
|
|
504
503
|
while ( n-- ) {
|
|
505
504
|
if ( !*m ) {
|
|
506
|
-
VALUE str = *p1;
|
|
505
|
+
volatile VALUE str = *p1;
|
|
507
506
|
Check_Type(str, T_STRING);
|
|
508
507
|
if ( bytes <= RSTRING_LEN(str) ) {
|
|
509
508
|
memcpy(p2, StringValuePtr(str), bytes);
|
|
@@ -518,7 +517,7 @@ OBJECT.each do |type1|
|
|
|
518
517
|
}
|
|
519
518
|
else {
|
|
520
519
|
while ( n-- ) {
|
|
521
|
-
VALUE str = *p1;
|
|
520
|
+
volatile VALUE str = *p1;
|
|
522
521
|
Check_Type(str, T_STRING);
|
|
523
522
|
if ( bytes <= RSTRING_LEN(str) ) {
|
|
524
523
|
memcpy(p2, StringValuePtr(str), bytes);
|
|
@@ -545,6 +544,35 @@ OBJECT.each do |type1|
|
|
|
545
544
|
ctype1 = ctype[type1]
|
|
546
545
|
ctype2 = ctype[type2]
|
|
547
546
|
CA_CAST_TABLE[type1][type2] = "ca_cast_#{ctype1}_#{ctype2}"
|
|
547
|
+
if type2 == CA_BOOLEAN
|
|
548
|
+
# object -> boolean: a String is read by its words (1 / 0 / true /
|
|
549
|
+
# false), any other value as OBJ2BOOL takes it. With a mask buffer
|
|
550
|
+
# (to_type) a cell that does not read becomes UNDEF; without one (a
|
|
551
|
+
# store) it raises.
|
|
552
|
+
puts <<-END_DEF .gsub(/^ {8}/, '')
|
|
553
|
+
static void
|
|
554
|
+
ca_cast_#{ctype1}_#{ctype2}(ca_size_t n, CArray *a1, void *ptr1, CArray *a2, void *ptr2, boolean8_t *m)
|
|
555
|
+
{
|
|
556
|
+
ca_u_VALUE *p1 = ptr1;
|
|
557
|
+
boolean8_t *p2 = ptr2;
|
|
558
|
+
if ( m ) {
|
|
559
|
+
while ( n-- ) {
|
|
560
|
+
if ( !*m && ! ca_boolean_value_to(*p1, p2) ) {
|
|
561
|
+
*m = 1;
|
|
562
|
+
*p2 = 0;
|
|
563
|
+
}
|
|
564
|
+
p1++; p2++; m++;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
else {
|
|
568
|
+
while ( n-- ) { ca_boolean_value_store(*p1, p2); p1++; p2++; }
|
|
569
|
+
}
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
END_DEF
|
|
573
|
+
puts
|
|
574
|
+
next
|
|
575
|
+
end
|
|
548
576
|
if (INTEGER+FLOAT+[CA_CMPLX64, CA_CMPLX128]).include?(type2)
|
|
549
577
|
# object -> int/float/complex: parse failure -> masked (UNDEF) output
|
|
550
578
|
# cell. The mask-aware loop runs only when a mask buffer is supplied
|
data/ext/carray_class.c
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
---------------------------------------------------------------------------- */
|
|
7
7
|
|
|
8
8
|
#include "carray.h"
|
|
9
|
-
#include "carray_internal.h" /* CA_CHECK_*_GIVEN */
|
|
10
9
|
|
|
11
10
|
/* ------------------------------------------------------------------- */
|
|
12
11
|
/* Symbol cache for data_type code → Symbol lookup.
|
|
@@ -26,16 +25,15 @@ ID ca_data_type_sym[CA_NTYPE];
|
|
|
26
25
|
VALUE
|
|
27
26
|
rb_ca_data_type_to_sym (int8_t data_type)
|
|
28
27
|
{
|
|
29
|
-
|
|
28
|
+
CA_CHECK_DATA_TYPE(data_type);
|
|
30
29
|
return ID2SYM(ca_data_type_sym[data_type]);
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
/* Returns the
|
|
34
|
-
(0 = CA_LITTLE_ENDIAN, 1 = CA_BIG_ENDIAN). */
|
|
32
|
+
/* Returns the host byte order as :big or :little. */
|
|
35
33
|
static VALUE
|
|
36
34
|
rb_ca_s_endian (VALUE klass)
|
|
37
35
|
{
|
|
38
|
-
return
|
|
36
|
+
return ID2SYM(rb_intern(( ca_endian == CA_BIG_ENDIAN ) ? "big" : "little"));
|
|
39
37
|
}
|
|
40
38
|
|
|
41
39
|
/* Returns true if the host byte order is big-endian. */
|
|
@@ -70,8 +68,8 @@ static VALUE
|
|
|
70
68
|
rb_ca_s_data_type_name (VALUE klass, VALUE type)
|
|
71
69
|
{
|
|
72
70
|
int8_t data_type = rb_ca_guess_type(type);
|
|
73
|
-
|
|
74
|
-
return
|
|
71
|
+
CA_CHECK_DATA_TYPE(data_type);
|
|
72
|
+
return rb_str_new_cstr(ca_type_name[data_type]);
|
|
75
73
|
}
|
|
76
74
|
|
|
77
75
|
/* Returns the internal int8_t data_type code (e.g. 8 for :int64,
|
|
@@ -85,7 +83,7 @@ static VALUE
|
|
|
85
83
|
rb_ca_s_data_type_code (VALUE klass, VALUE type)
|
|
86
84
|
{
|
|
87
85
|
int8_t data_type = rb_ca_guess_type(type);
|
|
88
|
-
|
|
86
|
+
CA_CHECK_DATA_TYPE(data_type);
|
|
89
87
|
return INT2NUM(data_type);
|
|
90
88
|
}
|
|
91
89
|
|
|
@@ -98,9 +96,6 @@ Init_carray_class (void)
|
|
|
98
96
|
Init_carray_ext (ruby_carray.c) before the CA_* data_type constants
|
|
99
97
|
are defined. Don't re-initialize here. */
|
|
100
98
|
|
|
101
|
-
rb_define_const(rb_cObject, "CA_BIG_ENDIAN", INT2NUM(CA_BIG_ENDIAN));
|
|
102
|
-
rb_define_const(rb_cObject, "CA_LITTLE_ENDIAN", INT2NUM(CA_LITTLE_ENDIAN));
|
|
103
|
-
|
|
104
99
|
rb_define_singleton_method(rb_cCArray, "endian", rb_ca_s_endian, 0);
|
|
105
100
|
rb_define_singleton_method(rb_cCArray, "big_endian?",
|
|
106
101
|
rb_ca_s_big_endian_p, 0);
|
data/ext/carray_conversion.c
CHANGED
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
---------------------------------------------------------------------------- */
|
|
13
13
|
|
|
14
14
|
#include "carray.h"
|
|
15
|
-
#include "carray_internal.h" /* ca_attach_window */
|
|
16
15
|
|
|
17
16
|
#include "ruby/io.h"
|
|
18
17
|
#include "ruby/util.h" /* ruby_strtod */
|
|
@@ -133,7 +132,7 @@ to_a_fast_recurse (CArray *ca, int32_t level, const char *base,
|
|
|
133
132
|
slab_bytes = slab_elements * bytes;
|
|
134
133
|
|
|
135
134
|
for (i = 0; i < n; i++) {
|
|
136
|
-
volatile VALUE child =
|
|
135
|
+
volatile VALUE child = rb_ary_new_capa(ca->dim[level + 1]);
|
|
137
136
|
rb_ary_store(dst, i, child);
|
|
138
137
|
to_a_fast_recurse(ca, level + 1,
|
|
139
138
|
base + i * slab_bytes,
|
|
@@ -146,13 +145,13 @@ to_a_fast_recurse (CArray *ca, int32_t level, const char *base,
|
|
|
146
145
|
through the leaf switch is not safe. Walks every cell through
|
|
147
146
|
rb_ca_fetch_index; masked cells return CA_UNDEF via the fetcher. */
|
|
148
147
|
static void
|
|
149
|
-
rb_ca_to_a_loop_universal (VALUE self, int32_t level, ca_size_t *idx, VALUE ary)
|
|
148
|
+
rb_ca_to_a_loop_universal (volatile VALUE self, int32_t level, ca_size_t *idx, VALUE ary)
|
|
150
149
|
{
|
|
151
150
|
volatile VALUE obj;
|
|
152
151
|
CArray *ca;
|
|
153
152
|
ca_size_t i;
|
|
154
153
|
|
|
155
|
-
|
|
154
|
+
GetCArray(self, ca);
|
|
156
155
|
|
|
157
156
|
if ( level == ca->ndim - 1 ) {
|
|
158
157
|
for (i=0; i<ca->dim[level]; i++) {
|
|
@@ -163,7 +162,7 @@ rb_ca_to_a_loop_universal (VALUE self, int32_t level, ca_size_t *idx, VALUE ary)
|
|
|
163
162
|
else {
|
|
164
163
|
for (i=0; i<ca->dim[level]; i++) {
|
|
165
164
|
idx[level] = i;
|
|
166
|
-
obj =
|
|
165
|
+
obj = rb_ary_new_capa(ca->dim[level+1]);
|
|
167
166
|
rb_ca_to_a_loop_universal(self, level+1, idx, obj);
|
|
168
167
|
rb_ary_store(ary, i, obj);
|
|
169
168
|
}
|
|
@@ -180,7 +179,8 @@ rb_ca_to_a_loop_universal (VALUE self, int32_t level, ca_size_t *idx, VALUE ary)
|
|
|
180
179
|
* to the universal fetch_index walk. */
|
|
181
180
|
/* The universal walk reads each cell through the fetch path, which
|
|
182
181
|
decodes -- an object cell, a Face's element -- and can raise, so it runs
|
|
183
|
-
|
|
182
|
+
while the arrays are attached, through ca_attach_window. The fast path
|
|
183
|
+
only copies numbers out. */
|
|
184
184
|
typedef struct {
|
|
185
185
|
VALUE self;
|
|
186
186
|
VALUE ary;
|
|
@@ -203,7 +203,7 @@ ca_to_a_empty_nesting (CArray *ca, int32_t level)
|
|
|
203
203
|
volatile VALUE ary;
|
|
204
204
|
ca_size_t i;
|
|
205
205
|
|
|
206
|
-
ary =
|
|
206
|
+
ary = rb_ary_new_capa(ca->dim[level]);
|
|
207
207
|
if ( level < ca->ndim - 1 ) {
|
|
208
208
|
for (i=0; i<ca->dim[level]; i++) {
|
|
209
209
|
rb_ary_store(ary, i, ca_to_a_empty_nesting(ca, level + 1));
|
|
@@ -213,17 +213,17 @@ ca_to_a_empty_nesting (CArray *ca, int32_t level)
|
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
VALUE
|
|
216
|
-
rb_ca_to_a (VALUE self)
|
|
216
|
+
rb_ca_to_a (volatile VALUE self)
|
|
217
217
|
{
|
|
218
218
|
volatile VALUE ary;
|
|
219
219
|
CArray *ca;
|
|
220
220
|
int data_type, fast_eligible;
|
|
221
221
|
|
|
222
|
-
|
|
222
|
+
GetCArray(self, ca);
|
|
223
223
|
if ( ca->elements == 0 && ca->ndim > 0 ) {
|
|
224
224
|
return ca_to_a_empty_nesting(ca, 0);
|
|
225
225
|
}
|
|
226
|
-
ary = rb_ca_is_empty(self) ? rb_ary_new() :
|
|
226
|
+
ary = rb_ca_is_empty(self) ? rb_ary_new() : rb_ary_new_capa(ca->dim[0]);
|
|
227
227
|
|
|
228
228
|
/* Once attached, ca->ptr is a contig row-major buffer (alias for
|
|
229
229
|
contig views, materialised otherwise) and ca->mask matches, so the
|
|
@@ -250,7 +250,7 @@ rb_ca_to_a (VALUE self)
|
|
|
250
250
|
if ( fast_eligible ) {
|
|
251
251
|
int has_mask;
|
|
252
252
|
const boolean8_t *mask_base;
|
|
253
|
-
ca_attach(ca); /*
|
|
253
|
+
ca_attach(ca); /* attach: nothing raises before the detach */
|
|
254
254
|
has_mask = (ca->mask != NULL);
|
|
255
255
|
mask_base = has_mask ? (const boolean8_t *) ca->mask->ptr : NULL;
|
|
256
256
|
to_a_fast_recurse(ca, 0, ca->ptr, mask_base, ary,
|
|
@@ -271,7 +271,7 @@ rb_ca_to_a (VALUE self)
|
|
|
271
271
|
#undef TO_A_DISPATCH_LEAF
|
|
272
272
|
#undef TO_A_DISPATCH_LEAF_MASKED
|
|
273
273
|
|
|
274
|
-
/* convert yields
|
|
274
|
+
/* convert yields while self and the output are attached, so the loop
|
|
275
275
|
runs through ca_attach_window. An output mask made part way (the first
|
|
276
276
|
UNDEF from the block) is attached inside the loop, and closed by an
|
|
277
277
|
ensure of its own. */
|
|
@@ -323,7 +323,7 @@ ca_convert_loop (VALUE arg)
|
|
|
323
323
|
if ( ret == CA_UNDEF ) {
|
|
324
324
|
if ( ! co->mask ) {
|
|
325
325
|
ca_create_mask(co);
|
|
326
|
-
ca_attach(co->mask); /*
|
|
326
|
+
ca_attach(co->mask); /* attach: closed by the ensure in ca_convert_body */
|
|
327
327
|
c->co_mask_attached = 1;
|
|
328
328
|
dst_mask = (boolean8_t *) co->mask->ptr;
|
|
329
329
|
memset(dst_mask, 0, (size_t) n);
|
|
@@ -364,32 +364,41 @@ ca_convert_body (VALUE arg)
|
|
|
364
364
|
* and the template result are attached symmetrically (R3-compliant) so
|
|
365
365
|
* an overridden #template returning a view stays on the in-ptr path. */
|
|
366
366
|
static VALUE
|
|
367
|
-
rb_ca_convert (int argc, VALUE *argv, VALUE self)
|
|
367
|
+
rb_ca_convert (int argc, VALUE *argv, volatile VALUE self)
|
|
368
368
|
{
|
|
369
369
|
volatile VALUE obj;
|
|
370
370
|
ca_convert_ctx_t c;
|
|
371
371
|
CArray *list[2];
|
|
372
372
|
|
|
373
|
+
/* args: looks at the type only; template reads them all */
|
|
373
374
|
rb_need_block();
|
|
375
|
+
if ( argc >= 1 && RTEST(rb_obj_is_data_class(argv[0])) ) {
|
|
376
|
+
rb_raise(rb_eArgError,
|
|
377
|
+
"convert: a data class (%"PRIsVALUE") is not a data_type of "
|
|
378
|
+
"the cells; convert(:object) and then to_type(%"PRIsVALUE") "
|
|
379
|
+
"makes records", argv[0], argv[0]);
|
|
380
|
+
}
|
|
374
381
|
|
|
375
|
-
|
|
382
|
+
/* template is called as a method, so a Face that overrides it is used */
|
|
383
|
+
obj = rb_funcallv_kw(self, rb_intern("template"), argc, argv,
|
|
384
|
+
RB_PASS_CALLED_KEYWORDS);
|
|
376
385
|
|
|
377
|
-
|
|
378
|
-
|
|
386
|
+
GetCArray(self, c.ca);
|
|
387
|
+
GetCArray(obj, c.co);
|
|
379
388
|
c.self = self;
|
|
380
389
|
c.obj = obj;
|
|
381
390
|
c.has_mask = ca_has_mask(c.ca);
|
|
382
391
|
c.co_mask_attached = 0;
|
|
383
392
|
|
|
384
393
|
/* Attaching an array attaches its mask, so the output's mask is made
|
|
385
|
-
before
|
|
394
|
+
before anything is attached when the source already has one. */
|
|
386
395
|
if ( c.has_mask && ! c.co->mask ) {
|
|
387
396
|
ca_create_mask(c.co);
|
|
388
397
|
}
|
|
389
398
|
|
|
390
399
|
list[0] = c.ca;
|
|
391
400
|
list[1] = c.co;
|
|
392
|
-
ca_attach_window_yielding(
|
|
401
|
+
ca_attach_window_yielding(rb_ary_new_from_args(2, self, obj), 2, list, "rw",
|
|
393
402
|
ca_convert_body, (VALUE) &c);
|
|
394
403
|
|
|
395
404
|
return obj;
|
|
@@ -407,6 +416,7 @@ static VALUE
|
|
|
407
416
|
ca_dump_into_string_body (VALUE arg)
|
|
408
417
|
{
|
|
409
418
|
ca_dump_into_string_t *d = (ca_dump_into_string_t *) arg;
|
|
419
|
+
/* gc: d lives in the caller's frame, and the caller holds io */
|
|
410
420
|
ca_copy_data(d->ca, RSTRING_PTR(d->io));
|
|
411
421
|
return Qnil;
|
|
412
422
|
}
|
|
@@ -426,26 +436,20 @@ ca_dump_into_string_unlock (VALUE io)
|
|
|
426
436
|
* other object must respond to #write. Rejects CA_OBJECT (data is
|
|
427
437
|
* VALUE, not portable). */
|
|
428
438
|
static VALUE
|
|
429
|
-
rb_ca_dump_binary (int argc, VALUE *argv, VALUE self)
|
|
439
|
+
rb_ca_dump_binary (int argc, VALUE *argv, volatile VALUE self)
|
|
430
440
|
{
|
|
431
441
|
volatile VALUE io;
|
|
432
442
|
CArray *ca;
|
|
433
443
|
|
|
434
|
-
|
|
444
|
+
rb_reject_options(rb_pop_options(&argc, &argv));
|
|
445
|
+
rb_check_arity(argc, 0, 1);
|
|
446
|
+
GetCArray(self, ca);
|
|
435
447
|
|
|
436
448
|
if ( ca_is_object_type(ca) ) {
|
|
437
449
|
rb_raise(rb_eCADataTypeError, "don't dump object array");
|
|
438
450
|
}
|
|
439
451
|
|
|
440
|
-
|
|
441
|
-
io = rb_str_new(NULL, 0);
|
|
442
|
-
}
|
|
443
|
-
else if ( argc == 1 ) {
|
|
444
|
-
io = argv[0];
|
|
445
|
-
}
|
|
446
|
-
else {
|
|
447
|
-
rb_raise(rb_eArgError, "invalid # of arguments (%i for 1)", argc);
|
|
448
|
-
}
|
|
452
|
+
io = ( argc == 0 ) ? rb_str_new(NULL, 0) : argv[0];
|
|
449
453
|
|
|
450
454
|
switch ( TYPE(io) ) {
|
|
451
455
|
case T_STRING:
|
|
@@ -505,11 +509,13 @@ rb_ca_dump_binary (int argc, VALUE *argv, VALUE self)
|
|
|
505
509
|
return io;
|
|
506
510
|
}
|
|
507
511
|
|
|
508
|
-
/* CArray#to_s —
|
|
512
|
+
/* CArray#to_s — the same text as inspect. Ruby calls to_s wherever it puts
|
|
513
|
+
* an object into text (interpolation, puts, error messages), so it is the
|
|
514
|
+
* readable form; the element bytes are dump_binary's. */
|
|
509
515
|
static VALUE
|
|
510
516
|
rb_ca_to_s (VALUE self)
|
|
511
517
|
{
|
|
512
|
-
return
|
|
518
|
+
return rb_inspect(self);
|
|
513
519
|
}
|
|
514
520
|
|
|
515
521
|
/* CArray#load_binary(io) — overwrite self's element bytes with ca_length
|
|
@@ -521,12 +527,12 @@ rb_ca_to_s (VALUE self)
|
|
|
521
527
|
* targets buffer the full read and recurse via T_STRING because
|
|
522
528
|
* ca_sync_data scatters in one pass. */
|
|
523
529
|
static VALUE
|
|
524
|
-
rb_ca_load_binary (VALUE self, VALUE io)
|
|
530
|
+
rb_ca_load_binary (volatile VALUE self, volatile VALUE io)
|
|
525
531
|
{
|
|
526
532
|
CArray *ca;
|
|
527
533
|
|
|
528
534
|
rb_ca_modify(self);
|
|
529
|
-
|
|
535
|
+
GetCArray(self, ca);
|
|
530
536
|
|
|
531
537
|
if ( ca_is_object_type(ca) ) {
|
|
532
538
|
rb_raise(rb_eCADataTypeError, "don't load object array");
|
|
@@ -547,7 +553,6 @@ rb_ca_load_binary (VALUE self, VALUE io)
|
|
|
547
553
|
ca_boolean_normalize_bytes(RSTRING_PTR(io), ca->elements);
|
|
548
554
|
}
|
|
549
555
|
ca_sync_data(ca, RSTRING_PTR(io));
|
|
550
|
-
RB_GC_GUARD(io);
|
|
551
556
|
return self;
|
|
552
557
|
break;
|
|
553
558
|
default:
|
|
@@ -559,10 +564,10 @@ rb_ca_load_binary (VALUE self, VALUE io)
|
|
|
559
564
|
const ca_size_t CHUNK = 65536;
|
|
560
565
|
volatile VALUE scratch = rb_str_buf_new(CHUNK < total ? CHUNK : total);
|
|
561
566
|
ca_size_t off = 0;
|
|
562
|
-
ca_allocate(ca); /*
|
|
567
|
+
ca_allocate(ca); /* attach: an entity, whose allocate holds nothing */
|
|
563
568
|
while ( off < total ) {
|
|
564
569
|
ca_size_t want = (total - off < CHUNK) ? (total - off) : CHUNK;
|
|
565
|
-
VALUE r = rb_funcall(io, id_read, 2, SIZE2NUM(want), scratch);
|
|
570
|
+
volatile VALUE r = rb_funcall(io, id_read, 2, SIZE2NUM(want), scratch);
|
|
566
571
|
if ( NIL_P(r) || RSTRING_LEN(r) != want ) {
|
|
567
572
|
ca_detach(ca);
|
|
568
573
|
rb_raise(rb_eArgError,
|
|
@@ -643,7 +648,7 @@ ca_double_of_shortest_decimal_of_float32 (float x)
|
|
|
643
648
|
double its shortest decimal reads as, for to_csv to write that decimal.
|
|
644
649
|
The mask is kept. */
|
|
645
650
|
static VALUE
|
|
646
|
-
rb_ca_widen_keeping_shortest_decimal (VALUE self)
|
|
651
|
+
rb_ca_widen_keeping_shortest_decimal (volatile VALUE self)
|
|
647
652
|
{
|
|
648
653
|
volatile VALUE out, holder = 0;
|
|
649
654
|
CArray *ca, *co;
|
data/ext/carray_copy.c
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
|
|
11
11
|
#include "carray.h"
|
|
12
12
|
#include "ca_obj_face.h" /* CA_FACE_LIFT_IF_FACE */
|
|
13
|
-
#include "carray_internal.h" /* ca_gc_hold_push / ca_gc_hold_pop_to */
|
|
14
13
|
#include "ca_sweep_engine.h" /* ca_sweep_same_shape / ca_sweep_refuse_shapes */
|
|
15
14
|
#include <stdarg.h>
|
|
16
15
|
|
|
@@ -159,12 +158,12 @@ ca_copy (void *ap)
|
|
|
159
158
|
* Face (e.g. CARecord), lifts the wrapped result so the derived class
|
|
160
159
|
* identity is preserved on the copy. The copy keeps self's attributes. */
|
|
161
160
|
VALUE
|
|
162
|
-
rb_ca_copy (VALUE self)
|
|
161
|
+
rb_ca_copy (volatile VALUE self)
|
|
163
162
|
{
|
|
164
163
|
volatile VALUE obj;
|
|
165
164
|
CArray *ca, *co;
|
|
166
165
|
int guard = -1;
|
|
167
|
-
|
|
166
|
+
GetCArray(self, ca);
|
|
168
167
|
co = ca_copy(ca);
|
|
169
168
|
/* The copy holds VALUEs that so far exist only in co->ptr, and
|
|
170
169
|
ca_wrap_struct allocates. Keep them reachable until the wrapper
|
|
@@ -190,17 +189,11 @@ rb_ca_copy (VALUE self)
|
|
|
190
189
|
int
|
|
191
190
|
ca_to_ca_writable_arg (int argc, VALUE *argv)
|
|
192
191
|
{
|
|
193
|
-
VALUE opts;
|
|
194
|
-
ID kw_ids[1];
|
|
195
|
-
VALUE kw_vals[1];
|
|
192
|
+
VALUE opts, vwritable = Qundef;
|
|
196
193
|
|
|
197
194
|
rb_scan_args(argc, argv, "0:", &opts);
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
kw_ids[0] = rb_intern("writable");
|
|
202
|
-
rb_get_kwargs(opts, kw_ids, 0, 1, kw_vals);
|
|
203
|
-
return ( kw_vals[0] == Qundef ) ? 0 : RTEST(kw_vals[0]);
|
|
195
|
+
rb_scan_options(opts, "writable", &vwritable);
|
|
196
|
+
return ( vwritable == Qundef ) ? 0 : ca_bool_arg(vwritable, "writable");
|
|
204
197
|
}
|
|
205
198
|
|
|
206
199
|
/* Refusal an implementation raises when `writable: true` was asked of a
|
|
@@ -227,11 +220,11 @@ ca_to_ca_refuse_writable (VALUE self)
|
|
|
227
220
|
* entity; both are copies and so refuse `writable: true`. When an
|
|
228
221
|
* independent owned copy is required, callers use `copy`. */
|
|
229
222
|
VALUE
|
|
230
|
-
rb_ca_to_ca (int argc, VALUE *argv, VALUE self)
|
|
223
|
+
rb_ca_to_ca (int argc, VALUE *argv, volatile VALUE self)
|
|
231
224
|
{
|
|
232
225
|
if ( ca_to_ca_writable_arg(argc, argv) ) {
|
|
233
226
|
CArray *ca;
|
|
234
|
-
|
|
227
|
+
GetCArray(self, ca);
|
|
235
228
|
if ( ca_is_readonly(ca) ) {
|
|
236
229
|
ca_refuse_read_only();
|
|
237
230
|
}
|
|
@@ -280,7 +273,7 @@ CArray *
|
|
|
280
273
|
ca_template_safe2 (void *ap, int8_t data_type, ca_size_t bytes)
|
|
281
274
|
{
|
|
282
275
|
CArray *ca = (CArray *) ap;
|
|
283
|
-
|
|
276
|
+
CA_CHECK_DATA_TYPE(data_type);
|
|
284
277
|
if ( ca_is_scalar(ca) ) {
|
|
285
278
|
return (CArray*) cscalar_new(data_type, bytes, NULL);
|
|
286
279
|
}
|
|
@@ -299,23 +292,29 @@ ca_template_safe2 (void *ap, int8_t data_type, ca_size_t bytes)
|
|
|
299
292
|
* The arity dispatch matches `CArray.new` (ca_obj_array.c) so the two
|
|
300
293
|
* factories behave the same for block-driven initialisation. */
|
|
301
294
|
static VALUE
|
|
302
|
-
rb_ca_template_kw (int argc, VALUE *argv, VALUE ropt, VALUE self
|
|
295
|
+
rb_ca_template_kw (int argc, VALUE *argv, VALUE ropt, volatile VALUE self,
|
|
296
|
+
int use_block)
|
|
303
297
|
{
|
|
304
|
-
volatile VALUE obj
|
|
298
|
+
volatile VALUE obj;
|
|
299
|
+
VALUE rtype, rbytes = Qnil;
|
|
305
300
|
CArray *ca, *co;
|
|
306
301
|
int8_t data_type;
|
|
307
302
|
ca_size_t bytes;
|
|
308
303
|
|
|
309
|
-
rb_scan_args(argc, argv, "01",
|
|
304
|
+
rb_scan_args(argc, argv, "01", &rtype);
|
|
310
305
|
rb_scan_options(ropt, "bytes", &rbytes);
|
|
311
306
|
|
|
312
|
-
|
|
307
|
+
GetCArray(self, ca);
|
|
313
308
|
|
|
314
309
|
if ( NIL_P(rtype) ) {
|
|
315
310
|
co = ca_template_safe(ca);
|
|
316
311
|
obj = ca_wrap_struct(co);
|
|
317
312
|
}
|
|
318
313
|
else {
|
|
314
|
+
if ( use_block ) { /* called from Ruby */
|
|
315
|
+
ca_refuse_type_number(rtype);
|
|
316
|
+
ca_refuse_data_class(rtype, "template");
|
|
317
|
+
}
|
|
319
318
|
rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
|
|
320
319
|
co = ca_template_safe2(ca, data_type, bytes);
|
|
321
320
|
obj = ca_wrap_struct(co);
|
|
@@ -334,7 +333,10 @@ rb_ca_template_kw (int argc, VALUE *argv, VALUE ropt, VALUE self)
|
|
|
334
333
|
CA_FACE_LIFT_IF_FACE(obj, self, ca);
|
|
335
334
|
}
|
|
336
335
|
|
|
337
|
-
|
|
336
|
+
/* Only the Ruby method `template` reads a block. The C helpers below
|
|
337
|
+
are called from inside other methods, where rb_block_given_p sees the
|
|
338
|
+
caller's block (`a.sort { ... }` would fill sort's scratch with it). */
|
|
339
|
+
if ( use_block && rb_block_given_p() ) {
|
|
338
340
|
if ( rb_proc_arity(rb_block_proc()) == 0 ) {
|
|
339
341
|
volatile VALUE rval = rb_yield_values2(0, NULL);
|
|
340
342
|
if ( rval != self ) {
|
|
@@ -343,10 +345,10 @@ rb_ca_template_kw (int argc, VALUE *argv, VALUE ropt, VALUE self)
|
|
|
343
345
|
}
|
|
344
346
|
else {
|
|
345
347
|
CArray *co;
|
|
346
|
-
|
|
348
|
+
GetCArray(obj, co);
|
|
347
349
|
if ( co->ndim > 0 ) {
|
|
348
350
|
ca_size_t idx[CA_RANK_MAX];
|
|
349
|
-
volatile VALUE ridx =
|
|
351
|
+
volatile VALUE ridx = rb_ary_new_capa(co->ndim);
|
|
350
352
|
rb_ca_index_walk(obj, co, 0, idx, ridx, CA_LOOP_STORE);
|
|
351
353
|
}
|
|
352
354
|
else {
|
|
@@ -363,13 +365,13 @@ static VALUE
|
|
|
363
365
|
rb_ca_template_method (int argc, VALUE *argv, VALUE self)
|
|
364
366
|
{
|
|
365
367
|
volatile VALUE ropt = rb_pop_options(&argc, &argv);
|
|
366
|
-
return rb_ca_template_kw(argc, argv, ropt, self);
|
|
368
|
+
return rb_ca_template_kw(argc, argv, ropt, self, 1);
|
|
367
369
|
}
|
|
368
370
|
|
|
369
371
|
VALUE
|
|
370
372
|
rb_ca_template (VALUE self)
|
|
371
373
|
{
|
|
372
|
-
return
|
|
374
|
+
return rb_ca_template_kw(0, NULL, Qnil, self, 0);
|
|
373
375
|
}
|
|
374
376
|
|
|
375
377
|
VALUE
|
|
@@ -377,7 +379,7 @@ rb_ca_template_with_type (VALUE self, VALUE rtype, VALUE rbytes)
|
|
|
377
379
|
{
|
|
378
380
|
volatile VALUE ropt = rb_hash_new();
|
|
379
381
|
rb_set_options(ropt, "bytes", rbytes);
|
|
380
|
-
return rb_ca_template_kw(1, &rtype, ropt, self);
|
|
382
|
+
return rb_ca_template_kw(1, &rtype, ropt, self, 0);
|
|
381
383
|
}
|
|
382
384
|
|
|
383
385
|
/* Returns `template` of the first non-scalar among `n` variadic CArray
|
|
@@ -400,7 +402,7 @@ rb_ca_template_n (int n, ...)
|
|
|
400
402
|
va_end(vargs);
|
|
401
403
|
rb_raise(rb_eRuntimeError, "[BUG] not-carray object given to rb_ca_template_n");
|
|
402
404
|
}
|
|
403
|
-
|
|
405
|
+
GetCArray(varg, ca);
|
|
404
406
|
if ( i == 0 ) {
|
|
405
407
|
obj = varg;
|
|
406
408
|
}
|