numo-narray-alt 0.9.4 → 0.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -0
  3. data/README.md +22 -3
  4. data/Rakefile +8 -0
  5. data/ext/numo/narray/SFMT-params19937.h +16 -12
  6. data/ext/numo/narray/SFMT.c +12 -5
  7. data/ext/numo/narray/array.c +51 -21
  8. data/ext/numo/narray/data.c +88 -86
  9. data/ext/numo/narray/index.c +51 -28
  10. data/ext/numo/narray/kwargs.c +11 -9
  11. data/ext/numo/narray/math.c +14 -6
  12. data/ext/numo/narray/narray.c +93 -58
  13. data/ext/numo/narray/ndloop.c +52 -63
  14. data/ext/numo/narray/numo/intern.h +9 -3
  15. data/ext/numo/narray/numo/narray.h +20 -20
  16. data/ext/numo/narray/numo/ndloop.h +1 -1
  17. data/ext/numo/narray/numo/template.h +85 -81
  18. data/ext/numo/narray/numo/types/bit.h +76 -0
  19. data/ext/numo/narray/numo/types/complex.h +7 -3
  20. data/ext/numo/narray/numo/types/complex_macro.h +28 -25
  21. data/ext/numo/narray/numo/types/float_macro.h +21 -17
  22. data/ext/numo/narray/numo/types/real_accum.h +22 -22
  23. data/ext/numo/narray/numo/types/robj_macro.h +20 -12
  24. data/ext/numo/narray/numo/types/xint_macro.h +51 -8
  25. data/ext/numo/narray/rand.c +7 -0
  26. data/ext/numo/narray/src/mh/mean.h +102 -0
  27. data/ext/numo/narray/src/mh/rms.h +102 -0
  28. data/ext/numo/narray/src/mh/stddev.h +103 -0
  29. data/ext/numo/narray/src/mh/var.h +102 -0
  30. data/ext/numo/narray/src/t_bit.c +206 -147
  31. data/ext/numo/narray/src/t_dcomplex.c +531 -641
  32. data/ext/numo/narray/src/t_dfloat.c +1341 -1421
  33. data/ext/numo/narray/src/t_int16.c +562 -468
  34. data/ext/numo/narray/src/t_int32.c +562 -468
  35. data/ext/numo/narray/src/t_int64.c +561 -467
  36. data/ext/numo/narray/src/t_int8.c +520 -448
  37. data/ext/numo/narray/src/t_robject.c +519 -619
  38. data/ext/numo/narray/src/t_scomplex.c +524 -659
  39. data/ext/numo/narray/src/t_sfloat.c +1332 -1410
  40. data/ext/numo/narray/src/t_uint16.c +562 -468
  41. data/ext/numo/narray/src/t_uint32.c +562 -468
  42. data/ext/numo/narray/src/t_uint64.c +562 -468
  43. data/ext/numo/narray/src/t_uint8.c +522 -448
  44. data/ext/numo/narray/step.c +7 -2
  45. data/ext/numo/narray/struct.c +31 -24
  46. data/lib/numo/narray/extra.rb +74 -30
  47. data/numo-narray-alt.gemspec +38 -0
  48. metadata +10 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e9e18fd6506f406eafb8165f2d167f71ab53c77801c5fbcf9124eb9c5aa49e9
4
- data.tar.gz: 064b228731e03805711f7f2d662ddb71305df3125b75738106e7ed477dc22415
3
+ metadata.gz: 819274f9f9bc411b8276d69966bcba8aa94bc6d61f73920f653411729e4ef247
4
+ data.tar.gz: c4ccb23dd013573cd80bd8ab73398fd1a67adf6018a8bd55eebff776a69df6d8
5
5
  SHA512:
6
- metadata.gz: af18cc5d7d017240601b59c80ec8d4a804a03e206ede0ede39fc85c0c50aad62de385c6e0df72931435c16297851a093beda4991baa9a0ce9fdbb20fa8965a44
7
- data.tar.gz: f1149100a201b20cfda5d8a382e04b19f6b30a19f775139a72c80ae87ce41a55b4ff362f7ea62bc623613f179a009c7ef05811b3b5daddad4f330bafd7a6d0aa
6
+ metadata.gz: 35056f83d76f4c565f45b97ee8c9c992e6e3f3d77bd63b4ad7102d26631e4fbd82caaec87cb188bd2b23baf9785068923c6e54c441a6c188492526c848e2d0c0
7
+ data.tar.gz: 78f1154e6e77b6d9848b5a8c1e8d5818b7daeb891f5f476950eff003d7045022f7f57b0518c51c192756bd9b140e5bef737236d168b9918fe2610365388ac2f4
data/Gemfile CHANGED
@@ -5,15 +5,18 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in narray-devel.gemspec
6
6
  gemspec
