carray 3.0.0 → 3.0.1
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 +2 -1
- data/CHANGELOG.md +325 -3
- data/{NEWS.md → CHANGELOG.v1.md} +1 -1
- data/README.md +32 -32
- data/carray.gemspec +12 -8
- data/ext/ca_axis_group.c +55 -19
- data/ext/ca_binop_dispatch.c +5 -6
- data/ext/ca_binop_dispatch.h +0 -7
- data/ext/ca_categorical_iterator.c +13 -13
- data/ext/ca_for_each_element.h +6 -8
- data/ext/ca_group_iter.c +1 -1
- data/ext/ca_kernel_iterator.c +69 -23
- data/ext/ca_kernel_iterator.h +3 -10
- data/ext/ca_obj_bincmp.c +57 -27
- data/ext/ca_obj_binop.c +86 -30
- data/ext/ca_obj_const_string.c +3 -1
- data/ext/ca_obj_face.c +80 -0
- data/ext/ca_obj_face.h +33 -1
- data/ext/ca_obj_fake.c +11 -0
- data/ext/ca_obj_fixlen_string.c +3 -1
- data/ext/ca_obj_grid.c +11 -3
- data/ext/ca_obj_meld.c +13 -8
- data/ext/ca_obj_moncmp.c +33 -14
- data/ext/ca_obj_monop.c +19 -7
- data/ext/ca_obj_object.c +99 -4
- data/ext/ca_obj_record.c +3 -1
- data/ext/ca_obj_refer.c +30 -6
- data/ext/ca_obj_roll.c +13 -5
- data/ext/ca_obj_select_axis.c +16 -6
- data/ext/ca_obj_shift.c +3 -3
- data/ext/ca_obj_stride.c +106 -23
- data/ext/ca_obj_string.c +3 -1
- data/ext/ca_obj_tile.c +13 -5
- data/ext/ca_obj_time.c +3 -1
- data/ext/ca_obj_timedelta.c +3 -1
- data/ext/ca_obj_transpose.c +1 -1
- data/ext/ca_obj_triop.c +62 -23
- data/ext/ca_obj_window.c +86 -17
- data/ext/ca_op_cmplx64.h +123 -0
- data/ext/ca_op_ipower.c +0 -3
- data/ext/ca_sort_kernels.h +5 -5
- data/ext/ca_sweep_engine.c +78 -35
- data/ext/ca_sweep_engine.h +13 -4
- data/ext/ca_transform_common.c +7 -0
- data/ext/carray.h +127 -130
- data/ext/carray_access.c +56 -34
- data/ext/carray_bincount.c +8 -8
- data/ext/carray_broadcast.c +99 -6
- data/ext/carray_build_flags.h +3 -0
- data/ext/carray_call_cfunc.c +1491 -0
- data/ext/carray_call_cfunc.h +153 -0
- data/ext/carray_cast.c +69 -31
- data/ext/carray_conversion.c +22 -22
- data/ext/carray_copy.c +12 -2
- data/ext/carray_core.c +57 -10
- data/ext/carray_count.c +1 -1
- data/ext/carray_element.c +7 -7
- data/ext/carray_factorize.c +28 -28
- data/ext/carray_hold.c +1 -1
- data/ext/carray_index_classifier.c +7 -21
- data/ext/carray_internal.h +19 -3
- data/ext/carray_kernels_bincmp.c +1 -0
- data/ext/carray_kernels_binop.c +320 -298
- data/ext/carray_kernels_init.c +1095 -0
- data/ext/carray_kernels_map.c +1 -0
- data/ext/carray_kernels_moncmp.c +1 -0
- data/ext/carray_kernels_monop.c +412 -411
- data/ext/carray_kernels_reduce_aggregate.c +88 -87
- data/ext/carray_kernels_reduce_boolean.c +1 -0
- data/ext/carray_kernels_reduce_cumulative.c +54 -53
- data/ext/carray_kernels_reduce_extreme.c +51 -50
- data/ext/carray_kernels_reduce_variance.c +1 -0
- data/ext/carray_kernels_scan.c +1 -0
- data/ext/carray_kernels_search.c +93 -92
- data/ext/carray_kernels_sort.c +1 -0
- data/ext/carray_kernels_triop.c +1 -0
- data/ext/carray_lazy.c +175 -5
- data/ext/carray_mask.c +6 -5
- data/ext/carray_median_percentile.c +1 -1
- data/ext/carray_memory_view.c +46 -21
- data/ext/carray_operator.c +46 -49
- data/ext/carray_partition.c +4 -4
- data/ext/carray_random.c +7 -7
- data/ext/carray_scatter.c +1 -1
- data/ext/carray_sort.c +3 -3
- data/ext/carray_sort_kernel.c +10 -10
- data/ext/carray_test.c +1 -1
- data/ext/extconf.rb +18 -0
- data/ext/mk_call_cfunc.rb +243 -52
- data/ext/mkkernel.rb +354 -100
- data/ext/ruby_carray.c +18 -16
- data/ext/version.h +4 -4
- data/lib/carray/autoload_carray.rb +19 -0
- data/lib/carray/autoload_method_extension.rb +2 -1
- data/lib/carray/axis_group.rb +7 -7
- data/lib/carray/basics.rb +59 -59
- data/lib/carray/bincount_nd.rb +12 -12
- data/lib/carray/block_iterator.rb +24 -14
- data/lib/carray/categorical.rb +4 -4
- data/lib/carray/categorical_iterator.rb +98 -76
- data/lib/carray/conditional.rb +14 -14
- data/lib/carray/construct.rb +21 -0
- data/lib/carray/core_extensions.rb +62 -5
- data/lib/carray/data_type_extension.rb +18 -1
- data/lib/carray/frame/concat.rb +3 -3
- data/lib/carray/frame/convert.rb +1 -1
- data/lib/carray/frame/frame.rb +4 -11
- data/lib/carray/frame/io.rb +159 -2
- data/lib/carray/frame/sort.rb +1 -1
- data/lib/carray/frame/verbs.rb +18 -1
- data/lib/carray/fuse_source.rb +123 -0
- data/lib/carray/fusion.rb +218 -0
- data/lib/carray/histogram.rb +16 -16
- data/lib/carray/inspect.rb +1 -7
- data/lib/carray/iterator.rb +4 -3
- data/lib/carray/lazy.rb +125 -73
- data/lib/carray/meld_reduce.rb +2 -2
- data/lib/carray/methods/align_addr.rb +1 -1
- data/lib/carray/methods/composition.rb +1 -1
- data/lib/carray/methods/is_in.rb +12 -12
- data/lib/carray/methods/locate_addr.rb +6 -1
- data/lib/carray/methods/mask_duplicates.rb +1 -1
- data/lib/carray/methods/meshgrid.rb +4 -5
- data/lib/carray/methods/mode.rb +2 -2
- data/lib/carray/methods/nunique.rb +1 -1
- data/lib/carray/methods/snap.rb +7 -2
- data/lib/carray/methods/unique.rb +3 -3
- data/lib/carray/methods/value_counts.rb +2 -2
- data/lib/carray/runtime.rb +0 -19
- data/lib/carray/slab_iterator.rb +20 -7
- data/lib/carray/string_operation_extension.rb +5 -5
- data/lib/carray/time.rb +890 -491
- data/lib/carray/window_iterator.rb +285 -13
- data/lib/carray.rb +5 -5
- data/yard-stubs/ca_obj_array.rb +385 -0
- data/yard-stubs/ca_obj_bitarray.rb +38 -0
- data/yard-stubs/ca_obj_bitfield.rb +43 -0
- data/yard-stubs/ca_obj_block.rb +73 -0
- data/yard-stubs/ca_obj_byte_swap.rb +56 -0
- data/yard-stubs/ca_obj_fake.rb +31 -0
- data/yard-stubs/ca_obj_farray.rb +32 -0
- data/yard-stubs/ca_obj_field.rb +45 -0
- data/yard-stubs/ca_obj_grid.rb +35 -0
- data/yard-stubs/ca_obj_refer.rb +72 -0
- data/yard-stubs/ca_obj_roll.rb +45 -0
- data/yard-stubs/ca_obj_shift.rb +43 -0
- data/yard-stubs/ca_obj_stride.rb +181 -0
- data/yard-stubs/ca_obj_tile.rb +29 -0
- data/yard-stubs/ca_obj_transpose.rb +40 -0
- data/yard-stubs/ca_obj_window.rb +49 -0
- data/yard-stubs/carray_access.rb +131 -0
- data/yard-stubs/carray_attribute.rb +246 -0
- data/yard-stubs/carray_broadcast.rb +37 -0
- data/yard-stubs/carray_cast.rb +489 -0
- data/yard-stubs/carray_class.rb +65 -0
- data/yard-stubs/carray_conversion.rb +76 -0
- data/yard-stubs/carray_copy.rb +79 -0
- data/yard-stubs/carray_core.rb +114 -0
- data/yard-stubs/carray_count.rb +79 -0
- data/yard-stubs/carray_element.rb +108 -0
- data/yard-stubs/carray_generate.rb +66 -0
- data/yard-stubs/carray_lazy.rb +23 -0
- data/yard-stubs/carray_loop.rb +140 -0
- data/yard-stubs/carray_mask.rb +259 -0
- data/yard-stubs/carray_math.rb +132 -0
- data/yard-stubs/carray_mathfunc.rb +45 -0
- data/yard-stubs/carray_median_percentile.rb +89 -0
- data/yard-stubs/carray_memory_view.rb +163 -0
- data/yard-stubs/carray_order.rb +312 -0
- data/yard-stubs/carray_random.rb +89 -0
- data/yard-stubs/carray_scatter.rb +106 -0
- data/yard-stubs/carray_slab.rb +57 -0
- data/yard-stubs/carray_sort.rb +163 -0
- data/yard-stubs/carray_test.rb +85 -0
- data/yard-stubs/carray_undef.rb +64 -0
- data/yard-stubs/carray_utils.rb +97 -0
- data/yard-stubs/ruby_carray.rb +193 -0
- metadata +59 -10
- data/ext/ca_obj_unbound_repeat.c +0 -496
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for CArray#field defined in ext/ca_obj_field.c. The CAField
|
|
3
|
+
# class shell lives in yard-stubs/ruby_carray.rb.
|
|
4
|
+
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
5
|
+
|
|
6
|
+
class CArray
|
|
7
|
+
# @!group Views
|
|
8
|
+
|
|
9
|
+
# @overload field(offset, data_type, bytes: nil)
|
|
10
|
+
# Returns a {CAField} view of one field of a fixlen-record `self`.
|
|
11
|
+
# The view has the same shape as `self`; each element is the
|
|
12
|
+
# `bytes`-wide slice of element type `data_type` at byte `offset`
|
|
13
|
+
# within the corresponding record. No data is copied; writes go
|
|
14
|
+
# through to `self`.
|
|
15
|
+
# @param offset [Integer] byte offset of the field within one record.
|
|
16
|
+
# @param data_type [Symbol, Integer] element type symbol or constant.
|
|
17
|
+
# `:object` is not allowed.
|
|
18
|
+
# @param bytes [Integer, nil] element size; required for `:fixlen`,
|
|
19
|
+
# inferred otherwise.
|
|
20
|
+
# @return [CAField]
|
|
21
|
+
# @raise [RuntimeError] when `offset` is negative or the
|
|
22
|
+
# `offset + bytes` window falls outside one parent record.
|
|
23
|
+
# @overload field(offset, template)
|
|
24
|
+
# Returns a CARefer over a {CAField}: takes `template.elements *
|
|
25
|
+
# template.bytes` bytes at `offset` and exposes them with
|
|
26
|
+
# `template`'s element type and trailing shape.
|
|
27
|
+
# @param offset [Integer]
|
|
28
|
+
# @param template [CArray] element type and trailing shape donor.
|
|
29
|
+
# @return [CArray]
|
|
30
|
+
# @overload field(offset, data_class)
|
|
31
|
+
# Returns a `CARecord` wrapping a {CAField} so the result carries
|
|
32
|
+
# `data_class`'s encode/decode dispatch.
|
|
33
|
+
# @param offset [Integer]
|
|
34
|
+
# @param data_class [Class] e.g. a CAStruct subclass.
|
|
35
|
+
# @return [CArray]
|
|
36
|
+
# @overload field(name)
|
|
37
|
+
# Returns the field named `name`. Delegates to the parent's Face
|
|
38
|
+
# layer (`rb_ca_face_field`); resolution depends on the record
|
|
39
|
+
# schema attached to `self`.
|
|
40
|
+
# @param name [Symbol, String]
|
|
41
|
+
# @return [CArray]
|
|
42
|
+
def field(*); end
|
|
43
|
+
|
|
44
|
+
# @!endgroup
|
|
45
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for methods defined in ext/ca_obj_grid.c.
|
|
3
|
+
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
#
|
|
5
|
+
# CAGrid itself is an internal (:nodoc:) view class; only the CArray#grid
|
|
6
|
+
# entry point is user-facing.
|
|
7
|
+
|
|
8
|
+
class CArray
|
|
9
|
+
# @!group Views
|
|
10
|
+
# @overload grid(*selectors)
|
|
11
|
+
# Returns a coordinate-selected view of `self`: one selector per
|
|
12
|
+
# axis picks a set of parent indices along that axis, and the view
|
|
13
|
+
# is their Cartesian product. The output size along axis `k` is the
|
|
14
|
+
# number of indices selected for that axis.
|
|
15
|
+
#
|
|
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
|
+
# - a `CArray` of integer indices — gather exactly those parent
|
|
20
|
+
# indices (arbitrary order; duplicates produce duplicated cells).
|
|
21
|
+
# - a boolean `CArray` — the indices where it is true.
|
|
22
|
+
#
|
|
23
|
+
# A masked index `CArray` selects only its not-masked cells. The
|
|
24
|
+
# view is writable; scattering back to overlapping cells (from
|
|
25
|
+
# duplicate indices) is last-write-wins.
|
|
26
|
+
#
|
|
27
|
+
# @param selectors [Array<nil, Range, CArray>] one selector per axis.
|
|
28
|
+
# @return [CArray] the grid view.
|
|
29
|
+
# @raise [ArgumentError] when more selectors than `ndim` are given.
|
|
30
|
+
# @raise [IndexError] when a selected index is out of range.
|
|
31
|
+
# @raise [RuntimeError] when a selector is a plain Ruby `Array`
|
|
32
|
+
# (not supported; pass a CArray of indices instead).
|
|
33
|
+
def grid(*selectors); end
|
|
34
|
+
# @!endgroup
|
|
35
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for CArray#refer, #reshape, #flatten defined in ext/ca_obj_refer.c.
|
|
3
|
+
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
#
|
|
5
|
+
# The CARefer class shell lives in yard-stubs/ruby_carray.rb.
|
|
6
|
+
|
|
7
|
+
class CArray
|
|
8
|
+
# @!group Views
|
|
9
|
+
|
|
10
|
+
# Returns a {CARefer} view of `self` — a strided reinterpretation
|
|
11
|
+
# of the parent's memory. With no arguments the view has the same
|
|
12
|
+
# `data_type`, shape and `bytes` as `self`; the second form
|
|
13
|
+
# accepts a different `data_type` (or a data_class), and optional
|
|
14
|
+
# `bytes:` / `offset:` keywords so the view exposes the parent's
|
|
15
|
+
# bytes as elements of a different width.
|
|
16
|
+
#
|
|
17
|
+
# `bytes:` must divide `parent.bytes` (or vice versa) so element
|
|
18
|
+
# boundaries align. `offset:` is measured in parent elements.
|
|
19
|
+
# The total byte extent of the view must fit inside `self`.
|
|
20
|
+
#
|
|
21
|
+
# When `data_type` is a data_class, the result is wrapped in a
|
|
22
|
+
# `CARecord` so field projection continues to work.
|
|
23
|
+
#
|
|
24
|
+
# @overload refer
|
|
25
|
+
# @return [CARefer] a same-shape same-width alias of `self`.
|
|
26
|
+
# @overload refer(data_type, dim = nil, bytes: nil, offset: 0)
|
|
27
|
+
# @param data_type [Integer, Symbol, Class] target data type or
|
|
28
|
+
# a data_class.
|
|
29
|
+
# @param dim [Array<Integer>, nil] target shape; `nil` reuses
|
|
30
|
+
# `self.shape` (only valid when the byte width is unchanged).
|
|
31
|
+
# @param bytes [Integer, nil] target byte width per element;
|
|
32
|
+
# defaults to `self.bytes`.
|
|
33
|
+
# @param offset [Integer] offset in parent elements.
|
|
34
|
+
# @return [CARefer, CARecord]
|
|
35
|
+
# @raise [RuntimeError] when the byte widths do not divide
|
|
36
|
+
# evenly, when `offset` is negative, or when the requested
|
|
37
|
+
# view extends past the parent's data.
|
|
38
|
+
# @raise [RuntimeError] when reinterpreting a CA_OBJECT parent
|
|
39
|
+
# with a non-object `data_type`.
|
|
40
|
+
def refer(*argv); end
|
|
41
|
+
|
|
42
|
+
# Returns a view of `self` with the requested shape. Element
|
|
43
|
+
# count must match (`-1` or `:~` may stand in for one axis, whose
|
|
44
|
+
# size is inferred); `nil` copies the corresponding axis from
|
|
45
|
+
# `self`. When the reshape can be expressed as strides over
|
|
46
|
+
# `self`'s deepest non-CAStride ancestor, the result is a
|
|
47
|
+
# {CAStride}; otherwise a {CARefer}.
|
|
48
|
+
#
|
|
49
|
+
# @overload reshape(*newdim)
|
|
50
|
+
# @param newdim [Array<Integer, nil, Symbol>] target shape.
|
|
51
|
+
# Integers are axis sizes; `nil` copies from `self` in
|
|
52
|
+
# position order (mirrored from the end after the placeholder);
|
|
53
|
+
# `-1` or `:~` marks the auto-infer placeholder (at most one).
|
|
54
|
+
# @return [CArray] the reshape view.
|
|
55
|
+
# @raise [ArgumentError] when the number of dims exceeds
|
|
56
|
+
# `CA_RANK_MAX`.
|
|
57
|
+
# @raise [RuntimeError] when the product does not equal
|
|
58
|
+
# `self.elements` (with no placeholder), when the placeholder
|
|
59
|
+
# cannot be inferred, when more than one placeholder is
|
|
60
|
+
# given, or when a `nil` has no matching source axis.
|
|
61
|
+
def reshape(*newdim); end
|
|
62
|
+
|
|
63
|
+
# Returns a 1-D view of all cells in row-major order — a
|
|
64
|
+
# {CAStride} when the flatten reduces to pure strides over the
|
|
65
|
+
# deepest ancestor, otherwise a {CARefer}.
|
|
66
|
+
#
|
|
67
|
+
# @overload flatten
|
|
68
|
+
# @return [CArray] the 1-D view.
|
|
69
|
+
def flatten; end
|
|
70
|
+
|
|
71
|
+
# @!endgroup
|
|
72
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for CARoll and CArray#roll defined in ext/ca_obj_roll.c.
|
|
3
|
+
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
|
|
5
|
+
# Cyclic-shift view of the parent. Same shape as the parent; each
|
|
6
|
+
# axis `k` is rotated by `shift[k]` cells (modulo `parent.dim[k]`).
|
|
7
|
+
# All parent cells alias through the view exactly once, so writes
|
|
8
|
+
# through the view reach the parent.
|
|
9
|
+
#
|
|
10
|
+
# `CARoll` is a `typedef` of {CATile}: the class hierarchy places it
|
|
11
|
+
# under {CATile}, and the operation table is a copy of `ca_tile_func`
|
|
12
|
+
# with the shift-specific slots overridden.
|
|
13
|
+
class CARoll < CATile
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Mask companion of {CARoll}.
|
|
17
|
+
# @private
|
|
18
|
+
class CARollMask < CARoll
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class CArray
|
|
22
|
+
# @!group Views
|
|
23
|
+
|
|
24
|
+
# Returns a {CARoll} view of `self` cyclically shifted by
|
|
25
|
+
# `shifts[k]` along each axis `k`. Positive shifts move cell `i`
|
|
26
|
+
# of the parent to position `i + shift`; negative shifts move it
|
|
27
|
+
# the other way. Each `shift[k]` is normalised into
|
|
28
|
+
# `[0, self.dim[k])` before use, so any integer is accepted.
|
|
29
|
+
#
|
|
30
|
+
# Fewer args than `ndim` treats the missing axes as `shift = 0`.
|
|
31
|
+
# More args than `ndim` raises `ArgumentError`.
|
|
32
|
+
#
|
|
33
|
+
# The in-place idiom is `ca[] = ca.roll(...)`; there is no `roll!`.
|
|
34
|
+
# For a non-cyclic translation with a fill value use {#shift}.
|
|
35
|
+
#
|
|
36
|
+
# @overload roll(*shifts)
|
|
37
|
+
# @param shifts [Array<Integer>] one shift per axis; may be
|
|
38
|
+
# shorter than `ndim` (missing axes default to `0`).
|
|
39
|
+
# @return [CARoll]
|
|
40
|
+
# @raise [ArgumentError] when more than `ndim` shifts are given.
|
|
41
|
+
# @raise [IndexError] when any parent dimension is non-positive.
|
|
42
|
+
def roll(*shifts); end
|
|
43
|
+
|
|
44
|
+
# @!endgroup
|
|
45
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for CAShift and CArray#shift defined in ext/ca_obj_shift.c.
|
|
3
|
+
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
|
|
5
|
+
# Translated view of the parent along each axis. Pure `CAWindow`
|
|
6
|
+
# typedef: only the obj_type tag differs. No data is copied; in-range
|
|
7
|
+
# cells alias the parent, out-of-range cells take the fill value (or are
|
|
8
|
+
# masked).
|
|
9
|
+
class CAShift < CAWindow
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Mask companion of {CAShift}.
|
|
13
|
+
# @private
|
|
14
|
+
class CAShiftMask < CAShift
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class CArray
|
|
18
|
+
# @!group Views
|
|
19
|
+
|
|
20
|
+
# Returns a {CAShift} view of `self` translated by `shifts` along each
|
|
21
|
+
# axis (one shift per dimension; a positive shift moves cell `i` of the
|
|
22
|
+
# parent to position `i + shift`). Out-of-range cells take `fill_value`
|
|
23
|
+
# (default `0`); passing `fill_value: UNDEF` masks them instead of
|
|
24
|
+
# filling. In-range cells alias the parent, so writes through the view
|
|
25
|
+
# reach the parent.
|
|
26
|
+
#
|
|
27
|
+
# The in-place idiom is `ca[] = ca.shift(...)`; there is no `shift!`.
|
|
28
|
+
# For a cyclic (wrap-around) shift use {#roll}, which returns a `CARoll`
|
|
29
|
+
# view.
|
|
30
|
+
#
|
|
31
|
+
# @overload shift(*shifts, fill_value: 0)
|
|
32
|
+
# @param shifts [Array<Integer>] one shift per axis; the count must
|
|
33
|
+
# equal `self.ndim`.
|
|
34
|
+
# @param fill_value [Object] value written to out-of-range cells;
|
|
35
|
+
# `UNDEF` masks them instead.
|
|
36
|
+
# @return [CAShift]
|
|
37
|
+
# @raise [ArgumentError] when the number of shifts does not equal
|
|
38
|
+
# `ndim`, when the removed `:roll` option is given, or when a block
|
|
39
|
+
# is passed (the block form was removed in 3.0).
|
|
40
|
+
def shift(*shifts, fill_value: 0); end
|
|
41
|
+
|
|
42
|
+
# @!endgroup
|
|
43
|
+
end
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for CAStride and the CArray view constructors defined in
|
|
3
|
+
# ext/ca_obj_stride.c. See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
|
|
5
|
+
# Generic strided view of the parent: each cell is addressed as
|
|
6
|
+
# `base_offset + Σ idx[k] * strides[k]` bytes from the parent's buffer, with
|
|
7
|
+
# byte strides that may be negative or zero. That is enough to express axis
|
|
8
|
+
# permutation, reshape, stepped slicing and broadcasting, so most view
|
|
9
|
+
# classes are CAStride subclasses and inherit its behaviour unchanged.
|
|
10
|
+
class CAStride < CAView
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Mask companion of {CAStride}.
|
|
14
|
+
# @private
|
|
15
|
+
class CAStrideMask < CAStride
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
class CArray
|
|
19
|
+
# @!group Views
|
|
20
|
+
|
|
21
|
+
# Returns a {CAStride} view of `self` with the given byte strides and
|
|
22
|
+
# starting byte offset, inheriting the receiver's data type and element
|
|
23
|
+
# size. Memory is shared with the receiver.
|
|
24
|
+
#
|
|
25
|
+
# This is a low-level escape hatch: the strides and offset are **not**
|
|
26
|
+
# bounds-checked against the receiver's memory, so a combination that
|
|
27
|
+
# addresses outside it reads or writes past the buffer. Prefer the
|
|
28
|
+
# derived constructors ({#sliding_windows}, {#block_view}, {#flip},
|
|
29
|
+
# {#diagonal}) when one of them expresses the layout.
|
|
30
|
+
#
|
|
31
|
+
# @overload as_strided(shape:, strides:, offset: 0)
|
|
32
|
+
# @param shape [Array<Integer>] axis lengths.
|
|
33
|
+
# @param strides [Array<Integer>] byte stride per axis, same length as
|
|
34
|
+
# `shape`; negative values are allowed.
|
|
35
|
+
# @param offset [Integer] byte offset from the receiver's buffer to the
|
|
36
|
+
# `[0, ..., 0]` element.
|
|
37
|
+
# @return [CAStride]
|
|
38
|
+
# @raise [ArgumentError] when `shape:` or `strides:` is missing, when
|
|
39
|
+
# their lengths differ, or when the rank is 0 or above `CA_RANK_MAX`.
|
|
40
|
+
def as_strided(shape:, strides:, offset: 0); end
|
|
41
|
+
|
|
42
|
+
# Returns a {CAStride} view of overlapping windows over every axis. A
|
|
43
|
+
# parent of shape `[d0, ..., dN-1]` becomes a view of shape
|
|
44
|
+
# `[(d0-w0)/s0+1, ..., (dN-1-wN-1)/sN-1+1, w0, ..., wN-1]`, where `wi` is
|
|
45
|
+
# the window length on axis `i` and `si` the step.
|
|
46
|
+
#
|
|
47
|
+
# Truncate mode: a trailing partial window is dropped rather than padded.
|
|
48
|
+
# Memory is shared with the parent, and because windows overlap, one parent
|
|
49
|
+
# cell is visible from several positions of the view.
|
|
50
|
+
#
|
|
51
|
+
# Reduce over the trailing `ndim` axes for a rolling statistic.
|
|
52
|
+
#
|
|
53
|
+
# @overload sliding_windows(window, step: nil)
|
|
54
|
+
# @overload sliding_windows(w0, w1, ..., step: nil)
|
|
55
|
+
# @param window [Array<Integer>, Integer] window length per axis, one per
|
|
56
|
+
# dimension, as an Array or as variadic arguments.
|
|
57
|
+
# @param step [Array<Integer>, Integer, nil] stride between windows per
|
|
58
|
+
# axis; `nil` means 1 on every axis.
|
|
59
|
+
# @return [CAStride] of rank `2 * ndim`.
|
|
60
|
+
# @raise [ArgumentError] when the window count does not equal `ndim`,
|
|
61
|
+
# when a window or step is not positive, when a window is longer than
|
|
62
|
+
# its axis, or when `2 * ndim` exceeds `CA_RANK_MAX`.
|
|
63
|
+
def sliding_windows(*window, step: nil); end
|
|
64
|
+
|
|
65
|
+
# Returns a {CAStride} view of overlapping windows over the leading `S`
|
|
66
|
+
# axes, with the remaining `ndim - S` trailing axes riding along untouched
|
|
67
|
+
# at their original strides — {#sliding_windows} generalised to arrays that
|
|
68
|
+
# carry non-spatial dimensions such as channels.
|
|
69
|
+
#
|
|
70
|
+
# The window axes are inserted before the trailing axes, so the result rank
|
|
71
|
+
# is `ndim + S`. With `S == ndim` there are no trailing axes and the
|
|
72
|
+
# result is identical to {#sliding_windows}. Truncate mode; memory is
|
|
73
|
+
# shared with the parent.
|
|
74
|
+
#
|
|
75
|
+
# @overload unfold(window, step: nil)
|
|
76
|
+
# @overload unfold(w0, w1, ..., step: nil)
|
|
77
|
+
# @param window [Array<Integer>, Integer] window length for each of the
|
|
78
|
+
# leading axes; its size chooses how many axes are slid over.
|
|
79
|
+
# @param step [Array<Integer>, Integer, nil] stride between windows;
|
|
80
|
+
# `nil` means 1.
|
|
81
|
+
# @return [CAStride] of rank `ndim + window.size`.
|
|
82
|
+
# @raise [ArgumentError] when the window count is not between 1 and
|
|
83
|
+
# `ndim`, when a window or step is not positive, when a window is
|
|
84
|
+
# longer than its axis, or when `ndim + S` exceeds `CA_RANK_MAX`.
|
|
85
|
+
def unfold(*window, step: nil); end
|
|
86
|
+
|
|
87
|
+
# Returns a {CAStride} view of non-overlapping tiles. A parent of shape
|
|
88
|
+
# `[d0, ..., dN-1]` becomes a view of shape
|
|
89
|
+
# `[d0/b0, ..., dN-1/bN-1, b0, ..., bN-1]`, where `bi` is the tile length
|
|
90
|
+
# on axis `i`.
|
|
91
|
+
#
|
|
92
|
+
# Unlike {#sliding_windows} each parent dimension must divide evenly by its
|
|
93
|
+
# tile size: nothing is truncated and no cell is aliased twice. Reduce over
|
|
94
|
+
# the trailing `ndim` axes (e.g. `v.mean(-1, -2)` for a 2-D parent) for
|
|
95
|
+
# per-tile statistics such as pooling or block-wise aggregation. Memory is
|
|
96
|
+
# shared with the parent.
|
|
97
|
+
#
|
|
98
|
+
# @overload block_view(block)
|
|
99
|
+
# @overload block_view(b0, b1, ...)
|
|
100
|
+
# @param block [Array<Integer>, Integer] tile length per axis, one per
|
|
101
|
+
# dimension, as an Array or as variadic arguments.
|
|
102
|
+
# @return [CAStride] of rank `2 * ndim`.
|
|
103
|
+
# @raise [ArgumentError] when the tile count does not equal `ndim`, when
|
|
104
|
+
# a tile length is not positive, when an axis is not divisible by its
|
|
105
|
+
# tile length, or when `2 * ndim` exceeds `CA_RANK_MAX`.
|
|
106
|
+
def block_view(*block); end
|
|
107
|
+
|
|
108
|
+
# Returns a `CATranspose` view in which the given axes are moved to the
|
|
109
|
+
# front, in the order given, with the remaining axes following in their
|
|
110
|
+
# original order — a thin alias over `transposed` that names the intent
|
|
111
|
+
# "bring these axes to the front, keep the rest as the inner slice".
|
|
112
|
+
#
|
|
113
|
+
# @example
|
|
114
|
+
# a = CArray.float64(3, 4, 5).seq
|
|
115
|
+
# a.dim_view(0, 2) # shape [3, 5, 4]
|
|
116
|
+
# a.dim_view(1) # shape [4, 3, 5]
|
|
117
|
+
# a.dim_view(-1) # shape [5, 3, 4]
|
|
118
|
+
#
|
|
119
|
+
# @overload dim_view(axes)
|
|
120
|
+
# @overload dim_view(a0, a1, ...)
|
|
121
|
+
# @param axes [Array<Integer>, Integer] axes to bring to the front;
|
|
122
|
+
# negative indices count from the last axis.
|
|
123
|
+
# @return [CATranspose]
|
|
124
|
+
# @raise [ArgumentError] when no axis is given, when more axes are given
|
|
125
|
+
# than `ndim`, or when an axis is out of range or repeated.
|
|
126
|
+
def dim_view(*axes); end
|
|
127
|
+
|
|
128
|
+
# Returns a {CAStride} view with the listed axes reversed (a negative
|
|
129
|
+
# stride on each); with no argument every axis is reversed. Memory is
|
|
130
|
+
# shared with the parent, so writes through the view propagate.
|
|
131
|
+
#
|
|
132
|
+
# This is the named counterpart of the indexer form
|
|
133
|
+
# `ca[-1..0, nil, -1..0]` — both produce a true negative-stride view with
|
|
134
|
+
# no copy. Use `flip` when the axis list is parametric or when the named
|
|
135
|
+
# intent reads better than the slice form. There is no `flip!`; the
|
|
136
|
+
# in-place idiom is `ca[] = ca.flip`.
|
|
137
|
+
#
|
|
138
|
+
# `reverse` is an alias of `flip`.
|
|
139
|
+
#
|
|
140
|
+
# @example
|
|
141
|
+
# a = CArray.float64(4, 5).seq
|
|
142
|
+
# a.flip # every axis reversed
|
|
143
|
+
# a.flip(0) # row order reversed
|
|
144
|
+
# a.flip(-1) # same as a.flip(1)
|
|
145
|
+
# a.flip([0, 1]) # Array form
|
|
146
|
+
#
|
|
147
|
+
# @overload flip
|
|
148
|
+
# @overload flip(axis)
|
|
149
|
+
# @overload flip(a0, a1, ...)
|
|
150
|
+
# @overload flip([a0, a1, ...])
|
|
151
|
+
# @param axis [Array<Integer>, Integer] axes to reverse; negative indices
|
|
152
|
+
# count from the last axis.
|
|
153
|
+
# @return [CAStride]
|
|
154
|
+
# @raise [ArgumentError] when an axis is out of range or repeated.
|
|
155
|
+
def flip(*axis); end
|
|
156
|
+
|
|
157
|
+
# Returns a {CAStride} view of one diagonal of the parent. For a 2-D
|
|
158
|
+
# parent of shape `[m, n]` this is a 1-D view of length
|
|
159
|
+
# `min(m, n - offset)` for `offset >= 0`, or `min(m + offset, n)` for
|
|
160
|
+
# `offset < 0`.
|
|
161
|
+
#
|
|
162
|
+
# For a higher-rank parent, the two axes named by `axis:` collapse into a
|
|
163
|
+
# single diagonal axis appended at the **end** of the result, and the
|
|
164
|
+
# remaining axes keep their order in front. Memory is shared with the
|
|
165
|
+
# parent.
|
|
166
|
+
#
|
|
167
|
+
# @overload diagonal(offset = 0, axis: [0, 1])
|
|
168
|
+
# @param offset [Integer] signed shift from the main diagonal; positive
|
|
169
|
+
# selects a super-diagonal, negative a sub-diagonal. An offset larger
|
|
170
|
+
# than the relevant axis yields an empty view rather than an error.
|
|
171
|
+
# May be passed positionally or as `offset:`, but not both.
|
|
172
|
+
# @param axis [Array<Integer>] the two distinct axes to take the diagonal
|
|
173
|
+
# over; negative indices count from the last axis.
|
|
174
|
+
# @return [CAStride]
|
|
175
|
+
# @raise [ArgumentError] when the parent has fewer than two dimensions,
|
|
176
|
+
# when `offset` is given both positionally and as a keyword, or when
|
|
177
|
+
# `axis:` is not two distinct in-range axes.
|
|
178
|
+
def diagonal(offset = 0, axis: [0, 1]); end
|
|
179
|
+
|
|
180
|
+
# @!endgroup
|
|
181
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for methods defined in ext/ca_obj_tile.c.
|
|
3
|
+
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
|
|
5
|
+
# Tiled repetition view. Output shape is `parent.dim[k] * reps[k]`
|
|
6
|
+
# along each axis; every tile is a full-parent alias, so writes to
|
|
7
|
+
# overlapping cells are last-write-wins.
|
|
8
|
+
class CATile < CAView
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Mask companion of {CATile}.
|
|
12
|
+
# @private
|
|
13
|
+
class CATileMask < CATile
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class CArray
|
|
17
|
+
# @!group Views
|
|
18
|
+
# @overload tile(*reps)
|
|
19
|
+
# Returns a {CATile} view of `self` tiled `reps[k]` times along
|
|
20
|
+
# each axis `k`. Accepts either positional args
|
|
21
|
+
# (`a.tile(2, 3)`) or a single array (`a.tile([2, 3])`); the
|
|
22
|
+
# number of reps must equal `ndim`.
|
|
23
|
+
# @param reps [Array<Integer>] repetition count per axis.
|
|
24
|
+
# @return [CATile]
|
|
25
|
+
# @raise [ArgumentError] when the number of reps does not match `ndim`.
|
|
26
|
+
# @raise [IndexError] when any `reps[k]` is not positive.
|
|
27
|
+
def tile(*reps); end
|
|
28
|
+
# @!endgroup
|
|
29
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for CATranspose and CArray#transpose / #T defined in
|
|
3
|
+
# ext/ca_obj_transpose.c.
|
|
4
|
+
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
5
|
+
|
|
6
|
+
# Permuted-axis view of the parent. Pure `CAStride` typedef: only
|
|
7
|
+
# the dim / stride layout differs. No data is copied; writes go
|
|
8
|
+
# through to the parent.
|
|
9
|
+
class CATranspose < CAStride
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Mask companion of {CATranspose}.
|
|
13
|
+
# @private
|
|
14
|
+
class CATransposeMask < CATranspose
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class CArray
|
|
18
|
+
# @!group Views
|
|
19
|
+
|
|
20
|
+
# @overload transpose
|
|
21
|
+
# Returns a {CATranspose} view of `self` with the dimension order
|
|
22
|
+
# reversed (`view.shape[k] == self.shape[ndim-1-k]`).
|
|
23
|
+
# @return [CATranspose]
|
|
24
|
+
# @overload transpose(*imap)
|
|
25
|
+
# Returns a {CATranspose} view of `self` permuted by `imap`, a
|
|
26
|
+
# permutation of `0 ... self.ndim`. Element
|
|
27
|
+
# `view[i_0, ..., i_{n-1}]` aliases parent element with axis `k`
|
|
28
|
+
# sourced from `i` at position `imap[k]`.
|
|
29
|
+
# @param imap [Array<Integer>] permutation of `0 ... ndim`.
|
|
30
|
+
# @return [CATranspose]
|
|
31
|
+
# @raise [ArgumentError] when `imap.length != ndim`.
|
|
32
|
+
# @raise [RuntimeError] when an entry of `imap` is out of range
|
|
33
|
+
# or duplicated.
|
|
34
|
+
def transpose(*imap); end
|
|
35
|
+
|
|
36
|
+
# Alias of {#transpose}.
|
|
37
|
+
def T(*imap); end
|
|
38
|
+
|
|
39
|
+
# @!endgroup
|
|
40
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for CAWindow and CArray#window defined in ext/ca_obj_window.c.
|
|
3
|
+
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
|
|
5
|
+
# Sliding rectangular view of the parent whose cells may fall outside it.
|
|
6
|
+
# In-range cells alias the parent, out-of-range cells take the fill value
|
|
7
|
+
# (or are masked). {CAShift} is the same view expressed as a translation.
|
|
8
|
+
class CAWindow < CAView
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Mask companion of {CAWindow}.
|
|
12
|
+
# @private
|
|
13
|
+
class CAWindowMask < CAWindow
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class CArray
|
|
17
|
+
# @!group Views
|
|
18
|
+
|
|
19
|
+
# Returns a {CAWindow} view of `self` covering `ranges` — one range per
|
|
20
|
+
# axis, which may extend past either end of the parent. Cells inside the
|
|
21
|
+
# parent alias it, so writes through the view reach the parent; cells
|
|
22
|
+
# outside take `fill_value` (default `0`), and `fill_value: UNDEF` masks
|
|
23
|
+
# them instead.
|
|
24
|
+
#
|
|
25
|
+
# Only unit-step ranges are accepted, and each range must run forward, so
|
|
26
|
+
# the `0..-1` end-relative notation cannot be used here.
|
|
27
|
+
#
|
|
28
|
+
# @overload window(*ranges, fill_value: 0, bounds: "fill")
|
|
29
|
+
# @param ranges [Array<Range, Integer>] one range per axis; the count
|
|
30
|
+
# must equal `self.ndim`.
|
|
31
|
+
# @param fill_value [Object] value given to out-of-range cells; `UNDEF`
|
|
32
|
+
# masks them instead.
|
|
33
|
+
# @param bounds [String] what an out-of-range index means: `"fill"`
|
|
34
|
+
# (default) uses `fill_value`, `"nearest"` clamps to the edge cell,
|
|
35
|
+
# `"ruby"` reads negative indices from the far end, `"strict"` raises.
|
|
36
|
+
# `"mask"` masks the cell but warns — pass `fill_value: UNDEF` instead.
|
|
37
|
+
# @return [CAWindow]
|
|
38
|
+
# @raise [ArgumentError] when the number of ranges does not equal `ndim`,
|
|
39
|
+
# when a range has a step other than 1 or runs backwards, when a block
|
|
40
|
+
# is passed (the block form was removed in 3.0), or when `bounds` is
|
|
41
|
+
# `"periodic"` / `"reflect"` (both removed in 3.0; use {#roll} for a
|
|
42
|
+
# cyclic shift).
|
|
43
|
+
# @raise [IndexError] when a range selects zero cells.
|
|
44
|
+
# @raise [RuntimeError] when `bounds` conflicts with `fill_value: UNDEF`,
|
|
45
|
+
# or when `bounds` is not a recognised value.
|
|
46
|
+
def window(*ranges, fill_value: 0, bounds: "fill"); end
|
|
47
|
+
|
|
48
|
+
# @!endgroup
|
|
49
|
+
end
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for methods defined in ext/carray_access.c.
|
|
3
|
+
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
#
|
|
5
|
+
# The indexer surface (`[]` / `[]=`) is large; the per-form detail lives in
|
|
6
|
+
# the user guides (see the @see links) rather than being duplicated here.
|
|
7
|
+
|
|
8
|
+
class CArray
|
|
9
|
+
# @!group Indexing and slicing
|
|
10
|
+
|
|
11
|
+
# @overload [](*index)
|
|
12
|
+
# Returns a view of `self` (or a single element) selected by one
|
|
13
|
+
# `index` per axis. Every array-returning form is a view onto the
|
|
14
|
+
# original storage — writing through it reaches the source.
|
|
15
|
+
#
|
|
16
|
+
# Accepted per-axis index forms:
|
|
17
|
+
# - Integer — one position (negative counts from the end); an
|
|
18
|
+
# all-Integer index returns the single element (masked -> UNDEF).
|
|
19
|
+
# - `nil` — the whole axis.
|
|
20
|
+
# - Range — a contiguous (or stepped, via a stepped Range) sub-range.
|
|
21
|
+
# - boolean CArray — masked selection along that axis.
|
|
22
|
+
# - Integer CArray — fancy gather (index array); shape follows the
|
|
23
|
+
# index array.
|
|
24
|
+
# - `:_` — newaxis: insert a size-1 axis at this position.
|
|
25
|
+
# - `:*` / `:%` — repeat / tiling sugar.
|
|
26
|
+
# - `:>` — slab axis: wrap the result in a `CASlabIterator`.
|
|
27
|
+
# - a member name Symbol — project a struct field (see `CARecord`).
|
|
28
|
+
#
|
|
29
|
+
# A single flat Integer (fewer indices than `ndim`) addresses the
|
|
30
|
+
# array in row-major flat order.
|
|
31
|
+
# @param index [Array<Integer, Range, nil, CArray, Symbol>] one entry
|
|
32
|
+
# per axis (or a single flat address).
|
|
33
|
+
# @return [CArray, Object] a view for a slicing form, or the element
|
|
34
|
+
# value (or `UNDEF` if masked) for an all-scalar index.
|
|
35
|
+
# @raise [IndexError] on an out-of-range index or an unrecognised form.
|
|
36
|
+
# @see file:docs/drafts/02_indexing_and_slicing.md Indexing and slicing
|
|
37
|
+
# @see file:docs/drafts/16_indexer_reference.md Indexer reference
|
|
38
|
+
def [](*index); end
|
|
39
|
+
|
|
40
|
+
# @overload []=(*index, value)
|
|
41
|
+
# Sets the cells of `self` selected by `index` (same per-axis forms as
|
|
42
|
+
# {#[]}) to `value`. `value` may be a scalar (broadcast), an Array, or
|
|
43
|
+
# a CArray whose element count matches the selection; assigning `UNDEF`
|
|
44
|
+
# masks the selected cells.
|
|
45
|
+
#
|
|
46
|
+
# Assignment through a slab iterator (`:>`) is not supported — use a
|
|
47
|
+
# block index (e.g. `ca[range, nil] = val`) or `each_slab`.
|
|
48
|
+
# @param index [Array<Integer, Range, nil, CArray, Symbol>] one entry
|
|
49
|
+
# per axis (or a single flat address).
|
|
50
|
+
# @param value [Object, Array, CArray] the value(s) to store, or
|
|
51
|
+
# `UNDEF` to mask.
|
|
52
|
+
# @return [Object] `value`.
|
|
53
|
+
# @raise [IndexError] on an out-of-range index or an unsupported form.
|
|
54
|
+
# @see file:docs/drafts/16_indexer_reference.md Indexer reference
|
|
55
|
+
def []=(*index, value); end
|
|
56
|
+
|
|
57
|
+
# @!endgroup
|
|
58
|
+
|
|
59
|
+
# @!group Indexing and slicing
|
|
60
|
+
|
|
61
|
+
# @overload fill(value)
|
|
62
|
+
# Sets every element of `self` to `value` and clears any mask.
|
|
63
|
+
# @param value [Object] the fill value.
|
|
64
|
+
# @return [self]
|
|
65
|
+
def fill(value); end
|
|
66
|
+
|
|
67
|
+
# @overload fill_copy(value)
|
|
68
|
+
# Returns a copy of `self` with every element set to `value`.
|
|
69
|
+
# @param value [Object] the fill value.
|
|
70
|
+
# @return [CArray] the filled copy.
|
|
71
|
+
def fill_copy(value); end
|
|
72
|
+
|
|
73
|
+
# @!endgroup
|
|
74
|
+
|
|
75
|
+
# @!group Index and address conversion
|
|
76
|
+
|
|
77
|
+
# @overload addr2index(addr)
|
|
78
|
+
# Unravels a flat row-major address into per-axis indices, sized by
|
|
79
|
+
# `self.shape`. With an Integer `addr` returns N Integers; with a
|
|
80
|
+
# CArray of addresses returns N CArrays of the same shape as `addr`
|
|
81
|
+
# (mask propagated per cell). In both cases the return is a Ruby
|
|
82
|
+
# Array of length `self.ndim`, so `i, j = ca.addr2index(x)` unpacks
|
|
83
|
+
# uniformly for scalar and vector inputs.
|
|
84
|
+
# @param addr [Integer, CArray] a flat address in `0...elements`,
|
|
85
|
+
# or a CArray of such addresses (arbitrary shape).
|
|
86
|
+
# @return [Array<Integer>, Array<CArray>] one entry per axis.
|
|
87
|
+
# @raise [ArgumentError] when any `addr` is out of range.
|
|
88
|
+
def addr2index(addr); end
|
|
89
|
+
|
|
90
|
+
# @overload index2addr(*index)
|
|
91
|
+
# Folds per-axis indices into flat row-major address(es), using
|
|
92
|
+
# `self.shape`. With all-Integer indices returns a single Integer;
|
|
93
|
+
# when any index is a CArray, returns a CArray of addresses whose
|
|
94
|
+
# shape follows the first non-scalar input (other non-scalar inputs
|
|
95
|
+
# must match that shape). Mask propagates from the inputs.
|
|
96
|
+
# @param index [Array<Integer, CArray>] one entry per axis.
|
|
97
|
+
# @return [Integer, CArray] the flat address(es).
|
|
98
|
+
# @raise [IndexError] on an out-of-range index.
|
|
99
|
+
# @raise [ArgumentError] on shape mismatch between non-scalar inputs.
|
|
100
|
+
def index2addr(*index); end
|
|
101
|
+
|
|
102
|
+
# @overload addr2index(addr, shape:)
|
|
103
|
+
# Class-form of {#addr2index} that takes an explicit `shape:` rather
|
|
104
|
+
# than reading it from a receiver. Useful for coordinate arithmetic
|
|
105
|
+
# without allocating a template CArray.
|
|
106
|
+
# @param addr [Integer, CArray] a flat address or a CArray of them.
|
|
107
|
+
# @param shape [Array<Integer>] the row-major shape defining the grid.
|
|
108
|
+
# @return [Array<Integer>, Array<CArray>] one entry per axis.
|
|
109
|
+
# @raise [ArgumentError] when any `addr` is out of range or `shape:`
|
|
110
|
+
# is missing.
|
|
111
|
+
def self.addr2index(addr, shape:); end
|
|
112
|
+
|
|
113
|
+
# @overload index2addr(*index, shape:)
|
|
114
|
+
# Class-form of {#index2addr}.
|
|
115
|
+
# @param index [Array<Integer, CArray>] one entry per axis.
|
|
116
|
+
# @param shape [Array<Integer>] the row-major shape defining the grid.
|
|
117
|
+
# @return [Integer, CArray] the flat address(es).
|
|
118
|
+
# @raise [ArgumentError] on out-of-range index, shape mismatch, or
|
|
119
|
+
# missing `shape:`.
|
|
120
|
+
def self.index2addr(*index, shape:); end
|
|
121
|
+
|
|
122
|
+
# @overload normalize_index(idx)
|
|
123
|
+
# Returns a canonical form of the index array `idx` classified against
|
|
124
|
+
# `self`'s shape (scalars normalised, `nil` for whole axes, `[start,
|
|
125
|
+
# count, step]` for blocks). Used to inspect how an index resolves.
|
|
126
|
+
# @param idx [Array] the raw index spec.
|
|
127
|
+
# @return [Array] the normalised per-axis index.
|
|
128
|
+
def normalize_index(idx); end
|
|
129
|
+
|
|
130
|
+
# @!endgroup
|
|
131
|
+
end
|