carray 3.0.3 → 3.0.4

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 (212) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +264 -0
  3. data/README.md +3 -2
  4. data/carray.gemspec +1 -1
  5. data/ext/ca_axis_descriptor.h +27 -24
  6. data/ext/ca_axis_dispatch.c +1 -6
  7. data/ext/ca_axis_group.c +27 -27
  8. data/ext/ca_binop_dispatch.c +1 -29
  9. data/ext/ca_binop_dispatch.h +0 -1
  10. data/ext/ca_categorical_iterator.c +205 -134
  11. data/ext/ca_compare.c +7 -18
  12. data/ext/ca_group_iter.c +16 -17
  13. data/ext/ca_kernel_iterator.c +1234 -1994
  14. data/ext/ca_kernel_iterator.h +391 -437
  15. data/ext/ca_monop_dispatch.c +82 -59
  16. data/ext/ca_monop_dispatch.h +1 -0
  17. data/ext/ca_obj_array.c +96 -39
  18. data/ext/ca_obj_bincmp.c +24 -21
  19. data/ext/ca_obj_binop.c +15 -26
  20. data/ext/ca_obj_bitarray.c +3 -2
  21. data/ext/ca_obj_bitfield.c +5 -6
  22. data/ext/ca_obj_block.c +18 -9
  23. data/ext/ca_obj_byte_swap.c +5 -6
  24. data/ext/ca_obj_const_string.c +173 -19
  25. data/ext/ca_obj_face.c +238 -57
  26. data/ext/ca_obj_face.h +19 -0
  27. data/ext/ca_obj_fake.c +15 -29
  28. data/ext/ca_obj_farray.c +6 -3
  29. data/ext/ca_obj_field.c +17 -5
  30. data/ext/ca_obj_fixlen_string.c +2 -3
  31. data/ext/ca_obj_grid.c +406 -132
  32. data/ext/ca_obj_meld.c +172 -34
  33. data/ext/ca_obj_moncmp.c +23 -8
  34. data/ext/ca_obj_monop.c +67 -57
  35. data/ext/ca_obj_object.c +157 -51
  36. data/ext/ca_obj_record.c +12 -7
  37. data/ext/ca_obj_reduce.c +13 -8
  38. data/ext/ca_obj_refer.c +25 -27
  39. data/ext/ca_obj_remap.c +30 -9
  40. data/ext/ca_obj_repeat.c +9 -10
  41. data/ext/ca_obj_roll.c +6 -5
  42. data/ext/ca_obj_select.c +14 -9
  43. data/ext/ca_obj_select_axis.c +15 -47
  44. data/ext/ca_obj_shift.c +11 -1
  45. data/ext/ca_obj_stack.c +179 -34
  46. data/ext/ca_obj_stride.c +162 -115
  47. data/ext/ca_obj_string.c +71 -4
  48. data/ext/ca_obj_tile.c +6 -5
  49. data/ext/ca_obj_time.c +22 -6
  50. data/ext/ca_obj_timedelta.c +22 -6
  51. data/ext/ca_obj_transpose.c +5 -3
  52. data/ext/ca_obj_triop.c +23 -32
  53. data/ext/ca_obj_window.c +190 -26
  54. data/ext/ca_sweep_engine.c +2 -2
  55. data/ext/caframe_csv_reader.c +80 -1
  56. data/ext/carray.h +181 -75
  57. data/ext/carray_access.c +184 -96
  58. data/ext/carray_address_basis.c +343 -87
  59. data/ext/carray_attribute.c +89 -6
  60. data/ext/carray_bincount.c +10 -8
  61. data/ext/carray_broadcast.c +13 -8
  62. data/ext/carray_build_flags.h +3 -0
  63. data/ext/carray_call_cfunc.c +108 -0
  64. data/ext/carray_cast.c +142 -24
  65. data/ext/carray_cast_func.rb +46 -6
  66. data/ext/carray_class.c +4 -3
  67. data/ext/carray_config.h +28 -0
  68. data/ext/carray_conversion.c +16 -7
  69. data/ext/carray_copy.c +51 -14
  70. data/ext/carray_core.c +147 -55
  71. data/ext/carray_count.c +50 -20
  72. data/ext/carray_element.c +76 -33
  73. data/ext/carray_factorize.c +118 -64
  74. data/ext/carray_generate.c +191 -50
  75. data/ext/carray_histogram.c +62 -17
  76. data/ext/carray_hold.c +12 -15
  77. data/ext/carray_index_classifier.c +388 -176
  78. data/ext/carray_internal.h +336 -29
  79. data/ext/carray_kernels_bincmp.c +4453 -0
  80. data/ext/carray_kernels_binop.c +11368 -0
  81. data/ext/carray_kernels_init.c +1734 -0
  82. data/ext/carray_kernels_moncmp.c +2104 -0
  83. data/ext/carray_kernels_monop.c +18369 -0
  84. data/ext/carray_kernels_reduce_aggregate.c +23818 -0
  85. data/ext/carray_kernels_reduce_boolean.c +406 -0
  86. data/ext/carray_kernels_reduce_cumulative.c +10086 -0
  87. data/ext/carray_kernels_reduce_extreme.c +17634 -0
  88. data/ext/carray_kernels_reduce_variance.c +3849 -0
  89. data/ext/carray_kernels_scan.c +4302 -0
  90. data/ext/carray_kernels_search.c +33829 -0
  91. data/ext/carray_kernels_sort.c +10906 -0
  92. data/ext/carray_kernels_triop.c +1864 -0
  93. data/ext/carray_key_windows.c +216 -0
  94. data/ext/carray_lazy.c +170 -111
  95. data/ext/carray_mask.c +292 -72
  96. data/ext/carray_median_percentile.c +82 -28
  97. data/ext/carray_memory_view.c +669 -561
  98. data/ext/carray_operator.c +124 -47
  99. data/ext/carray_order.c +384 -76
  100. data/ext/carray_partition.c +28 -27
  101. data/ext/carray_random.c +67 -13
  102. data/ext/carray_round.c +273 -0
  103. data/ext/carray_scatter.c +63 -38
  104. data/ext/carray_segment.c +3 -3
  105. data/ext/carray_slab.c +91 -28
  106. data/ext/carray_sort.c +35 -35
  107. data/ext/carray_struct.c +19 -18
  108. data/ext/carray_test.c +26 -5
  109. data/ext/carray_undef.c +4 -0
  110. data/ext/carray_utils.c +246 -45
  111. data/ext/mk_call_cfunc.rb +19 -2
  112. data/ext/mkkernel.rb +198 -240
  113. data/ext/ruby_carray.c +10 -4
  114. data/ext/version.h +4 -4
  115. data/lib/carray/attribute.rb +126 -22
  116. data/lib/carray/autoload_carray.rb +8 -31
  117. data/lib/carray/autoload_method_extension.rb +14 -5
  118. data/lib/carray/axis_group.rb +255 -106
  119. data/lib/carray/basics.rb +78 -10
  120. data/lib/carray/bincount_nd.rb +12 -2
  121. data/lib/carray/block_iterator.rb +126 -23
  122. data/lib/carray/boolean_reduce.rb +17 -17
  123. data/lib/carray/categorical.rb +165 -43
  124. data/lib/carray/categorical_iterator.rb +130 -27
  125. data/lib/carray/complex.rb +5 -5
  126. data/lib/carray/conditional.rb +67 -18
  127. data/lib/carray/const_string.rb +14 -5
  128. data/lib/carray/construct.rb +15 -11
  129. data/lib/carray/data_type_extension.rb +1 -0
  130. data/lib/carray/distance_limit.rb +77 -0
  131. data/lib/carray/fixlen_string.rb +7 -1
  132. data/lib/carray/frame/column_verbs.rb +70 -0
  133. data/lib/carray/frame/convert.rb +69 -0
  134. data/lib/carray/frame/csv_parser.rb +111 -17
  135. data/lib/carray/frame/describe.rb +3 -2
  136. data/lib/carray/frame/frame.rb +246 -21
  137. data/lib/carray/frame/group.rb +510 -95
  138. data/lib/carray/frame/io.rb +115 -28
  139. data/lib/carray/frame/join.rb +312 -51
  140. data/lib/carray/frame/records.rb +83 -7
  141. data/lib/carray/frame/reshape.rb +42 -35
  142. data/lib/carray/frame/sort.rb +7 -19
  143. data/lib/carray/frame/verbs.rb +188 -48
  144. data/lib/carray/frame/windows.rb +117 -0
  145. data/lib/carray/frame.rb +2 -0
  146. data/lib/carray/fuse_source.rb +11 -4
  147. data/lib/carray/fusion.rb +40 -16
  148. data/lib/carray/histogram.rb +6 -1
  149. data/lib/carray/inspect.rb +31 -8
  150. data/lib/carray/iterator.rb +85 -7
  151. data/lib/carray/key_windows.rb +620 -0
  152. data/lib/carray/lazy.rb +182 -183
  153. data/lib/carray/mask_gap_fill.rb +63 -57
  154. data/lib/carray/meld_reduce.rb +12 -14
  155. data/lib/carray/methods/bin.rb +26 -18
  156. data/lib/carray/methods/bincount.rb +16 -0
  157. data/lib/carray/methods/bit_string.rb +1 -1
  158. data/lib/carray/methods/choose.rb +16 -3
  159. data/lib/carray/methods/composition.rb +3 -1
  160. data/lib/carray/methods/gather_nd.rb +14 -5
  161. data/lib/carray/methods/insert_block.rb +2 -2
  162. data/lib/carray/methods/is_between.rb +59 -0
  163. data/lib/carray/methods/is_in.rb +53 -36
  164. data/lib/carray/methods/join.rb +1 -6
  165. data/lib/carray/methods/lag.rb +49 -0
  166. data/lib/carray/methods/locate_addr.rb +47 -51
  167. data/lib/carray/methods/mode.rb +1 -1
  168. data/lib/carray/methods/nunique.rb +11 -6
  169. data/lib/carray/methods/resize.rb +3 -3
  170. data/lib/carray/methods/value_counts.rb +4 -11
  171. data/lib/carray/record_order.rb +3 -3
  172. data/lib/carray/rng.rb +3 -0
  173. data/lib/carray/runtime.rb +53 -8
  174. data/lib/carray/segment_iterator.rb +313 -82
  175. data/lib/carray/serialize.rb +24 -10
  176. data/lib/carray/slab_iterator.rb +50 -0
  177. data/lib/carray/string.rb +105 -5
  178. data/lib/carray/string_operation_extension.rb +8 -1
  179. data/lib/carray/struct.rb +9 -21
  180. data/lib/carray/struct_builder.rb +19 -8
  181. data/lib/carray/time.rb +726 -104
  182. data/lib/carray/window_iterator.rb +122 -16
  183. data/lib/carray.rb +7 -0
  184. data/yard-stubs/ca_obj_bitfield.rb +1 -1
  185. data/yard-stubs/ca_obj_field.rb +4 -0
  186. data/yard-stubs/ca_obj_grid.rb +21 -10
  187. data/yard-stubs/ca_obj_refer.rb +2 -1
  188. data/yard-stubs/ca_obj_roll.rb +2 -2
  189. data/yard-stubs/ca_obj_shift.rb +5 -1
  190. data/yard-stubs/ca_obj_tile.rb +1 -1
  191. data/yard-stubs/ca_obj_window.rb +8 -3
  192. data/yard-stubs/carray_access.rb +6 -1
  193. data/yard-stubs/carray_attribute.rb +0 -5
  194. data/yard-stubs/carray_cast.rb +10 -0
  195. data/yard-stubs/carray_conversion.rb +2 -1
  196. data/yard-stubs/carray_copy.rb +4 -2
  197. data/yard-stubs/carray_count.rb +4 -4
  198. data/yard-stubs/carray_element.rb +10 -4
  199. data/yard-stubs/carray_generate.rb +21 -1
  200. data/yard-stubs/carray_mask.rb +26 -2
  201. data/yard-stubs/carray_math.rb +27 -1
  202. data/yard-stubs/carray_median_percentile.rb +5 -2
  203. data/yard-stubs/carray_memory_view.rb +40 -23
  204. data/yard-stubs/carray_order.rb +29 -18
  205. data/yard-stubs/carray_random.rb +13 -4
  206. data/yard-stubs/carray_scatter.rb +14 -9
  207. data/yard-stubs/carray_slab.rb +9 -2
  208. data/yard-stubs/carray_sort.rb +6 -5
  209. data/yard-stubs/carray_test.rb +5 -3
  210. metadata +25 -3
  211. data/lib/carray/arrow_tensor.rb +0 -401
  212. data/lib/carray/table.rb +0 -108
