nmatrix 0.1.0.rc1 → 0.1.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -1
- data/Gemfile +1 -4
- data/History.txt +64 -2
- data/Manifest.txt +6 -4
- data/README.rdoc +8 -5
- data/Rakefile +0 -2
- data/ext/nmatrix/data/data.cpp +2 -1
- data/ext/nmatrix/data/data.h +3 -2
- data/ext/nmatrix/extconf.rb +4 -9
- data/ext/nmatrix/math.cpp +65 -0
- data/ext/nmatrix/math/math.h +1 -0
- data/ext/nmatrix/nmatrix.h +2 -2
- data/ext/nmatrix/ruby_constants.cpp +3 -1
- data/ext/nmatrix/ruby_constants.h +3 -1
- data/ext/nmatrix/ruby_nmatrix.c +153 -8
- data/ext/nmatrix/util/sl_list.cpp +6 -2
- data/lib/nmatrix/io/point_cloud.rb +182 -0
- data/lib/nmatrix/math.rb +35 -5
- data/lib/nmatrix/nmatrix.rb +70 -26
- data/lib/nmatrix/shortcuts.rb +18 -1
- data/lib/nmatrix/version.rb +1 -1
- data/nmatrix.gemspec +2 -2
- data/spec/00_nmatrix_spec.rb +220 -176
- data/spec/01_enum_spec.rb +29 -29
- data/spec/02_slice_spec.rb +85 -85
- data/spec/blas_spec.rb +18 -18
- data/spec/elementwise_spec.rb +44 -44
- data/spec/io_spec.rb +31 -24
- data/spec/lapack_spec.rb +34 -34
- data/spec/math_spec.rb +61 -46
- data/spec/nmatrix_yale_spec.rb +35 -35
- data/spec/rspec_spec.rb +2 -2
- data/spec/shortcuts_spec.rb +66 -48
- data/spec/slice_set_spec.rb +31 -31
- data/spec/stat_spec.rb +40 -40
- data/spec/test.pcd +20 -0
- metadata +5 -2
data/spec/01_enum_spec.rb
CHANGED
@@ -55,9 +55,9 @@ describe "NMatrix enumeration for" do
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
vv.
|
59
|
-
ii.
|
60
|
-
jj.
|
58
|
+
expect(vv).to eq([7,8,9, 12,13,0, 0,0,0, 0,17,18])
|
59
|
+
expect(ii).to eq([0]*12)
|
60
|
+
expect(jj).to eq([0,1,2]*4)
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should iterate along diagonal portion of A array" do
|
@@ -69,9 +69,9 @@ describe "NMatrix enumeration for" do
|
|
69
69
|
ii << i
|
70
70
|
jj << j
|
71
71
|
end
|
72
|
-
vv.
|
73
|
-
ii.
|
74
|
-
jj.
|
72
|
+
expect(vv).to eq([1,7,13,0,19])
|
73
|
+
expect(ii).to eq([0,1,2,3,4])
|
74
|
+
expect(jj).to eq(ii)
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should iterate along non-diagonal portion of A array" do
|
@@ -84,9 +84,9 @@ describe "NMatrix enumeration for" do
|
|
84
84
|
jj << j
|
85
85
|
end
|
86
86
|
|
87
|
-
vv.
|
88
|
-
ii.
|
89
|
-
jj.
|
87
|
+
expect(vv).to eq([2,3,4,5, 6,8,9,10, 11,12,14,15, 16,17,18,20])
|
88
|
+
expect(ii).to eq([[0]*4, [1]*4, [2]*4, [4]*4].flatten)
|
89
|
+
expect(jj).to eq([1,2,3,4, 0,2,3,5, 0,1,4,5, 0,2,3,5])
|
90
90
|
end
|
91
91
|
|
92
92
|
it "should iterate along a sliced diagonal portion of an A array" do
|
@@ -99,9 +99,9 @@ describe "NMatrix enumeration for" do
|
|
99
99
|
ii << i
|
100
100
|
jj << j
|
101
101
|
end
|
102
|
-
vv.
|
103
|
-
ii.
|
104
|
-
jj.
|
102
|
+
expect(vv).to eq([7,13,0])
|
103
|
+
expect(ii).to eq([1,2,3])
|
104
|
+
expect(jj).to eq([0,1,2])
|
105
105
|
end
|
106
106
|
|
107
107
|
it "should iterate along a sliced non-diagonal portion of a sliced A array" do
|
@@ -116,9 +116,9 @@ describe "NMatrix enumeration for" do
|
|
116
116
|
jj << j
|
117
117
|
end
|
118
118
|
|
119
|
-
ii.
|
120
|
-
jj.
|
121
|
-
vv.
|
119
|
+
expect(ii).to eq([0,0, 1, 3,3 ])
|
120
|
+
expect(jj).to eq([1,2, 0, 1,2 ])
|
121
|
+
expect(vv).to eq([8,9, 12, 17,18])
|
122
122
|
end
|
123
123
|
|
124
124
|
it "should visit each stored element of the matrix in order by indices" do
|
@@ -131,9 +131,9 @@ describe "NMatrix enumeration for" do
|
|
131
131
|
jj << j
|
132
132
|
end
|
133
133
|
|
134
|
-
vv.
|
135
|
-
ii.
|
136
|
-
jj.
|
134
|
+
expect(vv).to eq([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 16, 17, 18, 19, 20])
|
135
|
+
expect(ii).to eq([[0]*5, [1]*5, [2]*5, [3]*1, [4]*5].flatten)
|
136
|
+
expect(jj).to eq([0,1,2,3,4, 0,1,2,3,5, 0,1,2,4,5, 3, 0,2,3,4,5])
|
137
137
|
end
|
138
138
|
|
139
139
|
it "should visit each stored element of the slice in order by indices" do
|
@@ -146,9 +146,9 @@ describe "NMatrix enumeration for" do
|
|
146
146
|
ii << i
|
147
147
|
jj << j
|
148
148
|
end
|
149
|
-
ii.
|
150
|
-
jj.
|
151
|
-
vv.
|
149
|
+
expect(ii).to eq([0,0,0, 1,1, 2, 3,3 ])
|
150
|
+
expect(jj).to eq([0,1,2, 0,1, 2, 1,2 ])
|
151
|
+
expect(vv).to eq([7,8,9, 12,13, 0, 17,18 ])
|
152
152
|
end
|
153
153
|
end
|
154
154
|
|
@@ -162,9 +162,9 @@ describe "NMatrix enumeration for" do
|
|
162
162
|
jj << j
|
163
163
|
end
|
164
164
|
|
165
|
-
vv.
|
166
|
-
ii.
|
167
|
-
jj.
|
165
|
+
expect(vv).to eq([1,2,3,4,5,0,6,7,8,9,0,10,11,12,13,0,14,15,0,0,0,0,0,0,16,0,17,18,19,20])
|
166
|
+
expect(ii).to eq([[0]*6, [1]*6, [2]*6, [3]*6, [4]*6].flatten)
|
167
|
+
expect(jj).to eq([0,1,2,3,4,5]*5)
|
168
168
|
end
|
169
169
|
|
170
170
|
it "should visit each cell in the slice as if dense, making indices available" do
|
@@ -176,21 +176,21 @@ describe "NMatrix enumeration for" do
|
|
176
176
|
ii << i
|
177
177
|
jj << j
|
178
178
|
end
|
179
|
-
jj.
|
180
|
-
ii.
|
181
|
-
vv.
|
179
|
+
expect(jj).to eq([0,1,2]*4)
|
180
|
+
expect(ii).to eq([[0]*3, [1]*3, [2]*3, [3]*3].flatten)
|
181
|
+
expect(vv).to eq([7,8,9,12,13,0,0,0,0,0,17,18])
|
182
182
|
|
183
183
|
end
|
184
184
|
|
185
185
|
if stype == :list or stype == :dense then
|
186
186
|
it "should correctly map to a matrix with a single element" do
|
187
187
|
nm = N.new([1], [2.0], stype: stype)
|
188
|
-
nm.map { |e| e**2 }.
|
188
|
+
expect(nm.map { |e| e**2 }).to eq N.new([1], [4.0], stype: stype)
|
189
189
|
end
|
190
190
|
|
191
191
|
it "should correctly map to a matrix with multiple elements" do
|
192
192
|
nm = N.new([2], [2.0, 2.0], stype: stype)
|
193
|
-
nm.map { |e| e**2 }.
|
193
|
+
expect(nm.map { |e| e**2 }).to eq N.new([2], [4.0, 4.0], stype: stype)
|
194
194
|
end
|
195
195
|
end
|
196
196
|
end
|
data/spec/02_slice_spec.rb
CHANGED
@@ -45,8 +45,8 @@ describe "Slice operation" do
|
|
45
45
|
it "should correctly return a row of a reference-slice" do
|
46
46
|
@n = create_rectangular_matrix(stype)
|
47
47
|
@m = @n[1..4,1..3]
|
48
|
-
@m.row(1, :copy).
|
49
|
-
@m.row(1, :copy).to_flat_array.
|
48
|
+
expect(@m.row(1, :copy)).to eq(@m.row(1, :reference))
|
49
|
+
expect(@m.row(1, :copy).to_flat_array).to eq([12,13,0])
|
50
50
|
end
|
51
51
|
|
52
52
|
if stype == :yale
|
@@ -69,9 +69,9 @@ describe "Slice operation" do
|
|
69
69
|
js << j
|
70
70
|
end
|
71
71
|
|
72
|
-
vs.
|
73
|
-
js.
|
74
|
-
is.
|
72
|
+
expect(vs).to eq([3,4,5,6,7])
|
73
|
+
expect(js).to eq([2,3,5,7,8])
|
74
|
+
expect(is).to eq([0,0,0,0,0])
|
75
75
|
end
|
76
76
|
elsif stype == :list
|
77
77
|
it "should iterate across a partial row of stored indices" do
|
@@ -86,9 +86,9 @@ describe "Slice operation" do
|
|
86
86
|
js << j
|
87
87
|
end
|
88
88
|
|
89
|
-
vs.
|
90
|
-
is.
|
91
|
-
js.
|
89
|
+
expect(vs).to eq([7,8])
|
90
|
+
expect(is).to eq([0,0])
|
91
|
+
expect(js).to eq([0,1])
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
@@ -103,9 +103,9 @@ describe "Slice operation" do
|
|
103
103
|
is << i
|
104
104
|
js << j
|
105
105
|
end
|
106
|
-
vs.
|
107
|
-
is.
|
108
|
-
js.
|
106
|
+
expect(vs).to eq(stype == :yale ? [8,6,7] : [6,7,8])
|
107
|
+
expect(is).to eq([0,0,0])
|
108
|
+
expect(js).to eq(stype == :yale ? [2,0,1] : [0,1,2])
|
109
109
|
end
|
110
110
|
|
111
111
|
it "should iterate across a submatrix of stored indices" do
|
@@ -118,91 +118,91 @@ describe "Slice operation" do
|
|
118
118
|
js << j
|
119
119
|
end
|
120
120
|
|
121
|
-
vs.
|
122
|
-
is.
|
123
|
-
js.
|
121
|
+
expect(vs).to eq(stype == :yale ? [4,1,2,5] : [1,2,4,5])
|
122
|
+
expect(is).to eq(stype == :yale ? [1,0,0,1] : [0,0,1,1])
|
123
|
+
expect(js).to eq(stype == :yale ? [0,0,1,1] : [0,1,0,1])
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
127
|
it "should return correct supershape" do
|
128
128
|
x = NMatrix.random([10,12])
|
129
129
|
y = x[0...8,5...12]
|
130
|
-
y.shape.
|
131
|
-
y.supershape.
|
130
|
+
expect(y.shape).to eq([8,7])
|
131
|
+
expect(y.supershape).to eq([10,12])
|
132
132
|
end
|
133
133
|
|
134
134
|
it "should have #is_ref? method" do
|
135
135
|
a = @m[0..1, 0..1]
|
136
136
|
b = @m.slice(0..1, 0..1)
|
137
|
-
@m.is_ref
|
138
|
-
a.is_ref
|
139
|
-
b.is_ref
|
137
|
+
expect(@m.is_ref?).to be_false
|
138
|
+
expect(a.is_ref?).to be_true
|
139
|
+
expect(b.is_ref?).to be_false
|
140
140
|
end
|
141
141
|
|
142
142
|
it "reference should compare with non-reference" do
|
143
|
-
@m.slice(1..2,0..1).
|
144
|
-
@m[1..2,0..1].
|
145
|
-
@m[1..2,0..1].
|
143
|
+
expect(@m.slice(1..2,0..1)).to eq(@m[1..2, 0..1])
|
144
|
+
expect(@m[1..2,0..1]).to eq(@m.slice(1..2, 0..1))
|
145
|
+
expect(@m[1..2,0..1]).to eq(@m[1..2, 0..1])
|
146
146
|
end
|
147
147
|
|
148
148
|
context "with copying" do
|
149
149
|
it 'should return an NMatrix' do
|
150
150
|
n = @m.slice(0..1,0..1)
|
151
|
-
nm_eql(n, NMatrix.new([2,2], [0,1,3,4], dtype: :int32)).
|
151
|
+
expect(nm_eql(n, NMatrix.new([2,2], [0,1,3,4], dtype: :int32))).to be_true
|
152
152
|
end
|
153
153
|
|
154
154
|
it 'should return a copy of 2x2 matrix to self elements' do
|
155
155
|
n = @m.slice(1..2,0..1)
|
156
|
-
n.shape.
|
156
|
+
expect(n.shape).to eql([2,2])
|
157
157
|
|
158
|
-
n[1,1].
|
158
|
+
expect(n[1,1]).to eq(@m[2,1])
|
159
159
|
n[1,1] = -9
|
160
|
-
@m[2,1].
|
160
|
+
expect(@m[2,1]).to eql(7)
|
161
161
|
end
|
162
162
|
|
163
163
|
it 'should return a 1x2 matrix without refs to self elements' do
|
164
164
|
n = @m.slice(0,1..2)
|
165
|
-
n.shape.
|
165
|
+
expect(n.shape).to eql([1,2])
|
166
166
|
|
167
|
-
n[0].
|
168
|
-
n[1].
|
167
|
+
expect(n[0]).to eq(@m[0,1])
|
168
|
+
expect(n[1]).to eq(@m[0,2])
|
169
169
|
n[0] = -9
|
170
|
-
@m[0,1].
|
171
|
-
@m[0,2].
|
170
|
+
expect(@m[0,1]).to eql(1)
|
171
|
+
expect(@m[0,2]).to eql(2)
|
172
172
|
end
|
173
173
|
|
174
174
|
it 'should return a 2x1 matrix without refs to self elements' do
|
175
175
|
@m.extend NMatrix::YaleFunctions
|
176
176
|
|
177
177
|
n = @m.slice(0..1,1)
|
178
|
-
n.shape.
|
178
|
+
expect(n.shape).to eql([2,1])
|
179
179
|
|
180
|
-
n[0].
|
181
|
-
n[1].
|
180
|
+
expect(n[0]).to eq(@m[0,1])
|
181
|
+
expect(n[1]).to eq(@m[1,1])
|
182
182
|
n[0] = -9
|
183
|
-
@m[0,1].
|
184
|
-
@m[1,1].
|
183
|
+
expect(@m[0,1]).to eql(1)
|
184
|
+
expect(@m[1,1]).to eql(4)
|
185
185
|
end
|
186
186
|
|
187
187
|
it 'should be correct slice for range 0..2 and 0...3' do
|
188
|
-
@m.slice(0..2,0..2).
|
188
|
+
expect(@m.slice(0..2,0..2)).to eq(@m.slice(0...3,0...3))
|
189
189
|
end
|
190
190
|
|
191
191
|
[:dense, :list, :yale].each do |cast_type|
|
192
192
|
it "should cast copied slice from #{stype.upcase} to #{cast_type.upcase}" do
|
193
|
-
nm_eql(@m.slice(1..2, 1..2).cast(cast_type, :int32), @m.slice(1..2,1..2)).
|
194
|
-
nm_eql(@m.slice(0..1, 1..2).cast(cast_type, :int32), @m.slice(0..1,1..2)).
|
195
|
-
nm_eql(@m.slice(1..2, 0..1).cast(cast_type, :int32), @m.slice(1..2,0..1)).
|
196
|
-
nm_eql(@m.slice(0..1, 0..1).cast(cast_type, :int32), @m.slice(0..1,0..1)).
|
193
|
+
expect(nm_eql(@m.slice(1..2, 1..2).cast(cast_type, :int32), @m.slice(1..2,1..2))).to be_true
|
194
|
+
expect(nm_eql(@m.slice(0..1, 1..2).cast(cast_type, :int32), @m.slice(0..1,1..2))).to be_true
|
195
|
+
expect(nm_eql(@m.slice(1..2, 0..1).cast(cast_type, :int32), @m.slice(1..2,0..1))).to be_true
|
196
|
+
expect(nm_eql(@m.slice(0..1, 0..1).cast(cast_type, :int32), @m.slice(0..1,0..1))).to be_true
|
197
197
|
|
198
198
|
# Non square
|
199
|
-
nm_eql(@m.slice(0..2, 1..2).cast(cast_type, :int32), @m.slice(0..2,1..2)).
|
199
|
+
expect(nm_eql(@m.slice(0..2, 1..2).cast(cast_type, :int32), @m.slice(0..2,1..2))).to be_true
|
200
200
|
#require 'pry'
|
201
201
|
#binding.pry if cast_type == :yale
|
202
|
-
nm_eql(@m.slice(1..2, 0..2).cast(cast_type, :int32), @m.slice(1..2,0..2)).
|
202
|
+
expect(nm_eql(@m.slice(1..2, 0..2).cast(cast_type, :int32), @m.slice(1..2,0..2))).to be_true
|
203
203
|
|
204
204
|
# Full
|
205
|
-
nm_eql(@m.slice(0..2, 0..2).cast(cast_type, :int32), @m).
|
205
|
+
expect(nm_eql(@m.slice(0..2, 0..2).cast(cast_type, :int32), @m)).to be_true
|
206
206
|
end
|
207
207
|
end
|
208
208
|
end
|
@@ -221,47 +221,47 @@ describe "Slice operation" do
|
|
221
221
|
context "by reference" do
|
222
222
|
it 'should return an NMatrix' do
|
223
223
|
n = @m[0..1,0..1]
|
224
|
-
nm_eql(n, NMatrix.new([2,2], [0,1,3,4], dtype: :int32)).
|
224
|
+
expect(nm_eql(n, NMatrix.new([2,2], [0,1,3,4], dtype: :int32))).to be_true
|
225
225
|
end
|
226
226
|
|
227
227
|
it 'should return a 2x2 matrix with refs to self elements' do
|
228
228
|
n = @m[1..2,0..1]
|
229
|
-
n.shape.
|
229
|
+
expect(n.shape).to eql([2,2])
|
230
230
|
|
231
|
-
n[0,0].
|
231
|
+
expect(n[0,0]).to eq(@m[1,0])
|
232
232
|
n[0,0] = -9
|
233
|
-
@m[1,0].
|
233
|
+
expect(@m[1,0]).to eql(-9)
|
234
234
|
end
|
235
235
|
|
236
236
|
it 'should return a 1x2 vector with refs to self elements' do
|
237
237
|
n = @m[0,1..2]
|
238
|
-
n.shape.
|
238
|
+
expect(n.shape).to eql([1,2])
|
239
239
|
|
240
|
-
n[0].
|
240
|
+
expect(n[0]).to eq(@m[0,1])
|
241
241
|
n[0] = -9
|
242
|
-
@m[0,1].
|
242
|
+
expect(@m[0,1]).to eql(-9)
|
243
243
|
end
|
244
244
|
|
245
245
|
it 'should return a 2x1 vector with refs to self elements' do
|
246
246
|
n = @m[0..1,1]
|
247
|
-
n.shape.
|
247
|
+
expect(n.shape).to eql([2,1])
|
248
248
|
|
249
|
-
n[0].
|
249
|
+
expect(n[0]).to eq(@m[0,1])
|
250
250
|
n[0] = -9
|
251
|
-
@m[0,1].
|
251
|
+
expect(@m[0,1]).to eql(-9)
|
252
252
|
end
|
253
253
|
|
254
254
|
it 'should slice again' do
|
255
255
|
n = @m[1..2, 1..2]
|
256
|
-
nm_eql(n[1,0..1], NVector.new(2, [7,8], dtype: :int32).transpose).
|
256
|
+
expect(nm_eql(n[1,0..1], NVector.new(2, [7,8], dtype: :int32).transpose)).to be_true
|
257
257
|
end
|
258
258
|
|
259
259
|
it 'should be correct slice for range 0..2 and 0...3' do
|
260
|
-
@m[0..2,0..2].
|
260
|
+
expect(@m[0..2,0..2]).to eq(@m[0...3,0...3])
|
261
261
|
end
|
262
262
|
|
263
263
|
it 'should correctly handle :* slice notation' do
|
264
|
-
@m[:*,0].
|
264
|
+
expect(@m[:*,0]).to eq @m[0...@m.shape[0], 0]
|
265
265
|
end
|
266
266
|
|
267
267
|
if stype == :dense
|
@@ -297,14 +297,14 @@ describe "Slice operation" do
|
|
297
297
|
m = NMatrix.new([3,2], mary, dtype: right_dtype)[1..2,0..1]
|
298
298
|
|
299
299
|
r = n.dot m
|
300
|
-
r.shape.
|
300
|
+
expect(r.shape).to eql([3,2])
|
301
301
|
|
302
|
-
r[0,0].
|
303
|
-
r[0,1].
|
304
|
-
r[1,0].
|
305
|
-
r[1,1].
|
306
|
-
r[2,0].
|
307
|
-
r[2,1].
|
302
|
+
expect(r[0,0]).to eq(219.0)
|
303
|
+
expect(r[0,1]).to eq(185.0)
|
304
|
+
expect(r[1,0]).to eq(244.0)
|
305
|
+
expect(r[1,1]).to eq(205.0)
|
306
|
+
expect(r[2,0]).to eq(42.0)
|
307
|
+
expect(r[2,1]).to eq(35.0)
|
308
308
|
|
309
309
|
end
|
310
310
|
end
|
@@ -313,37 +313,37 @@ describe "Slice operation" do
|
|
313
313
|
context "operations" do
|
314
314
|
|
315
315
|
it "correctly transposes slices" do
|
316
|
-
@m[0...3,0].transpose.
|
316
|
+
expect(@m[0...3,0].transpose).to eq NMatrix[[0, 3, 6]]
|
317
317
|
end
|
318
318
|
|
319
319
|
it "adds slices" do
|
320
|
-
(NMatrix[[0,0,0]] + @m[1,0..2]).
|
320
|
+
expect(NMatrix[[0,0,0]] + @m[1,0..2]).to eq NMatrix[[3, 4, 5]]
|
321
321
|
end
|
322
322
|
|
323
323
|
it "scalar adds to slices" do
|
324
|
-
(@m[1,0..2]+1).
|
324
|
+
expect(@m[1,0..2]+1).to eq NMatrix[[4, 5, 6]]
|
325
325
|
end
|
326
326
|
|
327
327
|
it "compares slices to scalars" do
|
328
|
-
(@m[1, 0..2] > 2).each { |e| (e != 0).
|
328
|
+
(@m[1, 0..2] > 2).each { |e| expect(e != 0).to be_true }
|
329
329
|
end
|
330
330
|
|
331
331
|
it "iterates only over elements in the slice" do
|
332
332
|
els = []
|
333
333
|
@m[1, 0..2].each { |e| els << e }
|
334
|
-
els.size.
|
335
|
-
els[0].
|
336
|
-
els[1].
|
337
|
-
els[2].
|
334
|
+
expect(els.size).to eq 3
|
335
|
+
expect(els[0]).to eq 3
|
336
|
+
expect(els[1]).to eq 4
|
337
|
+
expect(els[2]).to eq 5
|
338
338
|
end
|
339
339
|
|
340
340
|
it "iterates with index only over elements in the slice" do
|
341
341
|
els = []
|
342
342
|
@m[1, 0..2].each_stored_with_indices { |a| els << a }
|
343
|
-
els.size.
|
344
|
-
els[0].
|
345
|
-
els[1].
|
346
|
-
els[2].
|
343
|
+
expect(els.size).to eq 3
|
344
|
+
expect(els[0]).to eq [3, 0, 0]
|
345
|
+
expect(els[1]).to eq [4, 0, 1]
|
346
|
+
expect(els[2]).to eq [5, 0, 2]
|
347
347
|
end
|
348
348
|
|
349
349
|
end
|
@@ -359,33 +359,33 @@ describe "Slice operation" do
|
|
359
359
|
end
|
360
360
|
|
361
361
|
step "reference slice of casted-copy" do
|
362
|
-
@m.
|
362
|
+
expect(@m).to eq(NMatrix.new([3,3], (0..9).to_a, dtype: :int32).cast(stype, :int32))
|
363
363
|
n = nil
|
364
364
|
1.times do
|
365
365
|
m = NMatrix.new([2,2], [1,2,3,4]).cast(stype, :int32)
|
366
366
|
n = m[0..1,0..1]
|
367
367
|
end
|
368
368
|
GC.start
|
369
|
-
n.
|
369
|
+
expect(n).to eq(NMatrix.new([2,2], [1,2,3,4]).cast(stype, :int32))
|
370
370
|
end
|
371
371
|
end
|
372
372
|
|
373
373
|
[:dense, :list, :yale].each do |cast_type|
|
374
374
|
it "should cast a square reference-slice from #{stype.upcase} to #{cast_type.upcase}" do
|
375
|
-
nm_eql(@m[1..2, 1..2].cast(cast_type), @m[1..2,1..2]).
|
376
|
-
nm_eql(@m[0..1, 1..2].cast(cast_type), @m[0..1,1..2]).
|
377
|
-
nm_eql(@m[1..2, 0..1].cast(cast_type), @m[1..2,0..1]).
|
378
|
-
nm_eql(@m[0..1, 0..1].cast(cast_type), @m[0..1,0..1]).
|
375
|
+
expect(nm_eql(@m[1..2, 1..2].cast(cast_type), @m[1..2,1..2])).to be_true
|
376
|
+
expect(nm_eql(@m[0..1, 1..2].cast(cast_type), @m[0..1,1..2])).to be_true
|
377
|
+
expect(nm_eql(@m[1..2, 0..1].cast(cast_type), @m[1..2,0..1])).to be_true
|
378
|
+
expect(nm_eql(@m[0..1, 0..1].cast(cast_type), @m[0..1,0..1])).to be_true
|
379
379
|
end
|
380
380
|
|
381
381
|
it "should cast a rectangular reference-slice from #{stype.upcase} to #{cast_type.upcase}" do
|
382
382
|
# Non square
|
383
|
-
nm_eql(@m[0..2, 1..2].cast(cast_type), @m[0..2,1..2]).
|
384
|
-
nm_eql(@m[1..2, 0..2].cast(cast_type), @m[1..2,0..2]).
|
383
|
+
expect(nm_eql(@m[0..2, 1..2].cast(cast_type), @m[0..2,1..2])).to be_true # FIXME: memory problem.
|
384
|
+
expect(nm_eql(@m[1..2, 0..2].cast(cast_type), @m[1..2,0..2])).to be_true # this one is fine
|
385
385
|
end
|
386
386
|
|
387
387
|
it "should cast a square full-matrix reference-slice from #{stype.upcase} to #{cast_type.upcase}" do
|
388
|
-
nm_eql(@m[0..2, 0..2].cast(cast_type), @m).
|
388
|
+
expect(nm_eql(@m[0..2, 0..2].cast(cast_type), @m)).to be_true
|
389
389
|
end
|
390
390
|
end
|
391
391
|
end
|