7
7
 
8
+ gem 'irb', '~> 1.15'
8
9
  gem 'minitest', '~> 5.25'
9
10
  gem 'rake', '~> 13.3'
10
11
  gem 'rake-compiler', '~> 1.3'
12
+ gem 'rdoc', '~> 6.15'
11
13
  gem 'rubocop', '~> 1.80'
12
14
  gem 'rubocop-minitest', '~> 0.38.2'
13
15
  gem 'rubocop-performance', '~> 1.26'
14
16
  gem 'rubocop-rake', '~> 0.7.1'
15
17
  gem 'simplecov', '~> 0.22.0'
16
18
  gem 'test-unit', '~> 3.7'
19
+ gem 'yard', '~> 0.9.37'
17
20
 
18
21
  group :memcheck, optional: true do
19
22
  gem 'ruby_memcheck', '~> 3.0' if RUBY_VERSION.split('.')[0].to_i >= 3
data/README.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Numo::NArray Alternative
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/numo-narray-alt.svg)](https://badge.fury.io/rb/numo-narray-alt)
4
+ [![Build Status](https://github.com/yoshoku/numo-narray-alt/actions/workflows/build.yml/badge.svg)](https://github.com/yoshoku/numo-narray-alt/actions/workflows/build.yml)
5
+ [![BSD 3-Clause License](https://img.shields.io/badge/License-BSD%203--Clause-orange.svg)](https://github.com/yoshoku/numo-narray-alt/blob/main/LICENSE)
6
+ [![Documentation](https://img.shields.io/badge/api-reference-blue.svg)](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,
@@ -35,6 +40,19 @@ Numo::DFloat#shape=[2,2]
35
40
  irb(main):004>
36
41
  ```
37
42
 
43
+ ## Related Projects
44
+
45
+ Numo::NArray Alternative is used in the following projects:
46
+
47
+ - [numo-linalg-alt](https://github.com/yoshoku/numo-linalg-alt): Linear algebra library with BLAS/LAPACK.
48
+ - [numo-optimize](https://github.com/yoshoku/numo-optimize): Optimization library for minimizing objective functions.
49
+ - [numo-random](https://github.com/yoshoku/numo-random): Random number generation library with several distributions.
50
+ - [numo-pocketfft](https://github.com/yoshoku/numo-pocketfft): Fourier transform library with pocketfft.
51
+ - [numo-libsvm](https://github.com/yoshoku/numo-libsvm): LIBSVM bindings library for numo-narray-alt.
52
+ - [numo-liblinear](https://github.com/yoshoku/numo-liblinear): LIBLINEAR bindings library for numo-narray-alt.
53
+ - [numo-linalg-randsvd](https://github.com/yoshoku/numo-linalg-randsvd): Randomized SVD library for numo-linalg-alt.
54
+ - [rumale](https://github.com/yoshoku/rumale): Machine learning library.
55
+
38
56
  ## Development
39
57
 
40
58
  preparation:
@@ -61,9 +79,10 @@ $ clang-format --dry-run --Werror --style=file ext/**/*.h ext/**/*.c
61
79
 
62
80
  ## Contributing
63
81
 
64
- This project is in an early experimental stage.
65
- Therefore, we are not accepting any Issues or Pull Requests at this time.
66
- Thank you for your understanding.
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yoshoku/numo-narray-alt.
83
+ This project is intended to be a safe, welcoming space for collaboration,
84
+ and contributors are expected to adhere to
85
+ the [code of conduct](https://github.com/yoshoku/numo-narray-alt/blob/main/CODE_OF_CONDUCT.md).
67
86
 
68
87
  ## License
69
88
 
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 (vector unsigned char)(1, 2, 3, 23, 5, 6, 7, 0, 9, 10, 11, 4, 13, 14, 15, 8)
25
- #define ALTI_SL2_PERM64 (vector unsigned char)(1, 2, 3, 4, 5, 6, 7, 31, 9, 10, 11, 12, 13, 14, 15, 0)
26
- #define ALTI_SR2_PERM (vector unsigned char)(7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10, 17, 12, 13, 14)
27
- #define ALTI_SR2_PERM64 (vector unsigned char)(15, 0, 1, 2, 3, 4, 5, 6, 17, 8, 9, 10, 11, 12, 13, 14)
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"
@@ -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)] = 1812433253UL * (psfmt32[idxof(i - 1)] ^ (psfmt32[idxof(i - 1)] >> 30)) + 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(psfmt32[idxof(i)] ^ psfmt32[idxof((i + mid) % N32)] ^ psfmt32[idxof((i + N32 - 1) % N32)]);
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(psfmt32[idxof(i)] ^ psfmt32[idxof((i + mid) % N32)] ^ psfmt32[idxof((i + N32 - 1) % N32)]);
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(psfmt32[idxof(i)] + psfmt32[idxof((i + mid) % N32)] + psfmt32[idxof((i + N32 - 1) % N32)]);
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;
@@ -22,7 +22,17 @@ typedef struct {
22
22
  } na_mdai_t;
23
23
 
24
24
  // Order of Ruby object.
25
- enum { NA_NONE, NA_BIT, NA_INT32, NA_INT64, NA_RATIONAL, NA_DFLOAT, NA_DCOMPLEX, NA_ROBJ, NA_NTYPES };
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)) && RTEST(rb_funcall(v, id_ge, 1, int32_min))) {
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) rb_raise(rb_eStandardError, "cannot convert from a recursive Array to NArray");
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
- NULL,
300
- na_mdai_free,
301
- na_mdai_memsize,
302
- },
303
- 0,
304
- 0,
305
- RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED};
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;
@@ -433,8 +446,8 @@ static VALUE na_s_array_type(VALUE mod, VALUE ary) {
433
446
  /*
434
447
  Generate NArray object. NArray datatype is automatically selected.
435
448
  @overload [](elements)
436
- @param [Numeric,Array] elements
437
- @return [NArray]
449
+ @param [Numeric,Array] elements
450
+ @return [NArray]
438
451
  */
439
452
  static VALUE nary_s_bracket(VALUE klass, VALUE ary) {
440
453
  VALUE dtype = Qnil;
@@ -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,14 +551,37 @@ 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
  }
551
557
  */
552
558
 
553
559
  void Init_nary_array(void) {
560
+ /**
561
+ * return shape of NArray which would be created from given Array.
562
+ * @overload array_shape(ary)
563
+ * @param [Array] ary
564
+ * @return [Array] shape
565
+ * @example
566
+ * Numo::NArray.array_shape([[1, 2, 3],[4, 5, 6]])
567
+ * # => [2,3]
568
+ * Numo::NArray.array_shape(Numo::DFloat[[1, 2, 3], [4, 5, 6]])
569
+ * # => []
570
+ */
554
571
  rb_define_singleton_method(cNArray, "array_shape", na_s_array_shape, 1);
572
+ /**
573
+ * return type of NArray which would be created from given Array.
574
+ * @overload array_type(ary)
575
+ * @param [Array] ary
576
+ * @return [Class] NArray class
577
+ * @example
578
+ * Numo::NArray.array_type([1, 2, 3])
579
+ * # => Numo::Int32
580
+ * Numo::NArray.array_type([0, 1, 2i])
581
+ * # => Numo::DComplex
582
+ * Numo::NArray.array_type(Numo::DFloat[1, 2, 3])
583
+ * # => Numo::DFloat
584
+ */
555
585
  rb_define_singleton_method(cNArray, "array_type", na_s_array_type, 1);
556
586
  rb_define_singleton_method(cNArray, "new_like", na_s_new_like, 1);
557
587
 
@@ -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) {
@@ -156,9 +156,9 @@ static inline int check_axis(int axis, int ndim) {
156
156
  /*
157
157
  Interchange two axes.
158
158
  @overload swapaxes(axis1,axis2)
159
- @param [Integer] axis1
160
- @param [Integer] axis2
161
- @return [Numo::NArray] view of NArray.
159
+ @param [Integer] axis1
160
+ @param [Integer] axis2
161
+ @return [Numo::NArray] view of NArray.
162
162
  @example
163
163
  x = Numo::Int32[[1,2,3]]
164
164
 
@@ -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) {
@@ -355,9 +355,8 @@ static void na_check_reshape(int argc, VALUE* argv, VALUE self, size_t* shape) {
355
355
  Raise exception if self is non-contiguous.
356
356
 
357
357
  @overload reshape!(size0,size1,...)
358
- @param sizeN [Integer] new shape
359
- @return [Numo::NArray] return self.
360
- @example
358
+ @param sizeN [Integer] new shape
359
+ @return [Numo::NArray] return self.
361
360
  */
362
361
  static VALUE na_reshape_bang(int argc, VALUE* argv, VALUE self) {
363
362
  size_t* shape;
@@ -400,9 +399,8 @@ static VALUE na_reshape_bang(int argc, VALUE* argv, VALUE self) {
400
399
  Returns a copied NArray.
401
400
 
402
401
  @overload reshape(size0,size1,...)
403
- @param sizeN [Integer] new shape
404
- @return [Numo::NArray] return self.
405
- @example
402
+ @param sizeN [Integer] new shape
403
+ @return [Numo::NArray] return self.
406
404
  */
407
405
  static VALUE na_reshape(int argc, VALUE* argv, VALUE self) {
408
406
  size_t* shape;
@@ -545,13 +543,13 @@ na_flatten(VALUE self) {
545
543
  /*
546
544
  Returns a diagonal view of NArray
547
545
  @overload diagonal([offset,axes])
548
- @param [Integer] offset Diagonal offset from the main diagonal.
549
- The default is 0. k>0 for diagonals above the main diagonal,
550
- and k<0 for diagonals below the main diagonal.
551
- @param [Array] axes Array of axes to be used as the 2-d sub-arrays
552
- from which the diagonals should be taken. Defaults to last-two
553
- axes ([-2,-1]).
554
- @return [Numo::NArray] diagonal view of NArray.
546
+ @param [Integer] offset Diagonal offset from the main diagonal.
547
+ The default is 0. k>0 for diagonals above the main diagonal,
548
+ and k<0 for diagonals below the main diagonal.
549
+ @param [Array] axes Array of axes to be used as the 2-d sub-arrays
550
+ from which the diagonals should be taken. Defaults to last-two
551
+ axes ([-2,-1]).
552
+ @return [Numo::NArray] diagonal view of NArray.
555
553
  @example
556
554
  a = Numo::DFloat.new(4,5).seq
557
555
  # => Numo::DFloat#shape=[4,5]
@@ -656,19 +654,23 @@ static VALUE na_diagonal(int argc, VALUE* argv, VALUE self) {
656
654
  k0 = 0;
657
655
  k1 = kofs;
658
656
  if (k1 >= na->shape[ax[1]]) {
659
- rb_raise(rb_eArgError,
660
- "invalid diagonal offset(%" SZF "d) for "
661
- "last dimension size(%" SZF "d)",
662
- kofs, na->shape[ax[1]]);
657
+ rb_raise(
658
+ rb_eArgError,
659
+ "invalid diagonal offset(%" SZF "d) for "
660
+ "last dimension size(%" SZF "d)",
661
+ kofs, na->shape[ax[1]]
662
+ );
663
663
  }
664
664
  } else {
665
665
  k0 = -kofs;
666
666
  k1 = 0;
667
667
  if (k0 >= na->shape[ax[0]]) {
668
- rb_raise(rb_eArgError,
669
- "invalid diagonal offset(=%" SZF "d) for "
670
- "last-1 dimension size(%" SZF "d)",
671
- kofs, na->shape[ax[0]]);
668
+ rb_raise(
669
+ rb_eArgError,
670
+ "invalid diagonal offset(=%" SZF "d) for "
671
+ "last-1 dimension size(%" SZF "d)",
672
+ kofs, na->shape[ax[0]]
673
+ );
672
674
  }
673
675
  }
674
676
 
@@ -777,11 +779,11 @@ static VALUE na_diagonal(int argc, VALUE* argv, VALUE self) {
777
779
  #ifdef SWAP
778
780
  #undef SWAP
779
781
  #endif
780
- #define SWAP(a, b, t) \
781
- { \
782
- t = a; \
783
- a = b; \
784
- b = t; \
782
+ #define SWAP(a, b, t) \
783
+ { \
784
+ t = a; \
785
+ a = b; \
786
+ b = t; \
785
787
  }
786
788
 
787
789
  static VALUE