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.
Files changed (277) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -1
  3. data/CHANGELOG.md +7 -1830
  4. data/README.md +62 -35
  5. data/carray.gemspec +16 -4
  6. data/docs/changelogs/CHANGELOG-3.0.md +2464 -0
  7. data/ext/ca_array_pool.c +4 -5
  8. data/ext/ca_axis_descriptor.h +45 -30
  9. data/ext/ca_axis_dispatch.c +7 -4
  10. data/ext/ca_axis_group.c +12 -15
  11. data/ext/ca_bincmp_dispatch.h +16 -38
  12. data/ext/ca_binop_dispatch.c +35 -0
  13. data/ext/ca_binop_dispatch.h +22 -46
  14. data/ext/ca_categorical_iterator.c +36 -34
  15. data/ext/ca_compare.c +0 -1
  16. data/ext/ca_compare.h +8 -1
  17. data/ext/ca_composite_dispatch.h +6 -0
  18. data/ext/ca_for_buffer.h +6 -1
  19. data/ext/ca_group_iter.c +17 -18
  20. data/ext/ca_iter_state_fields.h +196 -0
  21. data/ext/ca_iter_substrate.h +84 -103
  22. data/ext/ca_kernel_iterator.c +125 -89
  23. data/ext/ca_kernel_iterator.h +229 -1504
  24. data/ext/ca_kernel_iterator_internal.h +1167 -0
  25. data/ext/ca_moncmp_dispatch.h +17 -24
  26. data/ext/ca_monop_dispatch.h +25 -74
  27. data/ext/ca_obj_array.c +92 -165
  28. data/ext/ca_obj_bincmp.c +65 -48
  29. data/ext/ca_obj_binop.c +74 -49
  30. data/ext/ca_obj_bitarray.c +7 -21
  31. data/ext/ca_obj_bitfield.c +93 -26
  32. data/ext/ca_obj_block.c +11 -12
  33. data/ext/ca_obj_byte_swap.c +34 -34
  34. data/ext/ca_obj_const_string.c +464 -304
  35. data/ext/ca_obj_face.c +167 -121
  36. data/ext/ca_obj_face.h +32 -170
  37. data/ext/ca_obj_fake.c +127 -34
  38. data/ext/ca_obj_farray.c +13 -9
  39. data/ext/ca_obj_field.c +17 -13
  40. data/ext/ca_obj_fixlen_string.c +57 -34
  41. data/ext/ca_obj_grid.c +149 -113
  42. data/ext/ca_obj_meld.c +28 -26
  43. data/ext/ca_obj_moncmp.c +10 -21
  44. data/ext/ca_obj_monop.c +88 -73
  45. data/ext/ca_obj_object.c +60 -46
  46. data/ext/ca_obj_record.c +74 -22
  47. data/ext/ca_obj_reduce.c +10 -14
  48. data/ext/ca_obj_refer.c +146 -39
  49. data/ext/ca_obj_remap.c +11 -29
  50. data/ext/ca_obj_repeat.c +41 -23
  51. data/ext/ca_obj_roll.c +20 -28
  52. data/ext/ca_obj_select.c +17 -27
  53. data/ext/ca_obj_select_axis.c +35 -42
  54. data/ext/ca_obj_shift.c +22 -42
  55. data/ext/ca_obj_source.c +1 -5
  56. data/ext/ca_obj_stack.c +33 -29
  57. data/ext/ca_obj_stride.c +99 -62
  58. data/ext/ca_obj_string.c +8 -20
  59. data/ext/ca_obj_tile.c +14 -16
  60. data/ext/ca_obj_time.c +12 -23
  61. data/ext/ca_obj_timedelta.c +12 -23
  62. data/ext/ca_obj_transpose.c +8 -10
  63. data/ext/ca_obj_triop.c +48 -49
  64. data/ext/ca_obj_window.c +87 -99
  65. data/ext/ca_op_cmplx64.h +4 -0
  66. data/ext/ca_op_ipower.c +97 -27
  67. data/ext/ca_op_powi.h +9 -28
  68. data/ext/ca_pow5_table.h +2 -1
  69. data/ext/ca_rng_normal.h +4 -0
  70. data/ext/ca_rng_xoshiro256pp.h +3 -0
  71. data/ext/ca_sort_kernels.h +23 -26
  72. data/ext/ca_sweep_engine.c +92 -26
  73. data/ext/ca_sweep_engine.h +22 -15
  74. data/ext/ca_transform_common.c +3 -8
  75. data/ext/ca_triop_dispatch.h +20 -32
  76. data/ext/caframe_csv_reader.c +12 -12
  77. data/ext/carray.h +300 -1009
  78. data/ext/carray_access.c +320 -207
  79. data/ext/carray_address_basis.c +128 -59
  80. data/ext/carray_attribute.c +81 -104
  81. data/ext/carray_bincount.c +12 -14
  82. data/ext/carray_broadcast.c +31 -27
  83. data/ext/carray_call_cfunc.c +174 -285
  84. data/ext/carray_call_cfunc.h +36 -28
  85. data/ext/carray_cast.c +1191 -351
  86. data/ext/carray_cast_func.rb +68 -8
  87. data/ext/carray_class.c +6 -11
  88. data/ext/carray_conversion.c +98 -39
  89. data/ext/carray_copy.c +52 -26
  90. data/ext/carray_core.c +286 -132
  91. data/ext/carray_count.c +53 -22
  92. data/ext/carray_element.c +49 -28
  93. data/ext/carray_factorize.c +64 -63
  94. data/ext/carray_generate.c +26 -19
  95. data/ext/carray_histogram.c +9 -11
  96. data/ext/carray_hold.c +7 -9
  97. data/ext/carray_index_classifier.c +127 -230
  98. data/ext/carray_index_classifier.h +11 -10
  99. data/ext/carray_integer_total.c +523 -0
  100. data/ext/carray_internal.h +1364 -156
  101. data/ext/carray_key_windows.c +3 -3
  102. data/ext/carray_lazy.c +37 -37
  103. data/ext/carray_loop.c +27 -23
  104. data/ext/carray_mask.c +235 -150
  105. data/ext/carray_math_kernel.h +23 -47
  106. data/ext/carray_mathfunc.c +10 -3
  107. data/ext/carray_median_percentile.c +106 -100
  108. data/ext/carray_memory_view.c +83 -69
  109. data/ext/carray_operator.c +490 -128
  110. data/ext/carray_order.c +163 -84
  111. data/ext/carray_partition.c +14 -16
  112. data/ext/carray_random.c +48 -42
  113. data/ext/carray_round.c +33 -5
  114. data/ext/carray_scatter.c +57 -39
  115. data/ext/carray_segment.c +42 -46
  116. data/ext/carray_slab.c +77 -51
  117. data/ext/carray_slab.h +44 -33
  118. data/ext/carray_sort.c +37 -31
  119. data/ext/carray_sort_kernel.c +36 -10
  120. data/ext/carray_struct.c +44 -34
  121. data/ext/carray_test.c +131 -81
  122. data/ext/carray_time_text.c +30 -31
  123. data/ext/carray_undef.c +50 -7
  124. data/ext/carray_utils.c +373 -139
  125. data/ext/extconf.rb +24 -17
  126. data/ext/mk_call_cfunc.rb +25 -31
  127. data/ext/mk_pow5_table.rb +2 -1
  128. data/ext/mkkernel.rb +819 -488
  129. data/ext/ruby_carray.c +47 -42
  130. data/ext/version.h +7 -5
  131. data/lib/carray/attribute.rb +19 -18
  132. data/lib/carray/autoload_carray.rb +20 -15
  133. data/lib/carray/autoload_method_extension.rb +64 -57
  134. data/lib/carray/axis_group.rb +272 -185
  135. data/lib/carray/basics.rb +298 -56
  136. data/lib/carray/bincount_nd.rb +41 -18
  137. data/lib/carray/block_iterator.rb +167 -119
  138. data/lib/carray/boolean_reduce.rb +7 -4
  139. data/lib/carray/categorical.rb +84 -59
  140. data/lib/carray/categorical_iterator.rb +90 -67
  141. data/lib/carray/complex.rb +61 -41
  142. data/lib/carray/conditional.rb +98 -23
  143. data/lib/carray/const_string.rb +112 -46
  144. data/lib/carray/core_extensions.rb +20 -69
  145. data/lib/carray/distance_limit.rb +7 -5
  146. data/lib/carray/factories.rb +269 -0
  147. data/lib/carray/fixlen_string.rb +95 -12
  148. data/lib/carray/frame/column_verbs.rb +76 -9
  149. data/lib/carray/frame/concat.rb +51 -7
  150. data/lib/carray/frame/convert.rb +2 -1
  151. data/lib/carray/frame/csv_parser.rb +20 -5
  152. data/lib/carray/frame/frame.rb +73 -31
  153. data/lib/carray/frame/group.rb +247 -187
  154. data/lib/carray/frame/io.rb +36 -12
  155. data/lib/carray/frame/join.rb +56 -17
  156. data/lib/carray/frame/records.rb +7 -5
  157. data/lib/carray/frame/reshape.rb +27 -7
  158. data/lib/carray/frame/sort.rb +10 -8
  159. data/lib/carray/frame/verbs.rb +217 -134
  160. data/lib/carray/frame/windows.rb +254 -19
  161. data/lib/carray/frame.rb +1 -2
  162. data/lib/carray/fuse_source.rb +28 -23
  163. data/lib/carray/fusion.rb +30 -30
  164. data/lib/carray/histogram.rb +35 -16
  165. data/lib/carray/inspect.rb +7 -7
  166. data/lib/carray/iterator.rb +104 -23
  167. data/lib/carray/key_windows.rb +93 -61
  168. data/lib/carray/lazy.rb +208 -111
  169. data/lib/carray/limits.rb +80 -0
  170. data/lib/carray/mask_gap_fill.rb +21 -16
  171. data/lib/carray/math.rb +87 -50
  172. data/lib/carray/meld_reduce.rb +30 -8
  173. data/lib/carray/methods/align_addr.rb +29 -17
  174. data/lib/carray/methods/bin.rb +8 -1
  175. data/lib/carray/methods/bincount.rb +4 -2
  176. data/lib/carray/methods/bit_string.rb +19 -31
  177. data/lib/carray/methods/broadcast.rb +8 -3
  178. data/lib/carray/methods/choose.rb +5 -5
  179. data/lib/carray/methods/composition.rb +73 -72
  180. data/lib/carray/methods/{index.rb → coordinate.rb} +13 -13
  181. data/lib/carray/methods/discovery_along.rb +3 -3
  182. data/lib/carray/methods/factorize.rb +2 -0
  183. data/lib/carray/methods/gather_nd.rb +106 -103
  184. data/lib/carray/methods/insert_block.rb +2 -2
  185. data/lib/carray/methods/is_between.rb +6 -4
  186. data/lib/carray/methods/is_in.rb +183 -143
  187. data/lib/carray/methods/join.rb +2 -1
  188. data/lib/carray/methods/lag.rb +6 -2
  189. data/lib/carray/methods/locate_addr.rb +157 -94
  190. data/lib/carray/methods/mask_duplicates.rb +1 -1
  191. data/lib/carray/methods/meshgrid.rb +28 -16
  192. data/lib/carray/methods/mode.rb +67 -67
  193. data/lib/carray/methods/nunique.rb +9 -7
  194. data/lib/carray/methods/repeat.rb +23 -13
  195. data/lib/carray/methods/resize.rb +1 -1
  196. data/lib/carray/methods/snap.rb +24 -20
  197. data/lib/carray/methods/string_format.rb +2 -2
  198. data/lib/carray/methods/unique.rb +4 -2
  199. data/lib/carray/methods/value_counts.rb +1 -1
  200. data/lib/carray/mkmf.rb +25 -28
  201. data/lib/carray/percentile_arguments.rb +82 -0
  202. data/lib/carray/record_order.rb +50 -20
  203. data/lib/carray/rng.rb +1 -0
  204. data/lib/carray/runtime.rb +195 -17
  205. data/lib/carray/segment_iterator.rb +262 -137
  206. data/lib/carray/serialize.rb +635 -566
  207. data/lib/carray/slab_iterator.rb +114 -114
  208. data/lib/carray/stack.rb +14 -15
  209. data/lib/carray/string.rb +16 -22
  210. data/lib/carray/string_operation_extension.rb +97 -52
  211. data/lib/carray/struct.rb +122 -164
  212. data/lib/carray/struct_builder.rb +247 -73
  213. data/lib/carray/time.rb +663 -365
  214. data/lib/carray/window_iterator.rb +232 -155
  215. data/lib/carray.rb +6 -11
  216. data/yard-stubs/ca_obj_array.rb +20 -135
  217. data/yard-stubs/ca_obj_bitarray.rb +1 -8
  218. data/yard-stubs/ca_obj_bitfield.rb +6 -2
  219. data/yard-stubs/ca_obj_byte_swap.rb +21 -7
  220. data/yard-stubs/ca_obj_fake.rb +3 -1
  221. data/yard-stubs/ca_obj_farray.rb +1 -1
  222. data/yard-stubs/ca_obj_field.rb +8 -6
  223. data/yard-stubs/ca_obj_refer.rb +10 -5
  224. data/yard-stubs/ca_obj_roll.rb +7 -6
  225. data/yard-stubs/ca_obj_shift.rb +2 -3
  226. data/yard-stubs/ca_obj_stride.rb +5 -7
  227. data/yard-stubs/ca_obj_tile.rb +1 -1
  228. data/yard-stubs/ca_obj_time.rb +43 -0
  229. data/yard-stubs/ca_obj_transpose.rb +1 -1
  230. data/yard-stubs/ca_obj_window.rb +28 -16
  231. data/yard-stubs/carray_access.rb +55 -6
  232. data/yard-stubs/carray_attribute.rb +26 -38
  233. data/yard-stubs/carray_cast.rb +121 -162
  234. data/yard-stubs/carray_class.rb +3 -4
  235. data/yard-stubs/carray_conversion.rb +6 -7
  236. data/yard-stubs/carray_copy.rb +2 -1
  237. data/yard-stubs/carray_count.rb +10 -5
  238. data/yard-stubs/carray_element.rb +4 -3
  239. data/yard-stubs/carray_limits.rb +100 -0
  240. data/yard-stubs/carray_loop.rb +0 -20
  241. data/yard-stubs/carray_mask.rb +59 -41
  242. data/yard-stubs/carray_math.rb +162 -100
  243. data/yard-stubs/carray_mathfunc.rb +415 -3
  244. data/yard-stubs/carray_median_percentile.rb +29 -11
  245. data/yard-stubs/carray_memory_view.rb +2 -2
  246. data/yard-stubs/carray_order.rb +72 -33
  247. data/yard-stubs/carray_random.rb +6 -6
  248. data/yard-stubs/carray_reduce.rb +353 -0
  249. data/yard-stubs/carray_rng.rb +92 -0
  250. data/yard-stubs/carray_scatter.rb +12 -3
  251. data/yard-stubs/carray_slab.rb +7 -4
  252. data/yard-stubs/carray_sort.rb +7 -6
  253. data/yard-stubs/carray_test.rb +18 -5
  254. data/yard-stubs/carray_undef.rb +44 -5
  255. data/yard-stubs/ruby_carray.rb +75 -40
  256. metadata +63 -25
  257. data/CHANGELOG.v1.md +0 -126
  258. data/ext/carray_build_flags.h +0 -3
  259. data/ext/carray_config.h +0 -28
  260. data/ext/carray_data_type.c +0 -90
  261. data/ext/carray_kernels_bincmp.c +0 -6457
  262. data/ext/carray_kernels_binop.c +0 -31534
  263. data/ext/carray_kernels_init.c +0 -1734
  264. data/ext/carray_kernels_moncmp.c +0 -2104
  265. data/ext/carray_kernels_monop.c +0 -25387
  266. data/ext/carray_kernels_reduce_aggregate.c +0 -27545
  267. data/ext/carray_kernels_reduce_boolean.c +0 -1924
  268. data/ext/carray_kernels_reduce_cumulative.c +0 -11646
  269. data/ext/carray_kernels_reduce_extreme.c +0 -21631
  270. data/ext/carray_kernels_reduce_variance.c +0 -5981
  271. data/ext/carray_kernels_scan.c +0 -4302
  272. data/ext/carray_kernels_search.c +0 -37776
  273. data/ext/carray_kernels_sort.c +0 -10814
  274. data/ext/carray_kernels_triop.c +0 -1864
  275. data/lib/carray/construct.rb +0 -360
  276. data/lib/carray/data_type_extension.rb +0 -261
  277. 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 -> :int CArray
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 (data_type = nil) # :nodoc:
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 () ; string_map { |s| s.upcase } ; end
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 () ; string_map { |s| s.downcase } ; end
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 () ; string_map { |s| s.capitalize } ; end
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 () ; string_map { |s| s.swapcase } ; end
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 () ; string_map { |s| s.strip } ; end
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 () ; string_map { |s| s.lstrip } ; end
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 () ; string_map { |s| s.rstrip } ; end
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 (*a) ; string_map { |s| s.chomp(*a) } ; end
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 (*a, &b) ; string_map { |s| s.gsub(*a, &b) } ; end
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 (p) ; string_map { |s| s.delete_prefix(p) } ; end
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 (p) ; string_map { |s| s.delete_suffix(p) } ; end
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 (*a) ; string_map { |s| s.center(*a) } ; end
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 (*a) ; string_map { |s| s.ljust(*a) } ; end
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 (*a) ; string_map { |s| s.rjust(*a) } ; end
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 (*a) ; string_map { |s| s.encode(*a) } ; end
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 (e) ; string_map { |s| s.force_encoding(e) } ; end
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 () ; string_map { |s| s.scrub } ; end
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? (*a) ; string_map(:boolean) { |s| s.start_with?(*a) } ; end
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? (*a) ; string_map(:boolean) { |s| s.end_with?(*a) } ; end
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? (sub) ; string_map(:boolean) { |s| s.include?(sub) } ; end
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? (re) ; string_map(:boolean) { |s| s.match?(re) } ; end
150
+ def match?(re) ; string_map(:boolean) { |s| s.match?(re) } ; end
117
151
 
