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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a64ac3265fa7102eee1017c69d80a8e08a15085e0f117e108c4cf0affca905f
|
4
|
+
data.tar.gz: c2100ac54472937c494f24b9800e1b27d296ae66fbdd5582eeb7204385eca86d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b91256a44b0f992e34299e11cdc85c5e754780cb1fc19540bb281060b19213cd687fc9084ad7538931b564d555299562c38c8ae3f87ae3484b05eea9dab705b6
|
7
|
+
data.tar.gz: 110e56f1fb83cf1896edd88de1f7d4e800758ae212e6c72b8a9b5ee9e62c79d27d60ae5b6c22084fa20213549c0bac31b6dc02cbfae846621b4b37c38b0e7da1
|
data/README.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Numo::NArray Alternative
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/numo-narray-alt)
|
4
|
+
[](https://github.com/yoshoku/numo-narray-alt/actions/workflows/build.yml)
|
5
|
+
[](https://github.com/yoshoku/numo-narray-alt/blob/main/LICENSE)
|
6
|
+
[](https://gemdocs.org/gems/numo-narray-alt/)
|
7
|
+
|
3
8
|
Numo::NArray Alternative is an experimental project forked from [Numo::NArray](https://github.com/ruby-numo/numo-narray).
|
4
9
|
Its goal is to adopt more modern Ruby features and development practices.
|
5
10
|
The project owner is also the developer of [Rumale](https://github.com/yoshoku/rumale), a machine learning library,
|
@@ -61,9 +66,10 @@ $ clang-format --dry-run --Werror --style=file ext/**/*.h ext/**/*.c
|
|
61
66
|
|
62
67
|
## Contributing
|
63
68
|
|
64
|
-
|
65
|
-
|
66
|
-
|
69
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/yoshoku/numo-narray-alt.
|
70
|
+
This project is intended to be a safe, welcoming space for collaboration,
|
71
|
+
and contributors are expected to adhere to
|
72
|
+
the [code of conduct](https://github.com/yoshoku/numo-narray-alt/blob/main/CODE_OF_CONDUCT.md).
|
67
73
|
|
68
74
|
## License
|
69
75
|
|
data/Rakefile
CHANGED
@@ -11,6 +11,12 @@ task :doc do
|
|
11
11
|
sh "rm -rf yard .yardoc; yard doc -o yard -m markdown -r README.md #{src.join(' ')}"
|
12
12
|
end
|
13
13
|
|
14
|
+
task :'clang-format' do
|
15
|
+
sh 'bash -c "shopt -s globstar && clang-format -style=file -Werror --dry-run ext/numo/narray/**/*.{c,h}"' do |ok, _res|
|
16
|
+
puts 'clang-format violations found, here is the autofix command: clang-format --style=file -i ...' unless ok
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
14
20
|
require 'ruby_memcheck' if ENV['BUNDLE_WITH'] == 'memcheck'
|
15
21
|
require 'rake/testtask'
|
16
22
|
|
@@ -34,3 +40,5 @@ end
|
|
34
40
|
|
35
41
|
require 'rake/extensiontask'
|
36
42
|
Rake::ExtensionTask.new('numo/narray')
|
43
|
+
|
44
|
+
task default: %i[clobber compile test]
|
@@ -21,26 +21,30 @@
|
|
21
21
|
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
|
22
22
|
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
|
23
23
|
#define ALTI_MSK64 (vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
|
24
|
-
#define ALTI_SL2_PERM
|
25
|
-
|
26
|
-
#define
|
27
|
-
|
24
|
+
#define ALTI_SL2_PERM \
|
25
|
+
(vector unsigned char)(1, 2, 3, 23, 5, 6, 7, 0, 9, 10, 11, 4, 13, 14, 15, 8)
|
26
|
+
#define ALTI_SL2_PERM64 \
|
27
|
+
(vector unsigned char)(1, 2, 3, 4, 5, 6, 7, 31, 9, 10, 11, 12, 13, 14, 15, 0)
|
28
|
+
#define ALTI_SR2_PERM \
|
29
|
+
(vector unsigned char)(7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10, 17, 12, 13, 14)
|
30
|
+
#define ALTI_SR2_PERM64 \
|
31
|
+
(vector unsigned char)(15, 0, 1, 2, 3, 4, 5, 6, 17, 8, 9, 10, 11, 12, 13, 14)
|
28
32
|
#else /* For OTHER OSs(Linux?) */
|
29
|
-
#define ALTI_SL1
|
33
|
+
#define ALTI_SL1 \
|
30
34
|
{ SL1, SL1, SL1, SL1 }
|
31
|
-
#define ALTI_SR1
|
35
|
+
#define ALTI_SR1 \
|
32
36
|
{ SR1, SR1, SR1, SR1 }
|
33
|
-
#define ALTI_MSK
|
37
|
+
#define ALTI_MSK \
|
34
38
|
{ MSK1, MSK2, MSK3, MSK4 }
|
35
|
-
#define ALTI_MSK64
|
39
|
+
#define ALTI_MSK64 \
|
36
40
|
{ MSK2, MSK1, MSK4, MSK3 }
|
37
|
-
#define ALTI_SL2_PERM
|
41
|
+
#define ALTI_SL2_PERM \
|
38
42
|
{ 1, 2, 3, 23, 5, 6, 7, 0, 9, 10, 11, 4, 13, 14, 15, 8 }
|
39
|
-
#define ALTI_SL2_PERM64
|
43
|
+
#define ALTI_SL2_PERM64 \
|
40
44
|
{ 1, 2, 3, 4, 5, 6, 7, 31, 9, 10, 11, 12, 13, 14, 15, 0 }
|
41
|
-
#define ALTI_SR2_PERM
|
45
|
+
#define ALTI_SR2_PERM \
|
42
46
|
{ 7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10, 17, 12, 13, 14 }
|
43
|
-
#define ALTI_SR2_PERM64
|
47
|
+
#define ALTI_SR2_PERM64 \
|
44
48
|
{ 15, 0, 1, 2, 3, 4, 5, 6, 17, 8, 9, 10, 11, 12, 13, 14 }
|
45
49
|
#endif /* For OSX */
|
46
50
|
#define IDSTR "SFMT-19937:122-18-1-11-1:dfffffef-ddfecb7f-bffaffff-bffffff6"
|
data/ext/numo/narray/SFMT.c
CHANGED
@@ -82,7 +82,7 @@ static int idx;
|
|
82
82
|
* initialized. */
|
83
83
|
static int initialized = 0;
|
84
84
|
/** a parity check vector which certificate the period of 2^{MEXP} */
|
85
|
-
static uint32_t parity[4] = {PARITY1, PARITY2, PARITY3, PARITY4};
|
85
|
+
static uint32_t parity[4] = { PARITY1, PARITY2, PARITY3, PARITY4 };
|
86
86
|
|
87
87
|
/*----------------
|
88
88
|
STATIC FUNCTIONS
|
@@ -527,7 +527,8 @@ void init_gen_rand(uint32_t seed) {
|
|
527
527
|
|
528
528
|
psfmt32[idxof(0)] = seed;
|
529
529
|
for (i = 1; i < N32; i++) {
|
530
|
-
psfmt32[idxof(i)] =
|
530
|
+
psfmt32[idxof(i)] =
|
531
|
+
1812433253UL * (psfmt32[idxof(i - 1)] ^ (psfmt32[idxof(i - 1)] >> 30)) + i;
|
531
532
|
}
|
532
533
|
idx = N32;
|
533
534
|
period_certification();
|
@@ -572,7 +573,9 @@ void init_by_array(uint32_t* init_key, int key_length) {
|
|
572
573
|
|
573
574
|
count--;
|
574
575
|
for (i = 1, j = 0; (j < count) && (j < key_length); j++) {
|
575
|
-
r = func1(
|
576
|
+
r = func1(
|
577
|
+
psfmt32[idxof(i)] ^ psfmt32[idxof((i + mid) % N32)] ^ psfmt32[idxof((i + N32 - 1) % N32)]
|
578
|
+
);
|
576
579
|
psfmt32[idxof((i + mid) % N32)] += r;
|
577
580
|
r += init_key[j] + i;
|
578
581
|
psfmt32[idxof((i + mid + lag) % N32)] += r;
|
@@ -580,7 +583,9 @@ void init_by_array(uint32_t* init_key, int key_length) {
|
|
580
583
|
i = (i + 1) % N32;
|
581
584
|
}
|
582
585
|
for (; j < count; j++) {
|
583
|
-
r = func1(
|
586
|
+
r = func1(
|
587
|
+
psfmt32[idxof(i)] ^ psfmt32[idxof((i + mid) % N32)] ^ psfmt32[idxof((i + N32 - 1) % N32)]
|
588
|
+
);
|
584
589
|
psfmt32[idxof((i + mid) % N32)] += r;
|
585
590
|
r += i;
|
586
591
|
psfmt32[idxof((i + mid + lag) % N32)] += r;
|
@@ -588,7 +593,9 @@ void init_by_array(uint32_t* init_key, int key_length) {
|
|
588
593
|
i = (i + 1) % N32;
|
589
594
|
}
|
590
595
|
for (j = 0; j < N32; j++) {
|
591
|
-
r = func2(
|
596
|
+
r = func2(
|
597
|
+
psfmt32[idxof(i)] + psfmt32[idxof((i + mid) % N32)] + psfmt32[idxof((i + N32 - 1) % N32)]
|
598
|
+
);
|
592
599
|
psfmt32[idxof((i + mid) % N32)] ^= r;
|
593
600
|
r -= i;
|
594
601
|
psfmt32[idxof((i + mid + lag) % N32)] ^= r;
|
data/ext/numo/narray/array.c
CHANGED
@@ -22,7 +22,17 @@ typedef struct {
|
|
22
22
|
} na_mdai_t;
|
23
23
|
|
24
24
|
// Order of Ruby object.
|
25
|
-
enum {
|
25
|
+
enum {
|
26
|
+
NA_NONE,
|
27
|
+
NA_BIT,
|
28
|
+
NA_INT32,
|
29
|
+
NA_INT64,
|
30
|
+
NA_RATIONAL,
|
31
|
+
NA_DFLOAT,
|
32
|
+
NA_DCOMPLEX,
|
33
|
+
NA_ROBJ,
|
34
|
+
NA_NTYPES
|
35
|
+
};
|
26
36
|
|
27
37
|
static ID id_begin;
|
28
38
|
static ID id_end;
|
@@ -51,7 +61,8 @@ static VALUE na_object_type(int type, VALUE v) {
|
|
51
61
|
return type;
|
52
62
|
case T_BIGNUM:
|
53
63
|
if (type < NA_INT64) {
|
54
|
-
if (RTEST(rb_funcall(v, id_le, 1, int32_max)) &&
|
64
|
+
if (RTEST(rb_funcall(v, id_le, 1, int32_max)) &&
|
65
|
+
RTEST(rb_funcall(v, id_ge, 1, int32_min))) {
|
55
66
|
if (type < NA_INT32) return NA_INT32;
|
56
67
|
} else {
|
57
68
|
return NA_INT64;
|
@@ -160,7 +171,8 @@ static int na_mdai_investigate(na_mdai_t* mdai, int ndim) {
|
|
160
171
|
if (TYPE(v) == T_ARRAY) {
|
161
172
|
/* check recursive array */
|
162
173
|
for (j = 0; j < ndim; j++) {
|
163
|
-
if (mdai->item[j].val == v)
|
174
|
+
if (mdai->item[j].val == v)
|
175
|
+
rb_raise(rb_eStandardError, "cannot convert from a recursive Array to NArray");
|
164
176
|
}
|
165
177
|
if (ndim >= mdai->capa) {
|
166
178
|
na_mdai_realloc(mdai, 4);
|
@@ -294,15 +306,16 @@ static size_t na_mdai_memsize(const void* ptr) {
|
|
294
306
|
return sizeof(na_mdai_t) + mdai->capa * sizeof(na_mdai_item_t);
|
295
307
|
}
|
296
308
|
|
297
|
-
static const rb_data_type_t mdai_data_type = {"Numo::NArray/mdai",
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
309
|
+
static const rb_data_type_t mdai_data_type = { "Numo::NArray/mdai",
|
310
|
+
{
|
311
|
+
NULL,
|
312
|
+
na_mdai_free,
|
313
|
+
na_mdai_memsize,
|
314
|
+
},
|
315
|
+
0,
|
316
|
+
0,
|
317
|
+
RUBY_TYPED_FREE_IMMEDIATELY |
|
318
|
+
RUBY_TYPED_WB_PROTECTED };
|
306
319
|
|
307
320
|
static void na_composition3_ary(VALUE ary, VALUE* ptype, VALUE* pshape, VALUE* pnary) {
|
308
321
|
VALUE vmdai;
|
@@ -462,7 +475,6 @@ na_mdai_for_struct(na_mdai_t *mdai, int ndim)
|
|
462
475
|
VALUE val;
|
463
476
|
narray_t *na;
|
464
477
|
|
465
|
-
//fprintf(stderr,"ndim=%d\n",ndim); rb_p(mdai->na_type);
|
466
478
|
if (ndim>4) { abort(); }
|
467
479
|
val = mdai->item[ndim].val;
|
468
480
|
|
@@ -488,7 +500,6 @@ na_mdai_for_struct(na_mdai_t *mdai, int ndim)
|
|
488
500
|
rb_raise(rb_eStandardError,
|
489
501
|
"cannot convert from a recursive Array to NArray");
|
490
502
|
}
|
491
|
-
//fprintf(stderr,"check:"); rb_p(val);
|
492
503
|
// val is a Struct recort
|
493
504
|
if (RTEST( nst_check_compatibility(mdai->na_type, val) )) {
|
494
505
|
//fputs("compati\n",stderr);
|
@@ -496,7 +507,6 @@ na_mdai_for_struct(na_mdai_t *mdai, int ndim)
|
|
496
507
|
}
|
497
508
|
// otherwise, multi-dimension
|
498
509
|
if (ndim >= mdai->capa) {
|
499
|
-
//fprintf(stderr,"exeed capa\n"); abort();
|
500
510
|
na_mdai_realloc(mdai,4);
|
501
511
|
}
|
502
512
|
// finally, multidimension-check
|
@@ -510,10 +520,8 @@ na_mdai_for_struct(na_mdai_t *mdai, int ndim)
|
|
510
520
|
}
|
511
521
|
for (i=0; i < len; i++) {
|
512
522
|
v = RARRAY_AREF(val,i);
|
513
|
-
//fprintf(stderr,"check:"); rb_p(v);
|
514
523
|
mdai->item[ndim+1].val = v;
|
515
524
|
if ( na_mdai_for_struct( mdai, ndim+1 ) == 0 ) {
|
516
|
-
//fprintf(stderr,"not struct:"); rb_p(v);
|
517
525
|
//abort();
|
518
526
|
return 0;
|
519
527
|
}
|
@@ -524,7 +532,6 @@ na_mdai_for_struct(na_mdai_t *mdai, int ndim)
|
|
524
532
|
return 1;
|
525
533
|
}
|
526
534
|
|
527
|
-
//fprintf(stderr,"invalid for struct:"); rb_p(val); abort();
|
528
535
|
return 0;
|
529
536
|
}
|
530
537
|
*/
|
@@ -544,7 +551,6 @@ na_ary_composition_for_struct(VALUE nstruct, VALUE ary)
|
|
544
551
|
nc = na_compose_alloc();
|
545
552
|
vnc = WrapCompose(nc);
|
546
553
|
na_mdai_result(mdai, nc);
|
547
|
-
//fprintf(stderr,"nc->ndim=%d\n",nc->ndim);
|
548
554
|
rb_gc_force_recycle(vmdai);
|
549
555
|
return vnc;
|
550
556
|
}
|
data/ext/numo/narray/data.c
CHANGED
@@ -14,44 +14,44 @@ static ID id_swap_byte;
|
|
14
14
|
|
15
15
|
// ---------------------------------------------------------------------
|
16
16
|
|
17
|
-
#define LOOP_UNARY_PTR(lp, proc)
|
18
|
-
{
|
19
|
-
size_t i;
|
20
|
-
ssize_t s1, s2;
|
21
|
-
char *p1, *p2;
|
22
|
-
size_t *idx1, *idx2;
|
23
|
-
INIT_COUNTER(lp, i);
|
24
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
25
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
26
|
-
if (idx1) {
|
27
|
-
if (idx2) {
|
28
|
-
for (; i--;) {
|
29
|
-
proc((p1 + *idx1), (p2 + *idx2));
|
30
|
-
idx1++;
|
31
|
-
idx2++;
|
32
|
-
}
|
33
|
-
} else {
|
34
|
-
for (; i--;) {
|
35
|
-
proc((p1 + *idx1), p2);
|
36
|
-
idx1++;
|
37
|
-
p2 += s2;
|
38
|
-
}
|
39
|
-
}
|
40
|
-
} else {
|
41
|
-
if (idx2) {
|
42
|
-
for (; i--;) {
|
43
|
-
proc(p1, (p1 + *idx2));
|
44
|
-
p1 += s1;
|
45
|
-
idx2++;
|
46
|
-
}
|
47
|
-
} else {
|
48
|
-
for (; i--;) {
|
49
|
-
proc(p1, p2);
|
50
|
-
p1 += s1;
|
51
|
-
p2 += s2;
|
52
|
-
}
|
53
|
-
}
|
54
|
-
}
|
17
|
+
#define LOOP_UNARY_PTR(lp, proc) \
|
18
|
+
{ \
|
19
|
+
size_t i; \
|
20
|
+
ssize_t s1, s2; \
|
21
|
+
char *p1, *p2; \
|
22
|
+
size_t *idx1, *idx2; \
|
23
|
+
INIT_COUNTER(lp, i); \
|
24
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1); \
|
25
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2); \
|
26
|
+
if (idx1) { \
|
27
|
+
if (idx2) { \
|
28
|
+
for (; i--;) { \
|
29
|
+
proc((p1 + *idx1), (p2 + *idx2)); \
|
30
|
+
idx1++; \
|
31
|
+
idx2++; \
|
32
|
+
} \
|
33
|
+
} else { \
|
34
|
+
for (; i--;) { \
|
35
|
+
proc((p1 + *idx1), p2); \
|
36
|
+
idx1++; \
|
37
|
+
p2 += s2; \
|
38
|
+
} \
|
39
|
+
} \
|
40
|
+
} else { \
|
41
|
+
if (idx2) { \
|
42
|
+
for (; i--;) { \
|
43
|
+
proc(p1, (p1 + *idx2)); \
|
44
|
+
p1 += s1; \
|
45
|
+
idx2++; \
|
46
|
+
} \
|
47
|
+
} else { \
|
48
|
+
for (; i--;) { \
|
49
|
+
proc(p1, p2); \
|
50
|
+
p1 += s1; \
|
51
|
+
p2 += s2; \
|
52
|
+
} \
|
53
|
+
} \
|
54
|
+
} \
|
55
55
|
}
|
56
56
|
|
57
57
|
#define m_memcpy(src, dst) memcpy(dst, src, e)
|
@@ -64,9 +64,9 @@ static void iter_copy_bytes(na_loop_t* const lp) {
|
|
64
64
|
VALUE
|
65
65
|
na_copy(VALUE self) {
|
66
66
|
VALUE v;
|
67
|
-
ndfunc_arg_in_t ain[1] = {{Qnil, 0}};
|
68
|
-
ndfunc_arg_out_t aout[1] = {{INT2FIX(0), 0}};
|
69
|
-
ndfunc_t ndf = {iter_copy_bytes, FULL_LOOP, 1, 1, ain, aout};
|
67
|
+
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
|
68
|
+
ndfunc_arg_out_t aout[1] = { { INT2FIX(0), 0 } };
|
69
|
+
ndfunc_t ndf = { iter_copy_bytes, FULL_LOOP, 1, 1, ain, aout };
|
70
70
|
|
71
71
|
v = na_ndloop(&ndf, 1, self);
|
72
72
|
return v;
|
@@ -79,14 +79,14 @@ na_store(VALUE self, VALUE src) {
|
|
79
79
|
|
80
80
|
// ---------------------------------------------------------------------
|
81
81
|
|
82
|
-
#define m_swap_byte(q1, q2)
|
83
|
-
{
|
84
|
-
size_t j;
|
85
|
-
memcpy(b1, q1, e);
|
86
|
-
for (j = 0; j < e; j++) {
|
87
|
-
b2[e - 1 - j] = b1[j];
|
88
|
-
}
|
89
|
-
memcpy(q2, b2, e);
|
82
|
+
#define m_swap_byte(q1, q2) \
|
83
|
+
{ \
|
84
|
+
size_t j; \
|
85
|
+
memcpy(b1, q1, e); \
|
86
|
+
for (j = 0; j < e; j++) { \
|
87
|
+
b2[e - 1 - j] = b1[j]; \
|
88
|
+
} \
|
89
|
+
memcpy(q2, b2, e); \
|
90
90
|
}
|
91
91
|
|
92
92
|
static void iter_swap_byte(na_loop_t* const lp) {
|
@@ -101,9 +101,9 @@ static void iter_swap_byte(na_loop_t* const lp) {
|
|
101
101
|
|
102
102
|
static VALUE nary_swap_byte(VALUE self) {
|
103
103
|
VALUE v;
|
104
|
-
ndfunc_arg_in_t ain[1] = {{Qnil, 0}};
|
105
|
-
ndfunc_arg_out_t aout[1] = {{INT2FIX(0), 0}};
|
106
|
-
ndfunc_t ndf = {iter_swap_byte, FULL_LOOP | NDF_ACCEPT_BYTESWAP, 1, 1, ain, aout};
|
104
|
+
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
|
105
|
+
ndfunc_arg_out_t aout[1] = { { INT2FIX(0), 0 } };
|
106
|
+
ndfunc_t ndf = { iter_swap_byte, FULL_LOOP | NDF_ACCEPT_BYTESWAP, 1, 1, ain, aout };
|
107
107
|
|
108
108
|
v = na_ndloop(&ndf, 1, self);
|
109
109
|
if (self != v) {
|
@@ -231,11 +231,11 @@ static VALUE na_transpose_map(VALUE self, int* map) {
|
|
231
231
|
return view;
|
232
232
|
}
|
233
233
|
|
234
|
-
#define SWAP(a, b, tmp)
|
235
|
-
{
|
236
|
-
tmp = a;
|
237
|
-
a = b;
|
238
|
-
b = tmp;
|
234
|
+
#define SWAP(a, b, tmp) \
|
235
|
+
{ \
|
236
|
+
tmp = a; \
|
237
|
+
a = b; \
|
238
|
+
b = tmp; \
|
239
239
|
}
|
240
240
|
|
241
241
|
static VALUE na_transpose(int argc, VALUE* argv, VALUE self) {
|
@@ -656,19 +656,23 @@ static VALUE na_diagonal(int argc, VALUE* argv, VALUE self) {
|
|
656
656
|
k0 = 0;
|
657
657
|
k1 = kofs;
|
658
658
|
if (k1 >= na->shape[ax[1]]) {
|
659
|
-
rb_raise(
|
660
|
-
|
661
|
-
|
662
|
-
|
659
|
+
rb_raise(
|
660
|
+
rb_eArgError,
|
661
|
+
"invalid diagonal offset(%" SZF "d) for "
|
662
|
+
"last dimension size(%" SZF "d)",
|
663
|
+
kofs, na->shape[ax[1]]
|
664
|
+
);
|
663
665
|
}
|
664
666
|
} else {
|
665
667
|
k0 = -kofs;
|
666
668
|
k1 = 0;
|
667
669
|
if (k0 >= na->shape[ax[0]]) {
|
668
|
-
rb_raise(
|
669
|
-
|
670
|
-
|
671
|
-
|
670
|
+
rb_raise(
|
671
|
+
rb_eArgError,
|
672
|
+
"invalid diagonal offset(=%" SZF "d) for "
|
673
|
+
"last-1 dimension size(%" SZF "d)",
|
674
|
+
kofs, na->shape[ax[0]]
|
675
|
+
);
|
672
676
|
}
|
673
677
|
}
|
674
678
|
|
@@ -777,11 +781,11 @@ static VALUE na_diagonal(int argc, VALUE* argv, VALUE self) {
|
|
777
781
|
#ifdef SWAP
|
778
782
|
#undef SWAP
|
779
783
|
#endif
|
780
|
-
#define SWAP(a, b, t)
|
781
|
-
{
|
782
|
-
t = a;
|
783
|
-
a = b;
|
784
|
-
b = t;
|
784
|
+
#define SWAP(a, b, t) \
|
785
|
+
{ \
|
786
|
+
t = a; \
|
787
|
+
a = b; \
|
788
|
+
b = t; \
|
785
789
|
}
|
786
790
|
|
787
791
|
static VALUE
|
data/ext/numo/narray/extconf.rb
CHANGED
data/ext/numo/narray/index.c
CHANGED
@@ -71,7 +71,10 @@ static void na_index_set_step(na_index_arg_t* q, int i, size_t n, size_t beg, ss
|
|
71
71
|
}
|
72
72
|
|
73
73
|
static void na_index_set_scalar(na_index_arg_t* q, int i, ssize_t size, ssize_t x) {
|
74
|
-
if (x < -size || x >= size)
|
74
|
+
if (x < -size || x >= size)
|
75
|
+
rb_raise(
|
76
|
+
rb_eRangeError, "array index (%" SZF "d) is out of array size (%" SZF "d)", x, size
|
77
|
+
);
|
75
78
|
if (x < 0) x += size;
|
76
79
|
q->n = 1;
|
77
80
|
q->beg = x;
|
@@ -172,7 +175,8 @@ static void na_parse_narray_index(VALUE a, int orig_dim, ssize_t size, na_index_
|
|
172
175
|
q->orig_dim = orig_dim;
|
173
176
|
}
|
174
177
|
|
175
|
-
static void
|
178
|
+
static void
|
179
|
+
na_parse_range(VALUE range, ssize_t step, int orig_dim, ssize_t size, na_index_arg_t* q) {
|
176
180
|
int n;
|
177
181
|
ssize_t beg, end, beg_orig, end_orig;
|
178
182
|
const char *dot = "..", *edot = "...";
|
@@ -192,7 +196,9 @@ static void na_parse_range(VALUE range, ssize_t step, int orig_dim, ssize_t size
|
|
192
196
|
dot = edot;
|
193
197
|
}
|
194
198
|
if (beg < 0 || beg >= size) {
|
195
|
-
rb_raise(
|
199
|
+
rb_raise(
|
200
|
+
rb_eRangeError, "%" SZF "d%s is out of range for size=%" SZF "d", beg_orig, dot, size
|
201
|
+
);
|
196
202
|
}
|
197
203
|
} else {
|
198
204
|
end = end_orig = NUM2SSIZET(x.end);
|
@@ -204,7 +210,10 @@ static void na_parse_range(VALUE range, ssize_t step, int orig_dim, ssize_t size
|
|
204
210
|
dot = edot;
|
205
211
|
}
|
206
212
|
if (beg < 0 || beg >= size || end < 0 || end >= size) {
|
207
|
-
rb_raise(
|
213
|
+
rb_raise(
|
214
|
+
rb_eRangeError, "%" SZF "d%s%" SZF "d is out of range for size=%" SZF "d", beg_orig,
|
215
|
+
dot, end_orig, size
|
216
|
+
);
|
208
217
|
}
|
209
218
|
}
|
210
219
|
#else
|
@@ -224,7 +233,10 @@ static void na_parse_range(VALUE range, ssize_t step, int orig_dim, ssize_t size
|
|
224
233
|
dot = edot;
|
225
234
|
}
|
226
235
|
if (beg < 0 || beg >= size || end < 0 || end >= size) {
|
227
|
-
rb_raise(
|
236
|
+
rb_raise(
|
237
|
+
rb_eRangeError, "%" SZF "d%s%" SZF "d is out of range for size=%" SZF "d", beg_orig, dot,
|
238
|
+
end_orig, size
|
239
|
+
);
|
228
240
|
}
|
229
241
|
#endif
|
230
242
|
n = (int)((end - beg) / step + 1);
|
@@ -342,7 +354,8 @@ static void na_index_parse_each(volatile VALUE a, ssize_t size, int i, na_index_
|
|
342
354
|
}
|
343
355
|
}
|
344
356
|
|
345
|
-
static void
|
357
|
+
static void
|
358
|
+
na_at_parse_each(volatile VALUE a, ssize_t size, int i, VALUE* idx, ssize_t stride) {
|
346
359
|
na_index_arg_t q;
|
347
360
|
size_t n, k;
|
348
361
|
ssize_t* index;
|
@@ -444,7 +457,6 @@ static size_t na_index_parse_args(VALUE args, narray_t* na, na_index_arg_t* q, i
|
|
444
457
|
// rest (ellipsis) dimension
|
445
458
|
if (v == Qfalse) {
|
446
459
|
for (l = ndim - (nidx - 1); l > 0; l--) {
|
447
|
-
// printf("i=%d j=%d k=%d l=%d ndim=%d nidx=%d\n",i,j,k,l,ndim,nidx);
|
448
460
|
na_index_parse_each(Qtrue, na->shape[k], k, &q[j]);
|
449
461
|
if (q[j].n > 1) {
|
450
462
|
total *= q[j].n;
|
@@ -481,8 +493,10 @@ static void na_get_strides_nadata(const narray_data_t* na, ssize_t* strides, ssi
|
|
481
493
|
}
|
482
494
|
}
|
483
495
|
|
484
|
-
static void na_index_aref_nadata(
|
485
|
-
|
496
|
+
static void na_index_aref_nadata(
|
497
|
+
narray_data_t* na1, narray_view_t* na2, na_index_arg_t* q, ssize_t elmsz, int ndim,
|
498
|
+
int keep_dim
|
499
|
+
) {
|
486
500
|
int i, j;
|
487
501
|
ssize_t size, k, total = 1;
|
488
502
|
ssize_t stride1;
|
@@ -531,8 +545,10 @@ static void na_index_aref_nadata(narray_data_t* na1, narray_view_t* na2, na_inde
|
|
531
545
|
na2->base.size = total;
|
532
546
|
}
|
533
547
|
|
534
|
-
static void na_index_aref_naview(
|
535
|
-
|
548
|
+
static void na_index_aref_naview(
|
549
|
+
narray_view_t* na1, narray_view_t* na2, na_index_arg_t* q, ssize_t elmsz, int ndim,
|
550
|
+
int keep_dim
|
551
|
+
) {
|
536
552
|
int i, j;
|
537
553
|
ssize_t total = 1;
|
538
554
|
|
@@ -779,10 +795,12 @@ static int check_index_count(int argc, int na_ndim, int count_new, int count_res
|
|
779
795
|
case 0:
|
780
796
|
if (argc == 1 && count_new == 0) return 1;
|
781
797
|
if (argc == result_nd) return result_nd;
|
782
|
-
rb_raise(
|
783
|
-
|
784
|
-
|
785
|
-
|
798
|
+
rb_raise(
|
799
|
+
rb_eIndexError,
|
800
|
+
"# of index(=%i) should be "
|
801
|
+
"equal to ndim(=%i) or 1",
|
802
|
+
argc, na_ndim
|
803
|
+
);
|
786
804
|
break;
|
787
805
|
case 1:
|
788
806
|
if (argc - 1 <= result_nd) return result_nd;
|
@@ -794,7 +812,9 @@ static int check_index_count(int argc, int na_ndim, int count_new, int count_res
|
|
794
812
|
return -1;
|
795
813
|
}
|
796
814
|
|
797
|
-
int na_get_result_dimension(
|
815
|
+
int na_get_result_dimension(
|
816
|
+
VALUE self, int argc, VALUE* argv, ssize_t stride, size_t* pos_idx
|
817
|
+
) {
|
798
818
|
int i, j;
|
799
819
|
int count_new = 0;
|
800
820
|
int count_rest = 0;
|
@@ -890,10 +910,12 @@ int na_get_result_dimension(VALUE self, int argc, VALUE* argv, ssize_t stride, s
|
|
890
910
|
return 0;
|
891
911
|
}
|
892
912
|
}
|
893
|
-
rb_raise(
|
894
|
-
|
895
|
-
|
896
|
-
|
913
|
+
rb_raise(
|
914
|
+
rb_eIndexError,
|
915
|
+
"# of index(=%i) should be "
|
916
|
+
"equal to ndim(=%i) or 1",
|
917
|
+
argc, na->ndim
|
918
|
+
);
|
897
919
|
return -1;
|
898
920
|
}
|
899
921
|
|
@@ -936,11 +958,12 @@ static VALUE na_slice(int argc, VALUE* argv, VALUE self) {
|
|
936
958
|
|
937
959
|
/*
|
938
960
|
Multi-dimensional element reference.
|
939
|
-
Returns an element at `dim0`, `dim1`, ... are Numeric indices for each dimension, or returns a
|
940
|
-
if `dim0`, `dim1`, ... includes other than Numeric index, e.g.,
|
961
|
+
Returns an element at `dim0`, `dim1`, ... are Numeric indices for each dimension, or returns a
|
962
|
+
NArray View as a sliced array if `dim0`, `dim1`, ... includes other than Numeric index, e.g.,
|
963
|
+
Range or Array or true.
|
941
964
|
@overload [](dim0,...,dimL)
|
942
|
-
@param [Numeric,Range,Array,Numo::Int32,Numo::Int64,Numo::Bit,TrueClass,FalseClass,Symbol]
|
943
|
-
indices.
|
965
|
+
@param [Numeric,Range,Array,Numo::Int32,Numo::Int64,Numo::Bit,TrueClass,FalseClass,Symbol]
|
966
|
+
dim0,...,dimL multi-dimensional indices.
|
944
967
|
@return [Numeric,Numo::NArray] an element or NArray view.
|
945
968
|
@see #[]=
|
946
969
|
@see #at
|
@@ -980,8 +1003,8 @@ static VALUE na_slice(int argc, VALUE* argv, VALUE self) {
|
|
980
1003
|
Replace element(s) at `dim0`, `dim1`, ... .
|
981
1004
|
Broadcasting mechanism is applied.
|
982
1005
|
@overload []=(dim0,...,dimL,val)
|
983
|
-
@param [Numeric,Range,Array,Numo::Int32,Numo::Int64,Numo::Bit,TrueClass,FalseClass,Symbol]
|
984
|
-
indices.
|
1006
|
+
@param [Numeric,Range,Array,Numo::Int32,Numo::Int64,Numo::Bit,TrueClass,FalseClass,Symbol]
|
1007
|
+
dim0,...,dimL multi-dimensional indices.
|
985
1008
|
@param [Numeric,Numo::NArray,Array] val Value(s) to be set to self.
|
986
1009
|
@return [Numeric,Numo::NArray,Array] returns `val` (last argument).
|
987
1010
|
@see #[]
|