numo-narray 0.9.1.4 → 0.9.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -6
  3. data/Rakefile +4 -63
  4. data/ext/numo/narray/array.c +35 -32
  5. data/ext/numo/narray/data.c +40 -43
  6. data/ext/numo/narray/depend.erb +6 -10
  7. data/ext/numo/narray/extconf.rb +24 -21
  8. data/ext/numo/narray/gen/cogen.rb +2 -2
  9. data/ext/numo/narray/gen/narray_def.rb +5 -1
  10. data/ext/numo/narray/gen/spec.rb +17 -7
  11. data/ext/numo/narray/gen/tmpl/accum.c +2 -2
  12. data/ext/numo/narray/gen/tmpl/accum_arg.c +88 -0
  13. data/ext/numo/narray/gen/tmpl/accum_binary.c +1 -1
  14. data/ext/numo/narray/gen/tmpl/accum_index.c +25 -14
  15. data/ext/numo/narray/gen/tmpl/alloc_func.c +4 -1
  16. data/ext/numo/narray/gen/tmpl/allocate.c +1 -0
  17. data/ext/numo/narray/gen/tmpl/aref.c +5 -35
  18. data/ext/numo/narray/gen/tmpl/aset.c +7 -37
  19. data/ext/numo/narray/gen/tmpl/bincount.c +7 -7
  20. data/ext/numo/narray/gen/tmpl/cast.c +7 -0
  21. data/ext/numo/narray/gen/tmpl/clip.c +11 -15
  22. data/ext/numo/narray/gen/tmpl/cum.c +1 -1
  23. data/ext/numo/narray/gen/tmpl/each.c +4 -2
  24. data/ext/numo/narray/gen/tmpl/each_with_index.c +5 -2
  25. data/ext/numo/narray/gen/tmpl/lib.c +2 -2
  26. data/ext/numo/narray/gen/tmpl/logseq.c +6 -5
  27. data/ext/numo/narray/gen/tmpl/map_with_index.c +5 -6
  28. data/ext/numo/narray/gen/tmpl/median.c +2 -2
  29. data/ext/numo/narray/gen/tmpl/minmax.c +1 -1
  30. data/ext/numo/narray/gen/tmpl/poly.c +4 -4
  31. data/ext/numo/narray/gen/tmpl/qsort.c +1 -1
  32. data/ext/numo/narray/gen/tmpl/rand.c +8 -6
  33. data/ext/numo/narray/gen/tmpl/rand_norm.c +18 -16
  34. data/ext/numo/narray/gen/tmpl/seq.c +5 -4
  35. data/ext/numo/narray/gen/tmpl/sort.c +3 -3
  36. data/ext/numo/narray/gen/tmpl/sort_index.c +2 -2
  37. data/ext/numo/narray/gen/tmpl/store_array.c +14 -2
  38. data/ext/numo/narray/gen/tmpl/unary_s.c +55 -31
  39. data/ext/numo/narray/gen/tmpl_bit/allocate.c +1 -0
  40. data/ext/numo/narray/gen/tmpl_bit/aref.c +22 -30
  41. data/ext/numo/narray/gen/tmpl_bit/aset.c +20 -34
  42. data/ext/numo/narray/gen/tmpl_bit/binary.c +48 -14
  43. data/ext/numo/narray/gen/tmpl_bit/bit_count.c +5 -0
  44. data/ext/numo/narray/gen/tmpl_bit/bit_reduce.c +5 -0
  45. data/ext/numo/narray/gen/tmpl_bit/store_array.c +14 -2
  46. data/ext/numo/narray/gen/tmpl_bit/store_bit.c +27 -9
  47. data/ext/numo/narray/gen/tmpl_bit/unary.c +25 -7
  48. data/ext/numo/narray/index.c +363 -59
  49. data/ext/numo/narray/math.c +2 -2
  50. data/ext/numo/narray/narray.c +151 -36
  51. data/ext/numo/narray/ndloop.c +4 -4
  52. data/ext/numo/narray/numo/intern.h +3 -2
  53. data/ext/numo/narray/numo/narray.h +37 -14
  54. data/ext/numo/narray/numo/ndloop.h +2 -2
  55. data/ext/numo/narray/numo/template.h +11 -15
  56. data/ext/numo/narray/numo/types/complex.h +2 -2
  57. data/ext/numo/narray/numo/types/int16.h +5 -2
  58. data/ext/numo/narray/numo/types/int32.h +0 -1
  59. data/ext/numo/narray/numo/types/int64.h +0 -1
  60. data/ext/numo/narray/numo/types/int8.h +1 -2
  61. data/ext/numo/narray/numo/types/uint16.h +5 -2
  62. data/ext/numo/narray/numo/types/uint32.h +0 -1
  63. data/ext/numo/narray/numo/types/uint64.h +0 -1
  64. data/ext/numo/narray/numo/types/uint8.h +1 -2
  65. data/ext/numo/narray/numo/types/xint_macro.h +2 -0
  66. data/ext/numo/narray/step.c +58 -252
  67. data/ext/numo/narray/struct.c +3 -3
  68. data/lib/numo/narray.rb +1 -7
  69. data/lib/numo/narray/extra.rb +214 -213
  70. data/numo-narray.gemspec +7 -8
  71. metadata +17 -36
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aba2ab60aae2fbf24973f75a9b17c9f35bd7fec15c58e110b6711a62773b2de0
4
- data.tar.gz: feae74cc5b9d5dfbe238f78f60b22f017a4558b241fe772b0615ac3fa0c80b68
3
+ metadata.gz: 2de0f542db4df78b97eecd077130fb8f3146191a229698512d487916a8a57ce0
4
+ data.tar.gz: 1452f989e4dc615c0e4f4b4891c9f44072431f9face27a602ce9b91286909cbf
5
5
  SHA512:
