numo-narray 0.9.1.4 → 0.9.1.9

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 (71) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -6
  3. data/Rakefile +4 -63
  4. data/ext/numo/narray/array.c +35 -32
  5. data/ext/numo/narray/data.c +40 -43
  6. data/ext/numo/narray/depend.erb +6 -10
  7. data/ext/numo/narray/extconf.rb +24 -21
  8. data/ext/numo/narray/gen/cogen.rb +2 -2
  9. data/ext/numo/narray/gen/narray_def.rb +5 -1
  10. data/ext/numo/narray/gen/spec.rb +17 -7
  11. data/ext/numo/narray/gen/tmpl/accum.c +2 -2
  12. data/ext/numo/narray/gen/tmpl/accum_arg.c +88 -0
  13. data/ext/numo/narray/gen/tmpl/accum_binary.c +1 -1
  14. data/ext/numo/narray/gen/tmpl/accum_index.c +25 -14
  15. data/ext/numo/narray/gen/tmpl/alloc_func.c +4 -1
  16. data/ext/numo/narray/gen/tmpl/allocate.c +1 -0
  17. data/ext/numo/narray/gen/tmpl/aref.c +5 -35
  18. data/ext/numo/narray/gen/tmpl/aset.c +7 -37
  19. data/ext/numo/narray/gen/tmpl/bincount.c +7 -7
  20. data/ext/numo/narray/gen/tmpl/cast.c +7 -0
  21. data/ext/numo/narray/gen/tmpl/clip.c +11 -15
  22. data/ext/numo/narray/gen/tmpl/cum.c +1 -1
  23. data/ext/numo/narray/gen/tmpl/each.c +4 -2
  24. data/ext/numo/narray/gen/tmpl/each_with_index.c +5 -2
  25. data/ext/numo/narray/gen/tmpl/lib.c +2 -2
  26. data/ext/numo/narray/gen/tmpl/logseq.c +6 -5
  27. data/ext/numo/narray/gen/tmpl/map_with_index.c +5 -6
  28. data/ext/numo/narray/gen/tmpl/median.c +2 -2
  29. data/ext/numo/narray/gen/tmpl/minmax.c +1 -1
  30. data/ext/numo/narray/gen/tmpl/poly.c +4 -4
  31. data/ext/numo/narray/gen/tmpl/qsort.c +1 -1
  32. data/ext/numo/narray/gen/tmpl/rand.c +8 -6
  33. data/ext/numo/narray/gen/tmpl/rand_norm.c +18 -16
  34. data/ext/numo/narray/gen/tmpl/seq.c +5 -4
  35. data/ext/numo/narray/gen/tmpl/sort.c +3 -3
  36. data/ext/numo/narray/gen/tmpl/sort_index.c +2 -2
  37. data/ext/numo/narray/gen/tmpl/store_array.c +14 -2
  38. data/ext/numo/narray/gen/tmpl/unary_s.c +55 -31
  39. data/ext/numo/narray/gen/tmpl_bit/allocate.c +1 -0
  40. data/ext/numo/narray/gen/tmpl_bit/aref.c +22 -30
  41. data/ext/numo/narray/gen/tmpl_bit/aset.c +20 -34
  42. data/ext/numo/narray/gen/tmpl_bit/binary.c +48 -14
  43. data/ext/numo/narray/gen/tmpl_bit/bit_count.c +5 -0
  44. data/ext/numo/narray/gen/tmpl_bit/bit_reduce.c +5 -0
  45. data/ext/numo/narray/gen/tmpl_bit/store_array.c +14 -2
  46. data/ext/numo/narray/gen/tmpl_bit/store_bit.c +27 -9
  47. data/ext/numo/narray/gen/tmpl_bit/unary.c +25 -7
  48. data/ext/numo/narray/index.c +363 -59
  49. data/ext/numo/narray/math.c +2 -2
  50. data/ext/numo/narray/narray.c +151 -36
  51. data/ext/numo/narray/ndloop.c +4 -4
  52. data/ext/numo/narray/numo/intern.h +3 -2
  53. data/ext/numo/narray/numo/narray.h +37 -14
  54. data/ext/numo/narray/numo/ndloop.h +2 -2
  55. data/ext/numo/narray/numo/template.h +11 -15
  56. data/ext/numo/narray/numo/types/complex.h +2 -2
  57. data/ext/numo/narray/numo/types/int16.h +5 -2
  58. data/ext/numo/narray/numo/types/int32.h +0 -1
  59. data/ext/numo/narray/numo/types/int64.h +0 -1
  60. data/ext/numo/narray/numo/types/int8.h +1 -2
  61. data/ext/numo/narray/numo/types/uint16.h +5 -2
  62. data/ext/numo/narray/numo/types/uint32.h +0 -1
  63. data/ext/numo/narray/numo/types/uint64.h +0 -1
  64. data/ext/numo/narray/numo/types/uint8.h +1 -2
  65. data/ext/numo/narray/numo/types/xint_macro.h +2 -0
  66. data/ext/numo/narray/step.c +58 -252
  67. data/ext/numo/narray/struct.c +3 -3
  68. data/lib/numo/narray.rb +1 -7
  69. data/lib/numo/narray/extra.rb +214 -213
  70. data/numo-narray.gemspec +7 -8
  71. metadata +17 -36
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  math.c
3
- Numerical Array Extension for Ruby
4
- (C) Copyright 1999-2017 by Masahiro TANAKA
3
+ Ruby/Numo::NArray - Numerical Array class for Ruby
4
+ Copyright (C) 1999-2020 Masahiro TANAKA
5
5
  */
