numo-narray-alt 0.9.3 → 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/Gemfile +6 -0
- data/README.md +9 -3
- data/Rakefile +26 -6
- 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 +54 -29
- 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 +23 -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 +8 -2
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/Gemfile
CHANGED
@@ -5,10 +5,16 @@ source 'https://rubygems.org'
|
|
5
5
|
# Specify your gem's dependencies in narray-devel.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
+
gem 'minitest', '~> 5.25'
|
8
9
|
gem 'rake', '~> 13.3'
|
9
10
|
gem 'rake-compiler', '~> 1.3'
|
10
11
|
gem 'rubocop', '~> 1.80'
|
12
|
+
gem 'rubocop-minitest', '~> 0.38.2'
|
11
13
|
gem 'rubocop-performance', '~> 1.26'
|
12
14
|
gem 'rubocop-rake', '~> 0.7.1'
|
13
15
|
gem 'simplecov', '~> 0.22.0'
|
14
16
|
gem 'test-unit', '~> 3.7'
|
17
|
+
|
18
|
+
group :memcheck, optional: true do
|
19
|
+
gem 'ruby_memcheck', '~> 3.0' if RUBY_VERSION.split('.')[0].to_i >= 3
|
20
|
+
end
|
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,14 +11,34 @@ 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
|
+
|
20
|
+
require 'ruby_memcheck' if ENV['BUNDLE_WITH'] == 'memcheck'
|
14
21
|
require 'rake/testtask'
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
22
|
+
|
23
|
+
if ENV['BUNDLE_WITH'] == 'memcheck'
|
24
|
+
test_config = lambda do |t|
|
25
|
+
t.libs << 'test'
|
26
|
+
t.libs << 'lib'
|
27
|
+
t.test_files = FileList['test/**/test_*.rb']
|
28
|
+
end
|
29
|
+
Rake::TestTask.new(test: :compile, &test_config)
|
30
|
+
namespace :test do
|
31
|
+
RubyMemcheck::TestTask.new(valgrind: :compile, &test_config)
|
32
|
+
end
|
33
|
+
else
|
34
|
+
Rake::TestTask.new(:test) do |t|
|
35
|
+
t.libs << 'test'
|
36
|
+
t.libs << 'lib'
|
37
|
+
t.test_files = FileList['test/**/test_*.rb']
|
38
|
+
end
|
21
39
|
end
|
22
40
|
|
23
41
|
require 'rake/extensiontask'
|
24
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
|