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.
Files changed (275) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -1
  3. data/CHANGELOG.md +7 -1940
  4. data/README.md +38 -32
  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 +6 -9
  11. data/ext/ca_bincmp_dispatch.h +16 -38
  12. data/ext/ca_binop_dispatch.c +27 -0
  13. data/ext/ca_binop_dispatch.h +22 -47
  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 -1506
  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 +90 -163
  28. data/ext/ca_obj_bincmp.c +47 -46
  29. data/ext/ca_obj_binop.c +38 -38
  30. data/ext/ca_obj_bitarray.c +5 -17
  31. data/ext/ca_obj_bitfield.c +15 -30
  32. data/ext/ca_obj_block.c +11 -12
  33. data/ext/ca_obj_byte_swap.c +32 -30
  34. data/ext/ca_obj_const_string.c +57 -62
  35. data/ext/ca_obj_face.c +99 -91
  36. data/ext/ca_obj_face.h +32 -170
  37. data/ext/ca_obj_fake.c +15 -21
  38. data/ext/ca_obj_farray.c +7 -9
  39. data/ext/ca_obj_field.c +17 -13
  40. data/ext/ca_obj_fixlen_string.c +8 -19
  41. data/ext/ca_obj_grid.c +137 -106
  42. data/ext/ca_obj_meld.c +23 -21
  43. data/ext/ca_obj_moncmp.c +10 -21
  44. data/ext/ca_obj_monop.c +24 -35
  45. data/ext/ca_obj_object.c +51 -37
  46. data/ext/ca_obj_record.c +74 -22
  47. data/ext/ca_obj_reduce.c +8 -10
  48. data/ext/ca_obj_refer.c +42 -29
  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 +18 -24
  52. data/ext/ca_obj_select.c +10 -22
  53. data/ext/ca_obj_select_axis.c +27 -36
  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 +28 -24
  57. data/ext/ca_obj_stride.c +53 -54
  58. data/ext/ca_obj_string.c +6 -18
  59. data/ext/ca_obj_tile.c +12 -12
  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 +35 -39
  64. data/ext/ca_obj_window.c +67 -86
  65. data/ext/ca_op_cmplx64.h +4 -0
  66. data/ext/ca_op_ipower.c +34 -12
  67. data/ext/ca_op_powi.h +4 -0
  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 +20 -26
  72. data/ext/ca_sweep_engine.c +2 -3
  73. data/ext/ca_sweep_engine.h +17 -9
  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 +11 -11
  77. data/ext/carray.h +300 -1011
  78. data/ext/carray_access.c +234 -180
  79. data/ext/carray_address_basis.c +33 -38
  80. data/ext/carray_attribute.c +81 -104
  81. data/ext/carray_bincount.c +12 -14
  82. data/ext/carray_broadcast.c +30 -26
  83. data/ext/carray_call_cfunc.c +169 -277
  84. data/ext/carray_call_cfunc.h +36 -28
  85. data/ext/carray_cast.c +912 -346
  86. data/ext/carray_cast_func.rb +31 -3
  87. data/ext/carray_class.c +6 -11
  88. data/ext/carray_conversion.c +43 -38
  89. data/ext/carray_copy.c +28 -26
  90. data/ext/carray_core.c +217 -126
  91. data/ext/carray_count.c +27 -15
  92. data/ext/carray_element.c +40 -25
  93. data/ext/carray_factorize.c +53 -52
  94. data/ext/carray_generate.c +26 -19
  95. data/ext/carray_histogram.c +8 -10
  96. data/ext/carray_hold.c +7 -9
  97. data/ext/carray_index_classifier.c +123 -228
  98. data/ext/carray_index_classifier.h +11 -10
  99. data/ext/carray_integer_total.c +523 -0
  100. data/ext/carray_internal.h +1274 -160
  101. data/ext/carray_key_windows.c +3 -3
  102. data/ext/carray_lazy.c +21 -36
  103. data/ext/carray_loop.c +19 -22
  104. data/ext/carray_mask.c +123 -145
  105. data/ext/carray_math_kernel.h +23 -47
  106. data/ext/carray_mathfunc.c +10 -3
  107. data/ext/carray_median_percentile.c +95 -94
  108. data/ext/carray_memory_view.c +42 -47
  109. data/ext/carray_operator.c +423 -122
  110. data/ext/carray_order.c +121 -85
  111. data/ext/carray_partition.c +13 -15
  112. data/ext/carray_random.c +47 -41
  113. data/ext/carray_round.c +9 -4
  114. data/ext/carray_scatter.c +54 -40
  115. data/ext/carray_segment.c +41 -45
  116. data/ext/carray_slab.c +64 -47
  117. data/ext/carray_slab.h +44 -33
  118. data/ext/carray_sort.c +32 -29
  119. data/ext/carray_sort_kernel.c +12 -10
  120. data/ext/carray_struct.c +38 -43
  121. data/ext/carray_test.c +47 -43
  122. data/ext/carray_time_text.c +24 -31
  123. data/ext/carray_undef.c +50 -7
  124. data/ext/carray_utils.c +258 -94
  125. data/ext/extconf.rb +24 -17
  126. data/ext/mk_call_cfunc.rb +19 -20
  127. data/ext/mk_pow5_table.rb +2 -1
  128. data/ext/mkkernel.rb +782 -461
  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 +264 -180
  135. data/lib/carray/basics.rb +272 -48
  136. data/lib/carray/bincount_nd.rb +33 -16
  137. data/lib/carray/block_iterator.rb +123 -102
  138. data/lib/carray/boolean_reduce.rb +7 -4
  139. data/lib/carray/categorical.rb +63 -51
  140. data/lib/carray/categorical_iterator.rb +89 -67
  141. data/lib/carray/complex.rb +61 -41
  142. data/lib/carray/conditional.rb +49 -22
  143. data/lib/carray/const_string.rb +54 -62
  144. data/lib/carray/core_extensions.rb +1 -1
  145. data/lib/carray/distance_limit.rb +7 -5
  146. data/lib/carray/factories.rb +269 -0
  147. data/lib/carray/fixlen_string.rb +25 -24
  148. data/lib/carray/frame/column_verbs.rb +20 -8
  149. data/lib/carray/frame/concat.rb +3 -3
  150. data/lib/carray/frame/convert.rb +2 -1
  151. data/lib/carray/frame/csv_parser.rb +7 -1
  152. data/lib/carray/frame/frame.rb +35 -25
  153. data/lib/carray/frame/group.rb +183 -150
  154. data/lib/carray/frame/io.rb +26 -7
  155. data/lib/carray/frame/join.rb +37 -12
  156. data/lib/carray/frame/records.rb +1 -1
  157. data/lib/carray/frame/reshape.rb +3 -3
  158. data/lib/carray/frame/sort.rb +10 -8
  159. data/lib/carray/frame/verbs.rb +148 -118
  160. data/lib/carray/frame/windows.rb +232 -21
  161. data/lib/carray/frame.rb +1 -2
  162. data/lib/carray/fuse_source.rb +24 -21
  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 +97 -24
  167. data/lib/carray/key_windows.rb +83 -57
  168. data/lib/carray/lazy.rb +196 -94
  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 +5 -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 +72 -71
  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/gather_nd.rb +106 -106
  183. data/lib/carray/methods/insert_block.rb +2 -2
  184. data/lib/carray/methods/is_between.rb +6 -4
  185. data/lib/carray/methods/is_in.rb +165 -145
  186. data/lib/carray/methods/join.rb +2 -1
  187. data/lib/carray/methods/lag.rb +6 -2
  188. data/lib/carray/methods/locate_addr.rb +150 -138
  189. data/lib/carray/methods/mask_duplicates.rb +1 -1
  190. data/lib/carray/methods/meshgrid.rb +28 -16
  191. data/lib/carray/methods/mode.rb +67 -67
  192. data/lib/carray/methods/nunique.rb +9 -7
  193. data/lib/carray/methods/repeat.rb +12 -12
  194. data/lib/carray/methods/resize.rb +1 -1
  195. data/lib/carray/methods/snap.rb +24 -20
  196. data/lib/carray/methods/string_format.rb +2 -2
  197. data/lib/carray/methods/unique.rb +4 -2
  198. data/lib/carray/methods/value_counts.rb +1 -1
  199. data/lib/carray/mkmf.rb +25 -28
  200. data/lib/carray/percentile_arguments.rb +82 -0
  201. data/lib/carray/record_order.rb +18 -17
  202. data/lib/carray/rng.rb +1 -0
  203. data/lib/carray/runtime.rb +190 -22
  204. data/lib/carray/segment_iterator.rb +251 -129
  205. data/lib/carray/serialize.rb +618 -571
  206. data/lib/carray/slab_iterator.rb +114 -114
  207. data/lib/carray/stack.rb +11 -12
  208. data/lib/carray/string.rb +16 -22
  209. data/lib/carray/string_operation_extension.rb +76 -52
  210. data/lib/carray/struct.rb +122 -164
  211. data/lib/carray/struct_builder.rb +243 -72
  212. data/lib/carray/time.rb +496 -342
  213. data/lib/carray/window_iterator.rb +191 -150
  214. data/lib/carray.rb +6 -11
  215. data/yard-stubs/ca_obj_array.rb +20 -135
  216. data/yard-stubs/ca_obj_bitarray.rb +1 -8
  217. data/yard-stubs/ca_obj_bitfield.rb +4 -3
  218. data/yard-stubs/ca_obj_byte_swap.rb +21 -7
  219. data/yard-stubs/ca_obj_fake.rb +3 -1
  220. data/yard-stubs/ca_obj_farray.rb +1 -1
  221. data/yard-stubs/ca_obj_field.rb +8 -6
  222. data/yard-stubs/ca_obj_refer.rb +7 -5
  223. data/yard-stubs/ca_obj_roll.rb +7 -6
  224. data/yard-stubs/ca_obj_shift.rb +2 -3
  225. data/yard-stubs/ca_obj_stride.rb +5 -7
  226. data/yard-stubs/ca_obj_tile.rb +1 -1
  227. data/yard-stubs/ca_obj_time.rb +43 -0
  228. data/yard-stubs/ca_obj_transpose.rb +1 -1
  229. data/yard-stubs/ca_obj_window.rb +26 -15
  230. data/yard-stubs/carray_access.rb +51 -4
  231. data/yard-stubs/carray_attribute.rb +26 -38
  232. data/yard-stubs/carray_cast.rb +118 -165
  233. data/yard-stubs/carray_class.rb +3 -4
  234. data/yard-stubs/carray_conversion.rb +6 -7
  235. data/yard-stubs/carray_copy.rb +2 -1
  236. data/yard-stubs/carray_count.rb +5 -3
  237. data/yard-stubs/carray_element.rb +4 -3
  238. data/yard-stubs/carray_limits.rb +100 -0
  239. data/yard-stubs/carray_loop.rb +0 -20
  240. data/yard-stubs/carray_mask.rb +59 -41
  241. data/yard-stubs/carray_math.rb +157 -100
  242. data/yard-stubs/carray_mathfunc.rb +415 -3
  243. data/yard-stubs/carray_median_percentile.rb +29 -11
  244. data/yard-stubs/carray_memory_view.rb +2 -2
  245. data/yard-stubs/carray_order.rb +67 -34
  246. data/yard-stubs/carray_random.rb +6 -6
  247. data/yard-stubs/carray_reduce.rb +353 -0
  248. data/yard-stubs/carray_rng.rb +92 -0
  249. data/yard-stubs/carray_scatter.rb +10 -2
  250. data/yard-stubs/carray_slab.rb +7 -4
  251. data/yard-stubs/carray_sort.rb +7 -6
  252. data/yard-stubs/carray_undef.rb +44 -5
  253. data/yard-stubs/ruby_carray.rb +75 -40
  254. metadata +62 -24
  255. data/CHANGELOG.v1.md +0 -126
  256. data/ext/carray_build_flags.h +0 -3
  257. data/ext/carray_config.h +0 -28
  258. data/ext/carray_data_type.c +0 -90
  259. data/ext/carray_kernels_bincmp.c +0 -6457
  260. data/ext/carray_kernels_binop.c +0 -31534
  261. data/ext/carray_kernels_init.c +0 -1734
  262. data/ext/carray_kernels_moncmp.c +0 -2104
  263. data/ext/carray_kernels_monop.c +0 -25337
  264. data/ext/carray_kernels_reduce_aggregate.c +0 -27545
  265. data/ext/carray_kernels_reduce_boolean.c +0 -1924
  266. data/ext/carray_kernels_reduce_cumulative.c +0 -11646
  267. data/ext/carray_kernels_reduce_extreme.c +0 -21631
  268. data/ext/carray_kernels_reduce_variance.c +0 -5981
  269. data/ext/carray_kernels_scan.c +0 -4302
  270. data/ext/carray_kernels_search.c +0 -37776
  271. data/ext/carray_kernels_sort.c +0 -10814
  272. data/ext/carray_kernels_triop.c +0 -1864
  273. data/lib/carray/construct.rb +0 -360
  274. data/lib/carray/data_type_extension.rb +0 -262
  275. data/lib/carray/data_type_limits.rb +0 -91
