carray 3.0.6 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (277) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -1
  3. data/CHANGELOG.md +7 -1830
  4. data/README.md +62 -35
  5. data/carray.gemspec +16 -4
  6. data/docs/changelogs/CHANGELOG-3.0.md +2464 -0
  7. data/ext/ca_array_pool.c +4 -5
  8. data/ext/ca_axis_descriptor.h +45 -30
  9. data/ext/ca_axis_dispatch.c +7 -4
  10. data/ext/ca_axis_group.c +12 -15
  11. data/ext/ca_bincmp_dispatch.h +16 -38
  12. data/ext/ca_binop_dispatch.c +35 -0
  13. data/ext/ca_binop_dispatch.h +22 -46
  14. data/ext/ca_categorical_iterator.c +36 -34
  15. data/ext/ca_compare.c +0 -1
  16. data/ext/ca_compare.h +8 -1
  17. data/ext/ca_composite_dispatch.h +6 -0
  18. data/ext/ca_for_buffer.h +6 -1
  19. data/ext/ca_group_iter.c +17 -18
  20. data/ext/ca_iter_state_fields.h +196 -0
  21. data/ext/ca_iter_substrate.h +84 -103
  22. data/ext/ca_kernel_iterator.c +125 -89
  23. data/ext/ca_kernel_iterator.h +229 -1504
  24. data/ext/ca_kernel_iterator_internal.h +1167 -0
  25. data/ext/ca_moncmp_dispatch.h +17 -24
  26. data/ext/ca_monop_dispatch.h +25 -74
  27. data/ext/ca_obj_array.c +92 -165
  28. data/ext/ca_obj_bincmp.c +65 -48
  29. data/ext/ca_obj_binop.c +74 -49
  30. data/ext/ca_obj_bitarray.c +7 -21
  31. data/ext/ca_obj_bitfield.c +93 -26
  32. data/ext/ca_obj_block.c +11 -12
  33. data/ext/ca_obj_byte_swap.c +34 -34
  34. data/ext/ca_obj_const_string.c +464 -304
  35. data/ext/ca_obj_face.c +167 -121
  36. data/ext/ca_obj_face.h +32 -170
  37. data/ext/ca_obj_fake.c +127 -34
  38. data/ext/ca_obj_farray.c +13 -9
  39. data/ext/ca_obj_field.c +17 -13
  40. data/ext/ca_obj_fixlen_string.c +57 -34
  41. data/ext/ca_obj_grid.c +149 -113
  42. data/ext/ca_obj_meld.c +28 -26
  43. data/ext/ca_obj_moncmp.c +10 -21
  44. data/ext/ca_obj_monop.c +88 -73
  45. data/ext/ca_obj_object.c +60 -46
  46. data/ext/ca_obj_record.c +74 -22
  47. data/ext/ca_obj_reduce.c +10 -14
  48. data/ext/ca_obj_refer.c +146 -39
  49. data/ext/ca_obj_remap.c +11 -29
  50. data/ext/ca_obj_repeat.c +41 -23
  51. data/ext/ca_obj_roll.c +20 -28
  52. data/ext/ca_obj_select.c +17 -27
  53. data/ext/ca_obj_select_axis.c +35 -42
  54. data/ext/ca_obj_shift.c +22 -42
  55. data/ext/ca_obj_source.c +1 -5
  56. data/ext/ca_obj_stack.c +33 -29
  57. data/ext/ca_obj_stride.c +99 -62
  58. data/ext/ca_obj_string.c +8 -20
  59. data/ext/ca_obj_tile.c +14 -16
  60. data/ext/ca_obj_time.c +12 -23
  61. data/ext/ca_obj_timedelta.c +12 -23
  62. data/ext/ca_obj_transpose.c +8 -10
  63. data/ext/ca_obj_triop.c +48 -49
  64. data/ext/ca_obj_window.c +87 -99
  65. data/ext/ca_op_cmplx64.h +4 -0
  66. data/ext/ca_op_ipower.c +97 -27
  67. data/ext/ca_op_powi.h +9 -28
  68. data/ext/ca_pow5_table.h +2 -1
  69. data/ext/ca_rng_normal.h +4 -0
  70. data/ext/ca_rng_xoshiro256pp.h +3 -0
  71. data/ext/ca_sort_kernels.h +23 -26
  72. data/ext/ca_sweep_engine.c +92 -26
  73. data/ext/ca_sweep_engine.h +22 -15
  74. data/ext/ca_transform_common.c +3 -8
  75. data/ext/ca_triop_dispatch.h +20 -32
  76. data/ext/caframe_csv_reader.c +12 -12
  77. data/ext/carray.h +300 -1009
  78. data/ext/carray_access.c +320 -207
  79. data/ext/carray_address_basis.c +128 -59
  80. data/ext/carray_attribute.c +81 -104
  81. data/ext/carray_bincount.c +12 -14
  82. data/ext/carray_broadcast.c +31 -27
  83. data/ext/carray_call_cfunc.c +174 -285
  84. data/ext/carray_call_cfunc.h +36 -28
  85. data/ext/carray_cast.c +1191 -351
  86. data/ext/carray_cast_func.rb +68 -8
  87. data/ext/carray_class.c +6 -11
  88. data/ext/carray_conversion.c +98 -39
  89. data/ext/carray_copy.c +52 -26
  90. data/ext/carray_core.c +286 -132
  91. data/ext/carray_count.c +53 -22
  92. data/ext/carray_element.c +49 -28
  93. data/ext/carray_factorize.c +64 -63
  94. data/ext/carray_generate.c +26 -19
  95. data/ext/carray_histogram.c +9 -11
  96. data/ext/carray_hold.c +7 -9
  97. data/ext/carray_index_classifier.c +127 -230
  98. data/ext/carray_index_classifier.h +11 -10
  99. data/ext/carray_integer_total.c +523 -0
  100. data/ext/carray_internal.h +1364 -156
  101. data/ext/carray_key_windows.c +3 -3
  102. data/ext/carray_lazy.c +37 -37
  103. data/ext/carray_loop.c +27 -23
  104. data/ext/carray_mask.c +235 -150
  105. data/ext/carray_math_kernel.h +23 -47
  106. data/ext/carray_mathfunc.c +10 -3
  107. data/ext/carray_median_percentile.c +106 -100
  108. data/ext/carray_memory_view.c +83 -69
  109. data/ext/carray_operator.c +490 -128
  110. data/ext/carray_order.c +163 -84
  111. data/ext/carray_partition.c +14 -16
  112. data/ext/carray_random.c +48 -42
  113. data/ext/carray_round.c +33 -5
  114. data/ext/carray_scatter.c +57 -39
  115. data/ext/carray_segment.c +42 -46
  116. data/ext/carray_slab.c +77 -51
  117. data/ext/carray_slab.h +44 -33
  118. data/ext/carray_sort.c +37 -31
  119. data/ext/carray_sort_kernel.c +36 -10
  120. data/ext/carray_struct.c +44 -34
  121. data/ext/carray_test.c +131 -81
  122. data/ext/carray_time_text.c +30 -31
  123. data/ext/carray_undef.c +50 -7
  124. data/ext/carray_utils.c +373 -139
  125. data/ext/extconf.rb +24 -17
  126. data/ext/mk_call_cfunc.rb +25 -31
  127. data/ext/mk_pow5_table.rb +2 -1
  128. data/ext/mkkernel.rb +819 -488
  129. data/ext/ruby_carray.c +47 -42
  130. data/ext/version.h +7 -5
  131. data/lib/carray/attribute.rb +19 -18
  132. data/lib/carray/autoload_carray.rb +20 -15
  133. data/lib/carray/autoload_method_extension.rb +64 -57
  134. data/lib/carray/axis_group.rb +272 -185
  135. data/lib/carray/basics.rb +298 -56
  136. data/lib/carray/bincount_nd.rb +41 -18
  137. data/lib/carray/block_iterator.rb +167 -119
  138. data/lib/carray/boolean_reduce.rb +7 -4
  139. data/lib/carray/categorical.rb +84 -59
  140. data/lib/carray/categorical_iterator.rb +90 -67
  141. data/lib/carray/complex.rb +61 -41
  142. data/lib/carray/conditional.rb +98 -23
  143. data/lib/carray/const_string.rb +112 -46
  144. data/lib/carray/core_extensions.rb +20 -69
  145. data/lib/carray/distance_limit.rb +7 -5
  146. data/lib/carray/factories.rb +269 -0
  147. data/lib/carray/fixlen_string.rb +95 -12
  148. data/lib/carray/frame/column_verbs.rb +76 -9
  149. data/lib/carray/frame/concat.rb +51 -7
  150. data/lib/carray/frame/convert.rb +2 -1
  151. data/lib/carray/frame/csv_parser.rb +20 -5
  152. data/lib/carray/frame/frame.rb +73 -31
  153. data/lib/carray/frame/group.rb +247 -187
  154. data/lib/carray/frame/io.rb +36 -12
  155. data/lib/carray/frame/join.rb +56 -17
  156. data/lib/carray/frame/records.rb +7 -5
  157. data/lib/carray/frame/reshape.rb +27 -7
  158. data/lib/carray/frame/sort.rb +10 -8
  159. data/lib/carray/frame/verbs.rb +217 -134
  160. data/lib/carray/frame/windows.rb +254 -19
  161. data/lib/carray/frame.rb +1 -2
  162. data/lib/carray/fuse_source.rb +28 -23
  163. data/lib/carray/fusion.rb +30 -30
  164. data/lib/carray/histogram.rb +35 -16
  165. data/lib/carray/inspect.rb +7 -7
  166. data/lib/carray/iterator.rb +104 -23
  167. data/lib/carray/key_windows.rb +93 -61
  168. data/lib/carray/lazy.rb +208 -111
  169. data/lib/carray/limits.rb +80 -0
  170. data/lib/carray/mask_gap_fill.rb +21 -16
  171. data/lib/carray/math.rb +87 -50
  172. data/lib/carray/meld_reduce.rb +30 -8
  173. data/lib/carray/methods/align_addr.rb +29 -17
  174. data/lib/carray/methods/bin.rb +8 -1
  175. data/lib/carray/methods/bincount.rb +4 -2
  176. data/lib/carray/methods/bit_string.rb +19 -31
  177. data/lib/carray/methods/broadcast.rb +8 -3
  178. data/lib/carray/methods/choose.rb +5 -5
  179. data/lib/carray/methods/composition.rb +73 -72
  180. data/lib/carray/methods/{index.rb → coordinate.rb} +13 -13
  181. data/lib/carray/methods/discovery_along.rb +3 -3
  182. data/lib/carray/methods/factorize.rb +2 -0
  183. data/lib/carray/methods/gather_nd.rb +106 -103
  184. data/lib/carray/methods/insert_block.rb +2 -2
  185. data/lib/carray/methods/is_between.rb +6 -4
  186. data/lib/carray/methods/is_in.rb +183 -143
  187. data/lib/carray/methods/join.rb +2 -1
  188. data/lib/carray/methods/lag.rb +6 -2
  189. data/lib/carray/methods/locate_addr.rb +157 -94
  190. data/lib/carray/methods/mask_duplicates.rb +1 -1
  191. data/lib/carray/methods/meshgrid.rb +28 -16
  192. data/lib/carray/methods/mode.rb +67 -67
  193. data/lib/carray/methods/nunique.rb +9 -7
  194. data/lib/carray/methods/repeat.rb +23 -13
  195. data/lib/carray/methods/resize.rb +1 -1
  196. data/lib/carray/methods/snap.rb +24 -20
  197. data/lib/carray/methods/string_format.rb +2 -2
  198. data/lib/carray/methods/unique.rb +4 -2
  199. data/lib/carray/methods/value_counts.rb +1 -1
  200. data/lib/carray/mkmf.rb +25 -28
  201. data/lib/carray/percentile_arguments.rb +82 -0
  202. data/lib/carray/record_order.rb +50 -20
  203. data/lib/carray/rng.rb +1 -0
  204. data/lib/carray/runtime.rb +195 -17
  205. data/lib/carray/segment_iterator.rb +262 -137
  206. data/lib/carray/serialize.rb +635 -566
  207. data/lib/carray/slab_iterator.rb +114 -114
  208. data/lib/carray/stack.rb +14 -15
  209. data/lib/carray/string.rb +16 -22
  210. data/lib/carray/string_operation_extension.rb +97 -52
  211. data/lib/carray/struct.rb +122 -164
  212. data/lib/carray/struct_builder.rb +247 -73
  213. data/lib/carray/time.rb +663 -365
  214. data/lib/carray/window_iterator.rb +232 -155
  215. data/lib/carray.rb +6 -11
  216. data/yard-stubs/ca_obj_array.rb +20 -135
  217. data/yard-stubs/ca_obj_bitarray.rb +1 -8
  218. data/yard-stubs/ca_obj_bitfield.rb +6 -2
  219. data/yard-stubs/ca_obj_byte_swap.rb +21 -7
  220. data/yard-stubs/ca_obj_fake.rb +3 -1
  221. data/yard-stubs/ca_obj_farray.rb +1 -1
  222. data/yard-stubs/ca_obj_field.rb +8 -6
  223. data/yard-stubs/ca_obj_refer.rb +10 -5
  224. data/yard-stubs/ca_obj_roll.rb +7 -6
  225. data/yard-stubs/ca_obj_shift.rb +2 -3
  226. data/yard-stubs/ca_obj_stride.rb +5 -7
  227. data/yard-stubs/ca_obj_tile.rb +1 -1
  228. data/yard-stubs/ca_obj_time.rb +43 -0
  229. data/yard-stubs/ca_obj_transpose.rb +1 -1
  230. data/yard-stubs/ca_obj_window.rb +28 -16
  231. data/yard-stubs/carray_access.rb +55 -6
  232. data/yard-stubs/carray_attribute.rb +26 -38
  233. data/yard-stubs/carray_cast.rb +121 -162
  234. data/yard-stubs/carray_class.rb +3 -4
  235. data/yard-stubs/carray_conversion.rb +6 -7
  236. data/yard-stubs/carray_copy.rb +2 -1
  237. data/yard-stubs/carray_count.rb +10 -5
  238. data/yard-stubs/carray_element.rb +4 -3
  239. data/yard-stubs/carray_limits.rb +100 -0
  240. data/yard-stubs/carray_loop.rb +0 -20
  241. data/yard-stubs/carray_mask.rb +59 -41
  242. data/yard-stubs/carray_math.rb +162 -100
  243. data/yard-stubs/carray_mathfunc.rb +415 -3
  244. data/yard-stubs/carray_median_percentile.rb +29 -11
  245. data/yard-stubs/carray_memory_view.rb +2 -2
  246. data/yard-stubs/carray_order.rb +72 -33
  247. data/yard-stubs/carray_random.rb +6 -6
  248. data/yard-stubs/carray_reduce.rb +353 -0
  249. data/yard-stubs/carray_rng.rb +92 -0
  250. data/yard-stubs/carray_scatter.rb +12 -3
  251. data/yard-stubs/carray_slab.rb +7 -4
  252. data/yard-stubs/carray_sort.rb +7 -6
  253. data/yard-stubs/carray_test.rb +18 -5
  254. data/yard-stubs/carray_undef.rb +44 -5
  255. data/yard-stubs/ruby_carray.rb +75 -40
  256. metadata +63 -25
  257. data/CHANGELOG.v1.md +0 -126
  258. data/ext/carray_build_flags.h +0 -3
  259. data/ext/carray_config.h +0 -28
  260. data/ext/carray_data_type.c +0 -90
  261. data/ext/carray_kernels_bincmp.c +0 -6457
  262. data/ext/carray_kernels_binop.c +0 -31534
  263. data/ext/carray_kernels_init.c +0 -1734
  264. data/ext/carray_kernels_moncmp.c +0 -2104
  265. data/ext/carray_kernels_monop.c +0 -25387
  266. data/ext/carray_kernels_reduce_aggregate.c +0 -27545
  267. data/ext/carray_kernels_reduce_boolean.c +0 -1924
  268. data/ext/carray_kernels_reduce_cumulative.c +0 -11646
  269. data/ext/carray_kernels_reduce_extreme.c +0 -21631
  270. data/ext/carray_kernels_reduce_variance.c +0 -5981
  271. data/ext/carray_kernels_scan.c +0 -4302
  272. data/ext/carray_kernels_search.c +0 -37776
  273. data/ext/carray_kernels_sort.c +0 -10814
  274. data/ext/carray_kernels_triop.c +0 -1864
  275. data/lib/carray/construct.rb +0 -360
  276. data/lib/carray/data_type_extension.rb +0 -261
  277. data/lib/carray/data_type_limits.rb +0 -91
