carray 3.0.4 → 3.0.5

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 (111) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +205 -0
  3. data/carray.gemspec +1 -1
  4. data/ext/ca_array_pool.c +25 -1
  5. data/ext/ca_axis_dispatch.c +13 -20
  6. data/ext/ca_categorical_iterator.c +27 -20
  7. data/ext/ca_compare.c +4 -4
  8. data/ext/ca_composite_dispatch.c +9 -9
  9. data/ext/ca_kernel_iterator.c +6 -6
  10. data/ext/ca_kernel_iterator.h +112 -83
  11. data/ext/ca_obj_array.c +69 -19
  12. data/ext/ca_obj_bincmp.c +1 -0
  13. data/ext/ca_obj_binop.c +1 -0
  14. data/ext/ca_obj_bitarray.c +5 -1
  15. data/ext/ca_obj_bitfield.c +58 -43
  16. data/ext/ca_obj_byte_swap.c +2 -1
  17. data/ext/ca_obj_const_string.c +15 -3
  18. data/ext/ca_obj_face.c +42 -1
  19. data/ext/ca_obj_field.c +13 -3
  20. data/ext/ca_obj_grid.c +52 -5
  21. data/ext/ca_obj_monop.c +46 -10
  22. data/ext/ca_obj_object.c +64 -12
  23. data/ext/ca_obj_record.c +3 -0
  24. data/ext/ca_obj_reduce.c +4 -0
  25. data/ext/ca_obj_refer.c +18 -9
  26. data/ext/ca_obj_roll.c +26 -6
  27. data/ext/ca_obj_select.c +34 -5
  28. data/ext/ca_obj_shift.c +31 -7
  29. data/ext/ca_obj_stack.c +1 -0
  30. data/ext/ca_obj_stride.c +28 -19
  31. data/ext/ca_obj_string.c +11 -2
  32. data/ext/ca_obj_tile.c +27 -7
  33. data/ext/ca_obj_transpose.c +8 -4
  34. data/ext/ca_obj_triop.c +3 -0
  35. data/ext/ca_obj_window.c +79 -50
  36. data/ext/ca_op_ipower.c +4 -4
  37. data/ext/ca_sort_kernels.h +6 -3
  38. data/ext/carray.h +33 -0
  39. data/ext/carray_access.c +16 -3
  40. data/ext/carray_attribute.c +24 -0
  41. data/ext/carray_cast.c +243 -82
  42. data/ext/carray_cast_func.rb +56 -26
  43. data/ext/carray_conversion.c +2 -2
  44. data/ext/carray_core.c +3 -0
  45. data/ext/carray_count.c +6 -0
  46. data/ext/carray_element.c +9 -4
  47. data/ext/carray_factorize.c +20 -20
  48. data/ext/carray_generate.c +8 -2
  49. data/ext/carray_histogram.c +1 -1
  50. data/ext/carray_index_classifier.c +4 -4
  51. data/ext/carray_internal.h +12 -0
  52. data/ext/carray_kernels_bincmp.c +168 -168
  53. data/ext/carray_kernels_binop.c +900 -900
  54. data/ext/carray_kernels_init.c +4 -4
  55. data/ext/carray_kernels_moncmp.c +96 -96
  56. data/ext/carray_kernels_monop.c +1984 -1984
  57. data/ext/carray_kernels_reduce_aggregate.c +1733 -1733
  58. data/ext/carray_kernels_reduce_cumulative.c +642 -642
  59. data/ext/carray_kernels_reduce_extreme.c +1150 -1150
  60. data/ext/carray_kernels_reduce_variance.c +258 -258
  61. data/ext/carray_kernels_scan.c +128 -128
  62. data/ext/carray_kernels_search.c +340 -340
  63. data/ext/carray_kernels_sort.c +295 -304
  64. data/ext/carray_kernels_triop.c +114 -114
  65. data/ext/carray_key_windows.c +4 -0
  66. data/ext/carray_mask.c +45 -22
  67. data/ext/carray_memory_view.c +2 -2
  68. data/ext/carray_operator.c +5 -5
  69. data/ext/carray_order.c +227 -8
  70. data/ext/carray_random.c +18 -18
  71. data/ext/carray_scatter.c +24 -7
  72. data/ext/carray_slab.c +32 -9
  73. data/ext/carray_sort.c +224 -16
  74. data/ext/carray_sort_kernel.c +5 -7
  75. data/ext/carray_struct.c +35 -43
  76. data/ext/carray_time_text.c +4 -2
  77. data/ext/carray_utils.c +63 -21
  78. data/ext/mkkernel.rb +210 -115
  79. data/ext/version.h +4 -4
  80. data/lib/carray/attribute.rb +17 -4
  81. data/lib/carray/basics.rb +27 -7
  82. data/lib/carray/categorical.rb +30 -16
  83. data/lib/carray/categorical_iterator.rb +6 -6
  84. data/lib/carray/const_string.rb +10 -0
  85. data/lib/carray/data_type_extension.rb +8 -1
  86. data/lib/carray/fixlen_string.rb +41 -2
  87. data/lib/carray/frame/column_verbs.rb +4 -3
  88. data/lib/carray/frame/concat.rb +17 -3
  89. data/lib/carray/frame/frame.rb +6 -7
  90. data/lib/carray/frame/group.rb +100 -13
  91. data/lib/carray/frame/io.rb +3 -1
  92. data/lib/carray/fuse_source.rb +31 -2
  93. data/lib/carray/lazy.rb +35 -0
  94. data/lib/carray/methods/is_in.rb +8 -1
  95. data/lib/carray/segment_iterator.rb +12 -8
  96. data/lib/carray/serialize.rb +19 -2
  97. data/lib/carray/stack.rb +15 -12
  98. data/lib/carray/string.rb +8 -0
  99. data/lib/carray/string_operation_extension.rb +13 -5
  100. data/lib/carray/struct_builder.rb +5 -3
  101. data/lib/carray/time.rb +107 -68
  102. data/yard-stubs/ca_obj_transpose.rb +5 -4
  103. data/yard-stubs/carray_attribute.rb +3 -1
  104. data/yard-stubs/carray_cast.rb +2 -0
  105. data/yard-stubs/carray_conversion.rb +5 -1
  106. data/yard-stubs/carray_element.rb +7 -6
  107. data/yard-stubs/carray_mask.rb +8 -3
  108. data/yard-stubs/carray_math.rb +14 -4
  109. data/yard-stubs/carray_order.rb +100 -4
  110. data/yard-stubs/carray_scatter.rb +7 -5
  111. metadata +1 -1
