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
data/ext/ca_obj_array.c
CHANGED
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
---------------------------------------------------------------------------- */
|
|
10
10
|
|
|
11
11
|
#include "carray.h"
|
|
12
|
-
#include "carray_internal.h"
|
|
13
12
|
|
|
14
13
|
/* -------------------------------------------------------------------- */
|
|
15
14
|
|
|
@@ -108,7 +107,7 @@ const rb_data_type_t caview_data_type = {
|
|
|
108
107
|
|
|
109
108
|
const rb_data_type_t carray_mask_data_type = {
|
|
110
109
|
.parent = &carray_data_type,
|
|
111
|
-
.wrap_struct_name = "
|
|
110
|
+
.wrap_struct_name = "CArray::Mask",
|
|
112
111
|
.function = {
|
|
113
112
|
.dmark = NULL,
|
|
114
113
|
.dfree = ca_free_nop,
|
|
@@ -147,10 +146,10 @@ carray_setup_i (CArray *ca,
|
|
|
147
146
|
ca_size_t k;
|
|
148
147
|
|
|
149
148
|
/* check arguments */
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
149
|
+
CA_CHECK_DATA_TYPE(data_type);
|
|
150
|
+
CA_CHECK_RANK(ndim);
|
|
151
|
+
CA_CHECK_DIM(ndim, dim);
|
|
152
|
+
CA_CHECK_BYTES(data_type, bytes);
|
|
154
153
|
|
|
155
154
|
elements = ca_shape_elements(ndim, dim, bytes);
|
|
156
155
|
|
|
@@ -425,8 +424,8 @@ static int
|
|
|
425
424
|
cscalar_setup (CScalar *ca,
|
|
426
425
|
int8_t data_type, ca_size_t bytes, CArray *mask)
|
|
427
426
|
{
|
|
428
|
-
|
|
429
|
-
|
|
427
|
+
CA_CHECK_DATA_TYPE(data_type);
|
|
428
|
+
CA_CHECK_BYTES(data_type, bytes);
|
|
430
429
|
|
|
431
430
|
/* ca == NULL asks for the checks above only, so that a constructor can
|
|
432
431
|
run them before it allocates. */
|
|
@@ -923,21 +922,23 @@ rb_ca_s_allocate (VALUE klass)
|
|
|
923
922
|
return TypedData_Make_Struct(klass, CArray, &carray_data_type, ca);
|
|
924
923
|
}
|
|
925
924
|
|
|
926
|
-
/* Reads the (data_type, dim, bytes: nil) argument list
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
the demand that dim be an Array -- is written once here. */
|
|
925
|
+
/* Reads the (data_type, dim, bytes: nil, raw: false) argument list of
|
|
926
|
+
CArray.new: the optional bytes for a fixlen, the refusal of a Class,
|
|
927
|
+
the guess of the data type, the demand that dim be an Array, and
|
|
928
|
+
whether the buffer is left without the zero fill (raw: true). */
|
|
931
929
|
|
|
932
930
|
static void
|
|
933
931
|
ca_scan_construct_args (int argc, VALUE *argv, int8_t *data_type,
|
|
934
|
-
ca_size_t *bytes, int8_t *ndim, ca_size_t *dim
|
|
932
|
+
ca_size_t *bytes, int8_t *ndim, ca_size_t *dim,
|
|
933
|
+
int *raw)
|
|
935
934
|
{
|
|
936
|
-
|
|
935
|
+
VALUE rtype, rdim, ropt, rbytes = Qnil, rraw = Qnil;
|
|
937
936
|
int8_t i;
|
|
938
937
|
|
|
939
|
-
rb_scan_args(argc, argv, "21",
|
|
940
|
-
rb_scan_options(ropt, "bytes", &rbytes);
|
|
938
|
+
rb_scan_args(argc, argv, "21", &rtype, &rdim, &ropt);
|
|
939
|
+
rb_scan_options(ropt, "bytes,raw", &rbytes, &rraw);
|
|
940
|
+
|
|
941
|
+
*raw = ca_bool_arg(rraw, "raw");
|
|
941
942
|
|
|
942
943
|
/* data_class may only be attached to a CARecord (= Face), so
|
|
943
944
|
constructing a data_class-bearing entity with `CArray.new(MyStruct,
|
|
@@ -945,46 +946,52 @@ ca_scan_construct_args (int argc, VALUE *argv, int8_t *data_type,
|
|
|
945
946
|
guidance. (View-side data_class propagation, e.g. refer(MyStruct,
|
|
946
947
|
[N]), is handled elsewhere via the data_class inherit path.) */
|
|
947
948
|
if ( TYPE(rtype) == T_CLASS ) {
|
|
949
|
+
volatile VALUE rshape = RB_TYPE_P(rdim, T_ARRAY)
|
|
950
|
+
? rb_ary_join(rdim, rb_str_new_cstr(", "))
|
|
951
|
+
: rb_str_new_cstr("*shape");
|
|
948
952
|
rb_raise(rb_eArgError,
|
|
949
|
-
"CArray.new
|
|
950
|
-
"
|
|
951
|
-
"
|
|
952
|
-
|
|
953
|
+
"CArray.new: %"PRIsVALUE" is a data class, not a data type; "
|
|
954
|
+
"an array of its records is `CARecord.new(%"PRIsVALUE", "
|
|
955
|
+
"%"PRIsVALUE")`, or define "
|
|
956
|
+
"`class MyArr < CARecord; data_class %"PRIsVALUE"; end`",
|
|
957
|
+
rb_inspect(rtype), rb_inspect(rtype), rshape, rb_inspect(rtype));
|
|
953
958
|
}
|
|
954
959
|
|
|
960
|
+
ca_refuse_type_number(rtype);
|
|
955
961
|
rb_ca_guess_type_and_bytes(rtype, rbytes, data_type, bytes);
|
|
956
962
|
|
|
957
963
|
Check_Type(rdim, T_ARRAY);
|
|
958
|
-
|
|
964
|
+
CA_CHECK_RANK(RARRAY_LEN(rdim)); /* before dim[] is filled */
|
|
959
965
|
*ndim = RARRAY_LEN(rdim);
|
|
960
966
|
for (i=0; i<*ndim; i++) {
|
|
961
|
-
dim[i] =
|
|
967
|
+
dim[i] = ca_integer_arg(rb_ary_entry(rdim, i), "a dimension", NULL);
|
|
962
968
|
}
|
|
963
969
|
}
|
|
964
970
|
|
|
965
|
-
/* @overload initialize(data_type, dim, bytes
|
|
971
|
+
/* @overload initialize(data_type, dim, bytes: nil, raw: false) { ... }
|
|
966
972
|
|
|
967
|
-
Constructs a new CArray object of <i>data_type</i
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
973
|
+
Constructs a new CArray object of <i>data_type</i> with the shape
|
|
974
|
+
<i>dim</i> (an <code>Array</code> of <code>Integer</code>). The element
|
|
975
|
+
width of a fixed-length array (<code>:fixlen</code>) is given by
|
|
976
|
+
<i>bytes</i>; for other data types it has no effect. The cells are set
|
|
977
|
+
to 0, unless <i>raw</i> is true: then the buffer is returned as it was
|
|
978
|
+
allocated, and its contents are undefined until written. If a block is
|
|
979
|
+
given, the new CArray is initialized by the values returned from the
|
|
980
|
+
block.
|
|
975
981
|
*/
|
|
976
982
|
|
|
977
983
|
static VALUE
|
|
978
|
-
rb_ca_initialize (int argc, VALUE *argv, VALUE self)
|
|
984
|
+
rb_ca_initialize (int argc, VALUE *argv, volatile VALUE self)
|
|
979
985
|
{
|
|
980
986
|
CArray *ca;
|
|
981
987
|
int8_t data_type, ndim;
|
|
982
988
|
ca_size_t dim[CA_RANK_MAX];
|
|
983
989
|
ca_size_t bytes;
|
|
990
|
+
int raw;
|
|
984
991
|
|
|
985
|
-
ca_scan_construct_args(argc, argv, &data_type, &bytes, &ndim, dim);
|
|
992
|
+
ca_scan_construct_args(argc, argv, &data_type, &bytes, &ndim, dim, &raw);
|
|
986
993
|
|
|
987
|
-
|
|
994
|
+
GetCArray(self, ca);
|
|
988
995
|
ca_check_uninitialized(ca);
|
|
989
996
|
/* Checks first: a rejected argument leaves the struct as allocated, so
|
|
990
997
|
it takes no pool and can be initialized again. */
|
|
@@ -992,7 +999,14 @@ rb_ca_initialize (int argc, VALUE *argv, VALUE self)
|
|
|
992
999
|
if ( ca_func[CA_OBJ_ARRAY].pool_init ) {
|
|
993
1000
|
ca_array_pool_alloc(ca, CA_OBJ_ARRAY, ndim);
|
|
994
1001
|
}
|
|
995
|
-
|
|
1002
|
+
/* raw: true leaves out the zero fill; an object array is still set to
|
|
1003
|
+
0 inside carray_setup_i, because the garbage collector walks it. */
|
|
1004
|
+
if ( raw ) {
|
|
1005
|
+
carray_setup(ca, data_type, ndim, dim, bytes, NULL);
|
|
1006
|
+
}
|
|
1007
|
+
else {
|
|
1008
|
+
carray_safe_setup(ca, data_type, ndim, dim, bytes, NULL);
|
|
1009
|
+
}
|
|
996
1010
|
|
|
997
1011
|
if ( rb_block_given_p() ) {
|
|
998
1012
|
/* Two block forms:
|
|
@@ -1019,11 +1033,11 @@ rb_ca_initialize (int argc, VALUE *argv, VALUE self)
|
|
|
1019
1033
|
}
|
|
1020
1034
|
else if ( ca->ndim > 0 ) {
|
|
1021
1035
|
ca_size_t idx[CA_RANK_MAX];
|
|
1022
|
-
volatile VALUE ridx =
|
|
1036
|
+
volatile VALUE ridx = rb_ary_new_capa(ca->ndim);
|
|
1023
1037
|
rb_ca_index_walk(self, ca, 0, idx, ridx, CA_LOOP_STORE);
|
|
1024
1038
|
}
|
|
1025
1039
|
else {
|
|
1026
|
-
/* 0-D
|
|
1040
|
+
/* 0-D fallback (rare from CArray.new path): yield no args. */
|
|
1027
1041
|
volatile VALUE rval = rb_yield_values2(0, NULL);
|
|
1028
1042
|
rb_ca_store_addr(self, 0, rval);
|
|
1029
1043
|
}
|
|
@@ -1042,20 +1056,22 @@ static VALUE
|
|
|
1042
1056
|
rb_ca_s_fixlen (int argc, VALUE *argv, VALUE klass)
|
|
1043
1057
|
{
|
|
1044
1058
|
volatile VALUE ropt = rb_pop_options(&argc, &argv);
|
|
1045
|
-
volatile VALUE rdim =
|
|
1046
|
-
VALUE args[3] = {
|
|
1059
|
+
volatile VALUE rdim = rb_ary_new_from_values(argc, argv);
|
|
1060
|
+
VALUE args[3] = { ID2SYM(ca_data_type_sym[CA_FIXLEN]), rdim, ropt };
|
|
1047
1061
|
return rb_class_new_instance(3, args, klass);
|
|
1048
1062
|
}
|
|
1049
1063
|
|
|
1050
1064
|
#define rb_ca_s_body(code) \
|
|
1051
1065
|
{ \
|
|
1052
1066
|
if ( argc == 0 ) { \
|
|
1053
|
-
|
|
1067
|
+
rb_raise(rb_eArgError, \
|
|
1068
|
+
"CArray.%s: give the shape of the new array", \
|
|
1069
|
+
ca_type_name[code]); \
|
|
1054
1070
|
} \
|
|
1055
1071
|
else { \
|
|
1056
1072
|
volatile VALUE ropt = rb_pop_options(&argc, &argv); \
|
|
1057
|
-
volatile VALUE rdim =
|
|
1058
|
-
VALUE args[3] = {
|
|
1073
|
+
volatile VALUE rdim = rb_ary_new_from_values(argc, argv); \
|
|
1074
|
+
VALUE args[3] = { ID2SYM(ca_data_type_sym[code]), rdim, ropt }; \
|
|
1059
1075
|
return rb_class_new_instance(3, args, klass); \
|
|
1060
1076
|
} \
|
|
1061
1077
|
}
|
|
@@ -1207,15 +1223,18 @@ static VALUE rb_ca_s_VALUE (int argc, VALUE *argv, VALUE klass)
|
|
|
1207
1223
|
|
|
1208
1224
|
*/
|
|
1209
1225
|
static VALUE
|
|
1210
|
-
rb_ca_initialize_copy (VALUE self, VALUE other)
|
|
1226
|
+
rb_ca_initialize_copy (volatile VALUE self, volatile VALUE other)
|
|
1211
1227
|
{
|
|
1212
1228
|
CArray *ca, *cs;
|
|
1213
1229
|
|
|
1214
|
-
|
|
1230
|
+
{
|
|
1231
|
+
VALUE args[1] = { other };
|
|
1232
|
+
rb_call_super(1, args);
|
|
1233
|
+
}
|
|
1215
1234
|
|
|
1216
|
-
|
|
1235
|
+
GetCArray(self, ca);
|
|
1217
1236
|
ca_check_uninitialized(ca);
|
|
1218
|
-
|
|
1237
|
+
GetCArray(other, cs);
|
|
1219
1238
|
|
|
1220
1239
|
ca_update_mask(cs);
|
|
1221
1240
|
if ( ca_func[CA_OBJ_ARRAY].pool_init ) {
|
|
@@ -1226,6 +1245,12 @@ rb_ca_initialize_copy (VALUE self, VALUE other)
|
|
|
1226
1245
|
if ( cs->ptr ) {
|
|
1227
1246
|
memcpy(ca->ptr, cs->ptr, ca_length(cs));
|
|
1228
1247
|
}
|
|
1248
|
+
else if ( cs->obj_type == CA_OBJ_ARRAY_WRAP ) {
|
|
1249
|
+
/* A wrap that borrows no memory yet (the one a CAObject keeps for its
|
|
1250
|
+
cells) has no values to copy. Ruby's Ractor copy clones it, then
|
|
1251
|
+
refuses the CAObject that holds it. */
|
|
1252
|
+
memset(ca->ptr, 0, ca_length(cs));
|
|
1253
|
+
}
|
|
1229
1254
|
else {
|
|
1230
1255
|
/* An entity cold at rest (a CAObject's mask, a source) is read
|
|
1231
1256
|
through its slots. */
|
|
@@ -1244,14 +1269,14 @@ rb_ca_initialize_copy (VALUE self, VALUE other)
|
|
|
1244
1269
|
a copy of a mask is still a mask (its class, CArrayMask, says so) and
|
|
1245
1270
|
can no more hold a mask of its own than the original. */
|
|
1246
1271
|
static void
|
|
1247
|
-
ca_dup_keep_state (VALUE self, VALUE other)
|
|
1272
|
+
ca_dup_keep_state (volatile VALUE self, volatile VALUE other)
|
|
1248
1273
|
{
|
|
1249
1274
|
CArray *ca, *cs;
|
|
1250
1275
|
if ( ! rb_obj_is_kind_of(other, rb_cCArray) ) {
|
|
1251
1276
|
return;
|
|
1252
1277
|
}
|
|
1253
|
-
|
|
1254
|
-
|
|
1278
|
+
GetCArray(self, ca);
|
|
1279
|
+
GetCArray(other, cs);
|
|
1255
1280
|
if ( ca_is_view(cs) ) {
|
|
1256
1281
|
ca_keep_chain_flags(ca, cs);
|
|
1257
1282
|
}
|
|
@@ -1275,7 +1300,7 @@ rb_ca_initialize_dup (VALUE self, VALUE other)
|
|
|
1275
1300
|
going to be frozen (freeze: true, or freeze: omitted and the original
|
|
1276
1301
|
frozen). */
|
|
1277
1302
|
static VALUE
|
|
1278
|
-
rb_ca_initialize_clone (int argc, VALUE *argv, VALUE self)
|
|
1303
|
+
rb_ca_initialize_clone (int argc, VALUE *argv, volatile VALUE self)
|
|
1279
1304
|
{
|
|
1280
1305
|
VALUE orig, opts, vfreeze = Qnil;
|
|
1281
1306
|
int will_freeze;
|
|
@@ -1291,7 +1316,7 @@ rb_ca_initialize_clone (int argc, VALUE *argv, VALUE self)
|
|
|
1291
1316
|
will_freeze = NIL_P(vfreeze) ? OBJ_FROZEN(orig) : RTEST(vfreeze);
|
|
1292
1317
|
if ( will_freeze ) {
|
|
1293
1318
|
CArray *ca;
|
|
1294
|
-
|
|
1319
|
+
GetCArray(self, ca);
|
|
1295
1320
|
ca_set_flag(ca, CA_FLAG_READ_ONLY);
|
|
1296
1321
|
}
|
|
1297
1322
|
return self;
|
|
@@ -1314,16 +1339,8 @@ rb_ca_wrap_clone (int argc, VALUE *argv, VALUE self)
|
|
|
1314
1339
|
VALUE opt = Qnil, rfreeze = Qnil;
|
|
1315
1340
|
volatile VALUE obj;
|
|
1316
1341
|
rb_scan_args(argc, argv, "0:", &opt);
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
ID kw[1];
|
|
1320
|
-
VALUE val[1];
|
|
1321
|
-
kw[0] = rb_intern("freeze");
|
|
1322
|
-
rb_get_kwargs(opt, kw, 0, 1, val);
|
|
1323
|
-
if ( val[0] != Qundef ) {
|
|
1324
|
-
rfreeze = val[0];
|
|
1325
|
-
}
|
|
1326
|
-
}
|
|
1342
|
+
/* Any key but freeze: is refused, as Kernel#clone does. */
|
|
1343
|
+
rb_scan_options(opt, "freeze", &rfreeze);
|
|
1327
1344
|
obj = rb_ca_copy(self);
|
|
1328
1345
|
if ( RTEST(rfreeze) || ( NIL_P(rfreeze) && OBJ_FROZEN(self) ) ) {
|
|
1329
1346
|
rb_obj_freeze(obj);
|
|
@@ -1331,45 +1348,6 @@ rb_ca_wrap_clone (int argc, VALUE *argv, VALUE self)
|
|
|
1331
1348
|
return obj;
|
|
1332
1349
|
}
|
|
1333
1350
|
|
|
1334
|
-
/* @overload wrap (data_type, dim, bytes=0) { target }
|
|
1335
|
-
|
|
1336
|
-
[TBD] (Construction)
|
|
1337
|
-
target should have method "wrap_as_carray(obj)"
|
|
1338
|
-
*/
|
|
1339
|
-
|
|
1340
|
-
static VALUE
|
|
1341
|
-
rb_ca_s_wrap (int argc, VALUE *argv, VALUE self)
|
|
1342
|
-
{
|
|
1343
|
-
volatile VALUE obj, target, rtype, rdim, ropt, rbytes = Qnil;
|
|
1344
|
-
CArray *ca;
|
|
1345
|
-
int8_t data_type, ndim;
|
|
1346
|
-
ca_size_t dim[CA_RANK_MAX];
|
|
1347
|
-
ca_size_t bytes;
|
|
1348
|
-
int8_t i;
|
|
1349
|
-
|
|
1350
|
-
rb_scan_args(argc, argv, "21", (VALUE *) &rtype, (VALUE *) &rdim, (VALUE *) &ropt);
|
|
1351
|
-
rb_scan_options(ropt, "bytes", &rbytes);
|
|
1352
|
-
|
|
1353
|
-
rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
|
|
1354
|
-
|
|
1355
|
-
Check_Type(rdim, T_ARRAY);
|
|
1356
|
-
CA_CHECK_RANK_GIVEN(RARRAY_LEN(rdim)); /* before dim[] is filled */
|
|
1357
|
-
ndim = RARRAY_LEN(rdim);
|
|
1358
|
-
for (i=0; i<ndim; i++) {
|
|
1359
|
-
dim[i] = NUM2SIZE(rb_ary_entry(rdim, i));
|
|
1360
|
-
}
|
|
1361
|
-
|
|
1362
|
-
target = rb_yield_values(0);
|
|
1363
|
-
|
|
1364
|
-
obj = TypedData_Make_Struct(rb_cCAWrap, CAWrap, &cawrap_data_type, ca);
|
|
1365
|
-
ca_wrap_setup_null(ca, data_type, ndim, dim, bytes, NULL);
|
|
1366
|
-
|
|
1367
|
-
rb_funcall(target, rb_intern("wrap_as_carray"), 1, obj);
|
|
1368
|
-
rb_ivar_set(obj, rb_intern("referred_object"), target);
|
|
1369
|
-
|
|
1370
|
-
return obj;
|
|
1371
|
-
}
|
|
1372
|
-
|
|
1373
1351
|
VALUE
|
|
1374
1352
|
rb_carray_wrap_ptr (int8_t data_type, int8_t ndim, ca_size_t *dim,
|
|
1375
1353
|
ca_size_t bytes, CArray *mask, char *ptr, VALUE refer)
|
|
@@ -1409,15 +1387,16 @@ rb_cs_s_allocate (VALUE klass)
|
|
|
1409
1387
|
*/
|
|
1410
1388
|
|
|
1411
1389
|
static VALUE
|
|
1412
|
-
rb_cs_initialize (int argc, VALUE *argv, VALUE self)
|
|
1390
|
+
rb_cs_initialize (int argc, VALUE *argv, volatile VALUE self)
|
|
1413
1391
|
{
|
|
1414
|
-
|
|
1392
|
+
VALUE rtype, ropt, rbytes = Qnil;
|
|
1415
1393
|
CScalar *ca;
|
|
1416
1394
|
int8_t data_type;
|
|
1417
1395
|
ca_size_t bytes;
|
|
1418
1396
|
|
|
1419
|
-
rb_scan_args(argc, argv, "11",
|
|
1397
|
+
rb_scan_args(argc, argv, "11", &rtype, &ropt);
|
|
1420
1398
|
rb_scan_options(ropt, "bytes", &rbytes);
|
|
1399
|
+
ca_refuse_type_number(rtype);
|
|
1421
1400
|
|
|
1422
1401
|
rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
|
|
1423
1402
|
|
|
@@ -1445,7 +1424,7 @@ static VALUE
|
|
|
1445
1424
|
rb_cs_s_fixlen (int argc, VALUE *argv, VALUE klass)
|
|
1446
1425
|
{
|
|
1447
1426
|
volatile VALUE ropt = rb_pop_options(&argc, &argv);
|
|
1448
|
-
VALUE args[2] = {
|
|
1427
|
+
VALUE args[2] = { ID2SYM(ca_data_type_sym[CA_FIXLEN]), ropt };
|
|
1449
1428
|
if ( argc > 0 ) {
|
|
1450
1429
|
rb_raise(rb_eArgError, "invalid number of arguments");
|
|
1451
1430
|
}
|
|
@@ -1455,7 +1434,7 @@ rb_cs_s_fixlen (int argc, VALUE *argv, VALUE klass)
|
|
|
1455
1434
|
#define rb_cs_s_body(code) \
|
|
1456
1435
|
{ \
|
|
1457
1436
|
volatile VALUE ropt = rb_pop_options(&argc, &argv); \
|
|
1458
|
-
VALUE args[2] = {
|
|
1437
|
+
VALUE args[2] = { ID2SYM(ca_data_type_sym[code]), ropt }; \
|
|
1459
1438
|
if ( argc > 0 ) { \
|
|
1460
1439
|
rb_raise(rb_eArgError, "invalid number of arguments"); \
|
|
1461
1440
|
} \
|
|
@@ -1611,7 +1590,7 @@ rb_cs_s_VALUE (int argc, VALUE *argv, VALUE klass) {
|
|
|
1611
1590
|
*/
|
|
1612
1591
|
|
|
1613
1592
|
static VALUE
|
|
1614
|
-
rb_cs_initialize_copy (VALUE self, VALUE other)
|
|
1593
|
+
rb_cs_initialize_copy (volatile VALUE self, volatile VALUE other)
|
|
1615
1594
|
{
|
|
1616
1595
|
CScalar *ca, *cs;
|
|
1617
1596
|
|
|
@@ -1638,15 +1617,15 @@ rb_cs_coerce (VALUE self, VALUE other)
|
|
|
1638
1617
|
{
|
|
1639
1618
|
CScalar *ca;
|
|
1640
1619
|
TypedData_Get_Struct(self, CScalar, &cscalar_data_type, ca);
|
|
1641
|
-
return
|
|
1642
|
-
|
|
1620
|
+
return rb_ary_new_from_args(2, rb_cscalar_new_with_value(ca->data_type, ca->bytes, other),
|
|
1621
|
+
self);
|
|
1643
1622
|
}
|
|
1644
1623
|
*/
|
|
1645
1624
|
|
|
1646
1625
|
/* Internal primitive that wraps rb_carray_new (= uninit alloc) for the
|
|
1647
|
-
Ruby-side
|
|
1626
|
+
Ruby-side callers that build an array they fill at once.
|
|
1648
1627
|
Bypasses the explicit MEMZERO that CArray.new (= rb_carray_new_safe)
|
|
1649
|
-
pays
|
|
1628
|
+
pays unless raw: true is given. CA_OBJECT silently falls through to the zero-VALUE
|
|
1650
1629
|
init inside carray_setup_i (= required for GC), so it is safe to
|
|
1651
1630
|
call this with any data_type. */
|
|
1652
1631
|
static VALUE
|
|
@@ -1659,36 +1638,9 @@ rb_ca_s_alloc_uninit (VALUE klass, VALUE rtype, VALUE rshape)
|
|
|
1659
1638
|
int8_t i;
|
|
1660
1639
|
rb_ca_guess_type_and_bytes(rtype, Qnil, &data_type, &bytes);
|
|
1661
1640
|
Check_Type(rshape, T_ARRAY);
|
|
1662
|
-
|
|
1641
|
+
CA_CHECK_RANK(RARRAY_LEN(rshape)); /* before dim[] is filled */
|
|
1663
1642
|
ndim = (int8_t) RARRAY_LEN(rshape);
|
|
1664
|
-
for (i = 0; i < ndim; i++) dim[i] =
|
|
1665
|
-
return rb_carray_new(data_type, ndim, dim, bytes, NULL);
|
|
1666
|
-
}
|
|
1667
|
-
|
|
1668
|
-
/* Internal primitive behind CArray.empty(data_type, dim, bytes: nil) in
|
|
1669
|
-
lib/carray/construct.rb, which also routes the compatibility spelling
|
|
1670
|
-
CArray.empty(*shape). It is CArray.new with the fill left out: the
|
|
1671
|
-
arguments are read by the same function, and the buffer comes from
|
|
1672
|
-
rb_carray_new (= no MEMZERO) rather than rb_carray_new_safe. A block
|
|
1673
|
-
is refused -- filling is what CArray.new is for. CA_OBJECT still
|
|
1674
|
-
falls through to the zero-VALUE init inside carray_setup_i (= required
|
|
1675
|
-
for GC), so any data_type is safe to ask for. */
|
|
1676
|
-
|
|
1677
|
-
static VALUE
|
|
1678
|
-
rb_ca_s_empty (int argc, VALUE *argv, VALUE klass)
|
|
1679
|
-
{
|
|
1680
|
-
int8_t data_type, ndim;
|
|
1681
|
-
ca_size_t dim[CA_RANK_MAX];
|
|
1682
|
-
ca_size_t bytes;
|
|
1683
|
-
|
|
1684
|
-
if ( rb_block_given_p() ) {
|
|
1685
|
-
rb_raise(rb_eArgError,
|
|
1686
|
-
"CArray.empty does not take a block "
|
|
1687
|
-
"(its contents are left undefined); use CArray.new to fill.");
|
|
1688
|
-
}
|
|
1689
|
-
|
|
1690
|
-
ca_scan_construct_args(argc, argv, &data_type, &bytes, &ndim, dim);
|
|
1691
|
-
|
|
1643
|
+
for (i = 0; i < ndim; i++) dim[i] = ca_integer_arg(rb_ary_entry(rshape, i), "a dimension", NULL);
|
|
1692
1644
|
return rb_carray_new(data_type, ndim, dim, bytes, NULL);
|
|
1693
1645
|
}
|
|
1694
1646
|
|
|
@@ -1703,7 +1655,6 @@ Init_ca_obj_array (void)
|
|
|
1703
1655
|
rb_define_method(rb_cCArray, "initialize", rb_ca_initialize, -1);
|
|
1704
1656
|
rb_define_singleton_method(rb_cCArray, "__alloc_uninit__",
|
|
1705
1657
|
rb_ca_s_alloc_uninit, 2);
|
|
1706
|
-
rb_define_private_method(rb_singleton_class(rb_cCArray), "empty_of_data_type", rb_ca_s_empty, -1);
|
|
1707
1658
|
|
|
1708
1659
|
rb_define_singleton_method(rb_cCArray, "fixlen", rb_ca_s_fixlen, -1);
|
|
1709
1660
|
rb_define_singleton_method(rb_cCArray, "boolean", rb_ca_s_boolean, -1);
|
|
@@ -1723,22 +1674,11 @@ Init_ca_obj_array (void)
|
|
|
1723
1674
|
#endif
|
|
1724
1675
|
rb_define_singleton_method(rb_cCArray, "object", rb_ca_s_VALUE, -1);
|
|
1725
1676
|
|
|
1726
|
-
rb_define_singleton_method(rb_cCArray, "byte", rb_ca_s_uint8, -1);
|
|
1727
|
-
rb_define_singleton_method(rb_cCArray, "short", rb_ca_s_int16, -1);
|
|
1728
|
-
rb_define_singleton_method(rb_cCArray, "int", rb_ca_s_int32, -1);
|
|
1729
|
-
rb_define_singleton_method(rb_cCArray, "float", rb_ca_s_float32, -1);
|
|
1730
|
-
rb_define_singleton_method(rb_cCArray, "double", rb_ca_s_float64, -1);
|
|
1731
|
-
#ifdef HAVE_COMPLEX_H
|
|
1732
|
-
rb_define_singleton_method(rb_cCArray, "complex", rb_ca_s_cmplx64, -1);
|
|
1733
|
-
rb_define_singleton_method(rb_cCArray, "dcomplex", rb_ca_s_cmplx128, -1);
|
|
1734
|
-
#endif
|
|
1735
|
-
|
|
1736
1677
|
rb_define_method(rb_cCArray, "initialize_copy", rb_ca_initialize_copy, 1);
|
|
1737
1678
|
rb_define_method(rb_cCArray, "initialize_dup", rb_ca_initialize_dup, 1);
|
|
1738
1679
|
rb_define_method(rb_cCArray, "initialize_clone", rb_ca_initialize_clone, -1);
|
|
1739
1680
|
rb_define_method(rb_cCAWrap, "dup", rb_ca_wrap_dup, 0);
|
|
1740
1681
|
rb_define_method(rb_cCAWrap, "clone", rb_ca_wrap_clone, -1);
|
|
1741
|
-
rb_define_singleton_method(rb_cCArray, "wrap", rb_ca_s_wrap, -1);
|
|
1742
1682
|
|
|
1743
1683
|
/* ------------------------------------------------------------------- */
|
|
1744
1684
|
|
|
@@ -1764,21 +1704,8 @@ Init_ca_obj_array (void)
|
|
|
1764
1704
|
#endif
|
|
1765
1705
|
rb_define_singleton_method(rb_cCScalar, "object", rb_cs_s_VALUE, -1);
|
|
1766
1706
|
|
|
1767
|
-
rb_define_singleton_method(rb_cCScalar, "byte", rb_cs_s_uint8, -1);
|
|
1768
|
-
rb_define_singleton_method(rb_cCScalar, "short", rb_cs_s_int16, -1);
|
|
1769
|
-
rb_define_singleton_method(rb_cCScalar, "int", rb_cs_s_int32, -1);
|
|
1770
|
-
rb_define_singleton_method(rb_cCScalar, "float", rb_cs_s_float32, -1);
|
|
1771
|
-
rb_define_singleton_method(rb_cCScalar, "double", rb_cs_s_float64, -1);
|
|
1772
|
-
#ifdef HAVE_COMPLEX_H
|
|
1773
|
-
rb_define_singleton_method(rb_cCScalar, "complex", rb_cs_s_cmplx64, -1);
|
|
1774
|
-
rb_define_singleton_method(rb_cCScalar, "dcomplex", rb_cs_s_cmplx128, -1);
|
|
1775
|
-
#endif
|
|
1776
|
-
|
|
1777
1707
|
rb_define_method(rb_cCScalar, "initialize_copy", rb_cs_initialize_copy, 1);
|
|
1778
1708
|
// rb_define_method(rb_cCScalar, "coerce", rb_cs_coerce, 1);
|
|
1779
1709
|
|
|
1780
|
-
rb_define_const(rb_cObject, "CA_OBJ_ARRAY", INT2NUM(CA_OBJ_ARRAY));
|
|
1781
|
-
rb_define_const(rb_cObject, "CA_OBJ_ARRAY_WRAP", INT2NUM(CA_OBJ_ARRAY_WRAP));
|
|
1782
|
-
rb_define_const(rb_cObject, "CA_OBJ_SCALAR", INT2NUM(CA_OBJ_SCALAR));
|
|
1783
1710
|
|
|
1784
1711
|
}
|