6
- metadata.gz: f7af93ba0ac1b6732fa9bbe22f72572ecdd8c9142861c0a12ca9124eb2094fef512923ce6040a52576c835ebde4b9a697af973e68c97a9703430f92ad5d6442b
7
- data.tar.gz: b413079a3a924e698b074183d462397bd306bad255e619d1e58b52c623c175d93ca5ad72dbf17a84becc21172f10cc0cba4ea6c5d8c291cc706e20e0ff867d2e
6
+ metadata.gz: 23e67c8a70a95d69d25ad78561286eb56db63a0aa6465903ebbed1e076dfef6c4df4aa1ccd1d2f5ec40f4d02307c82c51b47c0da4cb48415c93bfdc6adaf4f27
7
+ data.tar.gz: 63847fb7e9173d0be70dc63be57ebbcb52a0dc6f52e613b7c9c69fab33f83920ba6b4b478156a18fa1fac0f6e08718713449441485149a6d9f178af7f2d87bdd
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Numo::NArray - New NArray class library for Ruby/Numo (NUmerical MOdule)
1
+ # Numo::NArray
2
2
 
3
3
  [![Binder](http://mybinder.org/badge.svg)](http://mybinder.org/repo/ruby-numo/numo-narray)
4
4
  [![Build Status](https://travis-ci.org/ruby-numo/numo-narray.svg?branch=master)](https://travis-ci.org/ruby-numo/numo-narray)
@@ -11,17 +11,17 @@ for fast processing and easy manipulation of multi-dimensional numerical data,
11
11
  similar to numpy.ndaray.
12
12
  This project is the successor to [Ruby/NArray](http://masa16.github.io/narray/).
13
13
 
14
- under development
15
-
16
14
  ## Documentation
15
+
17
16
  All documents are primitive.
18
17
 
19
- * [Numo::NArray API Doc](http://ruby-numo.github.io/narray/narray/frames.html)
18
+ * [Numo::NArray API Doc](http://ruby-numo.github.io/numo-narray/yard/index.html)
20
19
  * [Numo::NArray vs numpy](https://github.com/ruby-numo/numo-narray/wiki/Numo-vs-numpy)
21
20
  * [Numo::NArray vs ndarray](https://github.com/ruby-numo/numo-narray/wiki/Numo-vs-ndarray)
22
- * [Numo::NArray Overview](https://github.com/ruby-numo/numo-narray/wiki/Numo::NArray%E6%A6%82%E8%A6%81) (in Japanese)
21
+ * [Numo::NArray Overview](https://github.com/ruby-numo/numo-narray/wiki/Numo::NArray-Overview-(Japanese)) (in Japanese)
23
22
 
24
23
  ## Related Projects
24
+
25
25
  * [Numo::Linalg](https://github.com/ruby-numo/numo-linalg) - Linear Algebra library with [LAPACK](http://www.netlib.org/lapack/).
26
26
  * [Numo::GSL](https://github.com/ruby-numo/numo-gsl) - Ruby interface for [GSL (GNU Scientific Library)](http://www.gnu.org/software/gsl/).
27
27
  * [Numo::FFTW](https://github.com/ruby-numo/numo-fftw) - Ruby/Numo interface to [FFTW (A Discrete Fourier Transform library](http://www.fftw.org/).
@@ -29,10 +29,13 @@ All documents are primitive.
29
29
  * [Numo::Gnuplot](https://github.com/ruby-numo/numo-gnuplot) - Simple and easy-to-use Gnuplot interface.
30
30
 
31
31
  ## Installation
32
+
32
33
  ### Requirement
33
- Ruby ver 2.1 and later.
34
+
35
+ Ruby ver 2.2 and later.
34
36
 
35
37
  ### Ubuntu, Debian, Bash on Windows
38
+
36
39
  ```shell
37
40
  apt install -y git ruby gcc ruby-dev rake make
38
41
  gem install specific_install
@@ -40,7 +43,9 @@ gem specific_install https://github.com/ruby-numo/numo-narray.git
40
43
  ```
41
44
 
42
45
  ## Quick start
46
+
43
47
  An example
48
+
44
49
  ```ruby
45
50
  [1] pry(main)> require "numo/narray"
46
51
  => true
@@ -58,6 +63,7 @@ An example
58
63
  [6] pry(main)> a.size
59
64
  => 15
60
65
  ```
66
+
61
67
  For more examples, check out this [narray version of 100 numpy exercises](https://github.com/ruby-numo/numo-narray/wiki/100-narray-exercises) (and the [IRuby Notebook](https://github.com/ruby-numo/numo-narray/blob/master/100-narray-exercises.ipynb)).
62
68
 
63
69
  ## Development
data/Rakefile CHANGED
@@ -1,76 +1,14 @@
1
1
  require "bundler/gem_tasks"
2
- begin
3
2
 
4
3
  task :doc do
5
4
  dir = "ext/numo/narray"
6
5
  src = %w[array.c data.c index.c math.c narray.c rand.c struct.c].
7
6
  map{|s| File.join(dir,s)} +
8
- [File.join(dir,"types/*.c"), "lib/numo/narray/extra.rb"]
7
+ [File.join(dir,"t_*.c"), "lib/numo/narray/extra.rb"]
9
8
  sh "cd ext/numo/narray; ruby extconf.rb; make src"
10
9
  sh "rm -rf yard .yardoc; yard doc -o yard -m markdown -r README.md #{src.join(' ')}"
11
10
  end
12
11
 
13
- require "rake/extensiontask"
14
- require "rake_compiler_dock"
15
- require "shellwords"
16
-
17
- spec = Bundler::GemHelper.gemspec
18
-
19
- cross_platforms = ["x86-mingw32", "x64-mingw32"]
20
- Rake::ExtensionTask.new("numo/narray", spec) do |ext|
21
- ext.cross_compile = true
22
- ext.cross_platform = cross_platforms
23
- end
24
-
25
- pkg_dir = "pkg"
26
- windows_gem_paths = cross_platforms.collect do |platform|
27
- File.join(pkg_dir, "#{spec.full_name}-#{platform}.gem")
28
- end
29
-
30
- namespace :build do
31
- directory pkg_dir
32
-
33
- desc "Build gems for Windows into the pkg directory"
34
- task :windows => pkg_dir do
35
- build_dir = "tmp/windows"
36
- rm_rf build_dir
37
- mkdir_p build_dir
38
-
39
- commands = [
40
- ["git", "clone", "file://#{Dir.pwd}/.git", build_dir],
41
- ["cd", build_dir],
42
- ["bundle"],
43
- [
44
- "rake",
45
- "RUBY_CC_VERSION=2.5.0:2.4.0:2.3.0:2.2.2:2.1.6",
46
- "cross",
47
- "native",
48
- "gem",
49
- ],
50
- ]
51
- raw_commands = commands.collect do |command|
52
- Shellwords.join(command)
53
- end
54
- raw_command_line = raw_commands.join(" && ")
55
-
56
- RakeCompilerDock.sh(raw_command_line)
57
-
58
- cp(Dir.glob("#{build_dir}/#{pkg_dir}/*.gem"),
59
- "#{pkg_dir}/")
60
- end
61
- end
62
-
63
- namespace :release do
64
- task :windows => "build:windows" do
65
- windows_gem_paths.each do |path|
66
- ruby("-S", "gem", "push", path)
67
- end
68
- end
69
- end
70
-
71
- rescue LoadError
72
- end
73
-
74
12
  require 'rake/testtask'
75
13
  Rake::TestTask.new(:test) do |t|
76
14
  t.libs << "test"
@@ -79,3 +17,6 @@ Rake::TestTask.new(:test) do |t|
79
17
  t.warning = false
80
18
  t.test_files = FileList['test/**/*_test.rb']
81
19
  end
20
+
21
+ require 'rake/extensiontask'
22
+ Rake::ExtensionTask.new('numo/narray')
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  array.c
3
- Numerical Array Extension for Ruby
4
- (C) Copyright 1999-2017 by Masahiro TANAKA
3
+ Ruby/Numo::NArray - Numerical Array class for Ruby
4
+ Copyright (C) 1999-2020 Masahiro TANAKA
5
5
  */
6
6
  #include <ruby.h>
7
7
  #include "numo/narray.h"
@@ -30,16 +30,16 @@ static ID id_step;
30
30
  static ID id_abs;
31
31
  static ID id_cast;
32
32
  static ID id_le;
33
+ #if SIZEOF_LONG <= 4
34
+ static ID id_ge;
35
+ #endif
33
36
  static ID id_Complex;
34
-
37
+ static VALUE int32_max = Qnil;
38
+ static VALUE int32_min = Qnil;
35
39
 
36
40
  static VALUE
37
41
  na_object_type(int type, VALUE v)
38
42
  {
39
- static VALUE int32_max = Qnil;
40
- if (NIL_P(int32_max))
41
- int32_max = ULONG2NUM(2147483647);
42
-
43
43
  switch(TYPE(v)) {
44
44
 
45
45
  case T_TRUE:
@@ -48,15 +48,15 @@ static VALUE
48
48
  return NA_BIT;
49
49
  return type;
50
50
 
51
- #if SIZEOF_LONG == 4
51
+ #if SIZEOF_LONG <= 4
52
52
  case T_FIXNUM:
53
53
  if (type<NA_INT32)
54
54
  return NA_INT32;
55
55
  return type;
56
56
  case T_BIGNUM:
57
57
  if (type<NA_INT64) {
58
- v = rb_funcall(v,id_abs,0);
59
- if (RTEST(rb_funcall(v,id_le,1,int32_max))) {
58
+ if (RTEST(rb_funcall(v,id_le,1,int32_max)) &&
59
+ RTEST(rb_funcall(v,id_ge,1,int32_min))) {
60
60
  if (type<NA_INT32)
61
61
  return NA_INT32;
62
62
  } else {
@@ -64,13 +64,11 @@ static VALUE
64
64
  }
65
65
  }
66
66
  return type;
67
-
68
- #elif SIZEOF_LONG == 8
67
+ #else
69
68
  case T_FIXNUM:
70
69
  if (type<NA_INT64) {
71
70
  long x = NUM2LONG(v);
72
- if (x<0) x=-x;
73
- if (x<=2147483647) {
71
+ if (x<=2147483647L && x>=-2147483648L) {
74
72
  if (type<NA_INT32)
75
73
  return NA_INT32;
76
74
  } else {
@@ -82,19 +80,6 @@ static VALUE
82
80
  if (type<NA_INT64)
83
81
  return NA_INT64;
84
82
  return type;
85
- #else
86
- case T_FIXNUM:
87
- case T_BIGNUM:
88
- if (type<NA_INT64) {
89
- v = rb_funcall(v,id_abs,0);
90
- if (RTEST(rb_funcall(v,id_le,1,int32_max))) {
91
- if (type<NA_INT32)
92
- return NA_INT32;
93
- } else {
94
- return NA_INT64;
95
- }
96
- }
97
- return type;
98
83
  #endif
99
84
 
100
85
  case T_FLOAT:
@@ -122,10 +107,12 @@ static int na_mdai_object_type(int type, VALUE v)
122
107
  if (rb_obj_is_kind_of(v, rb_cRange)) {
123
108
  MDAI_ATTR_TYPE(type,v,begin);
124
109
  MDAI_ATTR_TYPE(type,v,end);
125
- } else if (rb_obj_is_kind_of(v, na_cStep)) {
110
+ #ifdef HAVE_RB_ARITHMETIC_SEQUENCE_EXTRACT
111
+ } else if (rb_obj_is_kind_of(v, rb_cArithSeq)) {
126
112
  MDAI_ATTR_TYPE(type,v,begin);
127
113
  MDAI_ATTR_TYPE(type,v,end);
128
114
  MDAI_ATTR_TYPE(type,v,step);
115
+ #endif
129
116
  } else {
130
117
  type = na_object_type(type,v);
131
118
  }
@@ -210,7 +197,13 @@ na_mdai_investigate(na_mdai_t *mdai, int ndim)
210
197
  }
211
198
  }
212
199
  else
213
- if (rb_obj_is_kind_of(v, rb_cRange) || rb_obj_is_kind_of(v, na_cStep)) {
200
+ if (rb_obj_is_kind_of(v, rb_cRange)
201
+ #ifdef HAVE_RB_ARITHMETIC_SEQUENCE_EXTRACT
202
+ || rb_obj_is_kind_of(v, rb_cArithSeq)
203
+ #else
204
+ || rb_obj_is_kind_of(v, rb_cEnumerator)
205
+ #endif
206
+ ) {
214
207
  nary_step_sequence(v,&length,&dbeg,&dstep);
215
208
  len += length-1;
216
209
  mdai->type = na_mdai_object_type(mdai->type, v);
@@ -465,11 +458,13 @@ na_s_array_shape(VALUE mod, VALUE ary)
465
458
  @return [Numo::NArray]
466
459
  @example
467
460
  Numo::NArray.new_like([[1,2,3],[4,5,6]])
468
- => Numo::Int32#shape=[2,3](empty)
461
+ # => Numo::Int32#shape=[2,3](empty)
462
+
469
463
  Numo::DFloat.new_like([[1,2],[3,4]])
470
- => Numo::DFloat#shape=[2,2](empty)
464
+ # => Numo::DFloat#shape=[2,2](empty)
465
+
471
466
  Numo::NArray.new_like([1,2i,3])
472
- => Numo::DComplex#shape=[3](empty)
467
+ # => Numo::DComplex#shape=[3](empty)
473
468
  */
474
469
  VALUE
475
470
  na_s_new_like(VALUE type, VALUE obj)
@@ -639,5 +634,13 @@ Init_nary_array()
639
634
  id_cast = rb_intern("cast");
640
635
  id_abs = rb_intern("abs");
641
636
  id_le = rb_intern("<=");
637
+ #if SIZEOF_LONG <= 4
638
+ id_ge = rb_intern(">=");
639
+ #endif
642
640
  id_Complex = rb_intern("Complex");
641
+
642
+ rb_global_variable(&int32_max);
643
+ int32_max = INT2NUM(2147483647);
644
+ rb_global_variable(&int32_min);
645
+ int32_min = INT2NUM(-2147483648);
643
646
  }
@@ -1,16 +1,14 @@
1
1
  /*
2
2
  data.c
3
- Numerical Array Extension for Ruby
4
- (C) Copyright 1999-2017 by Masahiro TANAKA
3
+ Ruby/Numo::NArray - Numerical Array class for Ruby
4
+ Copyright (C) 1999-2020 Masahiro TANAKA
5
5
  */
6
6
 
7
7
  #include <ruby.h>
8
8
  #include "numo/narray.h"
9
9
  #include "numo/template.h"
10
10
 
11
- static VALUE sym_mulsum;
12
11
  static ID id_mulsum;
13
- static ID id_respond_to_p;
14
12
  static ID id_store;
15
13
  static ID id_swap_byte;
16
14
 
@@ -186,21 +184,21 @@ check_axis(int axis, int ndim)
186
184
  @example
187
185
  x = Numo::Int32[[1,2,3]]
188
186
 
189
- p x.swapaxes(0,1)
190
- # Numo::Int32(view)#shape=[3,1]
187
+ x.swapaxes(0,1)
188
+ # => Numo::Int32(view)#shape=[3,1]
191
189
  # [[1],
192
190
  # [2],
193
191
  # [3]]
194
192
 
195
- p x = Numo::Int32[[[0,1],[2,3]],[[4,5],[6,7]]]
196
- # Numo::Int32#shape=[2,2,2]
193
+ x = Numo::Int32[[[0,1],[2,3]],[[4,5],[6,7]]]
194
+ # => Numo::Int32#shape=[2,2,2]
197
195
  # [[[0, 1],
198
196
  # [2, 3]],
199
197
  # [[4, 5],
200
198
  # [6, 7]]]
201
199
 
202
- p x.swapaxes(0,2)
203
- # Numo::Int32(view)#shape=[2,2,2]
200
+ x.swapaxes(0,2)
201
+ # => Numo::Int32(view)#shape=[2,2,2]
204
202
  # [[[0, 4],
205
203
  # [2, 6]],
206
204
  # [[1, 5],
@@ -457,7 +455,7 @@ VALUE
457
455
  na_flatten_dim(VALUE self, int sd)
458
456
  {
459
457
  int i, nd, fd;
460
- size_t j;
458
+ size_t j, ofs;
461
459
  size_t *c, *pos, *idx1, *idx2;
462
460
  size_t stride;
463
461
  size_t *shape, size;
@@ -501,7 +499,6 @@ na_flatten_dim(VALUE self, int sd)
501
499
  case NARRAY_FILEMAP_T:
502
500
  stride = nary_element_stride(self);
503
501
  for (i=sd+1; i--; ) {
504
- //printf("data: i=%d shpae[i]=%ld stride=%ld\n",i,shape[i],stride);
505
502
  SDX_SET_STRIDE(na2->stridx[i],stride);
506
503
  stride *= shape[i];
507
504
  }
@@ -522,32 +519,35 @@ na_flatten_dim(VALUE self, int sd)
522
519
  SDX_SET_INDEX(na2->stridx[i],idx2);
523
520
  } else {
524
521
  na2->stridx[i] = na1->stridx[i];
525
- //printf("view: i=%d stridx=%d\n",i,SDX_GET_STRIDE(sdx));
526
522
  }
527
523
  }
528
524
  // flat dimenion == last dimension
529
525
  if (RTEST(na_check_ladder(self,sd))) {
530
- //if (0) {
531
526
  na2->stridx[sd] = na1->stridx[nd-1];
532
527
  } else {
533
528
  // set index
534
- idx2 = ALLOC_N(size_t, shape[sd]);
529
+ idx2 = ALLOC_N(size_t, (shape[sd]==0) ? 1 : shape[sd]);
535
530
  SDX_SET_INDEX(na2->stridx[sd],idx2);
536
531
  // init for md-loop
537
532
  fd = nd-sd;
538
- c = ALLOC_N(size_t, fd);
533
+ c = ALLOCA_N(size_t, fd);
539
534
  for (i=0; i<fd; i++) c[i]=0;
540
- pos = ALLOC_N(size_t, fd+1);
535
+ pos = ALLOCA_N(size_t, fd+1);
541
536
  pos[0] = 0;
542
537
  // md-loop
543
538
  for (i=j=0;;) {
544
539
  for (; i<fd; i++) {
545
540
  sdx = na1->stridx[i+sd];
546
541
  if (SDX_IS_INDEX(sdx)) {
547
- pos[i+1] = pos[i] + SDX_GET_INDEX(sdx)[c[i]];
542
+ if (SDX_GET_INDEX(sdx)) {
543
+ ofs = SDX_GET_INDEX(sdx)[c[i]];
544
+ } else {
545
+ ofs = 0;
546
+ }
548
547
  } else {
549
- pos[i+1] = pos[i] + SDX_GET_STRIDE(sdx)*c[i];
548
+ ofs = SDX_GET_STRIDE(sdx)*c[i];
550
549
  }
550
+ pos[i+1] = pos[i] + ofs;
551
551
  }
552
552
  idx2[j++] = pos[i];
553
553
  for (;;) {
@@ -559,8 +559,7 @@ na_flatten_dim(VALUE self, int sd)
559
559
  }
560
560
  }
561
561
  loop_end:
562
- xfree(pos);
563
- xfree(c);
562
+ ;
564
563
  }
565
564
  break;
566
565
  }
@@ -589,28 +588,30 @@ na_flatten(VALUE self)
589
588
  @return [Numo::NArray] diagonal view of NArray.
590
589
  @example
591
590
  a = Numo::DFloat.new(4,5).seq
592
- => Numo::DFloat#shape=[4,5]
593
- [[0, 1, 2, 3, 4],
594
- [5, 6, 7, 8, 9],
595
- [10, 11, 12, 13, 14],
596
- [15, 16, 17, 18, 19]]
591
+ # => Numo::DFloat#shape=[4,5]
592
+ # [[0, 1, 2, 3, 4],
593
+ # [5, 6, 7, 8, 9],
594
+ # [10, 11, 12, 13, 14],
595
+ # [15, 16, 17, 18, 19]]
597
596
  b = a.diagonal(1)
598
- => Numo::DFloat(view)#shape=[4]
599
- [1, 7, 13, 19]
597
+ # => Numo::DFloat(view)#shape=[4]
598
+ # [1, 7, 13, 19]
599
+
600
600
  b.store(0)
601
601
  a
602
- => Numo::DFloat#shape=[4,5]
603
- [[0, 0, 2, 3, 4],
604
- [5, 6, 0, 8, 9],
605
- [10, 11, 12, 0, 14],
606
- [15, 16, 17, 18, 0]]
602
+ # => Numo::DFloat#shape=[4,5]
603
+ # [[0, 0, 2, 3, 4],
604
+ # [5, 6, 0, 8, 9],
605
+ # [10, 11, 12, 0, 14],
606
+ # [15, 16, 17, 18, 0]]
607
+
607
608
  b.store([1,2,3,4])
608
609
  a
609
- => Numo::DFloat#shape=[4,5]
610
- [[0, 1, 2, 3, 4],
611
- [5, 6, 2, 8, 9],
612
- [10, 11, 12, 3, 14],
613
- [15, 16, 17, 18, 4]]
610
+ # => Numo::DFloat#shape=[4,5]
611
+ # [[0, 1, 2, 3, 4],
612
+ # [5, 6, 2, 8, 9],
613
+ # [10, 11, 12, 3, 14],
614
+ # [15, 16, 17, 18, 4]]
614
615
  */
615
616
  static VALUE
616
617
  na_diagonal(int argc, VALUE *argv, VALUE self)
@@ -918,12 +919,10 @@ na_new_dimension_for_dot(VALUE self, int pos, int len, bool transpose)
918
919
  static VALUE
919
920
  numo_na_dot(VALUE self, VALUE other)
920
921
  {
921
- VALUE test;
922
922
  volatile VALUE a1=self, a2=other;
923
923
  narray_t *na1, *na2;
924
924
 
925
- test = rb_funcall(a1, id_respond_to_p, 1, sym_mulsum);
926
- if (!RTEST(test)) {
925
+ if (!rb_respond_to(a1, id_mulsum)) {
927
926
  rb_raise(rb_eNoMethodError,"requires mulsum method for dot method");
928
927
  }
929
928
  GetNArray(a1,na1);
@@ -980,8 +979,6 @@ Init_nary_data()
980
979
  //rb_define_method(cNArray, "dot", numo_na_dot, 1);
981
980
 
982
981
  id_mulsum = rb_intern("mulsum");
983
- sym_mulsum = ID2SYM(id_mulsum);
984
- id_respond_to_p = rb_intern("respond_to?");
985
982
  id_store = rb_intern("store");
986
983
  id_swap_byte = rb_intern("swap_byte");
987
984
  }