|
104 | 104 | [:dense, :yale, :list].each do |stype|
|
105 | 105 | context "#block_diagonal #{dtype} #{stype}" do
|
106 | 106 | it "block_diagonal() creates a block-diagonal NMatrix" do
|
| 107 | + pending("not yet implemented for NMatrix-JRuby") if jruby? and dtype == :object |
107 | 108 | a = NMatrix.new([2,2], [1,2,
|
108 | 109 | 3,4])
|
109 | 110 | b = NMatrix.new([1,1], [123.0])
|
110 | 111 | c = NMatrix.new([3,3], [1,2,3,
|
111 | 112 | 1,2,3,
|
112 | 113 | 1,2,3])
|
113 |
| - d = Array[ [1,1,1], [2,2,2], [3,3,3] ] |
| 114 | + d = Array[ [1,1,1], [2,2,2], [3,3,3] ] |
114 | 115 | e = 12
|
115 | 116 | m = NMatrix.block_diagonal(a, b, c, d, e, dtype: dtype, stype: stype)
|
116 | 117 | expect(m).to eq(NMatrix.new([10,10], [1, 2, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
158 | 159 | expect { NMatrix.random("not an array or integer") }.to raise_error
|
159 | 160 | end
|
160 | 161 | end
|
161 |
| - |
| 162 | + |
162 | 163 | context "::magic" do
|
163 |
| - |
| 164 | + |
164 | 165 | ALL_DTYPES.each do |dtype|
|
165 | 166 | context dtype do
|
166 | 167 | it "creates a matrix with numbers from 1 to n^n(n squared)" do
|
| 168 | + pending("not yet implemented for NMatrix-JRuby") if jruby? |
167 | 169 | a = NMatrix.magic(3, dtype: dtype)
|
168 |
| - magic3 = NMatrix.new([3,3], [4, 9, 2, 3, 5, 7, 8, 1, 6], dtype: dtype) |
| 170 | + magic3 = NMatrix.new([3,3], [4, 9, 2, 3, 5, 7, 8, 1, 6], dtype: dtype) |
169 | 171 | expect(a).to eq magic3
|
170 |
| - |
| 172 | + |
171 | 173 | b = NMatrix.magic(4, dtype: dtype)
|
172 | 174 | magic4 = NMatrix.new([4,4], [1, 15, 14, 4, 12, 6, 7, 9, 8, 10, 11, 5, 13, 3, 2, 16], dtype: dtype)
|
173 | 175 | expect(b).to eq magic4
|
174 |
| - |
| 176 | + |
175 | 177 | c = NMatrix.magic(6, dtype: dtype)
|
176 | 178 | magic6 = NMatrix.new([6,6], [31, 9, 2, 22, 27, 20, 3, 32, 7, 21, 23, 25, 35, 1, 6, 26, 19, 24, 4, 36, 29, 13, 18, 11, 30, 5, 34, 12, 14, 16, 8, 28, 33, 17, 10, 15], dtype: dtype)
|
177 |
| - expect(c).to eq magic6 |
| 179 | + expect(c).to eq magic6 |
178 | 180 | end
|
179 | 181 | end
|
180 | 182 | end
|
181 |
| - |
| 183 | + |
182 | 184 | it "shape of two is not allowed" do
|
183 | 185 | expect { NMatrix.magic(2) }.to raise_error(ArgumentError)
|
184 | 186 | end
|
185 |
| - |
186 |
| - it "Only accepts an integer as dimension" do |
| 187 | + |
| 188 | + it "Only accepts an integer as dimension" do |
187 | 189 | expect { NMatrix.magic(3.0) }.to raise_error(ArgumentError)
|
188 | 190 | end
|
189 | 191 | end
|
190 |
| - |
| 192 | + |
191 | 193 | context "::linspace" do
|
192 | 194 | it "creates a row vector when given only one shape parameter" do
|
| 195 | + pending("not yet implemented for NMatrix-JRuby") if jruby? |
193 | 196 | v = NMatrix.linspace(1, 10, 4)
|
194 | 197 | #Expect a row vector only
|
195 | 198 | expect(v.shape.length).to eq(1)
|
196 |
| - |
| 199 | + |
197 | 200 | ans = [1.0,4.0,7.0,10.0]
|
198 | 201 |
|
199 | 202 | expect(v[0]).to be_within(0.000001).of(ans[0])
|
200 | 203 | expect(v[1]).to be_within(0.000001).of(ans[1])
|
201 | 204 | expect(v[2]).to be_within(0.000001).of(ans[2])
|
202 | 205 | expect(v[3]).to be_within(0.000001).of(ans[3])
|
203 | 206 | end
|
204 |
| - |
| 207 | + |
205 | 208 | it "creates a matrix of input shape with each entry linearly spaced in row major order" do
|
| 209 | + pending("not yet implemented for NMatrix-JRuby") if jruby? |
206 | 210 | v = NMatrix.linspace(1, Math::PI, [2,2])
|
207 | 211 | expect(v.dtype).to eq(:float64)
|
208 | 212 |
|
209 | 213 | ans = [1.0, 1.7138642072677612, 2.4277284145355225, 3.1415927410125732]
|
210 |
| - |
| 214 | + |
211 | 215 | expect(v[0,0]).to be_within(0.000001).of(ans[0])
|
212 | 216 | expect(v[0,1]).to be_within(0.000001).of(ans[1])
|
213 | 217 | expect(v[1,0]).to be_within(0.000001).of(ans[2])
|
|
217 | 221 |
|
218 | 222 | context "::logspace" do
|
219 | 223 | it "creates a logarithmically spaced vector" do
|
| 224 | + pending("not yet implemented for NMatrix-JRuby") if jruby? |
220 | 225 | v = NMatrix.logspace(1, 2, 10)
|
221 |
| - |
| 226 | + |
222 | 227 | expect(v.shape.length).to eq(1)
|
223 |
| - |
| 228 | + |
224 | 229 | #Unit test taken from Matlab R2015b output of logspace(1,2,10)
|
225 | 230 | ans = [10.0000, 12.9155, 16.6810, 21.5443, 27.8256, 35.9381, 46.4159, 59.9484, 77.4264, 100.0000]
|
226 |
| - |
| 231 | + |
227 | 232 | expect(v[0].round(4)).to be_within(0.000001).of(ans[0])
|
228 | 233 | expect(v[1].round(4)).to be_within(0.000001).of(ans[1])
|
229 | 234 | expect(v[2].round(4)).to be_within(0.000001).of(ans[2])
|
|
235 | 240 | expect(v[8].round(4)).to be_within(0.000001).of(ans[8])
|
236 | 241 | expect(v[9].round(4)).to be_within(0.000001).of(ans[9])
|
237 | 242 | end
|
238 |
| - |
| 243 | + |
239 | 244 | it "creates a logarithmically spaced vector bounded by Math::PI if :pi is pre-supplied" do
|
| 245 | + pending("not yet implemented for NMatrix-JRuby") if jruby? |
240 | 246 | v = NMatrix.logspace(1, :pi, 7)
|
241 |
| - |
| 247 | + |
242 | 248 | #Unit test taken from Matlab R2015b output of logspace(1,pi,10)
|
243 | 249 | ans = [10.0000, 8.2450, 6.7980, 5.6050, 4.6213, 3.8103, 3.1416]
|
244 |
| - |
| 250 | + |
245 | 251 | expect(v[0].round(4)).to be_within(0.000001).of(ans[0])
|
246 | 252 | expect(v[1].round(4)).to be_within(0.000001).of(ans[1])
|
247 | 253 | expect(v[2].round(4)).to be_within(0.000001).of(ans[2])
|
248 | 254 | expect(v[3].round(4)).to be_within(0.000001).of(ans[3])
|
249 | 255 | expect(v[4].round(4)).to be_within(0.000001).of(ans[4])
|
250 | 256 | expect(v[5].round(4)).to be_within(0.000001).of(ans[5])
|
251 | 257 | expect(v[6].round(4)).to be_within(0.000001).of(ans[6])
|
252 |
| - end |
| 258 | + end |
253 | 259 |
|
254 | 260 | it "creates a matrix of input shape with each entry logarithmically spaced in row major order" do
|
| 261 | + pending("not yet implemented for NMatrix-JRuby") if jruby? |
255 | 262 | v = NMatrix.logspace(1, 2, [3,2])
|
256 |
| - |
| 263 | + |
257 | 264 | ans = [10.0, 15.8489, 25.1189, 39.8107, 63.0957, 100.0]
|
258 |
| - |
| 265 | + |
259 | 266 | expect(v[0,0].round(4)).to be_within(0.000001).of(ans[0])
|
260 | 267 | expect(v[0,1].round(4)).to be_within(0.000001).of(ans[1])
|
261 | 268 | expect(v[1,0].round(4)).to be_within(0.000001).of(ans[2])
|
|
360 | 367 | end
|
361 | 368 |
|
362 | 369 | it "should create an nmatrix of ones with dimensions and type the same as its argument" do
|
| 370 | + pending("not yet implemented for NMatrix-JRuby") if jruby? |
363 | 371 | expect(NMatrix.ones_like(@nm_1d)).to eq NMatrix[1.0, 1.0, 1.0, 1.0, 1.0]
|
364 | 372 | expect(NMatrix.ones_like(@nm_2d)).to eq NMatrix[[1.0, 1.0], [1.0, 1.0]]
|
365 | 373 | end
|
|
383 | 391 | end
|
384 | 392 |
|
385 | 393 | it "ones() creates a vector of ones" do
|
| 394 | + pending("not yet implemented for NMatrix-JRuby") if jruby? |
386 | 395 | v = NVector.ones(3)
|
387 | 396 |
|
388 | 397 | 3.times do |i|
|
|
391 | 400 | end
|
392 | 401 |
|
393 | 402 | it "random() creates a vector of random numbers" do
|
| 403 | + pending("not yet implemented for NMatrix-JRuby") if jruby? |
394 | 404 | v = NVector.random(4)
|
395 | 405 | expect(v.dtype).to eq(:float64)
|
396 | 406 | expect(v.stype).to eq(:dense)
|
|
424 | 434 | end
|
425 | 435 |
|
426 | 436 | it "cindgen() creates a vector of complexes, sequentially" do
|
| 437 | + pending("not yet implemented for NMatrix-JRuby") if jruby? |
427 | 438 | v = NVector.cindgen(2)
|
428 | 439 | expect(v).to eq(NMatrix.new([2,1], [Complex(0.0, 0.0), Complex(1.0, 0.0)], dtype: :complex64))
|
429 | 440 | end
|
430 | 441 |
|
431 | 442 | it "linspace() creates a vector with n values equally spaced between a and b" do
|
| 443 | + pending("not yet implemented for NMatrix-JRuby") if jruby? |
432 | 444 | v = NVector.linspace(0, 2, 5)
|
433 | 445 | expect(v).to eq(NMatrix.new([5,1], [0.0, 0.5, 1.0, 1.5, 2.0]))
|
434 | 446 | end
|
435 | 447 |
|
436 | 448 | it "logspace() creates a vector with n values logarithmically spaced between decades 10^a and 10^b" do
|
| 449 | + pending("not yet implemented for NMatrix-JRuby") if jruby? |
437 | 450 | v = NVector.logspace(0, 3, 4)
|
438 | 451 | expect(v).to eq(NMatrix.new([4,1], [1.0, 10.0, 100.0, 1000.0]))
|
439 | 452 | end
|
|
0 commit comments