@@ -437,6 +437,7 @@ rb_ca_is_object_type (VALUE self)
437
437
  /* ------------------------------------------------------------------- */
438
438
 
439
439
  static ID id_parent;
440
+ static ID id_lifted_from;
440
441
  static ID id_attr;
441
442
  static ID id_attrs;
442
443
 
@@ -446,6 +447,47 @@ rb_ca_parent (VALUE self)
446
447
  return rb_ivar_get(self, id_parent);
447
448
  }
448
449
 
450
+ /* A view of a Face is built on the Face's storage and wrapped in a new Face
451
+ (ca_face_lift), so the Face it was taken from is not on its parent chain.
452
+ The lift records that Face here, and the attribute walk goes to it in
453
+ place of the parent: the attributes set on a Face show on its views. */
454
+ void
455
+ rb_ca_set_lifted_from (VALUE lifted, VALUE face)
456
+ {
457
+ rb_ivar_set(lifted, id_lifted_from, face);
458
+ }
459
+
460
+ /* The next array of the attribute walk: the Face a lifted view was taken
461
+ from, or else the parent. */
462
+ static VALUE
463
+ ca_attr_parent (VALUE obj)
464
+ {
465
+ if ( rb_ivar_defined(obj, id_lifted_from) ) {
466
+ return rb_ivar_get(obj, id_lifted_from);
467
+ }
468
+ return rb_ivar_get(obj, id_parent);
469
+ }
470
+
471
+ static VALUE
472
+ rb_ca_attribute_parent (VALUE self)
473
+ {
474
+ return ca_attr_parent(self);
475
+ }
476
+
477
+ /* dup and clone copy the instance variables before initialize_copy, so the
478
+ copy would share the receiver's attribute Hash and a set_attr on it would
479
+ write into the receiver. Give the copy a Hash of its own. */
480
+ void
481
+ rb_ca_own_attr (VALUE self)
482
+ {
483
+ if ( rb_ivar_defined(self, id_attr) ) {
484
+ VALUE h = rb_ivar_get(self, id_attr);
485
+ if ( RB_TYPE_P(h, T_HASH) ) {
486
+ rb_ivar_set(self, id_attr, rb_hash_dup(h));
487
+ }
488
+ }
489
+ }
490
+
449
491
  /* Give dst the attributes (lib/carray/attribute.rb) that src shows, as its
450
492
  own Hash. Used by the methods that produce a new entity holding the
451
493
  same values -- copy, to_type. The parent walk here only decides
@@ -458,13 +500,14 @@ rb_ca_inherit_attr (VALUE dst, VALUE src)
458
500
  VALUE obj = src, attrs;
459
501
  int depth;
460
502
 
503
+ /* A chain longer than this is left to #attrs, which walks it all. */
461
504
  for (depth = 0; depth < 64 && ! NIL_P(obj); depth++) {
462
505
  if ( rb_ivar_defined(obj, id_attr) ) {
463
506
  break;
464
507
  }
465
- obj = rb_ivar_get(obj, id_parent);
508
+ obj = ca_attr_parent(obj);
466
509
  }