6
6
  #include <ruby.h>
7
7
  #include "numo/narray.h"
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  narray.c
3
- Numerical Array Extension for Ruby
4
- (C) Copyright 1999-2017 by Masahiro TANAKA
3
+ Ruby/Numo::NArray - Numerical Array class for Ruby
4
+ Copyright (C) 1999-2020 Masahiro TANAKA
5
5
  */
6
6
  #define NARRAY_C
7
7
  #include <ruby.h>
@@ -34,6 +34,7 @@ static ID id_count_false;
34
34
  static ID id_axis;
35
35
  static ID id_nan;
36
36
  static ID id_keepdims;
37
+ static ID id_source;
37
38
 
38
39
  VALUE cPointer;
39
40
 
@@ -42,17 +43,21 @@ VALUE sym_option;
42
43
  VALUE sym_loop_opt;
43
44
  VALUE sym_init;
44
45
 
45
- VALUE na_cStep;
46
46
  #ifndef HAVE_RB_CCOMPLEX
47
47
  VALUE rb_cComplex;
48
48
  #endif
49
+ #ifdef HAVE_RB_ARITHMETIC_SEQUENCE_EXTRACT
50
+ VALUE rb_cArithSeq;
51
+ #endif
49
52
 
50
53
  int numo_na_inspect_rows=20;
51
54
  int numo_na_inspect_cols=80;
52
55
 
53
56
  void Init_nary_data();
54
57
  void Init_nary_ndloop();
58
+ #ifndef HAVE_RB_ARITHMETIC_SEQUENCE_EXTRACT
55
59
  void Init_nary_step();
60
+ #endif
56
61
  void Init_nary_index();
57
62
  void Init_numo_bit();
58
63
  void Init_numo_int8();
@@ -348,19 +353,19 @@ na_setup(VALUE self, int ndim, size_t *shape)
348
353
 
349
354
  @example
350
355
  i = Numo::Int64.new([2,4,3])
351
- #=> Numo::Int64#shape=[2,4,3](empty)
356
+ # => Numo::Int64#shape=[2,4,3](empty)
352
357
 
353
358
  f = Numo::DFloat.new(3,4)
354
- #=> Numo::DFloat#shape=[3,4](empty)
359
+ # => Numo::DFloat#shape=[3,4](empty)
355
360
 
356
361
  f.fill(2)
357
- #=> Numo::DFloat#shape=[3,4]
362
+ # => Numo::DFloat#shape=[3,4]
358
363
  # [[2, 2, 2, 2],
359
364
  # [2, 2, 2, 2],
