carray 3.0.0 → 3.0.2

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 (202) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +2 -1
  3. data/CHANGELOG.md +845 -3
  4. data/{NEWS.md → CHANGELOG.v1.md} +1 -1
  5. data/README.md +33 -33
  6. data/carray.gemspec +12 -8
  7. data/ext/ca_axis_dispatch.c +33 -4
  8. data/ext/ca_axis_group.c +256 -114
  9. data/ext/ca_binop_dispatch.c +5 -6
  10. data/ext/ca_binop_dispatch.h +0 -7
  11. data/ext/ca_categorical_iterator.c +121 -67
  12. data/ext/ca_for_each_element.h +6 -8
  13. data/ext/ca_group_iter.c +1 -1
  14. data/ext/ca_kernel_iterator.c +386 -74
  15. data/ext/ca_kernel_iterator.h +145 -45
  16. data/ext/ca_obj_array.c +62 -20
  17. data/ext/ca_obj_bincmp.c +57 -27
  18. data/ext/ca_obj_binop.c +86 -30
  19. data/ext/ca_obj_block.c +4 -4
  20. data/ext/ca_obj_const_string.c +88 -27
  21. data/ext/ca_obj_face.c +104 -0
  22. data/ext/ca_obj_face.h +48 -1
  23. data/ext/ca_obj_fake.c +11 -0
  24. data/ext/ca_obj_fixlen_string.c +21 -6
  25. data/ext/ca_obj_grid.c +11 -3
  26. data/ext/ca_obj_meld.c +125 -22
  27. data/ext/ca_obj_moncmp.c +33 -14
  28. data/ext/ca_obj_monop.c +19 -7
  29. data/ext/ca_obj_object.c +107 -4
  30. data/ext/ca_obj_record.c +3 -1
  31. data/ext/ca_obj_refer.c +30 -6
  32. data/ext/ca_obj_roll.c +13 -5
  33. data/ext/ca_obj_select.c +49 -34
  34. data/ext/ca_obj_select_axis.c +16 -6
  35. data/ext/ca_obj_shift.c +3 -3
  36. data/ext/ca_obj_stack.c +3 -8
  37. data/ext/ca_obj_stride.c +178 -24
  38. data/ext/ca_obj_string.c +11 -5
  39. data/ext/ca_obj_tile.c +13 -5
  40. data/ext/ca_obj_time.c +3 -1
  41. data/ext/ca_obj_timedelta.c +3 -1
  42. data/ext/ca_obj_transpose.c +1 -1
  43. data/ext/ca_obj_triop.c +62 -23
  44. data/ext/ca_obj_window.c +94 -19
  45. data/ext/ca_op_cmplx64.h +123 -0
  46. data/ext/ca_op_ipower.c +1 -5
  47. data/ext/ca_rng_normal.h +42 -0
  48. data/ext/ca_rng_xoshiro256pp.h +105 -0
  49. data/ext/ca_sort_kernels.h +5 -5
  50. data/ext/ca_sweep_engine.c +362 -155
  51. data/ext/ca_sweep_engine.h +39 -9
  52. data/ext/ca_transform_common.c +7 -0
  53. data/ext/carray.h +148 -132
  54. data/ext/carray_access.c +83 -49
  55. data/ext/carray_address_basis.c +590 -0
  56. data/ext/carray_bincount.c +8 -8
  57. data/ext/carray_broadcast.c +102 -9
  58. data/ext/carray_build_flags.h +3 -0
  59. data/ext/carray_call_cfunc.c +2010 -335
  60. data/ext/carray_call_cfunc.h +153 -0
  61. data/ext/carray_cast.c +184 -72
  62. data/ext/carray_conversion.c +22 -22
  63. data/ext/carray_copy.c +67 -32
  64. data/ext/carray_core.c +140 -13
  65. data/ext/carray_count.c +10 -11
  66. data/ext/carray_element.c +7 -7
  67. data/ext/carray_factorize.c +72 -51
  68. data/ext/carray_hold.c +1 -1
  69. data/ext/carray_index_classifier.c +7 -21
  70. data/ext/carray_internal.h +36 -3
  71. data/ext/carray_kernels_bincmp.c +1 -0
  72. data/ext/carray_kernels_binop.c +320 -298
  73. data/ext/carray_kernels_init.c +1095 -0
  74. data/ext/carray_kernels_map.c +1 -0
  75. data/ext/carray_kernels_moncmp.c +1 -0
  76. data/ext/carray_kernels_monop.c +412 -411
  77. data/ext/carray_kernels_reduce_aggregate.c +256 -87
  78. data/ext/carray_kernels_reduce_boolean.c +1 -0
  79. data/ext/carray_kernels_reduce_cumulative.c +324 -54
  80. data/ext/carray_kernels_reduce_extreme.c +605 -58
  81. data/ext/carray_kernels_reduce_variance.c +1 -0
  82. data/ext/carray_kernels_scan.c +5 -4
  83. data/ext/carray_kernels_search.c +187 -106
  84. data/ext/carray_kernels_sort.c +1 -0
  85. data/ext/carray_kernels_triop.c +1 -0
  86. data/ext/carray_lazy.c +175 -5
  87. data/ext/carray_loop.c +7 -1
  88. data/ext/carray_mask.c +29 -13
  89. data/ext/carray_median_percentile.c +56 -1
  90. data/ext/carray_memory_view.c +46 -21
  91. data/ext/carray_operator.c +50 -53
  92. data/ext/carray_order.c +1 -1
  93. data/ext/carray_partition.c +4 -4
  94. data/ext/carray_random.c +391 -47
  95. data/ext/carray_scatter.c +1 -1
  96. data/ext/carray_slab.c +13 -0
  97. data/ext/carray_sort.c +22 -24
  98. data/ext/carray_sort_kernel.c +10 -10
  99. data/ext/carray_test.c +1 -1
  100. data/ext/extconf.rb +18 -0
  101. data/ext/mk_call_cfunc.rb +323 -145
  102. data/ext/mkkernel.rb +651 -129
  103. data/ext/ruby_carray.c +28 -17
  104. data/ext/version.h +4 -4
  105. data/lib/carray/autoload_carray.rb +24 -3
  106. data/lib/carray/autoload_method_extension.rb +14 -1
  107. data/lib/carray/axis_group.rb +84 -7
  108. data/lib/carray/basics.rb +63 -59
  109. data/lib/carray/bincount_nd.rb +12 -12
  110. data/lib/carray/block_iterator.rb +111 -25
  111. data/lib/carray/categorical.rb +154 -37
  112. data/lib/carray/categorical_iterator.rb +300 -151
  113. data/lib/carray/conditional.rb +14 -14
  114. data/lib/carray/const_string.rb +131 -27
  115. data/lib/carray/construct.rb +61 -0
  116. data/lib/carray/core_extensions.rb +62 -5
  117. data/lib/carray/data_type_extension.rb +21 -1
  118. data/lib/carray/data_type_limits.rb +91 -0
  119. data/lib/carray/fixlen_string.rb +1 -1
  120. data/lib/carray/frame/concat.rb +3 -3
  121. data/lib/carray/frame/convert.rb +1 -1
  122. data/lib/carray/frame/csv_parser.rb +11 -4
  123. data/lib/carray/frame/frame.rb +85 -21
  124. data/lib/carray/frame/group.rb +36 -3
  125. data/lib/carray/frame/io.rb +224 -15
  126. data/lib/carray/frame/records.rb +18 -4
  127. data/lib/carray/frame/sort.rb +1 -1
  128. data/lib/carray/frame/verbs.rb +32 -12
  129. data/lib/carray/fuse_source.rb +123 -0
  130. data/lib/carray/fusion.rb +218 -0
  131. data/lib/carray/histogram.rb +16 -16
  132. data/lib/carray/inspect.rb +43 -16
  133. data/lib/carray/iterator.rb +147 -3
  134. data/lib/carray/lazy.rb +88 -73
  135. data/lib/carray/mask_gap_fill.rb +3 -1
  136. data/lib/carray/meld_reduce.rb +2 -2
  137. data/lib/carray/methods/align_addr.rb +1 -1
  138. data/lib/carray/methods/composition.rb +1 -1
  139. data/lib/carray/methods/discovery_along.rb +74 -0
  140. data/lib/carray/methods/factorize.rb +50 -0
  141. data/lib/carray/methods/is_in.rb +25 -14
  142. data/lib/carray/methods/locate_addr.rb +81 -3
  143. data/lib/carray/methods/mask_duplicates.rb +36 -2
  144. data/lib/carray/methods/meshgrid.rb +4 -5
  145. data/lib/carray/methods/mode.rb +2 -2
  146. data/lib/carray/methods/nunique.rb +23 -2
  147. data/lib/carray/methods/repeat.rb +110 -0
  148. data/lib/carray/methods/snap.rb +7 -2
  149. data/lib/carray/methods/unique.rb +44 -4
  150. data/lib/carray/methods/value_counts.rb +2 -2
  151. data/lib/carray/rng.rb +86 -0
  152. data/lib/carray/runtime.rb +0 -19
  153. data/lib/carray/slab_iterator.rb +77 -19
  154. data/lib/carray/string_operation_extension.rb +10 -6
  155. data/lib/carray/time.rb +906 -491
  156. data/lib/carray/window_iterator.rb +421 -27
  157. data/lib/carray.rb +7 -5
  158. data/yard-stubs/ca_obj_array.rb +385 -0
  159. data/yard-stubs/ca_obj_bitarray.rb +38 -0
  160. data/yard-stubs/ca_obj_bitfield.rb +43 -0
  161. data/yard-stubs/ca_obj_block.rb +68 -0
  162. data/yard-stubs/ca_obj_byte_swap.rb +56 -0
  163. data/yard-stubs/ca_obj_fake.rb +31 -0
  164. data/yard-stubs/ca_obj_farray.rb +32 -0
  165. data/yard-stubs/ca_obj_field.rb +45 -0
  166. data/yard-stubs/ca_obj_grid.rb +35 -0
  167. data/yard-stubs/ca_obj_refer.rb +72 -0
  168. data/yard-stubs/ca_obj_roll.rb +45 -0
  169. data/yard-stubs/ca_obj_shift.rb +43 -0
  170. data/yard-stubs/ca_obj_stride.rb +181 -0
  171. data/yard-stubs/ca_obj_tile.rb +29 -0
  172. data/yard-stubs/ca_obj_transpose.rb +40 -0
  173. data/yard-stubs/ca_obj_window.rb +57 -0
  174. data/yard-stubs/carray_access.rb +131 -0
  175. data/yard-stubs/carray_attribute.rb +246 -0
  176. data/yard-stubs/carray_broadcast.rb +37 -0
  177. data/yard-stubs/carray_cast.rb +489 -0
  178. data/yard-stubs/carray_class.rb +65 -0
  179. data/yard-stubs/carray_conversion.rb +76 -0
  180. data/yard-stubs/carray_copy.rb +79 -0
  181. data/yard-stubs/carray_core.rb +34 -0
  182. data/yard-stubs/carray_count.rb +84 -0
  183. data/yard-stubs/carray_element.rb +108 -0
  184. data/yard-stubs/carray_generate.rb +66 -0
  185. data/yard-stubs/carray_lazy.rb +228 -0
  186. data/yard-stubs/carray_loop.rb +140 -0
  187. data/yard-stubs/carray_mask.rb +259 -0
  188. data/yard-stubs/carray_math.rb +1615 -0
  189. data/yard-stubs/carray_mathfunc.rb +45 -0
  190. data/yard-stubs/carray_median_percentile.rb +103 -0
  191. data/yard-stubs/carray_memory_view.rb +163 -0
  192. data/yard-stubs/carray_order.rb +252 -0
  193. data/yard-stubs/carray_random.rb +89 -0
  194. data/yard-stubs/carray_scatter.rb +106 -0
  195. data/yard-stubs/carray_slab.rb +59 -0
  196. data/yard-stubs/carray_sort.rb +165 -0
  197. data/yard-stubs/carray_test.rb +85 -0
  198. data/yard-stubs/carray_undef.rb +64 -0
  199. data/yard-stubs/carray_utils.rb +97 -0
  200. data/yard-stubs/ruby_carray.rb +193 -0
  201. metadata +67 -10
  202. data/ext/ca_obj_unbound_repeat.c +0 -496