467
- if ( depth == 64 || NIL_P(obj) ) {
510
+ if ( NIL_P(obj) ) {
468
511
  return;
469
512
  }
470
513
  attrs = rb_funcall(src, id_attrs, 0);
@@ -553,12 +596,50 @@ ca_root_array (void *ap)
553
596
  }
554
597
 
555
598
  /* Whether two arrays may share memory: their cells live in the same
556
- root. An operation that writes one while reading the other must read
557
- from a copy taken before it writes. */
599
+ root, or in two entities whose memory overlaps (one wraps the other's
600
+ memory, as wrap_memory_view does). A view with several parents (a
601
+ stack, a meld, a lazy expression) is the end of its own chain, so its
602
+ parents are asked in turn. An operation that writes one while reading
603
+ the other must read from a copy taken before it writes. */
558
604
  int
559
605
  ca_shares_root (void *ap, void *aq)
560
606
  {
561
- return ca_root_array(ap) == ca_root_array(aq);
607
+ CArray *ra = ca_root_array(ap);
608
+ CArray *rb = ca_root_array(aq);
609
+ if ( ra == rb ) {
610
+ return 1;
611
+ }
612
+ if ( ca_test_flag(ra, CA_FLAG_MULTI_PARENTS) ) {
613
+ CAMultiParent *mp = (CAMultiParent *) ra;
614
+ int32_t k;
615
+ for ( k = 0; k < mp->n_parents; k++ ) {
616
+ if ( mp->parents[k] && ca_shares_root(mp->parents[k], rb) ) {
617
+ return 1;
618
+ }
619
+ }
620
+ return 0;
621
+ }
622
+ if ( ca_test_flag(rb, CA_FLAG_MULTI_PARENTS) ) {
623
+ return ca_shares_root(rb, ra);
624
+ }
625
+ if ( ca_is_entity(ra) && ca_is_entity(rb) && ra->ptr && rb->ptr ) {
626
+ char *a0 = ra->ptr, *a1 = ra->ptr + ca_length(ra);
627
+ char *b0 = rb->ptr, *b1 = rb->ptr + ca_length(rb);
628
+ return a0 < b1 && b0 < a1;
629
+ }
630
+ return 0;
631
+ }
632
+
633
+ /* Whether self and other may share memory (ca_shares_root), for the plan
634
+ reader that keeps an evaluator off a store reading what it writes. */
635
+ static VALUE
636
+ rb_ca_storage_overlaps (VALUE self, VALUE other)
637
+ {
638
+ CArray *ca, *cb;
639
+ rb_check_carray_object(other);
640
+ TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
641
+ TypedData_Get_Struct(other, CArray, &carray_data_type, cb);
642
+ return ca_shares_root(ca, cb) ? Qtrue : Qfalse;
562
643
  }
