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
data/lib/carray/slab_iterator.rb
CHANGED
|
@@ -18,40 +18,30 @@
|
|
|
18
18
|
# `ca[..., :>]` evaluation.
|
|
19
19
|
|
|
20
20
|
class CASlabIterator < CAIterator
|
|
21
|
-
# Built from C via `CASlabIterator.new(
|
|
21
|
+
# Built from C via `CASlabIterator.new(source, slab_axes)`: `source`
|
|
22
22
|
# is the sliced base view (with `:>` axes as full range), `slab_axes` are
|
|
23
23
|
# the positions marked with `:>`.
|
|
24
|
-
def initialize
|
|
25
|
-
@
|
|
24
|
+
def initialize(source, slab_axes)
|
|
25
|
+
@source = source
|
|
26
26
|
@slab_axes = slab_axes
|
|
27
|
-
rdim =
|
|
28
|
-
@outer_positions = (0...
|
|
27
|
+
rdim = source.shape
|
|
28
|
+
@outer_positions = (0...source.ndim).reject { |k| slab_axes.include?(k) }.freeze
|
|
29
29
|
@shape = @outer_positions.map { |k| rdim[k] }
|
|
30
30
|
@ndim = @shape.size
|
|
31
31
|
self
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
# iterators expose theirs as `source`). The base has no common accessor.
|
|
36
|
-
attr_reader :reference, :slab_axes
|
|
37
|
-
|
|
38
|
-
# Slab view at outer index `idx` (Array, length = self.ndim). Returns
|
|
39
|
-
# `@reference[*full_idx]` where slab axes are nil (full range) and
|
|
40
|
-
# outer axes take their values from idx.
|
|
41
|
-
def kernel_at_index (idx)
|
|
42
|
-
full = Array.new(@reference.ndim) # nil at every position
|
|
43
|
-
@outer_positions.each_with_index { |k, i| full[k] = idx[i] }
|
|
44
|
-
@reference[*full]
|
|
45
|
-
end
|
|
34
|
+
attr_reader :slab_axes
|
|
46
35
|
|
|
47
36
|
# @overload each { |slab| ... }
|
|
48
37
|
# Yields each slab as an inner CArray. Without a block, returns
|
|
49
|
-
# an `Enumerator
|
|
38
|
+
# an `Enumerator`.
|
|
50
39
|
# @yieldparam slab [CArray]
|
|
51
40
|
# @return [Enumerator, self]
|
|
52
|
-
def each
|
|
53
|
-
return
|
|
54
|
-
@
|
|
41
|
+
def each(&block)
|
|
42
|
+
return to_enum(:each) unless block
|
|
43
|
+
@source.each_slab(axis: @slab_axes, &block)
|
|
44
|
+
self
|
|
55
45
|
end
|
|
56
46
|
|
|
57
47
|
# @overload map { |slab| ... }
|
|
@@ -60,28 +50,32 @@ class CASlabIterator < CAIterator
|
|
|
60
50
|
# @yieldparam slab [CArray]
|
|
61
51
|
# @yieldreturn [Object] per-slab result.
|
|
62
52
|
# @return [CArray]
|
|
63
|
-
def map
|
|
64
|
-
@
|
|
53
|
+
def map(&block)
|
|
54
|
+
@source.map_slab(axis: @slab_axes, &block)
|
|
65
55
|
end
|
|
66
56
|
|
|
67
|
-
# @overload reduce { |
|
|
68
|
-
#
|
|
69
|
-
#
|
|
70
|
-
#
|
|
71
|
-
#
|
|
72
|
-
# @yieldreturn [Object] updated accumulator.
|
|
73
|
-
# @return [Object]
|
|
74
|
-
# @overload reduce(init) { |acc, slab| ... }
|
|
75
|
-
# @param init [Object] initial accumulator value.
|
|
76
|
-
# @yieldparam acc [Object]
|
|
57
|
+
# @overload reduce(data_type: nil) { |slab| ... }
|
|
58
|
+
# Custom per-slab reduction: the block receives each slab and returns one
|
|
59
|
+
# value for it. The values fill an array of the outer shape, in
|
|
60
|
+
# `:object` cells unless `data_type:` is given, as the other iterators'
|
|
61
|
+
# `reduce` does.
|
|
77
62
|
# @yieldparam slab [CArray]
|
|
78
|
-
# @
|
|
79
|
-
#
|
|
80
|
-
|
|
63
|
+
# @return [CArray]
|
|
64
|
+
# @overload reduce(init, data_type: nil) { |acc, elem| ... }
|
|
65
|
+
# Per-slab element fold: each slab's present cells are folded element by
|
|
66
|
+
# element from a copy of `init` (`init.dup`). A masked cell is not passed;
|
|
67
|
+
# a slab with none present answers `init`.
|
|
68
|
+
# @param init [Object] initial accumulator.
|
|
69
|
+
# @return [CArray]
|
|
70
|
+
def reduce(*args, data_type: nil, &block)
|
|
71
|
+
if args.size > 1
|
|
72
|
+
raise ArgumentError, "reduce: wrong number of arguments (given #{args.size}, expected 0..1)"
|
|
73
|
+
end
|
|
74
|
+
data_type ||= CA_OBJECT
|
|
81
75
|
if args.empty?
|
|
82
|
-
@
|
|
76
|
+
@source.reduce_slab(axis: @slab_axes, data_type: data_type, &block)
|
|
83
77
|
else
|
|
84
|
-
@
|
|
78
|
+
@source.reduce_slab(axis: @slab_axes, init: args[0], data_type: data_type, &block)
|
|
85
79
|
end
|
|
86
80
|
end
|
|
87
81
|
|
|
@@ -89,13 +83,13 @@ class CASlabIterator < CAIterator
|
|
|
89
83
|
#
|
|
90
84
|
# A per-slab reduction that folds each slab to one value is exactly the core
|
|
91
85
|
# per-axis reduction over the slab axes, so every reduction is a direct
|
|
92
|
-
# delegation to `
|
|
86
|
+
# delegation to `source.<op>(axis: slab_axes)`. This inherits the core
|
|
93
87
|
# data type, mask, empty/all-masked (identity vs UNDEF) and epsilon-close
|
|
94
88
|
# contracts unchanged -- there is no separate slab reduction kernel. (Unlike
|
|
95
89
|
# the map / reduce block surface, these are mask-aware: they route through the
|
|
96
90
|
# core reduction, which handles masked sources.)
|
|
97
91
|
|
|
98
|
-
# Each reduction below delegates to `
|
|
92
|
+
# Each reduction below delegates to `source.<op>(axis: slab_axes)`, so it
|
|
99
93
|
# inherits the core data type, mask, empty / all-masked and epsilon-close
|
|
100
94
|
# contracts unchanged. See {CAIterator} for what each one computes.
|
|
101
95
|
#
|
|
@@ -160,16 +154,16 @@ class CASlabIterator < CAIterator
|
|
|
160
154
|
:variancep, :stddevp, :minmax, :min_index, :max_index,
|
|
161
155
|
:min_addr, :max_addr].each do |op|
|
|
162
156
|
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
163
|
-
def #{op}
|
|
164
|
-
@
|
|
157
|
+
def #{op}(min_count: nil, fill_value: nil)
|
|
158
|
+
@source.#{op}(axis: @slab_axes, **reduce_options(min_count, fill_value))
|
|
165
159
|
end
|
|
166
160
|
RUBY
|
|
167
161
|
end
|
|
168
162
|
|
|
169
163
|
[:all, :any].each do |op|
|
|
170
164
|
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
171
|
-
def #{op}
|
|
172
|
-
@
|
|
165
|
+
def #{op}(**kw)
|
|
166
|
+
@source.#{op}(axis: @slab_axes, **CAIterator.send(:reduce_keywords, :#{op}, kw))
|
|
173
167
|
end
|
|
174
168
|
RUBY
|
|
175
169
|
end
|
|
@@ -189,39 +183,39 @@ class CASlabIterator < CAIterator
|
|
|
189
183
|
# These take no `min_count:` or `fill_value:`, as the core ones do not.
|
|
190
184
|
[:first, :last, :nunique].each do |op|
|
|
191
185
|
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
192
|
-
def #{op}
|
|
193
|
-
@
|
|
186
|
+
def #{op}(**kw)
|
|
187
|
+
@source.#{op}(axis: @slab_axes, **CAIterator.send(:reduce_keywords, :#{op}, kw))
|
|
194
188
|
end
|
|
195
189
|
RUBY
|
|
196
190
|
end
|
|
197
191
|
|
|
198
192
|
# @overload count(v = <none>)
|
|
199
|
-
# Per-slab count, delegating to `
|
|
193
|
+
# Per-slab count, delegating to `source.count(..., axis: slab_axes)`.
|
|
200
194
|
# No argument counts present (non-masked) cells; `count(UNDEF)` counts
|
|
201
195
|
# masked cells; `count(v)` counts cells equal to `v`.
|
|
202
196
|
# @return [CArray] one count per slab
|
|
203
|
-
def count
|
|
197
|
+
def count(*args, **kw)
|
|
204
198
|
return count_not_masked(**kw) if args.empty?
|
|
205
|
-
# CABlock / CAWindow shadow #count with a geometry accessor, and @
|
|
199
|
+
# CABlock / CAWindow shadow #count with a geometry accessor, and @source
|
|
206
200
|
# may be such a view, so dispatch CArray#count explicitly for count(v).
|
|
207
|
-
|
|
208
|
-
**CAIterator.
|
|
201
|
+
count_cells(@source, *args, axis: @slab_axes,
|
|
202
|
+
**CAIterator.send(:reduce_keywords, :count, kw))
|
|
209
203
|
end
|
|
210
204
|
|
|
211
205
|
# @overload count_not_masked
|
|
212
206
|
# Per-slab count of present (non-masked) cells.
|
|
213
207
|
# @return [CArray]
|
|
214
|
-
def count_not_masked
|
|
215
|
-
@
|
|
216
|
-
**CAIterator.
|
|
208
|
+
def count_not_masked(**kw)
|
|
209
|
+
@source.count_not_masked(axis: @slab_axes,
|
|
210
|
+
**CAIterator.send(:reduce_keywords, :count_not_masked, kw))
|
|
217
211
|
end
|
|
218
212
|
|
|
219
213
|
# @overload count_masked
|
|
220
214
|
# Per-slab count of masked cells.
|
|
221
215
|
# @return [CArray]
|
|
222
|
-
def count_masked
|
|
223
|
-
@
|
|
224
|
-
**CAIterator.
|
|
216
|
+
def count_masked(**kw)
|
|
217
|
+
@source.count_masked(axis: @slab_axes,
|
|
218
|
+
**CAIterator.send(:reduce_keywords, :count_masked, kw))
|
|
225
219
|
end
|
|
226
220
|
|
|
227
221
|
# @overload elements
|
|
@@ -230,10 +224,10 @@ class CASlabIterator < CAIterator
|
|
|
230
224
|
# space.
|
|
231
225
|
# @return [CArray]
|
|
232
226
|
def elements
|
|
233
|
-
sz = @slab_axes.inject(1) { |p, ax| p * @
|
|
227
|
+
sz = @slab_axes.inject(1) { |p, ax| p * @source.shape[ax] }
|
|
234
228
|
# count_not_masked gives the correct output shape (and, unlike bare #count,
|
|
235
229
|
# is not shadowed by CABlock / CAWindow); overwrite with the constant size.
|
|
236
|
-
out = @
|
|
230
|
+
out = @source.count_not_masked(axis: @slab_axes)
|
|
237
231
|
out[] = sz
|
|
238
232
|
out
|
|
239
233
|
end
|
|
@@ -248,26 +242,28 @@ class CASlabIterator < CAIterator
|
|
|
248
242
|
# @overload median(min_count: nil, fill_value: nil)
|
|
249
243
|
# Per-slab median.
|
|
250
244
|
# @return [CArray]
|
|
251
|
-
def median
|
|
245
|
+
def median(min_count: nil, fill_value: nil)
|
|
252
246
|
opts = reduce_options(min_count, fill_value)
|
|
253
247
|
if @slab_axes.size == 1
|
|
254
|
-
@
|
|
248
|
+
@source.median(axis: @slab_axes[0], **opts)
|
|
255
249
|
else
|
|
256
|
-
@
|
|
250
|
+
@source.reduce_slab(axis: @slab_axes) { |s| s.median(**opts) }
|
|
257
251
|
end
|
|
258
252
|
end
|
|
259
253
|
|
|
260
|
-
# @overload percentile(
|
|
261
|
-
# Per-slab percentile(s)
|
|
262
|
-
#
|
|
254
|
+
# @overload percentile(p, min_count: nil, fill_value: nil)
|
|
255
|
+
# Per-slab percentile(s), in the form `CArray#percentile` returns: one p
|
|
256
|
+
# gives one CArray, an Array of p an Array of CArrays, and several p
|
|
257
|
+
# (or a CArray of p) one CArray with the p axes in front.
|
|
263
258
|
# @return [CArray, Array<CArray>]
|
|
264
|
-
def percentile
|
|
259
|
+
def percentile(*pers, min_count: nil, fill_value: nil)
|
|
265
260
|
opts = reduce_options(min_count, fill_value)
|
|
266
261
|
if @slab_axes.size == 1
|
|
267
|
-
@
|
|
262
|
+
@source.percentile(*pers, axis: @slab_axes[0], **opts)
|
|
268
263
|
else
|
|
269
|
-
|
|
270
|
-
|
|
264
|
+
list, form = CArray.send(:percentile_arguments, pers)
|
|
265
|
+
answers = list.map { |p| @source.reduce_slab(axis: @slab_axes) { |s| s.percentile(p, **opts) } }
|
|
266
|
+
CArray.send(:percentile_answer, answers, form)
|
|
271
267
|
end
|
|
272
268
|
end
|
|
273
269
|
|
|
@@ -275,12 +271,14 @@ class CASlabIterator < CAIterator
|
|
|
275
271
|
# Per-slab five-number summary `[min, Q1, median, Q3, max]` (five CArrays),
|
|
276
272
|
# as `CArray#quantile`.
|
|
277
273
|
# @return [Array<CArray>]
|
|
278
|
-
def quantile
|
|
274
|
+
def quantile(*args, min_count: nil, fill_value: nil)
|
|
275
|
+
CAIterator.send(:refuse_quantile_arguments, args)
|
|
276
|
+
opts = reduce_options(min_count, fill_value)
|
|
279
277
|
if @slab_axes.size == 1
|
|
280
|
-
@
|
|
278
|
+
@source.quantile(axis: @slab_axes[0], **opts)
|
|
281
279
|
else
|
|
282
280
|
[0, 25, 50, 75, 100].map { |p|
|
|
283
|
-
@
|
|
281
|
+
@source.reduce_slab(axis: @slab_axes) { |s| s.percentile(p, **opts) }
|
|
284
282
|
}
|
|
285
283
|
end
|
|
286
284
|
end
|
|
@@ -292,49 +290,51 @@ class CASlabIterator < CAIterator
|
|
|
292
290
|
# the reductions above, sort does not accept an axis array). A multi-axis slab
|
|
293
291
|
# has no single sort axis, so it raises; sort one axis at a time.
|
|
294
292
|
|
|
295
|
-
# @overload sort_addr
|
|
293
|
+
# @overload sort_addr(masked_position: :last)
|
|
296
294
|
# Per-slab sort by flat source address. Delegates to
|
|
297
|
-
# `
|
|
298
|
-
# carry the flat source addresses that sort that slab
|
|
299
|
-
#
|
|
300
|
-
|
|
301
|
-
|
|
295
|
+
# `source.sort_addr(axis: slab_axis, masked_position:)`: source-shaped,
|
|
296
|
+
# each slab's cells carry the flat source addresses that sort that slab
|
|
297
|
+
# ascending, the masked cells last (or first with `:first`).
|
|
298
|
+
# @param masked_position [Symbol] `:last` (default) or `:first`.
|
|
299
|
+
# @return [CArray] source-shaped int64
|
|
300
|
+
def sort_addr(masked_position: :last)
|
|
301
|
+
@source.sort_addr(axis: single_sort_axis(:sort_addr), masked_position: masked_position)
|
|
302
302
|
end
|
|
303
303
|
|
|
304
304
|
# @overload sort_index
|
|
305
305
|
# Per-slab sort by axis-local index (usable with take_along_axis).
|
|
306
|
-
# Delegates to `
|
|
306
|
+
# Delegates to `source.sort_index(axis: slab_axis)`: source-shaped, the
|
|
307
307
|
# axis-local rank order within the slab axis.
|
|
308
|
-
# @return [CArray]
|
|
308
|
+
# @return [CArray] source-shaped int64
|
|
309
309
|
def sort_index
|
|
310
|
-
@
|
|
310
|
+
@source.sort_index(axis: single_sort_axis(:sort_index))
|
|
311
311
|
end
|
|
312
312
|
|
|
313
313
|
# ---- weighted (tier 2) ------------------------------------------------
|
|
314
314
|
#
|
|
315
315
|
# Delegated to the core weighted reduction over the slab axes; `weights` has
|
|
316
|
-
# the same shape as the
|
|
316
|
+
# the same shape as the source (one weight per cell). Core wsum / wmean
|
|
317
317
|
# accept multi-axis, so this covers multi-axis slabs directly.
|
|
318
318
|
|
|
319
319
|
# @overload wsum(weights, min_count: nil, fill_value: nil)
|
|
320
|
-
# Per-slab weighted sum, `weights` shaped like the
|
|
320
|
+
# Per-slab weighted sum, `weights` shaped like the source.
|
|
321
321
|
# @return [CArray]
|
|
322
|
-
def wsum
|
|
323
|
-
@
|
|
322
|
+
def wsum(weights, min_count: nil, fill_value: nil)
|
|
323
|
+
@source.wsum(weights, axis: @slab_axes, **reduce_options(min_count, fill_value))
|
|
324
324
|
end
|
|
325
325
|
|
|
326
326
|
# @overload wmean(weights, min_count: nil, fill_value: nil)
|
|
327
|
-
# Per-slab weighted mean, `weights` shaped like the
|
|
327
|
+
# Per-slab weighted mean, `weights` shaped like the source.
|
|
328
328
|
# @return [CArray]
|
|
329
|
-
def wmean
|
|
330
|
-
@
|
|
329
|
+
def wmean(weights, min_count: nil, fill_value: nil)
|
|
330
|
+
@source.wmean(weights, axis: @slab_axes, **reduce_options(min_count, fill_value))
|
|
331
331
|
end
|
|
332
332
|
|
|
333
333
|
# ---- segment scan: within-slab running statistics ---------------------
|
|
334
334
|
#
|
|
335
335
|
# A per-slab running accumulation along the slab axis is exactly the core
|
|
336
336
|
# per-axis cumulative over that axis, so every scan delegates to
|
|
337
|
-
# `
|
|
337
|
+
# `source.<op>(axis: slab_axis)`, inheriting the core data type / mask (masked
|
|
338
338
|
# cells hold the running total, output unmasked) contracts unchanged. Each
|
|
339
339
|
# cell is in exactly one slab (a partition), so the running value is
|
|
340
340
|
# well-defined; the surface is uniform with the family even though it
|
|
@@ -343,55 +343,55 @@ class CASlabIterator < CAIterator
|
|
|
343
343
|
# scan one axis at a time, like the order surface.
|
|
344
344
|
|
|
345
345
|
# @!method cumsum
|
|
346
|
-
# Per-slab inclusive running sum (float64),
|
|
346
|
+
# Per-slab inclusive running sum (float64), source-shaped.
|
|
347
347
|
# @return [CArray]
|
|
348
348
|
# @!method cumprod
|
|
349
|
-
# Per-slab inclusive running product (float64),
|
|
349
|
+
# Per-slab inclusive running product (float64), source-shaped.
|
|
350
350
|
# @return [CArray]
|
|
351
351
|
# @!method cummax
|
|
352
|
-
# Per-slab inclusive running maximum (
|
|
352
|
+
# Per-slab inclusive running maximum (source data type), source-shaped.
|
|
353
353
|
# @return [CArray]
|
|
354
354
|
# @!method cummin
|
|
355
|
-
# Per-slab inclusive running minimum (
|
|
355
|
+
# Per-slab inclusive running minimum (source data type), source-shaped.
|
|
356
356
|
# @return [CArray]
|
|
357
357
|
# @!method cumcount
|
|
358
|
-
# Per-slab running count of present cells (int64),
|
|
358
|
+
# Per-slab running count of present cells (int64), source-shaped.
|
|
359
359
|
# @return [CArray]
|
|
360
360
|
[:cumsum, :cumprod, :cummax, :cummin, :cumcount].each do |op|
|
|
361
361
|
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
362
362
|
def #{op}
|
|
363
|
-
@
|
|
363
|
+
@source.#{op}(axis: single_scan_axis(:#{op}))
|
|
364
364
|
end
|
|
365
365
|
RUBY
|
|
366
366
|
end
|
|
367
367
|
|
|
368
368
|
# @overload lag(n = 1)
|
|
369
369
|
# Per-slab value `n` steps earlier along the slab axis (UNDEF where the
|
|
370
|
-
# slab has none), as `
|
|
371
|
-
#
|
|
370
|
+
# slab has none), as `source.lag(n, axis: slab_axis)`: a view of the
|
|
371
|
+
# source. A multi-axis slab has no single direction to step in, so it
|
|
372
372
|
# raises, as the scans do.
|
|
373
|
-
# @return [CArray]
|
|
374
|
-
def lag
|
|
375
|
-
@
|
|
373
|
+
# @return [CArray] source-shaped
|
|
374
|
+
def lag(n = 1)
|
|
375
|
+
@source.lag(n, axis: single_scan_axis(:lag))
|
|
376
376
|
end
|
|
377
377
|
|
|
378
378
|
# @overload strip_mask(method:)
|
|
379
379
|
# Per-slab fill of the masked cells along the slab axis, as
|
|
380
|
-
# `
|
|
381
|
-
# or `:backward
|
|
382
|
-
# @return [CArray]
|
|
383
|
-
def strip_mask
|
|
384
|
-
CAIterator.hold_backward
|
|
385
|
-
@
|
|
380
|
+
# `source.strip_mask(method:, axis: slab_axis)`: `:forward`
|
|
381
|
+
# or `:backward`. A multi-axis slab raises, as the scans do.
|
|
382
|
+
# @return [CArray] source-shaped
|
|
383
|
+
def strip_mask(method:)
|
|
384
|
+
CAIterator.send(:hold_backward?, method)
|
|
385
|
+
@source.strip_mask(method: method, axis: single_scan_axis(:strip_mask))
|
|
386
386
|
end
|
|
387
387
|
|
|
388
|
-
# @overload
|
|
388
|
+
# @overload rank_index(descending: false, method: :ordinal, kind: :quick)
|
|
389
389
|
# Per-slab rank of each cell along the slab axis (int64), as
|
|
390
|
-
# `
|
|
390
|
+
# `source.rank_index(axis: slab_axis, ...)`. A multi-axis slab has no
|
|
391
391
|
# single sort axis, so it raises, as sort_addr does.
|
|
392
|
-
# @return [CArray]
|
|
393
|
-
def
|
|
394
|
-
@
|
|
392
|
+
# @return [CArray] source-shaped
|
|
393
|
+
def rank_index(**kw)
|
|
394
|
+
@source.rank_index(axis: single_sort_axis(:rank_index), **CAIterator.send(:reduce_keywords, :rank_index, kw))
|
|
395
395
|
end
|
|
396
396
|
|
|
397
397
|
private
|
|
@@ -399,14 +399,14 @@ class CASlabIterator < CAIterator
|
|
|
399
399
|
# The single slab axis for the order surface (core sort takes one integer
|
|
400
400
|
# axis). A multi-axis slab has no single sort axis, so raise.
|
|
401
401
|
# The reduction keywords that were given, for the core call.
|
|
402
|
-
def reduce_options
|
|
402
|
+
def reduce_options(min_count, fill_value)
|
|
403
403
|
opts = {}
|
|
404
404
|
opts[:min_count] = min_count unless min_count.nil?
|
|
405
405
|
opts[:fill_value] = fill_value unless fill_value.nil?
|
|
406
406
|
opts
|
|
407
407
|
end
|
|
408
408
|
|
|
409
|
-
def single_sort_axis
|
|
409
|
+
def single_sort_axis(op)
|
|
410
410
|
return @slab_axes[0] if @slab_axes.size == 1
|
|
411
411
|
raise ArgumentError,
|
|
412
412
|
"#{op}: a multi-axis slab (axes #{@slab_axes.inspect}) has no single " \
|
|
@@ -415,7 +415,7 @@ class CASlabIterator < CAIterator
|
|
|
415
415
|
|
|
416
416
|
# The single slab axis for a segment scan (core scan takes one integer axis).
|
|
417
417
|
# A multi-axis slab has no single scan axis, so raise.
|
|
418
|
-
def single_scan_axis
|
|
418
|
+
def single_scan_axis(op)
|
|
419
419
|
return @slab_axes[0] if @slab_axes.size == 1
|
|
420
420
|
raise ArgumentError,
|
|
421
421
|
"#{op}: a multi-axis slab (axes #{@slab_axes.inspect}) has no single " \
|
data/lib/carray/stack.rb
CHANGED
|
@@ -41,8 +41,7 @@ class CArray
|
|
|
41
41
|
# / Module targets are rejected (= `data_type: CATime` is invalid;
|
|
42
42
|
# use auto-detect for Face round-trip).
|
|
43
43
|
#
|
|
44
|
-
#
|
|
45
|
-
# low-level raw constructor is `CAStack.new(list, axis:)`; this method
|
|
44
|
+
# The low-level raw constructor is `CAStack.new(list, axis:)`; this method
|
|
46
45
|
# is the high-level surface that performs promote_list + CAStack.new +
|
|
47
46
|
# (face_lift when homogeneous Face).
|
|
48
47
|
# @overload stack(list, axis: 0, data_type: nil)
|
|
@@ -57,10 +56,10 @@ class CArray
|
|
|
57
56
|
# inferred when `nil`.
|
|
58
57
|
# @return [CArray] CAStack view.
|
|
59
58
|
# @raise [ArgumentError] when `list` is empty.
|
|
60
|
-
def self.stack
|
|
59
|
+
def self.stack(list, axis: 0, data_type: nil)
|
|
61
60
|
raise ArgumentError, "stack: list must not be empty" if list.empty?
|
|
62
61
|
axis = 0 if axis.nil?
|
|
63
|
-
list =
|
|
62
|
+
list = promote_list_for("stack", list, data_type: data_type)
|
|
64
63
|
axis = CArray.normalize_axis(axis, list[0].ndim + 1, "stack")
|
|
65
64
|
CAStack.new(list, axis: axis) # CAStack.new does Face lift internally
|
|
66
65
|
end
|
|
@@ -90,7 +89,7 @@ class CArray
|
|
|
90
89
|
# @return [CAMeld] view over the welded pieces.
|
|
91
90
|
# @raise [ArgumentError] when the list is empty, ndim mismatch,
|
|
92
91
|
# or non-axis dim mismatch across pieces (surfaced by CAMeld.new).
|
|
93
|
-
def self.meld
|
|
92
|
+
def self.meld(*arrays, axis: 0, data_type: nil)
|
|
94
93
|
if arrays.length == 1 && arrays[0].is_a?(Array)
|
|
95
94
|
arrays = arrays[0]
|
|
96
95
|
end
|
|
@@ -98,10 +97,10 @@ class CArray
|
|
|
98
97
|
axis = 0 if axis.nil?
|
|
99
98
|
first = arrays[0]
|
|
100
99
|
unless first.is_a?(CArray)
|
|
101
|
-
raise
|
|
100
|
+
raise TypeError, "meld: entries must be CArray (got #{first.class})"
|
|
102
101
|
end
|
|
103
102
|
axis_norm = CArray.normalize_axis(axis, first.ndim, "meld")
|
|
104
|
-
arrays =
|
|
103
|
+
arrays = promote_list_for("meld", arrays, data_type: data_type)
|
|
105
104
|
# Flatten nested CAMeld inputs that share our meld axis: they already
|
|
106
105
|
# describe a segment sequence, so absorbing their parents keeps chain
|
|
107
106
|
# depth at 1 (avoids 2-level xfer_all / reduce chains through the
|
|
@@ -130,7 +129,7 @@ class CArray
|
|
|
130
129
|
# @param data_type [Symbol, Integer, nil] result `data_type`.
|
|
131
130
|
# @return [CAMeld]
|
|
132
131
|
# @raise [ArgumentError] when no `others` are given.
|
|
133
|
-
def meld
|
|
132
|
+
def meld(*others, axis: 0, data_type: nil)
|
|
134
133
|
raise ArgumentError, "meld: at least one other array required" if others.empty?
|
|
135
134
|
CArray.meld(self, *others, axis: axis, data_type: data_type)
|
|
136
135
|
end
|
|
@@ -172,7 +171,7 @@ class CArray
|
|
|
172
171
|
# @return [CArray] tiled view.
|
|
173
172
|
# @raise [ArgumentError] when `list` is empty or `tdim.product !=
|
|
174
173
|
# list.size`.
|
|
175
|
-
def self.montage
|
|
174
|
+
def self.montage(list, tdim, axis: 0, data_type: nil)
|
|
176
175
|
raise ArgumentError, "montage: list must not be empty" if list.empty?
|
|
177
176
|
unless tdim.is_a?(Array) && tdim.size > 0
|
|
178
177
|
raise ArgumentError, "montage: tdim must be a non-empty Array of Integer"
|
|
@@ -183,7 +182,7 @@ class CArray
|
|
|
183
182
|
"montage: tdim product (#{expected}) must equal list size (#{list.size})"
|
|
184
183
|
end
|
|
185
184
|
|
|
186
|
-
list =
|
|
185
|
+
list = promote_list_for("montage", list, data_type: data_type)
|
|
187
186
|
parent_shape = list[0].shape
|
|
188
187
|
ntile = tdim.size
|
|
189
188
|
nparent = parent_shape.size
|
|
@@ -228,7 +227,7 @@ class CArray
|
|
|
228
227
|
# @param data_type [Symbol, Integer, nil] result `data_type`.
|
|
229
228
|
# @return [CArray] CAStack view.
|
|
230
229
|
# @raise [ArgumentError] when no `others` are given.
|
|
231
|
-
def stack
|
|
230
|
+
def stack(*others, axis: 0, data_type: nil)
|
|
232
231
|
raise ArgumentError, "stack: at least one other parent required" if others.empty?
|
|
233
232
|
CArray.stack([self] + others, axis: axis, data_type: data_type)
|
|
234
233
|
end
|
|
@@ -239,7 +238,7 @@ class CArray
|
|
|
239
238
|
#
|
|
240
239
|
# CArray.stack(a.split(axis: k), axis: k) == a
|
|
241
240
|
#
|
|
242
|
-
# a =
|
|
241
|
+
# a = CA_INT32([[1,2,3], [4,5,6]])
|
|
243
242
|
# a.split(axis: 0) #=> [ <[1,2,3]>, <[4,5,6]> ] (row views)
|
|
244
243
|
# a.split(axis: 1) #=> [ <[1,4]>, <[2,5]>, <[3,6]> ] (column views)
|
|
245
244
|
#
|
|
@@ -249,7 +248,7 @@ class CArray
|
|
|
249
248
|
# - +axis:+ takes a single Integer (the multi-axis Array form, which
|
|
250
249
|
# returned an N-D object grid, is no longer accepted)
|
|
251
250
|
# - pieces are CABlock views, NOT copies; writing through a piece
|
|
252
|
-
# mutates +self+. Chain +.copy+
|
|
251
|
+
# mutates +self+. Chain +.copy+ for independent entities.
|
|
253
252
|
# @overload split(axis:)
|
|
254
253
|
# Returns an Array of `(ndim-1)`-D writable CABlock views obtained
|
|
255
254
|
# by splitting `self` along `axis`. Inverse of `CArray.stack`.
|
|
@@ -259,7 +258,7 @@ class CArray
|
|
|
259
258
|
# @return [Array<CArray>] one slice per index along `axis`.
|
|
260
259
|
# @raise [ArgumentError] when `axis` is not a single Integer
|
|
261
260
|
# (including `nil`).
|
|
262
|
-
def split
|
|
261
|
+
def split(axis:)
|
|
263
262
|
raise ArgumentError, "split: axis: is required" if axis.nil?
|
|
264
263
|
if axis.is_a?(Array)
|
|
265
264
|
raise ArgumentError, "split: axis must be a single Integer"
|
|
@@ -298,7 +297,7 @@ class CAStack
|
|
|
298
297
|
# writes into its cells stay refused.
|
|
299
298
|
# @return [CAStack]
|
|
300
299
|
# @raise [ArgumentError] when no `others` are given.
|
|
301
|
-
def append
|
|
300
|
+
def append(*others)
|
|
302
301
|
raise ArgumentError, "append: at least one parent required" if others.empty?
|
|
303
302
|
if mask_array?
|
|
304
303
|
raise ArgumentError, "append: a mask array can have no mask and can not be a part"
|
data/lib/carray/string.rb
CHANGED
|
@@ -46,7 +46,7 @@ class CArray
|
|
|
46
46
|
# @yieldparam i [Integer] cell index.
|
|
47
47
|
# @yieldreturn [String, nil] value for cell `i`.
|
|
48
48
|
# @return [CAString]
|
|
49
|
-
def self.string
|
|
49
|
+
def self.string(arg, &block)
|
|
50
50
|
return string_face_of(arg).to_string if arg.is_a?(CArray)
|
|
51
51
|
|
|
52
52
|
if block
|
|
@@ -97,40 +97,34 @@ class CAString
|
|
|
97
97
|
|
|
98
98
|
# Per-cell `String#+`.
|
|
99
99
|
# @return [CAString] shape and mask carried.
|
|
100
|
-
def +
|
|
100
|
+
def +(other) ; as_text(super) ; end
|
|
101
101
|
# Per-cell `String#+` (the word form of {#+}).
|
|
102
102
|
# @return [CAString]
|
|
103
|
-
def add
|
|
103
|
+
def add(other) ; as_text(super) ; end
|
|
104
104
|
# Per-cell `String#*`.
|
|
105
105
|
# @return [CAString] shape and mask carried.
|
|
106
|
-
def *
|
|
106
|
+
def *(other) ; as_text(super) ; end
|
|
107
107
|
# Per-cell `String#*` (the word form of {#*}).
|
|
108
108
|
# @return [CAString]
|
|
109
|
-
def mul
|
|
109
|
+
def mul(other) ; as_text(super) ; end
|
|
110
110
|
# Per-cell `String#%` (format).
|
|
111
111
|
# @return [CAString] shape and mask carried.
|
|
112
|
-
def %
|
|
112
|
+
def %(other) ; as_text(super) ; end
|
|
113
113
|
# Per-cell `String#%` (the word form of {#%}).
|
|
114
114
|
# @return [CAString]
|
|
115
|
-
def mod
|
|
115
|
+
def mod(other) ; as_text(super) ; end
|
|
116
116
|
# The later String of each cell and `other`, cell by cell.
|
|
117
117
|
# @return [CAString]
|
|
118
|
-
def pmax (other) ; as_text(super) ; end
|
|
118
|
+
def pmax(other) ; refuse_unordered_operands("pmax", other) ; as_text(super) ; end
|
|
119
119
|
# The earlier String of each cell and `other`, cell by cell.
|
|
120
120
|
# @return [CAString]
|
|
121
|
-
def pmin (other) ; as_text(super) ; end
|
|
121
|
+
def pmin(other) ; refuse_unordered_operands("pmin", other) ; as_text(super) ; end
|
|
122
122
|
# Another name of {#pmax} (a String has no NaN to let win).
|
|
123
123
|
# @return [CAString]
|
|
124
|
-
def maximum (other) ; as_text(super) ; end
|
|
124
|
+
def maximum(other) ; refuse_unordered_operands("maximum", other) ; as_text(super) ; end
|
|
125
125
|
# Another name of {#pmin}.
|
|
126
126
|
# @return [CAString]
|
|
127
|
-
def minimum (other) ; as_text(super) ; end
|
|
128
|
-
# Another name of {#pmax}.
|
|
129
|
-
# @return [CAString]
|
|
130
|
-
def fmax (other) ; as_text(super) ; end
|
|
131
|
-
# Another name of {#pmin}.
|
|
132
|
-
# @return [CAString]
|
|
133
|
-
def fmin (other) ; as_text(super) ; end
|
|
127
|
+
def minimum(other) ; refuse_unordered_operands("minimum", other) ; as_text(super) ; end
|
|
134
128
|
|
|
135
129
|
# The String a blank cell holds: the cell a fresh {#template} gives and
|
|
136
130
|
# the one {#shift} fills by default. Frozen, because every blank cell
|
|
@@ -142,7 +136,7 @@ class CAString
|
|
|
142
136
|
# UNDEF. Given a data type, the result is a plain array of that type.
|
|
143
137
|
# @overload template(type = nil, **opts)
|
|
144
138
|
# @return [CAString, CArray]
|
|
145
|
-
def template
|
|
139
|
+
def template(*args, **opts, &block)
|
|
146
140
|
return super if block || ! args.empty? || ! opts.empty?
|
|
147
141
|
out = super
|
|
148
142
|
out[] = BLANK
|
|
@@ -152,25 +146,25 @@ class CAString
|
|
|
152
146
|
# Shifts the cells as {CArray#shift} does. The cells shifted in hold
|
|
153
147
|
# {BLANK} unless `fill_value:` names a String or UNDEF.
|
|
154
148
|
# @return [CAString] a view over the shifted cells.
|
|
155
|
-
def shift
|
|
149
|
+
def shift(*shifts, fill_value: BLANK, **opts)
|
|
156
150
|
super(*shifts, fill_value: fill_value, **opts)
|
|
157
151
|
end
|
|
158
152
|
|
|
159
153
|
# A window as {CArray#window} gives. The cells outside the array hold
|
|
160
154
|
# {BLANK} unless `fill_value:` names a String or UNDEF.
|
|
161
155
|
# @return [CAString] a view over the window.
|
|
162
|
-
def window
|
|
156
|
+
def window(*ranges, fill_value: BLANK, **opts)
|
|
163
157
|
super(*ranges, fill_value: fill_value, **opts)
|
|
164
158
|
end
|
|
165
159
|
|
|
166
160
|
# A resized copy as {CArray#resize} gives. The new cells hold {BLANK}
|
|
167
161
|
# unless `fill_value:` names a String or UNDEF.
|
|
168
162
|
# @return [CAString]
|
|
169
|
-
def resize
|
|
163
|
+
def resize(*newdim, fill_value: BLANK)
|
|
170
164
|
super(*newdim, fill_value: fill_value)
|
|
171
165
|
end
|
|
172
166
|
|
|
173
|
-
private def as_text
|
|
167
|
+
private def as_text(result)
|
|
174
168
|
result = result.copy if result.lazy_view?
|
|
175
169
|
CAString.wrap(result)
|
|
176
170
|
end
|