118
- # ---- length / position (Integer result -> :int) ----------------------
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] `:int`, shape and mask of `self` preserved.
125
- def str_len () ; string_map(:int) { |s| s.length } ; end
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] `:int`, shape and mask of `self` preserved.
128
- def bytesize () ; string_map(:int) { |s| s.bytesize } ; end
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] `:int`, shape and mask of `self` preserved; UNDEF
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 (*a) ; string_map(:int) { |s| s.index(*a) } ; end
166
+ def str_index(*a) ; string_map(:int32) { |s| s.index(*a) } ; end
133
167
  # Per-cell `String#rindex`.
134
- # @return [CArray] `:int`, shape and mask of `self` preserved; UNDEF
168
+ # @return [CArray] `:int32`, shape and mask of `self` preserved; UNDEF
135
169
  # where the cell does not hold the substring.
136
- def rindex (*a) ; string_map(:int) { |s| s.rindex(*a) } ; end
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] `:int`, shape and mask of `self` preserved.
142
- def to_i () ; string_map(:int) { |s| s.to_i } ; end
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 () ; string_map(:float64) { |s| s.to_f } ; end
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
- def in? (*strings)
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 (regexp, replace = '\0')
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 (bytes: nil, truncate: :error)
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.wrap(entity)
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! () ; self[] = upcase ; end
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! () ; self[] = downcase ; end
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! () ; self[] = capitalize ; end
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! () ; self[] = swapcase ; end
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! () ; self[] = strip ; end
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! () ; self[] = lstrip ; end
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! () ; self[] = rstrip ; end
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! (*a) ; self[] = chomp(*a) ; end
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! (*a, &b) ; self[] = gsub(*a, &b) ; end
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 (ca, verb = "CArray.string")
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.