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
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
# padded entity is built (unlike CAWindowIterator) and the interior stays on
|
|
25
25
|
# the source buffer.
|
|
26
26
|
#
|
|
27
|
-
# The remainder is not the user's concern. There is no boundary-policy
|
|
27
|
+
# The remainder is not the user's concern. There is no boundary-policy option:
|
|
28
28
|
# the sole behaviour is full coverage — every cell belongs to a tile, the
|
|
29
29
|
# edge tiles simply fold whatever cells are present (present-only), and the
|
|
30
30
|
# output is the ceil tile grid. A partial edge tile carries fewer real cells,
|
|
@@ -59,14 +59,13 @@ class CABlockIterator < CAIterator
|
|
|
59
59
|
|
|
60
60
|
# @overload initialize(source, *blocks)
|
|
61
61
|
# Builds a block iterator tiling `source` with a per-axis tile size. Each
|
|
62
|
-
# `blocks[i]` is
|
|
63
|
-
#
|
|
64
|
-
#
|
|
65
|
-
# argument is taken as the per-axis size list.
|
|
62
|
+
# `blocks[i]` is an Integer tile size; the tiles start at index 0. A
|
|
63
|
+
# single Array argument is taken as the per-axis size list. To start the
|
|
64
|
+
# tiles elsewhere, slice first: `a[2..-1].blocks(3)`.
|
|
66
65
|
#
|
|
67
66
|
# @param source [CArray] the array to tile.
|
|
68
|
-
# @param blocks [Array<Integer
|
|
69
|
-
def initialize
|
|
67
|
+
# @param blocks [Array<Integer>] per-axis tile sizes.
|
|
68
|
+
def initialize(source, *blocks)
|
|
70
69
|
blocks = blocks[0] if blocks.size == 1 && blocks[0].is_a?(Array)
|
|
71
70
|
|
|
72
71
|
unless blocks.size == source.ndim
|
|
@@ -76,38 +75,32 @@ class CABlockIterator < CAIterator
|
|
|
76
75
|
end
|
|
77
76
|
# Each tile is read through a view with one axis per tile position and
|
|
78
77
|
# one per cell in the tile, twice the source's rank.
|
|
79
|
-
if 2 * source.ndim >
|
|
78
|
+
if 2 * source.ndim > CArray::RANK_MAX
|
|
80
79
|
raise ArgumentError,
|
|
81
80
|
"blocks: a rank #{source.ndim} array would need #{2 * source.ndim} " \
|
|
82
|
-
"axes for its tiles, beyond the limit of #{
|
|
83
|
-
"blocks works up to rank #{
|
|
81
|
+
"axes for its tiles, beyond the limit of #{CArray::RANK_MAX}; " \
|
|
82
|
+
"blocks works up to rank #{CArray::RANK_MAX / 2}"
|
|
84
83
|
end
|
|
85
84
|
|
|
86
85
|
@sndim = source.ndim
|
|
87
|
-
offsets = Array.new(@sndim, 0)
|
|
88
86
|
@sizes = Array.new(@sndim)
|
|
89
87
|
blocks.each_with_index do |b, i|
|
|
90
88
|
if b.is_a?(Range)
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
raise TypeError,
|
|
90
|
+
"blocks: a tile size must be an Integer (got #{b.inspect}); " \
|
|
91
|
+
"to start the tiles elsewhere, slice first: a[2..-1].blocks(3)"
|
|
92
|
+
elsif b.is_a?(Integer)
|
|
93
|
+
@sizes[i] = b
|
|
93
94
|
else
|
|
94
|
-
|
|
95
|
+
raise TypeError, "blocks: a tile size must be an Integer (got #{b.class})"
|
|
95
96
|
end
|
|
96
97
|
if @sizes[i] < 1
|
|
97
98
|
raise ArgumentError, "blocks: tile size on axis #{i} must be >= 1"
|
|
98
99
|
end
|
|
99
100
|
end
|
|
100
101
|
|
|
101
|
-
#
|
|
102
|
-
|
|
103
|
-
@source =
|
|
104
|
-
if source.scalar?
|
|
105
|
-
source.flatten # a CScalar takes no index; its one-cell view does
|
|
106
|
-
elsif offsets.all?(&:zero?)
|
|
107
|
-
source
|
|
108
|
-
else
|
|
109
|
-
source[*offsets.map { |o| o..-1 }]
|
|
110
|
-
end
|
|
102
|
+
# A CScalar takes no index; its one-cell view does.
|
|
103
|
+
@source = source.scalar? ? source.flatten : source
|
|
111
104
|
|
|
112
105
|
n = @source.shape
|
|
113
106
|
@q = @sndim.times.map { |i| n[i] / @sizes[i] } # full tiles per axis
|
|
@@ -122,11 +115,6 @@ class CABlockIterator < CAIterator
|
|
|
122
115
|
self
|
|
123
116
|
end
|
|
124
117
|
|
|
125
|
-
# @overload source
|
|
126
|
-
# Returns the array being tiled (with any leading offset already applied).
|
|
127
|
-
# @return [CArray]
|
|
128
|
-
attr_reader :source
|
|
129
|
-
|
|
130
118
|
# ---- region decomposition ---------------------------------------------
|
|
131
119
|
#
|
|
132
120
|
# The tile grid splits into regions by whether each axis sits on its interior
|
|
@@ -208,17 +196,17 @@ class CABlockIterator < CAIterator
|
|
|
208
196
|
# assembling the Face itself would copy its surface bytes into an array that
|
|
209
197
|
# no longer knows it is one. A CAConstString's storage points into its own
|
|
210
198
|
# buffer, which the regions do not share, so it is assembled as strings.
|
|
211
|
-
def face_grid_part
|
|
199
|
+
def face_grid_part(r)
|
|
212
200
|
r.is_a?(CAConstString) ? r.to_string.parent : r.parent
|
|
213
201
|
end
|
|
214
202
|
|
|
215
|
-
def face_grid
|
|
203
|
+
def face_grid(grid, face)
|
|
216
204
|
return CArray.const_string(grid, encoding: face.encoding) if face.is_a?(CAConstString)
|
|
217
|
-
grid.face_lift
|
|
205
|
+
grid.send(:face_lift, face)
|
|
218
206
|
end
|
|
219
207
|
|
|
220
208
|
# Fold every region with a single core reduction `op` (the tier-1 shape).
|
|
221
|
-
def fold
|
|
209
|
+
def fold(op, **kw)
|
|
222
210
|
assemble { |view, _tiles| view.public_send(op, axis: @tile_axes, **kw) }
|
|
223
211
|
end
|
|
224
212
|
|
|
@@ -316,7 +304,7 @@ class CABlockIterator < CAIterator
|
|
|
316
304
|
[:sum, :accumulate, :prod, :mean, :min, :max, :variance, :stddev,
|
|
317
305
|
:variancep, :stddevp], :fold_reduction)
|
|
318
306
|
|
|
319
|
-
private def fold_reduction
|
|
307
|
+
private def fold_reduction(op, min_count: nil, fill_value: nil)
|
|
320
308
|
if FACE_WINNER_INDEX.key?(op) && @source.face?
|
|
321
309
|
return face_winner(FACE_WINNER_INDEX[op], min_count, fill_value)
|
|
322
310
|
end
|
|
@@ -328,8 +316,8 @@ class CABlockIterator < CAIterator
|
|
|
328
316
|
|
|
329
317
|
CArray.send(:define_named_methods, self, [:all, :any], :fold_with_keywords)
|
|
330
318
|
|
|
331
|
-
private def fold_with_keywords
|
|
332
|
-
fold(op, **CAIterator.reduce_keywords
|
|
319
|
+
private def fold_with_keywords(op, **kw)
|
|
320
|
+
fold(op, **CAIterator.send(:reduce_keywords, op, kw))
|
|
333
321
|
end
|
|
334
322
|
|
|
335
323
|
# @!method first
|
|
@@ -362,35 +350,28 @@ class CABlockIterator < CAIterator
|
|
|
362
350
|
# partial edge tile); `count(UNDEF)` counts masked cells; `count(v)` counts
|
|
363
351
|
# cells equal to `v`.
|
|
364
352
|
# @return [CArray] tile-grid shaped
|
|
365
|
-
def count
|
|
353
|
+
def count(*args, **kw)
|
|
366
354
|
return count_not_masked(**kw) if args.empty?
|
|
367
|
-
kw = CAIterator.
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
# block_view is a CAStride, so #count is not shadowed; dispatch
|
|
372
|
-
# CArray#count explicitly anyway, matching the family regularity.
|
|
373
|
-
red = CArray.instance_method(:count).bind_call(view, *args, axis: @tile_axes, **kw)
|
|
374
|
-
out ||= CArray.new(red.data_type, @shape, bytes: red.bytes)
|
|
375
|
-
out[*out_ranges] = red
|
|
376
|
-
end
|
|
377
|
-
out
|
|
355
|
+
kw = CAIterator.send(:reduce_keywords, :count, kw)
|
|
356
|
+
# block_view is a CAStride, so #count is not shadowed; dispatch
|
|
357
|
+
# CArray#count explicitly anyway, matching the family regularity.
|
|
358
|
+
assemble { |view, _| count_cells(view, *args, axis: @tile_axes, **kw) }
|
|
378
359
|
end
|
|
379
360
|
|
|
380
361
|
# @overload count_not_masked
|
|
381
362
|
# Per-tile count of present (non-masked) cells. For a partial edge tile
|
|
382
363
|
# this is the real cell count (the OOB cells are not present).
|
|
383
364
|
# @return [CArray]
|
|
384
|
-
def count_not_masked
|
|
385
|
-
fold(:count_not_masked, **CAIterator.
|
|
365
|
+
def count_not_masked(**kw)
|
|
366
|
+
fold(:count_not_masked, **CAIterator.send(:reduce_keywords, :count_not_masked, kw))
|
|
386
367
|
end
|
|
387
368
|
|
|
388
369
|
# @overload count_masked
|
|
389
370
|
# Per-tile count of masked cells. Equals `elements - count_not_masked`;
|
|
390
371
|
# the OOB cells of a partial edge tile count here.
|
|
391
372
|
# @return [CArray]
|
|
392
|
-
def count_masked
|
|
393
|
-
kw = CAIterator.
|
|
373
|
+
def count_masked(**kw)
|
|
374
|
+
kw = CAIterator.send(:reduce_keywords, :count_masked, kw)
|
|
394
375
|
need = CArray.__present_cells_needed_per_result_cell__(:count_masked, kw[:min_count], 0)
|
|
395
376
|
out = elements - count_not_masked
|
|
396
377
|
# A count of the mask reads every cell of the tile.
|
|
@@ -416,7 +397,7 @@ class CABlockIterator < CAIterator
|
|
|
416
397
|
# @overload minmax(min_count: nil, fill_value: nil)
|
|
417
398
|
# Per-tile `[min, max]` (two tile-grid-shaped CArrays, a single fused pass).
|
|
418
399
|
# @return [Array<CArray>]
|
|
419
|
-
def minmax
|
|
400
|
+
def minmax(min_count: nil, fill_value: nil)
|
|
420
401
|
if @source.face?
|
|
421
402
|
return [min(min_count: min_count, fill_value: fill_value),
|
|
422
403
|
max(min_count: min_count, fill_value: fill_value)]
|
|
@@ -428,17 +409,21 @@ class CABlockIterator < CAIterator
|
|
|
428
409
|
end
|
|
429
410
|
|
|
430
411
|
# @!method min_index
|
|
431
|
-
# Per-tile position of the minimum, as a flat index within the tile
|
|
432
|
-
# partial edge tile
|
|
412
|
+
# Per-tile position of the minimum, as a flat index within the tile. A
|
|
413
|
+
# partial edge tile is indexed as a full tile, the shape {#each} yields,
|
|
414
|
+
# so every index unravels by the same tile shape.
|
|
433
415
|
# @return [CArray] tile-grid shaped
|
|
434
416
|
# @!method max_index
|
|
435
417
|
# Per-tile position of the maximum (tile-local flat index).
|
|
436
418
|
# @return [CArray]
|
|
437
419
|
[:min_index, :max_index].each do |op|
|
|
438
420
|
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
439
|
-
def #{op}
|
|
440
|
-
kw = CAIterator.reduce_keywords
|
|
441
|
-
|
|
421
|
+
def #{op}(**kw)
|
|
422
|
+
kw = CAIterator.send(:reduce_keywords, :#{op}, kw)
|
|
423
|
+
# fill_value: is not a position, so it is put in after the move.
|
|
424
|
+
fill = kw.delete(:fill_value)
|
|
425
|
+
out = assemble { |view, tiles| full_tile_index(view.#{op}(axis: @tile_axes, **kw), tiles) }
|
|
426
|
+
CArray.__fill_undefined_result_cells__(out, fill)
|
|
442
427
|
end
|
|
443
428
|
RUBY
|
|
444
429
|
end
|
|
@@ -449,19 +434,19 @@ class CABlockIterator < CAIterator
|
|
|
449
434
|
# minima. Unlike `min_index` (the tile-local position) this indexes back
|
|
450
435
|
# into the original array. An all-masked tile is a masked cell.
|
|
451
436
|
# @return [CArray] tile-grid shaped int64
|
|
452
|
-
def min_addr
|
|
437
|
+
def min_addr(**kw); winner_addr(:min_index, kw); end
|
|
453
438
|
|
|
454
439
|
# @overload max_addr
|
|
455
440
|
# Per-tile flat source address of the maximum. See {#min_addr}.
|
|
456
441
|
# @return [CArray] tile-grid shaped int64
|
|
457
|
-
def max_addr
|
|
442
|
+
def max_addr(**kw); winner_addr(:max_index, kw); end
|
|
458
443
|
|
|
459
444
|
private
|
|
460
445
|
|
|
461
446
|
# Per-tile minimum or maximum of a Face source, gathered from the source by
|
|
462
447
|
# the winner's address so the result is the Face itself. An all-masked tile,
|
|
463
448
|
# and with `min_count` a tile with too few present cells, is a masked cell.
|
|
464
|
-
def face_winner
|
|
449
|
+
def face_winner(idx_op, min_count, fill_value)
|
|
465
450
|
addr = winner_addr(idx_op)
|
|
466
451
|
need = CArray.__present_cells_needed_per_result_cell__(idx_op == :min_index ? :min : :max, min_count, 0)
|
|
467
452
|
addr[count_not_masked.lt(need)] = UNDEF if need > 0
|
|
@@ -477,16 +462,38 @@ class CABlockIterator < CAIterator
|
|
|
477
462
|
return src[addr.strip_mask(hole[0])].copy
|
|
478
463
|
end
|
|
479
464
|
out = src[addr.strip_mask(0)].copy
|
|
465
|
+
unless out.__send__(:holds_new_values?)
|
|
466
|
+
# A const string's cells are written as Strings and packed again.
|
|
467
|
+
text = out.to_string
|
|
468
|
+
text[empty] = fill_value.nil? ? UNDEF : fill_value
|
|
469
|
+
return text.to_const_string
|
|
470
|
+
end
|
|
480
471
|
out[empty] = fill_value.nil? ? UNDEF : fill_value
|
|
481
472
|
out
|
|
482
473
|
end
|
|
483
474
|
|
|
475
|
+
# A flat index within a cut tile of shape `tiles`, as the flat index of the
|
|
476
|
+
# same cell within a full tile. Masked indices stay masked.
|
|
477
|
+
def full_tile_index(idx, tiles)
|
|
478
|
+
return idx if tiles == @sizes
|
|
479
|
+
rest = idx
|
|
480
|
+
full = nil
|
|
481
|
+
stride = 1
|
|
482
|
+
(@sndim - 1).downto(0) do |i|
|
|
483
|
+
coord = rest % tiles[i]
|
|
484
|
+
rest = rest / tiles[i]
|
|
485
|
+
full = full.nil? ? coord * stride : full + coord * stride
|
|
486
|
+
stride *= @sizes[i]
|
|
487
|
+
end
|
|
488
|
+
full
|
|
489
|
+
end
|
|
490
|
+
|
|
484
491
|
# Per-tile source address of the winner. The tile-local flat index (min_index /
|
|
485
492
|
# max_index) is looked up in a source-address companion tiled the same way, so
|
|
486
493
|
# the tile geometry is reused rather than recomputed. An all-masked tile yields
|
|
487
494
|
# a masked index; it is gathered at 0 and re-masked in the result.
|
|
488
|
-
def winner_addr
|
|
489
|
-
kw = CAIterator.reduce_keywords
|
|
495
|
+
def winner_addr(idx_op, kw = {})
|
|
496
|
+
kw = CAIterator.send(:reduce_keywords, idx_op, kw)
|
|
490
497
|
saddr = CArray.int64(*@source.shape).seq!
|
|
491
498
|
out = nil
|
|
492
499
|
each_region do |strip_ranges, tiles, out_ranges|
|
|
@@ -516,9 +523,11 @@ class CABlockIterator < CAIterator
|
|
|
516
523
|
# `source.reshape(source.elements)[bi.sort_addr]` is the source sorted within
|
|
517
524
|
# each tile. Multi-axis tiles are flattened (as for the order statistics). A
|
|
518
525
|
# partial edge tile sorts only its present cells. Masked values sort to the
|
|
519
|
-
# tail of their tile (as `CArray#sort`)
|
|
526
|
+
# tail of their tile (as `CArray#sort`), or to the head with
|
|
527
|
+
# `masked_position: :first`.
|
|
528
|
+
# @param masked_position [Symbol] `:last` (default) or `:first`.
|
|
520
529
|
# @return [CArray] source-shaped int64
|
|
521
|
-
def sort_addr
|
|
530
|
+
def sort_addr(masked_position: :last)
|
|
522
531
|
saddr = CArray.int64(*@source.shape).seq!
|
|
523
532
|
out = CArray.int64(*@source.shape)
|
|
524
533
|
out[] = UNDEF
|
|
@@ -527,7 +536,8 @@ class CABlockIterator < CAIterator
|
|
|
527
536
|
sview = saddr[*strip_ranges].block_view(*tiles)
|
|
528
537
|
grid = (0...@sndim).map { |i| vview.shape[i] }
|
|
529
538
|
cells = tiles.inject(1) { |p, t| p * t }
|
|
530
|
-
order = vview.copy.reshape(*(grid + [cells]))
|
|
539
|
+
order = vview.copy.reshape(*(grid + [cells]))
|
|
540
|
+
.sort_index(axis: @sndim, masked_position: masked_position)
|
|
531
541
|
src_sorted = sview.reshape(*(grid + [cells])).take_along_axis(order, axis: @sndim)
|
|
532
542
|
out[*strip_ranges].block_view(*tiles)[] = src_sorted.reshape(*(grid + tiles))
|
|
533
543
|
end
|
|
@@ -538,16 +548,20 @@ class CABlockIterator < CAIterator
|
|
|
538
548
|
# Per-tile weighted sum; `weights` is shaped like one full tile (`Π b_i`).
|
|
539
549
|
# At a partial edge tile the weight kernel is sliced to the present cells.
|
|
540
550
|
# @return [CArray]
|
|
541
|
-
|
|
542
|
-
|
|
551
|
+
# @raise [TypeError] when `weights` is a number, not one weight per
|
|
552
|
+
# cell of a tile.
|
|
553
|
+
def wsum(weights, **kw)
|
|
554
|
+
kw = CAIterator.send(:reduce_keywords, :wsum, kw)
|
|
543
555
|
weighted(weights) { |view, w| view.wsum(w, axis: @tile_axes, **kw) }
|
|
544
556
|
end
|
|
545
557
|
|
|
546
558
|
# @overload wmean(weights)
|
|
547
559
|
# Per-tile weighted mean; `weights` shaped like one full tile.
|
|
548
560
|
# @return [CArray]
|
|
549
|
-
|
|
550
|
-
|
|
561
|
+
# @raise [TypeError] when `weights` is a number, not one weight per
|
|
562
|
+
# cell of a tile.
|
|
563
|
+
def wmean(weights, **kw)
|
|
564
|
+
kw = CAIterator.send(:reduce_keywords, :wmean, kw)
|
|
551
565
|
weighted(weights) { |view, w| view.wmean(w, axis: @tile_axes, **kw) }
|
|
552
566
|
end
|
|
553
567
|
|
|
@@ -555,7 +569,9 @@ class CABlockIterator < CAIterator
|
|
|
555
569
|
|
|
556
570
|
# Broadcast a full-tile weight kernel over each region (sliced to the region's
|
|
557
571
|
# possibly-ragged tile) and yield (view, broadcast weights) for the reduction.
|
|
558
|
-
def weighted
|
|
572
|
+
def weighted(weights)
|
|
573
|
+
CArray.send(:refuse_ruby_array, "wsum/wmean", "a weight array") if weights.is_a?(Array)
|
|
574
|
+
CArray.send(:refuse_scalar_weights, "wsum/wmean", "a tile") if weights.is_a?(Numeric)
|
|
559
575
|
unless weights.shape == @sizes
|
|
560
576
|
raise ArgumentError,
|
|
561
577
|
"wsum/wmean: weights shape #{weights.shape.inspect} != " \
|
|
@@ -582,25 +598,30 @@ class CABlockIterator < CAIterator
|
|
|
582
598
|
|
|
583
599
|
# @overload median
|
|
584
600
|
# Per-tile median. @return [CArray]
|
|
585
|
-
def median
|
|
586
|
-
kw = CAIterator.
|
|
601
|
+
def median(**kw)
|
|
602
|
+
kw = CAIterator.send(:reduce_keywords, :median, kw)
|
|
587
603
|
order_stat { |v, axis| v.median(axis: axis, **kw) }
|
|
588
604
|
end
|
|
589
605
|
|
|
590
|
-
# @overload percentile(
|
|
591
|
-
# Per-tile percentile(s)
|
|
592
|
-
# of CArrays
|
|
606
|
+
# @overload percentile(p)
|
|
607
|
+
# Per-tile percentile(s), in the form `CArray#percentile` returns: one p
|
|
608
|
+
# gives one CArray, an Array of p an Array of CArrays, and several p
|
|
609
|
+
# (or a CArray of p) one CArray with the p axes in front.
|
|
593
610
|
# @return [CArray, Array<CArray>]
|
|
594
|
-
def percentile
|
|
595
|
-
kw = CAIterator.
|
|
596
|
-
|
|
611
|
+
def percentile(*pers, **kw)
|
|
612
|
+
kw = CAIterator.send(:reduce_keywords, :percentile, kw)
|
|
613
|
+
list, form = CArray.send(:percentile_arguments, pers)
|
|
614
|
+
answers = order_stat { |v, axis| v.percentile(list, axis: axis, **kw) }
|
|
615
|
+
CArray.send(:percentile_answer, answers, form)
|
|
597
616
|
end
|
|
598
617
|
|
|
599
618
|
# @overload quantile
|
|
600
619
|
# Per-tile five-number summary `[min, Q1, median, Q3, max]` (five CArrays).
|
|
601
620
|
# @return [Array<CArray>]
|
|
602
|
-
def quantile
|
|
603
|
-
|
|
621
|
+
def quantile(*args, **kw)
|
|
622
|
+
CAIterator.send(:refuse_quantile_arguments, args)
|
|
623
|
+
kw = CAIterator.send(:reduce_keywords, :quantile, kw)
|
|
624
|
+
order_stat { |v, axis| v.quantile(axis: axis, **kw) }
|
|
604
625
|
end
|
|
605
626
|
|
|
606
627
|
private
|
|
@@ -608,7 +629,7 @@ class CABlockIterator < CAIterator
|
|
|
608
629
|
# Drive an order statistic (yielded as `block.call(view, axis)`) per region:
|
|
609
630
|
# a 1-D tile passes the tile axis straight through; a multi-axis tile is
|
|
610
631
|
# materialized (peak O(region cells)) and its tile axes flattened into one.
|
|
611
|
-
def order_stat
|
|
632
|
+
def order_stat(&op)
|
|
612
633
|
assemble do |view, tiles|
|
|
613
634
|
if @sndim == 1
|
|
614
635
|
op.call(view, @tile_axes[0])
|
|
@@ -652,11 +673,15 @@ class CABlockIterator < CAIterator
|
|
|
652
673
|
# @yieldparam tile [CArray]
|
|
653
674
|
# @return [CArray] tile-grid shaped
|
|
654
675
|
# @overload reduce(init) { |acc, elem| ... }
|
|
655
|
-
# Per-tile fiber fold: each tile's cells are folded element by
|
|
656
|
-
# `init` (masked
|
|
676
|
+
# Per-tile fiber fold: each tile's present cells are folded element by
|
|
677
|
+
# element from a copy of `init` (`init.dup`). A masked cell and a cell
|
|
678
|
+
# past the edge are not passed; a tile with none present answers `init`.
|
|
657
679
|
# @param init [Object] initial accumulator.
|
|
658
680
|
# @return [CArray]
|
|
659
|
-
def reduce
|
|
681
|
+
def reduce(*args, data_type: nil, &blk)
|
|
682
|
+
if args.size > 1
|
|
683
|
+
raise ArgumentError, "reduce: wrong number of arguments (given #{args.size}, expected 0..1)"
|
|
684
|
+
end
|
|
660
685
|
raise LocalJumpError, "no block given (yield)" unless blk
|
|
661
686
|
out = CArray.new(data_type || CA_OBJECT, @shape)
|
|
662
687
|
tgv = tile_grid_view
|
|
@@ -666,8 +691,8 @@ class CABlockIterator < CAIterator
|
|
|
666
691
|
else
|
|
667
692
|
init = args[0]
|
|
668
693
|
CArray.each_index(*@shape) do |*g|
|
|
669
|
-
acc = init
|
|
670
|
-
tgv[*g, *nils].each { |e| acc = blk.call(acc, e) }
|
|
694
|
+
acc = init.dup
|
|
695
|
+
tgv[*g, *nils].each { |e| acc = blk.call(acc, e) unless UNDEF.equal?(e) }
|
|
671
696
|
out[*g] = acc
|
|
672
697
|
end
|
|
673
698
|
end
|
|
@@ -681,15 +706,24 @@ class CABlockIterator < CAIterator
|
|
|
681
706
|
# into a source-shaped CArray (the out-of-bounds cells of a partial edge
|
|
682
707
|
# tile are dropped). Well-defined because tiles do not overlap; the source
|
|
683
708
|
# is not modified (a new array is returned). Without a block, an Enumerator.
|
|
709
|
+
# The result has the source's data type; a Face source gives a result of
|
|
710
|
+
# the same Face, and a read-only Face (a categorical, a const string) an
|
|
711
|
+
# object array of its surface values.
|
|
684
712
|
# @yieldparam tile [CArray]
|
|
685
713
|
# @return [CArray, Enumerator] source-shaped
|
|
686
714
|
def map
|
|
687
715
|
return to_enum(:map) unless block_given?
|
|
688
|
-
|
|
716
|
+
src = padded_source
|
|
717
|
+
surface = src.face? && !src.__send__(:holds_new_values?)
|
|
718
|
+
pout = surface ? CArray.new(CA_OBJECT, src.shape) : src.__send__(:blank_like, src.shape)
|
|
689
719
|
pgv = pout.block_view(*@sizes)
|
|
690
720
|
tgv = tile_grid_view
|
|
691
721
|
nils = Array.new(@sndim, nil)
|
|
692
|
-
CArray.each_index(*@shape) { |*g|
|
|
722
|
+
CArray.each_index(*@shape) { |*g|
|
|
723
|
+
tile = yield(tgv[*g, *nils])
|
|
724
|
+
tile = tile.to_a if surface && tile.is_a?(CArray) && tile.face?
|
|
725
|
+
pgv[*g, *nils] = tile
|
|
726
|
+
}
|
|
693
727
|
pout[*@sndim.times.map { |i| 0...@source.shape[i] }].copy
|
|
694
728
|
end
|
|
695
729
|
|
|
@@ -725,7 +759,7 @@ class CABlockIterator < CAIterator
|
|
|
725
759
|
[:cumsum, :cumprod, :cummax, :cummin, :cumcount], :scan_tiles)
|
|
726
760
|
|
|
727
761
|
# A scan takes no arguments here.
|
|
728
|
-
private def scan_tiles
|
|
762
|
+
private def scan_tiles(op, *args)
|
|
729
763
|
unless args.empty?
|
|
730
764
|
raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 0)"
|
|
731
765
|
end
|
|
@@ -737,7 +771,7 @@ class CABlockIterator < CAIterator
|
|
|
737
771
|
# UNDEF where the tile has none, so a lag never reaches into another
|
|
738
772
|
# tile. A partial edge tile counts only the cells it has.
|
|
739
773
|
# @return [CArray] source-shaped
|
|
740
|
-
def lag
|
|
774
|
+
def lag(n = 1)
|
|
741
775
|
unless n.is_a?(Integer)
|
|
742
776
|
raise TypeError, "lag: n must be an Integer (got #{n.class})"
|
|
743
777
|
end
|
|
@@ -746,22 +780,22 @@ class CABlockIterator < CAIterator
|
|
|
746
780
|
|
|
747
781
|
# @overload strip_mask(method:)
|
|
748
782
|
# Per-tile fill of the masked cells, counting the tile's cells row-major:
|
|
749
|
-
# `:forward`
|
|
783
|
+
# `:forward` or `:backward`. A fill never reaches
|
|
750
784
|
# into another tile, so a masked cell with nothing to carry in its tile
|
|
751
785
|
# stays masked.
|
|
752
786
|
# @return [CArray] source-shaped
|
|
753
|
-
def strip_mask
|
|
754
|
-
CAIterator.hold_backward
|
|
787
|
+
def strip_mask(method:)
|
|
788
|
+
CAIterator.send(:hold_backward?, method)
|
|
755
789
|
tile_wise { |rows, axis| rows.strip_mask(method: method, axis: axis) }
|
|
756
790
|
end
|
|
757
791
|
|
|
758
|
-
# @overload
|
|
792
|
+
# @overload rank_index(descending: false, method: :ordinal, kind: :quick)
|
|
759
793
|
# Per-tile rank of each cell among the tile's cells (int64, `0` the
|
|
760
|
-
# smallest), as `CArray#
|
|
761
|
-
# the cells it has. The keywords are those of `CArray#
|
|
794
|
+
# smallest), as `CArray#rank_index` ranks them; a partial edge tile ranks only
|
|
795
|
+
# the cells it has. The keywords are those of `CArray#rank_index`.
|
|
762
796
|
# @return [CArray] source-shaped
|
|
763
|
-
def
|
|
764
|
-
tile_wise { |rows, axis| rows.
|
|
797
|
+
def rank_index(**kw)
|
|
798
|
+
tile_wise { |rows, axis| rows.rank_index(axis: axis, **kw) }
|
|
765
799
|
end
|
|
766
800
|
|
|
767
801
|
private
|
|
@@ -788,7 +822,7 @@ class CABlockIterator < CAIterator
|
|
|
788
822
|
# scatter back to a source-shaped result. The output data type is taken from the
|
|
789
823
|
# first tile's scan (all tiles share it); the padded margin is UNDEF and the
|
|
790
824
|
# OOB cells of a partial edge tile are cropped from the result.
|
|
791
|
-
def block_scan
|
|
825
|
+
def block_scan(op, *args)
|
|
792
826
|
tgv = tile_grid_view
|
|
793
827
|
nils = Array.new(@sndim, nil)
|
|
794
828
|
pout = nil
|
|
@@ -797,20 +831,23 @@ class CABlockIterator < CAIterator
|
|
|
797
831
|
tile = tgv[*g, *nils]
|
|
798
832
|
scanned = tile.copy.reshape(tile.elements).public_send(op, *args).reshape(*@sizes)
|
|
799
833
|
unless pout
|
|
800
|
-
pout =
|
|
834
|
+
pout = scanned.face? ? scanned.__send__(:blank_like, padded_source.shape) :
|
|
835
|
+
CArray.new(scanned.data_type, padded_source.shape, bytes: scanned.bytes)
|
|
801
836
|
pout[] = UNDEF
|
|
802
837
|
pgv = pout.block_view(*@sizes)
|
|
803
838
|
end
|
|
804
839
|
pgv[*g, *nils] = scanned
|
|
805
840
|
end
|
|
841
|
+
# a source with no cells has no tile; its own scan gives the type
|
|
842
|
+
return @source.copy.reshape(@source.elements).public_send(op, *args).reshape(*@source.shape) unless pout
|
|
806
843
|
pout[*@sndim.times.map { |i| 0...@source.shape[i] }].copy
|
|
807
844
|
end
|
|
808
845
|
|
|
809
846
|
# A source-shaped array that can hold what #tile_wise gives: of its kind,
|
|
810
|
-
# or an object array for a
|
|
811
|
-
# cell.
|
|
812
|
-
def tile_output
|
|
813
|
-
if lagged.face? && lagged.
|
|
847
|
+
# or an object array for a Face that holds no new value, which cannot be
|
|
848
|
+
# written cell by cell.
|
|
849
|
+
def tile_output(lagged)
|
|
850
|
+
if lagged.face? && !lagged.__send__(:holds_new_values?)
|
|
814
851
|
CArray.object(*@source.shape)
|
|
815
852
|
else
|
|
816
853
|
lagged.__send__(:blank_like, @source.shape)
|
|
@@ -819,7 +856,7 @@ class CABlockIterator < CAIterator
|
|
|
819
856
|
|
|
820
857
|
# The values as +out+ can hold them: a Face going into an object array
|
|
821
858
|
# goes as its surface values, not its storage.
|
|
822
|
-
def tile_values
|
|
859
|
+
def tile_values(out, lagged)
|
|
823
860
|
return lagged unless out.data_type == CA_OBJECT && lagged.face?
|
|
824
861
|
CArray.object(*lagged.shape) { lagged.to_a }
|
|
825
862
|
end
|
|
@@ -834,10 +871,21 @@ class CABlockIterator < CAIterator
|
|
|
834
871
|
if pshape == @source.shape.to_a
|
|
835
872
|
@source
|
|
836
873
|
else
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
874
|
+
interior = @sndim.times.map { |i| 0...@source.shape[i] }
|
|
875
|
+
if @source.face? && !@source.__send__(:holds_new_values?)
|
|
876
|
+
# A Face that holds no new value cannot be written: its storage is
|
|
877
|
+
# padded and the Face put back on.
|
|
878
|
+
storage = @source.__send__(:face_storage)
|
|
879
|
+
pad = CArray.new(storage.data_type, pshape, bytes: storage.bytes)
|
|
880
|
+
pad[] = UNDEF
|
|
881
|
+
pad[*interior] = storage
|
|
882
|
+
pad.send(:face_lift, @source)
|
|
883
|
+
else
|
|
884
|
+
pad = @source.__send__(:blank_like, pshape) # a Face stays one
|
|
885
|
+
pad[] = UNDEF
|
|
886
|
+
pad[*interior] = @source
|
|
887
|
+
pad
|
|
888
|
+
end
|
|
841
889
|
end
|
|
842
890
|
end
|
|
843
891
|
end
|
|
@@ -852,8 +900,8 @@ class CABlockIterator < CAIterator
|
|
|
852
900
|
# place, so the result shows the source's attributes, as CArray#lag and
|
|
853
901
|
# CArray#strip_mask(method:) do.
|
|
854
902
|
prepend(Module.new do
|
|
855
|
-
def lag
|
|
856
|
-
def strip_mask
|
|
903
|
+
def lag(*args, **keywords) = @source.__send__(:carry_attrs, super)
|
|
904
|
+
def strip_mask(**keywords) = @source.__send__(:carry_attrs, super)
|
|
857
905
|
end)
|
|
858
906
|
|
|
859
907
|
read_source_per_call :@padded_source, :@tile_grid_view
|
|
@@ -863,15 +911,15 @@ end
|
|
|
863
911
|
class CArray
|
|
864
912
|
# @overload blocks(*blocks)
|
|
865
913
|
# Returns a {CABlockIterator} tiling `self` with non-overlapping tiles of a
|
|
866
|
-
# per-axis size. Each argument is an Integer tile size
|
|
867
|
-
#
|
|
868
|
-
#
|
|
869
|
-
#
|
|
870
|
-
# @param blocks [Array<Integer
|
|
914
|
+
# per-axis size. Each argument is an Integer tile size; the tiles start
|
|
915
|
+
# at index 0. The remainder is covered by present-only edge tiles (ceil
|
|
916
|
+
# tile grid). Slice first to start the tiles elsewhere
|
|
917
|
+
# (`a[2..-1].blocks(3)`) or to keep only whole tiles.
|
|
918
|
+
# @param blocks [Array<Integer>] per-axis tile sizes.
|
|
871
919
|
# @return [CABlockIterator]
|
|
872
|
-
# @raise [ArgumentError] when `self` has a rank above `
|
|
920
|
+
# @raise [ArgumentError] when `self` has a rank above `CArray::RANK_MAX / 2`
|
|
873
921
|
# (8): the tiles are read through a view of twice the rank.
|
|
874
|
-
def blocks
|
|
922
|
+
def blocks(*blocks)
|
|
875
923
|
CABlockIterator.new(self, *blocks)
|
|
876
924
|
end
|
|
877
925
|
end
|
|
@@ -35,7 +35,8 @@ class CArray
|
|
|
35
35
|
# @param opts [Hash] forwarded to the underlying reduction (`axis:`,
|
|
36
36
|
# `keep_axis:`, ...).
|
|
37
37
|
# @return [Boolean, CArray] a scalar, or an array when an axis is given.
|
|
38
|
-
def any
|
|
38
|
+
def any(skip_masked: true, **opts)
|
|
39
|
+
skip_masked = CArray.send(:bool_arg, skip_masked, "skip_masked", "any")
|
|
39
40
|
return any_skipping_masked(**opts) if skip_masked
|
|
40
41
|
kleene_fold(:any, opts)
|
|
41
42
|
end
|
|
@@ -51,7 +52,8 @@ class CArray
|
|
|
51
52
|
# @param opts [Hash] forwarded to the underlying reduction (`axis:`,
|
|
52
53
|
# `keep_axis:`, ...).
|
|
53
54
|
# @return [Boolean, CArray] a scalar, or an array when an axis is given.
|
|
54
|
-
def all
|
|
55
|
+
def all(skip_masked: true, **opts)
|
|
56
|
+
skip_masked = CArray.send(:bool_arg, skip_masked, "skip_masked", "all")
|
|
55
57
|
return all_skipping_masked(**opts) if skip_masked
|
|
56
58
|
kleene_fold(:all, opts)
|
|
57
59
|
end
|
|
@@ -67,7 +69,8 @@ class CArray
|
|
|
67
69
|
# @param opts [Hash] forwarded to the underlying reduction (`axis:`,
|
|
68
70
|
# `keep_axis:`, ...).
|
|
69
71
|
# @return [Boolean, CArray] a scalar, or an array when an axis is given.
|
|
70
|
-
def none
|
|
72
|
+
def none(skip_masked: true, **opts)
|
|
73
|
+
skip_masked = CArray.send(:bool_arg, skip_masked, "skip_masked", "none")
|
|
71
74
|
return none_skipping_masked(**opts) if skip_masked
|
|
72
75
|
kleene_fold(:none, opts)
|
|
73
76
|
end
|
|
@@ -79,7 +82,7 @@ class CArray
|
|
|
79
82
|
# any, a false for all, a true for none); elsewhere a masked cell leaves the
|
|
80
83
|
# answer undetermined. Going through that reduction checks the data type,
|
|
81
84
|
# the axes and the keywords exactly as `skip_masked: true` does.
|
|
82
|
-
def kleene_fold
|
|
85
|
+
def kleene_fold(kind, opts)
|
|
83
86
|
r = case kind
|
|
84
87
|
when :any then any_skipping_masked(**opts)
|
|
85
88
|
when :all then all_skipping_masked(**opts)
|