data/ext/ca_obj_window.c CHANGED
@@ -30,7 +30,6 @@
30
30
  #include "carray.h"
31
31
  #include "ca_composite_dispatch.h"
32
32
  #include "ca_obj_face.h" /* CA_FACE_LIFT_IF_FACE, used by rb_ca_window */
33
- #include "carray_internal.h" /* ca_axis_view_attach_owned */
34
33
 
35
34
  /* should not be static variable as used by CAIteratorWindow */
36
35
 
@@ -114,7 +113,7 @@ const rb_data_type_t cawindow_data_type = {
114
113
  double-free it. */
115
114
  const rb_data_type_t cawindow_mask_data_type = {
116
115
  .parent = &cawindow_data_type,
117
- .wrap_struct_name = "CAWindowMask",
116
+ .wrap_struct_name = "CAWindow::Mask",
118
117
  .function = {
119
118
  .dmark = ca_mark,
120
119
  .dfree = ca_free_nop,
@@ -124,7 +123,7 @@ const rb_data_type_t cawindow_mask_data_type = {
124
123
  .flags = RUBY_TYPED_FREE_IMMEDIATELY
125
124
  };
126
125
 
127
- int8_t CA_OBJ_WINDOW;
126
+ int16_t CA_OBJ_WINDOW;
128
127
 
129
128
  VALUE rb_cCAWindow;
130
129
  VALUE rb_cCAWindowMask;
@@ -275,10 +274,11 @@ static int
275
274
  ca_window_func_fold_stride (void *ap, ca_fold_t *f, void **next_parent)
276
275
  {
277
276
  CAWindow *w = (CAWindow *) ap;
278
- ca_window_mask_current(w);
279
- /* A write folded through to a stand-in would bypass the settle in this
280
- window's write slots. */
281
- if ( ca_window_mask_reads_standin(w) ) {
277
+ /* A mask window never folds. A write folded through to a stand-in would
278
+ bypass the settle in this window's write slots, and answering by what
279
+ the window reads now would change when a write settles: a view attached
280
+ over this window would detach a root it never attached. */
281
+ if ( w->mask_owner ) {
282
282
  return 0;
283
283
  }
284
284
  ca_size_t synth_strides[CA_RANK_MAX];
@@ -332,6 +332,7 @@ static void ca_window_func_xfer_index (void *ap, ca_size_t *idx, void *data, int
332
332
  transposed / sub-sampled leaf) fall back to per-cell delivery (correct,
333
333
  no whole-view attach). data is contiguous (semantics b). The wiring
334
334
  guards ndim == window ndim. window.bytes == parent.bytes (no reinterpret). */
335
+ /* recursion: re-enters at most once, once the parent is attached */
335
336
  static void
336
337
  ca_window_func_xfer_stride (void *ap, ca_size_t *starts, ca_size_t *counts,
337
338
  ca_size_t *strides, void *data, int dir)
@@ -418,9 +419,11 @@ ca_window_func_xfer_stride (void *ap, ca_size_t *starts, ca_size_t *counts,
418
419
  if ( parent->ptr ) {
419
420
  ca_window_func_xfer_stride(ap, starts, counts, strides, data, dir);
420
421
  if ( dir == CA_XFER_PUT ) {
421
- ca_sync(parent);
422
+ ca_sync_detach(parent);
423
+ }
424
+ else {
425
+ ca_detach(parent);
422
426
  }
423
- ca_detach(parent);
424
427
  return;
425
428
  }
426
429
  ca_detach(parent);
@@ -701,7 +704,8 @@ ca_window_setup (CAWindow *ca, CArray *parent,
701
704
  /* Under "ruby" or "strict" an index outside the parent raises. The
702
705
  parent's shape is fixed, so a window that reaches outside it would raise
703
706
  on every whole read or write, and a write would have changed the cells
704
- before the one that raised. It is refused here instead. */
707
+ before the one that raised. It is refused here instead. Under
708
+ "nearest" an axis with no cells has no edge to replicate. */
705
709
  for (i=0; i<ndim; i++) {
706
710
  ca_size_t lo, hi, size = dim[i];
707
711
  if ( count[i] == 0 ) {
@@ -717,6 +721,9 @@ ca_window_setup (CAWindow *ca, CArray *parent,
717
721
  if ( lo < -size ) ca_index_out_of_range(lo, size, "index");
718
722
  if ( hi >= size ) ca_index_out_of_range(hi, size, "index");
719
723
  }
724
+ else if ( bounds[i] == CA_BOUNDS_NEAREST && size == 0 ) {
725
+ ca_index_out_of_range(lo, size, "index");
726
+ }
720
727
  }
721
728
 
722
729
  /* ca == NULL asks for the checks above only, so that a constructor can
@@ -1114,12 +1121,12 @@ ca_window_func_allocate (void *ap)
1114
1121
  ca->ptr = ca_alloc_cells((CArray *) ca);
1115
1122
  return;
1116
1123
  }
1117
- ca_attach(ca->parent);
1118
1124
  if ( ca->embed_alias_eligible ) {
1125
+ ca_attach(ca->parent);
1119
1126
  ca->ptr = ca_window_alias_ptr(ca);
1120
1127
  return;
1121
1128
  }
1122
- ca->ptr = ca_alloc_cells((CArray *) ca);
1129
+ ca->ptr = ca_alloc_cells_then_attach((CArray *) ca, 1, &ca->parent);
1123
1130
  }
1124
1131
 
1125
1132
  /* The engine paths below emit a per-axis descriptor (ca_window_describe_axes)
@@ -1139,7 +1146,6 @@ ca_window_func_attach (void *ap)
1139
1146
  ca_axis_view_attach_owned(ca);
1140
1147
  return;
1141
1148
  }
1142
- ca_attach(ca->parent);
1143
1149
  if ( ca->embed_alias_eligible ) {
1144
1150
  /* Alias path: inner axes full + interior, so the embedded region is a
1145
1151
  contiguous run of parent storage. Skip malloc/memcpy and point
@@ -1147,10 +1153,13 @@ ca_window_func_attach (void *ap)
1147
1153
  CAREFUL: sync and detach must agree with this — sync has nothing to
1148
1154
  scatter back (the writes already landed in the parent) and detach must
1149
1155
  not xfree a pointer it does not own. */
1156
+ ca_attach(ca->parent);
1150
1157
  ca->ptr = ca_window_alias_ptr(ca);
1151
- } else if ( ca->embed_eligible ) {
1152
- /* Embed path: allocate, then 1 fill + 1 strided memcpy. */
1153
- ca->ptr = ca_alloc_cells((CArray *) ca);
1158
+ return;
1159
+ }
1160
+ ca->ptr = ca_alloc_cells_then_attach((CArray *) ca, 1, &ca->parent);
1161
+ if ( ca->embed_eligible ) {
1162
+ /* Embed path: 1 fill + 1 strided memcpy. */
1154
1163
  ca_window_attach_embed(ca, ca->ptr);
1155
1164
  } else {
1156
1165
  /* Fallback: PERIODIC / REFLECT / NEAREST / RUBY / STRICT go through
@@ -1158,8 +1167,8 @@ ca_window_func_attach (void *ap)
1158
1167
  ca_axis_desc_t desc[CA_RANK_MAX];
1159
1168
  ca_size_t pdims[CA_RANK_MAX];
1160
1169
  ca_window_describe_axes(ca, desc, pdims);
1161
- ca->ptr = ca_axis_dispatch_attach(ca->parent, pdims, desc, ca->ndim,
1162
- ca->bytes, ca->elements, ca->fill);
1170
+ ca_axis_dispatch_gather(ca->parent, pdims, desc, ca->ndim,
1171
+ ca->bytes, ca->elements, ca->fill, ca->ptr);
1163
1172
  }
1164
1173
  }
1165
1174
 
@@ -1266,9 +1275,11 @@ ca_window_func_xfer_all (void *ap, void *data, int dir)
1266
1275
  ca_attach(ca->parent);
1267
1276
  ca_window_func_run_fast_path(ca, (char *) data, dir);
1268
1277
  if ( dir == CA_XFER_PUT ) {
1269
- ca_sync(ca->parent);
1278
+ ca_sync_detach(ca->parent);
1279
+ }
1280
+ else {
1281
+ ca_detach(ca->parent);
1270
1282
  }
1271
- ca_detach(ca->parent);
1272
1283
  return;
1273
1284
  }
1274
1285
  /* Second chance: ca_attach_is_alias reads the leaf view's own strides, so
@@ -1348,6 +1359,7 @@ ca_window_func_xfer_all (void *ap, void *data, int dir)
1348
1359
  fill_data, which continues compose-fold (covering
1349
1360
  CAStride-of-CAWindow-of-CAStride chains) and runs the merge + tight-fill
1350
1361
  inner loop. PERIODIC / REFLECT windows fall through to the engine path. */
1362
+ /* recursion: fills a stride view over the root, an entity */
1351
1363
  static void
1352
1364
  ca_window_func_fill_data (void *ap, void *ptr)
1353
1365
  {
@@ -1481,8 +1493,8 @@ ca_window_func_create_mask (void *ap)
1481
1493
  m->obj_type = ca->obj_type;
1482
1494
  m->mask_owner = (CArray *) ca;
1483
1495
  if ( pmask == ca->mask_standin ) {
1484
- /* writes inside an attach window reach the stand-in through the
1485
- sync, where they can give way to the parent's mask */
1496
+ /* writes made while this view is attached reach the stand-in
1497
+ through the sync, where they can give way to the parent's mask */
1486
1498
  m->embed_alias_eligible = 0;
1487
1499
  }
1488
1500
  ca->mask = (CArray *) m;
@@ -1615,7 +1627,7 @@ ca_window_describe_axes (void *ap, ca_axis_desc_t *out,
1615
1627
  /* ------------------------------------------------------------------- */
1616
1628
 
1617
1629
  VALUE
1618
- rb_ca_window_new (VALUE cary,
1630
+ rb_ca_window_new (volatile VALUE cary,
1619
1631
  ca_size_t *start, ca_size_t *count, int8_t bounds, char *fill)
1620
1632
  {
1621
1633
  /* Scalar-bounds wrapper for the Ruby surface: fan the single policy out
@@ -1626,7 +1638,7 @@ rb_ca_window_new (VALUE cary,
1626
1638
  uint8_t bounds_arr[CA_RANK_MAX];
1627
1639
  int8_t i;
1628
1640
  rb_check_carray_object(cary);
1629
- TypedData_Get_Struct(cary, CArray, &carray_data_type, parent);
1641
+ GetCArray(cary, parent);
1630
1642
  for (i = 0; i < parent->ndim; i++) bounds_arr[i] = (uint8_t) bounds;
1631
1643
  ca = ca_window_new(parent, start, count, bounds_arr, fill);
1632
1644
  obj = ca_wrap_struct(ca);
@@ -1635,9 +1647,12 @@ rb_ca_window_new (VALUE cary,
1635
1647
  }
1636
1648
 
1637
1649
  VALUE
1638
- rb_ca_window (int argc, VALUE *argv, VALUE self)
1650
+ rb_ca_window (int argc, VALUE *argv, volatile VALUE self)
1639
1651
  {
1640
- volatile VALUE obj, ropt, rfval = CA_UNSPECIFIED, rbounds = Qnil, rcs;
1652
+ volatile VALUE obj, ropt;
1653
+ VALUE rfval = CA_UNSPECIFIED;
1654
+ VALUE rbounds_arg = Qnil;
1655
+ volatile VALUE rbounds, rcs;
1641
1656
  CArray *ca;
1642
1657
  CScalar *cs;
1643
1658
  ca_size_t start[CA_RANK_MAX];
@@ -1647,10 +1662,11 @@ rb_ca_window (int argc, VALUE *argv, VALUE self)
1647
1662
  char *cbounds;
1648
1663
  ca_size_t i;
1649
1664
 
1650
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
1665
+ GetCArray(self, ca);
1651
1666
 
1652
1667
  ropt = rb_pop_options(&argc, &argv);
1653
- rb_scan_options(ropt, "bounds,fill_value", &rbounds, &rfval);
1668
+ rb_scan_options(ropt, "bounds,fill_value", &rbounds_arg, &rfval);
1669
+ rbounds = rbounds_arg;
1654
1670
 
1655
1671
  if ( argc != ca->ndim ) {
1656
1672
  rb_raise(rb_eArgError, "ndim mismatch");
@@ -1692,17 +1708,13 @@ rb_ca_window (int argc, VALUE *argv, VALUE self)
1692
1708
  }
1693
1709
 
1694
1710
  if ( ! NIL_P(rbounds) ) {
1695
- /* A Symbol says the same thing as the String, and is what the window
1696
- iterator (CArray#windows) is given -- accept both so the two spellings
1697
- of one policy do not diverge. */
1698
- if ( SYMBOL_P(rbounds) ) {
1699
- rbounds = rb_sym2str(rbounds);
1700
- }
1701
- if ( ! RB_TYPE_P(rbounds, T_STRING) ) {
1711
+ /* A Symbol, as CArray#windows takes its bounds:. */
1712
+ if ( ! SYMBOL_P(rbounds) ) {
1702
1713
  rb_raise(rb_eTypeError,
1703
- "window: bounds: must be a Symbol or a String (got %s)",
1704
- rb_obj_classname(rbounds));
1714
+ "window: bounds: must be a Symbol (got %"PRIsVALUE")",
1715
+ rb_inspect(rbounds));
1705
1716
  }
1717
+ rbounds = rb_sym2str(rbounds);
1706
1718
  cbounds = StringValueCStr(rbounds);
1707
1719
  if ( ! strcmp(cbounds, "ruby") ) {
1708
1720
  bounds = CA_BOUNDS_RUBY;
@@ -1713,28 +1725,14 @@ rb_ca_window (int argc, VALUE *argv, VALUE self)
1713
1725
  else if ( ! strcmp(cbounds, "nearest") ) {
1714
1726
  bounds = CA_BOUNDS_NEAREST;
1715
1727
  }
1716
- else if ( ! strcmp(cbounds, "periodic") ) {
1717
- rb_raise(rb_eArgError,
1718
- "bounds=>'periodic' removed in 3.0; "
1719
- "use CArray#roll(...) for cyclic shift "
1720
- "(returns a CARoll view)");
1721
- }
1722
- else if ( ! strcmp(cbounds, "reflect") ) {
1723
- rb_raise(rb_eArgError,
1724
- "bounds=>'reflect' removed in 3.0; "
1725
- "there is no view-based alternative");
1726
- }
1727
- else if ( ! strcmp(cbounds, "mask") ) {
1728
- rb_warn("CAWindow option :bounds=>\"mask\" will be obsolete");
1729
- rb_warn("use ca.window(..., fill_value: UNDEF)");
1730
- bounds = CA_BOUNDS_MASK;
1731
- }
1732
1728
  else if ( ! strcmp(cbounds, "fill") ) {
1733
1729
  bounds = ( rfval == CA_UNDEF ) ? CA_BOUNDS_MASK : CA_BOUNDS_FILL;
1734
1730
  }
1735
1731
  else {
1736
1732
  rb_raise(rb_eArgError,
1737
- "window: unknown bounds: '%s'", cbounds);
1733
+ "window: unknown bounds: '%s' (use :fill, :nearest, :ruby "
1734
+ "or :strict; to mask the cells outside, use fill_value: UNDEF)",
1735
+ cbounds);
1738
1736
  }
1739
1737
  /* A fill value says what the cells outside the array are; the other
1740
1738
  policies say something else about them. */
@@ -1743,12 +1741,6 @@ rb_ca_window (int argc, VALUE *argv, VALUE self)
1743
1741
  rb_raise(rb_eArgError,
1744
1742
  "window: fill_value: is for bounds: :fill, not :%s", cbounds);
1745
1743
  }
1746
- if ( rfval != CA_UNSPECIFIED && rfval != CA_UNDEF
1747
- && bounds == CA_BOUNDS_MASK ) {
1748
- rb_raise(rb_eArgError,
1749
- "window: fill_value: %+"PRIsVALUE" conflicts with bounds: :mask "
1750
- "(use fill_value: UNDEF to mask the cells outside)", rfval);
1751
- }
1752
1744
  }
1753
1745
 
1754
1746
  obj = rb_ca_window_new(self, start, count, bounds, fill);
@@ -1767,7 +1759,7 @@ rb_ca_window_s_allocate (VALUE klass)
1767
1759
  }
1768
1760
 
1769
1761
  static VALUE
1770
- rb_ca_window_initialize_copy (VALUE self, VALUE other)
1762
+ rb_ca_window_initialize_copy (volatile VALUE self, volatile VALUE other)
1771
1763
  {
1772
1764
  CAWindow *ca, *cs;
1773
1765
 
@@ -1791,13 +1783,14 @@ rb_ca_window_initialize_copy (VALUE self, VALUE other)
1791
1783
  }
1792
1784
 
1793
1785
  static VALUE
1794
- rb_ca_window_idx2addr0 (int argc, VALUE *argv, VALUE self)
1786
+ rb_ca_window_idx2addr0 (int argc, VALUE *argv, volatile VALUE self)
1795
1787
  {
1796
1788
  CAWindow *cw;
1797
1789
  ca_size_t addr;
1798
1790
  int8_t i;
1799
1791
  ca_size_t idxi;
1800
1792
 
1793
+ rb_reject_options(rb_pop_options(&argc, &argv));
1801
1794
  TypedData_Get_Struct(self, CAWindow, &cawindow_data_type, cw);
1802
1795
 
1803
1796
  if ( argc != cw->ndim ) {
@@ -1821,7 +1814,7 @@ rb_ca_window_idx2addr0 (int argc, VALUE *argv, VALUE self)
1821
1814
  }
1822
1815
 
1823
1816
  static VALUE
1824
- rb_ca_window_addr2addr0 (VALUE self, VALUE raddr)
1817
+ rb_ca_window_addr2addr0 (volatile VALUE self, VALUE raddr)
1825
1818
  {
1826
1819
  CAWindow *cw;
1827
1820
  ca_size_t addr = NUM2SIZE(raddr);
@@ -1847,69 +1840,66 @@ rb_ca_window_addr2addr0 (VALUE self, VALUE raddr)
1847
1840
 
1848
1841
 
1849
1842
  static VALUE
1850
- rb_ca_window_set_fill_value (VALUE self, VALUE rfval)
1843
+ rb_ca_window_get_fill_value (volatile VALUE self)
1851
1844
  {
1852
1845
  CAWindow *cw;
1853
1846
  TypedData_Get_Struct(self, CAWindow, &cawindow_data_type, cw);
1854
- rb_ca_obj2ptr(self, rfval, cw->fill);
1855
- return Qnil;
1847
+ return rb_ca_ptr2obj(self, cw->fill);
1856
1848
  }
1857
1849
 
1850
+ /* The name of a boundary rule, as CArray#window takes it. */
1858
1851
  static VALUE
1859
- rb_ca_window_get_fill_value (VALUE self)
1852
+ ca_window_bounds_symbol (int8_t bounds)
1860
1853
  {
1861
- CAWindow *cw;
1862
- TypedData_Get_Struct(self, CAWindow, &cawindow_data_type, cw);
1863
- return rb_ca_ptr2obj(self, cw->fill);
1854
+ const char *name;
1855
+ switch ( bounds ) {
1856
+ case CA_BOUNDS_RUBY: name = "ruby"; break;
1857
+ case CA_BOUNDS_STRICT: name = "strict"; break;
1858
+ case CA_BOUNDS_NEAREST: name = "nearest"; break;
1859
+ case CA_BOUNDS_PERIODIC: name = "periodic"; break;
1860
+ case CA_BOUNDS_REFLECT: name = "reflect"; break;
1861
+ case CA_BOUNDS_FILL: name = "fill"; break;
1862
+ case CA_BOUNDS_MASK: name = "mask"; break;
1863
+ default: name = "unknown"; break;
1864
+ }
1865
+ return ID2SYM(rb_intern(name));
1864
1866
  }
1865
1867
 
1866
1868
  static VALUE
1867
- rb_ca_window_get_bounds (VALUE self)
1869
+ rb_ca_window_get_bounds (volatile VALUE self)
1868
1870
  {
1869
- /* bounds is per-axis, but the Ruby surface always constructs with a single
1870
- scalar policy fanned out across all axes, so axis 0 reproduces the value
1871
- that was passed in. */
1871
+ /* bounds is per-axis, but CArray#window fans one rule out across all
1872
+ axes, so axis 0 reproduces the rule that was passed in. */
1872
1873
  CAWindow *cw;
1873
1874
  TypedData_Get_Struct(self, CAWindow, &cawindow_data_type, cw);
1874
- return SIZE2NUM(cw->bounds[0]);
1875
+ return ca_window_bounds_symbol(cw->bounds[0]);
1875
1876
  }
1876
1877
 
1877
1878
  /* The boundary rule on each axis, one Symbol per axis. `bounds` answers
1878
1879
  for axis 0 only, which is all CArray#window sets; a shift with `roll:`
1879
1880
  on some axes sets them one by one. */
1880
1881
  static VALUE
1881
- rb_ca_window_axis_bounds (VALUE self)
1882
+ rb_ca_window_axis_bounds (volatile VALUE self)
1882
1883
  {
1883
1884
  volatile VALUE ary;
1884
1885
  CAWindow *cw;
1885
- const char *name;
1886
1886
  int8_t i;
1887
1887
  TypedData_Get_Struct(self, CAWindow, &cawindow_data_type, cw);
1888
- ary = rb_ary_new2(cw->ndim);
1888
+ ary = rb_ary_new_capa(cw->ndim);
1889
1889
  for (i=0; i<cw->ndim; i++) {
1890
- switch ( cw->bounds[i] ) {
1891
- case CA_BOUNDS_RUBY: name = "ruby"; break;
1892
- case CA_BOUNDS_STRICT: name = "strict"; break;
1893
- case CA_BOUNDS_NEAREST: name = "nearest"; break;
1894
- case CA_BOUNDS_PERIODIC: name = "periodic"; break;
1895
- case CA_BOUNDS_REFLECT: name = "reflect"; break;
1896
- case CA_BOUNDS_FILL: name = "fill"; break;
1897
- case CA_BOUNDS_MASK: name = "mask"; break;
1898
- default: name = "unknown"; break;
1899
- }
1900
- rb_ary_store(ary, i, ID2SYM(rb_intern(name)));
1890
+ rb_ary_store(ary, i, ca_window_bounds_symbol(cw->bounds[i]));
1901
1891
  }
1902
1892
  return ary;
1903
1893
  }
1904
1894
 
1905
1895
  #define rb_cw_get_attr_ary(name) \
1906
- rb_cw_## name (VALUE self) \
1896
+ rb_cw_## name (volatile VALUE self) \
1907
1897
  { \
1908
1898
  volatile VALUE ary; \
1909
1899
  CAWindow *cw; \
1910
1900
  int8_t i; \
1911
1901
  TypedData_Get_Struct(self, CAWindow, &cawindow_data_type, cw); \
1912
- ary = rb_ary_new2(cw->ndim); \
1902
+ ary = rb_ary_new_capa(cw->ndim); \
1913
1903
  for (i=0; i<cw->ndim; i++) { \
1914
1904
  rb_ary_store(ary, i, SIZE2NUM(cw->name[i])); \
1915
1905
  } \
@@ -1928,15 +1918,15 @@ static VALUE rb_cw_get_attr_ary(size0);
1928
1918
  `extconf.rb --enable-dev-build` or `CARRAY_DEV=1 rake build_ext`.
1929
1919
 
1930
1920
  Polymorphic over CAWindow / CAShift: both share the same C struct layout
1931
- (CAShift is a typedef of CAWindow) but use distinct TypedData types.
1932
- DATA_PTR is safe here because Ruby method dispatch has already restricted
1933
- self to one of those two classes. */
1921
+ (CAShift is a typedef of CAWindow), and the data type of CAShift has the
1922
+ data type of CAWindow as parent, so the get below accepts both. */
1934
1923
  VALUE
1935
- rb_ca_window_embed_descriptor (VALUE self)
1924
+ rb_ca_window_embed_descriptor (volatile VALUE self)
1936
1925
  {
1937
- CAWindow *ca = (CAWindow *) DATA_PTR(self);
1926
+ CAWindow *ca;
1938
1927
  VALUE hash, ps_ary, ec_ary, oo_ary;
1939
1928
  int8_t k;
1929
+ TypedData_Get_Struct(self, CAWindow, &cawindow_data_type, ca);
1940
1930
 
1941
1931
  ps_ary = rb_ary_new_capa(ca->ndim);
1942
1932
  ec_ary = rb_ary_new_capa(ca->ndim);
@@ -1968,7 +1958,7 @@ Init_ca_obj_window (void)
1968
1958
  {
1969
1959
 
1970
1960
  rb_cCAWindow = rb_define_class("CAWindow", rb_cCAView);
1971
- rb_cCAWindowMask = rb_define_class("CAWindowMask", rb_cCAWindow);
1961
+ rb_cCAWindowMask = rb_define_class_under(rb_cCAWindow, "Mask", rb_cCAWindow);
1972
1962
 
1973
1963
  /* Pool framework: seven ndim-sized tail fields live in one _pool buffer
1974
1964
  (fill stays separate, bytes-sized). Set on the global ca_window_func
@@ -1983,7 +1973,6 @@ Init_ca_obj_window (void)
1983
1973
  rb_cCAWindowMask,
1984
1974
  &cawindow_mask_data_type, &ca_window_func, sizeof(ca_window_func));
1985
1975
  ca_register_cell_moving_view(CA_OBJ_WINDOW);
1986
- rb_define_const(rb_cObject, "CA_OBJ_WINDOW", INT2NUM(CA_OBJ_WINDOW));
1987
1976
 
1988
1977
  rb_define_method(rb_cCArray, "window", rb_ca_window, -1);
1989
1978
 
@@ -1996,7 +1985,6 @@ Init_ca_obj_window (void)
1996
1985
  rb_define_method(rb_cCAWindow, "addr2addr0", rb_ca_window_addr2addr0, 1);
1997
1986
 
1998
1987
  rb_define_method(rb_cCAWindow, "fill_value", rb_ca_window_get_fill_value, 0);
1999
- rb_define_method(rb_cCAWindow, "fill_value=", rb_ca_window_set_fill_value, 1);
2000
1988
 
2001
1989
  rb_define_method(rb_cCAWindow, "bounds", rb_ca_window_get_bounds, 0);
2002
1990
 
data/ext/ca_op_cmplx64.h CHANGED
@@ -3,6 +3,10 @@
3
3
  ca_op_cmplx64.h -- the cmplx64 products and quotients, computed in
4
4
  double and rounded once
5
5
 
6
+ This header is internal to carray and carries no contract. It is not
7
+ installed; it ships in the gem's ext/ directory only because carray is
8
+ built from it there.
9
+
6
10
  Used by:
7
11
  - ext/carray_kernels_binop.c and ext/carray_kernels_monop.c
8
12
  (generated from ext/mkkernel.rb): the `*`, `/`, `rcp` and