@@ -0,0 +1,100 @@
1
+ # DOCUMENTATION ONLY — DO NOT REQUIRE.
2
+ # Stubs for the constants of CArray::Limits, which lib/carray/limits.rb
3
+ # defines with const_set. The values written here are the ones of the
4
+ # usual widths; the library computes them from the widths of the build.
5
+ # See yard-stubs/README.md and yard-stubs/STYLE.md.
6
+
7
+ class CArray
8
+ # What each numeric data type can hold.
9
+ #
10
+ # CArray::Limits::INT32_MAX # => 2147483647
11
+ # CArray::Limits::FLOAT32_EPSILON # => 1.1920928955078125e-07
12
+ #
13
+ # `MIN` and `MAX` bracket the range of every numeric type alike, so for
14
+ # a float type `MIN` is the bottom of the range and not Ruby's
15
+ # `Float::MIN`:
16
+ #
17
+ # CArray::Limits::FLOAT64_MIN # => -1.7976931348623157e+308
18
+ # Float::MIN # => 2.2250738585072014e-308
19
+ #
20
+ # Ruby's `Float::MIN`, the smallest positive normal value, is `TINY`
21
+ # here.
22
+ #
23
+ # Only the integer and float types have limits. A complex type is a
24
+ # pair of floats and is bounded by the limits of its component
25
+ # (`FLOAT32_*` for `:cmplx64`, `FLOAT64_*` for `:cmplx128`). The
26
+ # boolean, fixlen and object types have no numeric range.
27
+ module Limits
28
+ # The smallest value an `:int8` element holds.
29
+ INT8_MIN = -128
30
+
31
+ # The largest value an `:int8` element holds.
32
+ INT8_MAX = 127
33
+
34
+ # The smallest value an `:int16` element holds.
35
+ INT16_MIN = -32768
36
+
37
+ # The largest value an `:int16` element holds.
38
+ INT16_MAX = 32767
39
+
40
+ # The smallest value an `:int32` element holds.
41
+ INT32_MIN = -2147483648
42
+
43
+ # The largest value an `:int32` element holds.
44
+ INT32_MAX = 2147483647
45
+
46
+ # The smallest value an `:int64` element holds.
47
+ INT64_MIN = -9223372036854775808
48
+
49
+ # The largest value an `:int64` element holds.
50
+ INT64_MAX = 9223372036854775807
51
+
52
+ # The smallest value a `:uint8` element holds.
53
+ UINT8_MIN = 0
54
+
55
+ # The largest value a `:uint8` element holds.
56
+ UINT8_MAX = 255
57
+
58
+ # The smallest value a `:uint16` element holds.
59
+ UINT16_MIN = 0
60
+
61
+ # The largest value a `:uint16` element holds.
62
+ UINT16_MAX = 65535
63
+
64
+ # The smallest value a `:uint32` element holds.
65
+ UINT32_MIN = 0
66
+
67
+ # The largest value a `:uint32` element holds.
68
+ UINT32_MAX = 4294967295
69
+
70
+ # The smallest value a `:uint64` element holds.
71
+ UINT64_MIN = 0
72
+
73
+ # The largest value a `:uint64` element holds.
74
+ UINT64_MAX = 18446744073709551615
75
+
76
+ # The step from `1.0` to the next `:float32` value.
77
+ FLOAT32_EPSILON = 1.1920928955078125e-07
78
+
79
+ # The largest finite `:float32` value.
80
+ FLOAT32_MAX = 3.4028234663852886e+38
81
+
82
+ # The most negative finite `:float32` value, `-FLOAT32_MAX`.
83
+ FLOAT32_MIN = -3.4028234663852886e+38
84
+
85
+ # The smallest positive normal `:float32` value.
86
+ FLOAT32_TINY = 1.1754943508222875e-38
87
+
88
+ # The step from `1.0` to the next `:float64` value.
89
+ FLOAT64_EPSILON = 2.220446049250313e-16
90
+
91
+ # The largest finite `:float64` value.
92
+ FLOAT64_MAX = 1.7976931348623157e+308
93
+
94
+ # The most negative finite `:float64` value, `-FLOAT64_MAX`.
95
+ FLOAT64_MIN = -1.7976931348623157e+308
96
+
97
+ # The smallest positive normal `:float64` value.
98
+ FLOAT64_TINY = 2.2250738585072014e-308
99
+ end
100
+ end
@@ -101,26 +101,6 @@ class CArray
101
101
  # @return [self]
