carray 3.0.2 → 3.0.4
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 +568 -0
- data/README.md +6 -6
- data/carray.gemspec +1 -1
- data/ext/ca_axis_descriptor.h +27 -24
- data/ext/ca_axis_dispatch.c +220 -0
- data/ext/ca_axis_group.c +201 -123
- data/ext/ca_binop_dispatch.c +46 -52
- data/ext/ca_binop_dispatch.h +1 -1
- data/ext/ca_categorical_iterator.c +249 -183
- data/ext/ca_compare.c +7 -12
- data/ext/ca_for_buffer.h +21 -68
- data/ext/ca_group_iter.c +38 -23
- data/ext/ca_kernel_iterator.c +1765 -2076
- data/ext/ca_kernel_iterator.h +584 -566
- data/ext/ca_monop_dispatch.c +86 -63
- data/ext/ca_monop_dispatch.h +5 -0
- data/ext/ca_obj_array.c +223 -56
- data/ext/ca_obj_bincmp.c +172 -138
- data/ext/ca_obj_binop.c +116 -230
- data/ext/ca_obj_bitarray.c +40 -26
- data/ext/ca_obj_bitfield.c +100 -68
- data/ext/ca_obj_block.c +19 -9
- data/ext/ca_obj_byte_swap.c +45 -46
- data/ext/ca_obj_const_string.c +269 -44
- data/ext/ca_obj_face.c +612 -89
- data/ext/ca_obj_face.h +111 -47
- data/ext/ca_obj_fake.c +36 -79
- data/ext/ca_obj_farray.c +7 -3
- data/ext/ca_obj_field.c +33 -8
- data/ext/ca_obj_fixlen_string.c +23 -24
- data/ext/ca_obj_grid.c +541 -210
- data/ext/ca_obj_meld.c +331 -111
- data/ext/ca_obj_moncmp.c +80 -65
- data/ext/ca_obj_monop.c +177 -149
- data/ext/ca_obj_object.c +664 -248
- data/ext/ca_obj_record.c +63 -23
- data/ext/ca_obj_reduce.c +18 -16
- data/ext/ca_obj_refer.c +140 -58
- data/ext/ca_obj_remap.c +85 -24
- data/ext/ca_obj_repeat.c +24 -9
- data/ext/ca_obj_roll.c +121 -16
- data/ext/ca_obj_select.c +61 -58
- data/ext/ca_obj_select_axis.c +73 -107
- data/ext/ca_obj_shift.c +32 -102
- data/ext/ca_obj_stack.c +372 -122
- data/ext/ca_obj_stride.c +348 -140
- data/ext/ca_obj_string.c +88 -22
- data/ext/ca_obj_tile.c +38 -21
- data/ext/ca_obj_time.c +45 -31
- data/ext/ca_obj_timedelta.c +43 -29
- data/ext/ca_obj_transpose.c +17 -6
- data/ext/ca_obj_triop.c +125 -141
- data/ext/ca_obj_window.c +330 -44
- 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 +104 -81
- 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 +542 -0
- data/ext/carray.h +241 -92
- data/ext/carray_access.c +608 -276
- data/ext/carray_address_basis.c +494 -97
- data/ext/carray_attribute.c +129 -4
- data/ext/carray_bincount.c +39 -7
- data/ext/carray_broadcast.c +56 -19
- data/ext/carray_build_flags.h +1 -1
- data/ext/carray_call_cfunc.c +108 -28
- data/ext/carray_cast.c +1576 -223
- data/ext/carray_cast_func.rb +77 -24
- data/ext/carray_class.c +4 -3
- data/ext/carray_conversion.c +208 -75
- data/ext/carray_copy.c +82 -24
- data/ext/carray_core.c +646 -162
- data/ext/carray_count.c +171 -88
- data/ext/carray_element.c +94 -60
- data/ext/carray_factorize.c +670 -324
- data/ext/carray_generate.c +260 -83
- data/ext/carray_histogram.c +209 -106
- data/ext/carray_hold.c +14 -16
- data/ext/carray_index_classifier.c +422 -243
- data/ext/carray_internal.h +692 -3
- data/ext/carray_kernels_bincmp.c +7 -0
- data/ext/carray_kernels_binop.c +487 -120
- data/ext/carray_kernels_init.c +653 -50
- data/ext/carray_kernels_moncmp.c +15 -8
- data/ext/carray_kernels_monop.c +99 -43
- data/ext/carray_kernels_reduce_aggregate.c +3925 -6112
- data/ext/carray_kernels_reduce_boolean.c +112 -36
- data/ext/carray_kernels_reduce_cumulative.c +2127 -6903
- data/ext/carray_kernels_reduce_extreme.c +3032 -2892
- data/ext/carray_kernels_reduce_variance.c +439 -500
- data/ext/carray_kernels_scan.c +1097 -488
- data/ext/carray_kernels_search.c +3787 -2176
- data/ext/carray_kernels_sort.c +1200 -920
- data/ext/carray_kernels_triop.c +479 -7
- data/ext/carray_key_windows.c +216 -0
- data/ext/carray_lazy.c +967 -153
- data/ext/carray_loop.c +81 -65
- data/ext/carray_mask.c +910 -324
- data/ext/carray_math_kernel.h +1 -0
- data/ext/carray_median_percentile.c +299 -100
- data/ext/carray_memory_view.c +872 -758
- data/ext/carray_operator.c +1171 -364
- data/ext/carray_order.c +505 -133
- data/ext/carray_partition.c +112 -65
- data/ext/carray_random.c +327 -239
- data/ext/carray_round.c +273 -0
- data/ext/carray_scatter.c +346 -78
- data/ext/carray_segment.c +257 -0
- data/ext/carray_slab.c +249 -86
- data/ext/carray_sort.c +224 -227
- data/ext/carray_sort_kernel.c +8 -1
- data/ext/carray_struct.c +118 -39
- data/ext/carray_test.c +193 -69
- data/ext/carray_time_text.c +1182 -0
- data/ext/carray_undef.c +4 -0
- data/ext/carray_utils.c +579 -113
- data/ext/extconf.rb +27 -2
- data/ext/mk_call_cfunc.rb +19 -4
- data/ext/mk_pow5_table.rb +35 -0
- data/ext/mkkernel.rb +1202 -1014
- data/ext/ruby_carray.c +17 -5
- data/ext/version.h +4 -4
- data/ext/version.rb +4 -2
- data/lib/carray/attribute.rb +160 -17
- data/lib/carray/autoload_carray.rb +23 -27
- data/lib/carray/autoload_method_extension.rb +20 -5
- data/lib/carray/axis_group.rb +360 -63
- data/lib/carray/basics.rb +162 -28
- data/lib/carray/bincount_nd.rb +18 -2
- data/lib/carray/block_iterator.rb +231 -58
- data/lib/carray/boolean_reduce.rb +34 -42
- data/lib/carray/categorical.rb +242 -52
- data/lib/carray/categorical_iterator.rb +437 -827
- data/lib/carray/complex.rb +41 -34
- data/lib/carray/conditional.rb +150 -14
- data/lib/carray/const_string.rb +59 -4
- data/lib/carray/construct.rb +15 -11
- data/lib/carray/data_type_extension.rb +1 -0
- data/lib/carray/distance_limit.rb +77 -0
- data/lib/carray/fixlen_string.rb +7 -1
- data/lib/carray/frame/column_verbs.rb +70 -0
- data/lib/carray/frame/concat.rb +157 -6
- data/lib/carray/frame/convert.rb +82 -7
- data/lib/carray/frame/csv_parser.rb +688 -87
- data/lib/carray/frame/describe.rb +80 -0
- data/lib/carray/frame/frame.rb +369 -45
- data/lib/carray/frame/group.rb +631 -90
- data/lib/carray/frame/io.rb +506 -79
- data/lib/carray/frame/join.rb +411 -62
- data/lib/carray/frame/records.rb +116 -19
- data/lib/carray/frame/reshape.rb +455 -0
- data/lib/carray/frame/sort.rb +30 -18
- data/lib/carray/frame/verbs.rb +868 -61
- data/lib/carray/frame/windows.rb +117 -0
- data/lib/carray/frame.rb +4 -0
- data/lib/carray/fuse_source.rb +118 -2
- data/lib/carray/fusion.rb +257 -42
- data/lib/carray/histogram.rb +6 -1
- data/lib/carray/inspect.rb +54 -13
- data/lib/carray/iterator.rb +99 -9
- data/lib/carray/key_windows.rb +620 -0
- data/lib/carray/lazy.rb +216 -193
- data/lib/carray/mask_gap_fill.rb +112 -92
- data/lib/carray/math.rb +32 -19
- data/lib/carray/meld_reduce.rb +52 -21
- data/lib/carray/methods/align_addr.rb +8 -4
- data/lib/carray/methods/bin.rb +26 -18
- data/lib/carray/methods/bincount.rb +18 -2
- data/lib/carray/methods/bit_string.rb +15 -4
- data/lib/carray/methods/choose.rb +16 -3
- data/lib/carray/methods/composition.rb +18 -10
- data/lib/carray/methods/factorize.rb +2 -2
- data/lib/carray/methods/gather_nd.rb +25 -5
- data/lib/carray/methods/insert_block.rb +9 -14
- data/lib/carray/methods/is_between.rb +59 -0
- data/lib/carray/methods/is_in.rb +140 -10
- data/lib/carray/methods/join.rb +2 -7
- data/lib/carray/methods/lag.rb +49 -0
- data/lib/carray/methods/locate_addr.rb +182 -45
- data/lib/carray/methods/mode.rb +18 -1
- data/lib/carray/methods/nunique.rb +11 -6
- 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/methods/value_counts.rb +4 -11
- data/lib/carray/record_order.rb +208 -0
- data/lib/carray/rng.rb +3 -0
- data/lib/carray/runtime.rb +65 -17
- data/lib/carray/segment_iterator.rb +1221 -0
- data/lib/carray/serialize.rb +214 -30
- data/lib/carray/slab_iterator.rb +101 -27
- data/lib/carray/stack.rb +10 -4
- data/lib/carray/string.rb +105 -5
- data/lib/carray/string_operation_extension.rb +12 -4
- data/lib/carray/struct.rb +137 -58
- data/lib/carray/struct_builder.rb +124 -17
- data/lib/carray/time.rb +1222 -186
- data/lib/carray/window_iterator.rb +242 -81
- data/lib/carray.rb +9 -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 +5 -1
- data/yard-stubs/ca_obj_grid.rb +21 -10
- data/yard-stubs/ca_obj_refer.rb +5 -4
- data/yard-stubs/ca_obj_roll.rb +2 -3
- data/yard-stubs/ca_obj_shift.rb +5 -1
- data/yard-stubs/ca_obj_stride.rb +10 -7
- data/yard-stubs/ca_obj_tile.rb +1 -1
- data/yard-stubs/ca_obj_transpose.rb +1 -1
- data/yard-stubs/ca_obj_window.rb +9 -5
- data/yard-stubs/carray_access.rb +11 -5
- data/yard-stubs/carray_attribute.rb +0 -5
- data/yard-stubs/carray_broadcast.rb +1 -1
- data/yard-stubs/carray_cast.rb +88 -43
- data/yard-stubs/carray_conversion.rb +15 -2
- data/yard-stubs/carray_copy.rb +12 -5
- data/yard-stubs/carray_core.rb +3 -3
- data/yard-stubs/carray_count.rb +9 -0
- data/yard-stubs/carray_element.rb +10 -4
- data/yard-stubs/carray_generate.rb +21 -1
- data/yard-stubs/carray_lazy.rb +5 -1
- data/yard-stubs/carray_loop.rb +4 -1
- data/yard-stubs/carray_mask.rb +60 -12
- data/yard-stubs/carray_math.rb +52 -14
- data/yard-stubs/carray_median_percentile.rb +15 -8
- data/yard-stubs/carray_memory_view.rb +40 -23
- data/yard-stubs/carray_order.rb +61 -29
- data/yard-stubs/carray_random.rb +13 -4
- data/yard-stubs/carray_scatter.rb +21 -9
- data/yard-stubs/carray_segment.rb +72 -0
- data/yard-stubs/carray_slab.rb +10 -2
- data/yard-stubs/carray_sort.rb +49 -8
- data/yard-stubs/carray_test.rb +15 -3
- data/yard-stubs/carray_utils.rb +0 -26
- metadata +19 -5
- data/ext/ca_for_each_element.h +0 -239
- data/ext/carray_kernels_map.c +0 -3467
- data/lib/carray/arrow_tensor.rb +0 -401
- data/lib/carray/table.rb +0 -108
|
@@ -19,24 +19,35 @@ class CArray
|
|
|
19
19
|
# of the returned array.
|
|
20
20
|
#
|
|
21
21
|
# `range` may be an integer (a single bit — the resulting view has
|
|
22
|
-
# `data_type :boolean`) or a `Range` covering the bit positions.
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
# `
|
|
28
|
-
# is
|
|
22
|
+
# `data_type :boolean`) or a `Range` covering the bit positions. A
|
|
23
|
+
# negative bit or range end counts from the last bit of the cell.
|
|
24
|
+
# A field is read with one 8-byte load from the byte it starts in, so
|
|
25
|
+
# it may not reach more than 64 bits past the start of that byte.
|
|
26
|
+
# `type` is the integer type the field is read as. A signed type
|
|
27
|
+
# (`:int8` .. `:int64`) reads the field's top bit as its sign: the
|
|
28
|
+
# 3-bit field `0b101` is 5 as `:uint8` and -3 as `:int8`. A type
|
|
29
|
+
# wider than the field only widens the value. Without `type`, the
|
|
30
|
+
# narrowest unsigned type that holds the field is used: 1 bit →
|
|
31
|
+
# `:boolean`, 2..8 → `:uint8`, 9..16 → `:uint16`, 17..32 → `:uint32`,
|
|
32
|
+
# 33..64 → `:uint64`. A write keeps the low bits of the value that
|
|
33
|
+
# fit the field, signed or not (-3 into a 3-bit field is `0b101`).
|
|
29
34
|
#
|
|
30
35
|
# @overload bitfield(range, type = nil)
|
|
31
36
|
# @param range [Integer, Range] bit position (single bit) or bit
|
|
32
37
|
# range within one parent cell.
|
|
33
|
-
# @param type [Symbol, nil]
|
|
38
|
+
# @param type [Symbol, Integer, nil] the integer type the field is
|
|
39
|
+
# read as, or `nil` for the narrowest unsigned type.
|
|
34
40
|
# @return [CABitfield]
|
|
35
41
|
# @raise [IndexError] when `range` extends past the parent's bit
|
|
36
|
-
# width, when the range has a step != 1,
|
|
37
|
-
# is outside `1..64
|
|
38
|
-
#
|
|
39
|
-
#
|
|
42
|
+
# width, when the range descends or has a step != 1, when the bit length
|
|
43
|
+
# is outside `1..64`, or when the field reaches more than 64 bits
|
|
44
|
+
# past the start of its first byte.
|
|
45
|
+
# @raise [CArray::DataTypeError] when `self` is an object or complex
|
|
46
|
+
# array.
|
|
47
|
+
# @raise [ArgumentError] when `type` is narrower than the field
|
|
48
|
+
# (or `:boolean` for a field of more than one bit).
|
|
49
|
+
# @raise [CArray::DataTypeError] when `type` is not an integer type
|
|
50
|
+
# or `:boolean`.
|
|
40
51
|
def bitfield(range, type = nil); end
|
|
41
52
|
|
|
42
53
|
# @!endgroup
|
data/yard-stubs/ca_obj_fake.rb
CHANGED
|
@@ -22,7 +22,7 @@ class CArray
|
|
|
22
22
|
# reinterpret the storage on purpose. A Numeric Face, whose surface *is*
|
|
23
23
|
# its storage, is unaffected.
|
|
24
24
|
# @param data_type [Symbol, Integer, Class, String]
|
|
25
|
-
# @param bytes [Integer] element byte size for `:fixlen
|
|
25
|
+
# @param bytes [Integer] element byte size for `:fixlen` (1 or more).
|
|
26
26
|
# @return [CAFake]
|
|
27
27
|
# @raise [TypeError] when `self` is a Face and the request would read its
|
|
28
28
|
# storage under another type.
|
data/yard-stubs/ca_obj_field.rb
CHANGED
|
@@ -18,8 +18,12 @@ class CArray
|
|
|
18
18
|
# @param bytes [Integer, nil] element size; required for `:fixlen`,
|
|
19
19
|
# inferred otherwise.
|
|
20
20
|
# @return [CAField]
|
|
21
|
-
# @raise [
|
|
21
|
+
# @raise [ArgumentError] when `offset` is negative or the
|
|
22
22
|
# `offset + bytes` window falls outside one parent record.
|
|
23
|
+
# @raise [CArray::DataTypeError] when a field of a numeric array is
|
|
24
|
+
# asked for as `:boolean` (a boolean cell holds 0 or 1; compare
|
|
25
|
+
# instead, `ne(0)`). A record's boolean member is a field of a
|
|
26
|
+
# fixlen array and is allowed.
|
|
23
27
|
# @overload field(offset, template)
|
|
24
28
|
# Returns a CARefer over a {CAField}: takes `template.elements *
|
|
25
29
|
# template.bytes` bytes at `offset` and exposes them with
|
data/yard-stubs/ca_obj_grid.rb
CHANGED
|
@@ -14,22 +14,33 @@ class CArray
|
|
|
14
14
|
# number of indices selected for that axis.
|
|
15
15
|
#
|
|
16
16
|
# Each selector is one of:
|
|
17
|
-
# - `nil` — the whole axis, in order.
|
|
18
|
-
# - an integer `Range` — a contiguous sub-range along the axis.
|
|
19
17
|
# - a `CArray` of integer indices — gather exactly those parent
|
|
20
18
|
# indices (arbitrary order; duplicates produce duplicated cells).
|
|
21
|
-
# - a boolean `CArray` — the indices where it is
|
|
19
|
+
# - a boolean `CArray` as long as its axis — the indices where it is
|
|
20
|
+
# true.
|
|
21
|
+
# - any other key, read as the indexer reads it in a block
|
|
22
|
+
# reference: `nil` the whole axis, a `Range` /
|
|
23
|
+
# `ArithmeticSequence` / Array form its run (a range ending before
|
|
24
|
+
# it starts reads backwards), the rubber marker (`false` / `:~`)
|
|
25
|
+
# as many whole axes as it stands for, and an `Integer` one cell,
|
|
26
|
+
# whose axis is then dropped from the view.
|
|
22
27
|
#
|
|
23
|
-
# A masked index `CArray` selects
|
|
24
|
-
# view
|
|
28
|
+
# A masked cell of an index `CArray` selects nothing: the position
|
|
29
|
+
# stays in the view and reads as masked (`UNDEF`), and a write to it
|
|
30
|
+
# is dropped, as in {#project} and {#gather_nd}. A masked cell of a
|
|
31
|
+
# boolean selector selects nothing either, so it adds no position.
|
|
32
|
+
# The view is writable; scattering back to overlapping cells (from
|
|
25
33
|
# duplicate indices) is last-write-wins.
|
|
26
34
|
#
|
|
27
|
-
# @param selectors [Array<nil, Range, CArray>] one
|
|
35
|
+
# @param selectors [Array<nil, Integer, Range, Array, CArray>] one
|
|
36
|
+
# selector per axis.
|
|
28
37
|
# @return [CArray] the grid view.
|
|
29
|
-
# @raise [ArgumentError] when more selectors than `ndim` are given
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
#
|
|
38
|
+
# @raise [ArgumentError] when more selectors than `ndim` are given, a
|
|
39
|
+
# boolean selector is not as long as its axis, or a masked index
|
|
40
|
+
# selects from a view of a value array or a mask array (which can
|
|
41
|
+
# not carry the mask that shows it).
|
|
42
|
+
# @raise [IndexError] when a selected index is out of range, or a
|
|
43
|
+
# selector is not a position (a String, a Float with a fraction).
|
|
33
44
|
def grid(*selectors); end
|
|
34
45
|
# @!endgroup
|
|
35
46
|
end
|
data/yard-stubs/ca_obj_refer.rb
CHANGED
|
@@ -32,11 +32,12 @@ class CArray
|
|
|
32
32
|
# defaults to `self.bytes`.
|
|
33
33
|
# @param offset [Integer] offset in parent elements.
|
|
34
34
|
# @return [CARefer, CARecord]
|
|
35
|
-
# @raise [
|
|
35
|
+
# @raise [ArgumentError] when the byte widths do not divide
|
|
36
36
|
# evenly, when `offset` is negative, or when the requested
|
|
37
37
|
# view extends past the parent's data.
|
|
38
|
-
# @raise [
|
|
39
|
-
# with a non-object `data_type
|
|
38
|
+
# @raise [CArray::DataTypeError] when reinterpreting a CA_OBJECT parent
|
|
39
|
+
# with a non-object `data_type`, or a parent of another data type as
|
|
40
|
+
# `:boolean` (a boolean cell holds 0 or 1; compare instead, `ne(0)`).
|
|
40
41
|
def refer(*argv); end
|
|
41
42
|
|
|
42
43
|
# Returns a view of `self` with the requested shape. Element
|
|
@@ -54,7 +55,7 @@ class CArray
|
|
|
54
55
|
# @return [CArray] the reshape view.
|
|
55
56
|
# @raise [ArgumentError] when the number of dims exceeds
|
|
56
57
|
# `CA_RANK_MAX`.
|
|
57
|
-
# @raise [
|
|
58
|
+
# @raise [ArgumentError] when the product does not equal
|
|
58
59
|
# `self.elements` (with no placeholder), when the placeholder
|
|
59
60
|
# cannot be inferred, when more than one placeholder is
|
|
60
61
|
# given, or when a `nil` has no matching source axis.
|
data/yard-stubs/ca_obj_roll.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
4
|
|
|
5
5
|
# Cyclic-shift view of the parent. Same shape as the parent; each
|
|
6
|
-
# axis `k` is rotated by `shift[k]` cells (modulo `parent.
|
|
6
|
+
# axis `k` is rotated by `shift[k]` cells (modulo `parent.shape[k]`).
|
|
7
7
|
# All parent cells alias through the view exactly once, so writes
|
|
8
8
|
# through the view reach the parent.
|
|
9
9
|
#
|
|
@@ -25,7 +25,7 @@ class CArray
|
|
|
25
25
|
# `shifts[k]` along each axis `k`. Positive shifts move cell `i`
|
|
26
26
|
# of the parent to position `i + shift`; negative shifts move it
|
|
27
27
|
# the other way. Each `shift[k]` is normalised into
|
|
28
|
-
# `[0, self.
|
|
28
|
+
# `[0, self.shape[k])` before use, so any integer is accepted.
|
|
29
29
|
#
|
|
30
30
|
# Fewer args than `ndim` treats the missing axes as `shift = 0`.
|
|
31
31
|
# More args than `ndim` raises `ArgumentError`.
|
|
@@ -38,7 +38,6 @@ class CArray
|
|
|
38
38
|
# shorter than `ndim` (missing axes default to `0`).
|
|
39
39
|
# @return [CARoll]
|
|
40
40
|
# @raise [ArgumentError] when more than `ndim` shifts are given.
|
|
41
|
-
# @raise [IndexError] when any parent dimension is non-positive.
|
|
42
41
|
def roll(*shifts); end
|
|
43
42
|
|
|
44
43
|
# @!endgroup
|
data/yard-stubs/ca_obj_shift.rb
CHANGED
|
@@ -22,7 +22,11 @@ class CArray
|
|
|
22
22
|
# parent to position `i + shift`). Out-of-range cells take `fill_value`
|
|
23
23
|
# (default `0`); passing `fill_value: UNDEF` masks them instead of
|
|
24
24
|
# filling. In-range cells alias the parent, so writes through the view
|
|
25
|
-
# reach the parent.
|
|
25
|
+
# reach the parent. A write to an out-of-range cell has no cell to land
|
|
26
|
+
# in and is discarded; under `fill_value: UNDEF` such a cell stays masked
|
|
27
|
+
# through `unmask` too. The default `0` is the storage value, so for a time
|
|
28
|
+
# array it is 1970-01-01, for a CAString `""`; `ts - ts.shift(1,
|
|
29
|
+
# fill_value: UNDEF)` leaves the first difference missing.
|
|
26
30
|
#
|
|
27
31
|
# The in-place idiom is `ca[] = ca.shift(...)`; there is no `shift!`.
|
|
28
32
|
# For a cyclic (wrap-around) shift use {#roll}, which returns a `CARoll`
|
data/yard-stubs/ca_obj_stride.rb
CHANGED
|
@@ -20,7 +20,8 @@ class CArray
|
|
|
20
20
|
|
|
21
21
|
# Returns a {CAStride} view of `self` with the given byte strides and
|
|
22
22
|
# starting byte offset, inheriting the receiver's data type and element
|
|
23
|
-
# size. Memory is shared with the receiver
|
|
23
|
+
# size. Memory is shared with the receiver, and a Face receiver stays the
|
|
24
|
+
# Face.
|
|
24
25
|
#
|
|
25
26
|
# This is a low-level escape hatch: the strides and offset are **not**
|
|
26
27
|
# bounds-checked against the receiver's memory, so a combination that
|
|
@@ -46,7 +47,8 @@ class CArray
|
|
|
46
47
|
#
|
|
47
48
|
# Truncate mode: a trailing partial window is dropped rather than padded.
|
|
48
49
|
# Memory is shared with the parent, and because windows overlap, one parent
|
|
49
|
-
# cell is visible from several positions of the view.
|
|
50
|
+
# cell is visible from several positions of the view. A Face parent stays
|
|
51
|
+
# the Face.
|
|
50
52
|
#
|
|
51
53
|
# Reduce over the trailing `ndim` axes for a rolling statistic.
|
|
52
54
|
#
|
|
@@ -70,7 +72,7 @@ class CArray
|
|
|
70
72
|
# The window axes are inserted before the trailing axes, so the result rank
|
|
71
73
|
# is `ndim + S`. With `S == ndim` there are no trailing axes and the
|
|
72
74
|
# result is identical to {#sliding_windows}. Truncate mode; memory is
|
|
73
|
-
# shared with the parent.
|
|
75
|
+
# shared with the parent, and a Face parent stays the Face.
|
|
74
76
|
#
|
|
75
77
|
# @overload unfold(window, step: nil)
|
|
76
78
|
# @overload unfold(w0, w1, ..., step: nil)
|
|
@@ -93,13 +95,14 @@ class CArray
|
|
|
93
95
|
# tile size: nothing is truncated and no cell is aliased twice. Reduce over
|
|
94
96
|
# the trailing `ndim` axes (e.g. `v.mean(-1, -2)` for a 2-D parent) for
|
|
95
97
|
# per-tile statistics such as pooling or block-wise aggregation. Memory is
|
|
96
|
-
# shared with the parent.
|
|
98
|
+
# shared with the parent, and a Face parent stays the Face.
|
|
97
99
|
#
|
|
98
100
|
# @overload block_view(block)
|
|
99
101
|
# @overload block_view(b0, b1, ...)
|
|
100
102
|
# @param block [Array<Integer>, Integer] tile length per axis, one per
|
|
101
103
|
# dimension, as an Array or as variadic arguments.
|
|
102
|
-
# @return [CAStride] of rank `2 * ndim
|
|
104
|
+
# @return [CAStride] of rank `2 * ndim` (the parent's Face class when
|
|
105
|
+
# the parent is a Face).
|
|
103
106
|
# @raise [ArgumentError] when the tile count does not equal `ndim`, when
|
|
104
107
|
# a tile length is not positive, when an axis is not divisible by its
|
|
105
108
|
# tile length, or when `2 * ndim` exceeds `CA_RANK_MAX`.
|
|
@@ -148,8 +151,8 @@ class CArray
|
|
|
148
151
|
# @overload flip(axis)
|
|
149
152
|
# @overload flip(a0, a1, ...)
|
|
150
153
|
# @overload flip([a0, a1, ...])
|
|
151
|
-
# @param axis [Array<Integer>, Integer] axes to reverse; negative
|
|
152
|
-
# count from the last axis.
|
|
154
|
+
# @param axis [Array<Integer>, Integer, nil] axes to reverse; negative
|
|
155
|
+
# indices count from the last axis. `flip(nil)` is the same as `flip`.
|
|
153
156
|
# @return [CAStride]
|
|
154
157
|
# @raise [ArgumentError] when an axis is out of range or repeated.
|
|
155
158
|
def flip(*axis); end
|
data/yard-stubs/ca_obj_tile.rb
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# Stubs for methods defined in ext/ca_obj_tile.c.
|
|
3
3
|
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
4
|
|
|
5
|
-
# Tiled repetition view. Output shape is `parent.
|
|
5
|
+
# Tiled repetition view. Output shape is `parent.shape[k] * reps[k]`
|
|
6
6
|
# along each axis; every tile is a full-parent alias, so writes to
|
|
7
7
|
# overlapping cells are last-write-wins.
|
|
8
8
|
class CATile < CAView
|
|
@@ -29,7 +29,7 @@ class CArray
|
|
|
29
29
|
# @param imap [Array<Integer>] permutation of `0 ... ndim`.
|
|
30
30
|
# @return [CATranspose]
|
|
31
31
|
# @raise [ArgumentError] when `imap.length != ndim`.
|
|
32
|
-
# @raise [
|
|
32
|
+
# @raise [ArgumentError] when an entry of `imap` is out of range
|
|
33
33
|
# or duplicated.
|
|
34
34
|
def transpose(*imap); end
|
|
35
35
|
|
data/yard-stubs/ca_obj_window.rb
CHANGED
|
@@ -21,7 +21,8 @@ class CArray
|
|
|
21
21
|
# parent alias it, so writes through the view reach the parent; cells
|
|
22
22
|
# outside take `fill_value` (default `0`), and `fill_value: UNDEF` masks
|
|
23
23
|
# them instead. A write that lands outside the parent has no cell to land
|
|
24
|
-
# in and is discarded
|
|
24
|
+
# in and is discarded; under `fill_value: UNDEF` such a cell stays masked
|
|
25
|
+
# through `unmask` too.
|
|
25
26
|
#
|
|
26
27
|
# A range wider than its axis is how an array is **padded**: `a.window(-1..
|
|
27
28
|
# a.dim0, -1..a.dim1)` puts a one-cell border all round, which is NumPy's
|
|
@@ -35,8 +36,9 @@ class CArray
|
|
|
35
36
|
# @overload window(*ranges, fill_value: 0, bounds: "fill")
|
|
36
37
|
# @param ranges [Array<Range, Integer>] one range per axis; the count
|
|
37
38
|
# must equal `self.ndim`.
|
|
38
|
-
# @param fill_value [Object] value given to out-of-range cells
|
|
39
|
-
#
|
|
39
|
+
# @param fill_value [Object] value given to out-of-range cells, written
|
|
40
|
+
# as a store writes it (a Time for a time array; a CAString's default
|
|
41
|
+
# is `""`); `UNDEF` masks them instead.
|
|
40
42
|
# @param bounds [String, Symbol] what an out-of-range index means; a
|
|
41
43
|
# Symbol says the same as the String, matching {#windows}: `"fill"`
|
|
42
44
|
# (default) uses `fill_value`, `"nearest"` clamps to the edge cell,
|
|
@@ -48,9 +50,11 @@ class CArray
|
|
|
48
50
|
# is passed (the block form was removed in 3.0), or when `bounds` is
|
|
49
51
|
# `"periodic"` / `"reflect"` (both removed in 3.0; use {#roll} for a
|
|
50
52
|
# cyclic shift).
|
|
51
|
-
# @raise [
|
|
52
|
-
# @raise [RuntimeError] when `bounds` conflicts with `fill_value: UNDEF`,
|
|
53
|
+
# @raise [ArgumentError] when `bounds` conflicts with `fill_value: UNDEF`,
|
|
53
54
|
# or when `bounds` is not a recognised value.
|
|
55
|
+
# @raise [IndexError] when `bounds` is `"strict"` and a range reaches
|
|
56
|
+
# outside `self`, or `"ruby"` and a range reaches past the end or
|
|
57
|
+
# before the first cell counted from the end.
|
|
54
58
|
def window(*ranges, fill_value: 0, bounds: "fill"); end
|
|
55
59
|
|
|
56
60
|
# @!endgroup
|
data/yard-stubs/carray_access.rb
CHANGED
|
@@ -20,7 +20,9 @@ class CArray
|
|
|
20
20
|
# - Range — a contiguous (or stepped, via a stepped Range) sub-range.
|
|
21
21
|
# - boolean CArray — masked selection along that axis.
|
|
22
22
|
# - Integer CArray — fancy gather (index array); shape follows the
|
|
23
|
-
# index array.
|
|
23
|
+
# index array. A masked cell of the index array selects nothing and
|
|
24
|
+
# keeps its place: it reads as masked, and a write to it has no cell
|
|
25
|
+
# to land in and is discarded.
|
|
24
26
|
# - `:_` — newaxis: insert a size-1 axis at this position.
|
|
25
27
|
# - `:%` — repeat / tiling sugar.
|
|
26
28
|
# - `:>` — slab axis: wrap the result in a `CASlabIterator`.
|
|
@@ -45,6 +47,9 @@ class CArray
|
|
|
45
47
|
#
|
|
46
48
|
# Assignment through a slab iterator (`:>`) is not supported — use a
|
|
47
49
|
# block index (e.g. `ca[range, nil] = val`) or `each_slab`.
|
|
50
|
+
#
|
|
51
|
+
# A store that raises may leave part of the destination written: its
|
|
52
|
+
# values and its mask after the raise are not specified.
|
|
48
53
|
# @param index [Array<Integer, Range, nil, CArray, Symbol>] one entry
|
|
49
54
|
# per axis (or a single flat address).
|
|
50
55
|
# @param value [Object, Array, CArray] the value(s) to store, or
|
|
@@ -82,9 +87,10 @@ class CArray
|
|
|
82
87
|
# Array of length `self.ndim`, so `i, j = ca.addr2index(x)` unpacks
|
|
83
88
|
# uniformly for scalar and vector inputs.
|
|
84
89
|
# @param addr [Integer, CArray] a flat address in `0...elements`,
|
|
85
|
-
# or a CArray of such addresses (arbitrary shape).
|
|
90
|
+
# or a CArray of such addresses (arbitrary shape). A negative
|
|
91
|
+
# address counts from the end.
|
|
86
92
|
# @return [Array<Integer>, Array<CArray>] one entry per axis.
|
|
87
|
-
# @raise [
|
|
93
|
+
# @raise [IndexError] when any `addr` is out of range.
|
|
88
94
|
def addr2index(addr); end
|
|
89
95
|
|
|
90
96
|
# @overload index2addr(*index)
|
|
@@ -106,8 +112,8 @@ class CArray
|
|
|
106
112
|
# @param addr [Integer, CArray] a flat address or a CArray of them.
|
|
107
113
|
# @param shape [Array<Integer>] the row-major shape defining the grid.
|
|
108
114
|
# @return [Array<Integer>, Array<CArray>] one entry per axis.
|
|
109
|
-
# @raise [
|
|
110
|
-
#
|
|
115
|
+
# @raise [IndexError] when any `addr` is out of range.
|
|
116
|
+
# @raise [ArgumentError] when `shape:` is missing.
|
|
111
117
|
def self.addr2index(addr, shape:); end
|
|
112
118
|
|
|
113
119
|
# @overload index2addr(*index, shape:)
|
|
@@ -35,11 +35,6 @@ class CArray
|
|
|
35
35
|
# @return [Integer]
|
|
36
36
|
def ndim; end
|
|
37
37
|
|
|
38
|
-
# @overload rank
|
|
39
|
-
# @deprecated Use {#ndim}.
|
|
40
|
-
# @return [Integer]
|
|
41
|
-
def rank; end
|
|
42
|
-
|
|
43
38
|
# @overload bytes
|
|
44
39
|
# Returns the byte size of one element. Equals
|
|
45
40
|
# `CArray.sizeof(data_type)` for numeric types; for fixed-length
|
|
@@ -23,7 +23,7 @@ class CArray
|
|
|
23
23
|
# @param shape [Array<Integer>] target shape, with
|
|
24
24
|
# `length >= self.ndim`.
|
|
25
25
|
# @return [CArray]
|
|
26
|
-
# @raise [
|
|
26
|
+
# @raise [ArgumentError] if a source axis cannot be paired with a
|
|
27
27
|
# target axis (cross-ndim expansion is intentionally strict —
|
|
28
28
|
# see {CArray.broadcast} for the explicit-`:_` axis
|
|
29
29
|
# declaration form).
|
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,25 @@ 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.
|
|
107
|
+
#
|
|
108
|
+
# From a float or complex array to an integer type, a NaN cell (in
|
|
109
|
+
# either part) becomes UNDEF. A finite value outside the integer type
|
|
110
|
+
# is converted as the machine's C converts it.
|
|
85
111
|
# @param data_type [Symbol, Integer, Class, String] target element type.
|
|
86
112
|
# @param bytes [Integer, nil] element width in bytes, required for
|
|
87
113
|
# `:fixlen`.
|
|
@@ -187,6 +213,10 @@ class CArray
|
|
|
187
213
|
# target. Use {#to_type} instead for parse-with-mask (an unparseable
|
|
188
214
|
# cell becomes UNDEF). The `CA_<TYPE>(obj)` construction shorthands
|
|
189
215
|
# take this same non-masking path.
|
|
216
|
+
# From a float or complex array to an integer type, reading a NaN cell
|
|
217
|
+
# raises FloatDomainError, as storing NaN into an integer array does; a
|
|
218
|
+
# masked NaN cell (left by {#mask_invalid}) reads UNDEF. {#to_type}
|
|
219
|
+
# makes a NaN cell UNDEF instead.
|
|
190
220
|
# A Face refuses: reinterpreting its storage would hand back the
|
|
191
221
|
# bytes its surface exists to hide (the serial instead of the time, the
|
|
192
222
|
# descriptor instead of the string), and no view decodes a surface. Take
|
|
@@ -198,6 +228,8 @@ class CArray
|
|
|
198
228
|
# @return [CAFake]
|
|
199
229
|
# @raise [TypeError] when `self` is a Face and the request would read its
|
|
200
230
|
# storage under another type.
|
|
231
|
+
# @raise [FloatDomainError] when a NaN cell that is not masked is read
|
|
232
|
+
# into an integer type.
|
|
201
233
|
def as_type(data_type, bytes: nil); end
|
|
202
234
|
|
|
203
235
|
# @overload as_boolean
|
|
@@ -337,7 +369,7 @@ class CArray
|
|
|
337
369
|
# primitive the binary operators use.
|
|
338
370
|
# @param other [CArray, Object] the second operand.
|
|
339
371
|
# @return [Array(CArray, CArray)]
|
|
340
|
-
# @raise [
|
|
372
|
+
# @raise [CArray::DataTypeError] when the two data_types have no common type.
|
|
341
373
|
def cast_with(other); end
|
|
342
374
|
|
|
343
375
|
# `coerce` is documented with its definition in ext/carray_operator.c;
|
|
@@ -376,10 +408,9 @@ class CArray
|
|
|
376
408
|
# `nil` keeps the source type (or `:object` when `other` is `nil`).
|
|
377
409
|
# @return [CArray]
|
|
378
410
|
# @raise [RuntimeError] when `other` is read-only, its MemoryView is
|
|
379
|
-
# read-only, its `to_ca` refuses `writable: true
|
|
380
|
-
#
|
|
381
|
-
#
|
|
382
|
-
# CArray.
|
|
411
|
+
# read-only, or its `to_ca` refuses `writable: true`.
|
|
412
|
+
# @raise [TypeError] when `other` cannot be wrapped as a CArray, or
|
|
413
|
+
# `other#to_ca` returns something that is not a CArray.
|
|
383
414
|
# @raise [ArgumentError] when `other#to_ca` does not accept `writable:`.
|
|
384
415
|
# @raise [TypeError] when `other` is a Face and `data_type` differs from
|
|
385
416
|
# its surface type.
|
|
@@ -445,20 +476,30 @@ class CArray
|
|
|
445
476
|
# data_type inferred (3 -> `:int64`, 3.14 -> `:float64`,
|
|
446
477
|
# 1+2i -> `:cmplx128`, ...)
|
|
447
478
|
#
|
|
448
|
-
#
|
|
449
|
-
#
|
|
479
|
+
# The arrays and data_type representations promote together. A
|
|
480
|
+
# scalar (a value, or a CScalar) then joins their type the way it
|
|
481
|
+
# does beside an operator: one of the same kind takes that type
|
|
482
|
+
# (`result_type(float32_array, 0.1)` is `:float32`, as
|
|
483
|
+
# `float32_array + 0.1` is), one of another kind promotes
|
|
484
|
+
# (`result_type(int32_array, 1.5)` is `:float64`), and an Integer
|
|
485
|
+
# that does not fit an integer type takes `:int64`. With no array or
|
|
486
|
+
# data_type representation, every argument promotes by its own type.
|
|
487
|
+
#
|
|
488
|
+
# Integer args are interpreted as *values*, not as data_type codes:
|
|
450
489
|
# `result_type(8)` returns `:int64` because the value 8 is an Integer,
|
|
451
490
|
# not because a data_type code equals 8. Use `result_type(:int64)` or
|
|
452
491
|
# `result_type(CA_INT64)` to be explicit about data_type intent.
|
|
453
492
|
# @param args [Array<CArray, Symbol, String, Class, Object>] operands.
|
|
454
493
|
# @return [Symbol]
|
|
455
494
|
# @raise [ArgumentError] when called with no arguments.
|
|
456
|
-
# @raise [
|
|
495
|
+
# @raise [CArray::DataTypeError] when two inputs are mutually incompatible
|
|
457
496
|
# (e.g. `:object` with `:fixlen`).
|
|
458
497
|
# @example
|
|
459
498
|
# CArray.result_type(:int32, :float32) #=> :float32
|
|
460
499
|
# CArray.result_type(3, 3.14) #=> :float64
|
|
461
500
|
# CArray.result_type(true, 3) #=> :int64
|
|
501
|
+
# CArray.result_type(CA_INT8([1]), 1) #=> :int8
|
|
502
|
+
# CArray.result_type(CA_INT8([1]), 300) #=> :int64
|
|
462
503
|
def self.result_type(*args); end
|
|
463
504
|
|
|
464
505
|
# @overload promote_list(list, data_type: nil)
|
|
@@ -471,8 +512,12 @@ class CArray
|
|
|
471
512
|
# elements passes through (CAStack lifts it), unless the class is not
|
|
472
513
|
# portable (CAConstString) or the elements disagree on state
|
|
473
514
|
# (CATime with different units); a list of primitives is
|
|
474
|
-
# promoted via {.result_type} + {.wrap_readonly}
|
|
475
|
-
#
|
|
515
|
+
# promoted via {.result_type} + {.wrap_readonly}, except that a list
|
|
516
|
+
# mixing signed and unsigned integers takes a type that holds both
|
|
517
|
+
# (`uint8` with `int8` is `int16`, 64-bit pairs are `:object`), and an
|
|
518
|
+
# integer of 32 bits or more beside `float32` takes `float64`, since
|
|
519
|
+
# the arrays are joined value for value; a mix of Face and non-Face,
|
|
520
|
+
# or heterogeneous Face classes, is rejected.
|
|
476
521
|
#
|
|
477
522
|
# With an explicit primitive `data_type`: all-primitive elements are
|
|
478
523
|
# 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,14 +67,20 @@ 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
|
|
66
77
|
# `String` of the exact size, or any object responding to
|
|
67
|
-
# `read(n, buf = nil)`.
|
|
78
|
+
# `read(n, buf = nil)`. Into a boolean array, a non-zero byte is
|
|
79
|
+
# read as 1 (true).
|
|
68
80
|
# @param io [String, IO, #read]
|
|
69
81
|
# @return [self]
|
|
70
|
-
# @raise [RuntimeError] on short read
|
|
82
|
+
# @raise [RuntimeError] on a short read.
|
|
83
|
+
# @raise [ArgumentError] when a String source is not the array's size.
|
|
71
84
|
# @raise [CArray::DataTypeError] if `self.data_type` is
|
|
72
85
|
# `:object`.
|
|
73
86
|
def load_binary(io); end
|