numo-narray 0.9.1.4 → 0.9.1.9
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 +12 -6
- data/Rakefile +4 -63
- data/ext/numo/narray/array.c +35 -32
- data/ext/numo/narray/data.c +40 -43
- data/ext/numo/narray/depend.erb +6 -10
- data/ext/numo/narray/extconf.rb +24 -21
- data/ext/numo/narray/gen/cogen.rb +2 -2
- data/ext/numo/narray/gen/narray_def.rb +5 -1
- data/ext/numo/narray/gen/spec.rb +17 -7
- data/ext/numo/narray/gen/tmpl/accum.c +2 -2
- data/ext/numo/narray/gen/tmpl/accum_arg.c +88 -0
- data/ext/numo/narray/gen/tmpl/accum_binary.c +1 -1
- data/ext/numo/narray/gen/tmpl/accum_index.c +25 -14
- data/ext/numo/narray/gen/tmpl/alloc_func.c +4 -1
- data/ext/numo/narray/gen/tmpl/allocate.c +1 -0
- data/ext/numo/narray/gen/tmpl/aref.c +5 -35
- data/ext/numo/narray/gen/tmpl/aset.c +7 -37
- data/ext/numo/narray/gen/tmpl/bincount.c +7 -7
- data/ext/numo/narray/gen/tmpl/cast.c +7 -0
- data/ext/numo/narray/gen/tmpl/clip.c +11 -15
- data/ext/numo/narray/gen/tmpl/cum.c +1 -1
- data/ext/numo/narray/gen/tmpl/each.c +4 -2
- data/ext/numo/narray/gen/tmpl/each_with_index.c +5 -2
- data/ext/numo/narray/gen/tmpl/lib.c +2 -2
- data/ext/numo/narray/gen/tmpl/logseq.c +6 -5
- data/ext/numo/narray/gen/tmpl/map_with_index.c +5 -6
- data/ext/numo/narray/gen/tmpl/median.c +2 -2
- data/ext/numo/narray/gen/tmpl/minmax.c +1 -1
- data/ext/numo/narray/gen/tmpl/poly.c +4 -4
- data/ext/numo/narray/gen/tmpl/qsort.c +1 -1
- data/ext/numo/narray/gen/tmpl/rand.c +8 -6
- data/ext/numo/narray/gen/tmpl/rand_norm.c +18 -16
- data/ext/numo/narray/gen/tmpl/seq.c +5 -4
- data/ext/numo/narray/gen/tmpl/sort.c +3 -3
- data/ext/numo/narray/gen/tmpl/sort_index.c +2 -2
- data/ext/numo/narray/gen/tmpl/store_array.c +14 -2
- data/ext/numo/narray/gen/tmpl/unary_s.c +55 -31
- data/ext/numo/narray/gen/tmpl_bit/allocate.c +1 -0
- data/ext/numo/narray/gen/tmpl_bit/aref.c +22 -30
- data/ext/numo/narray/gen/tmpl_bit/aset.c +20 -34
- data/ext/numo/narray/gen/tmpl_bit/binary.c +48 -14
- data/ext/numo/narray/gen/tmpl_bit/bit_count.c +5 -0
- data/ext/numo/narray/gen/tmpl_bit/bit_reduce.c +5 -0
- data/ext/numo/narray/gen/tmpl_bit/store_array.c +14 -2
- data/ext/numo/narray/gen/tmpl_bit/store_bit.c +27 -9
- data/ext/numo/narray/gen/tmpl_bit/unary.c +25 -7
- data/ext/numo/narray/index.c +363 -59
- data/ext/numo/narray/math.c +2 -2
- data/ext/numo/narray/narray.c +151 -36
- data/ext/numo/narray/ndloop.c +4 -4
- data/ext/numo/narray/numo/intern.h +3 -2
- data/ext/numo/narray/numo/narray.h +37 -14
- data/ext/numo/narray/numo/ndloop.h +2 -2
- data/ext/numo/narray/numo/template.h +11 -15
- data/ext/numo/narray/numo/types/complex.h +2 -2
- data/ext/numo/narray/numo/types/int16.h +5 -2
- data/ext/numo/narray/numo/types/int32.h +0 -1
- data/ext/numo/narray/numo/types/int64.h +0 -1
- data/ext/numo/narray/numo/types/int8.h +1 -2
- data/ext/numo/narray/numo/types/uint16.h +5 -2
- data/ext/numo/narray/numo/types/uint32.h +0 -1
- data/ext/numo/narray/numo/types/uint64.h +0 -1
- data/ext/numo/narray/numo/types/uint8.h +1 -2
- data/ext/numo/narray/numo/types/xint_macro.h +2 -0
- data/ext/numo/narray/step.c +58 -252
- data/ext/numo/narray/struct.c +3 -3
- data/lib/numo/narray.rb +1 -7
- data/lib/numo/narray/extra.rb +214 -213
- data/numo-narray.gemspec +7 -8
- metadata +17 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2de0f542db4df78b97eecd077130fb8f3146191a229698512d487916a8a57ce0
|
4
|
+
data.tar.gz: 1452f989e4dc615c0e4f4b4891c9f44072431f9face27a602ce9b91286909cbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23e67c8a70a95d69d25ad78561286eb56db63a0aa6465903ebbed1e076dfef6c4df4aa1ccd1d2f5ec40f4d02307c82c51b47c0da4cb48415c93bfdc6adaf4f27
|
7
|
+
data.tar.gz: 63847fb7e9173d0be70dc63be57ebbcb52a0dc6f52e613b7c9c69fab33f83920ba6b4b478156a18fa1fac0f6e08718713449441485149a6d9f178af7f2d87bdd
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Numo::NArray
|
1
|
+
# Numo::NArray
|
2
2
|
|
3
3
|
[](http://mybinder.org/repo/ruby-numo/numo-narray)
|
4
4
|
[](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/
|
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
|
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
|
-
|
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,"
|
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')
|
data/ext/numo/narray/array.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
array.c
|
3
|
-
Numerical Array
|
4
|
-
(C)
|
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
|
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
|
-
|
59
|
-
|
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
|
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
|
-
|
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)
|
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
|
}
|
data/ext/numo/narray/data.c
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
/*
|
2
2
|
data.c
|
3
|
-
Numerical Array
|
4
|
-
(C)
|
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
|
-
|
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
|
-
|
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
|
-
|
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 =
|
533
|
+
c = ALLOCA_N(size_t, fd);
|
539
534
|
for (i=0; i<fd; i++) c[i]=0;
|
540
|
-
pos =
|
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
|
-
|
542
|
+
if (SDX_GET_INDEX(sdx)) {
|
543
|
+
ofs = SDX_GET_INDEX(sdx)[c[i]];
|
544
|
+
} else {
|
545
|
+
ofs = 0;
|
546
|
+
}
|
548
547
|
} else {
|
549
|
-
|
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
|
-
|
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
|
-
|
595
|
-
|
596
|
-
|
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
|
-
|
605
|
-
|
606
|
-
|
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
|
-
|
612
|
-
|
613
|
-
|
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
|
-
|
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
|
}
|