563
644
 
564
645
  static VALUE
@@ -624,6 +705,7 @@ void
624
705
  Init_carray_attribute (void)
625
706
  {
626
707
  id_parent = rb_intern("parent");
708
+ id_lifted_from = rb_intern("lifted_from");
627
709
  id_attr = rb_intern("@attr");
628
710
  id_attrs = rb_intern("attrs");
629
711
 
@@ -632,7 +714,6 @@ Init_carray_attribute (void)
632
714
  rb_define_method(rb_cCArray, "bytes", rb_ca_bytes, 0);
633
715
  rb_define_method(rb_cCArray, "flags", rb_ca_flags, 0);
634
716
  rb_define_method(rb_cCArray, "ndim", rb_ca_ndim, 0);
635
- rb_define_method(rb_cCArray, "rank", rb_ca_ndim, 0);
636
717
  rb_define_method(rb_cCArray, "shape", rb_ca_dim, 0);
637
718
  rb_define_method(rb_cCArray, "dim", rb_ca_dim, 0);
638
719
  rb_define_method(rb_cCArray, "dim0", rb_ca_dim0, 0);
@@ -646,6 +727,7 @@ Init_carray_attribute (void)
646
727
  rb_define_method(rb_cCArray, "data_type_name", rb_ca_data_type_name, 0);
647
728
 
648
729
  rb_define_method(rb_cCArray, "parent", rb_ca_parent, 0);
730
+ rb_define_private_method(rb_cCArray, "attribute_parent", rb_ca_attribute_parent, 0);
649
731
 
650
732
  rb_define_method(rb_cCArray, "data_class", rb_ca_data_class, 0);
651
733
  rb_define_method(rb_cCArray, "data_class=", rb_ca_set_data_class, 1);
@@ -673,6 +755,7 @@ Init_carray_attribute (void)
673
755
  rb_define_method(rb_cCArray, "object?", rb_ca_is_object_type, 0);
674
756
 
675
757
  rb_define_method(rb_cCArray, "root_array", rb_ca_root_array, 0);
758
+ rb_define_private_method(rb_cCArray, "storage_overlaps?", rb_ca_storage_overlaps, 1);
676
759
  rb_define_method(rb_cCArray, "ancestors", rb_ca_ancestors, 0);
677
760
  }
678
761
 
@@ -67,8 +67,8 @@
67
67
  case CA_UINT64: COUNT_KERNEL(uint64_t, OUT_T); break; \
68
68
  default: \
