carray 3.0.6 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.yardopts +1 -1
- data/CHANGELOG.md +7 -1830
- data/README.md +62 -35
- data/carray.gemspec +16 -4
- data/docs/changelogs/CHANGELOG-3.0.md +2464 -0
- data/ext/ca_array_pool.c +4 -5
- data/ext/ca_axis_descriptor.h +45 -30
- data/ext/ca_axis_dispatch.c +7 -4
- data/ext/ca_axis_group.c +12 -15
- data/ext/ca_bincmp_dispatch.h +16 -38
- data/ext/ca_binop_dispatch.c +35 -0
- data/ext/ca_binop_dispatch.h +22 -46
- data/ext/ca_categorical_iterator.c +36 -34
- data/ext/ca_compare.c +0 -1
- data/ext/ca_compare.h +8 -1
- data/ext/ca_composite_dispatch.h +6 -0
- data/ext/ca_for_buffer.h +6 -1
- data/ext/ca_group_iter.c +17 -18
- data/ext/ca_iter_state_fields.h +196 -0
- data/ext/ca_iter_substrate.h +84 -103
- data/ext/ca_kernel_iterator.c +125 -89
- data/ext/ca_kernel_iterator.h +229 -1504
- data/ext/ca_kernel_iterator_internal.h +1167 -0
- data/ext/ca_moncmp_dispatch.h +17 -24
- data/ext/ca_monop_dispatch.h +25 -74
- data/ext/ca_obj_array.c +92 -165
- data/ext/ca_obj_bincmp.c +65 -48
- data/ext/ca_obj_binop.c +74 -49
- data/ext/ca_obj_bitarray.c +7 -21
- data/ext/ca_obj_bitfield.c +93 -26
- data/ext/ca_obj_block.c +11 -12
- data/ext/ca_obj_byte_swap.c +34 -34
- data/ext/ca_obj_const_string.c +464 -304
- data/ext/ca_obj_face.c +167 -121
- data/ext/ca_obj_face.h +32 -170
- data/ext/ca_obj_fake.c +127 -34
- data/ext/ca_obj_farray.c +13 -9
- data/ext/ca_obj_field.c +17 -13
- data/ext/ca_obj_fixlen_string.c +57 -34
- data/ext/ca_obj_grid.c +149 -113
- data/ext/ca_obj_meld.c +28 -26
- data/ext/ca_obj_moncmp.c +10 -21
- data/ext/ca_obj_monop.c +88 -73
- data/ext/ca_obj_object.c +60 -46
- data/ext/ca_obj_record.c +74 -22
- data/ext/ca_obj_reduce.c +10 -14
- data/ext/ca_obj_refer.c +146 -39
- data/ext/ca_obj_remap.c +11 -29
- data/ext/ca_obj_repeat.c +41 -23
- data/ext/ca_obj_roll.c +20 -28
- data/ext/ca_obj_select.c +17 -27
- data/ext/ca_obj_select_axis.c +35 -42
- data/ext/ca_obj_shift.c +22 -42
- data/ext/ca_obj_source.c +1 -5
- data/ext/ca_obj_stack.c +33 -29
- data/ext/ca_obj_stride.c +99 -62
- data/ext/ca_obj_string.c +8 -20
- data/ext/ca_obj_tile.c +14 -16
- data/ext/ca_obj_time.c +12 -23
- data/ext/ca_obj_timedelta.c +12 -23
- data/ext/ca_obj_transpose.c +8 -10
- data/ext/ca_obj_triop.c +48 -49
- data/ext/ca_obj_window.c +87 -99
- data/ext/ca_op_cmplx64.h +4 -0
- data/ext/ca_op_ipower.c +97 -27
- data/ext/ca_op_powi.h +9 -28
- data/ext/ca_pow5_table.h +2 -1
- data/ext/ca_rng_normal.h +4 -0
- data/ext/ca_rng_xoshiro256pp.h +3 -0
- data/ext/ca_sort_kernels.h +23 -26
- data/ext/ca_sweep_engine.c +92 -26
- data/ext/ca_sweep_engine.h +22 -15
- data/ext/ca_transform_common.c +3 -8
- data/ext/ca_triop_dispatch.h +20 -32
- data/ext/caframe_csv_reader.c +12 -12
- data/ext/carray.h +300 -1009
- data/ext/carray_access.c +320 -207
- data/ext/carray_address_basis.c +128 -59
- data/ext/carray_attribute.c +81 -104
- data/ext/carray_bincount.c +12 -14
- data/ext/carray_broadcast.c +31 -27
- data/ext/carray_call_cfunc.c +174 -285
- data/ext/carray_call_cfunc.h +36 -28
- data/ext/carray_cast.c +1191 -351
- data/ext/carray_cast_func.rb +68 -8
- data/ext/carray_class.c +6 -11
- data/ext/carray_conversion.c +98 -39
- data/ext/carray_copy.c +52 -26
- data/ext/carray_core.c +286 -132
- data/ext/carray_count.c +53 -22
- data/ext/carray_element.c +49 -28
- data/ext/carray_factorize.c +64 -63
- data/ext/carray_generate.c +26 -19
- data/ext/carray_histogram.c +9 -11
- data/ext/carray_hold.c +7 -9
- data/ext/carray_index_classifier.c +127 -230
- data/ext/carray_index_classifier.h +11 -10
- data/ext/carray_integer_total.c +523 -0
- data/ext/carray_internal.h +1364 -156
- data/ext/carray_key_windows.c +3 -3
- data/ext/carray_lazy.c +37 -37
- data/ext/carray_loop.c +27 -23
- data/ext/carray_mask.c +235 -150
- data/ext/carray_math_kernel.h +23 -47
- data/ext/carray_mathfunc.c +10 -3
- data/ext/carray_median_percentile.c +106 -100
- data/ext/carray_memory_view.c +83 -69
- data/ext/carray_operator.c +490 -128
- data/ext/carray_order.c +163 -84
- data/ext/carray_partition.c +14 -16
- data/ext/carray_random.c +48 -42
- data/ext/carray_round.c +33 -5
- data/ext/carray_scatter.c +57 -39
- data/ext/carray_segment.c +42 -46
- data/ext/carray_slab.c +77 -51
- data/ext/carray_slab.h +44 -33
- data/ext/carray_sort.c +37 -31
- data/ext/carray_sort_kernel.c +36 -10
- data/ext/carray_struct.c +44 -34
- data/ext/carray_test.c +131 -81
- data/ext/carray_time_text.c +30 -31
- data/ext/carray_undef.c +50 -7
- data/ext/carray_utils.c +373 -139
- data/ext/extconf.rb +24 -17
- data/ext/mk_call_cfunc.rb +25 -31
- data/ext/mk_pow5_table.rb +2 -1
- data/ext/mkkernel.rb +819 -488
- data/ext/ruby_carray.c +47 -42
- data/ext/version.h +7 -5
- data/lib/carray/attribute.rb +19 -18
- data/lib/carray/autoload_carray.rb +20 -15
- data/lib/carray/autoload_method_extension.rb +64 -57
- data/lib/carray/axis_group.rb +272 -185
- data/lib/carray/basics.rb +298 -56
- data/lib/carray/bincount_nd.rb +41 -18
- data/lib/carray/block_iterator.rb +167 -119
- data/lib/carray/boolean_reduce.rb +7 -4
- data/lib/carray/categorical.rb +84 -59
- data/lib/carray/categorical_iterator.rb +90 -67
- data/lib/carray/complex.rb +61 -41
- data/lib/carray/conditional.rb +98 -23
- data/lib/carray/const_string.rb +112 -46
- data/lib/carray/core_extensions.rb +20 -69
- data/lib/carray/distance_limit.rb +7 -5
- data/lib/carray/factories.rb +269 -0
- data/lib/carray/fixlen_string.rb +95 -12
- data/lib/carray/frame/column_verbs.rb +76 -9
- data/lib/carray/frame/concat.rb +51 -7
- data/lib/carray/frame/convert.rb +2 -1
- data/lib/carray/frame/csv_parser.rb +20 -5
- data/lib/carray/frame/frame.rb +73 -31
- data/lib/carray/frame/group.rb +247 -187
- data/lib/carray/frame/io.rb +36 -12
- data/lib/carray/frame/join.rb +56 -17
- data/lib/carray/frame/records.rb +7 -5
- data/lib/carray/frame/reshape.rb +27 -7
- data/lib/carray/frame/sort.rb +10 -8
- data/lib/carray/frame/verbs.rb +217 -134
- data/lib/carray/frame/windows.rb +254 -19
- data/lib/carray/frame.rb +1 -2
- data/lib/carray/fuse_source.rb +28 -23
- data/lib/carray/fusion.rb +30 -30
- data/lib/carray/histogram.rb +35 -16
- data/lib/carray/inspect.rb +7 -7
- data/lib/carray/iterator.rb +104 -23
- data/lib/carray/key_windows.rb +93 -61
- data/lib/carray/lazy.rb +208 -111
- data/lib/carray/limits.rb +80 -0
- data/lib/carray/mask_gap_fill.rb +21 -16
- data/lib/carray/math.rb +87 -50
- data/lib/carray/meld_reduce.rb +30 -8
- data/lib/carray/methods/align_addr.rb +29 -17
- data/lib/carray/methods/bin.rb +8 -1
- data/lib/carray/methods/bincount.rb +4 -2
- data/lib/carray/methods/bit_string.rb +19 -31
- data/lib/carray/methods/broadcast.rb +8 -3
- data/lib/carray/methods/choose.rb +5 -5
- data/lib/carray/methods/composition.rb +73 -72
- data/lib/carray/methods/{index.rb → coordinate.rb} +13 -13
- data/lib/carray/methods/discovery_along.rb +3 -3
- data/lib/carray/methods/factorize.rb +2 -0
- data/lib/carray/methods/gather_nd.rb +106 -103
- data/lib/carray/methods/insert_block.rb +2 -2
- data/lib/carray/methods/is_between.rb +6 -4
- data/lib/carray/methods/is_in.rb +183 -143
- data/lib/carray/methods/join.rb +2 -1
- data/lib/carray/methods/lag.rb +6 -2
- data/lib/carray/methods/locate_addr.rb +157 -94
- data/lib/carray/methods/mask_duplicates.rb +1 -1
- data/lib/carray/methods/meshgrid.rb +28 -16
- data/lib/carray/methods/mode.rb +67 -67
- data/lib/carray/methods/nunique.rb +9 -7
- data/lib/carray/methods/repeat.rb +23 -13
- data/lib/carray/methods/resize.rb +1 -1
- data/lib/carray/methods/snap.rb +24 -20
- data/lib/carray/methods/string_format.rb +2 -2
- data/lib/carray/methods/unique.rb +4 -2
- data/lib/carray/methods/value_counts.rb +1 -1
- data/lib/carray/mkmf.rb +25 -28
- data/lib/carray/percentile_arguments.rb +82 -0
- data/lib/carray/record_order.rb +50 -20
- data/lib/carray/rng.rb +1 -0
- data/lib/carray/runtime.rb +195 -17
- data/lib/carray/segment_iterator.rb +262 -137
- data/lib/carray/serialize.rb +635 -566
- data/lib/carray/slab_iterator.rb +114 -114
- data/lib/carray/stack.rb +14 -15
- data/lib/carray/string.rb +16 -22
- data/lib/carray/string_operation_extension.rb +97 -52
- data/lib/carray/struct.rb +122 -164
- data/lib/carray/struct_builder.rb +247 -73
- data/lib/carray/time.rb +663 -365
- data/lib/carray/window_iterator.rb +232 -155
- data/lib/carray.rb +6 -11
- data/yard-stubs/ca_obj_array.rb +20 -135
- data/yard-stubs/ca_obj_bitarray.rb +1 -8
- data/yard-stubs/ca_obj_bitfield.rb +6 -2
- data/yard-stubs/ca_obj_byte_swap.rb +21 -7
- data/yard-stubs/ca_obj_fake.rb +3 -1
- data/yard-stubs/ca_obj_farray.rb +1 -1
- data/yard-stubs/ca_obj_field.rb +8 -6
- data/yard-stubs/ca_obj_refer.rb +10 -5
- data/yard-stubs/ca_obj_roll.rb +7 -6
- data/yard-stubs/ca_obj_shift.rb +2 -3
- data/yard-stubs/ca_obj_stride.rb +5 -7
- data/yard-stubs/ca_obj_tile.rb +1 -1
- data/yard-stubs/ca_obj_time.rb +43 -0
- data/yard-stubs/ca_obj_transpose.rb +1 -1
- data/yard-stubs/ca_obj_window.rb +28 -16
- data/yard-stubs/carray_access.rb +55 -6
- data/yard-stubs/carray_attribute.rb +26 -38
- data/yard-stubs/carray_cast.rb +121 -162
- data/yard-stubs/carray_class.rb +3 -4
- data/yard-stubs/carray_conversion.rb +6 -7
- data/yard-stubs/carray_copy.rb +2 -1
- data/yard-stubs/carray_count.rb +10 -5
- data/yard-stubs/carray_element.rb +4 -3
- data/yard-stubs/carray_limits.rb +100 -0
- data/yard-stubs/carray_loop.rb +0 -20
- data/yard-stubs/carray_mask.rb +59 -41
- data/yard-stubs/carray_math.rb +162 -100
- data/yard-stubs/carray_mathfunc.rb +415 -3
- data/yard-stubs/carray_median_percentile.rb +29 -11
- data/yard-stubs/carray_memory_view.rb +2 -2
- data/yard-stubs/carray_order.rb +72 -33
- data/yard-stubs/carray_random.rb +6 -6
- data/yard-stubs/carray_reduce.rb +353 -0
- data/yard-stubs/carray_rng.rb +92 -0
- data/yard-stubs/carray_scatter.rb +12 -3
- data/yard-stubs/carray_slab.rb +7 -4
- data/yard-stubs/carray_sort.rb +7 -6
- data/yard-stubs/carray_test.rb +18 -5
- data/yard-stubs/carray_undef.rb +44 -5
- data/yard-stubs/ruby_carray.rb +75 -40
- metadata +63 -25
- data/CHANGELOG.v1.md +0 -126
- data/ext/carray_build_flags.h +0 -3
- data/ext/carray_config.h +0 -28
- data/ext/carray_data_type.c +0 -90
- data/ext/carray_kernels_bincmp.c +0 -6457
- data/ext/carray_kernels_binop.c +0 -31534
- data/ext/carray_kernels_init.c +0 -1734
- data/ext/carray_kernels_moncmp.c +0 -2104
- data/ext/carray_kernels_monop.c +0 -25387
- data/ext/carray_kernels_reduce_aggregate.c +0 -27545
- data/ext/carray_kernels_reduce_boolean.c +0 -1924
- data/ext/carray_kernels_reduce_cumulative.c +0 -11646
- data/ext/carray_kernels_reduce_extreme.c +0 -21631
- data/ext/carray_kernels_reduce_variance.c +0 -5981
- data/ext/carray_kernels_scan.c +0 -4302
- data/ext/carray_kernels_search.c +0 -37776
- data/ext/carray_kernels_sort.c +0 -10814
- data/ext/carray_kernels_triop.c +0 -1864
- data/lib/carray/construct.rb +0 -360
- data/lib/carray/data_type_extension.rb +0 -261
- data/lib/carray/data_type_limits.rb +0 -91
|
@@ -67,80 +67,15 @@ class CArray
|
|
|
67
67
|
|
|
68
68
|
# ---------------------------------------------------------------- eager ragged 2
|
|
69
69
|
|
|
70
|
-
# @overload concatenate(list, axis: 0, data_type: nil)
|
|
71
|
-
# Returns `list` concatenated along a single existing axis. Eager
|
|
72
|
-
# (returns a fresh CArray) and accepts non-uniform pieces (varying
|
|
73
|
-
# sizes along the `axis`); non-tile axes must agree across pieces.
|
|
74
|
-
#
|
|
75
|
-
# Use `CArray.meld` for the uniform-shape view-default counterpart.
|
|
76
|
-
#
|
|
77
|
-
# @param list [Array<CArray>] pieces to concatenate.
|
|
78
|
-
# @param axis [Integer, nil] axis to concatenate along; `nil` is the
|
|
79
|
-
# same as `0`.
|
|
80
|
-
# @param data_type [Symbol, Integer, nil] result `data_type`;
|
|
81
|
-
# inferred via `result_type` when `nil`.
|
|
82
|
-
# @return [CArray] fresh CArray with per-piece `axis` sizes summed.
|
|
83
|
-
# @raise [ArgumentError] when `list` is empty or piece shapes are
|
|
84
|
-
# inconsistent.
|
|
85
|
-
def self.concatenate (list, axis: 0, data_type: nil)
|
|
86
|
-
raise ArgumentError, "concatenate: list must not be empty" if list.empty?
|
|
87
|
-
axis = 0 if axis.nil?
|
|
88
|
-
__ragged_paste(list, [list.size], axis, data_type, "concatenate")
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
# @overload concatenate(*others, axis: 0, data_type: nil)
|
|
92
|
-
# Instance form of {CArray.concatenate}: returns `[self, *others]`
|
|
93
|
-
# concatenated along `axis` as a fresh CArray. Eager auto-cast
|
|
94
|
-
# counterpart of `#meld` (view).
|
|
95
|
-
#
|
|
96
|
-
# @param others [Array<CArray>] additional pieces.
|
|
97
|
-
# @param axis [Integer] axis to concatenate along.
|
|
98
|
-
# @param data_type [Symbol, Integer, nil] result `data_type`;
|
|
99
|
-
# inferred via `result_type` when `nil`.
|
|
100
|
-
# @return [CArray] fresh CArray.
|
|
101
|
-
# @raise [ArgumentError] when no `others` are given.
|
|
102
|
-
def concatenate (*others, axis: 0, data_type: nil)
|
|
103
|
-
raise ArgumentError, "concatenate: at least one other array required" if others.empty?
|
|
104
|
-
CArray.concatenate([self, *others], axis: axis, data_type: data_type)
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
# @overload mosaic(list, tdim, axis: 0, data_type: nil)
|
|
108
|
-
# Returns `list` tiled into an N-D grid layout described by
|
|
109
|
-
# `tdim`. Eager (returns a fresh CArray), accepts non-uniform
|
|
110
|
-
# sizes along the tile axes with block-matrix consistency
|
|
111
|
-
# (row-by-row / column-by-column agreement).
|
|
112
|
-
#
|
|
113
|
-
# @param list [Array<CArray>] pieces to tile; length must equal
|
|
114
|
-
# the product of `tdim`.
|
|
115
|
-
# @param tdim [Array<Integer>] tile grid shape.
|
|
116
|
-
# @param axis [Integer] first tile axis in the result.
|
|
117
|
-
# @param data_type [Symbol, Integer, nil] result `data_type`;
|
|
118
|
-
# inferred when `nil`.
|
|
119
|
-
# @return [CArray] fresh CArray with tile axes extended by summed
|
|
120
|
-
# per-tile sizes.
|
|
121
|
-
# @raise [ArgumentError] when `list` is empty, `tdim` is
|
|
122
|
-
# ill-formed, or piece shapes violate block-matrix consistency.
|
|
123
|
-
def self.mosaic (list, tdim, axis: 0, data_type: nil)
|
|
124
|
-
raise ArgumentError, "mosaic: list must not be empty" if list.empty?
|
|
125
|
-
unless tdim.is_a?(Array) && tdim.size > 0
|
|
126
|
-
raise ArgumentError, "mosaic: tdim must be a non-empty Array of Integer"
|
|
127
|
-
end
|
|
128
|
-
expected = tdim.inject(1, :*)
|
|
129
|
-
unless expected == list.size
|
|
130
|
-
raise ArgumentError,
|
|
131
|
-
"mosaic: tdim product (#{expected}) must equal list size (#{list.size})"
|
|
132
|
-
end
|
|
133
|
-
__ragged_paste(list, tdim, axis, data_type, "mosaic")
|
|
134
|
-
end
|
|
135
|
-
|
|
136
70
|
# Shared eager paste-loop helper (= ex-`combine` paste implementation,
|
|
137
71
|
# preserved verbatim for concatenate / mosaic). Returns a fresh CArray of
|
|
138
72
|
# shape obtained by tiling `list` over `tdim` starting at `axis`, with
|
|
139
73
|
# per-piece dim sizes summed along each tile axis (= block-matrix
|
|
140
74
|
# consistency required across rows / columns).
|
|
141
|
-
def self.__ragged_paste
|
|
75
|
+
def self.__ragged_paste(list, tdim, axis, data_type, name)
|
|
76
|
+
list.each { |a| refuse_ruby_array(name, "an array to join") if a.is_a?(Array) }
|
|
142
77
|
shared_attrs = attrs_shared_by(list)
|
|
143
|
-
list =
|
|
78
|
+
list = promote_list_for(name, list, data_type: data_type)
|
|
144
79
|
# promote_list has already enforced homogeneity (= common data_type, and
|
|
145
80
|
# for Face elements: same Face class + portable + state-compatible). So,
|
|
146
81
|
# mirroring CArray.stack, paste at the storage level and re-wrap the
|
|
@@ -223,12 +158,78 @@ class CArray
|
|
|
223
158
|
end
|
|
224
159
|
obj.paste(idx, item)
|
|
225
160
|
end
|
|
226
|
-
obj = obj.face_lift
|
|
161
|
+
obj = obj.send(:face_lift, face_parent) if face_parent
|
|
227
162
|
obj.set_attrs(shared_attrs) unless shared_attrs.empty?
|
|
228
163
|
obj
|
|
229
164
|
end
|
|
230
165
|
private_class_method :__ragged_paste
|
|
231
166
|
|
|
167
|
+
# @overload concatenate(list, axis: 0, data_type: nil)
|
|
168
|
+
# Returns `list` concatenated along a single existing axis. Eager
|
|
169
|
+
# (returns a fresh CArray) and accepts non-uniform pieces (varying
|
|
170
|
+
# sizes along the `axis`); non-tile axes must agree across pieces.
|
|
171
|
+
#
|
|
172
|
+
# Use `CArray.meld` for the uniform-shape view-default counterpart.
|
|
173
|
+
#
|
|
174
|
+
# @param list [Array<CArray>] pieces to concatenate.
|
|
175
|
+
# @param axis [Integer, nil] axis to concatenate along; `nil` is the
|
|
176
|
+
# same as `0`.
|
|
177
|
+
# @param data_type [Symbol, Integer, nil] result `data_type`;
|
|
178
|
+
# inferred via `result_type` when `nil`.
|
|
179
|
+
# @return [CArray] fresh CArray with per-piece `axis` sizes summed.
|
|
180
|
+
# @raise [ArgumentError] when `list` is empty or piece shapes are
|
|
181
|
+
# inconsistent.
|
|
182
|
+
def self.concatenate(list, axis: 0, data_type: nil)
|
|
183
|
+
raise ArgumentError, "concatenate: list must not be empty" if list.empty?
|
|
184
|
+
axis = 0 if axis.nil?
|
|
185
|
+
__ragged_paste(list, [list.size], axis, data_type, "concatenate")
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# @overload concatenate(*others, axis: 0, data_type: nil)
|
|
189
|
+
# Instance form of {CArray.concatenate}: returns `[self, *others]`
|
|
190
|
+
# concatenated along `axis` as a fresh CArray. Eager auto-cast
|
|
191
|
+
# counterpart of `#meld` (view).
|
|
192
|
+
#
|
|
193
|
+
# @param others [Array<CArray>] additional pieces.
|
|
194
|
+
# @param axis [Integer] axis to concatenate along.
|
|
195
|
+
# @param data_type [Symbol, Integer, nil] result `data_type`;
|
|
196
|
+
# inferred via `result_type` when `nil`.
|
|
197
|
+
# @return [CArray] fresh CArray.
|
|
198
|
+
# @raise [ArgumentError] when no `others` are given.
|
|
199
|
+
def concatenate(*others, axis: 0, data_type: nil)
|
|
200
|
+
raise ArgumentError, "concatenate: at least one other array required" if others.empty?
|
|
201
|
+
CArray.concatenate([self, *others], axis: axis, data_type: data_type)
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
# @overload mosaic(list, tdim, axis: 0, data_type: nil)
|
|
205
|
+
# Returns `list` tiled into an N-D grid layout described by
|
|
206
|
+
# `tdim`. Eager (returns a fresh CArray), accepts non-uniform
|
|
207
|
+
# sizes along the tile axes with block-matrix consistency
|
|
208
|
+
# (row-by-row / column-by-column agreement).
|
|
209
|
+
#
|
|
210
|
+
# @param list [Array<CArray>] pieces to tile; length must equal
|
|
211
|
+
# the product of `tdim`.
|
|
212
|
+
# @param tdim [Array<Integer>] tile grid shape.
|
|
213
|
+
# @param axis [Integer] first tile axis in the result.
|
|
214
|
+
# @param data_type [Symbol, Integer, nil] result `data_type`;
|
|
215
|
+
# inferred when `nil`.
|
|
216
|
+
# @return [CArray] fresh CArray with tile axes extended by summed
|
|
217
|
+
# per-tile sizes.
|
|
218
|
+
# @raise [ArgumentError] when `list` is empty, `tdim` is
|
|
219
|
+
# ill-formed, or piece shapes violate block-matrix consistency.
|
|
220
|
+
def self.mosaic(list, tdim, axis: 0, data_type: nil)
|
|
221
|
+
raise ArgumentError, "mosaic: list must not be empty" if list.empty?
|
|
222
|
+
unless tdim.is_a?(Array) && tdim.size > 0
|
|
223
|
+
raise ArgumentError, "mosaic: tdim must be a non-empty Array of Integer"
|
|
224
|
+
end
|
|
225
|
+
expected = tdim.inject(1, :*)
|
|
226
|
+
unless expected == list.size
|
|
227
|
+
raise ArgumentError,
|
|
228
|
+
"mosaic: tdim product (#{expected}) must equal list size (#{list.size})"
|
|
229
|
+
end
|
|
230
|
+
__ragged_paste(list, tdim, axis, data_type, "mosaic")
|
|
231
|
+
end
|
|
232
|
+
|
|
232
233
|
# ---------------------------------------------------------------- tabulate
|
|
233
234
|
|
|
234
235
|
# @overload tabulate(columns, data_type: nil)
|
|
@@ -255,11 +256,11 @@ class CArray
|
|
|
255
256
|
# @raise [ArgumentError] when `columns` is empty, entries are
|
|
256
257
|
# not 1-D or 2-D CArrays, or row counts disagree.
|
|
257
258
|
# @example
|
|
258
|
-
# c1 =
|
|
259
|
-
# c2 =
|
|
259
|
+
# c1 = CA_INT32([1, 2, 3])
|
|
260
|
+
# c2 = CA_FLOAT64([4.5, 5.5, 6.5])
|
|
260
261
|
# CArray.tabulate([c1, c2]) # float64 (3, 2)
|
|
261
262
|
# CArray.tabulate([c1, c2], data_type: :int32) # int32 (3, 2)
|
|
262
|
-
def self.tabulate
|
|
263
|
+
def self.tabulate(columns, data_type: nil)
|
|
263
264
|
raise ArgumentError, "tabulate: columns must not be empty" if columns.empty?
|
|
264
265
|
blocks = columns.map do |c|
|
|
265
266
|
unless c.is_a?(CArray) && (c.ndim == 1 || c.ndim == 2)
|
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
class CArray
|
|
2
2
|
|
|
3
|
-
# @overload
|
|
4
|
-
# Returns a writable
|
|
3
|
+
# @overload coordinate(axis: 0)
|
|
4
|
+
# Returns a writable int64 CArray holding the coordinate ramp
|
|
5
5
|
# `[0, 1, ..., shape[axis] - 1]` along `axis`, in an open
|
|
6
6
|
# broadcast shape: size `shape[axis]` on that axis and 1 on
|
|
7
|
-
# every other axis (e.g. for `(d0, d1, d2)`, `
|
|
7
|
+
# every other axis (e.g. for `(d0, d1, d2)`, `coordinate(axis: 1)`
|
|
8
8
|
# returns `(1, d1, 1)`).
|
|
9
9
|
#
|
|
10
10
|
# The result broadcasts against `self` in element-wise ops
|
|
11
11
|
# without materialising the full shape. For the dense
|
|
12
12
|
# full-shape grid use
|
|
13
|
-
# `
|
|
13
|
+
# `coordinate(axis: k).broadcast_to(*shape)` or `CArray.meshgrid`.
|
|
14
14
|
#
|
|
15
15
|
# @param axis [Integer] axis to vary (negative counts from the
|
|
16
16
|
# end).
|
|
17
|
-
# @return [CArray] writable
|
|
17
|
+
# @return [CArray] writable int64 CArray; size 1 on every axis
|
|
18
18
|
# except `axis`, which has size `shape[axis]`.
|
|
19
|
-
def
|
|
20
|
-
k = normalize_axis(axis, "
|
|
19
|
+
def coordinate(axis: 0)
|
|
20
|
+
k = normalize_axis(axis, "coordinate")
|
|
21
21
|
oshape = Array.new(ndim, 1)
|
|
22
22
|
oshape[k] = shape[k]
|
|
23
|
-
CArray.
|
|
23
|
+
CArray.int64(*oshape).seq!
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
# @overload
|
|
26
|
+
# @overload coordinates
|
|
27
27
|
# Returns an Array of +ndim+ coordinate ramps, one per axis, each in
|
|
28
|
-
# the open broadcast shape of {#
|
|
28
|
+
# the open broadcast shape of {#coordinate}.
|
|
29
29
|
# @return [Array<CArray>] one open coordinate ramp per axis.
|
|
30
|
-
# @overload
|
|
30
|
+
# @overload coordinates { |*ramps| ... }
|
|
31
31
|
# Yields the +ndim+ open coordinate ramps as splat arguments.
|
|
32
32
|
# @yield [*ramps] the per-axis open coordinate ramps.
|
|
33
33
|
# @return [Object] the block's return value.
|
|
34
|
-
def
|
|
35
|
-
list = (0...ndim).map { |k|
|
|
34
|
+
def coordinates
|
|
35
|
+
list = (0...ndim).map { |k| coordinate(axis: k) }
|
|
36
36
|
block_given? ? yield(*list) : list
|
|
37
37
|
end
|
|
38
38
|
|
|
@@ -14,14 +14,14 @@ class CArray
|
|
|
14
14
|
# anything, which a transpose or a strided view does not give;
|
|
15
15
|
# - byte equality is not the family's contract for floats, where
|
|
16
16
|
# every NaN is one value and -0.0 is +0.0;
|
|
17
|
-
# - masks fold
|
|
17
|
+
# - masks fold with no extra code -- a CARefer that covers several parent
|
|
18
18
|
# cells with one view cell OR-reduces their mask bits, so a
|
|
19
19
|
# sub-array holding a masked cell is a masked sub-array and the
|
|
20
20
|
# kernels skip it.
|
|
21
21
|
#
|
|
22
22
|
# Returns a 1-D fixlen array, one cell per sub-array, for the caller
|
|
23
23
|
# to run an ordinary cell-level discovery method over.
|
|
24
|
-
private def fibers_as_cells
|
|
24
|
+
private def fibers_as_cells(along, caller_name)
|
|
25
25
|
if ndim < 2
|
|
26
26
|
raise ArgumentError,
|
|
27
27
|
"#{caller_name}: along: compares sub-arrays, and a #{ndim}-D array " \
|
|
@@ -63,7 +63,7 @@ class CArray
|
|
|
63
63
|
|
|
64
64
|
# `axis:` and `along:` ask different questions of the same array, so
|
|
65
65
|
# answering both at once has no meaning.
|
|
66
|
-
private def reject_axis_with_along
|
|
66
|
+
private def reject_axis_with_along(axis, along, caller_name)
|
|
67
67
|
return unless axis and along
|
|
68
68
|
raise ArgumentError,
|
|
69
69
|
"#{caller_name}: axis: and along: cannot be given together -- " \
|
|
@@ -44,6 +44,8 @@ class CArray
|
|
|
44
44
|
if excluded.count(true) > 0
|
|
45
45
|
codes.mask = codes.has_mask? ? (codes.mask | excluded) : excluded
|
|
46
46
|
end
|
|
47
|
+
# A const string's discovery reads its bytes and gives Ruby Strings.
|
|
48
|
+
levels = CArray.const_string(levels, encoding: encoding) if is_a?(CAConstString)
|
|
47
49
|
[codes, levels]
|
|
48
50
|
end
|
|
49
51
|
|
|
@@ -14,120 +14,22 @@
|
|
|
14
14
|
|
|
15
15
|
class CArray
|
|
16
16
|
|
|
17
|
-
# @overload gather_nd(indices)
|
|
18
|
-
# Returns elements (or sub-arrays) gathered from `self` at the
|
|
19
|
-
# N-D coordinates given by `indices`.
|
|
20
|
-
#
|
|
21
|
-
# `indices` accepts two equivalent forms:
|
|
22
|
-
#
|
|
23
|
-
# * **stacked** — a single CArray whose last axis enumerates a
|
|
24
|
-
# K-dimensional coordinate tuple into the first K axes of `self`.
|
|
25
|
-
# * **per-axis** — an `Array` of K coordinate CArrays (one per
|
|
26
|
-
# consumed axis). The per-axis arrays are broadcast together
|
|
27
|
-
# (via {CArray.broadcast}) and stacked along a new trailing axis,
|
|
28
|
-
# so `gather_nd([i, j])` == `gather_nd(CArray.stack([i, j], axis: -1))`.
|
|
29
|
-
# An Integer scalar is accepted for a constant axis and broadcast
|
|
30
|
-
# to the common shape. Entries must be CArray or Integer: Ruby
|
|
31
|
-
# Array literals are rejected (wrap them with `CA_INT64(...)`
|
|
32
|
-
# yourself), keeping this a copy-free gather path.
|
|
33
|
-
#
|
|
34
|
-
# The remaining `self.shape[K..-1]` axes (called `rest`) are carried
|
|
35
|
-
# through:
|
|
36
|
-
#
|
|
37
|
-
# self.shape = (D0, ..., D_{K-1}, *rest)
|
|
38
|
-
# indices.shape = (*outer, K) # stacked form
|
|
39
|
-
# result.shape = (*outer, *rest)
|
|
40
|
-
#
|
|
41
|
-
# In the fully-degenerate case where both `outer` and `rest` are
|
|
42
|
-
# empty (a single full coordinate via 1-D `indices` of shape `(K,)`
|
|
43
|
-
# with `K == ndim`), the result is a 1-element `(1,)` CArray,
|
|
44
|
-
# following CArray's scalar model (CScalar carries shape `[1]`),
|
|
45
|
-
# not a 0-dim array.
|
|
46
|
-
#
|
|
47
|
-
# The result is a fresh materialised CArray. Negative indices on
|
|
48
|
-
# each coordinate axis follow CArray's standard wrap rule
|
|
49
|
-
# (`-1` == last); out-of-range indices raise. Duplicate
|
|
50
|
-
# coordinates in `indices` are fine on gather: the same value is
|
|
51
|
-
# picked multiple times. See {#put_nd} for the duplicate-write
|
|
52
|
-
# story.
|
|
53
|
-
#
|
|
54
|
-
# @param indices [CArray, Array<CArray, Integer>] stacked integer
|
|
55
|
-
# CArray with `ndim >= 1` and last axis size `K` in `[1, ndim]`,
|
|
56
|
-
# or an Array of K per-axis coordinate CArrays (Integer scalars
|
|
57
|
-
# allowed per axis).
|
|
58
|
-
# @return [CArray] materialised result with shape `outer + rest`.
|
|
59
|
-
# @raise [ArgumentError] when `indices` is neither a CArray nor an
|
|
60
|
-
# Array, is 0-dim, is non-integer, or has a last-axis size
|
|
61
|
-
# outside `[1, ndim]`.
|
|
62
|
-
# @raise [IndexError] when a coordinate is out of range on any axis.
|
|
63
|
-
def gather_nd (indices)
|
|
64
|
-
flat_addr, outer, rest = gather_nd_flat_addr(indices, "gather_nd")
|
|
65
|
-
out_shape = outer + rest
|
|
66
|
-
# flatten + 1-D fancy indexing -> CAGrid view -> materialise via .copy.
|
|
67
|
-
# A masked coordinate reads as UNDEF: project carries the address mask.
|
|
68
|
-
result = flat_addr.has_mask? ? flatten.project(flat_addr) : self.flatten[flat_addr].copy
|
|
69
|
-
out_shape.empty? ? result : result.reshape(*out_shape)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
# @overload put_nd(indices, values)
|
|
73
|
-
# Sets `self` at the N-D coordinates given by `indices` to
|
|
74
|
-
# `values`. Inverse of {#gather_nd}.
|
|
75
|
-
#
|
|
76
|
-
# self.shape = (D0, ..., D_{K-1}, *rest)
|
|
77
|
-
# indices.shape = (*outer, K)
|
|
78
|
-
# values broadcast to (*outer, *rest)
|
|
79
|
-
#
|
|
80
|
-
# Duplicate coordinates in `indices` use **last-write-wins**
|
|
81
|
-
# semantics, matching `put_along_axis`. Accumulate semantics
|
|
82
|
-
# (`+=`) are not provided here; route to the `scatter_*!`
|
|
83
|
-
# family instead (e.g. `self.flatten.scatter_add!(flat_addr, vals)`).
|
|
84
|
-
#
|
|
85
|
-
# @param indices [CArray, Array<CArray, Integer>] stacked integer
|
|
86
|
-
# CArray shaped `(*outer, K)`, or an Array of K per-axis
|
|
87
|
-
# coordinate arrays (same forms as {#gather_nd}).
|
|
88
|
-
# @param values [CArray, Numeric] values broadcastable to
|
|
89
|
-
# `(*outer, *rest)`.
|
|
90
|
-
# @return [self]
|
|
91
|
-
# @raise [ArgumentError] on the same conditions as {#gather_nd}.
|
|
92
|
-
# @raise [IndexError] when a coordinate is out of range on any axis.
|
|
93
|
-
def put_nd (indices, values)
|
|
94
|
-
# The write goes through a flattened view, which carries a frozen
|
|
95
|
-
# array's read-only flag but not its frozenness; say what the array is.
|
|
96
|
-
raise FrozenError.new("can't modify frozen #{self.class}", receiver: self) if frozen?
|
|
97
|
-
flat_addr, _outer, _rest = gather_nd_flat_addr(indices, "put_nd")
|
|
98
|
-
if flat_addr.has_mask?
|
|
99
|
-
# A masked coordinate writes nothing. The values are laid out over
|
|
100
|
-
# the coordinates by the store itself, so they mean what they mean
|
|
101
|
-
# unmasked, and only the cells at unmasked coordinates are written.
|
|
102
|
-
flat = flatten
|
|
103
|
-
vals = flat.project(flat_addr)
|
|
104
|
-
vals[] = values
|
|
105
|
-
sel = flat_addr.is_not_masked
|
|
106
|
-
flat[flat_addr[sel]] = vals[sel]
|
|
107
|
-
else
|
|
108
|
-
self.flatten[flat_addr] = values
|
|
109
|
-
end
|
|
110
|
-
self
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
private
|
|
114
|
-
|
|
115
17
|
# Shared helper: compute the flat-address CArray (shape = outer + rest)
|
|
116
18
|
# for both `gather_nd` and `put_nd`. Returns `[flat_addr, outer, rest]`.
|
|
117
|
-
def gather_nd_flat_addr
|
|
19
|
+
private def gather_nd_flat_addr(indices, name)
|
|
118
20
|
# Per-axis form: an Array of K coordinate arrays. Broadcast them to a
|
|
119
21
|
# common outer shape and stack along a new trailing axis, yielding the
|
|
120
22
|
# (*outer, K) stacked form the rest of this helper already handles.
|
|
121
23
|
indices = gather_nd_stack_axes(indices, name) if indices.is_a?(Array)
|
|
122
24
|
|
|
123
25
|
unless indices.is_a?(CArray)
|
|
124
|
-
raise
|
|
26
|
+
raise TypeError, "#{name}: indices must be a CArray or an Array of per-axis CArrays"
|
|
125
27
|
end
|
|
126
28
|
if indices.ndim == 0
|
|
127
29
|
raise ArgumentError, "#{name}: indices must have at least 1 dimension"
|
|
128
30
|
end
|
|
129
31
|
unless indices.integer?
|
|
130
|
-
raise
|
|
32
|
+
raise IndexError,
|
|
131
33
|
"#{name}: indices must be an integer CArray (got #{indices.data_type})"
|
|
132
34
|
end
|
|
133
35
|
|
|
@@ -188,7 +90,7 @@ class CArray
|
|
|
188
90
|
# implicit align) and stacked along a new trailing axis. Integer
|
|
189
91
|
# scalars are accepted per axis and expand to the common shape; an
|
|
190
92
|
# all-scalar list yields the 1-D `(K,)` single-coordinate form.
|
|
191
|
-
def gather_nd_stack_axes
|
|
93
|
+
private def gather_nd_stack_axes(list, name)
|
|
192
94
|
if list.empty?
|
|
193
95
|
raise ArgumentError, "#{name}: coordinate list must not be empty"
|
|
194
96
|
end
|
|
@@ -200,7 +102,7 @@ class CArray
|
|
|
200
102
|
# yourself once (CA_INT64(...)) if you have array literals.
|
|
201
103
|
list.each do |c|
|
|
202
104
|
unless c.is_a?(CArray) || c.is_a?(Integer)
|
|
203
|
-
raise
|
|
105
|
+
raise TypeError,
|
|
204
106
|
"#{name}: per-axis coordinate must be a CArray or Integer (got #{c.class})"
|
|
205
107
|
end
|
|
206
108
|
end
|
|
@@ -223,4 +125,105 @@ class CArray
|
|
|
223
125
|
CArray.stack(coords, axis: -1)
|
|
224
126
|
end
|
|
225
127
|
|
|
128
|
+
# @overload gather_nd(indices)
|
|
129
|
+
# Returns elements (or sub-arrays) gathered from `self` at the
|
|
130
|
+
# N-D coordinates given by `indices`.
|
|
131
|
+
#
|
|
132
|
+
# `indices` accepts two equivalent forms:
|
|
133
|
+
#
|
|
134
|
+
# * **stacked** — a single CArray whose last axis enumerates a
|
|
135
|
+
# K-dimensional coordinate tuple into the first K axes of `self`.
|
|
136
|
+
# * **per-axis** — an `Array` of K coordinate CArrays (one per
|
|
137
|
+
# consumed axis). The per-axis arrays are broadcast together
|
|
138
|
+
# (via {CArray.broadcast}) and stacked along a new trailing axis,
|
|
139
|
+
# so `gather_nd([i, j])` == `gather_nd(CArray.stack([i, j], axis: -1))`.
|
|
140
|
+
# An Integer scalar is accepted for a constant axis and broadcast
|
|
141
|
+
# to the common shape. Entries must be CArray or Integer: Ruby
|
|
142
|
+
# Array literals are rejected (wrap them with `CA_INT64(...)`
|
|
143
|
+
# yourself), keeping this a copy-free gather path.
|
|
144
|
+
#
|
|
145
|
+
# The remaining `self.shape[K..-1]` axes (called `rest`) are carried
|
|
146
|
+
# through:
|
|
147
|
+
#
|
|
148
|
+
# self.shape = (D0, ..., D_{K-1}, *rest)
|
|
149
|
+
# indices.shape = (*outer, K) # stacked form
|
|
150
|
+
# result.shape = (*outer, *rest)
|
|
151
|
+
#
|
|
152
|
+
# In the fully-degenerate case where both `outer` and `rest` are
|
|
153
|
+
# empty (a single full coordinate via 1-D `indices` of shape `(K,)`
|
|
154
|
+
# with `K == ndim`), the result is a 1-element `(1,)` CArray,
|
|
155
|
+
# following CArray's scalar model (CScalar carries shape `[1]`),
|
|
156
|
+
# not a 0-dim array.
|
|
157
|
+
#
|
|
158
|
+
# The result is a fresh materialised CArray. Negative indices on
|
|
159
|
+
# each coordinate axis follow CArray's standard wrap rule
|
|
160
|
+
# (`-1` == last); out-of-range indices raise. Duplicate
|
|
161
|
+
# coordinates in `indices` are fine on gather: the same value is
|
|
162
|
+
# picked multiple times. See {#put_nd} for the duplicate-write
|
|
163
|
+
# story.
|
|
164
|
+
#
|
|
165
|
+
# @param indices [CArray, Array<CArray, Integer>] stacked integer
|
|
166
|
+
# CArray with `ndim >= 1` and last axis size `K` in `[1, ndim]`,
|
|
167
|
+
# or an Array of K per-axis coordinate CArrays (Integer scalars
|
|
168
|
+
# allowed per axis).
|
|
169
|
+
# @return [CArray] materialised result with shape `outer + rest`.
|
|
170
|
+
# @raise [TypeError] when `indices` is neither a CArray nor an Array,
|
|
171
|
+
# or a per-axis coordinate is neither a CArray nor an Integer.
|
|
172
|
+
# @raise [ArgumentError] when `indices` is 0-dim or has a last-axis
|
|
173
|
+
# size outside `[1, ndim]`.
|
|
174
|
+
# @raise [IndexError] when `indices` is not an integer CArray, or a
|
|
175
|
+
# coordinate is out of range on any axis.
|
|
176
|
+
def gather_nd(indices)
|
|
177
|
+
flat_addr, outer, rest = gather_nd_flat_addr(indices, "gather_nd")
|
|
178
|
+
out_shape = outer + rest
|
|
179
|
+
# flatten + 1-D fancy indexing -> CAGrid view -> materialise via .copy.
|
|
180
|
+
# A masked coordinate reads as UNDEF: project carries the address mask.
|
|
181
|
+
result = flat_addr.has_mask? ? flatten.project(flat_addr) : self.flatten[flat_addr].copy
|
|
182
|
+
out_shape.empty? ? result : result.reshape(*out_shape)
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# @overload put_nd(indices, values)
|
|
186
|
+
# Sets `self` at the N-D coordinates given by `indices` to
|
|
187
|
+
# `values`. Inverse of {#gather_nd}.
|
|
188
|
+
#
|
|
189
|
+
# self.shape = (D0, ..., D_{K-1}, *rest)
|
|
190
|
+
# indices.shape = (*outer, K)
|
|
191
|
+
# values broadcast to (*outer, *rest)
|
|
192
|
+
#
|
|
193
|
+
# Duplicate coordinates in `indices` use **last-write-wins**
|
|
194
|
+
# semantics, matching `put_along_axis`. Accumulate semantics
|
|
195
|
+
# (`+=`) are not provided here; route to the `scatter_*!`
|
|
196
|
+
# family instead (e.g. `self.flatten.scatter_add!(flat_addr, vals)`).
|
|
197
|
+
#
|
|
198
|
+
# @param indices [CArray, Array<CArray, Integer>] stacked integer
|
|
199
|
+
# CArray shaped `(*outer, K)`, or an Array of K per-axis
|
|
200
|
+
# coordinate arrays (same forms as {#gather_nd}).
|
|
201
|
+
# @param values [CArray, Numeric] values broadcastable to
|
|
202
|
+
# `(*outer, *rest)`.
|
|
203
|
+
# @return [self]
|
|
204
|
+
# @raise [TypeError, ArgumentError, IndexError] on the same conditions
|
|
205
|
+
# as {#gather_nd}.
|
|
206
|
+
def put_nd(indices, values)
|
|
207
|
+
# The write goes through a flattened view, which carries a frozen
|
|
208
|
+
# array's read-only flag but not its frozenness; say what the array is.
|
|
209
|
+
raise FrozenError.new("can't modify frozen #{self.class}", receiver: self) if frozen?
|
|
210
|
+
flat_addr, outer, rest = gather_nd_flat_addr(indices, "put_nd")
|
|
211
|
+
# The values lie as gather_nd gives them back.
|
|
212
|
+
out_shape = outer + rest
|
|
213
|
+
flat_addr = flat_addr.reshape(*out_shape) unless out_shape.empty?
|
|
214
|
+
if flat_addr.has_mask?
|
|
215
|
+
# A masked coordinate writes nothing. The values are laid out over
|
|
216
|
+
# the coordinates by the store itself, so they mean what they mean
|
|
217
|
+
# unmasked, and only the cells at unmasked coordinates are written.
|
|
218
|
+
flat = flatten
|
|
219
|
+
vals = flat.project(flat_addr)
|
|
220
|
+
vals[] = values
|
|
221
|
+
sel = flat_addr.is_not_masked
|
|
222
|
+
flat[flat_addr[sel]] = vals[sel]
|
|
223
|
+
else
|
|
224
|
+
self.flatten[flat_addr] = values
|
|
225
|
+
end
|
|
226
|
+
self
|
|
227
|
+
end
|
|
228
|
+
|
|
226
229
|
end
|
|
@@ -21,7 +21,7 @@ class CArray
|
|
|
21
21
|
# @return [CArray] grown copy.
|
|
22
22
|
# @raise [ArgumentError] on `ndim` mismatch or out-of-range
|
|
23
23
|
# offset / size.
|
|
24
|
-
def insert_block
|
|
24
|
+
def insert_block(offset, bsize, &block)
|
|
25
25
|
if offset.size != ndim or bsize.size != ndim
|
|
26
26
|
raise ArgumentError, "ndim mismatch"
|
|
27
27
|
end
|
|
@@ -68,7 +68,7 @@ class CArray
|
|
|
68
68
|
# @return [CArray] shrunk copy.
|
|
69
69
|
# @raise [ArgumentError] on `ndim` mismatch or out-of-range
|
|
70
70
|
# offset / size.
|
|
71
|
-
def delete_block
|
|
71
|
+
def delete_block(offset, bsize)
|
|
72
72
|
if offset.size != ndim or bsize.size != ndim
|
|
73
73
|
raise ArgumentError, "ndim mismatch"
|
|
74
74
|
end
|
|
@@ -23,11 +23,13 @@ class CArray
|
|
|
23
23
|
# Bounds the wrong way round (`lo > hi`) contain nothing.
|
|
24
24
|
# @param lo [Object, nil] the lower bound.
|
|
25
25
|
# @param hi [Object, nil] the upper bound.
|
|
26
|
-
# @param exclude [nil, :lower, :upper, :both] the bounds left out
|
|
26
|
+
# @param exclude [nil, :lower, :upper, :both] the bounds left out; by
|
|
27
|
+
# default none, so the interval holds both bounds (a key window, which
|
|
28
|
+
# cuts a key into windows, leaves out its lower end by default).
|
|
27
29
|
# @return [CArray] boolean, the shape of `self`.
|
|
28
30
|
# @raise [ArgumentError] when neither bound is given, `exclude:` is not one
|
|
29
|
-
# of the
|
|
30
|
-
def is_between
|
|
31
|
+
# of the four, or a Range comes with a second bound or `exclude:`.
|
|
32
|
+
def is_between(*bounds, exclude: nil)
|
|
31
33
|
if bounds.size == 1 && bounds[0].is_a?(Range)
|
|
32
34
|
unless exclude.nil?
|
|
33
35
|
raise ArgumentError,
|
|
@@ -44,7 +46,7 @@ class CArray
|
|
|
44
46
|
end
|
|
45
47
|
unless [nil, :lower, :upper, :both].include?(exclude)
|
|
46
48
|
raise ArgumentError,
|
|
47
|
-
"is_between: exclude: must be :lower, :upper or :both (got #{exclude.inspect})"
|
|
49
|
+
"is_between: exclude: must be nil, :lower, :upper or :both (got #{exclude.inspect})"
|
|
48
50
|
end
|
|
49
51
|
if lo.nil? && hi.nil?
|
|
50
52
|
raise ArgumentError, "is_between: give at least one bound"
|