102
102
  def map_with_index!; end
103
103
 
104
- # @overload collect!
105
- # Alias of {#map!}.
106
- def collect!; end
107
-
108
- # @overload collect_addr!
109
- # Alias of {#map_addr!}.
110
- def collect_addr!; end
111
-
112
- # @overload collect_index!
113
- # Alias of {#map_index!}.
114
- def collect_index!; end
115
-
116
- # @overload collect_with_addr!
117
- # Alias of {#map_with_addr!}.
118
- def collect_with_addr!; end
119
-
120
- # @overload collect_with_index!
121
- # Alias of {#map_with_index!}.
122
- def collect_with_index!; end
123
-
124
104
  # @!endgroup
125
105
 
126
106
  class << self
@@ -41,8 +41,8 @@ class CArray
41
41
  # reads nothing from the masked ones.
42
42
  #
43
43
  # Nothing in a value array is masked, so `unmask` on it does nothing,
44
- # while a write that would mask a cell (`UNDEF`, `mask=`,
45
- # `invert_mask`) raises TypeError.
44
+ # while a write that would mask a cell (`UNDEF`, `mask=`)
45
+ # raises TypeError.
46
46
  #
47
47
  # On a Face the data slot is read through the Face. A {CACategorical}
48
48
  # cell excluded by the sentinel code has no label, so its value reads