360
365
  # [2, 2, 2, 2]]
361
366
 
362
367
  x = Numo::NArray.new(5)
363
- #=> in `new': allocator undefined for Numo::NArray (TypeError)
368
+ # => in `new': allocator undefined for Numo::NArray (TypeError)
364
369
  # from t.rb:9:in `<main>'
365
370
 
366
371
  */
@@ -444,10 +449,10 @@ na_initialize_copy(VALUE self, VALUE orig)
444
449
  * but for typed NArray subclasses, e.g., DFloat, Int64.
445
450
  * @example
446
451
  * a = Numo::DFloat.zeros(3,5)
447
- * => Numo::DFloat#shape=[3,5]
448
- * [[0, 0, 0, 0, 0],
449
- * [0, 0, 0, 0, 0],
450
- * [0, 0, 0, 0, 0]]
452
+ * # => Numo::DFloat#shape=[3,5]
453
+ * # [[0, 0, 0, 0, 0],
454
+ * # [0, 0, 0, 0, 0],
455
+ * # [0, 0, 0, 0, 0]]
451
456
  */
452
457
  static VALUE
453
458
  na_s_zeros(int argc, VALUE *argv, VALUE klass)
@@ -468,10 +473,10 @@ na_s_zeros(int argc, VALUE *argv, VALUE klass)
468
473
  * but for typed NArray subclasses, e.g., DFloat, Int64.
469
474
  * @example
470
475
  * a = Numo::DFloat.ones(3,5)
471
- * => Numo::DFloat#shape=[3,5]
472
- * [[1, 1, 1, 1, 1],
473
- * [1, 1, 1, 1, 1],
474
- * [1, 1, 1, 1, 1]]
476
+ * # => Numo::DFloat#shape=[3,5]
477
+ * # [[1, 1, 1, 1, 1],
478
+ * # [1, 1, 1, 1, 1],
479
+ * # [1, 1, 1, 1, 1]]
475
480
  */
476
481
  static VALUE
477
482
  na_s_ones(int argc, VALUE *argv, VALUE klass)
@@ -495,8 +500,8 @@ na_s_ones(int argc, VALUE *argv, VALUE klass)
495
500
 
496
501
  @example
497
502
  a = Numo::DFloat.linspace(-5,5,7)
498
- => Numo::DFloat#shape=[7]
499
- [-5, -3.33333, -1.66667, 0, 1.66667, 3.33333, 5]
503
+ # => Numo::DFloat#shape=[7]
504
+ # [-5, -3.33333, -1.66667, 0, 1.66667, 3.33333, 5]
500
505
  */
501
506
  static VALUE
502
507
  na_s_linspace(int argc, VALUE *argv, VALUE klass)
@@ -534,11 +539,12 @@ na_s_linspace(int argc, VALUE *argv, VALUE klass)
534
539
 
535
540
  @example
536
541
  Numo::DFloat.logspace(4,0,5,2)
537
- => Numo::DFloat#shape=[5]
538
- [16, 8, 4, 2, 1]
542
+ # => Numo::DFloat#shape=[5]
543
+ # [16, 8, 4, 2, 1]
544
+
539
545
  Numo::DComplex.logspace(0,1i*Math::PI,5,Math::E)
540
- => Numo::DComplex#shape=[5]
541
- [1+4.44659e-323i, 0.707107+0.707107i, 6.12323e-17+1i, -0.707107+0.707107i, ...]
546
+ # => Numo::DComplex#shape=[5]
547
+ # [1+4.44659e-323i, 0.707107+0.707107i, 6.12323e-17+1i, -0.707107+0.707107i, ...]
542
548
  */
543
549
  static VALUE
544
550
  na_s_logspace(int argc, VALUE *argv, VALUE klass)
@@ -572,10 +578,10 @@ na_s_logspace(int argc, VALUE *argv, VALUE klass)
572
578
  @return [Numo::NArray] created NArray.
573
579
  @example
574
580
  a = Numo::DFloat.eye(3)