69
69
  rb_raise(rb_eCADataTypeError, \
70
- "bincount: integer label array required (got %d)", \
71
- cl->data_type); \
70
+ "bincount: integer label array required (got %s)", \
71
+ ca_type_name[cl->data_type]); \
72
72
  } \
73
73
  } while (0)
74
74
 
@@ -83,8 +83,8 @@ bincount_check_types (CArray *cl, CArray *cw)
83
83
  break;
84
84
  default:
85
85
  rb_raise(rb_eCADataTypeError,
86
- "bincount: integer label array required (got %d)",
87
- cl->data_type);
86
+ "bincount: integer label array required (got %s)",
87
+ ca_type_name[cl->data_type]);
88
88
  }
89
89
  if ( ! cw ) {
90
90
  return;
@@ -96,7 +96,8 @@ bincount_check_types (CArray *cl, CArray *cw)
96
96
  break;
97
97
  default:
98
98
  rb_raise(rb_eCADataTypeError,
99
- "bincount: weights must be numeric (got %d)", cw->data_type);
99
+ "bincount: weights must be numeric (got %s)",
100
+ ca_type_name[cw->data_type]);
100
101
  }
101
102
  }
102
103
 
@@ -199,8 +200,8 @@ rb_ca_bincount_count_kernel (VALUE self, VALUE rlength)
199
200
  case CA_UINT64: WEIGHTED_KERNEL(uint64_t, W_T); break; \
200
201
  default: \
201
202
  rb_raise(rb_eCADataTypeError, \
202
- "bincount: integer label array required (got %d)", \
203
- cl->data_type); \
203
+ "bincount: integer label array required (got %s)", \
204
+ ca_type_name[cl->data_type]); \
204
205
  } \
205
206
  } while (0)
206
207
 
@@ -262,7 +263,8 @@ rb_ca_bincount_weighted_kernel (VALUE self, VALUE rweights, VALUE rlength)
262
263
  default:
263
264
  ca_detach_n(2, cl, cw);
264
265
  rb_raise(rb_eCADataTypeError,
265
- "bincount: weights must be numeric (got %d)", w_type);
266
+ "bincount: weights must be numeric (got %s)",
267
+ ca_type_name[w_type]);
266
268
  }
267
269
 
268
270
  ca_detach_n(2, cl, cw);
@@ -30,6 +30,7 @@
30
30
  ---------------------------------------------------------------------------- */
31
31
 
32
32
  #include "carray.h"
33
+ #include "carray_internal.h" /* ca_check_rank_fits */
33
34
  #include "ca_obj_face.h" /* CA_WRAPPER_LIFT */
34
35
 
35
36
  NORETURN(static void ca_broadcast_refuse_write (VALUE dst, VALUE src));
@@ -41,10 +42,11 @@ ca_broadcast_refuse_write (VALUE dst, VALUE src)
41
42
  volatile VALUE dst_s = rb_inspect(rb_funcall(dst, rb_intern("shape"), 0));
42
43
  volatile VALUE src_s = rb_inspect(rb_funcall(src, rb_intern("shape"), 0));
43
44
  rb_raise(rb_eArgError,
44
- "shape mismatch writing to carray (%s <- %s); shapes must agree "
45
+ "%s: shape mismatch writing to carray (%s <- %s); shapes must agree "
45
46
  "once size-1 axes are dropped, or one side must be 1-D, or the "
46
47
  "source must be smaller and broadcastable -- use .flatten to "
47
48
  "write the values in the order they lie",
49
+ ca_calling_method_name(),
48
50
  StringValueCStr(dst_s), StringValueCStr(src_s));
49
51
  }
50
52
 
@@ -87,7 +89,11 @@ ca_broadcast_to_destination (VALUE dst, volatile VALUE *src)
87
89
  return;
88
90
  }
89
91
 
90
- if ( cs->elements < cd->elements && cs->ndim == cd->ndim ) {
92
+ /* A size-1 axis repeated onto an axis of length 0 leaves the source
93
+ larger than an empty destination; the axes say it is a repeat all
94
+ the same. */
95
+ if ( ( cs->elements < cd->elements || cd->elements == 0 )
96
+ && cs->ndim == cd->ndim ) {
91
97
  int i;
92
98
  for ( i = 0; i < cd->ndim; i++ ) {
93
99
  if ( cs->dim[i] != cd->dim[i] && cs->dim[i] != 1 ) break;
@@ -196,10 +202,11 @@ ca_broadcast_refuse (VALUE self, VALUE other)
196
202
 
197
203
  if (ca->ndim != cb->ndim) {
198
204
  rb_raise(rb_eArgError,
199
- "shape mismatch between operands (%s and %s): the operands "
205
+ "%s: shape mismatch between operands (%s and %s): the operands "
200
206
  "have different numbers of axes, and axes are not added "
201
207
  "implicitly -- add size-1 axes with :_ so both have the same "
202
208
  "number (x[:_, nil] makes a 1-D x a row, x[nil, :_] a column)%s",
209
+ ca_calling_method_name(),
203
210
  StringValueCStr(self_s), StringValueCStr(other_s),
204
211
  flatten_hint);
205
212
  }
@@ -210,10 +217,10 @@ ca_broadcast_refuse (VALUE self, VALUE other)
210
217
  }
211
218
  }
212
219
  rb_raise(rb_eArgError,
213
- "shape mismatch between operands (%s and %s): axis %d has "
220
+ "%s: shape mismatch between operands (%s and %s): axis %d has "
214
221
  "sizes %lld and %lld; each axis must have the same size, or "
215
222
  "size 1 on one side%s",
216
- StringValueCStr(self_s), StringValueCStr(other_s), i,
223
+ ca_calling_method_name(), StringValueCStr(self_s), StringValueCStr(other_s), i,
217
224
  (long long) ca->dim[i], (long long) cb->dim[i], flatten_hint);
218
225
  }