@@ -34,6 +34,7 @@ static inline VALUE BOOL2VAL (boolean8_t x) { return x ? Qtrue : Qfalse; }
34
34
  #endif
35
35
 
36
36
  #include "ca_op_powi.h"
37
+ #include "ca_op_cmplx64.h"
37
38
 
38
39
  /* ===== find_value_index_ki ============================================ */
39
40
 
@@ -42,7 +43,7 @@ find_value_index_ki_native_i8 (VALUE self, CArray *ca, VALUE rval, int axis)
42
43
  {
43
44
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
44
45
  all dim==1 etc. to a Ruby Float and route it through the Case A
45
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
46
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
46
47
  downstream). */
47
48
  if ( rb_obj_is_carray(rval) ) {
48
49
  CArray *cv_pre_;
@@ -362,7 +363,7 @@ find_value_index_ki_native_u8 (VALUE self, CArray *ca, VALUE rval, int axis)
362
363
  {
363
364
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
364
365
  all dim==1 etc. to a Ruby Float and route it through the Case A
365
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
366
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
366
367
  downstream). */
367
368
  if ( rb_obj_is_carray(rval) ) {
368
369
  CArray *cv_pre_;
@@ -682,7 +683,7 @@ find_value_index_ki_native_i16 (VALUE self, CArray *ca, VALUE rval, int axis)
682
683
  {
683
684
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
684
685
  all dim==1 etc. to a Ruby Float and route it through the Case A
685
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
686
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
686
687
  downstream). */
687
688
  if ( rb_obj_is_carray(rval) ) {
688
689
  CArray *cv_pre_;
@@ -1002,7 +1003,7 @@ find_value_index_ki_native_u16 (VALUE self, CArray *ca, VALUE rval, int axis)
1002
1003
  {
1003
1004
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
1004
1005
  all dim==1 etc. to a Ruby Float and route it through the Case A
1005
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
1006
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
1006
1007
  downstream). */
1007
1008
  if ( rb_obj_is_carray(rval) ) {
1008
1009
  CArray *cv_pre_;
@@ -1322,7 +1323,7 @@ find_value_index_ki_native_i32 (VALUE self, CArray *ca, VALUE rval, int axis)
1322
1323
  {
1323
1324
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
1324
1325
  all dim==1 etc. to a Ruby Float and route it through the Case A
1325
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
1326
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
1326
1327
  downstream). */
1327
1328
  if ( rb_obj_is_carray(rval) ) {
1328
1329
  CArray *cv_pre_;
@@ -1642,7 +1643,7 @@ find_value_index_ki_native_u32 (VALUE self, CArray *ca, VALUE rval, int axis)
1642
1643
  {
1643
1644
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
1644
1645
  all dim==1 etc. to a Ruby Float and route it through the Case A
1645
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
1646
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
1646
1647
  downstream). */
1647
1648
  if ( rb_obj_is_carray(rval) ) {
1648
1649
  CArray *cv_pre_;
@@ -1962,7 +1963,7 @@ find_value_index_ki_native_i64 (VALUE self, CArray *ca, VALUE rval, int axis)
1962
1963
  {
1963
1964
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
1964
1965
  all dim==1 etc. to a Ruby Float and route it through the Case A
1965
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
1966
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
1966
1967
  downstream). */
1967
1968
  if ( rb_obj_is_carray(rval) ) {
1968
1969
  CArray *cv_pre_;
@@ -2282,7 +2283,7 @@ find_value_index_ki_native_u64 (VALUE self, CArray *ca, VALUE rval, int axis)
2282
2283
  {
2283
2284
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
2284
2285
  all dim==1 etc. to a Ruby Float and route it through the Case A
2285
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
2286
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
2286
2287
  downstream). */
2287
2288
  if ( rb_obj_is_carray(rval) ) {
2288
2289
  CArray *cv_pre_;
@@ -2602,7 +2603,7 @@ find_value_index_ki_native_f32 (VALUE self, CArray *ca, VALUE rval, int axis)
2602
2603
  {
2603
2604
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
2604
2605
  all dim==1 etc. to a Ruby Float and route it through the Case A
2605
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
2606
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
2606
2607
  downstream). */
2607
2608
  if ( rb_obj_is_carray(rval) ) {
2608
2609
  CArray *cv_pre_;
@@ -2922,7 +2923,7 @@ find_value_index_ki_native_f64 (VALUE self, CArray *ca, VALUE rval, int axis)
2922
2923
  {
2923
2924
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
2924
2925
  all dim==1 etc. to a Ruby Float and route it through the Case A
2925
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
2926
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
2926
2927
  downstream). */
2927
2928
  if ( rb_obj_is_carray(rval) ) {
2928
2929
  CArray *cv_pre_;
@@ -3242,7 +3243,7 @@ find_value_index_ki_native_bool (VALUE self, CArray *ca, VALUE rval, int axis)
3242
3243
  {
3243
3244
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
3244
3245
  all dim==1 etc. to a Ruby Float and route it through the Case A
3245
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
3246
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
3246
3247
  downstream). */
3247
3248
  if ( rb_obj_is_carray(rval) ) {
3248
3249
  CArray *cv_pre_;
@@ -3562,7 +3563,7 @@ find_value_index_ki_native_object (VALUE self, CArray *ca, VALUE rval, int axis)
3562
3563
  {
3563
3564
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
3564
3565
  all dim==1 etc. to a Ruby Float and route it through the Case A
3565
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
3566
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
3566
3567
  downstream). */
3567
3568
  if ( rb_obj_is_carray(rval) ) {
3568
3569
  CArray *cv_pre_;
@@ -3882,7 +3883,7 @@ find_value_index_ki_native_fixlen (VALUE self, CArray *ca, VALUE rval, int axis)
3882
3883
  {
3883
3884
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
3884
3885
  all dim==1 etc. to a Ruby Float and route it through the Case A
3885
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
3886
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
3886
3887
  downstream). */
3887
3888
  if ( rb_obj_is_carray(rval) ) {
3888
3889
  CArray *cv_pre_;
@@ -4246,7 +4247,7 @@ rb_ca_find_value_index_ki (VALUE self, VALUE rval, VALUE raxis)
4246
4247
  }
4247
4248
  if ( self_face_comparable ) {
4248
4249
  if ( rval_is_face ) {
4249
- rval = rb_ca_strip_face_value(rval);
4250
+ rval = ca_face_operand_descend(rval, "find_value_index_ki");
4250
4251
  }
4251
4252
  } else if ( self_was_face ) {
4252
4253
  if ( rb_respond_to(self_ref, rb_intern("to_comparable")) ) {
@@ -4297,7 +4298,7 @@ bsearch_ki_native_i8 (VALUE self, CArray *ca, VALUE rval, int axis)
4297
4298
  {
4298
4299
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
4299
4300
  all dim==1 etc. to a Ruby Float and route it through the Case A
4300
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
4301
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
4301
4302
  downstream). */
4302
4303
  if ( rb_obj_is_carray(rval) ) {
4303
4304
  CArray *cv_pre_;
@@ -4633,7 +4634,7 @@ bsearch_ki_native_u8 (VALUE self, CArray *ca, VALUE rval, int axis)
4633
4634
  {
4634
4635
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
4635
4636
  all dim==1 etc. to a Ruby Float and route it through the Case A
4636
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
4637
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
4637
4638
  downstream). */
4638
4639
  if ( rb_obj_is_carray(rval) ) {
4639
4640
  CArray *cv_pre_;
@@ -4969,7 +4970,7 @@ bsearch_ki_native_i16 (VALUE self, CArray *ca, VALUE rval, int axis)
4969
4970
  {
4970
4971
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
4971
4972
  all dim==1 etc. to a Ruby Float and route it through the Case A
4972
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
4973
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
4973
4974
  downstream). */
4974
4975
  if ( rb_obj_is_carray(rval) ) {
4975
4976
  CArray *cv_pre_;
@@ -5305,7 +5306,7 @@ bsearch_ki_native_u16 (VALUE self, CArray *ca, VALUE rval, int axis)
5305
5306
  {
5306
5307
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
5307
5308
  all dim==1 etc. to a Ruby Float and route it through the Case A
5308
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
5309
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
5309
5310
  downstream). */
5310
5311
  if ( rb_obj_is_carray(rval) ) {
5311
5312
  CArray *cv_pre_;
@@ -5641,7 +5642,7 @@ bsearch_ki_native_i32 (VALUE self, CArray *ca, VALUE rval, int axis)
5641
5642
  {
5642
5643
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
5643
5644
  all dim==1 etc. to a Ruby Float and route it through the Case A
5644
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
5645
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
5645
5646
  downstream). */
5646
5647
  if ( rb_obj_is_carray(rval) ) {
5647
5648
  CArray *cv_pre_;
@@ -5977,7 +5978,7 @@ bsearch_ki_native_u32 (VALUE self, CArray *ca, VALUE rval, int axis)
5977
5978
  {
5978
5979
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
5979
5980
  all dim==1 etc. to a Ruby Float and route it through the Case A
5980
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
5981
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
5981
5982
  downstream). */
5982
5983
  if ( rb_obj_is_carray(rval) ) {
5983
5984
  CArray *cv_pre_;
@@ -6313,7 +6314,7 @@ bsearch_ki_native_i64 (VALUE self, CArray *ca, VALUE rval, int axis)
6313
6314
  {
6314
6315
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
6315
6316
  all dim==1 etc. to a Ruby Float and route it through the Case A
6316
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
6317
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
6317
6318
  downstream). */
6318
6319
  if ( rb_obj_is_carray(rval) ) {
6319
6320
  CArray *cv_pre_;
@@ -6649,7 +6650,7 @@ bsearch_ki_native_u64 (VALUE self, CArray *ca, VALUE rval, int axis)
6649
6650
  {
6650
6651
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
6651
6652
  all dim==1 etc. to a Ruby Float and route it through the Case A
6652
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
6653
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
6653
6654
  downstream). */
6654
6655
  if ( rb_obj_is_carray(rval) ) {
6655
6656
  CArray *cv_pre_;
@@ -6985,7 +6986,7 @@ bsearch_ki_native_f32 (VALUE self, CArray *ca, VALUE rval, int axis)
6985
6986
  {
6986
6987
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
6987
6988
  all dim==1 etc. to a Ruby Float and route it through the Case A
6988
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
6989
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
6989
6990
  downstream). */
6990
6991
  if ( rb_obj_is_carray(rval) ) {
6991
6992
  CArray *cv_pre_;
@@ -7321,7 +7322,7 @@ bsearch_ki_native_f64 (VALUE self, CArray *ca, VALUE rval, int axis)
7321
7322
  {
7322
7323
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
7323
7324
  all dim==1 etc. to a Ruby Float and route it through the Case A
7324
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
7325
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
7325
7326
  downstream). */
7326
7327
  if ( rb_obj_is_carray(rval) ) {
7327
7328
  CArray *cv_pre_;
@@ -7657,7 +7658,7 @@ bsearch_ki_native_bool (VALUE self, CArray *ca, VALUE rval, int axis)
7657
7658
  {
7658
7659
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
7659
7660
  all dim==1 etc. to a Ruby Float and route it through the Case A
7660
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
7661
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
7661
7662
  downstream). */
7662
7663
  if ( rb_obj_is_carray(rval) ) {
7663
7664
  CArray *cv_pre_;
@@ -7993,7 +7994,7 @@ bsearch_ki_native_object (VALUE self, CArray *ca, VALUE rval, int axis)
7993
7994
  {
7994
7995
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
7995
7996
  all dim==1 etc. to a Ruby Float and route it through the Case A
7996
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
7997
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
7997
7998
  downstream). */
7998
7999
  if ( rb_obj_is_carray(rval) ) {
7999
8000
  CArray *cv_pre_;
@@ -8343,7 +8344,7 @@ bsearch_ki_native_fixlen (VALUE self, CArray *ca, VALUE rval, int axis)
8343
8344
  {
8344
8345
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
8345
8346
  all dim==1 etc. to a Ruby Float and route it through the Case A
8346
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
8347
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
8347
8348
  downstream). */
8348
8349
  if ( rb_obj_is_carray(rval) ) {
8349
8350
  CArray *cv_pre_;
@@ -8723,7 +8724,7 @@ rb_ca_bsearch_ki (VALUE self, VALUE rval, VALUE raxis)
8723
8724
  }
8724
8725
  if ( self_face_comparable ) {
8725
8726
  if ( rval_is_face ) {
8726
- rval = rb_ca_strip_face_value(rval);
8727
+ rval = ca_face_operand_descend(rval, "bsearch_ki");
8727
8728
  }
8728
8729
  } else if ( self_was_face ) {
8729
8730
  if ( rb_respond_to(self_ref, rb_intern("to_comparable")) ) {
@@ -8774,7 +8775,7 @@ search_ki_native_i8 (VALUE self, CArray *ca, VALUE rval, int axis, VALUE reps)
8774
8775
  {
8775
8776
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
8776
8777
  all dim==1 etc. to a Ruby Float and route it through the Case A
8777
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
8778
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
8778
8779
  downstream). */
8779
8780
  if ( rb_obj_is_carray(rval) ) {
8780
8781
  CArray *cv_pre_;
@@ -9099,7 +9100,7 @@ search_ki_native_u8 (VALUE self, CArray *ca, VALUE rval, int axis, VALUE reps)
9099
9100
  {
9100
9101
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
9101
9102
  all dim==1 etc. to a Ruby Float and route it through the Case A
9102
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
9103
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
9103
9104
  downstream). */
9104
9105
  if ( rb_obj_is_carray(rval) ) {
9105
9106
  CArray *cv_pre_;
@@ -9424,7 +9425,7 @@ search_ki_native_i16 (VALUE self, CArray *ca, VALUE rval, int axis, VALUE reps)
9424
9425
  {
9425
9426
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
9426
9427
  all dim==1 etc. to a Ruby Float and route it through the Case A
9427
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
9428
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
9428
9429
  downstream). */
9429
9430
  if ( rb_obj_is_carray(rval) ) {
9430
9431
  CArray *cv_pre_;
@@ -9749,7 +9750,7 @@ search_ki_native_u16 (VALUE self, CArray *ca, VALUE rval, int axis, VALUE reps)
9749
9750
  {
9750
9751
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
9751
9752
  all dim==1 etc. to a Ruby Float and route it through the Case A
9752
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
9753
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
9753
9754
  downstream). */
9754
9755
  if ( rb_obj_is_carray(rval) ) {
9755
9756
  CArray *cv_pre_;
@@ -10074,7 +10075,7 @@ search_ki_native_i32 (VALUE self, CArray *ca, VALUE rval, int axis, VALUE reps)
10074
10075
  {
10075
10076
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
10076
10077
  all dim==1 etc. to a Ruby Float and route it through the Case A
10077
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
10078
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
10078
10079
  downstream). */
10079
10080
  if ( rb_obj_is_carray(rval) ) {
10080
10081
  CArray *cv_pre_;
@@ -10399,7 +10400,7 @@ search_ki_native_u32 (VALUE self, CArray *ca, VALUE rval, int axis, VALUE reps)
10399
10400
  {
10400
10401
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
10401
10402
  all dim==1 etc. to a Ruby Float and route it through the Case A
10402
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
10403
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
10403
10404
  downstream). */
10404
10405
  if ( rb_obj_is_carray(rval) ) {
10405
10406
  CArray *cv_pre_;
@@ -10724,7 +10725,7 @@ search_ki_native_i64 (VALUE self, CArray *ca, VALUE rval, int axis, VALUE reps)
10724
10725
  {
10725
10726
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
10726
10727
  all dim==1 etc. to a Ruby Float and route it through the Case A
10727
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
10728
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
10728
10729
  downstream). */
10729
10730
  if ( rb_obj_is_carray(rval) ) {
10730
10731
  CArray *cv_pre_;
@@ -11049,7 +11050,7 @@ search_ki_native_u64 (VALUE self, CArray *ca, VALUE rval, int axis, VALUE reps)
11049
11050
  {
11050
11051
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
11051
11052
  all dim==1 etc. to a Ruby Float and route it through the Case A
11052
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
11053
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
11053
11054
  downstream). */
11054
11055
  if ( rb_obj_is_carray(rval) ) {
11055
11056
  CArray *cv_pre_;
@@ -11374,7 +11375,7 @@ search_ki_native_f32 (VALUE self, CArray *ca, VALUE rval, int axis, VALUE reps)
11374
11375
  {
11375
11376
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
11376
11377
  all dim==1 etc. to a Ruby Float and route it through the Case A
11377
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
11378
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
11378
11379
  downstream). */
11379
11380
  if ( rb_obj_is_carray(rval) ) {
11380
11381
  CArray *cv_pre_;
@@ -11697,7 +11698,7 @@ search_ki_native_f64 (VALUE self, CArray *ca, VALUE rval, int axis, VALUE reps)
11697
11698
  {
11698
11699
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
11699
11700
  all dim==1 etc. to a Ruby Float and route it through the Case A
11700
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
11701
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
11701
11702
  downstream). */
11702
11703
  if ( rb_obj_is_carray(rval) ) {
11703
11704
  CArray *cv_pre_;
@@ -12020,7 +12021,7 @@ search_ki_native_bool (VALUE self, CArray *ca, VALUE rval, int axis, VALUE reps)
12020
12021
  {
12021
12022
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
12022
12023
  all dim==1 etc. to a Ruby Float and route it through the Case A
12023
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
12024
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
12024
12025
  downstream). */
12025
12026
  if ( rb_obj_is_carray(rval) ) {
12026
12027
  CArray *cv_pre_;
@@ -12345,7 +12346,7 @@ search_ki_native_object (VALUE self, CArray *ca, VALUE rval, int axis, VALUE rep
12345
12346
  {
12346
12347
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
12347
12348
  all dim==1 etc. to a Ruby Float and route it through the Case A
12348
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
12349
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
12349
12350
  downstream). */
12350
12351
  if ( rb_obj_is_carray(rval) ) {
12351
12352
  CArray *cv_pre_;
@@ -12672,7 +12673,7 @@ search_ki_native_fixlen (VALUE self, CArray *ca, VALUE rval, int axis, VALUE rep
12672
12673
  {
12673
12674
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
12674
12675
  all dim==1 etc. to a Ruby Float and route it through the Case A
12675
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
12676
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
12676
12677
  downstream). */
12677
12678
  if ( rb_obj_is_carray(rval) ) {
12678
12679
  CArray *cv_pre_;
@@ -13045,7 +13046,7 @@ rb_ca_search_ki (int argc, VALUE *argv, VALUE self)
13045
13046
  }
13046
13047
  if ( self_face_comparable ) {
13047
13048
  if ( rval_is_face ) {
13048
- rval = rb_ca_strip_face_value(rval);
13049
+ rval = ca_face_operand_descend(rval, "search_ki");
13049
13050
  }
13050
13051
  } else if ( self_was_face ) {
13051
13052
  if ( rb_respond_to(self_ref, rb_intern("to_comparable")) ) {
@@ -13092,7 +13093,7 @@ search_nearest_ki_native_i8 (VALUE self, CArray *ca, VALUE rval, int axis)
13092
13093
  {
13093
13094
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
13094
13095
  all dim==1 etc. to a Ruby Float and route it through the Case A
13095
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
13096
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
13096
13097
  downstream). */
13097
13098
  if ( rb_obj_is_carray(rval) ) {
13098
13099
  CArray *cv_pre_;
@@ -13418,7 +13419,7 @@ search_nearest_ki_native_u8 (VALUE self, CArray *ca, VALUE rval, int axis)
13418
13419
  {
13419
13420
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
13420
13421
  all dim==1 etc. to a Ruby Float and route it through the Case A
13421
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
13422
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
13422
13423
  downstream). */
13423
13424
  if ( rb_obj_is_carray(rval) ) {
13424
13425
  CArray *cv_pre_;
@@ -13744,7 +13745,7 @@ search_nearest_ki_native_i16 (VALUE self, CArray *ca, VALUE rval, int axis)
13744
13745
  {
13745
13746
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
13746
13747
  all dim==1 etc. to a Ruby Float and route it through the Case A
13747
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
13748
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
13748
13749
  downstream). */
13749
13750
  if ( rb_obj_is_carray(rval) ) {
13750
13751
  CArray *cv_pre_;
@@ -14070,7 +14071,7 @@ search_nearest_ki_native_u16 (VALUE self, CArray *ca, VALUE rval, int axis)
14070
14071
  {
14071
14072
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
14072
14073
  all dim==1 etc. to a Ruby Float and route it through the Case A
14073
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
14074
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
14074
14075
  downstream). */
14075
14076
  if ( rb_obj_is_carray(rval) ) {
14076
14077
  CArray *cv_pre_;
@@ -14396,7 +14397,7 @@ search_nearest_ki_native_i32 (VALUE self, CArray *ca, VALUE rval, int axis)
14396
14397
  {
14397
14398
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
14398
14399
  all dim==1 etc. to a Ruby Float and route it through the Case A
14399
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
14400
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
14400
14401
  downstream). */
14401
14402
  if ( rb_obj_is_carray(rval) ) {
14402
14403
  CArray *cv_pre_;
@@ -14722,7 +14723,7 @@ search_nearest_ki_native_u32 (VALUE self, CArray *ca, VALUE rval, int axis)
14722
14723
  {
14723
14724
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
14724
14725
  all dim==1 etc. to a Ruby Float and route it through the Case A
14725
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
14726
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
14726
14727
  downstream). */
14727
14728
  if ( rb_obj_is_carray(rval) ) {
14728
14729
  CArray *cv_pre_;
@@ -15048,7 +15049,7 @@ search_nearest_ki_native_i64 (VALUE self, CArray *ca, VALUE rval, int axis)
15048
15049
  {
15049
15050
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
15050
15051
  all dim==1 etc. to a Ruby Float and route it through the Case A
15051
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
15052
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
15052
15053
  downstream). */
15053
15054
  if ( rb_obj_is_carray(rval) ) {
15054
15055
  CArray *cv_pre_;
@@ -15374,7 +15375,7 @@ search_nearest_ki_native_u64 (VALUE self, CArray *ca, VALUE rval, int axis)
15374
15375
  {
15375
15376
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
15376
15377
  all dim==1 etc. to a Ruby Float and route it through the Case A
15377
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
15378
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
15378
15379
  downstream). */
15379
15380
  if ( rb_obj_is_carray(rval) ) {
15380
15381
  CArray *cv_pre_;
@@ -15700,7 +15701,7 @@ search_nearest_ki_native_f32 (VALUE self, CArray *ca, VALUE rval, int axis)
15700
15701
  {
15701
15702
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
15702
15703
  all dim==1 etc. to a Ruby Float and route it through the Case A
15703
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
15704
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
15704
15705
  downstream). */
15705
15706
  if ( rb_obj_is_carray(rval) ) {
15706
15707
  CArray *cv_pre_;
@@ -16026,7 +16027,7 @@ search_nearest_ki_native_f64 (VALUE self, CArray *ca, VALUE rval, int axis)
16026
16027
  {
16027
16028
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
16028
16029
  all dim==1 etc. to a Ruby Float and route it through the Case A
16029
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
16030
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
16030
16031
  downstream). */
16031
16032
  if ( rb_obj_is_carray(rval) ) {
16032
16033
  CArray *cv_pre_;
@@ -16352,7 +16353,7 @@ search_nearest_ki_native_bool (VALUE self, CArray *ca, VALUE rval, int axis)
16352
16353
  {
16353
16354
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
16354
16355
  all dim==1 etc. to a Ruby Float and route it through the Case A
16355
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
16356
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
16356
16357
  downstream). */
16357
16358
  if ( rb_obj_is_carray(rval) ) {
16358
16359
  CArray *cv_pre_;
@@ -16678,7 +16679,7 @@ search_nearest_ki_native_object (VALUE self, CArray *ca, VALUE rval, int axis)
16678
16679
  {
16679
16680
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
16680
16681
  all dim==1 etc. to a Ruby Float and route it through the Case A
16681
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
16682
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
16682
16683
  downstream). */
16683
16684
  if ( rb_obj_is_carray(rval) ) {
16684
16685
  CArray *cv_pre_;
@@ -16723,12 +16724,32 @@ search_nearest_ki_native_object (VALUE self, CArray *ca, VALUE rval, int axis)
16723
16724
  {
16724
16725
  /* CA_OBJECT nearest: minimum of query_val.distance(cell), compared
16725
16726
  with `<` (matches the legacy flat proc_nearest_addr_VALUE). */
16727
+ /* Nearest needs a metric. #distance is the protocol the 2.0 flat
16728
+ kernel used, back when Numeric#distance was a monkey patch; it
16729
+ is an opt-in refinement now, and a refinement does not reach an
16730
+ rb_funcall from C -- so a number reaching here answers no more
16731
+ than a String does. Measure a number the way #distance itself
16732
+ does, keep #distance for anything that defines a real one, and
16733
+ refuse the rest by name rather than let a bare NoMethodError out
16734
+ of the loop below. */
16735
+ ID nearest_id = rb_intern("distance");
16736
+ int nearest_by_distance = rb_respond_to(query_val, nearest_id);
16737
+ if ( ! nearest_by_distance && ! rb_obj_is_kind_of(query_val, rb_cNumeric) ) {
16738
+ rb_raise(rb_eCADataTypeError,
16739
+ "search_nearest: nearest needs a distance, and %s is neither a "
16740
+ "number nor answers #distance (define one on the stored "
16741
+ "objects, or use search / bsearch for an exact match)",
16742
+ rb_obj_classname(query_val));
16743
+ }
16726
16744
  result = (ca_size_t) -1;
16727
16745
  VALUE best = Qnil;
16728
16746
  for ( ca_size_t i = 0; i < slab_n; i++ ) {
16729
16747
  if ( mask_in && mask_in[i * slab_mask_stride] ) continue;
16730
16748
  VALUE v = *(VALUE *)(slab_ptr + i * slab_stride);
16731
- VALUE dist = rb_funcall(query_val, rb_intern("distance"), 1, v);
16749
+ VALUE dist = nearest_by_distance
16750
+ ? rb_funcall(query_val, nearest_id, 1, v)
16751
+ : rb_funcall(rb_funcall(query_val, '-', 1, v),
16752
+ rb_intern("abs"), 0);
16732
16753
  if ( NIL_P(best) || RTEST(rb_funcall(dist, rb_intern("<"), 1, best)) ) {
16733
16754
  best = dist; result = i;
16734
16755
  }
@@ -16974,12 +16995,32 @@ search_nearest_ki_native_object (VALUE self, CArray *ca, VALUE rval, int axis)
16974
16995
  {
16975
16996
  /* CA_OBJECT nearest: minimum of query_val.distance(cell), compared
16976
16997
  with `<` (matches the legacy flat proc_nearest_addr_VALUE). */
16998
+ /* Nearest needs a metric. #distance is the protocol the 2.0 flat
16999
+ kernel used, back when Numeric#distance was a monkey patch; it
17000
+ is an opt-in refinement now, and a refinement does not reach an
17001
+ rb_funcall from C -- so a number reaching here answers no more
17002
+ than a String does. Measure a number the way #distance itself
17003
+ does, keep #distance for anything that defines a real one, and
17004
+ refuse the rest by name rather than let a bare NoMethodError out
17005
+ of the loop below. */
17006
+ ID nearest_id = rb_intern("distance");
17007
+ int nearest_by_distance = rb_respond_to(query_val, nearest_id);
17008
+ if ( ! nearest_by_distance && ! rb_obj_is_kind_of(query_val, rb_cNumeric) ) {
17009
+ rb_raise(rb_eCADataTypeError,
17010
+ "search_nearest: nearest needs a distance, and %s is neither a "
17011
+ "number nor answers #distance (define one on the stored "
17012
+ "objects, or use search / bsearch for an exact match)",
17013
+ rb_obj_classname(query_val));
17014
+ }
16977
17015
  result = (ca_size_t) -1;
16978
17016
  VALUE best = Qnil;
16979
17017
  for ( ca_size_t i = 0; i < slab_n; i++ ) {
16980
17018
  if ( mask_in && mask_in[i * slab_mask_stride] ) continue;
16981
17019
  VALUE v = *(VALUE *)(slab_ptr + i * slab_stride);
16982
- VALUE dist = rb_funcall(query_val, rb_intern("distance"), 1, v);
17020
+ VALUE dist = nearest_by_distance
17021
+ ? rb_funcall(query_val, nearest_id, 1, v)
17022
+ : rb_funcall(rb_funcall(query_val, '-', 1, v),
17023
+ rb_intern("abs"), 0);
16983
17024
  if ( NIL_P(best) || RTEST(rb_funcall(dist, rb_intern("<"), 1, best)) ) {
16984
17025
  best = dist; result = i;
16985
17026
  }
@@ -17054,7 +17095,7 @@ rb_ca_search_nearest_ki (VALUE self, VALUE rval, VALUE raxis)
17054
17095
  }
17055
17096
  if ( self_face_comparable ) {
17056
17097
  if ( rval_is_face ) {
17057
- rval = rb_ca_strip_face_value(rval);
17098
+ rval = ca_face_operand_descend(rval, "search_nearest_ki");
17058
17099
  }
17059
17100
  } else if ( self_was_face ) {
17060
17101
  if ( rb_respond_to(self_ref, rb_intern("to_comparable")) ) {
@@ -17100,7 +17141,7 @@ bsearch_addr_ki_native_i8 (VALUE self, CArray *ca, VALUE rval, int axis)
17100
17141
  {
17101
17142
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
17102
17143
  all dim==1 etc. to a Ruby Float and route it through the Case A
17103
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
17144
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
17104
17145
  downstream). */
17105
17146
  if ( rb_obj_is_carray(rval) ) {
17106
17147
  CArray *cv_pre_;
@@ -17458,7 +17499,7 @@ bsearch_addr_ki_native_u8 (VALUE self, CArray *ca, VALUE rval, int axis)
17458
17499
  {
17459
17500
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
17460
17501
  all dim==1 etc. to a Ruby Float and route it through the Case A
17461
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
17502
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
17462
17503
  downstream). */
17463
17504
  if ( rb_obj_is_carray(rval) ) {
17464
17505
  CArray *cv_pre_;
@@ -17816,7 +17857,7 @@ bsearch_addr_ki_native_i16 (VALUE self, CArray *ca, VALUE rval, int axis)
17816
17857
  {
17817
17858
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
17818
17859
  all dim==1 etc. to a Ruby Float and route it through the Case A
17819
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
17860
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
17820
17861
  downstream). */
17821
17862
  if ( rb_obj_is_carray(rval) ) {
17822
17863
  CArray *cv_pre_;
@@ -18174,7 +18215,7 @@ bsearch_addr_ki_native_u16 (VALUE self, CArray *ca, VALUE rval, int axis)
18174
18215
  {
18175
18216
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
18176
18217
  all dim==1 etc. to a Ruby Float and route it through the Case A
18177
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
18218
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
18178
18219
  downstream). */
18179
18220
  if ( rb_obj_is_carray(rval) ) {
18180
18221
  CArray *cv_pre_;
@@ -18532,7 +18573,7 @@ bsearch_addr_ki_native_i32 (VALUE self, CArray *ca, VALUE rval, int axis)
18532
18573
  {
18533
18574
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
18534
18575
  all dim==1 etc. to a Ruby Float and route it through the Case A
18535
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
18576
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
18536
18577
  downstream). */
18537
18578
  if ( rb_obj_is_carray(rval) ) {
18538
18579
  CArray *cv_pre_;
@@ -18890,7 +18931,7 @@ bsearch_addr_ki_native_u32 (VALUE self, CArray *ca, VALUE rval, int axis)
18890
18931
  {
18891
18932
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
18892
18933
  all dim==1 etc. to a Ruby Float and route it through the Case A
18893
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
18934
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
18894
18935
  downstream). */
18895
18936
  if ( rb_obj_is_carray(rval) ) {
18896
18937
  CArray *cv_pre_;
@@ -19248,7 +19289,7 @@ bsearch_addr_ki_native_i64 (VALUE self, CArray *ca, VALUE rval, int axis)
19248
19289
  {
19249
19290
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
19250
19291
  all dim==1 etc. to a Ruby Float and route it through the Case A
19251
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
19292
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
19252
19293
  downstream). */
19253
19294
  if ( rb_obj_is_carray(rval) ) {
19254
19295
  CArray *cv_pre_;
@@ -19606,7 +19647,7 @@ bsearch_addr_ki_native_u64 (VALUE self, CArray *ca, VALUE rval, int axis)
19606
19647
  {
19607
19648
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
19608
19649
  all dim==1 etc. to a Ruby Float and route it through the Case A
19609
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
19650
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
19610
19651
  downstream). */
19611
19652
  if ( rb_obj_is_carray(rval) ) {
19612
19653
  CArray *cv_pre_;
@@ -19964,7 +20005,7 @@ bsearch_addr_ki_native_f32 (VALUE self, CArray *ca, VALUE rval, int axis)
19964
20005
  {
19965
20006
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
19966
20007
  all dim==1 etc. to a Ruby Float and route it through the Case A
19967
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
20008
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
19968
20009
  downstream). */
19969
20010
  if ( rb_obj_is_carray(rval) ) {
19970
20011
  CArray *cv_pre_;
@@ -20322,7 +20363,7 @@ bsearch_addr_ki_native_f64 (VALUE self, CArray *ca, VALUE rval, int axis)
20322
20363
  {
20323
20364
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
20324
20365
  all dim==1 etc. to a Ruby Float and route it through the Case A
20325
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
20366
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
20326
20367
  downstream). */
20327
20368
  if ( rb_obj_is_carray(rval) ) {
20328
20369
  CArray *cv_pre_;
@@ -20680,7 +20721,7 @@ bsearch_addr_ki_native_bool (VALUE self, CArray *ca, VALUE rval, int axis)
20680
20721
  {
20681
20722
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
20682
20723
  all dim==1 etc. to a Ruby Float and route it through the Case A
20683
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
20724
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
20684
20725
  downstream). */
20685
20726
  if ( rb_obj_is_carray(rval) ) {
20686
20727
  CArray *cv_pre_;
@@ -21038,7 +21079,7 @@ bsearch_addr_ki_native_object (VALUE self, CArray *ca, VALUE rval, int axis)
21038
21079
  {
21039
21080
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
21040
21081
  all dim==1 etc. to a Ruby Float and route it through the Case A
21041
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
21082
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
21042
21083
  downstream). */
21043
21084
  if ( rb_obj_is_carray(rval) ) {
21044
21085
  CArray *cv_pre_;
@@ -21402,7 +21443,7 @@ bsearch_addr_ki_native_fixlen (VALUE self, CArray *ca, VALUE rval, int axis)
21402
21443
  {
21403
21444
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
21404
21445
  all dim==1 etc. to a Ruby Float and route it through the Case A
21405
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
21446
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
21406
21447
  downstream). */
21407
21448
  if ( rb_obj_is_carray(rval) ) {
21408
21449
  CArray *cv_pre_;
@@ -21800,7 +21841,7 @@ rb_ca_bsearch_addr_ki (VALUE self, VALUE rval, VALUE raxis)
21800
21841
  }
21801
21842
  if ( self_face_comparable ) {
21802
21843
  if ( rval_is_face ) {
21803
- rval = rb_ca_strip_face_value(rval);
21844
+ rval = ca_face_operand_descend(rval, "bsearch_addr_ki");
21804
21845
  }
21805
21846
  } else if ( self_was_face ) {
21806
21847
  if ( rb_respond_to(self_ref, rb_intern("to_comparable")) ) {
@@ -21851,7 +21892,7 @@ search_addr_ki_native_i8 (VALUE self, CArray *ca, VALUE rval, int axis, VALUE re
21851
21892
  {
21852
21893
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
21853
21894
  all dim==1 etc. to a Ruby Float and route it through the Case A
21854
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
21895
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
21855
21896
  downstream). */
21856
21897
  if ( rb_obj_is_carray(rval) ) {
21857
21898
  CArray *cv_pre_;
@@ -22198,7 +22239,7 @@ search_addr_ki_native_u8 (VALUE self, CArray *ca, VALUE rval, int axis, VALUE re
22198
22239
  {
22199
22240
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
22200
22241
  all dim==1 etc. to a Ruby Float and route it through the Case A
22201
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
22242
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
22202
22243
  downstream). */
22203
22244
  if ( rb_obj_is_carray(rval) ) {
22204
22245
  CArray *cv_pre_;
@@ -22545,7 +22586,7 @@ search_addr_ki_native_i16 (VALUE self, CArray *ca, VALUE rval, int axis, VALUE r
22545
22586
  {
22546
22587
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
22547
22588
  all dim==1 etc. to a Ruby Float and route it through the Case A
22548
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
22589
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
22549
22590
  downstream). */
22550
22591
  if ( rb_obj_is_carray(rval) ) {
22551
22592
  CArray *cv_pre_;
@@ -22892,7 +22933,7 @@ search_addr_ki_native_u16 (VALUE self, CArray *ca, VALUE rval, int axis, VALUE r
22892
22933
  {
22893
22934
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
22894
22935
  all dim==1 etc. to a Ruby Float and route it through the Case A
22895
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
22936
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
22896
22937
  downstream). */
22897
22938
  if ( rb_obj_is_carray(rval) ) {
22898
22939
  CArray *cv_pre_;
@@ -23239,7 +23280,7 @@ search_addr_ki_native_i32 (VALUE self, CArray *ca, VALUE rval, int axis, VALUE r
23239
23280
  {
23240
23281
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
23241
23282
  all dim==1 etc. to a Ruby Float and route it through the Case A
23242
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
23283
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
23243
23284
  downstream). */
23244
23285
  if ( rb_obj_is_carray(rval) ) {
23245
23286
  CArray *cv_pre_;
@@ -23586,7 +23627,7 @@ search_addr_ki_native_u32 (VALUE self, CArray *ca, VALUE rval, int axis, VALUE r
23586
23627
  {
23587
23628
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
23588
23629
  all dim==1 etc. to a Ruby Float and route it through the Case A
23589
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
23630
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
23590
23631
  downstream). */
23591
23632
  if ( rb_obj_is_carray(rval) ) {
23592
23633
  CArray *cv_pre_;
@@ -23933,7 +23974,7 @@ search_addr_ki_native_i64 (VALUE self, CArray *ca, VALUE rval, int axis, VALUE r
23933
23974
  {
23934
23975
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
23935
23976
  all dim==1 etc. to a Ruby Float and route it through the Case A
23936
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
23977
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
23937
23978
  downstream). */
23938
23979
  if ( rb_obj_is_carray(rval) ) {
23939
23980
  CArray *cv_pre_;
@@ -24280,7 +24321,7 @@ search_addr_ki_native_u64 (VALUE self, CArray *ca, VALUE rval, int axis, VALUE r
24280
24321
  {
24281
24322
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
24282
24323
  all dim==1 etc. to a Ruby Float and route it through the Case A
24283
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
24324
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
24284
24325
  downstream). */
24285
24326
  if ( rb_obj_is_carray(rval) ) {
24286
24327
  CArray *cv_pre_;
@@ -24627,7 +24668,7 @@ search_addr_ki_native_f32 (VALUE self, CArray *ca, VALUE rval, int axis, VALUE r
24627
24668
  {
24628
24669
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
24629
24670
  all dim==1 etc. to a Ruby Float and route it through the Case A
24630
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
24671
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
24631
24672
  downstream). */
24632
24673
  if ( rb_obj_is_carray(rval) ) {
24633
24674
  CArray *cv_pre_;
@@ -24972,7 +25013,7 @@ search_addr_ki_native_f64 (VALUE self, CArray *ca, VALUE rval, int axis, VALUE r
24972
25013
  {
24973
25014
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
24974
25015
  all dim==1 etc. to a Ruby Float and route it through the Case A
24975
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
25016
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
24976
25017
  downstream). */
24977
25018
  if ( rb_obj_is_carray(rval) ) {
24978
25019
  CArray *cv_pre_;
@@ -25317,7 +25358,7 @@ search_addr_ki_native_bool (VALUE self, CArray *ca, VALUE rval, int axis, VALUE
25317
25358
  {
25318
25359
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
25319
25360
  all dim==1 etc. to a Ruby Float and route it through the Case A
25320
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
25361
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
25321
25362
  downstream). */
25322
25363
  if ( rb_obj_is_carray(rval) ) {
25323
25364
  CArray *cv_pre_;
@@ -25664,7 +25705,7 @@ search_addr_ki_native_object (VALUE self, CArray *ca, VALUE rval, int axis, VALU
25664
25705
  {
25665
25706
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
25666
25707
  all dim==1 etc. to a Ruby Float and route it through the Case A
25667
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
25708
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
25668
25709
  downstream). */
25669
25710
  if ( rb_obj_is_carray(rval) ) {
25670
25711
  CArray *cv_pre_;
@@ -26009,7 +26050,7 @@ search_addr_ki_native_fixlen (VALUE self, CArray *ca, VALUE rval, int axis, VALU
26009
26050
  {
26010
26051
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
26011
26052
  all dim==1 etc. to a Ruby Float and route it through the Case A
26012
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
26053
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
26013
26054
  downstream). */
26014
26055
  if ( rb_obj_is_carray(rval) ) {
26015
26056
  CArray *cv_pre_;
@@ -26402,7 +26443,7 @@ rb_ca_search_addr_ki (int argc, VALUE *argv, VALUE self)
26402
26443
  }
26403
26444
  if ( self_face_comparable ) {
26404
26445
  if ( rval_is_face ) {
26405
- rval = rb_ca_strip_face_value(rval);
26446
+ rval = ca_face_operand_descend(rval, "search_addr_ki");
26406
26447
  }
26407
26448
  } else if ( self_was_face ) {
26408
26449
  if ( rb_respond_to(self_ref, rb_intern("to_comparable")) ) {
@@ -26449,7 +26490,7 @@ search_nearest_addr_ki_native_i8 (VALUE self, CArray *ca, VALUE rval, int axis)
26449
26490
  {
26450
26491
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
26451
26492
  all dim==1 etc. to a Ruby Float and route it through the Case A
26452
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
26493
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
26453
26494
  downstream). */
26454
26495
  if ( rb_obj_is_carray(rval) ) {
26455
26496
  CArray *cv_pre_;
@@ -26797,7 +26838,7 @@ search_nearest_addr_ki_native_u8 (VALUE self, CArray *ca, VALUE rval, int axis)
26797
26838
  {
26798
26839
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
26799
26840
  all dim==1 etc. to a Ruby Float and route it through the Case A
26800
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
26841
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
26801
26842
  downstream). */
26802
26843
  if ( rb_obj_is_carray(rval) ) {
26803
26844
  CArray *cv_pre_;
@@ -27145,7 +27186,7 @@ search_nearest_addr_ki_native_i16 (VALUE self, CArray *ca, VALUE rval, int axis)
27145
27186
  {
27146
27187
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
27147
27188
  all dim==1 etc. to a Ruby Float and route it through the Case A
27148
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
27189
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
27149
27190
  downstream). */
27150
27191
  if ( rb_obj_is_carray(rval) ) {
27151
27192
  CArray *cv_pre_;
@@ -27493,7 +27534,7 @@ search_nearest_addr_ki_native_u16 (VALUE self, CArray *ca, VALUE rval, int axis)
27493
27534
  {
27494
27535
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
27495
27536
  all dim==1 etc. to a Ruby Float and route it through the Case A
27496
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
27537
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
27497
27538
  downstream). */
27498
27539
  if ( rb_obj_is_carray(rval) ) {
27499
27540
  CArray *cv_pre_;
@@ -27841,7 +27882,7 @@ search_nearest_addr_ki_native_i32 (VALUE self, CArray *ca, VALUE rval, int axis)
27841
27882
  {
27842
27883
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
27843
27884
  all dim==1 etc. to a Ruby Float and route it through the Case A
27844
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
27885
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
27845
27886
  downstream). */
27846
27887
  if ( rb_obj_is_carray(rval) ) {
27847
27888
  CArray *cv_pre_;
@@ -28189,7 +28230,7 @@ search_nearest_addr_ki_native_u32 (VALUE self, CArray *ca, VALUE rval, int axis)
28189
28230
  {
28190
28231
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
28191
28232
  all dim==1 etc. to a Ruby Float and route it through the Case A
28192
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
28233
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
28193
28234
  downstream). */
28194
28235
  if ( rb_obj_is_carray(rval) ) {
28195
28236
  CArray *cv_pre_;
@@ -28537,7 +28578,7 @@ search_nearest_addr_ki_native_i64 (VALUE self, CArray *ca, VALUE rval, int axis)
28537
28578
  {
28538
28579
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
28539
28580
  all dim==1 etc. to a Ruby Float and route it through the Case A
28540
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
28581
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
28541
28582
  downstream). */
28542
28583
  if ( rb_obj_is_carray(rval) ) {
28543
28584
  CArray *cv_pre_;
@@ -28885,7 +28926,7 @@ search_nearest_addr_ki_native_u64 (VALUE self, CArray *ca, VALUE rval, int axis)
28885
28926
  {
28886
28927
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
28887
28928
  all dim==1 etc. to a Ruby Float and route it through the Case A
28888
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
28929
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
28889
28930
  downstream). */
28890
28931
  if ( rb_obj_is_carray(rval) ) {
28891
28932
  CArray *cv_pre_;
@@ -29233,7 +29274,7 @@ search_nearest_addr_ki_native_f32 (VALUE self, CArray *ca, VALUE rval, int axis)
29233
29274
  {
29234
29275
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
29235
29276
  all dim==1 etc. to a Ruby Float and route it through the Case A
29236
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
29277
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
29237
29278
  downstream). */
29238
29279
  if ( rb_obj_is_carray(rval) ) {
29239
29280
  CArray *cv_pre_;
@@ -29581,7 +29622,7 @@ search_nearest_addr_ki_native_f64 (VALUE self, CArray *ca, VALUE rval, int axis)
29581
29622
  {
29582
29623
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
29583
29624
  all dim==1 etc. to a Ruby Float and route it through the Case A
29584
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
29625
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
29585
29626
  downstream). */
29586
29627
  if ( rb_obj_is_carray(rval) ) {
29587
29628
  CArray *cv_pre_;
@@ -29929,7 +29970,7 @@ search_nearest_addr_ki_native_bool (VALUE self, CArray *ca, VALUE rval, int axis
29929
29970
  {
29930
29971
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
29931
29972
  all dim==1 etc. to a Ruby Float and route it through the Case A
29932
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
29973
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
29933
29974
  downstream). */
29934
29975
  if ( rb_obj_is_carray(rval) ) {
29935
29976
  CArray *cv_pre_;
@@ -30277,7 +30318,7 @@ search_nearest_addr_ki_native_object (VALUE self, CArray *ca, VALUE rval, int ax
30277
30318
  {
30278
30319
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
30279
30320
  all dim==1 etc. to a Ruby Float and route it through the Case A
30280
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
30321
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
30281
30322
  downstream). */
30282
30323
  if ( rb_obj_is_carray(rval) ) {
30283
30324
  CArray *cv_pre_;
@@ -30337,12 +30378,32 @@ for ( int8_t mm = 0; mm < st.outer_ndim; mm++ ) {
30337
30378
  {
30338
30379
  /* CA_OBJECT nearest (view_flat addr): minimum of
30339
30380
  query_val.distance(cell), compared with `<`. */
30381
+ /* Nearest needs a metric. #distance is the protocol the 2.0 flat
30382
+ kernel used, back when Numeric#distance was a monkey patch; it
30383
+ is an opt-in refinement now, and a refinement does not reach an
30384
+ rb_funcall from C -- so a number reaching here answers no more
30385
+ than a String does. Measure a number the way #distance itself
30386
+ does, keep #distance for anything that defines a real one, and
30387
+ refuse the rest by name rather than let a bare NoMethodError out
30388
+ of the loop below. */
30389
+ ID nearest_id = rb_intern("distance");
30390
+ int nearest_by_distance = rb_respond_to(query_val, nearest_id);
30391
+ if ( ! nearest_by_distance && ! rb_obj_is_kind_of(query_val, rb_cNumeric) ) {
30392
+ rb_raise(rb_eCADataTypeError,
30393
+ "search_nearest_addr: nearest needs a distance, and %s is neither a "
30394
+ "number nor answers #distance (define one on the stored "
30395
+ "objects, or use search / bsearch for an exact match)",
30396
+ rb_obj_classname(query_val));
30397
+ }
30340
30398
  result = (ca_size_t) -1;
30341
30399
  VALUE best = Qnil;
30342
30400
  for ( ca_size_t i = 0; i < slab_n; i++ ) {
30343
30401
  if ( mask_in && mask_in[i * slab_mask_stride] ) continue;
30344
30402
  VALUE v = *(VALUE *)(slab_ptr + i * slab_stride);
30345
- VALUE dist = rb_funcall(query_val, rb_intern("distance"), 1, v);
30403
+ VALUE dist = nearest_by_distance
30404
+ ? rb_funcall(query_val, nearest_id, 1, v)
30405
+ : rb_funcall(rb_funcall(query_val, '-', 1, v),
30406
+ rb_intern("abs"), 0);
30346
30407
  if ( NIL_P(best) || RTEST(rb_funcall(dist, rb_intern("<"), 1, best)) ) {
30347
30408
  best = dist; result = i;
30348
30409
  }
@@ -30595,12 +30656,32 @@ rb_raise(rb_eNotImpError, "search_nearest_addr_ki: view_flat semantics with CArr
30595
30656
  {
30596
30657
  /* CA_OBJECT nearest (view_flat addr): minimum of
30597
30658
  query_val.distance(cell), compared with `<`. */
30659
+ /* Nearest needs a metric. #distance is the protocol the 2.0 flat
30660
+ kernel used, back when Numeric#distance was a monkey patch; it
30661
+ is an opt-in refinement now, and a refinement does not reach an
30662
+ rb_funcall from C -- so a number reaching here answers no more
30663
+ than a String does. Measure a number the way #distance itself
30664
+ does, keep #distance for anything that defines a real one, and
30665
+ refuse the rest by name rather than let a bare NoMethodError out
30666
+ of the loop below. */
30667
+ ID nearest_id = rb_intern("distance");
30668
+ int nearest_by_distance = rb_respond_to(query_val, nearest_id);
30669
+ if ( ! nearest_by_distance && ! rb_obj_is_kind_of(query_val, rb_cNumeric) ) {
30670
+ rb_raise(rb_eCADataTypeError,
30671
+ "search_nearest_addr: nearest needs a distance, and %s is neither a "
30672
+ "number nor answers #distance (define one on the stored "
30673
+ "objects, or use search / bsearch for an exact match)",
30674
+ rb_obj_classname(query_val));
30675
+ }
30598
30676
  result = (ca_size_t) -1;
30599
30677
  VALUE best = Qnil;
30600
30678
  for ( ca_size_t i = 0; i < slab_n; i++ ) {
30601
30679
  if ( mask_in && mask_in[i * slab_mask_stride] ) continue;
30602
30680
  VALUE v = *(VALUE *)(slab_ptr + i * slab_stride);
30603
- VALUE dist = rb_funcall(query_val, rb_intern("distance"), 1, v);
30681
+ VALUE dist = nearest_by_distance
30682
+ ? rb_funcall(query_val, nearest_id, 1, v)
30683
+ : rb_funcall(rb_funcall(query_val, '-', 1, v),
30684
+ rb_intern("abs"), 0);
30604
30685
  if ( NIL_P(best) || RTEST(rb_funcall(dist, rb_intern("<"), 1, best)) ) {
30605
30686
  best = dist; result = i;
30606
30687
  }
@@ -30675,7 +30756,7 @@ rb_ca_search_nearest_addr_ki (VALUE self, VALUE rval, VALUE raxis)
30675
30756
  }
30676
30757
  if ( self_face_comparable ) {
30677
30758
  if ( rval_is_face ) {
30678
- rval = rb_ca_strip_face_value(rval);
30759
+ rval = ca_face_operand_descend(rval, "search_nearest_addr_ki");
30679
30760
  }
30680
30761
  } else if ( self_was_face ) {
30681
30762
  if ( rb_respond_to(self_ref, rb_intern("to_comparable")) ) {
@@ -30721,7 +30802,7 @@ linear_section_binary_ki_native_f64 (VALUE self, CArray *ca, VALUE rval, int axi
30721
30802
  {
30722
30803
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
30723
30804
  all dim==1 etc. to a Ruby Float and route it through the Case A
30724
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
30805
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
30725
30806
  downstream). */
30726
30807
  if ( rb_obj_is_carray(rval) ) {
30727
30808
  CArray *cv_pre_;
@@ -31229,7 +31310,7 @@ rb_ca_linear_section_binary_ki (VALUE self, VALUE rval, VALUE raxis)
31229
31310
  }
31230
31311
  if ( self_face_comparable ) {
31231
31312
  if ( rval_is_face ) {
31232
- rval = rb_ca_strip_face_value(rval);
31313
+ rval = ca_face_operand_descend(rval, "linear_section_binary_ki");
31233
31314
  }
31234
31315
  } else if ( self_was_face ) {
31235
31316
  if ( rb_respond_to(self_ref, rb_intern("to_comparable")) ) {
@@ -31268,7 +31349,7 @@ linear_section_linear_ki_native_f64 (VALUE self, CArray *ca, VALUE rval, int axi
31268
31349
  {
31269
31350
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
31270
31351
  all dim==1 etc. to a Ruby Float and route it through the Case A
31271
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
31352
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
31272
31353
  downstream). */
31273
31354
  if ( rb_obj_is_carray(rval) ) {
31274
31355
  CArray *cv_pre_;
@@ -31678,7 +31759,7 @@ rb_ca_linear_section_linear_ki (VALUE self, VALUE rval, VALUE raxis)
31678
31759
  }
31679
31760
  if ( self_face_comparable ) {
31680
31761
  if ( rval_is_face ) {
31681
- rval = rb_ca_strip_face_value(rval);
31762
+ rval = ca_face_operand_descend(rval, "linear_section_linear_ki");
31682
31763
  }
31683
31764
  } else if ( self_was_face ) {
31684
31765
  if ( rb_respond_to(self_ref, rb_intern("to_comparable")) ) {
@@ -31717,7 +31798,7 @@ linear_fetch_ki_native_f64 (VALUE self, CArray *ca, VALUE rval, int axis)
31717
31798
  {
31718
31799
  /* rev4 A1 via single-element CArray: convert CScalar / [1] 1-D /
31719
31800
  all dim==1 etc. to a Ruby Float and route it through the Case A
31720
- scalar path. The dtype matches ca (= rb_ca_obj2ptr coerces it
31801
+ scalar path. The data type matches ca (= rb_ca_obj2ptr coerces it
31721
31802
  downstream). */
31722
31803
  if ( rb_obj_is_carray(rval) ) {
31723
31804
  CArray *cv_pre_;
@@ -32089,7 +32170,7 @@ rb_ca_linear_fetch_ki (VALUE self, VALUE rval, VALUE raxis)
32089
32170
  }
32090
32171
  if ( self_face_comparable ) {
32091
32172
  if ( rval_is_face ) {
32092
- rval = rb_ca_strip_face_value(rval);
32173
+ rval = ca_face_operand_descend(rval, "linear_fetch_ki");
32093
32174
  }
32094
32175
  } else if ( self_was_face ) {
32095
32176
  if ( rb_respond_to(self_ref, rb_intern("to_comparable")) ) {