575
- => Numo::DFloat#shape=[3,3]
576
- [[1, 0, 0],
577
- [0, 1, 0],
578
- [0, 0, 1]]
581
+ # => Numo::DFloat#shape=[3,3]
582
+ # [[1, 0, 0],
583
+ # [0, 1, 0],
584
+ # [0, 0, 1]]
579
585
  */
580
586
  static VALUE
581
587
  na_s_eye(int argc, VALUE *argv, VALUE klass)
@@ -600,6 +606,87 @@ na_s_eye(int argc, VALUE *argv, VALUE klass)
600
606
  #define READ 1
601
607
  #define WRITE 2
602
608
 
609
+ static void
610
+ na_set_pointer(VALUE self, char *ptr, size_t byte_size)
611
+ {
612
+ VALUE obj;
613
+ narray_t *na;
614
+
615
+ if (OBJ_FROZEN(self)) {
616
+ rb_raise(rb_eRuntimeError, "cannot write to frozen NArray.");
617
+ }
618
+
619
+ GetNArray(self,na);
620
+
621
+ switch(NA_TYPE(na)) {
622
+ case NARRAY_DATA_T:
623
+ if (NA_SIZE(na) > 0) {
624
+ if (NA_DATA_PTR(na) != NULL && NA_DATA_OWNED(na)) {
625
+ xfree(NA_DATA_PTR(na));
626
+ }
627
+ NA_DATA_PTR(na) = ptr;
628
+ NA_DATA_OWNED(na) = FALSE;
629
+ }
630
+ return;
631
+ case NARRAY_VIEW_T:
632
+ obj = NA_VIEW_DATA(na);
633
+ if (OBJ_FROZEN(obj)) {
634
+ rb_raise(rb_eRuntimeError, "cannot write to frozen NArray.");
635
+ }
636
+ GetNArray(obj,na);
637
+ switch(NA_TYPE(na)) {
638
+ case NARRAY_DATA_T:
639
+ if (NA_SIZE(na) > 0) {
640
+ if (NA_DATA_PTR(na) != NULL && NA_DATA_OWNED(na)) {
641
+ xfree(NA_DATA_PTR(na));
642
+ }
643
+ NA_DATA_PTR(na) = ptr;
644
+ NA_DATA_OWNED(na) = FALSE;
645
+ }
646
+ return;
647
+ default:
648
+ rb_raise(rb_eRuntimeError,"invalid NA_TYPE of view: %d",NA_TYPE(na));
649
+ }
650
+ default:
651
+ rb_raise(rb_eRuntimeError,"invalid NA_TYPE: %d",NA_TYPE(na));
652
+ }
653
+ }
654
+
655
+ static void
656
+ na_pointer_copy_on_write(VALUE self)
657
+ {
658
+ narray_t *na;
659
+ void *ptr;
660
+ VALUE velmsz;
661
+ size_t byte_size;
662
+
663
+ GetNArray(self,na);
664
+ if (NA_TYPE(na) == NARRAY_VIEW_T) {
665
+ self = NA_VIEW_DATA(na);
666
+ GetNArray(self,na);
667
+ }
668
+
669
+ ptr = NA_DATA_PTR(na);
670
+ if (ptr == NULL) {
671
+ return;
672
+ }
673
+
674
+ if (NA_DATA_OWNED(na)) {
675
+ return;
676
+ }
677
+
678
+ velmsz = rb_const_get(rb_obj_class(self), id_element_byte_size);
679
+ if (FIXNUM_P(velmsz)) {
680
+ byte_size = NA_SIZE(na) * NUM2SIZET(velmsz);
681
+ } else {
682
+ byte_size = ceil(NA_SIZE(na) * NUM2DBL(velmsz));
683
+ }
684
+ NA_DATA_PTR(na) = NULL;
685
+ rb_funcall(self, id_allocate, 0);
686
+ memcpy(NA_DATA_PTR(na), ptr, byte_size);
687
+ rb_ivar_set(self, id_source, Qnil);
688
+ }
689
+
603
690
  static char *
604
691
  na_get_pointer_for_rw(VALUE self, int flag)