219
226
 
@@ -295,9 +302,7 @@ rb_ca_broadcast_to (int argc, VALUE *argv, VALUE self)
295
302
 
296
303
  TypedData_Get_Struct(self, CArray, &carray_data_type, cs);
297
304
 
298
- if (argc < 0 || argc > CA_RANK_MAX) {
299
- rb_raise(rb_eArgError, "broadcast_to: invalid number of dims (%d)", argc);
300
- }
305
+ ca_check_rank_fits(argc, "broadcast_to");
301
306
  target_ndim = (int8_t) argc;
302
307
 
303
308
  if (target_ndim < cs->ndim) {
@@ -0,0 +1,3 @@
1
+ /* GENERATED by extconf.rb: the flags this build's arithmetic
2
+ was compiled with. See CArray::BUILD_FLAGS. */
3
+ #define CA_BUILD_FLAGS "-O3 -fno-fast-math -fwrapv -fopenmp-simd -march=native"
@@ -226,6 +226,8 @@ ca_call_cfunc_2 (void (*func)(void *p0, void *p1), const char *fsync,
226
226
  ctx.userdata = NULL;
227
227
  ca_sweep_run(&state, ca_call_cfunc_2_walk, (VALUE) &ctx);
228
228
 
229
+ RB_GC_GUARD(rcx1);
230
+
229
231
  return rcx0;
230
232
  }
231
233
 
@@ -298,6 +300,9 @@ ca_call_cfunc_3 (void (*func)(void *p0, void *p1, void *p2), const char *fsync,
298
300
  ctx.userdata = NULL;
299
301
  ca_sweep_run(&state, ca_call_cfunc_3_walk, (VALUE) &ctx);
300
302
 
303
+ RB_GC_GUARD(rcx1);
304
+ RB_GC_GUARD(rcx2);
305
+
301
306
  return rcx0;
302
307
  }
303
308
 
@@ -371,6 +376,10 @@ ca_call_cfunc_4 (void (*func)(void *p0, void *p1, void *p2, void *p3), const cha
371
376
  ctx.userdata = NULL;
372
377
  ca_sweep_run(&state, ca_call_cfunc_4_walk, (VALUE) &ctx);
373
378
 
379
+ RB_GC_GUARD(rcx1);
380
+ RB_GC_GUARD(rcx2);
381
+ RB_GC_GUARD(rcx3);
382
+
374
383
  return rcx0;
375
384
  }
376
385
 
@@ -445,6 +454,11 @@ ca_call_cfunc_5 (void (*func)(void *p0, void *p1, void *p2, void *p3, void *p4),
445
454
  ctx.userdata = NULL;
446
455
  ca_sweep_run(&state, ca_call_cfunc_5_walk, (VALUE) &ctx);
447
456
 
457
+ RB_GC_GUARD(rcx1);
458
+ RB_GC_GUARD(rcx2);
459
+ RB_GC_GUARD(rcx3);
460
+ RB_GC_GUARD(rcx4);
461
+
448
462
  return rcx0;
449
463
  }
450
464
 
@@ -520,6 +534,12 @@ ca_call_cfunc_6 (void (*func)(void *p0, void *p1, void *p2, void *p3, void *p4,
520
534
  ctx.userdata = NULL;
521
535
  ca_sweep_run(&state, ca_call_cfunc_6_walk, (VALUE) &ctx);
522
536
 
537
+ RB_GC_GUARD(rcx1);
538
+ RB_GC_GUARD(rcx2);
539
+ RB_GC_GUARD(rcx3);
540
+ RB_GC_GUARD(rcx4);
541
+ RB_GC_GUARD(rcx5);
542
+
523
543
  return rcx0;
524
544
  }
525
545
 
@@ -596,6 +616,13 @@ ca_call_cfunc_7 (void (*func)(void *p0, void *p1, void *p2, void *p3, void *p4,
596
616
  ctx.userdata = NULL;
597
617
  ca_sweep_run(&state, ca_call_cfunc_7_walk, (VALUE) &ctx);
598
618
 
619
+ RB_GC_GUARD(rcx1);
620
+ RB_GC_GUARD(rcx2);
621
+ RB_GC_GUARD(rcx3);
622
+ RB_GC_GUARD(rcx4);
623
+ RB_GC_GUARD(rcx5);
624
+ RB_GC_GUARD(rcx6);
625
+
599
626
  return rcx0;
600
627
  }
601
628
 
@@ -1128,6 +1155,8 @@ ca_call_cfunc_2_r (void (*func)(void *p0, void *p1, void *userdata), const char
1128
1155
  ctx.userdata = userdata;
1129
1156
  ca_sweep_run(&state, ca_call_cfunc_2_r_walk, (VALUE) &ctx);
1130
1157
 
1158
+ RB_GC_GUARD(rcx1);
1159
+
1131
1160
  return rcx0;
1132
1161
  }
1133
1162
 
@@ -1201,6 +1230,9 @@ ca_call_cfunc_3_r (void (*func)(void *p0, void *p1, void *p2, void *userdata), c
1201
1230
  ctx.userdata = userdata;
1202
1231
  ca_sweep_run(&state, ca_call_cfunc_3_r_walk, (VALUE) &ctx);
1203
1232
 
1233
+ RB_GC_GUARD(rcx1);
1234
+ RB_GC_GUARD(rcx2);
1235
+
1204
1236
  return rcx0;
1205
1237
  }
1206
1238
 
@@ -1275,6 +1307,10 @@ ca_call_cfunc_4_r (void (*func)(void *p0, void *p1, void *p2, void *p3, void *us
1275
1307
  ctx.userdata = userdata;
1276
1308
  ca_sweep_run(&state, ca_call_cfunc_4_r_walk, (VALUE) &ctx);
1277
1309
 
1310
+ RB_GC_GUARD(rcx1);
1311
+ RB_GC_GUARD(rcx2);
1312
+ RB_GC_GUARD(rcx3);
1313
+
1278
1314
  return rcx0;
1279
1315
  }
1280
1316
 
@@ -1350,6 +1386,11 @@ ca_call_cfunc_5_r (void (*func)(void *p0, void *p1, void *p2, void *p3, void *p4
1350
1386
  ctx.userdata = userdata;
1351
1387
  ca_sweep_run(&state, ca_call_cfunc_5_r_walk, (VALUE) &ctx);
1352
1388
 
1389
+ RB_GC_GUARD(rcx1);
1390
+ RB_GC_GUARD(rcx2);
1391
+ RB_GC_GUARD(rcx3);
1392
+ RB_GC_GUARD(rcx4);
1393
+
1353
1394
  return rcx0;
1354
1395
  }
1355
1396
 
@@ -1426,6 +1467,12 @@ ca_call_cfunc_6_r (void (*func)(void *p0, void *p1, void *p2, void *p3, void *p4
1426
1467
  ctx.userdata = userdata;
1427
1468
  ca_sweep_run(&state, ca_call_cfunc_6_r_walk, (VALUE) &ctx);
1428
1469
 
1470
+ RB_GC_GUARD(rcx1);
1471
+ RB_GC_GUARD(rcx2);
1472
+ RB_GC_GUARD(rcx3);
1473
+ RB_GC_GUARD(rcx4);
1474
+ RB_GC_GUARD(rcx5);
1475
+
1429
1476
  return rcx0;
1430
1477
  }
1431
1478
 
@@ -1503,6 +1550,13 @@ ca_call_cfunc_7_r (void (*func)(void *p0, void *p1, void *p2, void *p3, void *p4
1503
1550
  ctx.userdata = userdata;
1504
1551
  ca_sweep_run(&state, ca_call_cfunc_7_r_walk, (VALUE) &ctx);
1505
1552
 
1553
+ RB_GC_GUARD(rcx1);
1554
+ RB_GC_GUARD(rcx2);
1555
+ RB_GC_GUARD(rcx3);
1556
+ RB_GC_GUARD(rcx4);
1557
+ RB_GC_GUARD(rcx5);
1558
+ RB_GC_GUARD(rcx6);
1559
+
1506
1560
  return rcx0;
1507
1561
  }
1508
1562
 
@@ -1973,6 +2027,8 @@ ca_call_cslab_2 (ca_cslab_t func, const char *fsync,
1973
2027
  ctx.userdata = NULL;
1974
2028
  ca_sweep_run_chunked(&state, ca_cslab_walk, (VALUE) &ctx);
1975
2029
 
2030
+ RB_GC_GUARD(rcx1);
2031
+
1976
2032
  return rcx0;
1977
2033
  }
1978
2034
 
@@ -2017,6 +2073,9 @@ ca_call_cslab_3 (ca_cslab_t func, const char *fsync,
2017
2073
  ctx.userdata = NULL;
2018
2074
  ca_sweep_run_chunked(&state, ca_cslab_walk, (VALUE) &ctx);
2019
2075
 
2076
+ RB_GC_GUARD(rcx1);
2077
+ RB_GC_GUARD(rcx2);
2078
+
2020
2079
  return rcx0;
2021
2080
  }
2022
2081
 
@@ -2062,6 +2121,10 @@ ca_call_cslab_4 (ca_cslab_t func, const char *fsync,
2062
2121
  ctx.userdata = NULL;
2063
2122
  ca_sweep_run_chunked(&state, ca_cslab_walk, (VALUE) &ctx);
2064
2123
 
2124
+ RB_GC_GUARD(rcx1);
2125
+ RB_GC_GUARD(rcx2);
2126
+ RB_GC_GUARD(rcx3);
2127
+
2065
2128
  return rcx0;
2066
2129
  }
2067
2130
 
@@ -2108,6 +2171,11 @@ ca_call_cslab_5 (ca_cslab_t func, const char *fsync,
2108
2171
  ctx.userdata = NULL;
2109
2172
  ca_sweep_run_chunked(&state, ca_cslab_walk, (VALUE) &ctx);
2110
2173
 
2174
+ RB_GC_GUARD(rcx1);
2175
+ RB_GC_GUARD(rcx2);
2176
+ RB_GC_GUARD(rcx3);
2177
+ RB_GC_GUARD(rcx4);
2178
+
2111
2179
  return rcx0;
2112
2180
  }
2113
2181
 
@@ -2155,6 +2223,12 @@ ca_call_cslab_6 (ca_cslab_t func, const char *fsync,
2155
2223
  ctx.userdata = NULL;
2156
2224
  ca_sweep_run_chunked(&state, ca_cslab_walk, (VALUE) &ctx);
2157
2225
 
2226
+ RB_GC_GUARD(rcx1);
2227
+ RB_GC_GUARD(rcx2);
2228
+ RB_GC_GUARD(rcx3);
2229
+ RB_GC_GUARD(rcx4);
2230
+ RB_GC_GUARD(rcx5);
2231
+
2158
2232
  return rcx0;
2159
2233
  }
2160
2234
 
@@ -2203,6 +2277,13 @@ ca_call_cslab_7 (ca_cslab_t func, const char *fsync,
2203
2277
  ctx.userdata = NULL;
2204
2278
  ca_sweep_run_chunked(&state, ca_cslab_walk, (VALUE) &ctx);
2205
2279
 
2280
+ RB_GC_GUARD(rcx1);
2281
+ RB_GC_GUARD(rcx2);
2282
+ RB_GC_GUARD(rcx3);
2283
+ RB_GC_GUARD(rcx4);
2284
+ RB_GC_GUARD(rcx5);
2285
+ RB_GC_GUARD(rcx6);
2286
+
2206
2287
  return rcx0;
2207
2288
  }
2208
2289
 
@@ -2290,6 +2371,8 @@ ca_call_cslab_2_r (ca_cslab_r_t func, const char *fsync,
2290
2371
  ctx.userdata = userdata;
2291
2372
  ca_sweep_run_chunked(&state, ca_cslab_r_walk, (VALUE) &ctx);
2292
2373
 
2374
+ RB_GC_GUARD(rcx1);
2375
+
2293
2376
  return rcx0;
2294
2377
  }
2295
2378
 
@@ -2335,6 +2418,9 @@ ca_call_cslab_3_r (ca_cslab_r_t func, const char *fsync,
2335
2418
  ctx.userdata = userdata;
2336
2419
  ca_sweep_run_chunked(&state, ca_cslab_r_walk, (VALUE) &ctx);
2337
2420
 
2421
+ RB_GC_GUARD(rcx1);
2422
+ RB_GC_GUARD(rcx2);
2423
+
2338
2424
  return rcx0;
2339
2425
  }
2340
2426
 
@@ -2381,6 +2467,10 @@ ca_call_cslab_4_r (ca_cslab_r_t func, const char *fsync,
2381
2467
  ctx.userdata = userdata;
2382
2468
  ca_sweep_run_chunked(&state, ca_cslab_r_walk, (VALUE) &ctx);
2383
2469
 
2470
+ RB_GC_GUARD(rcx1);
2471
+ RB_GC_GUARD(rcx2);
2472
+ RB_GC_GUARD(rcx3);
2473
+
2384
2474
  return rcx0;
2385
2475
  }
2386
2476
 
@@ -2428,6 +2518,11 @@ ca_call_cslab_5_r (ca_cslab_r_t func, const char *fsync,
2428
2518
  ctx.userdata = userdata;
2429
2519
  ca_sweep_run_chunked(&state, ca_cslab_r_walk, (VALUE) &ctx);
2430
2520
 
2521
+ RB_GC_GUARD(rcx1);
2522
+ RB_GC_GUARD(rcx2);
2523
+ RB_GC_GUARD(rcx3);
2524
+ RB_GC_GUARD(rcx4);
2525
+
2431
2526
  return rcx0;
2432
2527
  }
2433
2528
 
@@ -2476,6 +2571,12 @@ ca_call_cslab_6_r (ca_cslab_r_t func, const char *fsync,
2476
2571
  ctx.userdata = userdata;
2477
2572
  ca_sweep_run_chunked(&state, ca_cslab_r_walk, (VALUE) &ctx);
2478
2573
 
2574
+ RB_GC_GUARD(rcx1);
2575
+ RB_GC_GUARD(rcx2);
2576
+ RB_GC_GUARD(rcx3);
2577
+ RB_GC_GUARD(rcx4);
2578
+ RB_GC_GUARD(rcx5);
2579
+
2479
2580
  return rcx0;
2480
2581
  }
2481
2582
 
@@ -2525,6 +2626,13 @@ ca_call_cslab_7_r (ca_cslab_r_t func, const char *fsync,
2525
2626
  ctx.userdata = userdata;
2526
2627
  ca_sweep_run_chunked(&state, ca_cslab_r_walk, (VALUE) &ctx);
2527
2628
 
2629
+ RB_GC_GUARD(rcx1);
2630
+ RB_GC_GUARD(rcx2);
2631
+ RB_GC_GUARD(rcx3);
2632
+ RB_GC_GUARD(rcx4);
2633
+ RB_GC_GUARD(rcx5);
2634
+ RB_GC_GUARD(rcx6);
2635
+
2528
2636
  return rcx0;
2529
2637
  }
2530
2638