numo-narray-alt 0.12.0 → 0.12.1
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/ext/numo/narray/data.c +3 -0
- data/ext/numo/narray/index.c +6 -6
- data/ext/numo/narray/narray.c +12 -1
- data/ext/numo/narray/ndloop.c +105 -8
- data/ext/numo/narray/numo/narray.h +2 -2
- data/ext/numo/narray/src/mh/bincount.h +18 -0
- data/ext/numo/narray/src/mh/bit/left_shift.h +3 -3
- data/ext/numo/narray/src/mh/bit/right_shift.h +3 -3
- data/ext/numo/narray/src/mh/median.h +4 -4
- data/ext/numo/narray/src/mh/op/div.h +3 -3
- data/ext/numo/narray/src/mh/op/mod.h +3 -3
- data/ext/numo/narray/src/mh/store.h +11 -11
- data/ext/numo/narray/src/t_bit.c +11 -11
- data/ext/numo/narray/src/t_robject.c +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5c004883e2a167c36d837f0e8229c42c13f8aaeb1bb601c7675dfb02d478d990
|
|
4
|
+
data.tar.gz: 4f519008dc562985d9d35f78d7e40bfe99e48621f39ed3052b72fb1fa9d5de1a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: db91aff2f5d6340399432bad21ae09bb8597302e1eaadb78a5f10f6959a2d557d191cca3407d84bce9ea06c2f94eda422bd0a73b69d33e3679c0f40e8e24f002
|
|
7
|
+
data.tar.gz: 1b4e6f3186d9d48d9515b7fed2547d9ed19a4197a429dea1d9a3680b1198e300de52835c582975a260f82c644d32752de06a657653c0fc7c9b0f7c7930a7089d
|
data/ext/numo/narray/data.c
CHANGED
|
@@ -106,6 +106,9 @@ static VALUE nary_swap_byte(VALUE self) {
|
|
|
106
106
|
ndfunc_arg_out_t aout[1] = { { INT2FIX(0), 0 } };
|
|
107
107
|
ndfunc_t ndf = { iter_swap_byte, FULL_LOOP | NDF_ACCEPT_BYTESWAP, 1, 1, ain, aout };
|
|
108
108
|
|
|
109
|
+
if (RTEST(rb_obj_is_kind_of(self, numo_cRObject))) {
|
|
110
|
+
rb_raise(rb_eTypeError, "cannot swap bytes of %s", rb_obj_classname(self));
|
|
111
|
+
}
|
|
109
112
|
if (RTEST(rb_obj_is_kind_of(self, numo_cBit))) {
|
|
110
113
|
v = TEST_INPLACE(self) ? self : rb_funcall(self, id_copy, 0);
|
|
111
114
|
} else {
|
data/ext/numo/narray/index.c
CHANGED
|
@@ -439,8 +439,9 @@ static size_t na_index_parse_args(VALUE args, narray_t* na, na_index_arg_t* q, i
|
|
|
439
439
|
}
|
|
440
440
|
// new dimension
|
|
441
441
|
else if (v == sym_new) {
|
|
442
|
-
//
|
|
443
|
-
// a new axis
|
|
442
|
+
// The aref functions below take an axis past the last dimension with no
|
|
443
|
+
// index array as a new axis. On a 0-d array a range or true is one too,
|
|
444
|
+
// which works because it picks the only element.
|
|
444
445
|
na_index_parse_each(v, 1, na->ndim, &q[j]);
|
|
445
446
|
j++;
|
|
446
447
|
}
|
|
@@ -525,7 +526,7 @@ static void na_index_aref_nadata(
|
|
|
525
526
|
na2->base.reduce = rb_funcall(m, '|', 1, na2->base.reduce);
|
|
526
527
|
}
|
|
527
528
|
|
|
528
|
-
if (qi_orig_dim >= na1->base.ndim) {
|
|
529
|
+
if (qi_orig_dim >= na1->base.ndim && q[i].idx == NULL) {
|
|
529
530
|
// new dimension
|
|
530
531
|
newaxis[n_newaxes++] = j;
|
|
531
532
|
SDX_SET_STRIDE(na2->stridx[j], elmsz);
|
|
@@ -563,8 +564,7 @@ static void na_index_aref_naview(
|
|
|
563
564
|
|
|
564
565
|
for (i = j = 0; i < ndim; i++) {
|
|
565
566
|
stridx_t sdx1;
|
|
566
|
-
sdx1
|
|
567
|
-
sdx1.index = NULL;
|
|
567
|
+
SDX_SET_STRIDE(sdx1, 0);
|
|
568
568
|
const int qi_orig_dim = q[i].orig_dim;
|
|
569
569
|
if (qi_orig_dim < na1->base.ndim) {
|
|
570
570
|
sdx1 = na1->stridx[qi_orig_dim];
|
|
@@ -588,7 +588,7 @@ static void na_index_aref_naview(
|
|
|
588
588
|
na2->base.reduce = rb_funcall(m, '|', 1, na2->base.reduce);
|
|
589
589
|
}
|
|
590
590
|
|
|
591
|
-
if (qi_orig_dim >= na1->base.ndim) {
|
|
591
|
+
if (qi_orig_dim >= na1->base.ndim && q[i].idx == NULL) {
|
|
592
592
|
// new dimension
|
|
593
593
|
newaxis[n_newaxes++] = j;
|
|
594
594
|
SDX_SET_STRIDE(na2->stridx[j], elmsz);
|
data/ext/numo/narray/narray.c
CHANGED
|
@@ -781,7 +781,9 @@ static VALUE na_free(VALUE self) {
|
|
|
781
781
|
ptr = NA_DATA_PTR(na);
|
|
782
782
|
if (ptr != NULL) {
|
|
783
783
|
NA_DATA_PTR(na) = NULL;
|
|
784
|
-
|
|
784
|
+
if (NA_DATA_OWNED(na)) {
|
|
785
|
+
xfree(ptr);
|
|
786
|
+
}
|
|
785
787
|
}
|
|
786
788
|
break;
|
|
787
789
|
case NARRAY_VIEW_T:
|
|
@@ -1436,6 +1438,15 @@ static VALUE nary_to_binary(VALUE self) {
|
|
|
1436
1438
|
len = NUM2SIZET(nary_byte_size(self));
|
|
1437
1439
|
ptr = na_get_pointer_for_read(self);
|
|
1438
1440
|
str = rb_usascii_str_new(ptr + offset, len);
|
|
1441
|
+
// The last byte of a Bit array also carries the bits past its end. They hold
|
|
1442
|
+
// uninitialized memory, the input of from_binary, or the base of a view.
|
|
1443
|
+
// Count them on self, the same array that len came from.
|
|
1444
|
+
if (len > 0 && RTEST(rb_obj_is_kind_of(self, numo_cBit))) {
|
|
1445
|
+
GetNArray(self, na);
|
|
1446
|
+
if (na->size % 8 != 0) {
|
|
1447
|
+
RSTRING_PTR(str)[len - 1] &= (char)((1u << (na->size % 8)) - 1);
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1439
1450
|
RB_GC_GUARD(self);
|
|
1440
1451
|
return str;
|
|
1441
1452
|
}
|
data/ext/numo/narray/ndloop.c
CHANGED
|
@@ -29,6 +29,7 @@ typedef struct NA_BUFFER_COPY {
|
|
|
29
29
|
char* buf_ptr;
|
|
30
30
|
na_loop_iter_t* src_iter;
|
|
31
31
|
na_loop_iter_t* buf_iter;
|
|
32
|
+
bool is_bit;
|
|
32
33
|
} na_buffer_copy_t;
|
|
33
34
|
|
|
34
35
|
typedef struct NA_LOOP_XARGS {
|
|
@@ -52,6 +53,7 @@ typedef struct NA_MD_LOOP {
|
|
|
52
53
|
int init_aidx; // index of initializer argument
|
|
53
54
|
int reduce_dim;
|
|
54
55
|
int* trans_map;
|
|
56
|
+
size_t sub_narray_len;
|
|
55
57
|
VALUE vargs;
|
|
56
58
|
VALUE reduce;
|
|
57
59
|
VALUE loop_opt;
|
|
@@ -185,6 +187,7 @@ static void print_ndloop(na_md_loop_t* lp) {
|
|
|
185
187
|
if (lp->xargs[j].bufcp) {
|
|
186
188
|
printf(" xargs[%d].bufcp->ndim = %d\n", j, lp->xargs[j].bufcp->ndim);
|
|
187
189
|
printf(" xargs[%d].bufcp->elmsz = %" SZF "d\n", j, lp->xargs[j].bufcp->elmsz);
|
|
190
|
+
printf(" xargs[%d].bufcp->is_bit = %d\n", j, lp->xargs[j].bufcp->is_bit);
|
|
188
191
|
printf(" xargs[%d].bufcp->n = 0x%" SZF "x\n", j, (size_t)lp->xargs[j].bufcp->n);
|
|
189
192
|
printf(
|
|
190
193
|
" xargs[%d].bufcp->src_ptr = 0x%" SZF "x\n", j, (size_t)lp->xargs[j].bufcp->src_ptr
|
|
@@ -888,6 +891,47 @@ skip_ud:
|
|
|
888
891
|
}
|
|
889
892
|
}
|
|
890
893
|
|
|
894
|
+
static void ndloop_copy_bits(na_buffer_copy_t* lp, bool to_buffer) {
|
|
895
|
+
int i;
|
|
896
|
+
int nd = lp->ndim;
|
|
897
|
+
size_t* c;
|
|
898
|
+
size_t k, t, pos;
|
|
899
|
+
size_t total = 1;
|
|
900
|
+
size_t buf_pos = 0;
|
|
901
|
+
BIT_DIGIT x;
|
|
902
|
+
|
|
903
|
+
for (i = 0; i < nd; i++) {
|
|
904
|
+
total *= lp->n[i];
|
|
905
|
+
}
|
|
906
|
+
c = ALLOCA_N(size_t, nd + 1);
|
|
907
|
+
for (i = 0; i <= nd; i++) c[i] = 0;
|
|
908
|
+
for (t = 0; t < total; t++) {
|
|
909
|
+
pos = LITER_SRC(lp, 0).pos;
|
|
910
|
+
for (i = 0; i < nd; i++) {
|
|
911
|
+
if (LITER_SRC(lp, i).idx) {
|
|
912
|
+
pos += LITER_SRC(lp, i).idx[c[i]];
|
|
913
|
+
} else {
|
|
914
|
+
pos += LITER_SRC(lp, i).step * c[i];
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
for (k = 0; k < lp->elmsz; k++) {
|
|
918
|
+
if (to_buffer) {
|
|
919
|
+
LOAD_BIT(lp->src_ptr, pos + k, x);
|
|
920
|
+
STORE_BIT(lp->buf_ptr, buf_pos + k, x);
|
|
921
|
+
} else {
|
|
922
|
+
LOAD_BIT(lp->buf_ptr, buf_pos + k, x);
|
|
923
|
+
STORE_BIT(lp->src_ptr, pos + k, x);
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
buf_pos += lp->elmsz;
|
|
927
|
+
for (i = nd; i > 0;) {
|
|
928
|
+
i--;
|
|
929
|
+
if (++c[i] < lp->n[i]) break;
|
|
930
|
+
c[i] = 0;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
|
|
891
935
|
static void ndfunc_set_bufcp(na_md_loop_t* lp, unsigned int loop_spec) {
|
|
892
936
|
unsigned int f;
|
|
893
937
|
int i, j;
|
|
@@ -975,7 +1019,14 @@ static void ndfunc_set_bufcp(na_md_loop_t* lp, unsigned int loop_spec) {
|
|
|
975
1019
|
LBUFCP(lp, j)->buf_iter = buf_iter;
|
|
976
1020
|
LARG(lp, j).iter = buf_iter;
|
|
977
1021
|
LBUFCP(lp, j)->src_ptr = LARG(lp, j).ptr;
|
|
978
|
-
|
|
1022
|
+
// The positions and sizes of a Bit array count bits, not bytes.
|
|
1023
|
+
LBUFCP(lp, j)->is_bit = RTEST(rb_obj_is_kind_of(LARG(lp, j).value, numo_cBit));
|
|
1024
|
+
if (LBUFCP(lp, j)->is_bit) {
|
|
1025
|
+
LBUFCP(lp, j)->buf_ptr = (char*)ALLOC_N(BIT_DIGIT, (sz + NB - 1) / NB);
|
|
1026
|
+
} else {
|
|
1027
|
+
LBUFCP(lp, j)->buf_ptr = xmalloc(sz);
|
|
1028
|
+
}
|
|
1029
|
+
LARG(lp, j).ptr = LBUFCP(lp, j)->buf_ptr;
|
|
979
1030
|
}
|
|
980
1031
|
}
|
|
981
1032
|
|
|
@@ -1012,6 +1063,23 @@ static void ndfunc_set_bufcp(na_md_loop_t* lp, unsigned int loop_spec) {
|
|
|
1012
1063
|
}
|
|
1013
1064
|
}
|
|
1014
1065
|
|
|
1066
|
+
// The copy loops below and loop_narray run their body once before they check
|
|
1067
|
+
// any count, so they must not start on an empty axis.
|
|
1068
|
+
static int ndloop_has_empty_axis(const size_t* n, int ndim) {
|
|
1069
|
+
int i;
|
|
1070
|
+
for (i = 0; i < ndim; i++) {
|
|
1071
|
+
if (n[i] == 0) {
|
|
1072
|
+
return 1;
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
return 0;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
// A contiguous empty last axis is folded into elmsz, which is then 0.
|
|
1079
|
+
static int ndloop_buffer_is_empty(const na_buffer_copy_t* lp) {
|
|
1080
|
+
return lp->elmsz == 0 || ndloop_has_empty_axis(lp->n, lp->ndim);
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1015
1083
|
static void ndloop_copy_to_buffer(na_buffer_copy_t* lp) {
|
|
1016
1084
|
size_t* c;
|
|
1017
1085
|
char *src, *buf;
|
|
@@ -1021,6 +1089,10 @@ static void ndloop_copy_to_buffer(na_buffer_copy_t* lp) {
|
|
|
1021
1089
|
size_t buf_pos = 0;
|
|
1022
1090
|
DBG(size_t j);
|
|
1023
1091
|
|
|
1092
|
+
if (lp->is_bit) {
|
|
1093
|
+
ndloop_copy_bits(lp, true);
|
|
1094
|
+
return;
|
|
1095
|
+
}
|
|
1024
1096
|
DBG(printf("<to buf> ["));
|
|
1025
1097
|
// zero-dimension
|
|
1026
1098
|
if (nd == 0) {
|
|
@@ -1030,6 +1102,9 @@ static void ndloop_copy_to_buffer(na_buffer_copy_t* lp) {
|
|
|
1030
1102
|
DBG(for (j = 0; j < elmsz / 8; j++) { printf("%g,", ((double*)(buf))[j]); });
|
|
1031
1103
|
goto loop_end;
|
|
1032
1104
|
}
|
|
1105
|
+
if (ndloop_buffer_is_empty(lp)) {
|
|
1106
|
+
goto loop_end;
|
|
1107
|
+
}
|
|
1033
1108
|
// initialize loop counter
|
|
1034
1109
|
c = ALLOCA_N(size_t, nd + 1);
|
|
1035
1110
|
for (i = 0; i <= nd; i++) c[i] = 0;
|
|
@@ -1069,6 +1144,10 @@ static void ndloop_copy_from_buffer(na_buffer_copy_t* lp) {
|
|
|
1069
1144
|
size_t buf_pos = 0;
|
|
1070
1145
|
DBG(size_t j);
|
|
1071
1146
|
|
|
1147
|
+
if (lp->is_bit) {
|
|
1148
|
+
ndloop_copy_bits(lp, false);
|
|
1149
|
+
return;
|
|
1150
|
+
}
|
|
1072
1151
|
DBG(printf("<from buf> ["));
|
|
1073
1152
|
// zero-dimension
|
|
1074
1153
|
if (nd == 0) {
|
|
@@ -1078,6 +1157,9 @@ static void ndloop_copy_from_buffer(na_buffer_copy_t* lp) {
|
|
|
1078
1157
|
DBG(for (j = 0; j < elmsz / 8; j++) { printf("%g,", ((double*)(src))[j]); });
|
|
1079
1158
|
goto loop_end;
|
|
1080
1159
|
}
|
|
1160
|
+
if (ndloop_buffer_is_empty(lp)) {
|
|
1161
|
+
goto loop_end;
|
|
1162
|
+
}
|
|
1081
1163
|
// initialize loop counter
|
|
1082
1164
|
c = ALLOCA_N(size_t, nd + 1);
|
|
1083
1165
|
for (i = 0; i <= nd; i++) c[i] = 0;
|
|
@@ -1129,7 +1211,7 @@ static VALUE ndloop_extract(VALUE results, ndfunc_t* nf) {
|
|
|
1129
1211
|
case 0:
|
|
1130
1212
|
return Qnil;
|
|
1131
1213
|
case 1:
|
|
1132
|
-
x =
|
|
1214
|
+
x = rb_ary_entry(results, 0);
|
|
1133
1215
|
if (NDF_TEST(nf, NDF_EXTRACT)) {
|
|
1134
1216
|
if (IsNArray(x)) {
|
|
1135
1217
|
GetNArray(x, na);
|
|
@@ -1243,6 +1325,12 @@ static void loop_narray(ndfunc_t* nf, na_md_loop_t* lp) {
|
|
|
1243
1325
|
return;
|
|
1244
1326
|
}
|
|
1245
1327
|
|
|
1328
|
+
// An iterator without NDF_HAS_LOOP does not check a count, so on an empty
|
|
1329
|
+
// axis it would touch an element that does not exist.
|
|
1330
|
+
if (!NDF_TEST(nf, NDF_HAS_LOOP) && ndloop_has_empty_axis(lp->n, nd)) {
|
|
1331
|
+
return;
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1246
1334
|
// initialize loop counter
|
|
1247
1335
|
c = ALLOCA_N(size_t, nd + 1);
|
|
1248
1336
|
for (i = 0; i <= nd; i++) c[i] = 0;
|
|
@@ -1518,6 +1606,7 @@ na_ndloop_inspect(VALUE nary, na_text_func_t func, VALUE opt) {
|
|
|
1518
1606
|
static void loop_store_subnarray(ndfunc_t* nf, na_md_loop_t* lp, int i0, size_t* c, VALUE a) {
|
|
1519
1607
|
int nd = lp->ndim;
|
|
1520
1608
|
int i, j;
|
|
1609
|
+
bool* reach;
|
|
1521
1610
|
narray_t* na;
|
|
1522
1611
|
int* dim_map;
|
|
1523
1612
|
VALUE a_type;
|
|
@@ -1539,25 +1628,32 @@ static void loop_store_subnarray(ndfunc_t* nf, na_md_loop_t* lp, int i0, size_t*
|
|
|
1539
1628
|
for (i = 0; i < na->ndim; i++) {
|
|
1540
1629
|
dim_map[i] = lp->trans_map[i + i0];
|
|
1541
1630
|
}
|
|
1631
|
+
for (i = 0; i <= nd + lp->user.ndim; i++) {
|
|
1632
|
+
LITER(lp, i, 1).pos = 0;
|
|
1633
|
+
LITER(lp, i, 1).step = 0;
|
|
1634
|
+
LITER(lp, i, 1).idx = NULL;
|
|
1635
|
+
}
|
|
1542
1636
|
ndloop_set_stepidx(lp, 1, a, dim_map, NDL_READ);
|
|
1543
1637
|
LITER(lp, i0, 1).pos = LITER(lp, 0, 1).pos;
|
|
1544
|
-
LARG(lp, 1).shape = &(
|
|
1638
|
+
LARG(lp, 1).shape = &(lp->sub_narray_len);
|
|
1545
1639
|
|
|
1546
1640
|
// loop body
|
|
1641
|
+
reach = ALLOCA_N(bool, nd + 1);
|
|
1642
|
+
reach[i0] = true;
|
|
1547
1643
|
for (i = i0;;) {
|
|
1548
|
-
LARG(lp, 1).value = Qtrue;
|
|
1549
1644
|
for (; i < nd; i++) {
|
|
1645
|
+
reach[i + 1] = reach[i] && c[i] < na->shape[i - i0];
|
|
1550
1646
|
for (j = 0; j < 2; j++) {
|
|
1551
|
-
if (
|
|
1647
|
+
if (j == 1 && !reach[i + 1]) {
|
|
1648
|
+
LITER(lp, i + 1, j).pos = LITER(lp, i, j).pos;
|
|
1649
|
+
} else if (LITER(lp, i, j).idx) {
|
|
1552
1650
|
LITER(lp, i + 1, j).pos = LITER(lp, i, j).pos + LITER(lp, i, j).idx[c[i]];
|
|
1553
1651
|
} else {
|
|
1554
1652
|
LITER(lp, i + 1, j).pos = LITER(lp, i, j).pos + LITER(lp, i, j).step * c[i];
|
|
1555
1653
|
}
|
|
1556
1654
|
}
|
|
1557
|
-
if (c[i] >= na->shape[i - i0]) {
|
|
1558
|
-
LARG(lp, 1).value = Qfalse;
|
|
1559
|
-
}
|
|
1560
1655
|
}
|
|
1656
|
+
lp->sub_narray_len = reach[nd] ? na->shape[na->ndim - 1] : 0;
|
|
1561
1657
|
|
|
1562
1658
|
(*(nf->func))(&(lp->user));
|
|
1563
1659
|
|
|
@@ -1570,6 +1666,7 @@ static void loop_store_subnarray(ndfunc_t* nf, na_md_loop_t* lp, int i0, size_t*
|
|
|
1570
1666
|
}
|
|
1571
1667
|
}
|
|
1572
1668
|
loop_end:
|
|
1669
|
+
LARG(lp, 1).value = Qnil;
|
|
1573
1670
|
LARG(lp, 1).ptr = NULL;
|
|
1574
1671
|
}
|
|
1575
1672
|
|
|
@@ -13,10 +13,10 @@ extern "C" {
|
|
|
13
13
|
#endif
|
|
14
14
|
#endif
|
|
15
15
|
|
|
16
|
-
#define NARRAY_VERSION "0.12.
|
|
16
|
+
#define NARRAY_VERSION "0.12.1"
|
|
17
17
|
#define NARRAY_VERSION_MAJOR 0
|
|
18
18
|
#define NARRAY_VERSION_MINOR 12
|
|
19
|
-
#define NARRAY_VERSION_PATCH
|
|
19
|
+
#define NARRAY_VERSION_PATCH 1
|
|
20
20
|
#define NARRAY_VERSION_CODE \
|
|
21
21
|
(NARRAY_VERSION_MAJOR * 10000 + NARRAY_VERSION_MINOR * 100 + NARRAY_VERSION_PATCH)
|
|
22
22
|
|
|
@@ -11,6 +11,22 @@ static inline void na_bincount_check_item(size_t x, size_t n) {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
/* The loop does not call the iterator when the weight has an empty outer axis,
|
|
15
|
+
so this is checked before it too. The iterator keeps its own check, as Ruby
|
|
16
|
+
code can reshape the weight in between. */
|
|
17
|
+
static inline void na_bincount_check_weight(VALUE self, VALUE weight) {
|
|
18
|
+
narray_t* na_self;
|
|
19
|
+
narray_t* na_weight;
|
|
20
|
+
GetNArray(self, na_self);
|
|
21
|
+
GetNArray(weight, na_weight);
|
|
22
|
+
if (na_self->ndim == 0 || na_weight->ndim == 0) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (na_self->shape[na_self->ndim - 1] != na_weight->shape[na_weight->ndim - 1]) {
|
|
26
|
+
rb_raise(nary_eShapeError, "size mismatch along last axis between self and weight");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
14
30
|
#define DEF_BINCOUNT_FUNCS(tDType, tNAryClass) \
|
|
15
31
|
static void iter_##tDType##_bincount_32(na_loop_t* const lp) { \
|
|
16
32
|
char* p1; \
|
|
@@ -132,6 +148,7 @@ static inline void na_bincount_check_item(size_t x, size_t n) {
|
|
|
132
148
|
ndfunc_t ndf = { \
|
|
133
149
|
iter_##tDType##_bincount_sf, NO_LOOP | NDF_STRIDE_LOOP, 2, 1, ain, aout \
|
|
134
150
|
}; \
|
|
151
|
+
na_bincount_check_weight(self, weight); \
|
|
135
152
|
return na_ndloop(&ndf, 2, self, weight); \
|
|
136
153
|
} \
|
|
137
154
|
\
|
|
@@ -173,6 +190,7 @@ static inline void na_bincount_check_item(size_t x, size_t n) {
|
|
|
173
190
|
ndfunc_t ndf = { \
|
|
174
191
|
iter_##tDType##_bincount_df, NO_LOOP | NDF_STRIDE_LOOP, 2, 1, ain, aout \
|
|
175
192
|
}; \
|
|
193
|
+
na_bincount_check_weight(self, weight); \
|
|
176
194
|
return na_ndloop(&ndf, 2, self, weight); \
|
|
177
195
|
}
|
|
178
196
|
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
} \
|
|
31
31
|
if (is_aligned_step(s1, sizeof(tDType)) && is_aligned_step(s2, sizeof(tDType)) && \
|
|
32
32
|
is_aligned_step(s3, sizeof(tDType))) { \
|
|
33
|
-
if (s2 == 0) {
|
|
33
|
+
if (s2 == 0 && n > 0) { \
|
|
34
34
|
const tDType v2 = *(tDType*)p2; \
|
|
35
35
|
if (s1 == sizeof(tDType) && s3 == sizeof(tDType)) { \
|
|
36
36
|
if (p1 == p3) { \
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
INIT_PTR(lp, 0, p1, s1); \
|
|
109
109
|
INIT_PTR(lp, 1, p2, s2); \
|
|
110
110
|
INIT_PTR(lp, 2, p3, s3); \
|
|
111
|
-
if (s2 == 0) {
|
|
111
|
+
if (s2 == 0 && n > 0) { \
|
|
112
112
|
const tDType v2 = *(tDType*)p2; \
|
|
113
113
|
if (s1 == sizeof(tDType) && s3 == sizeof(tDType)) { \
|
|
114
114
|
if (p1 == p3) { \
|
|
@@ -174,7 +174,7 @@
|
|
|
174
174
|
INIT_PTR(lp, 0, p1, s1); \
|
|
175
175
|
INIT_PTR(lp, 1, p2, s2); \
|
|
176
176
|
INIT_PTR(lp, 2, p3, s3); \
|
|
177
|
-
if (s2 == 0) {
|
|
177
|
+
if (s2 == 0 && n > 0) { \
|
|
178
178
|
const robject v2 = *(robject*)p2; \
|
|
179
179
|
if (s1 == sizeof(robject) && s3 == sizeof(robject)) { \
|
|
180
180
|
if (p1 == p3) { \
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
} \
|
|
31
31
|
if (is_aligned_step(s1, sizeof(tDType)) && is_aligned_step(s2, sizeof(tDType)) && \
|
|
32
32
|
is_aligned_step(s3, sizeof(tDType))) { \
|
|
33
|
-
if (s2 == 0) {
|
|
33
|
+
if (s2 == 0 && n > 0) { \
|
|
34
34
|
const tDType v2 = *(tDType*)p2; \
|
|
35
35
|
if (s1 == sizeof(tDType) && s3 == sizeof(tDType)) { \
|
|
36
36
|
if (p1 == p3) { \
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
INIT_PTR(lp, 0, p1, s1); \
|
|
109
109
|
INIT_PTR(lp, 1, p2, s2); \
|
|
110
110
|
INIT_PTR(lp, 2, p3, s3); \
|
|
111
|
-
if (s2 == 0) {
|
|
111
|
+
if (s2 == 0 && n > 0) { \
|
|
112
112
|
const tDType v2 = *(tDType*)p2; \
|
|
113
113
|
if (s1 == sizeof(tDType) && s3 == sizeof(tDType)) { \
|
|
114
114
|
if (p1 == p3) { \
|
|
@@ -174,7 +174,7 @@
|
|
|
174
174
|
INIT_PTR(lp, 0, p1, s1); \
|
|
175
175
|
INIT_PTR(lp, 1, p2, s2); \
|
|
176
176
|
INIT_PTR(lp, 2, p3, s3); \
|
|
177
|
-
if (s2 == 0) {
|
|
177
|
+
if (s2 == 0 && n > 0) { \
|
|
178
178
|
const robject v2 = *(robject*)p2; \
|
|
179
179
|
if (s1 == sizeof(robject) && s3 == sizeof(robject)) { \
|
|
180
180
|
if (p1 == p3) { \
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
char* p2 = NDL_PTR(lp, 1); \
|
|
39
39
|
tDType* buf = (tDType*)p1; \
|
|
40
40
|
tDType##_qsort_ignan(buf, n, sizeof(tDType)); \
|
|
41
|
-
for (
|
|
42
|
-
if (!isnan(buf[
|
|
41
|
+
for (; n; n--) { \
|
|
42
|
+
if (!isnan(buf[n - 1])) break; \
|
|
43
43
|
} \
|
|
44
44
|
if (n == 0) { \
|
|
45
45
|
*(tDType*)p2 = buf[0]; \
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
char* p2 = NDL_PTR(lp, 1); \
|
|
58
58
|
tDType* buf = (tDType*)p1; \
|
|
59
59
|
tDType##_qsort_prnan(buf, n, sizeof(tDType)); \
|
|
60
|
-
for (
|
|
61
|
-
if (!isnan(buf[
|
|
60
|
+
for (; n; n--) { \
|
|
61
|
+
if (!isnan(buf[n - 1])) break; \
|
|
62
62
|
} \
|
|
63
63
|
if (n == 0) { \
|
|
64
64
|
*(tDType*)p2 = buf[0]; \
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
if (is_aligned_step(s1, sizeof(tDType)) && is_aligned_step(s2, sizeof(tDType)) && \
|
|
44
44
|
is_aligned_step(s3, sizeof(tDType))) { \
|
|
45
45
|
if (s2 == 0) { \
|
|
46
|
-
if ((*(tDType*)p2) == 0) {
|
|
46
|
+
if (n > 0 && (*(tDType*)p2) == 0) { \
|
|
47
47
|
lp->err_type = rb_eZeroDivError; \
|
|
48
48
|
return; \
|
|
49
49
|
} \
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
static void iter_##tDType##_div(na_loop_t* const lp) { \
|
|
68
68
|
ITER_BINARY_INIT_VARS() \
|
|
69
69
|
if (s2 == 0) { \
|
|
70
|
-
if ((*(tDType*)p2) == 0) {
|
|
70
|
+
if (n > 0 && (*(tDType*)p2) == 0) { \
|
|
71
71
|
lp->err_type = rb_eZeroDivError; \
|
|
72
72
|
return; \
|
|
73
73
|
} \
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
static void iter_robject_div(na_loop_t* const lp) { \
|
|
88
88
|
ITER_BINARY_INIT_VARS() \
|
|
89
89
|
if (s2 == 0) { \
|
|
90
|
-
if ((*(robject*)p2) == 0) {
|
|
90
|
+
if (n > 0 && (*(robject*)p2) == 0) { \
|
|
91
91
|
lp->err_type = rb_eZeroDivError; \
|
|
92
92
|
return; \
|
|
93
93
|
} \
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
if (is_aligned_step(s1, sizeof(tDType)) && is_aligned_step(s2, sizeof(tDType)) && \
|
|
44
44
|
is_aligned_step(s3, sizeof(tDType))) { \
|
|
45
45
|
if (s2 == 0) { \
|
|
46
|
-
if ((*(tDType*)p2) == 0) {
|
|
46
|
+
if (n > 0 && (*(tDType*)p2) == 0) { \
|
|
47
47
|
lp->err_type = rb_eZeroDivError; \
|
|
48
48
|
return; \
|
|
49
49
|
} \
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
static void iter_##tDType##_mod(na_loop_t* const lp) { \
|
|
68
68
|
ITER_BINARY_INIT_VARS() \
|
|
69
69
|
if (s2 == 0) { \
|
|
70
|
-
if ((*(tDType*)p2) == 0) {
|
|
70
|
+
if (n > 0 && (*(tDType*)p2) == 0) { \
|
|
71
71
|
lp->err_type = rb_eZeroDivError; \
|
|
72
72
|
return; \
|
|
73
73
|
} \
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
static void iter_robject_mod(na_loop_t* const lp) { \
|
|
88
88
|
ITER_BINARY_INIT_VARS() \
|
|
89
89
|
if (s2 == 0) { \
|
|
90
|
-
if ((*(robject*)p2) == 0) {
|
|
90
|
+
if (n > 0 && (*(robject*)p2) == 0) { \
|
|
91
91
|
lp->err_type = rb_eZeroDivError; \
|
|
92
92
|
return; \
|
|
93
93
|
} \
|
|
@@ -163,20 +163,20 @@ static inline bool na_store_rary_fetch(VALUE ary, size_t i, VALUE* x) {
|
|
|
163
163
|
INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
|
|
164
164
|
v1 = lp->args[1].value; \
|
|
165
165
|
i = 0; \
|
|
166
|
-
if (
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
166
|
+
if (IsNArray(v1)) { \
|
|
167
|
+
i = lp->args[1].shape[0]; \
|
|
168
|
+
if (i > n) { \
|
|
169
|
+
i = n; \
|
|
170
|
+
} \
|
|
171
|
+
if (i > 0) { \
|
|
172
172
|
NDL_CNT(lp) = i; \
|
|
173
173
|
iter_##tDType##_store_##tDType(lp); \
|
|
174
174
|
NDL_CNT(lp) = n; \
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
175
|
+
} \
|
|
176
|
+
if (idx1) { \
|
|
177
|
+
idx1 += i; \
|
|
178
|
+
} else { \
|
|
179
|
+
p1 += s1 * i; \
|
|
180
180
|
} \
|
|
181
181
|
goto loop_end; \
|
|
182
182
|
} \
|
data/ext/numo/narray/src/t_bit.c
CHANGED
|
@@ -1273,20 +1273,20 @@ static void iter_bit_store_array(na_loop_t* const lp) {
|
|
|
1273
1273
|
v1 = lp->args[1].value;
|
|
1274
1274
|
i = 0;
|
|
1275
1275
|
|
|
1276
|
-
if (
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1276
|
+
if (IsNArray(v1)) {
|
|
1277
|
+
i = lp->args[1].shape[0];
|
|
1278
|
+
if (i > n) {
|
|
1279
|
+
i = n;
|
|
1280
|
+
}
|
|
1281
|
+
if (i > 0) {
|
|
1282
1282
|
NDL_CNT(lp) = i;
|
|
1283
1283
|
iter_bit_store_bit(lp);
|
|
1284
1284
|
NDL_CNT(lp) = n;
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1285
|
+
}
|
|
1286
|
+
if (idx1) {
|
|
1287
|
+
idx1 += i;
|
|
1288
|
+
} else {
|
|
1289
|
+
p1 += s1 * i;
|
|
1290
1290
|
}
|
|
1291
1291
|
goto loop_end;
|
|
1292
1292
|
}
|
|
@@ -410,6 +410,7 @@ void Init_numo_robject(void) {
|
|
|
410
410
|
rb_undef_method(cT, "to_binary");
|
|
411
411
|
rb_undef_method(cT, "to_string");
|
|
412
412
|
rb_undef_method(cT, "swap_byte");
|
|
413
|
+
rb_undef_method(cT, "hton");
|
|
413
414
|
rb_undef_method(cT, "to_network");
|
|
414
415
|
rb_undef_method(cT, "to_vacs");
|
|
415
416
|
rb_undef_method(cT, "to_host");
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: numo-narray-alt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.12.
|
|
4
|
+
version: 0.12.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- yoshoku
|
|
@@ -214,7 +214,7 @@ licenses:
|
|
|
214
214
|
metadata:
|
|
215
215
|
homepage_uri: https://github.com/yoshoku/numo-narray-alt
|
|
216
216
|
changelog_uri: https://github.com/yoshoku/numo-narray-alt/blob/main/CHANGELOG.md
|
|
217
|
-
documentation_uri: https://gemdocs.org/gems/numo-narray-alt/0.12.
|
|
217
|
+
documentation_uri: https://gemdocs.org/gems/numo-narray-alt/0.12.1/
|
|
218
218
|
rubygems_mfa_required: 'true'
|
|
219
219
|
post_install_message: |
|
|
220
220
|
===
|