605
692
  {
@@ -615,6 +702,9 @@ na_get_pointer_for_rw(VALUE self, int flag)
615
702
 
616
703
  switch(NA_TYPE(na)) {
617
704
  case NARRAY_DATA_T:
705
+ if (flag & WRITE) {
706
+ na_pointer_copy_on_write(self);
707
+ }
618
708
  ptr = NA_DATA_PTR(na);
619
709
  if (NA_SIZE(na) > 0 && ptr == NULL) {
620
710
  if (flag & READ) {
@@ -631,6 +721,9 @@ na_get_pointer_for_rw(VALUE self, int flag)
631
721
  if ((flag & WRITE) && OBJ_FROZEN(obj)) {
632
722
  rb_raise(rb_eRuntimeError, "cannot write to frozen NArray.");
633
723
  }
724
+ if (flag & WRITE) {
725
+ na_pointer_copy_on_write(self);
726
+ }
634
727
  GetNArray(obj,na);
635
728
  switch(NA_TYPE(na)) {
636
729
  case NARRAY_DATA_T:
@@ -1255,7 +1348,6 @@ nary_s_from_binary(int argc, VALUE *argv, VALUE type)
1255
1348
  {
1256
1349
  size_t len, str_len, byte_size;
1257
1350
  size_t *shape;
1258
- char *ptr;
1259
1351
  int i, nd, narg;
1260
1352
  VALUE vstr, vshape, vna;
1261
1353
  VALUE velmsz;
@@ -1273,8 +1365,8 @@ nary_s_from_binary(int argc, VALUE *argv, VALUE type)
1273
1365
  break;
1274
1366
  case T_ARRAY:
1275
1367
  nd = RARRAY_LEN(vshape);
1276
- if (nd == 0 || nd > NA_MAX_DIMENSION) {
1277
- rb_raise(nary_eDimensionError,"too long or empty shape (%d)", nd);
1368
+ if (nd > NA_MAX_DIMENSION) {
1369
+ rb_raise(nary_eDimensionError,"shape exceeds max dimension");
1278
1370
  }
1279
1371
  shape = ALLOCA_N(size_t,nd);
1280
1372
  len = 1;
@@ -1310,9 +1402,13 @@ nary_s_from_binary(int argc, VALUE *argv, VALUE type)
1310
1402
  }
1311
1403
 
1312
1404
  vna = nary_new(type, nd, shape);
1313
- ptr = na_get_pointer_for_write(vna);
1314
-
1315
- memcpy(ptr, RSTRING_PTR(vstr), byte_size);
1405
+ if (OBJ_FROZEN(vstr)) {
1406
+ na_set_pointer(vna, RSTRING_PTR(vstr), byte_size);
1407
+ rb_ivar_set(vna, id_source, vstr);
1408
+ } else {
1409
+ void *ptr = na_get_pointer_for_write(vna);
1410
+ memcpy(ptr, RSTRING_PTR(vstr), byte_size);
1411
+ }
1316
1412
 
1317
1413
  return vna;
1318
1414
  }
@@ -1328,7 +1424,6 @@ static VALUE
1328
1424
  nary_store_binary(int argc, VALUE *argv, VALUE self)
1329
1425
  {
1330
1426
  size_t size, str_len, byte_size, offset;
1331
- char *ptr;
1332
1427
  int narg;
1333
1428
  VALUE vstr, voffset;
1334
1429
  VALUE velmsz;
@@ -1358,8 +1453,13 @@ nary_store_binary(int argc, VALUE *argv, VALUE self)
1358
1453
  rb_raise(rb_eArgError, "string is too short to store");
1359
1454
  }
1360
1455
 
1361
- ptr = na_get_pointer_for_write(self);
1362
- memcpy(ptr, RSTRING_PTR(vstr)+offset, byte_size);
1456
+ if (OBJ_FROZEN(vstr)) {
1457
+ na_set_pointer(self, RSTRING_PTR(vstr)+offset, byte_size);
1458
+ rb_ivar_set(self, id_source, vstr);
1459
+ } else {
1460
+ void *ptr = na_get_pointer_for_write(self);
1461
+ memcpy(ptr, RSTRING_PTR(vstr)+offset, byte_size);
1462
+ }
1363
1463
 
1364
1464
  return SIZET2NUM(byte_size);
1365
1465
  }
@@ -1465,6 +1565,7 @@ nary_marshal_load(VALUE self, VALUE a)
1465
1565
  ptr = na_get_pointer_for_write(self);
1466
1566
  memcpy(ptr, RARRAY_PTR(v), NA_SIZE(na)*sizeof(VALUE));
1467
1567
  } else {
1568
+ rb_str_freeze(v);
1468
1569
  nary_store_binary(1,&v,self);
1469
1570
  if (TEST_BYTE_SWAPPED(self)) {
1470
1571
  rb_funcall(na_inplace(self),id_to_host,0);
@@ -1583,8 +1684,13 @@ na_get_reduce_flag_from_axes(VALUE na_obj, VALUE axes)
1583
1684
  len = 1;
1584
1685
  step = 0;
1585
1686
  //printf("beg=%d step=%d len=%d\n",beg,step,len);
1586
- } else if (rb_obj_is_kind_of(v,rb_cRange) ||
1587
- rb_obj_is_kind_of(v,na_cStep)) {
1687
+ } else if (rb_obj_is_kind_of(v,rb_cRange)
1688
+ #ifdef HAVE_RB_ARITHMETIC_SEQUENCE_EXTRACT
1689
+ || rb_obj_is_kind_of(v,rb_cArithSeq)
1690
+ #else
1691
+ || rb_obj_is_kind_of(v,rb_cEnumerator)
1692
+ #endif
1693
+ ) {
1588
1694
  nary_step_array_index( v, ndim, &len, &beg, &step );
1589
1695
  } else {
1590
1696
  rb_raise(nary_eDimensionError, "invalid dimension argument %s",
@@ -1870,6 +1976,9 @@ na_equal(VALUE self, volatile VALUE other)
1870
1976
  return Qfalse;
1871
1977
  }
1872
1978
  }
1979
+ if (na1->size == 0) {
1980
+ return Qtrue;
1981
+ }
1873
1982
  vbool = rb_funcall(self, id_eq, 1, other);
1874
1983
  return (rb_funcall(vbool, id_count_false, 0)==INT2FIX(0)) ? Qtrue : Qfalse;
1875
1984
  }
@@ -1896,6 +2005,9 @@ Init_narray()
1896
2005
  rb_require("complex");
1897
2006
  rb_cComplex = rb_const_get(rb_cObject, rb_intern("Complex"));
1898
2007
  #endif
2008
+ #ifdef HAVE_RB_ARITHMETIC_SEQUENCE_EXTRACT
2009
+ rb_cArithSeq = rb_path2class("Enumerator::ArithmeticSequence");
2010
+ #endif
1899
2011
 
1900
2012
  rb_define_const(cNArray, "VERSION", rb_str_new2(NARRAY_VERSION));
1901
2013
 
@@ -1993,13 +2105,16 @@ Init_narray()
1993
2105
  id_axis = rb_intern("axis");
1994
2106
  id_nan = rb_intern("nan");
1995
2107
  id_keepdims = rb_intern("keepdims");
2108
+ id_source = rb_intern("source");
1996
2109
 
1997
2110
  sym_reduce = ID2SYM(rb_intern("reduce"));
1998
2111
  sym_option = ID2SYM(rb_intern("option"));
1999
2112
  sym_loop_opt = ID2SYM(rb_intern("loop_opt"));
2000
2113
  sym_init = ID2SYM(rb_intern("init"));
2001
2114
 
2115
+ #ifndef HAVE_RB_ARITHMETIC_SEQUENCE_EXTRACT
2002
2116
  Init_nary_step();
2117
+ #endif
2003
2118
  Init_nary_index();
2004
2119
 
2005
2120
  Init_nary_data();
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  ndloop.c
3
- Numerical Array Extension for Ruby
4
- (C) Copyright 1999-2017 by Masahiro TANAKA
3
+ Ruby/Numo::NArray - Numerical Array class for Ruby
4
+ Copyright (C) 1999-2020 Masahiro TANAKA
5
5
  */
6
6
 
7
7
  #include <ruby.h>
@@ -164,7 +164,7 @@ print_ndloop(na_md_loop_t *lp) {
164
164
  for (i=0; i<lp->user.ndim; i++) {
165
165
  printf(" &user.args[%d].iter[%d] = 0x%"SZF"x\n", j,i, (size_t)&lp->user.args[j].iter[i]);
166
166
  printf(" user.args[%d].iter[%d].pos = %"SZF"u\n", j,i, lp->user.args[j].iter[i].pos);
167
- printf(" user.args[%d].iter[%d].step = %"SZF"u\n", j,i, lp->user.args[j].iter[i].step);
167
+ printf(" user.args[%d].iter[%d].step = %"SZF"d\n", j,i, lp->user.args[j].iter[i].step);
168
168
  printf(" user.args[%d].iter[%d].idx = 0x%"SZF"x\n", j,i, (size_t)lp->user.args[j].iter[i].idx);
169
169
  }
170
170
  }
@@ -174,7 +174,7 @@ print_ndloop(na_md_loop_t *lp) {
174
174
  for (i=0; i<=nd; i++) {
175
175
  printf(" &xargs[%d].iter[%d] = 0x%"SZF"x\n", j,i, (size_t)&LITER(lp,i,j));
176
176
  printf(" xargs[%d].iter[%d].pos = %"SZF"u\n", j,i, LITER(lp,i,j).pos);
177
- printf(" xargs[%d].iter[%d].step = %"SZF"u\n", j,i, LITER(lp,i,j).step);
177
+ printf(" xargs[%d].iter[%d].step = %"SZF"d\n", j,i, LITER(lp,i,j).step);
178
178
  printf(" xargs[%d].iter[%d].idx = 0x%"SZF"x\n", j,i, (size_t)LITER(lp,i,j).idx);
179
179
  }
180
180
  printf(" xargs[%d].bufcp = 0x%"SZF"x\n", j, (size_t)lp->xargs[j].bufcp);
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  intern.h
3
- Numerical Array Extension for Ruby
4
- (C) Copyright 1999-2017 by Masahiro TANAKA
3
+ Ruby/Numo::NArray - Numerical Array class for Ruby
4
+ Copyright (C) 1999-2020 Masahiro TANAKA
5
5
  */
6
6
  #ifndef INTERN_H
7
7
  #define INTERN_H
@@ -99,6 +99,7 @@ bool nary_test_reduce(VALUE reduce, int dim);
99
99
 
100
100
  void nary_step_array_index(VALUE self, size_t ary_size, size_t *plen, ssize_t *pbeg, ssize_t *pstep);
101
101
  void nary_step_sequence(VALUE self, size_t *plen, double *pbeg, double *pstep);
102
+ void na_parse_enumerator_step(VALUE enum_obj, VALUE *pstep );
102
103
 
103
104
  // used in aref, aset
104
105
  #define na_get_result_dimension nary_get_result_dimension
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  narray.h
3
- Numerical Array Extension for Ruby
4
- (C) Copyright 1999-2017 by Masahiro TANAKA
3
+ Ruby/Numo::NArray - Numerical Array class for Ruby
4
+ Copyright (C) 1999-2020 Masahiro TANAKA
5
5
  */
6
6
  #ifndef NARRAY_H
7
7
  #define NARRAY_H
@@ -13,8 +13,8 @@ extern "C" {
13
13
  #endif
14
14
  #endif
15
15
 
16
- #define NARRAY_VERSION "0.9.1.4"
17
- #define NARRAY_VERSION_CODE 914
16
+ #define NARRAY_VERSION "0.9.1.9"
17
+ #define NARRAY_VERSION_CODE 919
18
18
 
19
19
  #include <math.h>
20
20
  #include "numo/compat.h"
@@ -81,6 +81,8 @@ extern "C" {
81
81
  # ifndef PRIu64
82
82
  # define PRIu64 "llu"
83
83
  # endif
84
+ #else
85
+ # error ---->> numo/narray requires 8-byte integer. <<----
84
86
  #endif
85
87
 
86
88
  #if SIZEOF_LONG==4
@@ -96,22 +98,22 @@ extern "C" {
96
98
  # endif
97
99
  #elif SIZEOF_INT==4
98
100
  # define NUM2INT32(x) NUM2INT(x)
99
- # define INT322NUM(x) INT2NUM(x)
100
101
  # define NUM2UINT32(x) NUM2UINT(x)
101
- # define UINT322NUM(x) UINT2NUM(x)
102
+ # if SIZEOF_LONG > 4
103
+ # define INT322NUM(x) INT2FIX(x)
104
+ # define UINT322NUM(x) INT2FIX(x)
105
+ # else
106
+ # define INT322NUM(x) INT2NUM(x)
107
+ # define UINT322NUM(x) UINT2NUM(x)
108
+ # endif
102
109
  # ifndef PRId32
103
110
  # define PRId32 "d"
104
111
  # endif
105
112
  # ifndef PRIu32
106
113
  # define PRIu32 "u"
107
114
  # endif
108
- #endif
109
-
110
- #if SIZEOF_VALUE > 4
111
- # undef INT322NUM
112
- # undef UINT322NUM
113
- # define INT322NUM(x) INT2FIX(x)
114
- # define UINT322NUM(x) INT2FIX(x)
115
+ #else
116
+ # error ---->> numo/narray requires 4-byte integer. <<----
115
117
  #endif
116
118
 
117
119
  #ifndef HAVE_TYPE_BOOL
@@ -165,10 +167,12 @@ extern VALUE numo_cUInt32;
165
167
  extern VALUE numo_cUInt16;
166
168
  extern VALUE numo_cUInt8;
167
169
  extern VALUE numo_cRObject;
168
- extern VALUE na_cStep;
169
170
  #ifndef HAVE_RB_CCOMPLEX
170
171
  extern VALUE rb_cComplex;
171
172
  #endif
173
+ #ifdef HAVE_RB_ARITHMETIC_SEQUENCE_EXTRACT
174
+ extern VALUE rb_cArithSeq;
175
+ #endif
172
176
 
173
177
  extern VALUE sym_reduce;
174
178
  extern VALUE sym_option;
@@ -193,6 +197,7 @@ typedef struct RNArray {
193
197
  typedef struct RNArrayData {
194
198
  narray_t base;
195
199
  char *ptr;
200
+ bool owned;
196
201
  } narray_data_t;
197
202
 
198
203
 
@@ -234,6 +239,23 @@ typedef struct {
234
239
  unsigned int element_stride;
235
240
  } narray_type_info_t;
236
241
 
242
+ // from ruby/enumerator.c
243
+ struct enumerator {
244
+ VALUE obj;
245
+ ID meth;
246
+ VALUE args;
247
+ // use only above in this source
248
+ VALUE fib;
249
+ VALUE dst;
250
+ VALUE lookahead;
251
+ VALUE feedvalue;
252
+ VALUE stop_exc;
253
+ VALUE size;
254
+ // incompatible below depending on ruby version
255
+ //VALUE procs; // ruby 2.4
256
+ //rb_enumerator_size_func *size_fn; // ruby 2.1-2.4
257
+ //VALUE (*size_fn)(ANYARGS); // ruby 2.0
258
+ };
237
259
 
238
260
  static inline narray_t *
239
261
  na_get_narray_t(VALUE obj)
@@ -304,6 +326,7 @@ _na_get_narray_t(VALUE obj, unsigned char na_type)
304
326
  #define NA_DATA(na) ((narray_data_t*)(na))
305
327
  #define NA_VIEW(na) ((narray_view_t*)(na))
306
328
  #define NA_DATA_PTR(na) (NA_DATA(na)->ptr)
329
+ #define NA_DATA_OWNED(na) (NA_DATA(na)->owned)
307
330
  #define NA_VIEW_DATA(na) (NA_VIEW(na)->data)
308
331
  #define NA_VIEW_OFFSET(na) (NA_VIEW(na)->offset)
309
332
  #define NA_VIEW_STRIDX(na) (NA_VIEW(na)->stridx)