@@ -11,6 +11,11 @@
11
11
  # builds a node in the expression tree instead of evaluating, and the
12
12
  # eager and lazy paths are required to agree element for element.
13
13
  #
14
+ # The transcendental functions call the platform's C math library, so
15
+ # their last bits, and the complex functions' answers at special values
16
+ # (signed zeros, infinities, NaN), follow that library and can differ
17
+ # between operating systems.
18
+ #
14
19
  # See yard-stubs/README.md and yard-stubs/STYLE.md.
15
20
 
16
21
  class CArray
@@ -598,6 +603,8 @@ class CArray
598
603
  # Returns each element of `self` with the magnitude it already has
599
604
  # and the sign of the matching element of `other`. The sign of a
600
605
  # zero is respected, so `copysign` distinguishes `-0.0` from `0.0`.
606
+ # The sign of a NaN that a computation produced (`sqrt(-1)`,
607
+ # `Inf * 0`) depends on the CPU: x86 sets it, ARM does not.
601
608
  # Accepts float and `:object` arrays only, as {#atan2}.
602
609
  # @param other [CArray, Numeric] sign source, broadcast to
603
610
  # `self.shape`.
@@ -683,8 +690,8 @@ class CArray
683
690
  # @overload pmax(other)
684
691
  # Returns the element-wise larger of `self` and `other`, ignoring
685
692
  # `NaN`: where one element is `NaN` the other is returned, and only
686
- # two `NaN`s give `NaN`. This is C's `fmax`. For the form that lets
687
- # a `NaN` win see {#maximum}.
693
+ # two `NaN`s give `NaN`. Of `-0.0` and `0.0` the result is `0.0`,
694
+ # in either order. For the form that lets a `NaN` win see {#maximum}.
688
695
  # @param other [CArray, Numeric] the other operand, broadcast to
689
696
  # `self.shape`.
690
697
  # @return [CArray] result of the promoted `data_type` of the two
@@ -697,7 +704,8 @@ class CArray
697
704
 
698
705
  # @overload pmin(other)
699
706
  # Returns the element-wise smaller of `self` and `other`, ignoring
700
- # `NaN`. The counterpart of {#pmax}.
707
+ # `NaN`. Of `-0.0` and `0.0` the result is `-0.0`, in either order.
708
+ # The counterpart of {#pmax}.
701
709
  # @param other [CArray, Numeric] the other operand.
702
710
  # @return [CArray]
703
711
  # @raise [CArray::DataTypeError] for a complex array.
@@ -929,7 +937,9 @@ class CArray
929
937
  # @overload signbit
