numo-narray-alt 0.9.4 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +9 -3
- data/Rakefile +8 -0
- data/ext/numo/narray/SFMT-params19937.h +16 -12
- data/ext/numo/narray/SFMT.c +12 -5
- data/ext/numo/narray/array.c +25 -19
- data/ext/numo/narray/data.c +74 -70
- data/ext/numo/narray/extconf.rb +1 -0
- data/ext/numo/narray/index.c +49 -26
- data/ext/numo/narray/kwargs.c +11 -9
- data/ext/numo/narray/math.c +4 -2
- data/ext/numo/narray/narray.c +17 -10
- data/ext/numo/narray/ndloop.c +52 -63
- data/ext/numo/narray/numo/intern.h +9 -3
- data/ext/numo/narray/numo/narray.h +20 -20
- data/ext/numo/narray/numo/ndloop.h +1 -1
- data/ext/numo/narray/numo/template.h +85 -81
- data/ext/numo/narray/numo/types/complex.h +7 -3
- data/ext/numo/narray/numo/types/complex_macro.h +27 -25
- data/ext/numo/narray/numo/types/float_macro.h +20 -17
- data/ext/numo/narray/numo/types/real_accum.h +22 -22
- data/ext/numo/narray/numo/types/robj_macro.h +19 -12
- data/ext/numo/narray/numo/types/xint_macro.h +9 -8
- data/ext/numo/narray/src/t_bit.c +97 -88
- data/ext/numo/narray/src/t_dcomplex.c +336 -307
- data/ext/numo/narray/src/t_dfloat.c +522 -456
- data/ext/numo/narray/src/t_int16.c +351 -308
- data/ext/numo/narray/src/t_int32.c +351 -308
- data/ext/numo/narray/src/t_int64.c +351 -308
- data/ext/numo/narray/src/t_int8.c +309 -288
- data/ext/numo/narray/src/t_mean.c +105 -0
- data/ext/numo/narray/src/t_robject.c +323 -296
- data/ext/numo/narray/src/t_scomplex.c +327 -302
- data/ext/numo/narray/src/t_sfloat.c +515 -451
- data/ext/numo/narray/src/t_uint16.c +351 -308
- data/ext/numo/narray/src/t_uint32.c +351 -308
- data/ext/numo/narray/src/t_uint64.c +351 -308
- data/ext/numo/narray/src/t_uint8.c +311 -288
- data/ext/numo/narray/step.c +7 -2
- data/ext/numo/narray/struct.c +24 -22
- data/lib/numo/narray/extra.rb +66 -25
- data/numo-narray-alt.gemspec +38 -0
- metadata +7 -1
data/ext/numo/narray/kwargs.c
CHANGED
@@ -15,10 +15,10 @@ struct RBasicRaw {
|
|
15
15
|
VALUE klass;
|
16
16
|
};
|
17
17
|
|
18
|
-
#define RBASIC_SET_CLASS(obj, cls)
|
19
|
-
do {
|
20
|
-
VALUE _obj_ = (obj);
|
21
|
-
RB_OBJ_WRITE(_obj_, &((struct RBasicRaw*)(_obj_))->klass, cls);
|
18
|
+
#define RBASIC_SET_CLASS(obj, cls) \
|
19
|
+
do { \
|
20
|
+
VALUE _obj_ = (obj); \
|
21
|
+
RB_OBJ_WRITE(_obj_, &((struct RBasicRaw*)(_obj_))->klass, cls); \
|
22
22
|
} while (0)
|
23
23
|
|
24
24
|
/* from class.c */
|
@@ -69,7 +69,7 @@ static int separate_symbol(st_data_t key, st_data_t value, st_data_t arg) {
|
|
69
69
|
|
70
70
|
VALUE
|
71
71
|
rb_extract_keywords(VALUE* orighash) {
|
72
|
-
VALUE parthash[2] = {0, 0};
|
72
|
+
VALUE parthash[2] = { 0, 0 };
|
73
73
|
VALUE hash = *orighash;
|
74
74
|
|
75
75
|
if (RHASH_EMPTY_P(hash)) {
|
@@ -84,15 +84,17 @@ rb_extract_keywords(VALUE* orighash) {
|
|
84
84
|
return parthash[0];
|
85
85
|
}
|
86
86
|
|
87
|
-
int rb_get_kwargs(
|
87
|
+
int rb_get_kwargs(
|
88
|
+
VALUE keyword_hash, const ID* table, int required, int optional, VALUE* values
|
89
|
+
) {
|
88
90
|
int i = 0, j;
|
89
91
|
int rest = 0;
|
90
92
|
VALUE missing = Qnil;
|
91
93
|
st_data_t key;
|
92
94
|
|
93
|
-
#define extract_kwarg(keyword, val)
|
94
|
-
(key = (st_data_t)(keyword),
|
95
|
-
|
95
|
+
#define extract_kwarg(keyword, val) \
|
96
|
+
(key = (st_data_t)(keyword), values ? st_delete(rb_hash_tbl_raw(keyword_hash), &key, (val)) \
|
97
|
+
: st_lookup(rb_hash_tbl_raw(keyword_hash), key, (val)))
|
96
98
|
|
97
99
|
if (NIL_P(keyword_hash)) keyword_hash = 0;
|
98
100
|
|
data/ext/numo/narray/math.c
CHANGED
@@ -40,8 +40,10 @@ static VALUE nary_math_cast2(VALUE type1, VALUE type2) {
|
|
40
40
|
if (RTEST(rb_class_inherited_p(type2, cNArray))) {
|
41
41
|
return nary_type_s_upcast(type2, type1);
|
42
42
|
}
|
43
|
-
if (RTEST(rb_class_inherited_p(type1, rb_cNumeric)) &&
|
44
|
-
|
43
|
+
if (RTEST(rb_class_inherited_p(type1, rb_cNumeric)) &&
|
44
|
+
RTEST(rb_class_inherited_p(type2, rb_cNumeric))) {
|
45
|
+
if (RTEST(rb_class_inherited_p(type1, rb_cComplex)) ||
|
46
|
+
RTEST(rb_class_inherited_p(type2, rb_cComplex))) {
|
45
47
|
return rb_cComplex;
|
46
48
|
}
|
47
49
|
return rb_cFloat;
|
data/ext/numo/narray/narray.c
CHANGED
@@ -77,6 +77,8 @@ void Init_nary_math();
|
|
77
77
|
void Init_nary_rand();
|
78
78
|
void Init_nary_array();
|
79
79
|
void Init_nary_struct();
|
80
|
+
// define mean method for integer array
|
81
|
+
void Init_nary_mean();
|
80
82
|
|
81
83
|
const rb_data_type_t na_data_type = {
|
82
84
|
"Numo::NArray",
|
@@ -857,7 +859,8 @@ void na_copy_flags(VALUE src, VALUE dst) {
|
|
857
859
|
na2->flag[0] = na1->flag[0];
|
858
860
|
// na2->flag[1] = NA_FL1_INIT;
|
859
861
|
|
860
|
-
RBASIC(dst)->flags |= (RBASIC(src)->flags) & (FL_USER1 | FL_USER2 | FL_USER3 | FL_USER4 |
|
862
|
+
RBASIC(dst)->flags |= (RBASIC(src)->flags) & (FL_USER1 | FL_USER2 | FL_USER3 | FL_USER4 |
|
863
|
+
FL_USER5 | FL_USER6 | FL_USER7);
|
861
864
|
}
|
862
865
|
|
863
866
|
// fix name, ex, allow_stride_for_flatten_view
|
@@ -1423,10 +1426,12 @@ static VALUE nary_marshal_load(VALUE self, VALUE a) {
|
|
1423
1426
|
rb_raise(rb_eArgError, "marshal array size should be 4");
|
1424
1427
|
}
|
1425
1428
|
if (RARRAY_AREF(a, 0) != INT2FIX(1)) {
|
1426
|
-
rb_raise(
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1429
|
+
rb_raise(
|
1430
|
+
rb_eArgError,
|
1431
|
+
"NArray marshal version %d is not supported "
|
1432
|
+
"(only version 1)",
|
1433
|
+
NUM2INT(RARRAY_AREF(a, 0))
|
1434
|
+
);
|
1430
1435
|
}
|
1431
1436
|
na_initialize(self, RARRAY_AREF(a, 1));
|
1432
1437
|
NA_FL0_SET(self, FIX2INT(RARRAY_AREF(a, 2)));
|
@@ -1538,7 +1543,6 @@ static VALUE na_get_reduce_flag_from_axes(VALUE na_obj, VALUE axes) {
|
|
1538
1543
|
narg = RARRAY_LEN(axes);
|
1539
1544
|
for (i = 0; i < narg; i++) {
|
1540
1545
|
v = RARRAY_AREF(axes, i);
|
1541
|
-
// printf("argv[%d]=",i);rb_p(v);
|
1542
1546
|
if (TYPE(v) == T_FIXNUM) {
|
1543
1547
|
beg = FIX2INT(v);
|
1544
1548
|
if (beg < 0) beg += ndim;
|
@@ -1547,7 +1551,6 @@ static VALUE na_get_reduce_flag_from_axes(VALUE na_obj, VALUE axes) {
|
|
1547
1551
|
}
|
1548
1552
|
len = 1;
|
1549
1553
|
step = 0;
|
1550
|
-
// printf("beg=%d step=%d len=%d\n",beg,step,len);
|
1551
1554
|
} else if (rb_obj_is_kind_of(v, rb_cRange)
|
1552
1555
|
#ifdef HAVE_RB_ARITHMETIC_SEQUENCE_EXTRACT
|
1553
1556
|
|| rb_obj_is_kind_of(v, rb_cArithSeq)
|
@@ -1611,12 +1614,14 @@ nary_reduce_options(VALUE axes, VALUE* opts, int naryc, VALUE* naryv, ndfunc_t*
|
|
1611
1614
|
}
|
1612
1615
|
|
1613
1616
|
VALUE
|
1614
|
-
nary_reduce_dimension(
|
1617
|
+
nary_reduce_dimension(
|
1618
|
+
int argc, VALUE* argv, int naryc, VALUE* naryv, ndfunc_t* ndf, na_iter_func_t iter_nan
|
1619
|
+
) {
|
1615
1620
|
long narg;
|
1616
1621
|
VALUE axes;
|
1617
1622
|
VALUE kw_hash = Qnil;
|
1618
|
-
ID kw_table[3] = {id_axis, id_keepdims, id_nan};
|
1619
|
-
VALUE opts[3] = {Qundef, Qundef, Qundef};
|
1623
|
+
ID kw_table[3] = { id_axis, id_keepdims, id_nan };
|
1624
|
+
VALUE opts[3] = { Qundef, Qundef, Qundef };
|
1620
1625
|
|
1621
1626
|
narg = rb_scan_args(argc, argv, "*:", &axes, &kw_hash);
|
1622
1627
|
rb_get_kwargs(kw_hash, kw_table, 0, 3, opts);
|
@@ -1968,6 +1973,8 @@ void Init_narray(void) {
|
|
1968
1973
|
Init_numo_bit();
|
1969
1974
|
Init_numo_robject();
|
1970
1975
|
|
1976
|
+
Init_nary_mean();
|
1977
|
+
|
1971
1978
|
Init_nary_math();
|
1972
1979
|
|
1973
1980
|
Init_nary_rand();
|
data/ext/numo/narray/ndloop.c
CHANGED
@@ -157,10 +157,19 @@ static void print_ndloop(na_md_loop_t* lp) {
|
|
157
157
|
printf(" user.args[%d].iter = 0x%" SZF "x\n", j, (size_t)lp->user.args[j].iter);
|
158
158
|
if (lp->user.args[j].iter) {
|
159
159
|
for (i = 0; i < lp->user.ndim; i++) {
|
160
|
-
printf(
|
161
|
-
|
162
|
-
|
163
|
-
printf(
|
160
|
+
printf(
|
161
|
+
" &user.args[%d].iter[%d] = 0x%" SZF "x\n", j, i, (size_t)&lp->user.args[j].iter[i]
|
162
|
+
);
|
163
|
+
printf(
|
164
|
+
" user.args[%d].iter[%d].pos = %" SZF "u\n", j, i, lp->user.args[j].iter[i].pos
|
165
|
+
);
|
166
|
+
printf(
|
167
|
+
" user.args[%d].iter[%d].step = %" SZF "d\n", j, i, lp->user.args[j].iter[i].step
|
168
|
+
);
|
169
|
+
printf(
|
170
|
+
" user.args[%d].iter[%d].idx = 0x%" SZF "x\n", j, i,
|
171
|
+
(size_t)lp->user.args[j].iter[i].idx
|
172
|
+
);
|
164
173
|
}
|
165
174
|
}
|
166
175
|
//
|
@@ -177,10 +186,18 @@ static void print_ndloop(na_md_loop_t* lp) {
|
|
177
186
|
printf(" xargs[%d].bufcp->ndim = %d\n", j, lp->xargs[j].bufcp->ndim);
|
178
187
|
printf(" xargs[%d].bufcp->elmsz = %" SZF "d\n", j, lp->xargs[j].bufcp->elmsz);
|
179
188
|
printf(" xargs[%d].bufcp->n = 0x%" SZF "x\n", j, (size_t)lp->xargs[j].bufcp->n);
|
180
|
-
printf(
|
181
|
-
|
182
|
-
|
183
|
-
printf(
|
189
|
+
printf(
|
190
|
+
" xargs[%d].bufcp->src_ptr = 0x%" SZF "x\n", j, (size_t)lp->xargs[j].bufcp->src_ptr
|
191
|
+
);
|
192
|
+
printf(
|
193
|
+
" xargs[%d].bufcp->buf_ptr = 0x%" SZF "x\n", j, (size_t)lp->xargs[j].bufcp->buf_ptr
|
194
|
+
);
|
195
|
+
printf(
|
196
|
+
" xargs[%d].bufcp->src_iter = 0x%" SZF "x\n", j, (size_t)lp->xargs[j].bufcp->src_iter
|
197
|
+
);
|
198
|
+
printf(
|
199
|
+
" xargs[%d].bufcp->buf_iter = 0x%" SZF "x\n", j, (size_t)lp->xargs[j].bufcp->buf_iter
|
200
|
+
);
|
184
201
|
}
|
185
202
|
}
|
186
203
|
printf("}\n");
|
@@ -295,8 +312,10 @@ static void ndloop_find_max_dimension(na_md_loop_t* lp, ndfunc_t* nf, VALUE args
|
|
295
312
|
loop_nd
|
296
313
|
*/
|
297
314
|
|
298
|
-
static void ndloop_alloc(
|
299
|
-
|
315
|
+
static void ndloop_alloc(
|
316
|
+
na_md_loop_t* lp, ndfunc_t* nf, VALUE args, void* opt_ptr, unsigned int copy_flag,
|
317
|
+
void (*loop_func)(ndfunc_t*, na_md_loop_t*)
|
318
|
+
) {
|
300
319
|
int i, j;
|
301
320
|
int narg;
|
302
321
|
int max_nd;
|
@@ -422,7 +441,6 @@ static VALUE ndloop_release(VALUE vlp) {
|
|
422
441
|
}
|
423
442
|
}
|
424
443
|
for (j = 0; j < lp->narg; j++) {
|
425
|
-
// printf("lp->xargs[%d].bufcp=%lx\n",j,(size_t)(lp->xargs[j].bufcp));
|
426
444
|
if (lp->xargs[j].bufcp) {
|
427
445
|
xfree(lp->xargs[j].bufcp->buf_iter);
|
428
446
|
xfree(lp->xargs[j].bufcp->buf_ptr);
|
@@ -456,7 +474,10 @@ static void ndloop_check_shape(na_md_loop_t* lp, int nf_dim, narray_t* na) {
|
|
456
474
|
lp->n[i] = n;
|
457
475
|
} else if (lp->n[i] != n) {
|
458
476
|
// inconsistent array shape
|
459
|
-
rb_raise(
|
477
|
+
rb_raise(
|
478
|
+
nary_eShapeError, "shape1[%d](=%" SZF "u) != shape2[%d](=%" SZF "u)", i, lp->n[i], k,
|
479
|
+
n
|
480
|
+
);
|
460
481
|
}
|
461
482
|
}
|
462
483
|
}
|
@@ -498,7 +519,6 @@ static void ndloop_set_stepidx(na_md_loop_t* lp, int j, VALUE vna, int* dim_map,
|
|
498
519
|
n = na->shape[k];
|
499
520
|
if (n > 1 || nd > 0) {
|
500
521
|
i = dim_map[k];
|
501
|
-
// printf("n=%d k=%d i=%d\n",n,k,i);
|
502
522
|
LITER(lp, i, j).step = s;
|
503
523
|
// LITER(lp,i,j).idx = NULL;
|
504
524
|
}
|
@@ -561,16 +581,17 @@ static void ndloop_init_args(ndfunc_t* nf, na_md_loop_t* lp, VALUE args) {
|
|
561
581
|
GetNArray(v, na);
|
562
582
|
nf_dim = nf->ain[j].dim;
|
563
583
|
if (nf_dim > na->ndim) {
|
564
|
-
rb_raise(
|
565
|
-
|
566
|
-
|
567
|
-
|
584
|
+
rb_raise(
|
585
|
+
nary_eDimensionError,
|
586
|
+
"requires >= %d-dimensioal array "
|
587
|
+
"while %d-dimensional array is given",
|
588
|
+
nf_dim, na->ndim
|
589
|
+
);
|
568
590
|
}
|
569
591
|
ndloop_check_shape(lp, nf_dim, na);
|
570
592
|
dim_beg = lp->ndim + nf->ain[j].dim - na->ndim;
|
571
593
|
for (i = 0; i < na->ndim; i++) {
|
572
594
|
dim_map[i] = lp->trans_map[i + dim_beg];
|
573
|
-
// printf("dim_map[%d]=%d na->shape[%d]=%d\n",i,dim_map[i],i,na->shape[i]);
|
574
595
|
}
|
575
596
|
if (nf->ain[j].type == OVERWRITE) {
|
576
597
|
lp->xargs[j].flag = flag = NDL_WRITE;
|
@@ -624,7 +645,9 @@ static int ndloop_check_inplace(VALUE type, int na_ndim, size_t* na_shape, VALUE
|
|
624
645
|
return 1;
|
625
646
|
}
|
626
647
|
|
627
|
-
static VALUE ndloop_find_inplace(
|
648
|
+
static VALUE ndloop_find_inplace(
|
649
|
+
ndfunc_t* nf, na_md_loop_t* lp, VALUE type, int na_ndim, size_t* na_shape, VALUE args
|
650
|
+
) {
|
628
651
|
int j;
|
629
652
|
VALUE v;
|
630
653
|
|
@@ -673,7 +696,8 @@ static VALUE ndloop_get_arg_type(ndfunc_t* nf, VALUE args, VALUE t) {
|
|
673
696
|
return t;
|
674
697
|
}
|
675
698
|
|
676
|
-
static VALUE
|
699
|
+
static VALUE
|
700
|
+
ndloop_set_output_narray(ndfunc_t* nf, na_md_loop_t* lp, int k, VALUE type, VALUE args) {
|
677
701
|
int i, j;
|
678
702
|
int na_ndim;
|
679
703
|
int lp_dim;
|
@@ -687,14 +711,11 @@ static VALUE ndloop_set_output_narray(ndfunc_t* nf, na_md_loop_t* lp, int k, VAL
|
|
687
711
|
na_shape = ALLOCA_N(size_t, max_nd);
|
688
712
|
dim_map = ALLOCA_N(int, max_nd);
|
689
713
|
|
690
|
-
// printf("max_nd=%d lp->ndim=%d\n",max_nd,lp->ndim);
|
691
|
-
|
692
714
|
// md-loop shape
|
693
715
|
na_ndim = 0;
|
694
716
|
for (i = 0; i < lp->ndim; i++) {
|
695
717
|
// na_shape[i] == lp->n[lp->trans_map[i]]
|
696
718
|
lp_dim = lp->trans_map[i];
|
697
|
-
// printf("i=%d lp_dim=%d\n",i,lp_dim);
|
698
719
|
if (NDF_TEST(nf, NDF_CUM)) { // cumulate with shape kept
|
699
720
|
na_shape[na_ndim] = lp->n[lp_dim];
|
700
721
|
} else if (na_test_reduce(lp->reduce, lp_dim)) { // accumulate dimension
|
@@ -706,7 +727,6 @@ static VALUE ndloop_set_output_narray(ndfunc_t* nf, na_md_loop_t* lp, int k, VAL
|
|
706
727
|
} else {
|
707
728
|
na_shape[na_ndim] = lp->n[lp_dim];
|
708
729
|
}
|
709
|
-
// printf("i=%d lp_dim=%d na_shape[%d]=%ld\n",i,lp_dim,i,na_shape[i]);
|
710
730
|
dim_map[na_ndim++] = lp_dim;
|
711
731
|
// dim_map[lp_dim] = na_ndim++;
|
712
732
|
}
|
@@ -789,13 +809,11 @@ static void ndfunc_contract_loop(na_md_loop_t* lp) {
|
|
789
809
|
redi = na_test_reduce(lp->reduce, 0);
|
790
810
|
|
791
811
|
// for (i=0; i<lp->ndim; i++) {
|
792
|
-
// printf("lp->n[%d]=%lu\n",i,lp->n[i]);
|
793
812
|
// }
|
794
813
|
|
795
814
|
for (i = 1; i < lp->ndim; i++) {
|
796
815
|
red0 = redi;
|
797
816
|
redi = na_test_reduce(lp->reduce, i);
|
798
|
-
// printf("contract i=%d reduce_cond=%d %d\n",i,red0,redi);
|
799
817
|
if (red0 != redi) {
|
800
818
|
continue;
|
801
819
|
}
|
@@ -808,7 +826,6 @@ static void ndfunc_contract_loop(na_md_loop_t* lp) {
|
|
808
826
|
}
|
809
827
|
}
|
810
828
|
if (success) {
|
811
|
-
// printf("contract i=%d-th and %d-th, lp->n[%d]=%"SZF"d, lp->n[%d]=%"SZF"d\n",
|
812
829
|
// i-1,i, i,lp->n[i], i-1,lp->n[i-1]);
|
813
830
|
// contract (i-1)-th and i-th dimension
|
814
831
|
lp->n[i] *= lp->n[i - 1];
|
@@ -816,7 +833,6 @@ static void ndfunc_contract_loop(na_md_loop_t* lp) {
|
|
816
833
|
for (k = i - 1; k > cnt; k--) {
|
817
834
|
lp->n[k] = lp->n[k - 1];
|
818
835
|
}
|
819
|
-
// printf("k=%d\n",k);
|
820
836
|
for (; k >= 0; k--) {
|
821
837
|
lp->n[k] = 1;
|
822
838
|
}
|
@@ -831,7 +847,6 @@ static void ndfunc_contract_loop(na_md_loop_t* lp) {
|
|
831
847
|
cnt++;
|
832
848
|
}
|
833
849
|
}
|
834
|
-
// printf("contract cnt=%d\n",cnt);
|
835
850
|
if (cnt > 0) {
|
836
851
|
for (j = 0; j < lp->narg; j++) {
|
837
852
|
LITER(lp, cnt, j).pos = LITER(lp, 0, j).pos;
|
@@ -839,7 +854,6 @@ static void ndfunc_contract_loop(na_md_loop_t* lp) {
|
|
839
854
|
}
|
840
855
|
lp->n = &(lp->n[cnt]);
|
841
856
|
lp->ndim -= cnt;
|
842
|
-
// for (i=0; i<lp->ndim; i++) {printf("lp->n[%d]=%lu\n",i,lp->n[i]);}
|
843
857
|
}
|
844
858
|
}
|
845
859
|
|
@@ -865,15 +879,12 @@ static void ndfunc_set_user_loop(ndfunc_t* nf, na_md_loop_t* lp) {
|
|
865
879
|
}
|
866
880
|
LARG(lp, j).ndim += ud;
|
867
881
|
LARG(lp, j).shape = &(lp->n[lp->ndim]);
|
868
|
-
// printf("LARG(lp,j).ndim=%d,LARG(lp,j).shape=%lx\n",LARG(lp,j).ndim,(size_t)LARG(lp,j).shape);
|
869
882
|
}
|
870
|
-
// printf("lp->reduce_dim=%d lp->user.ndim=%d lp->ndim=%d\n",lp->reduce_dim,lp->user.ndim,lp->ndim);
|
871
883
|
|
872
884
|
skip_ud:
|
873
885
|
lp->user.n = &(lp->n[lp->ndim]);
|
874
886
|
for (j = 0; j < lp->narg; j++) {
|
875
887
|
LARG(lp, j).iter = &LITER(lp, lp->ndim, j);
|
876
|
-
// printf("in ndfunc_set_user_loop: lp->user.args[%d].iter=%lx\n",j,(size_t)(LARG(lp,j).iter));
|
877
888
|
}
|
878
889
|
}
|
879
890
|
|
@@ -907,11 +918,9 @@ static void ndfunc_set_bufcp(na_md_loop_t* lp, unsigned int loop_spec) {
|
|
907
918
|
if (LARG(lp, j).shape) {
|
908
919
|
n = LARG(lp, j).shape[i];
|
909
920
|
} else {
|
910
|
-
// printf("shape is NULL\n");
|
911
921
|
n = lp->user.n[i];
|
912
922
|
}
|
913
923
|
stride = sz * n;
|
914
|
-
// printf("{j=%d,i=%d,ndim=%d,nd=%d,idx=%lx,step=%ld,n=%ld,sz=%ld,stride=%ld}\n",j,i,ndim,nd,(size_t)src_iter[i].idx,src_iter[i].step,n,sz,stride);
|
915
924
|
if (src_iter[i].idx) {
|
916
925
|
f |= 2; // INDEX LOOP
|
917
926
|
zero_step = 0;
|
@@ -931,7 +940,6 @@ static void ndfunc_set_bufcp(na_md_loop_t* lp, unsigned int loop_spec) {
|
|
931
940
|
}
|
932
941
|
sz = stride;
|
933
942
|
}
|
934
|
-
// printf("[j=%d f=%d loop_spec=%d zero_step=%d]\n",j,f,loop_spec,zero_step);
|
935
943
|
|
936
944
|
if (zero_step) {
|
937
945
|
// no buffer needed
|
@@ -942,7 +950,6 @@ static void ndfunc_set_bufcp(na_md_loop_t* lp, unsigned int loop_spec) {
|
|
942
950
|
|
943
951
|
// over loop_spec or reduce_loop is not contiguous
|
944
952
|
if (f & loop_spec || (lp->reduce_dim > 1 && ndim > 0)) {
|
945
|
-
// printf("(buf,nd=%d)",nd);
|
946
953
|
buf_iter = ALLOC_N(na_loop_iter_t, nd + 3);
|
947
954
|
buf_shape = ALLOC_N(size_t, nd);
|
948
955
|
buf_iter[nd].pos = 0;
|
@@ -967,10 +974,8 @@ static void ndfunc_set_bufcp(na_md_loop_t* lp, unsigned int loop_spec) {
|
|
967
974
|
LBUFCP(lp, j)->src_iter = src_iter;
|
968
975
|
LBUFCP(lp, j)->buf_iter = buf_iter;
|
969
976
|
LARG(lp, j).iter = buf_iter;
|
970
|
-
// printf("in ndfunc_set_bufcp(1): lp->user.args[%d].iter=%lx\n",j,(size_t)(LARG(lp,j).iter));
|
971
977
|
LBUFCP(lp, j)->src_ptr = LARG(lp, j).ptr;
|
972
978
|
LARG(lp, j).ptr = LBUFCP(lp, j)->buf_ptr = xmalloc(sz);
|
973
|
-
// printf("(LBUFCP(lp,%d)->buf_ptr=%lx)\n",j,(size_t)(LBUFCP(lp,j)->buf_ptr));
|
974
979
|
}
|
975
980
|
}
|
976
981
|
|
@@ -980,7 +985,6 @@ static void ndfunc_set_bufcp(na_md_loop_t* lp, unsigned int loop_spec) {
|
|
980
985
|
src_iter = LARG(lp,j).iter;
|
981
986
|
last_step = src_iter[ndim-1].step;
|
982
987
|
if (lp->reduce_dim>1) {
|
983
|
-
//printf("(reduce_dim=%d,ndim=%d,nd=%d,n=%ld,lst=%ld)\n",lp->reduce_dim,ndim,nd,n_total,last_step);
|
984
988
|
buf_iter = ALLOC_N(na_loop_iter_t,2);
|
985
989
|
buf_iter[0].pos = LARG(lp,j).iter[0].pos;
|
986
990
|
buf_iter[0].step = last_step;
|
@@ -989,7 +993,6 @@ static void ndfunc_set_bufcp(na_md_loop_t* lp, unsigned int loop_spec) {
|
|
989
993
|
buf_iter[1].step = 0;
|
990
994
|
buf_iter[1].idx = NULL;
|
991
995
|
LARG(lp,j).iter = buf_iter;
|
992
|
-
//printf("in ndfunc_set_bufcp(2): lp->user.args[%d].iter=%lx\n",j,(size_t)(LARG(lp,j).iter));
|
993
996
|
lp->xargs[j].free_user_iter = 1;
|
994
997
|
}
|
995
998
|
}
|
@@ -1018,7 +1021,6 @@ static void ndloop_copy_to_buffer(na_buffer_copy_t* lp) {
|
|
1018
1021
|
size_t buf_pos = 0;
|
1019
1022
|
DBG(size_t j);
|
1020
1023
|
|
1021
|
-
// printf("\nto_buf nd=%d elmsz=%ld\n",nd,elmsz);
|
1022
1024
|
DBG(printf("<to buf> ["));
|
1023
1025
|
// zero-dimension
|
1024
1026
|
if (nd == 0) {
|
@@ -1067,7 +1069,6 @@ static void ndloop_copy_from_buffer(na_buffer_copy_t* lp) {
|
|
1067
1069
|
size_t buf_pos = 0;
|
1068
1070
|
DBG(size_t j);
|
1069
1071
|
|
1070
|
-
// printf("\nfrom_buf nd=%d elmsz=%ld\n",nd,elmsz);
|
1071
1072
|
DBG(printf("<from buf> ["));
|
1072
1073
|
// zero-dimension
|
1073
1074
|
if (nd == 0) {
|
@@ -1173,7 +1174,6 @@ static VALUE ndloop_run(VALUE vlp) {
|
|
1173
1174
|
results = ndloop_set_output(nf, lp, args);
|
1174
1175
|
|
1175
1176
|
// if (na_debug_flag) {
|
1176
|
-
// printf("-- ndloop_set_output --\n");
|
1177
1177
|
// print_ndloop(lp);
|
1178
1178
|
// }
|
1179
1179
|
|
@@ -1181,7 +1181,6 @@ static VALUE ndloop_run(VALUE vlp) {
|
|
1181
1181
|
if (lp->loop_func == loop_narray) {
|
1182
1182
|
ndfunc_contract_loop(lp);
|
1183
1183
|
// if (na_debug_flag) {
|
1184
|
-
// printf("-- ndfunc_contract_loop --\n");
|
1185
1184
|
// print_ndloop(lp);
|
1186
1185
|
// }
|
1187
1186
|
}
|
@@ -1203,7 +1202,6 @@ static VALUE ndloop_run(VALUE vlp) {
|
|
1203
1202
|
(*(lp->loop_func))(nf, lp);
|
1204
1203
|
|
1205
1204
|
// if (na_debug_flag) {
|
1206
|
-
// printf("-- after loop --\n");
|
1207
1205
|
// print_ndloop(lp);
|
1208
1206
|
// }
|
1209
1207
|
|
@@ -1232,14 +1230,12 @@ static void loop_narray(ndfunc_t* nf, na_md_loop_t* lp) {
|
|
1232
1230
|
if (nd == 0) {
|
1233
1231
|
for (j = 0; j < lp->nin; j++) {
|
1234
1232
|
if (lp->xargs[j].bufcp) {
|
1235
|
-
// printf("copy_to_buffer j=%d\n",j);
|
1236
1233
|
ndloop_copy_to_buffer(lp->xargs[j].bufcp);
|
1237
1234
|
}
|
1238
1235
|
}
|
1239
1236
|
(*(nf->func))(&(lp->user));
|
1240
1237
|
for (j = 0; j < lp->narg; j++) {
|
1241
1238
|
if (lp->xargs[j].bufcp && (lp->xargs[j].flag & NDL_WRITE)) {
|
1242
|
-
// printf("copy_from_buffer j=%d\n",j);
|
1243
1239
|
// copy data to work buffer
|
1244
1240
|
ndloop_copy_from_buffer(lp->xargs[j].bufcp);
|
1245
1241
|
}
|
@@ -1262,14 +1258,12 @@ static void loop_narray(ndfunc_t* nf, na_md_loop_t* lp) {
|
|
1262
1258
|
} else {
|
1263
1259
|
LITER(lp, i + 1, j).pos = LITER(lp, i, j).pos + LITER(lp, i, j).step * c[i];
|
1264
1260
|
}
|
1265
|
-
// printf("j=%d c[i=%d]=%lu pos=%lu\n",j,i,c[i],LITER(lp,i+1,j).pos);
|
1266
1261
|
}
|
1267
1262
|
}
|
1268
1263
|
for (j = 0; j < lp->nin; j++) {
|
1269
1264
|
if (lp->xargs[j].bufcp) {
|
1270
1265
|
// copy data to work buffer
|
1271
1266
|
// cp lp->iter[j][nd..*] to lp->user.args[j].iter[0..*]
|
1272
|
-
// printf("copy_to_buffer j=%d\n",j);
|
1273
1267
|
ndloop_copy_to_buffer(lp->xargs[j].bufcp);
|
1274
1268
|
}
|
1275
1269
|
}
|
@@ -1277,7 +1271,6 @@ static void loop_narray(ndfunc_t* nf, na_md_loop_t* lp) {
|
|
1277
1271
|
for (j = 0; j < lp->narg; j++) {
|
1278
1272
|
if (lp->xargs[j].bufcp && (lp->xargs[j].flag & NDL_WRITE)) {
|
1279
1273
|
// copy data to work buffer
|
1280
|
-
// printf("copy_from_buffer j=%d\n",j);
|
1281
1274
|
ndloop_copy_from_buffer(lp->xargs[j].bufcp);
|
1282
1275
|
}
|
1283
1276
|
}
|
@@ -1494,8 +1487,8 @@ na_ndloop_inspect(VALUE nary, na_text_func_t func, VALUE opt) {
|
|
1494
1487
|
volatile VALUE args;
|
1495
1488
|
na_md_loop_t lp;
|
1496
1489
|
VALUE buf;
|
1497
|
-
ndfunc_arg_in_t ain[3] = {{Qnil, 0}, {sym_loop_opt}, {sym_option}};
|
1498
|
-
ndfunc_t nf = {(na_iter_func_t)func, NO_LOOP, 3, 0, ain, 0};
|
1490
|
+
ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { sym_loop_opt }, { sym_option } };
|
1491
|
+
ndfunc_t nf = { (na_iter_func_t)func, NO_LOOP, 3, 0, ain, 0 };
|
1499
1492
|
// nf = ndfunc_alloc(NULL, NO_LOOP, 1, 0, Qnil);
|
1500
1493
|
|
1501
1494
|
buf = na_info_str(nary);
|
@@ -1535,15 +1528,16 @@ static void loop_store_subnarray(ndfunc_t* nf, na_md_loop_t* lp, int i0, size_t*
|
|
1535
1528
|
}
|
1536
1529
|
GetNArray(a, na);
|
1537
1530
|
if (na->ndim != nd - i0 + 1) {
|
1538
|
-
rb_raise(
|
1539
|
-
|
1540
|
-
|
1541
|
-
|
1531
|
+
rb_raise(
|
1532
|
+
nary_eShapeError,
|
1533
|
+
"mismatched dimension of sub-narray: "
|
1534
|
+
"nd_src=%d, nd_dst=%d",
|
1535
|
+
na->ndim, nd - i0 + 1
|
1536
|
+
);
|
1542
1537
|
}
|
1543
1538
|
dim_map = ALLOCA_N(int, na->ndim);
|
1544
1539
|
for (i = 0; i < na->ndim; i++) {
|
1545
1540
|
dim_map[i] = lp->trans_map[i + i0];
|
1546
|
-
// printf("dim_map[i=%d] = %d, i0=%d\n", i, dim_map[i], i0);
|
1547
1541
|
}
|
1548
1542
|
ndloop_set_stepidx(lp, 1, a, dim_map, NDL_READ);
|
1549
1543
|
LARG(lp, 1).shape = &(na->shape[na->ndim - 1]);
|
@@ -1609,7 +1603,6 @@ static void loop_store_rarray(ndfunc_t* nf, na_md_loop_t* lp) {
|
|
1609
1603
|
a[i + 1] = Qnil;
|
1610
1604
|
}
|
1611
1605
|
} else if (IsNArray(a[i])) {
|
1612
|
-
// printf("a[i=%d]=0x%lx\n",i,a[i]);
|
1613
1606
|
loop_store_subnarray(nf, lp, i, c, a[i]);
|
1614
1607
|
goto loop_next;
|
1615
1608
|
} else {
|
@@ -1619,10 +1612,8 @@ static void loop_store_rarray(ndfunc_t* nf, na_md_loop_t* lp) {
|
|
1619
1612
|
a[i + 1] = Qnil;
|
1620
1613
|
}
|
1621
1614
|
}
|
1622
|
-
// printf("c[%d]=%lu\n",i,c[i]);
|
1623
1615
|
}
|
1624
1616
|
|
1625
|
-
// printf("a[i=%d]=0x%lx\n",i,a[i]);
|
1626
1617
|
if (IsNArray(a[i])) {
|
1627
1618
|
loop_store_subnarray(nf, lp, i, c, a[i]);
|
1628
1619
|
} else {
|
@@ -1695,7 +1686,6 @@ static void loop_narray_to_rarray(ndfunc_t* nf, na_md_loop_t* lp) {
|
|
1695
1686
|
c = ALLOCA_N(size_t, nd + 1);
|
1696
1687
|
for (i = 0; i <= nd; i++) c[i] = 0;
|
1697
1688
|
// c[i]=1; // for zero-dim
|
1698
|
-
// fprintf(stderr,"in loop_narray_to_rarray, nd=%d\n",nd);
|
1699
1689
|
|
1700
1690
|
a = ALLOCA_N(VALUE, nd + 1);
|
1701
1691
|
a[0] = a0 = lp->loop_opt;
|
@@ -1780,7 +1770,6 @@ static void loop_narray_with_index(ndfunc_t* nf, na_md_loop_t* lp) {
|
|
1780
1770
|
} else {
|
1781
1771
|
LITER(lp, i + 1, j).pos = LITER(lp, i, j).pos + LITER(lp, i, j).step * c[i];
|
1782
1772
|
}
|
1783
|
-
// printf("j=%d c[i=%d]=%lu pos=%lu\n",j,i,c[i],LITER(lp,i+1,j).pos);
|
1784
1773
|
}
|
1785
1774
|
}
|
1786
1775
|
|
@@ -72,7 +72,9 @@ void na_release_lock(VALUE); // currently do nothing
|
|
72
72
|
|
73
73
|
// used in reduce methods
|
74
74
|
#define na_reduce_dimension nary_reduce_dimension
|
75
|
-
VALUE nary_reduce_dimension(
|
75
|
+
VALUE nary_reduce_dimension(
|
76
|
+
int argc, VALUE* argv, int naryc, VALUE* naryv, ndfunc_t* ndf, na_iter_func_t nan_iter
|
77
|
+
);
|
76
78
|
|
77
79
|
#define na_reduce_options nary_reduce_options
|
78
80
|
VALUE nary_reduce_options(VALUE axes, VALUE* opts, int naryc, VALUE* naryv, ndfunc_t* ndf);
|
@@ -95,13 +97,17 @@ VALUE nary_info_str(VALUE);
|
|
95
97
|
#define na_test_reduce nary_test_reduce
|
96
98
|
bool nary_test_reduce(VALUE reduce, int dim);
|
97
99
|
|
98
|
-
void nary_step_array_index(
|
100
|
+
void nary_step_array_index(
|
101
|
+
VALUE self, size_t ary_size, size_t* plen, ssize_t* pbeg, ssize_t* pstep
|
102
|
+
);
|
99
103
|
void nary_step_sequence(VALUE self, size_t* plen, double* pbeg, double* pstep);
|
100
104
|
void na_parse_enumerator_step(VALUE enum_obj, VALUE* pstep);
|
101
105
|
|
102
106
|
// used in aref, aset
|
103
107
|
#define na_get_result_dimension nary_get_result_dimension
|
104
|
-
int nary_get_result_dimension(
|
108
|
+
int nary_get_result_dimension(
|
109
|
+
VALUE self, int argc, VALUE* argv, ssize_t stride, size_t* pos_idx
|
110
|
+
);
|
105
111
|
#define na_aref_main nary_aref_main
|
106
112
|
VALUE nary_aref_main(int nidx, VALUE* idx, VALUE self, int keep_dim, int nd);
|
107
113
|
|
@@ -13,8 +13,8 @@ extern "C" {
|
|
13
13
|
#endif
|
14
14
|
#endif
|
15
15
|
|
16
|
-
#define NARRAY_VERSION "0.9.
|
17
|
-
#define NARRAY_VERSION_CODE
|
16
|
+
#define NARRAY_VERSION "0.9.5"
|
17
|
+
#define NARRAY_VERSION_CODE 950
|
18
18
|
|
19
19
|
#include <math.h>
|
20
20
|
#include "numo/compat.h"
|
@@ -343,31 +343,31 @@ static inline narray_t* _na_get_narray_t(VALUE obj, unsigned char na_type) {
|
|
343
343
|
#define NA_FL0_TEST(x, f) (NA_FLAG0(x) & (f))
|
344
344
|
#define NA_FL1_TEST(x, f) (NA_FLAG1(x) & (f))
|
345
345
|
|
346
|
-
#define NA_FL0_SET(x, f)
|
347
|
-
do {
|
348
|
-
NA_FLAG0(x) |= (f);
|
346
|
+
#define NA_FL0_SET(x, f) \
|
347
|
+
do { \
|
348
|
+
NA_FLAG0(x) |= (f); \
|
349
349
|
} while (0)
|
350
|
-
#define NA_FL1_SET(x, f)
|
351
|
-
do {
|
352
|
-
NA_FLAG1(x) |= (f);
|
350
|
+
#define NA_FL1_SET(x, f) \
|
351
|
+
do { \
|
352
|
+
NA_FLAG1(x) |= (f); \
|
353
353
|
} while (0)
|
354
354
|
|
355
|
-
#define NA_FL0_UNSET(x, f)
|
356
|
-
do {
|
357
|
-
NA_FLAG0(x) &= ~(f);
|
355
|
+
#define NA_FL0_UNSET(x, f) \
|
356
|
+
do { \
|
357
|
+
NA_FLAG0(x) &= ~(f); \
|
358
358
|
} while (0)
|
359
|
-
#define NA_FL1_UNSET(x, f)
|
360
|
-
do {
|
361
|
-
NA_FLAG1(x) &= ~(f);
|
359
|
+
#define NA_FL1_UNSET(x, f) \
|
360
|
+
do { \
|
361
|
+
NA_FLAG1(x) &= ~(f); \
|
362
362
|
} while (0)
|
363
363
|
|
364
|
-
#define NA_FL0_REVERSE(x, f)
|
365
|
-
do {
|
366
|
-
NA_FLAG0(x) ^= (f);
|
364
|
+
#define NA_FL0_REVERSE(x, f) \
|
365
|
+
do { \
|
366
|
+
NA_FLAG0(x) ^= (f); \
|
367
367
|
} while (0)
|
368
|
-
#define NA_FL1_REVERSE(x, f)
|
369
|
-
do {
|
370
|
-
NA_FLAG1(x) ^= (f);
|
368
|
+
#define NA_FL1_REVERSE(x, f) \
|
369
|
+
do { \
|
370
|
+
NA_FLAG1(x) ^= (f); \
|
371
371
|
} while (0)
|
372
372
|
|
373
373
|
/* FLAGS
|