nmatrix 0.1.0.rc3 → 0.1.0.rc4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +22 -21
- data/History.txt +13 -0
- data/Manifest.txt +1 -2
- data/README.rdoc +8 -8
- data/ext/nmatrix/binary_format.txt +1 -1
- data/ext/nmatrix/data/complex.h +21 -21
- data/ext/nmatrix/data/data.cpp +9 -2
- data/ext/nmatrix/data/data.h +4 -2
- data/ext/nmatrix/math.cpp +69 -31
- data/ext/nmatrix/math/getf2.h +2 -2
- data/ext/nmatrix/math/getrf.h +2 -2
- data/ext/nmatrix/math/imax.h +101 -0
- data/ext/nmatrix/math/scal.h +30 -10
- data/ext/nmatrix/math/swap.h +1 -22
- data/ext/nmatrix/nm_memory.h +1 -1
- data/ext/nmatrix/nmatrix.h +2 -2
- data/ext/nmatrix/ruby_constants.cpp +1 -2
- data/ext/nmatrix/ruby_constants.h +6 -7
- data/ext/nmatrix/ruby_nmatrix.c +23 -18
- data/ext/nmatrix/storage/list/list.cpp +48 -47
- data/ext/nmatrix/util/io.cpp +2 -2
- data/lib/nmatrix.rb +0 -1
- data/lib/nmatrix/enumerate.rb +1 -1
- data/lib/nmatrix/io/market.rb +1 -1
- data/lib/nmatrix/io/mat_reader.rb +41 -41
- data/lib/nmatrix/lapack.rb +0 -1
- data/lib/nmatrix/math.rb +43 -0
- data/lib/nmatrix/nmatrix.rb +5 -1
- data/lib/nmatrix/version.rb +1 -1
- data/nmatrix.gemspec +3 -4
- data/spec/00_nmatrix_spec.rb +13 -6
- data/spec/01_enum_spec.rb +17 -25
- data/spec/02_slice_spec.rb +74 -82
- data/spec/blas_spec.rb +21 -6
- data/spec/elementwise_spec.rb +1 -6
- data/spec/io_spec.rb +15 -22
- data/spec/lapack_spec.rb +1 -6
- data/spec/leakcheck.rb +1 -1
- data/spec/math_spec.rb +43 -4
- data/spec/nmatrix_yale_spec.rb +1 -4
- data/spec/rspec_spec.rb +1 -1
- data/spec/shortcuts_spec.rb +1 -6
- data/spec/slice_set_spec.rb +1 -5
- data/spec/stat_spec.rb +46 -51
- metadata +32 -22
- data/Guardfile +0 -6
- data/ext/nmatrix/math/idamax.h +0 -86
- data/lib/nmatrix/nvector.rb +0 -184
data/spec/blas_spec.rb
CHANGED
@@ -25,13 +25,28 @@
|
|
25
25
|
# Tests for properly exposed BLAS functions.
|
26
26
|
#
|
27
27
|
|
28
|
-
|
29
|
-
require File.join(File.dirname(__FILE__), "spec_helper.rb")
|
28
|
+
require 'spec_helper'
|
30
29
|
|
31
30
|
describe NMatrix::BLAS do
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
[:byte, :int8, :int16, :int32, :int64,
|
32
|
+
:float32, :float64, :complex64, :complex128,
|
33
|
+
:rational32, :rational64, :rational128,
|
34
|
+
:object
|
35
|
+
].each do |dtype|
|
36
|
+
context dtype do
|
37
|
+
it "exposes cblas_scal" do
|
38
|
+
x = NMatrix.new([3, 1], [1, 2, 3], dtype: dtype)
|
39
|
+
NMatrix::BLAS.cblas_scal(3, 2, x, 1)
|
40
|
+
expect(x).to eq(NMatrix.new([3, 1], [2, 4, 6], dtype: dtype))
|
41
|
+
end
|
42
|
+
|
43
|
+
it "exposes cblas_imax" do
|
44
|
+
u = NMatrix.new([3,1], [1, 4, 3], dtype: dtype)
|
45
|
+
index = NMatrix::BLAS.cblas_imax(3, u, 1)
|
46
|
+
expect(index).to eq(1)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
35
50
|
|
36
51
|
[:rational32, :rational64, :rational128, :float32, :float64, :complex64, :complex128].each do |dtype|
|
37
52
|
context dtype do
|
@@ -144,4 +159,4 @@ describe NMatrix::BLAS do
|
|
144
159
|
|
145
160
|
end
|
146
161
|
end
|
147
|
-
end
|
162
|
+
end
|
data/spec/elementwise_spec.rb
CHANGED
@@ -25,14 +25,9 @@
|
|
25
25
|
# Element-wise operation tests.
|
26
26
|
#
|
27
27
|
|
28
|
-
|
29
|
-
require File.join(File.dirname(__FILE__), "spec_helper.rb")
|
28
|
+
require 'spec_helper'
|
30
29
|
|
31
30
|
describe NMatrix do
|
32
|
-
#after :each do
|
33
|
-
# GC.start
|
34
|
-
#end
|
35
|
-
|
36
31
|
context "yale" do
|
37
32
|
before :each do
|
38
33
|
@n = NMatrix.new(3, stype: :yale, dtype: :int64)
|
data/spec/io_spec.rb
CHANGED
@@ -25,19 +25,12 @@
|
|
25
25
|
# Basic tests for NMatrix::IO.
|
26
26
|
#
|
27
27
|
require "tmpdir" # Used to avoid cluttering the repository.
|
28
|
-
|
28
|
+
require 'spec_helper'
|
29
29
|
require "./lib/nmatrix"
|
30
30
|
|
31
31
|
describe NMatrix::IO do
|
32
|
-
|
33
|
-
|
34
|
-
@test_out = File.join(@tmp_dir, "test-out")
|
35
|
-
end
|
36
|
-
|
37
|
-
after :each do
|
38
|
-
File.delete(@test_out) if File.file?(@test_out)
|
39
|
-
Dir.rmdir(@tmp_dir)
|
40
|
-
end
|
32
|
+
let(:tmp_dir) { Dir.mktmpdir }
|
33
|
+
let(:test_out) { File.join(tmp_dir, 'test-out') }
|
41
34
|
|
42
35
|
it "repacks a string" do
|
43
36
|
expect(NMatrix::IO::Matlab.repack("hello", :miUINT8, :byte)).to eq("hello")
|
@@ -102,54 +95,54 @@ describe NMatrix::IO do
|
|
102
95
|
|
103
96
|
it "reads and writes NMatrix dense" do
|
104
97
|
n = NMatrix.new(:dense, [4,3], [0,1,2,3,4,5,6,7,8,9,10,11], :int32)
|
105
|
-
n.write(
|
98
|
+
n.write(test_out)
|
106
99
|
|
107
|
-
m = NMatrix.read(
|
100
|
+
m = NMatrix.read(test_out)
|
108
101
|
expect(n).to eq(m)
|
109
102
|
end
|
110
103
|
|
111
104
|
it "reads and writes NMatrix dense as symmetric" do
|
112
105
|
n = NMatrix.new(:dense, 3, [0,1,2,1,3,4,2,4,5], :int16)
|
113
|
-
n.write(
|
106
|
+
n.write(test_out, :symmetric)
|
114
107
|
|
115
|
-
m = NMatrix.read(
|
108
|
+
m = NMatrix.read(test_out)
|
116
109
|
expect(n).to eq(m)
|
117
110
|
end
|
118
111
|
|
119
112
|
it "reads and writes NMatrix dense as skew" do
|
120
113
|
n = NMatrix.new(:dense, 3, [0,1,2,-1,3,4,-2,-4,5], :float64)
|
121
|
-
n.write(
|
114
|
+
n.write(test_out, :skew)
|
122
115
|
|
123
|
-
m = NMatrix.read(
|
116
|
+
m = NMatrix.read(test_out)
|
124
117
|
expect(n).to eq(m)
|
125
118
|
end
|
126
119
|
|
127
120
|
it "reads and writes NMatrix dense as hermitian" do
|
128
121
|
n = NMatrix.new(:dense, 3, [0,1,2,1,3,4,2,4,5], :complex64)
|
129
|
-
n.write(
|
122
|
+
n.write(test_out, :hermitian)
|
130
123
|
|
131
|
-
m = NMatrix.read(
|
124
|
+
m = NMatrix.read(test_out)
|
132
125
|
expect(n).to eq(m)
|
133
126
|
end
|
134
127
|
|
135
128
|
it "reads and writes NMatrix dense as upper" do
|
136
129
|
n = NMatrix.new(:dense, 3, [-1,1,2,3,4,5,6,7,8], :int32)
|
137
|
-
n.write(
|
130
|
+
n.write(test_out, :upper)
|
138
131
|
|
139
132
|
m = NMatrix.new(:dense, 3, [-1,1,2,0,4,5,0,0,8], :int32) # lower version of the same
|
140
133
|
|
141
|
-
o = NMatrix.read(
|
134
|
+
o = NMatrix.read(test_out)
|
142
135
|
expect(o).to eq(m)
|
143
136
|
expect(o).not_to eq(n)
|
144
137
|
end
|
145
138
|
|
146
139
|
it "reads and writes NMatrix dense as lower" do
|
147
140
|
n = NMatrix.new(:dense, 3, [-1,1,2,3,4,5,6,7,8], :int32)
|
148
|
-
n.write(
|
141
|
+
n.write(test_out, :lower)
|
149
142
|
|
150
143
|
m = NMatrix.new(:dense, 3, [-1,0,0,3,4,0,6,7,8], :int32) # lower version of the same
|
151
144
|
|
152
|
-
o = NMatrix.read(
|
145
|
+
o = NMatrix.read(test_out)
|
153
146
|
expect(o).to eq(m)
|
154
147
|
expect(o).not_to eq(n)
|
155
148
|
end
|
data/spec/lapack_spec.rb
CHANGED
@@ -25,14 +25,9 @@
|
|
25
25
|
# Tests for properly exposed LAPACK functions.
|
26
26
|
#
|
27
27
|
|
28
|
-
|
29
|
-
require File.join(File.dirname(__FILE__), "spec_helper.rb")
|
28
|
+
require 'spec_helper'
|
30
29
|
|
31
30
|
describe NMatrix::LAPACK do
|
32
|
-
#after :each do
|
33
|
-
# GC.start
|
34
|
-
#end
|
35
|
-
|
36
31
|
# where integer math is allowed
|
37
32
|
[:byte, :int8, :int16, :int32, :int64, :rational32, :rational64, :rational128, :float32, :float64, :complex64, :complex128].each do |dtype|
|
38
33
|
context dtype do
|
data/spec/leakcheck.rb
CHANGED
data/spec/math_spec.rb
CHANGED
@@ -29,10 +29,6 @@
|
|
29
29
|
require 'spec_helper'
|
30
30
|
|
31
31
|
describe "math" do
|
32
|
-
#after :each do
|
33
|
-
# GC.start
|
34
|
-
#end
|
35
|
-
|
36
32
|
context "elementwise math functions" do
|
37
33
|
|
38
34
|
[:dense,:list,:yale].each do |stype|
|
@@ -124,7 +120,50 @@ describe "math" do
|
|
124
120
|
end
|
125
121
|
end
|
126
122
|
end
|
123
|
+
|
124
|
+
context "Floor and ceil for #{stype}" do
|
125
|
+
|
126
|
+
[:floor, :ceil].each do |meth|
|
127
|
+
[:byte,:int8,:int16,:int32,:int64, :float32,:float64, :object,:rational32,:rational64,:rational128, :complex64, :complex128].each do |dtype|
|
128
|
+
context dtype do
|
129
|
+
before :each do
|
130
|
+
@size = [2,2]
|
131
|
+
@m = NMatrix.seq(@size, dtype: dtype, stype: stype)+1
|
132
|
+
@a = @m.to_a.flatten
|
133
|
+
end
|
127
134
|
|
135
|
+
if dtype.to_s.match(/int/) or [:byte, :object].include?(dtype)
|
136
|
+
it "should return #{dtype} for #{dtype}" do
|
137
|
+
|
138
|
+
expect(@m.send(meth)).to eq N.new(@size, @a.map { |e| e.send(meth) }, dtype: dtype, stype: stype)
|
139
|
+
|
140
|
+
if dtype == :object
|
141
|
+
expect(@m.send(meth).dtype).to eq :object
|
142
|
+
else
|
143
|
+
expect(@m.send(meth).integer_dtype?).to eq true
|
144
|
+
end
|
145
|
+
end
|
146
|
+
elsif dtype.to_s.match(/float/) or dtype.to_s.match(/rational/)
|
147
|
+
it "should return dtype int64 for #{dtype}" do
|
148
|
+
|
149
|
+
expect(@m.send(meth)).to eq N.new(@size, @a.map { |e| e.send(meth) }, dtype: dtype, stype: stype)
|
150
|
+
|
151
|
+
expect(@m.send(meth).dtype).to eq :int64
|
152
|
+
end
|
153
|
+
elsif dtype.to_s.match(/complex/)
|
154
|
+
it "should properly calculate #{meth} for #{dtype}" do
|
155
|
+
|
156
|
+
expect(@m.send(meth)).to eq N.new(@size, @a.map { |e| e = Complex(e.real.send(meth), e.imag.send(meth)) }, dtype: dtype, stype: stype)
|
157
|
+
|
158
|
+
expect(@m.send(meth).dtype).to eq :complex64 if dtype == :complex64
|
159
|
+
expect(@m.send(meth).dtype).to eq :complex128 if dtype == :complex128
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
128
167
|
end
|
129
168
|
end
|
130
169
|
end
|
data/spec/nmatrix_yale_spec.rb
CHANGED
@@ -24,13 +24,10 @@
|
|
24
24
|
#
|
25
25
|
# Basic tests for NMatrix's Yale storage type.
|
26
26
|
#
|
27
|
+
require 'spec_helper'
|
27
28
|
require "./lib/nmatrix"
|
28
29
|
|
29
30
|
describe NMatrix do
|
30
|
-
#after :each do
|
31
|
-
# GC.start
|
32
|
-
#end
|
33
|
-
|
34
31
|
context :yale do
|
35
32
|
|
36
33
|
it "compares two empty matrices" do
|
data/spec/rspec_spec.rb
CHANGED
data/spec/shortcuts_spec.rb
CHANGED
@@ -25,15 +25,10 @@
|
|
25
25
|
# Specs for the shortcuts used in NMatrix and in NVector.
|
26
26
|
#
|
27
27
|
|
28
|
-
|
29
|
-
require File.join(File.dirname(__FILE__), "spec_helper.rb")
|
28
|
+
require 'spec_helper'
|
30
29
|
require 'pry'
|
31
30
|
|
32
31
|
describe NMatrix do
|
33
|
-
#after :each do
|
34
|
-
# GC.start
|
35
|
-
#end
|
36
|
-
|
37
32
|
it "zeros() creates a matrix of zeros" do
|
38
33
|
m = NMatrix.zeros(3)
|
39
34
|
n = NMatrix.new([3, 3], 0)
|
data/spec/slice_set_spec.rb
CHANGED
@@ -24,16 +24,12 @@
|
|
24
24
|
#
|
25
25
|
# Test of slice set operations.
|
26
26
|
|
27
|
+
require 'spec_helper'
|
27
28
|
require 'pry'
|
28
|
-
require File.dirname(__FILE__) + "/spec_helper.rb"
|
29
29
|
|
30
30
|
describe "Set slice operation" do
|
31
31
|
include RSpec::Longrun::DSL
|
32
32
|
|
33
|
-
#after :each do
|
34
|
-
# GC.start
|
35
|
-
#end
|
36
|
-
|
37
33
|
[:dense, :yale, :list].each do |stype|
|
38
34
|
context "for #{stype}" do
|
39
35
|
before :each do
|
data/spec/stat_spec.rb
CHANGED
@@ -25,62 +25,59 @@
|
|
25
25
|
# Tests for statistical functions in NMatrix.
|
26
26
|
#
|
27
27
|
|
28
|
-
|
29
|
-
require File.join(File.dirname(__FILE__), "spec_helper.rb")
|
28
|
+
require 'spec_helper'
|
30
29
|
require 'pry'
|
31
30
|
|
32
31
|
describe "Statistical functions" do
|
33
32
|
context "mapping and reduction related functions" do
|
34
33
|
[:dense, :yale, :list].each do |stype|
|
35
|
-
context "on #{stype} matrices" do
|
36
|
-
|
37
|
-
|
38
|
-
@nm_2d = NMatrix.new([2,2], [0.0, 1.0, 2.0, 3.0], stype: stype)
|
39
|
-
end
|
34
|
+
context "on #{stype} matrices" do
|
35
|
+
let(:nm_1d) { NMatrix.new([5], [5.0,0.0,1.0,2.0,3.0], stype: stype) unless stype == :yale }
|
36
|
+
let(:nm_2d) { NMatrix.new([2,2], [0.0, 1.0, 2.0, 3.0], stype: stype) }
|
40
37
|
|
41
38
|
it "behaves like Enumerable#reduce with no argument to reduce" do
|
42
|
-
expect(
|
43
|
-
expect(
|
39
|
+
expect(nm_1d.reduce_along_dim(0) { |acc, el| acc + el }.to_f).to eq 11 unless stype == :yale
|
40
|
+
expect(nm_2d.reduce_along_dim(1) { |acc, el| acc + el }).to eq NMatrix.new([2,1], [1.0, 5.0], stype: stype)
|
44
41
|
end
|
45
42
|
|
46
43
|
it "should calculate the mean along the specified dimension" do
|
47
44
|
unless stype == :yale then
|
48
|
-
puts
|
49
|
-
expect(
|
45
|
+
puts nm_1d.mean
|
46
|
+
expect(nm_1d.mean).to eq NMatrix.new([1], [2.2], stype: stype, dtype: :float64)
|
50
47
|
end
|
51
|
-
expect(
|
52
|
-
expect(
|
48
|
+
expect(nm_2d.mean).to eq NMatrix[[1.0,2.0], stype: stype]
|
49
|
+
expect(nm_2d.mean(1)).to eq NMatrix[[0.5], [2.5], stype: stype]
|
53
50
|
end
|
54
51
|
|
55
52
|
it "should calculate the minimum along the specified dimension" do
|
56
|
-
expect(
|
57
|
-
expect(
|
58
|
-
expect(
|
53
|
+
expect(nm_1d.min).to eq 0.0 unless stype == :yale
|
54
|
+
expect(nm_2d.min).to eq NMatrix[[0.0, 1.0], stype: stype]
|
55
|
+
expect(nm_2d.min(1)).to eq NMatrix[[0.0], [2.0], stype: stype]
|
59
56
|
end
|
60
57
|
|
61
58
|
it "should calculate the maximum along the specified dimension" do
|
62
|
-
expect(
|
63
|
-
expect(
|
59
|
+
expect(nm_1d.max).to eq 5.0 unless stype == :yale
|
60
|
+
expect(nm_2d.max).to eq NMatrix[[2.0, 3.0], stype: stype]
|
64
61
|
end
|
65
62
|
|
66
63
|
it "should calculate the variance along the specified dimension" do
|
67
|
-
expect(
|
68
|
-
expect(
|
64
|
+
expect(nm_1d.variance).to eq NMatrix[3.7, stype: stype] unless stype == :yale
|
65
|
+
expect(nm_2d.variance(1)).to eq NMatrix[[0.5], [0.5], stype: stype]
|
69
66
|
end
|
70
67
|
|
71
68
|
it "should calculate the sum along the specified dimension" do
|
72
|
-
expect(
|
73
|
-
expect(
|
69
|
+
expect(nm_1d.sum).to eq NMatrix[11.0, stype: stype] unless stype == :yale
|
70
|
+
expect(nm_2d.sum).to eq NMatrix[[2.0, 4.0], stype: stype]
|
74
71
|
end
|
75
72
|
|
76
73
|
it "should calculate the standard deviation along the specified dimension" do
|
77
|
-
expect(
|
78
|
-
expect(
|
74
|
+
expect(nm_1d.std).to eq NMatrix[Math.sqrt(3.7), stype: stype] unless stype == :yale
|
75
|
+
expect(nm_2d.std(1)).to eq NMatrix[[Math.sqrt(0.5)], [Math.sqrt(0.5)], stype: stype]
|
79
76
|
end
|
80
77
|
|
81
78
|
it "should raise an ArgumentError when any invalid dimension is provided" do
|
82
|
-
expect {
|
83
|
-
expect {
|
79
|
+
expect { nm_1d.mean(3) }.to raise_exception(RangeError) unless stype == :yale
|
80
|
+
expect { nm_2d.mean(3) }.to raise_exception(RangeError)
|
84
81
|
end
|
85
82
|
|
86
83
|
it "should convert to float if it contains only a single element" do
|
@@ -90,65 +87,64 @@ describe "Statistical functions" do
|
|
90
87
|
end
|
91
88
|
|
92
89
|
it "should raise an index error if it contains more than a single element" do
|
93
|
-
expect {
|
94
|
-
expect {
|
90
|
+
expect { nm_1d.to_f }.to raise_error(IndexError) unless stype == :yale
|
91
|
+
expect { nm_2d.to_f }.to raise_error(IndexError)
|
95
92
|
end
|
96
93
|
|
97
94
|
it "should map a block to all elements" do
|
98
|
-
|
99
|
-
expect(
|
100
|
-
expect(@nm_2d.map { |e| e ** 2 }).to eq NMatrix[[0.0,1.0],[4.0,9.0], stype: stype]
|
95
|
+
expect(nm_1d.map { |e| e ** 2 }).to eq NMatrix[25.0,0.0,1.0,4.0,9.0, stype: stype] unless stype == :yale
|
96
|
+
expect(nm_2d.map { |e| e ** 2 }).to eq NMatrix[[0.0,1.0],[4.0,9.0], stype: stype]
|
101
97
|
end
|
102
98
|
|
103
99
|
it "should map! a block to all elements in place" do
|
104
100
|
fct = Proc.new { |e| e ** 2 }
|
105
101
|
unless stype == :yale then
|
106
|
-
expected1 =
|
107
|
-
|
108
|
-
expect(
|
102
|
+
expected1 = nm_1d.map(&fct)
|
103
|
+
nm_1d.map!(&fct)
|
104
|
+
expect(nm_1d).to eq expected1
|
109
105
|
end
|
110
|
-
expected2 =
|
111
|
-
|
112
|
-
expect(
|
106
|
+
expected2 = nm_2d.map(&fct)
|
107
|
+
nm_2d.map!(&fct)
|
108
|
+
expect(nm_2d).to eq expected2
|
113
109
|
end
|
114
110
|
|
115
111
|
it "should return an enumerator for map without a block" do
|
116
|
-
expect(
|
112
|
+
expect(nm_2d.map).to be_a Enumerator
|
117
113
|
end
|
118
114
|
|
119
115
|
it "should return an enumerator for reduce without a block" do
|
120
|
-
expect(
|
116
|
+
expect(nm_2d.reduce_along_dim(0)).to be_a Enumerator
|
121
117
|
end
|
122
118
|
|
123
119
|
it "should return an enumerator for each_along_dim without a block" do
|
124
|
-
expect(
|
120
|
+
expect(nm_2d.each_along_dim(0)).to be_a Enumerator
|
125
121
|
end
|
126
122
|
|
127
123
|
it "should iterate correctly for map without a block" do
|
128
|
-
en =
|
129
|
-
expect(en.each { |e| e**2 }).to eq
|
130
|
-
en =
|
131
|
-
expect(en.each { |e| e**2 }).to eq
|
124
|
+
en = nm_1d.map unless stype == :yale
|
125
|
+
expect(en.each { |e| e**2 }).to eq nm_1d.map { |e| e**2 } unless stype == :yale
|
126
|
+
en = nm_2d.map
|
127
|
+
expect(en.each { |e| e**2 }).to eq nm_2d.map { |e| e**2 }
|
132
128
|
end
|
133
129
|
|
134
130
|
it "should iterate correctly for reduce without a block" do
|
135
131
|
unless stype == :yale then
|
136
|
-
en =
|
132
|
+
en = nm_1d.reduce_along_dim(0, 1.0)
|
137
133
|
expect(en.each { |a, e| a+e }.to_f).to eq 12
|
138
134
|
end
|
139
|
-
en =
|
135
|
+
en = nm_2d.reduce_along_dim(1, 1.0)
|
140
136
|
expect(en.each { |a, e| a+e }).to eq NMatrix[[2.0],[6.0], stype: stype]
|
141
137
|
end
|
142
138
|
|
143
139
|
it "should iterate correctly for each_along_dim without a block" do
|
144
140
|
unless stype == :yale then
|
145
|
-
res = NMatrix.zeros_like(
|
146
|
-
en =
|
141
|
+
res = NMatrix.zeros_like(nm_1d[0...1])
|
142
|
+
en = nm_1d.each_along_dim(0)
|
147
143
|
en.each { |e| res += e }
|
148
144
|
expect(res.to_f).to eq 11
|
149
145
|
end
|
150
|
-
res = NMatrix.zeros_like (
|
151
|
-
en =
|
146
|
+
res = NMatrix.zeros_like (nm_2d[0...2, 0])
|
147
|
+
en = nm_2d.each_along_dim(1)
|
152
148
|
en.each { |e| res += e }
|
153
149
|
expect(res).to eq NMatrix[[1.0], [5.0], stype: stype]
|
154
150
|
end
|
@@ -167,7 +163,6 @@ describe "Statistical functions" do
|
|
167
163
|
acc
|
168
164
|
end
|
169
165
|
|
170
|
-
m = NMatrix.new([2,3], [1,2,3,3,4,5], dtype: :complex128, stype: stype)
|
171
166
|
m.reduce_along_dim(1, 0.0) do |acc, sub_m|
|
172
167
|
expect(sub_m.dtype).to eq :complex128
|
173
168
|
acc
|