@@ -52,7 +52,7 @@ class CArray
52
52
 
53
53
  # @overload mask
54
54
  # Returns a new boolean view of the mask state of `self`. Each
55
- # element is `1` where `self` is masked and `0` where it is not.
55
+ # element is `true` where `self` is masked and `false` where it is not.
56
56
  # The returned view itself cannot carry a mask.
57
57
  #
58
58
  # The mask of a view is a view over its parent's mask: it follows
@@ -60,7 +60,11 @@ class CArray
60
60
  # `clone`, which is another view onto the same parent mask (a write
61
61
  # to it lands in the parent's mask). Use `copy` for a mask of its own.
62
62
  #
63
- # Returns `0` (Integer) if `self` has no mask array attached.
63
+ # Returns `0` (Integer) if `self` has no mask array attached. The
64
+ # `0` stands for a mask with no cell masked: `c.mask = a.mask` makes
65
+ # no cell of `c` masked, and `a.mask | b.mask` has the cells of
66
+ # `b.mask` set. `0` is true in Ruby, so use `has_mask?` to ask
67
+ # whether `self` has a mask.
64
68
  # @return [CArray, Integer]
65
69
  def mask; end
66
70
 
@@ -73,22 +77,24 @@ class CArray
73
77
  # `new_mask` makes the cell masked, as a masked value does in any