930
938
  # Returns a boolean array that is true where an element carries a
931
939
  # negative sign bit. A negative zero is true, which distinguishes
932
- # `-0.0` from `0.0` where a `< 0` comparison cannot.
940
+ # `-0.0` from `0.0` where a `< 0` comparison cannot. On a NaN that a
941
+ # computation produced (`sqrt(-1)`, `Inf * 0`) the answer depends on
942
+ # the CPU: x86 sets the sign bit, ARM does not.
933
943
  # @return [CArray] `:boolean`.
934
944
  # @raise [CArray::DataTypeError] for a complex array.
935
945
  # @example
@@ -128,7 +128,8 @@ class CArray
128
128
 
129
129
  # @overload bsearch(val)
130
130
  # Returns the flat address of `val` in `self` via binary search.
131
- # `self` must be sorted along its single (flat) axis. Returns
131
+ # `self` must be sorted along its single (flat) axis. Of several
132
+ # equal cells, the first one's address is returned. Returns
132
133
  # `nil` if `val` is not present. When `val` is a CArray, returns
133
134
  # a CArray of `:int64` addresses (one per element of `val`),
134
135
  # with `UNDEF` at positions where the value is not present.
@@ -159,7 +160,8 @@ class CArray
159
160
  # @overload search(val, eps = nil)
160
161
  # Returns the flat address of the first element of `self` equal
161
162
  # to `val`. For float types, `eps` (default machine epsilon)
162
- # sets the tolerance. Returns `nil` if no match.
163
+ # sets the tolerance; a negative or NaN `eps` raises
164
+ # `ArgumentError`. Returns `nil` if no match.
163
165
  #
164
166
  # `val` is compared in the type both share, as `self.eq(val)`
165
167
  # compares: an integer array searched with a Float is compared in
@@ -201,7 +203,10 @@ class CArray
201
203
 
202
204
  # @overload search_nearest(val)
203
205
  # Returns the flat address of the element of `self` whose value
204
- # is closest to `val`.
206
+ # is closest to `val`. Of several equally close elements, the one
207
+ # at the lowest address wins, as {#search} answers the first match
208
+ # (`[0, 2, 4].search_nearest(1)` is 0). {#locate_nearest_addr}
209
+ # rounds a position instead, and answers the larger value on a tie.
205
210
  #
206
211
  # In an `:object` array the distance is `val.distance(other)` when
207
212
  # `val` answers `#distance`, and `(val - other).abs` when it is a
@@ -268,7 +273,9 @@ class CArray
268
273
  # `self` is coerced to `:float64` if it is not already. When
269
274
  # `axis: nil`, `self` is flattened to 1-D first.
270
275
  #
271
- # Out-of-range `addr` returns NaN.
276
+ # A position with no answer -- out of range, or between samples one
277
+ # of which is NaN -- gives `nil` for a scalar `addr` and NaN in the
278
+ # cell of an array result.
272
279
  #
273
280
  # Because this half of the pair returns a *value* rather than a
274
281
  # position, a Face axis gets its Face back: `CATime#linear_fetch` /
@@ -280,5 +287,94 @@ class CArray
280
287
  # @see file:docs/topics/LinearInterpolation.md
281
288
  def linear_fetch(addr, axis: nil); end
282
289
 
