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
|
@@ -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.
|
|
@@ -44,59 +59,78 @@ class CArray
|
|
|
44
59
|
end
|
|
45
60
|
private :string_map
|
|
46
61
|
|
|
62
|
+
# An ordering (pmax and its kin, clip) with a value that is not a String
|
|
63
|
+
# is refused as String#< refuses it. nil (no bound, for clip), UNDEF,
|
|
64
|
+
# an Array and a CArray are left to the operation.
|
|
65
|
+
def refuse_unordered_operands(verb, *operands)
|
|
66
|
+
operands.each do |v|
|
|
67
|
+
next if v.nil? || v.is_a?(String) || v.is_a?(Array) || v.is_a?(CArray) || UNDEF.equal?(v)
|
|
68
|
+
name = v.is_a?(Symbol) ? v.inspect : v.class
|
|
69
|
+
raise ArgumentError, "#{verb}: comparison of String with #{name} failed"
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
private :refuse_unordered_operands
|
|
73
|
+
|
|
74
|
+
# Clips the strings in byte order (see {CArray#clip}); a bound that is
|
|
75
|
+
# not a String is refused.
|
|
76
|
+
def clip(min, max = nil, **kw)
|
|
77
|
+
refuse_unordered_operands("clip", min, max)
|
|
78
|
+
super
|
|
79
|
+
end
|
|
80
|
+
|
|
47
81
|
# ---- transforms (String result -> CAString) --------------------------
|
|
48
82
|
|
|
49
83
|
# Per-cell `String#upcase`.
|
|
50
84
|
# @return [CAString] shape and mask of `self` preserved.
|
|
51
|
-
def upcase
|
|
85
|
+
def upcase() ; string_map { |s| s.upcase } ; end
|
|
52
86
|
# Per-cell `String#downcase`.
|
|
53
87
|
# @return [CAString] shape and mask of `self` preserved.
|
|
54
|
-
def downcase
|
|
88
|
+
def downcase() ; string_map { |s| s.downcase } ; end
|
|
55
89
|
# Per-cell `String#capitalize`.
|
|
56
90
|
# @return [CAString] shape and mask of `self` preserved.
|
|
57
|
-
def capitalize
|
|
91
|
+
def capitalize() ; string_map { |s| s.capitalize } ; end
|
|
58
92
|
# Per-cell `String#swapcase`.
|
|
59
93
|
# @return [CAString] shape and mask of `self` preserved.
|
|
60
|
-
def swapcase
|
|
94
|
+
def swapcase() ; string_map { |s| s.swapcase } ; end
|
|
61
95
|
# Per-cell `String#strip`.
|
|
62
96
|
# @return [CAString] shape and mask of `self` preserved.
|
|
63
|
-
def strip
|
|
97
|
+
def strip() ; string_map { |s| s.strip } ; end
|
|
64
98
|
# Per-cell `String#lstrip`.
|
|
65
99
|
# @return [CAString] shape and mask of `self` preserved.
|
|
66
|
-
def lstrip
|
|
100
|
+
def lstrip() ; string_map { |s| s.lstrip } ; end
|
|
67
101
|
# Per-cell `String#rstrip`.
|
|
68
102
|
# @return [CAString] shape and mask of `self` preserved.
|
|
69
|
-
def rstrip
|
|
103
|
+
def rstrip() ; string_map { |s| s.rstrip } ; end
|
|
70
104
|
# Per-cell `String#chomp`.
|
|
71
105
|
# @return [CAString] shape and mask of `self` preserved.
|
|
72
|
-
def chomp
|
|
106
|
+
def chomp(*a) ; string_map { |s| s.chomp(*a) } ; end
|
|
73
107
|
# Per-cell `String#gsub`.
|
|
74
108
|
# @return [CAString] shape and mask of `self` preserved.
|
|
75
|
-
def gsub
|
|
109
|
+
def gsub(*a, &b) ; string_map { |s| s.gsub(*a, &b) } ; end
|
|
76
110
|
# Per-cell `String#delete_prefix`.
|
|
77
111
|
# @return [CAString] shape and mask of `self` preserved.
|
|
78
|
-
def delete_prefix
|
|
112
|
+
def delete_prefix(p) ; string_map { |s| s.delete_prefix(p) } ; end
|
|
79
113
|
# Per-cell `String#delete_suffix`.
|
|
80
114
|
# @return [CAString] shape and mask of `self` preserved.
|
|
81
|
-
def delete_suffix
|
|
115
|
+
def delete_suffix(p) ; string_map { |s| s.delete_suffix(p) } ; end
|
|
82
116
|
# Per-cell `String#center`.
|
|
83
117
|
# @return [CAString] shape and mask of `self` preserved.
|
|
84
|
-
def center
|
|
118
|
+
def center(*a) ; string_map { |s| s.center(*a) } ; end
|
|
85
119
|
# Per-cell `String#ljust`.
|
|
86
120
|
# @return [CAString] shape and mask of `self` preserved.
|
|
87
|
-
def ljust
|
|
121
|
+
def ljust(*a) ; string_map { |s| s.ljust(*a) } ; end
|
|
88
122
|
# Per-cell `String#rjust`.
|
|
89
123
|
# @return [CAString] shape and mask of `self` preserved.
|
|
90
|
-
def rjust
|
|
124
|
+
def rjust(*a) ; string_map { |s| s.rjust(*a) } ; end
|
|
91
125
|
# Per-cell `String#encode`.
|
|
92
126
|
# @return [CAString] shape and mask of `self` preserved.
|
|
93
|
-
def encode
|
|
127
|
+
def encode(*a) ; string_map { |s| s.encode(*a) } ; end
|
|
94
128
|
# Per-cell `String#force_encoding`.
|
|
95
129
|
# @return [CAString] shape and mask of `self` preserved.
|
|
96
|
-
def force_encoding
|
|
130
|
+
def force_encoding(e) ; string_map { |s| s.dup.force_encoding(e) } ; end
|
|
97
131
|
# Per-cell `String#scrub`.
|
|
98
132
|
# @return [CAString] shape and mask of `self` preserved.
|
|
99
|
-
def scrub
|
|
133
|
+
def scrub() ; string_map { |s| s.scrub } ; end
|
|
100
134
|
|
|
101
135
|
# ---- predicates (Boolean result -> :boolean) -------------------------
|
|
102
136
|
# start_with? / end_with? / include? are byte-level and free of collisions
|
|
@@ -104,55 +138,64 @@ class CArray
|
|
|
104
138
|
|
|
105
139
|
# Per-cell `String#start_with?`.
|
|
106
140
|
# @return [CArray] boolean, shape and mask of `self` preserved.
|
|
107
|
-
def start_with?
|
|
141
|
+
def start_with?(*a) ; string_map(:boolean) { |s| s.start_with?(*a) } ; end
|
|
108
142
|
# Per-cell `String#end_with?`.
|
|
109
143
|
# @return [CArray] boolean, shape and mask of `self` preserved.
|
|
110
|
-
def end_with?
|
|
144
|
+
def end_with?(*a) ; string_map(:boolean) { |s| s.end_with?(*a) } ; end
|
|
111
145
|
# Per-cell `String#include?`.
|
|
112
146
|
# @return [CArray] boolean, shape and mask of `self` preserved.
|
|
113
|
-
def include?
|
|
147
|
+
def include?(sub) ; string_map(:boolean) { |s| s.include?(sub) } ; end
|
|
114
148
|
# Per-cell `String#match?`.
|
|
115
149
|
# @return [CArray] boolean, shape and mask of `self` preserved.
|
|
116
|
-
def match?
|
|
150
|
+
def match?(re) ; string_map(:boolean) { |s| s.match?(re) } ; end
|
|
117
151
|
|
|
118
|
-
# ---- length / position (Integer result -> :
|
|
152
|
+
# ---- length / position (Integer result -> :int32) ----------------------
|
|
119
153
|
# `str_len` keeps the prefix because bare #length / #size mean element
|
|
120
154
|
# count on a CArray; `str_index` because bare #index is an array method.
|
|
121
155
|
# `bytesize` / `rindex` have no array-level collision, so they stay bare.
|
|
122
156
|
|
|
123
157
|
# Per-cell `String#length`.
|
|
124
|
-
# @return [CArray] `:
|
|
125
|
-
def str_len
|
|
158
|
+
# @return [CArray] `:int32`, shape and mask of `self` preserved.
|
|
159
|
+
def str_len() ; string_map(:int32) { |s| s.length } ; end
|
|
126
160
|
# Per-cell `String#bytesize`.
|
|
127
|
-
# @return [CArray] `:
|
|
128
|
-
def bytesize
|
|
161
|
+
# @return [CArray] `:int32`, shape and mask of `self` preserved.
|
|
162
|
+
def bytesize() ; string_map(:int32) { |s| s.bytesize } ; end
|
|
129
163
|
# Per-cell `String#index`.
|
|
130
|
-
# @return [CArray] `:
|
|
164
|
+
# @return [CArray] `:int32`, shape and mask of `self` preserved; UNDEF
|
|
131
165
|
# where the cell does not hold the substring.
|
|
132
|
-
def str_index
|
|
166
|
+
def str_index(*a) ; string_map(:int32) { |s| s.index(*a) } ; end
|
|
133
167
|
# Per-cell `String#rindex`.
|
|
134
|
-
# @return [CArray] `:
|
|
168
|
+
# @return [CArray] `:int32`, shape and mask of `self` preserved; UNDEF
|
|
135
169
|
# where the cell does not hold the substring.
|
|
136
|
-
def rindex
|
|
170
|
+
def rindex(*a) ; string_map(:int32) { |s| s.rindex(*a) } ; end
|
|
137
171
|
|
|
138
172
|
# ---- numeric parse (Integer / Float result) --------------------------
|
|
139
173
|
|
|
140
174
|
# Per-cell `String#to_i`.
|
|
141
|
-
# @return [CArray] `:
|
|
142
|
-
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
|
|
143
177
|
# Per-cell `String#to_f`.
|
|
144
178
|
# @return [CArray] `float64`, shape and mask of `self` preserved.
|
|
145
|
-
def to_f
|
|
179
|
+
def to_f() ; string_map(:float64) { |s| s.to_f } ; end
|
|
146
180
|
|
|
147
181
|
# ---- membership ------------------------------------------------------
|
|
148
182
|
|
|
149
183
|
# @overload in?(*strings)
|
|
150
184
|
# Returns a boolean CArray marking every cell whose value equals one of
|
|
151
185
|
# `strings` (set membership). The string counterpart of `#match?` for
|
|
152
|
-
# 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}.
|
|
153
189
|
# @param strings [Array<String>]
|
|
154
190
|
# @return [CArray]
|
|
155
|
-
|
|
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
|
|
156
199
|
string_map(:boolean) { |s| strings.include?(s) }
|
|
157
200
|
end
|
|
158
201
|
|
|
@@ -164,7 +207,7 @@ class CArray
|
|
|
164
207
|
# @param regexp [Regexp]
|
|
165
208
|
# @param replace [String]
|
|
166
209
|
# @return [CAString]
|
|
167
|
-
def extract
|
|
210
|
+
def extract(regexp, replace = '\0')
|
|
168
211
|
string_map { |s| regexp.match(s) { |m| m[0].sub(regexp, replace) } || UNDEF }
|
|
169
212
|
end
|
|
170
213
|
|
|
@@ -192,7 +235,7 @@ class CArray
|
|
|
192
235
|
# @param bytes [Integer, nil] slot width; defaults to the max bytesize.
|
|
193
236
|
# @param truncate [Symbol] :error or :silent (see {CArray.fixlen_string}).
|
|
194
237
|
# @return [CAFixlenString]
|
|
195
|
-
def to_fixlen_string
|
|
238
|
+
def to_fixlen_string(bytes: nil, truncate: :error)
|
|
196
239
|
unless [:error, :silent].include?(truncate)
|
|
197
240
|
raise ArgumentError, "truncate: must be :error or :silent (got #{truncate.inspect})"
|
|
198
241
|
end
|
|
@@ -221,14 +264,16 @@ class CArray
|
|
|
221
264
|
end
|
|
222
265
|
entity = CArray.new(CA_FIXLEN, shape, :bytes => width)
|
|
223
266
|
values.each_with_index { |s, i| entity[i] = s.nil? ? UNDEF : s }
|
|
224
|
-
CAFixlenString.
|
|
267
|
+
text = respond_to?(:encoding) ? encoding : CAFixlenString.__send__(:encoding_of_strings, values)
|
|
268
|
+
CAFixlenString.wrap(entity, encoding: text)
|
|
225
269
|
end
|
|
226
270
|
|
|
227
271
|
# Self (zero-copy) when already a {CAConstString} of the same encoding;
|
|
228
272
|
# otherwise materialises a compact column.
|
|
229
|
-
# @param encoding [Encoding] column encoding
|
|
273
|
+
# @param encoding [Encoding] column encoding; defaults to the encoding
|
|
274
|
+
# the array carries, and to UTF-8 for one that carries none.
|
|
230
275
|
# @return [CAConstString]
|
|
231
|
-
def to_const_string (encoding: Encoding::UTF_8)
|
|
276
|
+
def to_const_string(encoding: respond_to?(:encoding) ? self.encoding : Encoding::UTF_8)
|
|
232
277
|
if is_a?(CAConstString) && encoding == self.encoding
|
|
233
278
|
return self
|
|
234
279
|
end
|
|
@@ -250,31 +295,31 @@ class CArray
|
|
|
250
295
|
module Mutable
|
|
251
296
|
# Writes per-cell `String#upcase` back into `self`.
|
|
252
297
|
# @return [CAString] the computed values that were written.
|
|
253
|
-
def upcase!
|
|
298
|
+
def upcase!() ; self[] = upcase ; end
|
|
254
299
|
# Writes per-cell `String#downcase` back into `self`.
|
|
255
300
|
# @return [CAString] the computed values that were written.
|
|
256
|
-
def downcase!
|
|
301
|
+
def downcase!() ; self[] = downcase ; end
|
|
257
302
|
# Writes per-cell `String#capitalize` back into `self`.
|
|
258
303
|
# @return [CAString] the computed values that were written.
|
|
259
|
-
def capitalize!
|
|
304
|
+
def capitalize!() ; self[] = capitalize ; end
|
|
260
305
|
# Writes per-cell `String#swapcase` back into `self`.
|
|
261
306
|
# @return [CAString] the computed values that were written.
|
|
262
|
-
def swapcase!
|
|
307
|
+
def swapcase!() ; self[] = swapcase ; end
|
|
263
308
|
# Writes per-cell `String#strip` back into `self`.
|
|
264
309
|
# @return [CAString] the computed values that were written.
|
|
265
|
-
def strip!
|
|
310
|
+
def strip!() ; self[] = strip ; end
|
|
266
311
|
# Writes per-cell `String#lstrip` back into `self`.
|
|
267
312
|
# @return [CAString] the computed values that were written.
|
|
268
|
-
def lstrip!
|
|
313
|
+
def lstrip!() ; self[] = lstrip ; end
|
|
269
314
|
# Writes per-cell `String#rstrip` back into `self`.
|
|
270
315
|
# @return [CAString] the computed values that were written.
|
|
271
|
-
def rstrip!
|
|
316
|
+
def rstrip!() ; self[] = rstrip ; end
|
|
272
317
|
# Writes per-cell `String#chomp` back into `self`.
|
|
273
318
|
# @return [CAString] the computed values that were written.
|
|
274
|
-
def chomp!
|
|
319
|
+
def chomp!(*a) ; self[] = chomp(*a) ; end
|
|
275
320
|
# Writes per-cell `String#gsub` back into `self`.
|
|
276
321
|
# @return [CAString] the computed values that were written.
|
|
277
|
-
def gsub!
|
|
322
|
+
def gsub!(*a, &b) ; self[] = gsub(*a, &b) ; end
|
|
278
323
|
end
|
|
279
324
|
|
|
280
325
|
end
|
|
@@ -286,7 +331,7 @@ class CArray
|
|
|
286
331
|
# boolean array has no string reading and is rejected -- stringify explicitly
|
|
287
332
|
# with #format / CArray.format. (This mirrors the numeric gate that rejects
|
|
288
333
|
# numeric reductions on a String Face.)
|
|
289
|
-
def self.string_face_of
|
|
334
|
+
def self.string_face_of(ca, verb = "CArray.string")
|
|
290
335
|
return ca if ca.is_a?(CArray::StringOperationMixin)
|
|
291
336
|
# Another Face's storage is not its text: a CATime's fixlen surface
|
|
292
337
|
# holds ticks, a categorical's codes.
|