74
78
  # store. To mask the cells where a condition holds, prefer
75
79
  # `self[cond] = UNDEF`. There a masked cell of `cond` selects nothing,
76
- # as it does in any index.
80
+ # as it does in any index. To clear the mask, assign `false`; to give
81
+ # the masked cells a value as well, use {#unmask}.
77
82
  # @param new_mask [CArray, Boolean, Integer] mask values. A
78
83
  # non-CArray value is broadcast and stored elementwise; a CArray
79
84
  # of any type is coerced to boolean.
80
85
  # @return [Object] `new_mask`.
86
+ # @raise [TypeError] if `new_mask` is `nil`.
81
87
  def mask=(new_mask); end
82
88
 
83
89
  # @overload is_masked
84
90
  # Returns a new boolean CArray of the same shape as `self`, with
85
- # `1` at masked positions and `0` elsewhere.
91
+ # `true` at masked positions and `false` elsewhere.
86
92
  # @return [CArray]
87
93
  def is_masked; end
88
94
 
89
95
  # @overload is_not_masked
90
96
  # Returns a new boolean CArray of the same shape as `self`, with
91
- # `1` at not-masked positions and `0` elsewhere.
97
+ # `true` at not-masked positions and `false` elsewhere.
92
98
  # @return [CArray]
