carray 3.0.7 → 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 -1940
- data/README.md +38 -32
- 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 +6 -9
- data/ext/ca_bincmp_dispatch.h +16 -38
- data/ext/ca_binop_dispatch.c +27 -0
- data/ext/ca_binop_dispatch.h +22 -47
- 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 -1506
- 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 +90 -163
- data/ext/ca_obj_bincmp.c +47 -46
- data/ext/ca_obj_binop.c +38 -38
- data/ext/ca_obj_bitarray.c +5 -17
- data/ext/ca_obj_bitfield.c +15 -30
- data/ext/ca_obj_block.c +11 -12
- data/ext/ca_obj_byte_swap.c +32 -30
- data/ext/ca_obj_const_string.c +57 -62
- data/ext/ca_obj_face.c +99 -91
- data/ext/ca_obj_face.h +32 -170
- data/ext/ca_obj_fake.c +15 -21
- data/ext/ca_obj_farray.c +7 -9
- data/ext/ca_obj_field.c +17 -13
- data/ext/ca_obj_fixlen_string.c +8 -19
- data/ext/ca_obj_grid.c +137 -106
- data/ext/ca_obj_meld.c +23 -21
- data/ext/ca_obj_moncmp.c +10 -21
- data/ext/ca_obj_monop.c +24 -35
- data/ext/ca_obj_object.c +51 -37
- data/ext/ca_obj_record.c +74 -22
- data/ext/ca_obj_reduce.c +8 -10
- data/ext/ca_obj_refer.c +42 -29
- data/ext/ca_obj_remap.c +11 -29
- data/ext/ca_obj_repeat.c +41 -23
- data/ext/ca_obj_roll.c +18 -24
- data/ext/ca_obj_select.c +10 -22
- data/ext/ca_obj_select_axis.c +27 -36
- data/ext/ca_obj_shift.c +22 -42
- data/ext/ca_obj_source.c +1 -5
- data/ext/ca_obj_stack.c +28 -24
- data/ext/ca_obj_stride.c +53 -54
- data/ext/ca_obj_string.c +6 -18
- data/ext/ca_obj_tile.c +12 -12
- 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 +35 -39
- data/ext/ca_obj_window.c +67 -86
- data/ext/ca_op_cmplx64.h +4 -0
- data/ext/ca_op_ipower.c +34 -12
- data/ext/ca_op_powi.h +4 -0
- 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 +20 -26
- data/ext/ca_sweep_engine.c +2 -3
- data/ext/ca_sweep_engine.h +17 -9
- data/ext/ca_transform_common.c +3 -8
- data/ext/ca_triop_dispatch.h +20 -32
- data/ext/caframe_csv_reader.c +11 -11
- data/ext/carray.h +300 -1011
- data/ext/carray_access.c +234 -180
- data/ext/carray_address_basis.c +33 -38
- data/ext/carray_attribute.c +81 -104
- data/ext/carray_bincount.c +12 -14
- data/ext/carray_broadcast.c +30 -26
- data/ext/carray_call_cfunc.c +169 -277
- data/ext/carray_call_cfunc.h +36 -28
- data/ext/carray_cast.c +912 -346
- data/ext/carray_cast_func.rb +31 -3
- data/ext/carray_class.c +6 -11
- data/ext/carray_conversion.c +43 -38
- data/ext/carray_copy.c +28 -26
- data/ext/carray_core.c +217 -126
- data/ext/carray_count.c +27 -15
- data/ext/carray_element.c +40 -25
- data/ext/carray_factorize.c +53 -52
- data/ext/carray_generate.c +26 -19
- data/ext/carray_histogram.c +8 -10
- data/ext/carray_hold.c +7 -9
- data/ext/carray_index_classifier.c +123 -228
- data/ext/carray_index_classifier.h +11 -10
- data/ext/carray_integer_total.c +523 -0
- data/ext/carray_internal.h +1274 -160
- data/ext/carray_key_windows.c +3 -3
- data/ext/carray_lazy.c +21 -36
- data/ext/carray_loop.c +19 -22
- data/ext/carray_mask.c +123 -145
- data/ext/carray_math_kernel.h +23 -47
- data/ext/carray_mathfunc.c +10 -3
- data/ext/carray_median_percentile.c +95 -94
- data/ext/carray_memory_view.c +42 -47
- data/ext/carray_operator.c +423 -122
- data/ext/carray_order.c +121 -85
- data/ext/carray_partition.c +13 -15
- data/ext/carray_random.c +47 -41
- data/ext/carray_round.c +9 -4
- data/ext/carray_scatter.c +54 -40
- data/ext/carray_segment.c +41 -45
- data/ext/carray_slab.c +64 -47
- data/ext/carray_slab.h +44 -33
- data/ext/carray_sort.c +32 -29
- data/ext/carray_sort_kernel.c +12 -10
- data/ext/carray_struct.c +38 -43
- data/ext/carray_test.c +47 -43
- data/ext/carray_time_text.c +24 -31
- data/ext/carray_undef.c +50 -7
- data/ext/carray_utils.c +258 -94
- data/ext/extconf.rb +24 -17
- data/ext/mk_call_cfunc.rb +19 -20
- data/ext/mk_pow5_table.rb +2 -1
- data/ext/mkkernel.rb +782 -461
- 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 +264 -180
- data/lib/carray/basics.rb +272 -48
- data/lib/carray/bincount_nd.rb +33 -16
- data/lib/carray/block_iterator.rb +123 -102
- data/lib/carray/boolean_reduce.rb +7 -4
- data/lib/carray/categorical.rb +63 -51
- data/lib/carray/categorical_iterator.rb +89 -67
- data/lib/carray/complex.rb +61 -41
- data/lib/carray/conditional.rb +49 -22
- data/lib/carray/const_string.rb +54 -62
- data/lib/carray/core_extensions.rb +1 -1
- data/lib/carray/distance_limit.rb +7 -5
- data/lib/carray/factories.rb +269 -0
- data/lib/carray/fixlen_string.rb +25 -24
- data/lib/carray/frame/column_verbs.rb +20 -8
- data/lib/carray/frame/concat.rb +3 -3
- data/lib/carray/frame/convert.rb +2 -1
- data/lib/carray/frame/csv_parser.rb +7 -1
- data/lib/carray/frame/frame.rb +35 -25
- data/lib/carray/frame/group.rb +183 -150
- data/lib/carray/frame/io.rb +26 -7
- data/lib/carray/frame/join.rb +37 -12
- data/lib/carray/frame/records.rb +1 -1
- data/lib/carray/frame/reshape.rb +3 -3
- data/lib/carray/frame/sort.rb +10 -8
- data/lib/carray/frame/verbs.rb +148 -118
- data/lib/carray/frame/windows.rb +232 -21
- data/lib/carray/frame.rb +1 -2
- data/lib/carray/fuse_source.rb +24 -21
- 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 +97 -24
- data/lib/carray/key_windows.rb +83 -57
- data/lib/carray/lazy.rb +196 -94
- 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 +5 -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 +72 -71
- data/lib/carray/methods/{index.rb → coordinate.rb} +13 -13
- data/lib/carray/methods/discovery_along.rb +3 -3
- data/lib/carray/methods/gather_nd.rb +106 -106
- 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 +165 -145
- data/lib/carray/methods/join.rb +2 -1
- data/lib/carray/methods/lag.rb +6 -2
- data/lib/carray/methods/locate_addr.rb +150 -138
- 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 +12 -12
- 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 +18 -17
- data/lib/carray/rng.rb +1 -0
- data/lib/carray/runtime.rb +190 -22
- data/lib/carray/segment_iterator.rb +251 -129
- data/lib/carray/serialize.rb +618 -571
- data/lib/carray/slab_iterator.rb +114 -114
- data/lib/carray/stack.rb +11 -12
- data/lib/carray/string.rb +16 -22
- data/lib/carray/string_operation_extension.rb +76 -52
- data/lib/carray/struct.rb +122 -164
- data/lib/carray/struct_builder.rb +243 -72
- data/lib/carray/time.rb +496 -342
- data/lib/carray/window_iterator.rb +191 -150
- 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 +4 -3
- 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 +7 -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 +26 -15
- data/yard-stubs/carray_access.rb +51 -4
- data/yard-stubs/carray_attribute.rb +26 -38
- data/yard-stubs/carray_cast.rb +118 -165
- 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 +5 -3
- 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 +157 -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 +67 -34
- 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 +10 -2
- data/yard-stubs/carray_slab.rb +7 -4
- data/yard-stubs/carray_sort.rb +7 -6
- data/yard-stubs/carray_undef.rb +44 -5
- data/yard-stubs/ruby_carray.rb +75 -40
- metadata +62 -24
- 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 -25337
- 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 -262
- data/lib/carray/data_type_limits.rb +0 -91
|
@@ -22,14 +22,29 @@ class CArray
|
|
|
22
22
|
# Output by return category (Option alpha):
|
|
23
23
|
# String result -> CAString (mutable object-backed String array). Chain
|
|
24
24
|
# #to_const_string / #to_fixlen_string to re-compact.
|
|
25
|
-
# Integer result -> :
|
|
25
|
+
# Integer result -> :int32 CArray
|
|
26
26
|
# Boolean result -> :boolean CArray
|
|
27
27
|
module StringOperationMixin
|
|
28
28
|
|
|
29
|
+
# A Ruby Array is not an operand of a string array: it would be read as
|
|
30
|
+
# one value, and no cell equals it. Compare with a CArray of Strings
|
|
31
|
+
# (CArray.string(ary)) instead.
|
|
32
|
+
CArray.send(:define_named_methods, self, [:eq, :ne],
|
|
33
|
+
:refuse_array_operand, super_block: true)
|
|
34
|
+
|
|
35
|
+
private def refuse_array_operand(op, args, kw)
|
|
36
|
+
if args[0].is_a?(Array)
|
|
37
|
+
raise TypeError,
|
|
38
|
+
"#{op}: a Ruby Array is not an operand of a string array; " \
|
|
39
|
+
"make it a CArray first, e.g. CArray.string(ary)"
|
|
40
|
+
end
|
|
41
|
+
yield(*args, **kw)
|
|
42
|
+
end
|
|
43
|
+
|
|
29
44
|
# Per-cell map through the Face's scalar fetch. A nil `data_type` returns a
|
|
30
45
|
# CAString (string results); an explicit one returns a plain typed array
|
|
31
46
|
# (integer / boolean results). Shape and mask are carried.
|
|
32
|
-
def string_map
|
|
47
|
+
def string_map(data_type = nil) # :nodoc:
|
|
33
48
|
out = data_type ? template(data_type) : CArray.object(*shape)
|
|
34
49
|
# A typed result has no nil: a cell the String method answers nil for
|
|
35
50
|
# (index finds nothing) is UNDEF.
|
|
@@ -47,7 +62,7 @@ class CArray
|
|
|
47
62
|
# An ordering (pmax and its kin, clip) with a value that is not a String
|
|
48
63
|
# is refused as String#< refuses it. nil (no bound, for clip), UNDEF,
|
|
49
64
|
# an Array and a CArray are left to the operation.
|
|
50
|
-
def refuse_unordered_operands
|
|
65
|
+
def refuse_unordered_operands(verb, *operands)
|
|
51
66
|
operands.each do |v|
|
|
52
67
|
next if v.nil? || v.is_a?(String) || v.is_a?(Array) || v.is_a?(CArray) || UNDEF.equal?(v)
|
|
53
68
|
name = v.is_a?(Symbol) ? v.inspect : v.class
|
|
@@ -58,7 +73,7 @@ class CArray
|
|
|
58
73
|
|
|
59
74
|
# Clips the strings in byte order (see {CArray#clip}); a bound that is
|
|
60
75
|
# not a String is refused.
|
|
61
|
-
def clip
|
|
76
|
+
def clip(min, max = nil, **kw)
|
|
62
77
|
refuse_unordered_operands("clip", min, max)
|
|
63
78
|
super
|
|
64
79
|
end
|
|
@@ -67,55 +82,55 @@ class CArray
|
|
|
67
82
|
|
|
68
83
|
# Per-cell `String#upcase`.
|
|
69
84
|
# @return [CAString] shape and mask of `self` preserved.
|
|
70
|
-
def upcase
|
|
85
|
+
def upcase() ; string_map { |s| s.upcase } ; end
|
|
71
86
|
# Per-cell `String#downcase`.
|
|
72
87
|
# @return [CAString] shape and mask of `self` preserved.
|
|
73
|
-
def downcase
|
|
88
|
+
def downcase() ; string_map { |s| s.downcase } ; end
|
|
74
89
|
# Per-cell `String#capitalize`.
|
|
75
90
|
# @return [CAString] shape and mask of `self` preserved.
|
|
76
|
-
def capitalize
|
|
91
|
+
def capitalize() ; string_map { |s| s.capitalize } ; end
|
|
77
92
|
# Per-cell `String#swapcase`.
|
|
78
93
|
# @return [CAString] shape and mask of `self` preserved.
|
|
79
|
-
def swapcase
|
|
94
|
+
def swapcase() ; string_map { |s| s.swapcase } ; end
|
|
80
95
|
# Per-cell `String#strip`.
|
|
81
96
|
# @return [CAString] shape and mask of `self` preserved.
|
|
82
|
-
def strip
|
|
97
|
+
def strip() ; string_map { |s| s.strip } ; end
|
|
83
98
|
# Per-cell `String#lstrip`.
|
|
84
99
|
# @return [CAString] shape and mask of `self` preserved.
|
|
85
|
-
def lstrip
|
|
100
|
+
def lstrip() ; string_map { |s| s.lstrip } ; end
|
|
86
101
|
# Per-cell `String#rstrip`.
|
|
87
102
|
# @return [CAString] shape and mask of `self` preserved.
|
|
88
|
-
def rstrip
|
|
103
|
+
def rstrip() ; string_map { |s| s.rstrip } ; end
|
|
89
104
|
# Per-cell `String#chomp`.
|
|
90
105
|
# @return [CAString] shape and mask of `self` preserved.
|
|
91
|
-
def chomp
|
|
106
|
+
def chomp(*a) ; string_map { |s| s.chomp(*a) } ; end
|
|
92
107
|
# Per-cell `String#gsub`.
|
|
93
108
|
# @return [CAString] shape and mask of `self` preserved.
|
|
94
|
-
def gsub
|
|
109
|
+
def gsub(*a, &b) ; string_map { |s| s.gsub(*a, &b) } ; end
|
|
95
110
|
# Per-cell `String#delete_prefix`.
|
|
96
111
|
# @return [CAString] shape and mask of `self` preserved.
|
|
97
|
-
def delete_prefix
|
|
112
|
+
def delete_prefix(p) ; string_map { |s| s.delete_prefix(p) } ; end
|
|
98
113
|
# Per-cell `String#delete_suffix`.
|
|
99
114
|
# @return [CAString] shape and mask of `self` preserved.
|
|
100
|
-
def delete_suffix
|
|
115
|
+
def delete_suffix(p) ; string_map { |s| s.delete_suffix(p) } ; end
|
|
101
116
|
# Per-cell `String#center`.
|
|
102
117
|
# @return [CAString] shape and mask of `self` preserved.
|
|
103
|
-
def center
|
|
118
|
+
def center(*a) ; string_map { |s| s.center(*a) } ; end
|
|
104
119
|
# Per-cell `String#ljust`.
|
|
105
120
|
# @return [CAString] shape and mask of `self` preserved.
|
|
106
|
-
def ljust
|
|
121
|
+
def ljust(*a) ; string_map { |s| s.ljust(*a) } ; end
|
|
107
122
|
# Per-cell `String#rjust`.
|
|
108
123
|
# @return [CAString] shape and mask of `self` preserved.
|
|
109
|
-
def rjust
|
|
124
|
+
def rjust(*a) ; string_map { |s| s.rjust(*a) } ; end
|
|
110
125
|
# Per-cell `String#encode`.
|
|
111
126
|
# @return [CAString] shape and mask of `self` preserved.
|
|
112
|
-
def encode
|
|
127
|
+
def encode(*a) ; string_map { |s| s.encode(*a) } ; end
|
|
113
128
|
# Per-cell `String#force_encoding`.
|
|
114
129
|
# @return [CAString] shape and mask of `self` preserved.
|
|
115
|
-
def force_encoding
|
|
130
|
+
def force_encoding(e) ; string_map { |s| s.dup.force_encoding(e) } ; end
|
|
116
131
|
# Per-cell `String#scrub`.
|
|
117
132
|
# @return [CAString] shape and mask of `self` preserved.
|
|
118
|
-
def scrub
|
|
133
|
+
def scrub() ; string_map { |s| s.scrub } ; end
|
|
119
134
|
|
|
120
135
|
# ---- predicates (Boolean result -> :boolean) -------------------------
|
|
121
136
|
# start_with? / end_with? / include? are byte-level and free of collisions
|
|
@@ -123,55 +138,64 @@ class CArray
|
|
|
123
138
|
|
|
124
139
|
# Per-cell `String#start_with?`.
|
|
125
140
|
# @return [CArray] boolean, shape and mask of `self` preserved.
|
|
126
|
-
def start_with?
|
|
141
|
+
def start_with?(*a) ; string_map(:boolean) { |s| s.start_with?(*a) } ; end
|
|
127
142
|
# Per-cell `String#end_with?`.
|
|
128
143
|
# @return [CArray] boolean, shape and mask of `self` preserved.
|
|
129
|
-
def end_with?
|
|
144
|
+
def end_with?(*a) ; string_map(:boolean) { |s| s.end_with?(*a) } ; end
|
|
130
145
|
# Per-cell `String#include?`.
|
|
131
146
|
# @return [CArray] boolean, shape and mask of `self` preserved.
|
|
132
|
-
def include?
|
|
147
|
+
def include?(sub) ; string_map(:boolean) { |s| s.include?(sub) } ; end
|
|
133
148
|
# Per-cell `String#match?`.
|
|
134
149
|
# @return [CArray] boolean, shape and mask of `self` preserved.
|
|
135
|
-
def match?
|
|
150
|
+
def match?(re) ; string_map(:boolean) { |s| s.match?(re) } ; end
|
|
136
151
|
|
|
137
|
-
# ---- length / position (Integer result -> :
|
|
152
|
+
# ---- length / position (Integer result -> :int32) ----------------------
|
|
138
153
|
# `str_len` keeps the prefix because bare #length / #size mean element
|
|
139
154
|
# count on a CArray; `str_index` because bare #index is an array method.
|
|
140
155
|
# `bytesize` / `rindex` have no array-level collision, so they stay bare.
|
|
141
156
|
|
|
142
157
|
# Per-cell `String#length`.
|
|
143
|
-
# @return [CArray] `:
|
|
144
|
-
def str_len
|
|
158
|
+
# @return [CArray] `:int32`, shape and mask of `self` preserved.
|
|
159
|
+
def str_len() ; string_map(:int32) { |s| s.length } ; end
|
|
145
160
|
# Per-cell `String#bytesize`.
|
|
146
|
-
# @return [CArray] `:
|
|
147
|
-
def bytesize
|
|
161
|
+
# @return [CArray] `:int32`, shape and mask of `self` preserved.
|
|
162
|
+
def bytesize() ; string_map(:int32) { |s| s.bytesize } ; end
|
|
148
163
|
# Per-cell `String#index`.
|
|
149
|
-
# @return [CArray] `:
|
|
164
|
+
# @return [CArray] `:int32`, shape and mask of `self` preserved; UNDEF
|
|
150
165
|
# where the cell does not hold the substring.
|
|
151
|
-
def str_index
|
|
166
|
+
def str_index(*a) ; string_map(:int32) { |s| s.index(*a) } ; end
|
|
152
167
|
# Per-cell `String#rindex`.
|
|
153
|
-
# @return [CArray] `:
|
|
168
|
+
# @return [CArray] `:int32`, shape and mask of `self` preserved; UNDEF
|
|
154
169
|
# where the cell does not hold the substring.
|
|
155
|
-
def rindex
|
|
170
|
+
def rindex(*a) ; string_map(:int32) { |s| s.rindex(*a) } ; end
|
|
156
171
|
|
|
157
172
|
# ---- numeric parse (Integer / Float result) --------------------------
|
|
158
173
|
|
|
159
174
|
# Per-cell `String#to_i`.
|
|
160
|
-
# @return [CArray] `:
|
|
161
|
-
def to_i
|
|
175
|
+
# @return [CArray] `:int32`, shape and mask of `self` preserved.
|
|
176
|
+
def to_i() ; string_map(:int32) { |s| s.to_i } ; end
|
|
162
177
|
# Per-cell `String#to_f`.
|
|
163
178
|
# @return [CArray] `float64`, shape and mask of `self` preserved.
|
|
164
|
-
def to_f
|
|
179
|
+
def to_f() ; string_map(:float64) { |s| s.to_f } ; end
|
|
165
180
|
|
|
166
181
|
# ---- membership ------------------------------------------------------
|
|
167
182
|
|
|
168
183
|
# @overload in?(*strings)
|
|
169
184
|
# Returns a boolean CArray marking every cell whose value equals one of
|
|
170
185
|
# `strings` (set membership). The string counterpart of `#match?` for
|
|
171
|
-
# regexps: both mark all matching cells.
|
|
186
|
+
# regexps: both mark all matching cells. Each argument is a String, as
|
|
187
|
+
# `start_with?` takes them; to test against a set held in an Array or a
|
|
188
|
+
# CArray, use {#is_in}.
|
|
172
189
|
# @param strings [Array<String>]
|
|
173
190
|
# @return [CArray]
|
|
174
|
-
|
|
191
|
+
# @raise [TypeError] for an argument that is not a String.
|
|
192
|
+
def in?(*strings)
|
|
193
|
+
strings.each do |x|
|
|
194
|
+
next if x.is_a?(String)
|
|
195
|
+
raise TypeError,
|
|
196
|
+
"in?: #{x.inspect} (#{x.class}) is not a String; give the strings as " \
|
|
197
|
+
"separate arguments, or use is_in for a set held in an Array"
|
|
198
|
+
end
|
|
175
199
|
string_map(:boolean) { |s| strings.include?(s) }
|
|
176
200
|
end
|
|
177
201
|
|
|
@@ -183,7 +207,7 @@ class CArray
|
|
|
183
207
|
# @param regexp [Regexp]
|
|
184
208
|
# @param replace [String]
|
|
185
209
|
# @return [CAString]
|
|
186
|
-
def extract
|
|
210
|
+
def extract(regexp, replace = '\0')
|
|
187
211
|
string_map { |s| regexp.match(s) { |m| m[0].sub(regexp, replace) } || UNDEF }
|
|
188
212
|
end
|
|
189
213
|
|
|
@@ -211,7 +235,7 @@ class CArray
|
|
|
211
235
|
# @param bytes [Integer, nil] slot width; defaults to the max bytesize.
|
|
212
236
|
# @param truncate [Symbol] :error or :silent (see {CArray.fixlen_string}).
|
|
213
237
|
# @return [CAFixlenString]
|
|
214
|
-
def to_fixlen_string
|
|
238
|
+
def to_fixlen_string(bytes: nil, truncate: :error)
|
|
215
239
|
unless [:error, :silent].include?(truncate)
|
|
216
240
|
raise ArgumentError, "truncate: must be :error or :silent (got #{truncate.inspect})"
|
|
217
241
|
end
|
|
@@ -249,7 +273,7 @@ class CArray
|
|
|
249
273
|
# @param encoding [Encoding] column encoding; defaults to the encoding
|
|
250
274
|
# the array carries, and to UTF-8 for one that carries none.
|
|
251
275
|
# @return [CAConstString]
|
|
252
|
-
def to_const_string
|
|
276
|
+
def to_const_string(encoding: respond_to?(:encoding) ? self.encoding : Encoding::UTF_8)
|
|
253
277
|
if is_a?(CAConstString) && encoding == self.encoding
|
|
254
278
|
return self
|
|
255
279
|
end
|
|
@@ -271,31 +295,31 @@ class CArray
|
|
|
271
295
|
module Mutable
|
|
272
296
|
# Writes per-cell `String#upcase` back into `self`.
|
|
273
297
|
# @return [CAString] the computed values that were written.
|
|
274
|
-
def upcase!
|
|
298
|
+
def upcase!() ; self[] = upcase ; end
|
|
275
299
|
# Writes per-cell `String#downcase` back into `self`.
|
|
276
300
|
# @return [CAString] the computed values that were written.
|
|
277
|
-
def downcase!
|
|
301
|
+
def downcase!() ; self[] = downcase ; end
|
|
278
302
|
# Writes per-cell `String#capitalize` back into `self`.
|
|
279
303
|
# @return [CAString] the computed values that were written.
|
|
280
|
-
def capitalize!
|
|
304
|
+
def capitalize!() ; self[] = capitalize ; end
|
|
281
305
|
# Writes per-cell `String#swapcase` back into `self`.
|
|
282
306
|
# @return [CAString] the computed values that were written.
|
|
283
|
-
def swapcase!
|
|
307
|
+
def swapcase!() ; self[] = swapcase ; end
|
|
284
308
|
# Writes per-cell `String#strip` back into `self`.
|
|
285
309
|
# @return [CAString] the computed values that were written.
|
|
286
|
-
def strip!
|
|
310
|
+
def strip!() ; self[] = strip ; end
|
|
287
311
|
# Writes per-cell `String#lstrip` back into `self`.
|
|
288
312
|
# @return [CAString] the computed values that were written.
|
|
289
|
-
def lstrip!
|
|
313
|
+
def lstrip!() ; self[] = lstrip ; end
|
|
290
314
|
# Writes per-cell `String#rstrip` back into `self`.
|
|
291
315
|
# @return [CAString] the computed values that were written.
|
|
292
|
-
def rstrip!
|
|
316
|
+
def rstrip!() ; self[] = rstrip ; end
|
|
293
317
|
# Writes per-cell `String#chomp` back into `self`.
|
|
294
318
|
# @return [CAString] the computed values that were written.
|
|
295
|
-
def chomp!
|
|
319
|
+
def chomp!(*a) ; self[] = chomp(*a) ; end
|
|
296
320
|
# Writes per-cell `String#gsub` back into `self`.
|
|
297
321
|
# @return [CAString] the computed values that were written.
|
|
298
|
-
def gsub!
|
|
322
|
+
def gsub!(*a, &b) ; self[] = gsub(*a, &b) ; end
|
|
299
323
|
end
|
|
300
324
|
|
|
301
325
|
end
|
|
@@ -307,7 +331,7 @@ class CArray
|
|
|
307
331
|
# boolean array has no string reading and is rejected -- stringify explicitly
|
|
308
332
|
# with #format / CArray.format. (This mirrors the numeric gate that rejects
|
|
309
333
|
# numeric reductions on a String Face.)
|
|
310
|
-
def self.string_face_of
|
|
334
|
+
def self.string_face_of(ca, verb = "CArray.string")
|
|
311
335
|
return ca if ca.is_a?(CArray::StringOperationMixin)
|
|
312
336
|
# Another Face's storage is not its text: a CATime's fixlen surface
|
|
313
337
|
# holds ticks, a categorical's codes.
|