290
+ # @overload nlargest(n, axis: nil)
291
+ # Returns the `n` largest values, largest first. Without `axis:` the
292
+ # array is read flat; with it, each fiber along `axis` gives its own
293
+ # `n` and the axis keeps length `n`. A NaN and a masked cell lose to
294
+ # every value; when fewer cells remain than `n`, the result is
295
+ # shorter (or, per fiber, ends in UNDEF).
296
+ # @param n [Integer] how many values, 0 or more.
297
+ # @param axis [Integer, nil]
298
+ # @return [CArray]
299
+ # @raise [ArgumentError] when `n` is negative.
300
+ def nlargest(n, axis: nil); end
301
+
302
+ # @overload nsmallest(n, axis: nil)
303
+ # Returns the `n` smallest values, smallest first. As {#nlargest}
304
+ # otherwise.
305
+ # @param n [Integer]
306
+ # @param axis [Integer, nil]
307
+ # @return [CArray]
308
+ # @raise [ArgumentError] when `n` is negative.
309
+ def nsmallest(n, axis: nil); end
310
+
311
+ # @overload nlargest_index(n, axis:)
312
+ # Returns, along `axis`, the axis-local positions of each fiber's `n`
313
+ # largest values, largest first (`take_along_axis` reads the values
314
+ # back). `axis:` is required.
315
+ # @param n [Integer]
316
+ # @param axis [Integer]
317
+ # @return [CArray] `:int64` positions.
318
+ # @raise [ArgumentError] when `axis:` is missing or `n` is negative.
319
+ def nlargest_index(n, axis:); end
320
+
321
+ # @overload nsmallest_index(n, axis:)
322
+ # As {#nlargest_index}, for the `n` smallest values.
323
+ # @param n [Integer]
324
+ # @param axis [Integer]
325
+ # @return [CArray] `:int64` positions.
326
+ # @raise [ArgumentError] when `axis:` is missing or `n` is negative.
327
+ def nsmallest_index(n, axis:); end
328
+
329
+ # @overload sort_by_key(key, axis: 0)
330
+ # Returns `self` reordered along `axis` by the order of `key` (an
331
+ # array of `self`'s shape): `self[key.sort_addr(axis:)]`.
332
+ # @param key [CArray] the values to order by.
333
+ # @param axis [Integer]
334
+ # @return [CArray]
335
+ # @raise [ArgumentError] when `key`'s shape differs from `self`'s.
336
+ def sort_by_key(key, axis: 0); end
337
+
338
+ # @overload max_by_key(key, axis: nil)
339
+ # Returns the value of `self` where `key` is largest: one value, or
340
+ # one per fiber along `axis`. UNDEF where there is no cell to compare.
341
+ # @param key [CArray] the values to compare, of `self`'s shape.
342
+ # @param axis [Integer, nil]
343
+ # @return [Object, CArray]
344
+ # @raise [ArgumentError] when `key`'s shape differs from `self`'s.
345
+ def max_by_key(key, axis: nil); end
346
+
347
+ # @overload min_by_key(key, axis: nil)
348
+ # As {#max_by_key}, where `key` is smallest.
349
+ # @param key [CArray]
350
+ # @param axis [Integer, nil]
351
+ # @return [Object, CArray]
352
+ # @raise [ArgumentError] when `key`'s shape differs from `self`'s.
353
+ def min_by_key(key, axis: nil); end
354
+
355
+ # @overload take_along_axis(indices, axis: 0)
356
+ # Returns the values of `self` at axis-local `indices` along `axis`
357
+ # (`indices` has `self`'s shape except along `axis`), as the
358
+ # `*_index(axis:)` methods answer them. A masked index reads UNDEF.
359
+ # @param indices [CArray] integer positions along `axis`.
360
+ # @param axis [Integer]
361
+ # @return [CArray]
362
+ def take_along_axis(indices, axis: 0); end
363
+
364
+ # @overload put_along_axis(indices, values, axis: 0)
365
+ # Writes `values` into `self` at axis-local `indices` along `axis`,
366
+ # the inverse of {#take_along_axis}. A masked index writes nothing.
367
+ # @param indices [CArray] integer positions along `axis`.
368
+ # @param values [CArray, Object]
369
+ # @param axis [Integer]
370
+ # @return [self]
371
+ def put_along_axis(indices, values, axis: 0); end
372
+
373
+ # @overload range
374
+ # Returns `min..max` of `self` from one pass (`UNDEF..UNDEF` when no
375
+ # cell takes part).
376
+ # @return [Range]
377
+ def range; end
378
+
283
379
  # @!endgroup
284
380
  end
@@ -104,13 +104,15 @@ class CArray
104
104
  # allocates view state); useful in hot loops where a scatter
105
105
  # result is written back many times.
106
106
  #
107
- # Unlike the arithmetic `scatter_*!` family, `self` may be
108
- # **boolean** (assignment does not widen); `true` / `false` (or
109
- # `1` / `0`) are its scalar values. A scalar `UNDEF` masks every
110
- # addressed cell.
107
+ # Unlike the arithmetic `scatter_*!` family, `self` may be of any
108
+ # type (assignment does not widen): **boolean**, with `true` /
109
+ # `false` (or `1` / `0`) as its scalar values, and **object** or
110
+ # **fixlen**, written as `self.flatten[addrs] = vals` writes them
111
+ # (as `put_nd` and `put_along_axis` take them). A scalar `UNDEF`
112
+ # masks every addressed cell.
111
113
  #
112
114
  # @param addrs [CArray, Array<Integer>]
113
- # @param vals [CArray, Numeric, true, false, UNDEF]
115
+ # @param vals [CArray, Object, UNDEF]
114
116
  # @return [self]
115
117
  def scatter_replace!(addrs, vals); end
116
118
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carray
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.4
4
+ version: 3.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - himotoyoshi