93
99
  def is_not_masked; end
94
100
 
@@ -103,15 +109,23 @@ class CArray
103
109
  # unmatched row -- takes no write and stays masked, without an error.
104
110
  # `strip_mask` gives a new array, where every masked cell takes a value.
105
111
  #
106
- # @overload unmask
107
- # Clears the mask state of every element of `self`, leaving the
108
- # stored data values untouched. Mutates `self`.
109
- # @return [self]
112
+ # A value or `method:` is required: `unmask` with no argument raises
113
+ # `ArgumentError`, as `strip_mask` does. To clear the mask without
114
+ # giving the masked cells a value, assign `mask = false`; what the
115
+ # cells then show is not defined (see {#value}).
116
+ #
110
117
  # @overload unmask(fill_value)
111
118
  # Clears the mask state and overwrites the data at previously
112
119
  # masked positions with `fill_value`. Mutates `self`.
120
+ #
121
+ # `UNDEF` is a special argument: it is no value but "leave the cell
122
+ # masked", as storing `UNDEF` is, so `unmask(UNDEF)` does nothing. It
123
+ # is the one argument for which `unmask` leaves the mask in place. It
124
+ # is accepted so that a computed fill can be passed as it is:
125
+ # `a.unmask(a.mean)` leaves every cell masked, rather than raising,
126
+ # when every cell is masked and `a.mean` is `UNDEF`.
113
127
  # @param fill_value [Object] value to store at each previously
114
- # masked position, converted as a store into `self` converts it.
128
+ # masked position, converted as a store into `self` converts it;
115
129
  # `UNDEF` leaves the masked cells masked.
116
130
  # @return [self]
117
131
  # @overload unmask(method:, axis: nil)
@@ -121,8 +135,8 @@ class CArray
121
135
  # masked cells with no value to carry, and cells outside the valid
122
136
  # range (`:linear`), stay masked — so a mask may remain.
123
137
  # @param method [Symbol] fill rule:
124
- # `:forward` / `:ffill` carries the last valid value forward;
125
- # `:backward` / `:bfill` carries the next valid value backward
138
+ # `:forward` carries the last valid value forward;
139
+ # `:backward` carries the next valid value backward
126
140
  # (defined for every data_type — numeric, complex, bool, object,
127
141
  # fixlen, and Face); `:linear` interpolates each masked cell
128
142
  # linearly by index from the two bracketing valid cells (numeric
@@ -135,6 +149,8 @@ class CArray
135
149
  # float64 spacing there; the valid cells are not touched.
136
150
  # @param axis [Integer, nil] scan axis (single axis). `nil` flattens.
137
151
  # @return [self]
152
+ # @raise [ArgumentError] if neither a fill value nor `method:` is given,
153
+ # or if both are.
138
154
  def unmask(*, method: nil, axis: nil); end
139
155
 
140
156
  # `strip_mask` is the copy form of `unmask`: it returns a new array
@@ -146,18 +162,21 @@ class CArray
146
162
  # `self`, with no mask attached, and `fill_value` substituted at
147
163
  # positions that were masked in `self`. `self` is not modified.
148
164
  #
149
- # Replaces the removed `unmask_copy(fill)` from 2.x.
165
+ # `UNDEF` is a special argument, as for {#unmask}: the copy keeps the
166
+ # mask, the one argument for which `strip_mask` leaves it in place.
167
+ # `a.strip_mask(a.mean)` gives a copy still masked everywhere when
168
+ # every cell is masked and `a.mean` is `UNDEF`.
150
169
  # @param fill_value [Object] value to substitute at masked
151
- # positions, converted as a store into `self` converts it.
152
- # `UNDEF` leaves them masked (the copy keeps the mask).
170
+ # positions, converted as a store into `self` converts it;
171
+ # `UNDEF` leaves them masked.
153
172
  # @return [CArray]
154
173
  # @overload strip_mask(method:, axis: nil)
