carray 3.0.2 → 3.0.3
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/CHANGELOG.md +304 -0
- data/README.md +3 -4
- data/carray.gemspec +1 -1
- data/ext/ca_axis_dispatch.c +225 -0
- data/ext/ca_axis_group.c +177 -99
- data/ext/ca_binop_dispatch.c +54 -32
- data/ext/ca_binop_dispatch.h +1 -0
- data/ext/ca_categorical_iterator.c +66 -71
- data/ext/ca_compare.c +8 -2
- data/ext/ca_for_buffer.h +21 -68
- data/ext/ca_group_iter.c +27 -11
- data/ext/ca_kernel_iterator.c +663 -214
- data/ext/ca_kernel_iterator.h +231 -167
- data/ext/ca_monop_dispatch.c +4 -4
- data/ext/ca_monop_dispatch.h +4 -0
- data/ext/ca_obj_array.c +132 -22
- data/ext/ca_obj_bincmp.c +152 -121
- data/ext/ca_obj_binop.c +107 -210
- data/ext/ca_obj_bitarray.c +37 -24
- data/ext/ca_obj_bitfield.c +95 -62
- data/ext/ca_obj_block.c +1 -0
- data/ext/ca_obj_byte_swap.c +40 -40
- data/ext/ca_obj_const_string.c +96 -25
- data/ext/ca_obj_face.c +406 -64
- data/ext/ca_obj_face.h +92 -47
- data/ext/ca_obj_fake.c +21 -50
- data/ext/ca_obj_farray.c +1 -0
- data/ext/ca_obj_field.c +16 -3
- data/ext/ca_obj_fixlen_string.c +21 -21
- data/ext/ca_obj_grid.c +181 -124
- data/ext/ca_obj_meld.c +189 -107
- data/ext/ca_obj_moncmp.c +61 -61
- data/ext/ca_obj_monop.c +125 -107
- data/ext/ca_obj_object.c +543 -233
- data/ext/ca_obj_record.c +51 -16
- data/ext/ca_obj_reduce.c +5 -8
- data/ext/ca_obj_refer.c +117 -33
- data/ext/ca_obj_remap.c +57 -17
- data/ext/ca_obj_repeat.c +21 -5
- data/ext/ca_obj_roll.c +115 -11
- data/ext/ca_obj_select.c +47 -49
- data/ext/ca_obj_select_axis.c +58 -60
- data/ext/ca_obj_shift.c +22 -102
- data/ext/ca_obj_stack.c +223 -118
- data/ext/ca_obj_stride.c +195 -34
- data/ext/ca_obj_string.c +17 -18
- data/ext/ca_obj_tile.c +32 -16
- data/ext/ca_obj_time.c +23 -25
- data/ext/ca_obj_timedelta.c +21 -23
- data/ext/ca_obj_transpose.c +12 -3
- data/ext/ca_obj_triop.c +110 -117
- data/ext/ca_obj_window.c +149 -27
- data/ext/ca_op_ipower.c +24 -11
- data/ext/ca_op_powi.h +57 -30
- data/ext/ca_pow5_table.h +656 -0
- data/ext/ca_sort_kernels.h +70 -0
- data/ext/ca_sweep_engine.c +102 -79
- data/ext/ca_sweep_engine.h +7 -20
- data/ext/ca_triop_dispatch.c +4 -1
- data/ext/ca_triop_dispatch.h +5 -2
- data/ext/caframe_csv_reader.c +463 -0
- data/ext/carray.h +70 -27
- data/ext/carray_access.c +455 -211
- data/ext/carray_address_basis.c +177 -36
- data/ext/carray_attribute.c +45 -3
- data/ext/carray_bincount.c +32 -2
- data/ext/carray_broadcast.c +46 -14
- data/ext/carray_call_cfunc.c +0 -28
- data/ext/carray_cast.c +1444 -209
- data/ext/carray_cast_func.rb +34 -21
- data/ext/carray_conversion.c +197 -73
- data/ext/carray_copy.c +32 -11
- data/ext/carray_core.c +514 -122
- data/ext/carray_count.c +140 -87
- data/ext/carray_element.c +18 -27
- data/ext/carray_factorize.c +569 -277
- data/ext/carray_generate.c +76 -40
- data/ext/carray_histogram.c +152 -94
- data/ext/carray_hold.c +2 -1
- data/ext/carray_index_classifier.c +63 -96
- data/ext/carray_internal.h +385 -3
- data/ext/carray_lazy.c +834 -79
- data/ext/carray_loop.c +81 -65
- data/ext/carray_mask.c +682 -316
- data/ext/carray_math_kernel.h +1 -0
- data/ext/carray_median_percentile.c +221 -76
- data/ext/carray_memory_view.c +254 -248
- data/ext/carray_operator.c +1089 -359
- data/ext/carray_order.c +133 -69
- data/ext/carray_partition.c +102 -56
- data/ext/carray_random.c +273 -239
- data/ext/carray_scatter.c +308 -65
- data/ext/carray_segment.c +257 -0
- data/ext/carray_slab.c +170 -70
- data/ext/carray_sort.c +215 -218
- data/ext/carray_sort_kernel.c +8 -1
- data/ext/carray_struct.c +99 -21
- data/ext/carray_test.c +167 -64
- data/ext/carray_time_text.c +1182 -0
- data/ext/carray_utils.c +363 -98
- data/ext/extconf.rb +27 -2
- data/ext/mk_call_cfunc.rb +0 -2
- data/ext/mk_pow5_table.rb +35 -0
- data/ext/mkkernel.rb +1076 -846
- data/ext/ruby_carray.c +7 -1
- data/ext/version.h +4 -4
- data/ext/version.rb +4 -2
- data/lib/carray/attribute.rb +39 -0
- data/lib/carray/autoload_carray.rb +19 -0
- data/lib/carray/autoload_method_extension.rb +6 -0
- data/lib/carray/axis_group.rb +174 -26
- data/lib/carray/basics.rb +91 -25
- data/lib/carray/bincount_nd.rb +6 -0
- data/lib/carray/block_iterator.rb +118 -48
- data/lib/carray/boolean_reduce.rb +21 -29
- data/lib/carray/categorical.rb +94 -26
- data/lib/carray/categorical_iterator.rb +333 -826
- data/lib/carray/complex.rb +36 -29
- data/lib/carray/conditional.rb +94 -7
- data/lib/carray/const_string.rb +46 -0
- data/lib/carray/frame/concat.rb +157 -6
- data/lib/carray/frame/convert.rb +13 -7
- data/lib/carray/frame/csv_parser.rb +589 -82
- data/lib/carray/frame/describe.rb +79 -0
- data/lib/carray/frame/frame.rb +124 -25
- data/lib/carray/frame/group.rb +189 -63
- data/lib/carray/frame/io.rb +412 -72
- data/lib/carray/frame/join.rb +134 -46
- data/lib/carray/frame/records.rb +37 -16
- data/lib/carray/frame/reshape.rb +448 -0
- data/lib/carray/frame/sort.rb +26 -2
- data/lib/carray/frame/verbs.rb +715 -48
- data/lib/carray/frame.rb +2 -0
- data/lib/carray/fuse_source.rb +111 -2
- data/lib/carray/fusion.rb +229 -38
- data/lib/carray/inspect.rb +29 -11
- data/lib/carray/iterator.rb +14 -2
- data/lib/carray/lazy.rb +54 -30
- data/lib/carray/mask_gap_fill.rb +66 -52
- data/lib/carray/math.rb +32 -19
- data/lib/carray/meld_reduce.rb +40 -7
- data/lib/carray/methods/align_addr.rb +8 -4
- data/lib/carray/methods/bincount.rb +2 -2
- data/lib/carray/methods/bit_string.rb +14 -3
- data/lib/carray/methods/composition.rb +16 -10
- data/lib/carray/methods/factorize.rb +2 -2
- data/lib/carray/methods/gather_nd.rb +13 -2
- data/lib/carray/methods/insert_block.rb +9 -14
- data/lib/carray/methods/is_in.rb +117 -4
- data/lib/carray/methods/join.rb +1 -1
- data/lib/carray/methods/locate_addr.rb +177 -36
- data/lib/carray/methods/mode.rb +18 -1
- data/lib/carray/methods/repeat.rb +1 -20
- data/lib/carray/methods/resize.rb +21 -23
- data/lib/carray/methods/snap.rb +34 -12
- data/lib/carray/methods/unique.rb +11 -2
- data/lib/carray/record_order.rb +208 -0
- data/lib/carray/runtime.rb +14 -11
- data/lib/carray/segment_iterator.rb +990 -0
- data/lib/carray/serialize.rb +197 -27
- data/lib/carray/slab_iterator.rb +51 -27
- data/lib/carray/stack.rb +10 -4
- data/lib/carray/string_operation_extension.rb +4 -3
- data/lib/carray/struct.rb +142 -51
- data/lib/carray/struct_builder.rb +110 -14
- data/lib/carray/table.rb +2 -2
- data/lib/carray/time.rb +517 -103
- data/lib/carray/window_iterator.rb +127 -72
- data/lib/carray.rb +2 -2
- data/yard-stubs/ca_obj_array.rb +4 -4
- data/yard-stubs/ca_obj_bitarray.rb +7 -0
- data/yard-stubs/ca_obj_bitfield.rb +23 -12
- data/yard-stubs/ca_obj_fake.rb +1 -1
- data/yard-stubs/ca_obj_field.rb +1 -1
- data/yard-stubs/ca_obj_refer.rb +3 -3
- data/yard-stubs/ca_obj_roll.rb +0 -1
- data/yard-stubs/ca_obj_stride.rb +10 -7
- data/yard-stubs/ca_obj_transpose.rb +1 -1
- data/yard-stubs/ca_obj_window.rb +1 -2
- data/yard-stubs/carray_access.rb +5 -4
- data/yard-stubs/carray_broadcast.rb +1 -1
- data/yard-stubs/carray_cast.rb +78 -43
- data/yard-stubs/carray_conversion.rb +13 -1
- data/yard-stubs/carray_copy.rb +8 -3
- data/yard-stubs/carray_core.rb +3 -3
- data/yard-stubs/carray_count.rb +9 -0
- data/yard-stubs/carray_lazy.rb +5 -1
- data/yard-stubs/carray_loop.rb +4 -1
- data/yard-stubs/carray_mask.rb +34 -10
- data/yard-stubs/carray_math.rb +25 -13
- data/yard-stubs/carray_median_percentile.rb +10 -6
- data/yard-stubs/carray_order.rb +34 -13
- data/yard-stubs/carray_scatter.rb +10 -3
- data/yard-stubs/carray_segment.rb +72 -0
- data/yard-stubs/carray_slab.rb +2 -1
- data/yard-stubs/carray_sort.rb +43 -3
- data/yard-stubs/carray_test.rb +10 -0
- data/yard-stubs/carray_utils.rb +0 -26
- metadata +11 -19
- data/ext/ca_for_each_element.h +0 -239
- data/ext/carray_build_flags.h +0 -3
- data/ext/carray_config.h +0 -28
- data/ext/carray_kernels_bincmp.c +0 -4446
- data/ext/carray_kernels_binop.c +0 -11001
- data/ext/carray_kernels_init.c +0 -1131
- data/ext/carray_kernels_map.c +0 -3467
- data/ext/carray_kernels_moncmp.c +0 -2097
- data/ext/carray_kernels_monop.c +0 -18313
- data/ext/carray_kernels_reduce_aggregate.c +0 -26005
- data/ext/carray_kernels_reduce_boolean.c +0 -330
- data/ext/carray_kernels_reduce_cumulative.c +0 -14862
- data/ext/carray_kernels_reduce_extreme.c +0 -17494
- data/ext/carray_kernels_reduce_variance.c +0 -3910
- data/ext/carray_kernels_scan.c +0 -3693
- data/ext/carray_kernels_search.c +0 -32218
- data/ext/carray_kernels_sort.c +0 -10626
- data/ext/carray_kernels_triop.c +0 -1392
data/yard-stubs/carray_cast.rb
CHANGED
|
@@ -8,57 +8,75 @@
|
|
|
8
8
|
# is a top-level function that coerces `obj` (a CArray, Array,
|
|
9
9
|
# Numeric, or anything castable) into a CArray of the named element
|
|
10
10
|
# type, equivalent to `obj.to_ca.as_type(:<type>)`.
|
|
11
|
+
#
|
|
12
|
+
# These are casts, not shape spellings: `CA_INT32(3, 3)` is not the
|
|
13
|
+
# `(3, 3)` array that `CArray.int32(3, 3)` builds, and is refused.
|
|
14
|
+
# A `Range` accepts one more argument, the step, and that is the only
|
|
15
|
+
# two-argument form:
|
|
16
|
+
#
|
|
17
|
+
# CA_INT32(0..6) # => [ 0, 1, 2, 3, 4, 5, 6 ]
|
|
18
|
+
# CA_INT32(0..6, 2) # => [ 0, 2, 4, 6 ]
|
|
19
|
+
# CA_INT32(0, 2) # ArgumentError
|
|
20
|
+
#
|
|
21
|
+
# A step of `0` raises `RuntimeError`. A step given for anything but a
|
|
22
|
+
# `Range`, or a third argument, raises `ArgumentError`. An
|
|
23
|
+
# `Enumerator::ArithmeticSequence` already carries its own step, so
|
|
24
|
+
# `CA_INT32((0..6).step(2))` needs no second argument.
|
|
25
|
+
#
|
|
26
|
+
# `CA_FIXLEN` takes `bytes:` instead of a step; see {#CA_FIXLEN}.
|
|
11
27
|
module Kernel
|
|
12
28
|
# @!group CArray cast shorthands
|
|
13
29
|
|
|
14
30
|
# Coerces `obj` into a `:boolean` CArray. @return [CArray]
|
|
15
|
-
def CA_BOOLEAN(obj); end
|
|
31
|
+
def CA_BOOLEAN(obj = nil, step = nil); end
|
|
16
32
|
# Coerces `obj` into an `:int8` CArray. @return [CArray]
|
|
17
|
-
def CA_INT8(obj); end
|
|
33
|
+
def CA_INT8(obj = nil, step = nil); end
|
|
18
34
|
# Coerces `obj` into a `:uint8` CArray. @return [CArray]
|
|
19
|
-
def CA_UINT8(obj); end
|
|
35
|
+
def CA_UINT8(obj = nil, step = nil); end
|
|
20
36
|
# Coerces `obj` into an `:int16` CArray. @return [CArray]
|
|
21
|
-
def CA_INT16(obj); end
|
|
37
|
+
def CA_INT16(obj = nil, step = nil); end
|
|
22
38
|
# Coerces `obj` into a `:uint16` CArray. @return [CArray]
|
|
23
|
-
def CA_UINT16(obj); end
|
|
39
|
+
def CA_UINT16(obj = nil, step = nil); end
|
|
24
40
|
# Coerces `obj` into an `:int32` CArray. @return [CArray]
|
|
25
|
-
def CA_INT32(obj); end
|
|
41
|
+
def CA_INT32(obj = nil, step = nil); end
|
|
26
42
|
# Coerces `obj` into a `:uint32` CArray. @return [CArray]
|
|
27
|
-
def CA_UINT32(obj); end
|
|
43
|
+
def CA_UINT32(obj = nil, step = nil); end
|
|
28
44
|
# Coerces `obj` into an `:int64` CArray. @return [CArray]
|
|
29
|
-
def CA_INT64(obj); end
|
|
45
|
+
def CA_INT64(obj = nil, step = nil); end
|
|
30
46
|
# Coerces `obj` into a `:uint64` CArray. @return [CArray]
|
|
31
|
-
def CA_UINT64(obj); end
|
|
47
|
+
def CA_UINT64(obj = nil, step = nil); end
|
|
32
48
|
# Coerces `obj` into a `:float32` CArray. @return [CArray]
|
|
33
|
-
def CA_FLOAT32(obj); end
|
|
49
|
+
def CA_FLOAT32(obj = nil, step = nil); end
|
|
34
50
|
# Coerces `obj` into a `:float64` CArray. @return [CArray]
|
|
35
|
-
def CA_FLOAT64(obj); end
|
|
51
|
+
def CA_FLOAT64(obj = nil, step = nil); end
|
|
36
52
|
# Coerces `obj` into a `:cmplx64` CArray. @return [CArray]
|
|
37
|
-
def CA_CMPLX64(obj); end
|
|
53
|
+
def CA_CMPLX64(obj = nil, step = nil); end
|
|
38
54
|
# Coerces `obj` into a `:cmplx128` CArray. @return [CArray]
|
|
39
|
-
def CA_CMPLX128(obj); end
|
|
55
|
+
def CA_CMPLX128(obj = nil, step = nil); end
|
|
40
56
|
# Coerces `obj` into an `:object` CArray. @return [CArray]
|
|
41
|
-
def CA_OBJECT(obj); end
|
|
57
|
+
def CA_OBJECT(obj = nil, step = nil); end
|
|
42
58
|
# Coerces `obj` into a `CA_SIZE` (platform native size) CArray.
|
|
43
59
|
# @return [CArray]
|
|
44
|
-
def CA_SIZE(obj); end
|
|
45
|
-
# Coerces `obj` into a `:fixlen` CArray.
|
|
46
|
-
|
|
60
|
+
def CA_SIZE(obj = nil, step = nil); end
|
|
61
|
+
# Coerces `obj` into a `:fixlen` CArray. `bytes` defaults to the
|
|
62
|
+
# longest top-level element of an `Array`, or `0` for `nil`.
|
|
63
|
+
# @return [CArray]
|
|
64
|
+
def CA_FIXLEN(obj, bytes: nil); end
|
|
47
65
|
|
|
48
66
|
# Alias of {#CA_UINT8}. @return [CArray]
|
|
49
|
-
def CA_BYTE(obj); end
|
|
67
|
+
def CA_BYTE(obj = nil, step = nil); end
|
|
50
68
|
# Alias of {#CA_INT16}. @return [CArray]
|
|
51
|
-
def CA_SHORT(obj); end
|
|
69
|
+
def CA_SHORT(obj = nil, step = nil); end
|
|
52
70
|
# Alias of {#CA_INT32}. @return [CArray]
|
|
53
|
-
def CA_INT(obj); end
|
|
71
|
+
def CA_INT(obj = nil, step = nil); end
|
|
54
72
|
# Alias of {#CA_FLOAT32}. @return [CArray]
|
|
55
|
-
def CA_FLOAT(obj); end
|
|
73
|
+
def CA_FLOAT(obj = nil, step = nil); end
|
|
56
74
|
# Alias of {#CA_FLOAT64}. @return [CArray]
|
|
57
|
-
def CA_DOUBLE(obj); end
|
|
75
|
+
def CA_DOUBLE(obj = nil, step = nil); end
|
|
58
76
|
# Alias of {#CA_CMPLX64}. @return [CArray]
|
|
59
|
-
def CA_COMPLEX(obj); end
|
|
77
|
+
def CA_COMPLEX(obj = nil, step = nil); end
|
|
60
78
|
# Alias of {#CA_CMPLX128}. @return [CArray]
|
|
61
|
-
def CA_DCOMPLEX(obj); end
|
|
79
|
+
def CA_DCOMPLEX(obj = nil, step = nil); end
|
|
62
80
|
|
|
63
81
|
# @!endgroup
|
|
64
82
|
end
|
|
@@ -71,17 +89,21 @@ class CArray
|
|
|
71
89
|
# @overload to_type(data_type, bytes: nil)
|
|
72
90
|
# Returns a new entity holding the elements of `self` converted to
|
|
73
91
|
# `data_type` (an eager copy that owns its storage). Masked cells are
|
|
74
|
-
# carried across
|
|
75
|
-
# subclass) the result
|
|
92
|
+
# carried across, and so are the attributes `self` shows (`attrs`).
|
|
93
|
+
# When `data_type` is a data_class (a CAStruct subclass) the result
|
|
94
|
+
# is wrapped in CARecord.
|
|
76
95
|
#
|
|
77
96
|
# When `self` is an `:object` array and `data_type` is an integer or
|
|
78
|
-
# float type,
|
|
79
|
-
#
|
|
80
|
-
#
|
|
81
|
-
#
|
|
82
|
-
#
|
|
83
|
-
#
|
|
84
|
-
#
|
|
97
|
+
# float type, a String cell is read as a decimal number, not as a Ruby
|
|
98
|
+
# literal: `"010"` is 10, and `"0x10"` / `"1_000"` / `"0b11"` are not
|
|
99
|
+
# numbers. An integer type takes a number whose value is exactly an
|
|
100
|
+
# integer (`"1.0"`, `"1e3"`) but not `"1.5"`. A cell that cannot be
|
|
101
|
+
# read becomes UNDEF (masked) rather than a silent `0.0` or a raise:
|
|
102
|
+
# `nil`, `""`, `"xx"`, and a String integer the type cannot hold
|
|
103
|
+
# (`"300"` into `:int8`) all map to UNDEF. Explicit `nan` / `inf` /
|
|
104
|
+
# `infinity` (optional sign, any case) are kept as NaN / ±Infinity for
|
|
105
|
+
# float types. A cell that is not a String goes through `Integer()` /
|
|
106
|
+
# `Float()` as before.
|
|
85
107
|
# @param data_type [Symbol, Integer, Class, String] target element type.
|
|
86
108
|
# @param bytes [Integer, nil] element width in bytes, required for
|
|
87
109
|
# `:fixlen`.
|
|
@@ -337,7 +359,7 @@ class CArray
|
|
|
337
359
|
# primitive the binary operators use.
|
|
338
360
|
# @param other [CArray, Object] the second operand.
|
|
339
361
|
# @return [Array(CArray, CArray)]
|
|
340
|
-
# @raise [
|
|
362
|
+
# @raise [CArray::DataTypeError] when the two data_types have no common type.
|
|
341
363
|
def cast_with(other); end
|
|
342
364
|
|
|
343
365
|
# `coerce` is documented with its definition in ext/carray_operator.c;
|
|
@@ -376,10 +398,9 @@ class CArray
|
|
|
376
398
|
# `nil` keeps the source type (or `:object` when `other` is `nil`).
|
|
377
399
|
# @return [CArray]
|
|
378
400
|
# @raise [RuntimeError] when `other` is read-only, its MemoryView is
|
|
379
|
-
# read-only, its `to_ca` refuses `writable: true
|
|
380
|
-
#
|
|
381
|
-
#
|
|
382
|
-
# CArray.
|
|
401
|
+
# read-only, or its `to_ca` refuses `writable: true`.
|
|
402
|
+
# @raise [TypeError] when `other` cannot be wrapped as a CArray, or
|
|
403
|
+
# `other#to_ca` returns something that is not a CArray.
|
|
383
404
|
# @raise [ArgumentError] when `other#to_ca` does not accept `writable:`.
|
|
384
405
|
# @raise [TypeError] when `other` is a Face and `data_type` differs from
|
|
385
406
|
# its surface type.
|
|
@@ -445,20 +466,30 @@ class CArray
|
|
|
445
466
|
# data_type inferred (3 -> `:int64`, 3.14 -> `:float64`,
|
|
446
467
|
# 1+2i -> `:cmplx128`, ...)
|
|
447
468
|
#
|
|
448
|
-
#
|
|
449
|
-
#
|
|
469
|
+
# The arrays and data_type representations promote together. A
|
|
470
|
+
# scalar (a value, or a CScalar) then joins their type the way it
|
|
471
|
+
# does beside an operator: one of the same kind takes that type
|
|
472
|
+
# (`result_type(float32_array, 0.1)` is `:float32`, as
|
|
473
|
+
# `float32_array + 0.1` is), one of another kind promotes
|
|
474
|
+
# (`result_type(int32_array, 1.5)` is `:float64`), and an Integer
|
|
475
|
+
# that does not fit an integer type takes `:int64`. With no array or
|
|
476
|
+
# data_type representation, every argument promotes by its own type.
|
|
477
|
+
#
|
|
478
|
+
# Integer args are interpreted as *values*, not as data_type codes:
|
|
450
479
|
# `result_type(8)` returns `:int64` because the value 8 is an Integer,
|
|
451
480
|
# not because a data_type code equals 8. Use `result_type(:int64)` or
|
|
452
481
|
# `result_type(CA_INT64)` to be explicit about data_type intent.
|
|
453
482
|
# @param args [Array<CArray, Symbol, String, Class, Object>] operands.
|
|
454
483
|
# @return [Symbol]
|
|
455
484
|
# @raise [ArgumentError] when called with no arguments.
|
|
456
|
-
# @raise [
|
|
485
|
+
# @raise [CArray::DataTypeError] when two inputs are mutually incompatible
|
|
457
486
|
# (e.g. `:object` with `:fixlen`).
|
|
458
487
|
# @example
|
|
459
488
|
# CArray.result_type(:int32, :float32) #=> :float32
|
|
460
489
|
# CArray.result_type(3, 3.14) #=> :float64
|
|
461
490
|
# CArray.result_type(true, 3) #=> :int64
|
|
491
|
+
# CArray.result_type(CA_INT8([1]), 1) #=> :int8
|
|
492
|
+
# CArray.result_type(CA_INT8([1]), 300) #=> :int64
|
|
462
493
|
def self.result_type(*args); end
|
|
463
494
|
|
|
464
495
|
# @overload promote_list(list, data_type: nil)
|
|
@@ -471,8 +502,12 @@ class CArray
|
|
|
471
502
|
# elements passes through (CAStack lifts it), unless the class is not
|
|
472
503
|
# portable (CAConstString) or the elements disagree on state
|
|
473
504
|
# (CATime with different units); a list of primitives is
|
|
474
|
-
# promoted via {.result_type} + {.wrap_readonly}
|
|
475
|
-
#
|
|
505
|
+
# promoted via {.result_type} + {.wrap_readonly}, except that a list
|
|
506
|
+
# mixing signed and unsigned integers takes a type that holds both
|
|
507
|
+
# (`uint8` with `int8` is `int16`, 64-bit pairs are `:object`), and an
|
|
508
|
+
# integer of 32 bits or more beside `float32` takes `float64`, since
|
|
509
|
+
# the arrays are joined value for value; a mix of Face and non-Face,
|
|
510
|
+
# or heterogeneous Face classes, is rejected.
|
|
476
511
|
#
|
|
477
512
|
# With an explicit primitive `data_type`: all-primitive elements are
|
|
478
513
|
# wrapped read-only to the requested type; any Face element is
|
|
@@ -38,6 +38,13 @@ class CArray
|
|
|
38
38
|
|
|
39
39
|
# @!group Copy and conversion
|
|
40
40
|
|
|
41
|
+
# On a Face (`CATime`, `CACategorical`, `CAConstString`, ...) the
|
|
42
|
+
# bytes are its storage, and none of its state is written: not the
|
|
43
|
+
# unit of a `CATime`, not the labels of a `CACategorical`. A
|
|
44
|
+
# `CAConstString` cell is a `(start, end)` pair into its own byte
|
|
45
|
+
# pool, so its strings are not written at all; call
|
|
46
|
+
# `to_fixlen_string` first to dump the text.
|
|
47
|
+
#
|
|
41
48
|
# @overload dump_binary
|
|
42
49
|
# Returns a new binary String containing the raw element bytes of
|
|
43
50
|
# `self` in row-major order.
|
|
@@ -60,6 +67,10 @@ class CArray
|
|
|
60
67
|
# @return [String]
|
|
61
68
|
def to_s; end
|
|
62
69
|
|
|
70
|
+
# On a Face the bytes are read into its storage, and its state is
|
|
71
|
+
# the receiver's own: load into a Face set up with the same state
|
|
72
|
+
# (unit, labels) that was in force when the bytes were dumped.
|
|
73
|
+
#
|
|
63
74
|
# @overload load_binary(io)
|
|
64
75
|
# Reads `ca_length(self)` bytes from `io` and overwrites the
|
|
65
76
|
# element data of `self` in row-major order. `io` may be a
|
|
@@ -67,7 +78,8 @@ class CArray
|
|
|
67
78
|
# `read(n, buf = nil)`.
|
|
68
79
|
# @param io [String, IO, #read]
|
|
69
80
|
# @return [self]
|
|
70
|
-
# @raise [RuntimeError] on short read
|
|
81
|
+
# @raise [RuntimeError] on a short read.
|
|
82
|
+
# @raise [ArgumentError] when a String source is not the array's size.
|
|
71
83
|
# @raise [CArray::DataTypeError] if `self.data_type` is
|
|
72
84
|
# `:object`.
|
|
73
85
|
def load_binary(io); end
|
data/yard-stubs/carray_copy.rb
CHANGED
|
@@ -8,10 +8,15 @@ class CArray
|
|
|
8
8
|
# @overload copy
|
|
9
9
|
# Returns a fresh entity CArray with the same shape, `data_type`,
|
|
10
10
|
# element values, and mask state as `self`. Always allocates and
|
|
11
|
-
# copies, even when `self` is already an entity.
|
|
11
|
+
# copies, even when `self` is already an entity. The copy gets the
|
|
12
|
+
# attributes `self` shows (`attrs`) as its own.
|
|
12
13
|
#
|
|
13
14
|
# Use `copy` when you need an array you own and can mutate
|
|
14
|
-
# without affecting any source.
|
|
15
|
+
# without affecting any source. It is the only way to copy a
|
|
16
|
+
# CArray: `to_ca` returns `self`, and `dup` / `clone` on a view
|
|
17
|
+
# return another view onto the same storage, so writing to any of
|
|
18
|
+
# them writes to the source. Don't use `dup`, `clone` or `to_ca`
|
|
19
|
+
# to copy.
|
|
15
20
|
# @return [CArray] independent entity.
|
|
16
21
|
# @example A view's copy is independent of its source
|
|
17
22
|
# a = CArray.float64(4).seq
|
|
@@ -59,7 +64,7 @@ class CArray
|
|
|
59
64
|
# @param data_type [Symbol] target element type
|
|
60
65
|
# (e.g. `:int32`, `:float64`, `:fixlen`).
|
|
61
66
|
# @param bytes [Integer] element byte size; required for
|
|
62
|
-
# `:fixlen
|
|
67
|
+
# `:fixlen` (1 or more), ignored for numeric types.
|
|
63
68
|
# @return [CArray]
|
|
64
69
|
# @overload template { value }
|
|
65
70
|
# With a 0-arity block, fills every element of the result with
|
data/yard-stubs/carray_core.rb
CHANGED
|
@@ -10,7 +10,7 @@ class CArray
|
|
|
10
10
|
# Only valid when `self` carries a `data_class` (e.g. a
|
|
11
11
|
# `CARecord`).
|
|
12
12
|
# @return [Array<Symbol>]
|
|
13
|
-
# @raise [
|
|
13
|
+
# @raise [TypeError] if `self` has no `data_class`.
|
|
14
14
|
def members; end
|
|
15
15
|
|
|
16
16
|
# @overload fields
|
|
@@ -18,7 +18,7 @@ class CArray
|
|
|
18
18
|
# declaration order. Each entry is a CArray sharing storage with
|
|
19
19
|
# `self`.
|
|
20
20
|
# @return [Array<CArray>]
|
|
21
|
-
# @raise [
|
|
21
|
+
# @raise [TypeError] if `self` has no `data_class`.
|
|
22
22
|
def fields; end
|
|
23
23
|
|
|
24
24
|
# @overload fields_at(*names)
|
|
@@ -27,7 +27,7 @@ class CArray
|
|
|
27
27
|
# @param names [Array<Symbol, String, Integer>] member names or
|
|
28
28
|
# positional indices.
|
|
29
29
|
# @return [Array<CArray>]
|
|
30
|
-
# @raise [
|
|
30
|
+
# @raise [TypeError] if `self` has no `data_class`.
|
|
31
31
|
def fields_at(*names); end
|
|
32
32
|
|
|
33
33
|
# @!endgroup
|
data/yard-stubs/carray_count.rb
CHANGED
|
@@ -26,6 +26,11 @@ class CArray
|
|
|
26
26
|
# Mask-cardinality and value-match are distinct concepts, so the
|
|
27
27
|
# overloading is unambiguous.
|
|
28
28
|
#
|
|
29
|
+
# On an `:object` array a cell counts when it is `==` to `v` (so `1`
|
|
30
|
+
# and `1.0` match), as {#eq} compares; the hash-based family
|
|
31
|
+
# ({#is_in}, {#value_counts}) uses `eql?` instead, as Ruby's
|
|
32
|
+
# `Array#uniq` does.
|
|
33
|
+
#
|
|
29
34
|
# Dispatch:
|
|
30
35
|
# - no argument: forwards to {#count_not_masked} (present-cell
|
|
31
36
|
# count).
|
|
@@ -41,6 +46,10 @@ class CArray
|
|
|
41
46
|
# (`2`, `1.0`, `nil`, …) raises `TypeError`.
|
|
42
47
|
# - `self` is numeric, `v` is scalar: `v` must be numeric (true /
|
|
43
48
|
# false are rejected -- they are the boolean array's domain).
|
|
49
|
+
# On an integer array a Float `v`, or a `v` array of a wider
|
|
50
|
+
# type, is compared in the type the two share, as {#eq} compares:
|
|
51
|
+
# `CA_INT32([1, 2]).count(1.5)` is `0`. An Integer `v` that does
|
|
52
|
+
# not fit the array raises `RangeError`.
|
|
44
53
|
# - `self.data_type == :object`, `v` is scalar: cells equal to `v`
|
|
45
54
|
# by Ruby `==`, so `count(1)` and `count(1.0)` agree, and `true` /
|
|
46
55
|
# `false` / `nil` are ordinary values to count.
|
data/yard-stubs/carray_lazy.rb
CHANGED
|
@@ -17,7 +17,11 @@ class CArray
|
|
|
17
17
|
# materialise. The marker is transient — a Ruby reference can
|
|
18
18
|
# re-consume it (`m = a.lazy; m.sqrt + m.sin`) without side
|
|
19
19
|
# effects on `self`.
|
|
20
|
-
#
|
|
20
|
+
#
|
|
21
|
+
# A Face (`CATime`, `CACategorical`, a string array, ...) returns
|
|
22
|
+
# `self`: a lazy tree computes on storage and would drop what the
|
|
23
|
+
# Face means, so operations on a Face stay eager.
|
|
24
|
+
# @return [CALazyMarker, CArray] the marker, or `self` for a Face
|
|
21
25
|
def lazy; end
|
|
22
26
|
# @!endgroup
|
|
23
27
|
end
|
data/yard-stubs/carray_loop.rb
CHANGED
|
@@ -53,7 +53,10 @@ class CArray
|
|
|
53
53
|
|
|
54
54
|
# @overload map!
|
|
55
55
|
# Replaces each element of `self` with the block's return value.
|
|
56
|
-
# Mutates `self`.
|
|
56
|
+
# Mutates `self`. When the block raises or breaks part way, or
|
|
57
|
+
# returns a value that cannot be stored, the cells already replaced
|
|
58
|
+
# stay replaced -- through a view as well, which writes them back to
|
|
59
|
+
# its parent. The same holds for every `map_*!` below.
|
|
57
60
|
# @yieldparam elem [Object]
|
|
58
61
|
# @yieldreturn [Object] new value for the cell.
|
|
59
62
|
# @return [self]
|
data/yard-stubs/carray_mask.rb
CHANGED
|
@@ -74,7 +74,8 @@ class CArray
|
|
|
74
74
|
# Clears the mask state and overwrites the data at previously
|
|
75
75
|
# masked positions with `fill_value`. Mutates `self`.
|
|
76
76
|
# @param fill_value [Object] value to store at each previously
|
|
77
|
-
# masked position
|
|
77
|
+
# masked position, converted as a store into `self` converts it.
|
|
78
|
+
# `UNDEF` leaves the masked cells masked.
|
|
78
79
|
# @return [self]
|
|
79
80
|
# @overload unmask(method:, axis: nil)
|
|
80
81
|
# Fills masked cells in place from neighbouring valid cells along
|
|
@@ -106,7 +107,8 @@ class CArray
|
|
|
106
107
|
#
|
|
107
108
|
# Replaces the removed `unmask_copy(fill)` from 2.x.
|
|
108
109
|
# @param fill_value [Object] value to substitute at masked
|
|
109
|
-
# positions
|
|
110
|
+
# positions, converted as a store into `self` converts it.
|
|
111
|
+
# `UNDEF` leaves them masked (the copy keeps the mask).
|
|
110
112
|
# @return [CArray]
|
|
111
113
|
# @overload strip_mask(method:, axis: nil)
|
|
112
114
|
# Returns a new array with masked cells filled from neighbouring
|
|
@@ -151,6 +153,8 @@ class CArray
|
|
|
151
153
|
# Flips the mask state of every element of `self` in place
|
|
152
154
|
# (masked ↔ not masked). Mutates `self`.
|
|
153
155
|
# @return [self]
|
|
156
|
+
# @raise [FrozenError] if `self` is frozen or a view of a frozen array.
|
|
157
|
+
# @raise [RuntimeError] if `self` is read-only (a lazy expression, for one).
|
|
154
158
|
def invert_mask; end
|
|
155
159
|
|
|
156
160
|
# @overload inherit_mask(*others)
|
|
@@ -174,23 +178,43 @@ class CArray
|
|
|
174
178
|
# @overload count_masked
|
|
175
179
|
# Returns the total number of masked elements in `self`.
|
|
176
180
|
# @return [Integer]
|
|
177
|
-
# @overload count_masked(axis:)
|
|
181
|
+
# @overload count_masked(axis:, keep_axis: false, min_count: nil, fill_value: nil)
|
|
178
182
|
# Returns the per-slice count of masked elements along the given
|
|
179
183
|
# axis or axes. The result is an int64 CArray with `axis` removed
|
|
180
|
-
# from `shape
|
|
184
|
+
# from `shape` (kept as length 1 with `keep_axis: true`). Naming
|
|
185
|
+
# every axis without `keep_axis:` returns an Integer, as the form
|
|
186
|
+
# without `axis:` does. The answer is the same whether or not
|
|
187
|
+
# `self` has a mask.
|
|
181
188
|
# @param axis [Integer, Array<Integer>] axis or axes to reduce.
|
|
182
|
-
# @
|
|
189
|
+
# @param keep_axis [Boolean] keep the reduced axes as length 1.
|
|
190
|
+
# @param min_count [Integer, nil] cells with fewer than this many
|
|
191
|
+
# elements are UNDEF. A count of the mask reads every element,
|
|
192
|
+
# masked or not, so this compares with the slice size.
|
|
193
|
+
# @param fill_value [Object, nil] value written into UNDEF cells.
|
|
194
|
+
# @return [CArray, Integer]
|
|
195
|
+
# @raise [ArgumentError] if an axis is out of range, repeated, or
|
|
196
|
+
# the axis list is empty.
|
|
183
197
|
def count_masked(*, **); end
|
|
184
198
|
|
|
185
199
|
# @overload count_not_masked
|
|
186
200
|
# Returns the total number of not-masked elements in `self`.
|
|
187
201
|
# @return [Integer]
|
|
188
|
-
# @overload count_not_masked(axis:)
|
|
189
|
-
# Returns the per-slice count of not-masked elements along the
|
|
190
|
-
#
|
|
191
|
-
#
|
|
202
|
+
# @overload count_not_masked(axis:, keep_axis: false, min_count: nil, fill_value: nil)
|
|
203
|
+
# Returns the per-slice count of not-masked elements along the given
|
|
204
|
+
# axis or axes. The result is an int64 CArray with `axis` removed
|
|
205
|
+
# from `shape` (kept as length 1 with `keep_axis: true`). Naming
|
|
206
|
+
# every axis without `keep_axis:` returns an Integer, as the form
|
|
207
|
+
# without `axis:` does. The answer is the same whether or not
|
|
208
|
+
# `self` has a mask.
|
|
192
209
|
# @param axis [Integer, Array<Integer>] axis or axes to reduce.
|
|
193
|
-
# @
|
|
210
|
+
# @param keep_axis [Boolean] keep the reduced axes as length 1.
|
|
211
|
+
# @param min_count [Integer, nil] cells with fewer than this many
|
|
212
|
+
# elements are UNDEF. A count of the mask reads every element,
|
|
213
|
+
# masked or not, so this compares with the slice size.
|
|
214
|
+
# @param fill_value [Object, nil] value written into UNDEF cells.
|
|
215
|
+
# @return [CArray, Integer]
|
|
216
|
+
# @raise [ArgumentError] if an axis is out of range, repeated, or
|
|
217
|
+
# the axis list is empty.
|
|
194
218
|
def count_not_masked(*, **); end
|
|
195
219
|
|
|
196
220
|
# @!endgroup
|
data/yard-stubs/carray_math.rb
CHANGED
|
@@ -25,12 +25,15 @@ class CArray
|
|
|
25
25
|
# division is true division, as Ruby's `Float#/` is, so that
|
|
26
26
|
# identity is an integer one. Boolean arrays participate as their
|
|
27
27
|
# 0/1 storage. Masked elements stay masked, and a masked cell is
|
|
28
|
-
# never divided.
|
|
28
|
+
# never divided. The signed minimum divided by `-1` does not fit and
|
|
29
|
+
# is answered as the wrapped negation: `MIN / -1` is `MIN`.
|
|
29
30
|
# @param other [CArray, Numeric] divisor, broadcast to `self.shape`.
|
|
30
31
|
# @return [CArray] result of the promoted `data_type` of the two
|
|
31
32
|
# operands.
|
|
32
33
|
# @raise [ZeroDivisionError] when an integer divisor is `0`. Float
|
|
33
34
|
# division returns `Infinity` or `NaN` instead.
|
|
35
|
+
# @raise [RangeError] when an Integer `other` does not fit the
|
|
36
|
+
# integer `data_type` of `self`.
|
|
34
37
|
# @example
|
|
35
38
|
# CA_INT32([-7, -1, 7]) / 3 # => [ -3, -1, 2 ]
|
|
36
39
|
# CA_DOUBLE([-7.0]) / 3.0 # => [ -2.3333333333333335 ]
|
|
@@ -215,7 +218,7 @@ class CArray
|
|
|
215
218
|
# @overload rcp_mul(other)
|
|
216
219
|
# Returns `other` divided element-wise by `self` -- the reciprocal
|
|
217
220
|
# of {#/} in operand order, so that scaling a constant by an array
|
|
218
|
-
# needs no temporary.
|
|
221
|
+
# needs no temporary. Integer division floors, as {#/} does.
|
|
219
222
|
# @param other [CArray, Numeric] dividend, broadcast to `self.shape`.
|
|
220
223
|
# @return [CArray] result of the promoted `data_type` of the two
|
|
221
224
|
# operands.
|
|
@@ -241,12 +244,12 @@ class CArray
|
|
|
241
244
|
#
|
|
242
245
|
# A numeric array keeps its `data_type`; a complex array returns the
|
|
243
246
|
# real magnitude at that complex type's own width, so a `:cmplx64`
|
|
244
|
-
# yields `:float32` just as {#real} and {#imag} do.
|
|
245
|
-
#
|
|
246
|
-
# imaginary part) use {#abs_i}
|
|
247
|
-
# @return [CArray] `self`'s `data_type` for numeric
|
|
248
|
-
# component type for complex input.
|
|
249
|
-
# @raise [CArray::DataTypeError] for a boolean
|
|
247
|
+
# yields `:float32` just as {#real} and {#imag} do. An `:object`
|
|
248
|
+
# array calls each cell's `abs`. For the form that keeps a complex
|
|
249
|
+
# array complex (magnitude with a zero imaginary part) use {#abs_i}.
|
|
250
|
+
# @return [CArray] `self`'s `data_type` for numeric and `:object`
|
|
251
|
+
# input; the real component type for complex input.
|
|
252
|
+
# @raise [CArray::DataTypeError] for a boolean array.
|
|
250
253
|
# @example
|
|
251
254
|
# CA_CMPLX64([Complex(3, 4)]).abs # => [ 5.0 ] (:float32)
|
|
252
255
|
def abs; end
|
|
@@ -738,7 +741,8 @@ class CArray
|
|
|
738
741
|
# comparison) and `:object` (Ruby `==`) `data_type`. A masked
|
|
739
742
|
# element yields a masked result rather than `false`. Floating
|
|
740
743
|
# point equality is exact here; for a tolerant comparison see
|
|
741
|
-
# {#is_close} (absolute) or {#is_equiv} (relative).
|
|
744
|
+
# {#is_close} (absolute) or {#is_equiv} (relative). Integers compare
|
|
745
|
+
# by value, as for {#<}.
|
|
742
746
|
# @param other [CArray, Numeric, Object] comparand, broadcast to
|
|
743
747
|
# `self.shape`.
|
|
744
748
|
# @return [CArray] `:boolean`, same shape as `self`.
|
|
@@ -760,6 +764,11 @@ class CArray
|
|
|
760
764
|
# Accepts numeric, boolean, `:fixlen` (byte order, shorter first on
|
|
761
765
|
# a common prefix) and `:object` (Ruby `<`) `data_type`s. Complex
|
|
762
766
|
# arrays have no ordering and raise.
|
|
767
|
+
#
|
|
768
|
+
# Integers compare by value: an unsigned array against a signed one
|
|
769
|
+
# answers as the Integers would (`CA_UINT64([7]) < CA_INT64([-7])`
|
|
770
|
+
# is false), and so does an Integer the array's type cannot hold
|
|
771
|
+
# (`CA_UINT8([0]) > -1` is true).
|
|
763
772
|
# @param other [CArray, Numeric, Object] comparand, broadcast to
|
|
764
773
|
# `self.shape`.
|
|
765
774
|
# @return [CArray] `:boolean`, same shape as `self`.
|
|
@@ -861,8 +870,11 @@ class CArray
|
|
|
861
870
|
# Returns a boolean array that is true where an element is `NaN`.
|
|
862
871
|
# @return [CArray] `:boolean`, same shape as `self`.
|
|
863
872
|
# @raise [CArray::DataTypeError] for a boolean array.
|
|
864
|
-
#
|
|
865
|
-
#
|
|
873
|
+
# On an `:object` array an Integer or a Rational element is never
|
|
874
|
+
# `NaN`; other elements answer through `#nan?`.
|
|
875
|
+
# @raise [NoMethodError] for an `:object` array with an element that
|
|
876
|
+
# is not an Integer, a Rational or a Float and does not respond to
|
|
877
|
+
# `#nan?`.
|
|
866
878
|
def is_nan; end
|
|
867
879
|
|
|
868
880
|
# @overload is_inf
|
|
@@ -1043,7 +1055,7 @@ class CArray
|
|
|
1043
1055
|
# Applies {#abs} to `self` in place, keeping `self`'s
|
|
1044
1056
|
# `data_type`.
|
|
1045
1057
|
# @return [self]
|
|
1046
|
-
# @raise [
|
|
1058
|
+
# @raise [CArray::DataTypeError] for a boolean array.
|
|
1047
1059
|
def abs!; end
|
|
1048
1060
|
|
|
1049
1061
|
# @overload abs_i!
|
|
@@ -1093,7 +1105,7 @@ class CArray
|
|
|
1093
1105
|
# Applies {#arg} to `self` in place, keeping `self`'s
|
|
1094
1106
|
# `data_type`.
|
|
1095
1107
|
# @return [self]
|
|
1096
|
-
# @raise [
|
|
1108
|
+
# @raise [CArray::DataTypeError] for an integer or boolean array, whose
|
|
1097
1109
|
# `data_type` cannot hold the widened result -- {#arg} promotes it
|
|
1098
1110
|
# instead of raising.
|
|
1099
1111
|
def arg!; end
|
|
@@ -9,9 +9,11 @@ class CArray
|
|
|
9
9
|
# Returns the median of `self` along `axis` (or over all elements
|
|
10
10
|
# when `axis` is `nil`).
|
|
11
11
|
#
|
|
12
|
-
# Numeric arrays return a `Float
|
|
13
|
-
#
|
|
14
|
-
#
|
|
12
|
+
# Numeric arrays return a `Float`. A `CA_OBJECT` array answers in
|
|
13
|
+
# its elements' own terms: the middle element itself, or the
|
|
14
|
+
# average of two as `(lo + hi) * (1/2)`, so an Integer, Rational or
|
|
15
|
+
# BigDecimal median is exact (`CA_OBJECT([1, 2]).median` is `3/2`).
|
|
16
|
+
# Fixlen arrays raise, since no numeric midpoint is defined.
|
|
15
17
|
#
|
|
16
18
|
# An even number of elements has no middle one, only the average of
|
|
17
19
|
# two -- so an object array whose elements cannot be averaged (a
|
|
@@ -64,9 +66,11 @@ class CArray
|
|
|
64
66
|
# so only when the requested `p` actually falls between two
|
|
65
67
|
# elements (`percentile(50)` of five Strings still answers).
|
|
66
68
|
#
|
|
67
|
-
# Numeric arrays produce `Float` results
|
|
68
|
-
#
|
|
69
|
-
#
|
|
69
|
+
# Numeric arrays produce `Float` results. A `CA_OBJECT` array
|
|
70
|
+
# answers in its elements' own terms: a pick (`:lower`, `:higher`,
|
|
71
|
+
# `:nearest`) is the element itself, and `:linear` / `:midpoint`
|
|
72
|
+
# use the elements' arithmetic with an exact Rational weight, so an
|
|
73
|
+
# exact element gives an exact answer. Fixlen arrays raise.
|
|
70
74
|
#
|
|
71
75
|
# Masking, `min_count`, `fill_value`, and `keep_axis` follow the
|
|
72
76
|
# same rules as {#median}.
|