155
174
  # Returns a new array with masked cells filled from neighbouring
156
175
  # valid cells along `axis` (gap-fill). `self` is not modified.
157
176
  # Residual (leading / trailing / out-of-range) masked cells that
158
177
  # cannot be filled stay masked in the returned array.
159
- # @param method [Symbol] fill rule: `:forward` / `:ffill`,
160
- # `:backward` / `:bfill` (any data_type), or `:linear` (numeric or a
178
+ # @param method [Symbol] fill rule: `:forward`,
179
+ # `:backward` (any data_type), or `:linear` (numeric or a
161
180
  # time Face). See {#unmask} for the full description.
162
181
  # @param axis [Integer, nil] scan axis (single axis). `nil` flattens.
163
182
  # @return [CArray]
@@ -169,35 +188,34 @@ class CArray
169
188
  # degrade to the first / last element. Works for every data_type.
170
189
  #
171
190
  # @overload first(axis: nil, keep_axis: false)
172
- # Returns the first valid (unmasked) value along `axis`, skipping masked
173
- # cells. Identity-less: a fiber with no valid cell (all masked, or empty)
174
- # yields UNDEF. To substitute a default instead, complete at the call
175
- # site — `a.first(axis: 0).strip_mask(v)`.
176
- # @param axis [Integer, Array<Integer>, nil] reduce axis / axes; `nil`
177
- # reduces the whole array to a scalar.
191
+ # Returns the first value that is not masked, along `axis`. It is a
192
+ # reduction like `sum`: it skips masked elements, and it takes `axis:`,
193
+ # not a count, so `a.first(2)` raises. It is not `Array#first`: on a
194
+ # masked `a[0]`, `a.first` is the next value that is not masked. The
195
+ # first `n` elements are `a[0...n]`.
196
+ #
197
+ # Where every element is masked, or there are none, the result is
198
+ # UNDEF. To put a default value there, write
199
+ # `a.first(axis: 0).strip_mask(v)`.
200
+ # @param axis [Integer, Array<Integer>, nil] the axis or axes to
201
+ # reduce; `nil` reduces the whole array to a scalar.
178
202
  # @param keep_axis [Boolean] keep the reduced axis as a size-1 axis.
179
- # @return [Object, CArray] a scalar for a full reduce (UNDEF if no valid
180
- # cell), otherwise a reduced CArray.
203
+ # @return [Object, CArray] a scalar for a whole-array reduction (UNDEF
204
+ # if every element is masked), otherwise a reduced CArray.
181
205
  def first(axis: nil, keep_axis: false); end
182
206
 
183
207
  # @overload last(axis: nil, keep_axis: false)
184
- # Returns the last valid (unmasked) value along `axis` (the backward
185
- # counterpart of {#first}).
186
- # @param axis [Integer, Array<Integer>, nil] reduce axis / axes; `nil`
187
- # reduces the whole array to a scalar.
208
+ # Returns the last value that is not masked, along `axis`. It is the
209
+ # reduction {#first} is, read from the end: it takes `axis:`, not a
210
+ # count, and it is not `Array#last`. The last `n` elements are
211
+ # `a[-n..]`.
212
+ # @param axis [Integer, Array<Integer>, nil] the axis or axes to
213
+ # reduce; `nil` reduces the whole array to a scalar.
188
214
  # @param keep_axis [Boolean] keep the reduced axis as a size-1 axis.
189
- # @return [Object, CArray] a scalar for a full reduce (UNDEF if no valid
190
- # cell), otherwise a reduced CArray.
215
+ # @return [Object, CArray] a scalar for a whole-array reduction (UNDEF
216
+ # if every element is masked), otherwise a reduced CArray.
191
217
  def last(axis: nil, keep_axis: false); end
192
218
 
193
- # @overload invert_mask
194
- # Flips the mask state of every element of `self` in place
195
- # (masked ↔ not masked). Mutates `self`.
196
- # @return [self]
197
- # @raise [FrozenError] if `self` is frozen or a view of a frozen array.
198
- # @raise [RuntimeError] if `self` is read-only (a lazy expression, for one).
199
- def invert_mask; end
200
-
201
219
  # @overload inherit_mask(*others)
202
220
  # Sets the mask of `self` to the logical OR of the current mask
203
221
  # of `self` and the masks of each array in `others`. Mutates