nmatrix-lapacke 0.2.1 → 0.2.3
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/ext/nmatrix/data/data.h +7 -8
- data/ext/nmatrix/data/ruby_object.h +1 -4
- data/ext/nmatrix/math/asum.h +10 -31
- data/ext/nmatrix/math/cblas_templates_core.h +10 -10
- data/ext/nmatrix/math/getrf.h +2 -2
- data/ext/nmatrix/math/imax.h +12 -9
- data/ext/nmatrix/math/laswp.h +3 -3
- data/ext/nmatrix/math/long_dtype.h +16 -3
- data/ext/nmatrix/math/magnitude.h +54 -0
- data/ext/nmatrix/math/nrm2.h +19 -14
- data/ext/nmatrix/math/trsm.h +40 -36
- data/ext/nmatrix/math/util.h +14 -0
- data/ext/nmatrix/nmatrix.h +39 -1
- data/ext/nmatrix/storage/common.h +9 -3
- data/ext/nmatrix/storage/yale/class.h +1 -1
- data/ext/nmatrix_lapacke/extconf.rb +3 -136
- data/ext/nmatrix_lapacke/lapacke.cpp +104 -84
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_cgeqrf.c +77 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_cgeqrf_work.c +89 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_cunmqr.c +88 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_cunmqr_work.c +111 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_dgeqrf.c +75 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_dgeqrf_work.c +87 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_dormqr.c +86 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_dormqr_work.c +109 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_sgeqrf.c +75 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_sgeqrf_work.c +87 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_sormqr.c +86 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_sormqr_work.c +109 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_zgeqrf.c +77 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_zgeqrf_work.c +89 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_zunmqr.c +88 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_zunmqr_work.c +111 -0
- data/ext/nmatrix_lapacke/lapacke/utils/lapacke_c_nancheck.c +51 -0
- data/ext/nmatrix_lapacke/lapacke/utils/lapacke_d_nancheck.c +51 -0
- data/ext/nmatrix_lapacke/lapacke/utils/lapacke_s_nancheck.c +51 -0
- data/ext/nmatrix_lapacke/lapacke/utils/lapacke_z_nancheck.c +51 -0
- data/ext/nmatrix_lapacke/math_lapacke.cpp +149 -17
- data/ext/nmatrix_lapacke/math_lapacke/lapacke_templates.h +76 -0
- data/lib/nmatrix/lapacke.rb +118 -0
- data/spec/00_nmatrix_spec.rb +50 -1
- data/spec/02_slice_spec.rb +21 -21
- data/spec/blas_spec.rb +25 -3
- data/spec/math_spec.rb +233 -5
- data/spec/plugins/lapacke/lapacke_spec.rb +187 -0
- data/spec/shortcuts_spec.rb +145 -5
- data/spec/spec_helper.rb +24 -1
- metadata +38 -8
@@ -298,6 +298,193 @@ describe "NMatrix::LAPACK functions implemented with LAPACKE interface" do
|
|
298
298
|
expect(vr).to be_within(err).of(vr_true)
|
299
299
|
expect(vl).to be_within(err).of(vl_true)
|
300
300
|
end
|
301
|
+
|
302
|
+
it "exposes lapacke_geqrf" do
|
303
|
+
a = NMatrix.new(3, [12.0, -51.0, 4.0,
|
304
|
+
6.0, 167.0, -68.0,
|
305
|
+
-4.0, 24.0, -41.0] , dtype: dtype)
|
306
|
+
|
307
|
+
b = NMatrix.new([3,1], 0, dtype: dtype)
|
308
|
+
|
309
|
+
NMatrix::LAPACK::lapacke_geqrf(:row, a.shape[0], a.shape[1], a, a.shape[1], b)
|
310
|
+
|
311
|
+
x = NMatrix.new([3,1], TAU_SOLUTION_ARRAY, dtype: dtype)
|
312
|
+
|
313
|
+
y = NMatrix.new([3,3], GEQRF_SOLUTION_ARRAY, dtype: dtype)
|
314
|
+
|
315
|
+
err = case dtype
|
316
|
+
when :float32, :complex64
|
317
|
+
1e-4
|
318
|
+
when :float64, :complex128
|
319
|
+
1e-14
|
320
|
+
end
|
321
|
+
|
322
|
+
expect(b).to be_within(err).of(x)
|
323
|
+
expect(a).to be_within(err).of(y)
|
324
|
+
end
|
325
|
+
|
326
|
+
it "calculates QR decomposition in a compressed format using geqrf!" do
|
327
|
+
a = NMatrix.new(3, [12.0, -51.0, 4.0,
|
328
|
+
6.0, 167.0, -68.0,
|
329
|
+
-4.0, 24.0, -41.0] , dtype: dtype)
|
330
|
+
|
331
|
+
tau = a.geqrf!
|
332
|
+
|
333
|
+
x = NMatrix.new([3,1], TAU_SOLUTION_ARRAY, dtype: dtype)
|
334
|
+
|
335
|
+
y = NMatrix.new([3,3], GEQRF_SOLUTION_ARRAY, dtype: dtype)
|
336
|
+
|
337
|
+
err = case dtype
|
338
|
+
when :float32, :complex64
|
339
|
+
1e-4
|
340
|
+
when :float64, :complex128
|
341
|
+
1e-14
|
342
|
+
end
|
343
|
+
|
344
|
+
expect(tau).to be_within(err).of(x)
|
345
|
+
expect(a).to be_within(err).of(y)
|
346
|
+
end
|
347
|
+
|
348
|
+
it "exposes lapacke_ormqr and lapacke_unmqr" do
|
349
|
+
a = NMatrix.new([4,2], [34.0, 21.0,
|
350
|
+
23.0, 53.0,
|
351
|
+
26.0, 346.0,
|
352
|
+
23.0, 121.0] , dtype: dtype)
|
353
|
+
|
354
|
+
tau = NMatrix.new([2,1], dtype: dtype)
|
355
|
+
result = NMatrix.identity(4, dtype: dtype)
|
356
|
+
|
357
|
+
# get tau from geqrf, use for ormqr
|
358
|
+
NMatrix::LAPACK::lapacke_geqrf(:row, a.shape[0], a.shape[1], a, a.shape[1], tau)
|
359
|
+
|
360
|
+
#Q is stored in result
|
361
|
+
a.complex_dtype? ?
|
362
|
+
NMatrix::LAPACK::lapacke_unmqr(:row, :left, false, result.shape[0], result.shape[1], tau.shape[0],
|
363
|
+
a, a.shape[1], tau, result, result.shape[1])
|
364
|
+
:
|
365
|
+
|
366
|
+
NMatrix::LAPACK::lapacke_ormqr(:row, :left, false, result.shape[0], result.shape[1], tau.shape[0],
|
367
|
+
a, a.shape[1], tau, result, result.shape[1])
|
368
|
+
|
369
|
+
x = NMatrix.new([4,4], Q_SOLUTION_ARRAY_1, dtype: dtype)
|
370
|
+
|
371
|
+
err = case dtype
|
372
|
+
when :float32, :complex64
|
373
|
+
1e-4
|
374
|
+
when :float64, :complex128
|
375
|
+
1e-14
|
376
|
+
end
|
377
|
+
|
378
|
+
expect(result).to be_within(err).of(x)
|
379
|
+
end
|
380
|
+
|
381
|
+
it "calculates the product of the orthogonal matrix with an arbitrary matrix" do
|
382
|
+
a = N.new([2,2], [34.0, 21, 23, 53] , dtype: dtype)
|
383
|
+
|
384
|
+
tau = NMatrix.new([2,1], dtype: dtype)
|
385
|
+
|
386
|
+
#Result is the multiplicand that gets overriden : result = Q * result
|
387
|
+
result = NMatrix.new([2,2], [2,0,0,2], dtype: dtype)
|
388
|
+
|
389
|
+
# get tau from geqrf, use for ormqr
|
390
|
+
NMatrix::LAPACK::lapacke_geqrf(:row, a.shape[0], a.shape[1], a, a.shape[1], tau)
|
391
|
+
|
392
|
+
#Q is stored in result
|
393
|
+
a.complex_dtype? ?
|
394
|
+
NMatrix::LAPACK::lapacke_unmqr(:row, :left, false, result.shape[0], result.shape[1], tau.shape[0],
|
395
|
+
a, a.shape[1], tau, result, result.shape[1])
|
396
|
+
:
|
397
|
+
|
398
|
+
NMatrix::LAPACK::lapacke_ormqr(:row, :left, false, result.shape[0], result.shape[1], tau.shape[0],
|
399
|
+
a, a.shape[1], tau, result, result.shape[1])
|
400
|
+
|
401
|
+
x = NMatrix.new([2,2], [-1.6565668262559257 , -1.1206187354084205,
|
402
|
+
-1.1206187354084205 , 1.6565668262559263], dtype: dtype)
|
403
|
+
|
404
|
+
err = case dtype
|
405
|
+
when :float32, :complex64
|
406
|
+
1e-4
|
407
|
+
when :float64, :complex128
|
408
|
+
1e-14
|
409
|
+
end
|
410
|
+
|
411
|
+
expect(result).to be_within(err).of(x)
|
412
|
+
end
|
413
|
+
|
414
|
+
it "calculates the orthogonal matrix Q using ormqr/unmqr after geqrf!" do
|
415
|
+
a = NMatrix.new([4,2], [34.0, 21.0,
|
416
|
+
23.0, 53.0,
|
417
|
+
26.0, 346.0,
|
418
|
+
23.0, 121.0] , dtype: dtype)
|
419
|
+
|
420
|
+
# get tau from geqrf, use for ormqr
|
421
|
+
tau = a.geqrf!
|
422
|
+
|
423
|
+
#Q is stored in result
|
424
|
+
result = a.complex_dtype? ? a.unmqr(tau) : a.ormqr(tau)
|
425
|
+
|
426
|
+
|
427
|
+
x = NMatrix.new([4,4], Q_SOLUTION_ARRAY_1, dtype: dtype)
|
428
|
+
|
429
|
+
err = case dtype
|
430
|
+
when :float32, :complex64
|
431
|
+
1e-4
|
432
|
+
when :float64, :complex128
|
433
|
+
1e-14
|
434
|
+
end
|
435
|
+
|
436
|
+
expect(result).to be_within(err).of(x)
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
440
|
+
it "calculates the transpose of Q using ormqr/unmqr after geqrf!" do
|
441
|
+
a = NMatrix.new([4,2], [34.0, 21.0,
|
442
|
+
23.0, 53.0,
|
443
|
+
26.0, 346.0,
|
444
|
+
23.0, 121.0] , dtype: dtype)
|
445
|
+
|
446
|
+
# get tau from geqrf, use for ormqr
|
447
|
+
tau = a.geqrf!
|
448
|
+
|
449
|
+
#Q is stored in result
|
450
|
+
result = a.complex_dtype? ? a.unmqr(tau, :left, :complex_conjugate) : a.ormqr(tau, :left, :transpose)
|
451
|
+
|
452
|
+
|
453
|
+
x = NMatrix.new([4,4], Q_SOLUTION_ARRAY_1, dtype: dtype)
|
454
|
+
x = x.transpose
|
455
|
+
|
456
|
+
err = case dtype
|
457
|
+
when :float32, :complex64
|
458
|
+
1e-4
|
459
|
+
when :float64, :complex128
|
460
|
+
1e-14
|
461
|
+
end
|
462
|
+
|
463
|
+
expect(result).to be_within(err).of(x)
|
464
|
+
end
|
465
|
+
|
466
|
+
it "calculates the multiplication c * Q using ormqr/unmqr after geqrf!" do
|
467
|
+
a = NMatrix.new(3, [12.0, -51.0, 4.0,
|
468
|
+
6.0, 167.0, -68.0,
|
469
|
+
-4.0, 24.0, -41.0] , dtype: dtype)
|
470
|
+
|
471
|
+
# get tau from geqrf, use for ormqr
|
472
|
+
tau = a.geqrf!
|
473
|
+
c = NMatrix.new([2,3], [1,0,1,0,0,1], dtype: dtype)
|
474
|
+
|
475
|
+
#Q is stored in result
|
476
|
+
result = a.complex_dtype? ? a.unmqr(tau, :right, false, c) : a.ormqr(tau, :right, false, c)
|
477
|
+
|
478
|
+
solution = NMatrix.new([2,3], [-0.5714285714285714, 0.2228571428571429, 1.2742857142857142,
|
479
|
+
0.28571428571428575, -0.1714285714285714, 0.9428571428571428] , dtype: dtype)
|
480
|
+
err = case dtype
|
481
|
+
when :float32, :complex64
|
482
|
+
1e-4
|
483
|
+
when :float64, :complex128
|
484
|
+
1e-14
|
485
|
+
end
|
486
|
+
|
487
|
+
expect(result).to be_within(err).of(solution)
|
301
488
|
end
|
302
489
|
end
|
303
490
|
end
|
data/spec/shortcuts_spec.rb
CHANGED
@@ -50,10 +50,45 @@ describe NMatrix do
|
|
50
50
|
expect(m).to eq identity3
|
51
51
|
end
|
52
52
|
|
53
|
+
it "hilbert() creates an hilbert matrix" do
|
54
|
+
m = NMatrix.hilbert(8)
|
55
|
+
expect(m[4, 0]).to be_within(0.000001).of(0.2)
|
56
|
+
expect(m[4, 1]).to be_within(0.000001).of(0.16666666666666666)
|
57
|
+
expect(m[4, 2]).to be_within(0.000001).of(0.14285714285714285)
|
58
|
+
expect(m[4, 3]).to be_within(0.000001).of(0.125)
|
59
|
+
|
60
|
+
m = NMatrix.hilbert(3)
|
61
|
+
hilbert3 = NMatrix.new([3, 3], [1.0, 0.5, 0.3333333333333333,\
|
62
|
+
0.5, 0.3333333333333333, 0.25, 0.3333333333333333, 0.25, 0.2])
|
63
|
+
expect(m).to eq hilbert3
|
64
|
+
0.upto(2) do |i|
|
65
|
+
0.upto(2) do |j|
|
66
|
+
expect(m[i, j]).to be_within(0.000001).of(hilbert3[i,j])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it "inv_hilbert() creates an inverse hilbert matrix" do
|
72
|
+
m = NMatrix.inv_hilbert(6)
|
73
|
+
inv_hilbert6 = [3360.0, -88200.0, 564480.0, -1411200.0]
|
74
|
+
expect(m[2,0]).to be_within(0.000001).of(inv_hilbert6[0])
|
75
|
+
expect(m[2,1]).to be_within(0.000001).of(inv_hilbert6[1])
|
76
|
+
expect(m[2,2]).to be_within(0.000001).of(inv_hilbert6[2])
|
77
|
+
expect(m[2,3]).to be_within(0.000001).of(inv_hilbert6[3])
|
78
|
+
|
79
|
+
m = NMatrix.inv_hilbert(3)
|
80
|
+
inv_hilbert3 = NMatrix.new([3, 3], [ 9.0, -36.0, 30.0, -36.0, 192.0, -180.0, 30.0, -180.0, 180.0] )
|
81
|
+
0.upto(2) do |i|
|
82
|
+
0.upto(2) do |j|
|
83
|
+
expect(m[i, j]).to be_within(0.000001).of(inv_hilbert3[i,j])
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
53
88
|
it "diag() creates a matrix with pre-supplied diagonal" do
|
54
89
|
arr = [1,2,3,4]
|
55
90
|
m = NMatrix.diag(arr)
|
56
|
-
expect(m.is_a?(NMatrix)).to
|
91
|
+
expect(m.is_a?(NMatrix)).to be true
|
57
92
|
end
|
58
93
|
|
59
94
|
it "diagonals() contains the seeded values on the diagonal" do
|
@@ -123,6 +158,112 @@ describe NMatrix do
|
|
123
158
|
expect { NMatrix.random("not an array or integer") }.to raise_error
|
124
159
|
end
|
125
160
|
end
|
161
|
+
|
162
|
+
context "::magic" do
|
163
|
+
|
164
|
+
ALL_DTYPES.each do |dtype|
|
165
|
+
context dtype do
|
166
|
+
it "creates a matrix with numbers from 1 to n^n(n squared)" do
|
167
|
+
a = NMatrix.magic(3, dtype: dtype)
|
168
|
+
magic3 = NMatrix.new([3,3], [4, 9, 2, 3, 5, 7, 8, 1, 6], dtype: dtype)
|
169
|
+
expect(a).to eq magic3
|
170
|
+
|
171
|
+
b = NMatrix.magic(4, dtype: dtype)
|
172
|
+
magic4 = NMatrix.new([4,4], [1, 15, 14, 4, 12, 6, 7, 9, 8, 10, 11, 5, 13, 3, 2, 16], dtype: dtype)
|
173
|
+
expect(b).to eq magic4
|
174
|
+
|
175
|
+
c = NMatrix.magic(6, dtype: dtype)
|
176
|
+
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
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
it "shape of two is not allowed" do
|
183
|
+
expect { NMatrix.magic(2) }.to raise_error(ArgumentError)
|
184
|
+
end
|
185
|
+
|
186
|
+
it "Only accepts an integer as dimension" do
|
187
|
+
expect { NMatrix.magic(3.0) }.to raise_error(ArgumentError)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
context "::linspace" do
|
192
|
+
it "creates a row vector when given only one shape parameter" do
|
193
|
+
v = NMatrix.linspace(1, 10, 4)
|
194
|
+
#Expect a row vector only
|
195
|
+
expect(v.shape.length).to eq(1)
|
196
|
+
|
197
|
+
ans = [1.0,4.0,7.0,10.0]
|
198
|
+
|
199
|
+
expect(v[0]).to be_within(0.000001).of(ans[0])
|
200
|
+
expect(v[1]).to be_within(0.000001).of(ans[1])
|
201
|
+
expect(v[2]).to be_within(0.000001).of(ans[2])
|
202
|
+
expect(v[3]).to be_within(0.000001).of(ans[3])
|
203
|
+
end
|
204
|
+
|
205
|
+
it "creates a matrix of input shape with each entry linearly spaced in row major order" do
|
206
|
+
v = NMatrix.linspace(1, Math::PI, [2,2])
|
207
|
+
expect(v.dtype).to eq(:float64)
|
208
|
+
|
209
|
+
ans = [1.0, 1.7138642072677612, 2.4277284145355225, 3.1415927410125732]
|
210
|
+
|
211
|
+
expect(v[0,0]).to be_within(0.000001).of(ans[0])
|
212
|
+
expect(v[0,1]).to be_within(0.000001).of(ans[1])
|
213
|
+
expect(v[1,0]).to be_within(0.000001).of(ans[2])
|
214
|
+
expect(v[1,1]).to be_within(0.000001).of(ans[3])
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
context "::logspace" do
|
219
|
+
it "creates a logarithmically spaced vector" do
|
220
|
+
v = NMatrix.logspace(1, 2, 10)
|
221
|
+
|
222
|
+
expect(v.shape.length).to eq(1)
|
223
|
+
|
224
|
+
#Unit test taken from Matlab R2015b output of logspace(1,2,10)
|
225
|
+
ans = [10.0000, 12.9155, 16.6810, 21.5443, 27.8256, 35.9381, 46.4159, 59.9484, 77.4264, 100.0000]
|
226
|
+
|
227
|
+
expect(v[0].round(4)).to be_within(0.000001).of(ans[0])
|
228
|
+
expect(v[1].round(4)).to be_within(0.000001).of(ans[1])
|
229
|
+
expect(v[2].round(4)).to be_within(0.000001).of(ans[2])
|
230
|
+
expect(v[3].round(4)).to be_within(0.000001).of(ans[3])
|
231
|
+
expect(v[4].round(4)).to be_within(0.000001).of(ans[4])
|
232
|
+
expect(v[5].round(4)).to be_within(0.000001).of(ans[5])
|
233
|
+
expect(v[6].round(4)).to be_within(0.000001).of(ans[6])
|
234
|
+
expect(v[7].round(4)).to be_within(0.000001).of(ans[7])
|
235
|
+
expect(v[8].round(4)).to be_within(0.000001).of(ans[8])
|
236
|
+
expect(v[9].round(4)).to be_within(0.000001).of(ans[9])
|
237
|
+
end
|
238
|
+
|
239
|
+
it "creates a logarithmically spaced vector bounded by Math::PI if :pi is pre-supplied" do
|
240
|
+
v = NMatrix.logspace(1, :pi, 7)
|
241
|
+
|
242
|
+
#Unit test taken from Matlab R2015b output of logspace(1,pi,10)
|
243
|
+
ans = [10.0000, 8.2450, 6.7980, 5.6050, 4.6213, 3.8103, 3.1416]
|
244
|
+
|
245
|
+
expect(v[0].round(4)).to be_within(0.000001).of(ans[0])
|
246
|
+
expect(v[1].round(4)).to be_within(0.000001).of(ans[1])
|
247
|
+
expect(v[2].round(4)).to be_within(0.000001).of(ans[2])
|
248
|
+
expect(v[3].round(4)).to be_within(0.000001).of(ans[3])
|
249
|
+
expect(v[4].round(4)).to be_within(0.000001).of(ans[4])
|
250
|
+
expect(v[5].round(4)).to be_within(0.000001).of(ans[5])
|
251
|
+
expect(v[6].round(4)).to be_within(0.000001).of(ans[6])
|
252
|
+
end
|
253
|
+
|
254
|
+
it "creates a matrix of input shape with each entry logarithmically spaced in row major order" do
|
255
|
+
v = NMatrix.logspace(1, 2, [3,2])
|
256
|
+
|
257
|
+
ans = [10.0, 15.8489, 25.1189, 39.8107, 63.0957, 100.0]
|
258
|
+
|
259
|
+
expect(v[0,0].round(4)).to be_within(0.000001).of(ans[0])
|
260
|
+
expect(v[0,1].round(4)).to be_within(0.000001).of(ans[1])
|
261
|
+
expect(v[1,0].round(4)).to be_within(0.000001).of(ans[2])
|
262
|
+
expect(v[1,1].round(4)).to be_within(0.000001).of(ans[3])
|
263
|
+
expect(v[2,0].round(4)).to be_within(0.000001).of(ans[4])
|
264
|
+
expect(v[2,1].round(4)).to be_within(0.000001).of(ans[5])
|
265
|
+
end
|
266
|
+
end
|
126
267
|
|
127
268
|
it "seq() creates a matrix of integers, sequentially" do
|
128
269
|
m = NMatrix.seq(2) # 2x2 matrix.
|
@@ -136,7 +277,6 @@ describe NMatrix do
|
|
136
277
|
end
|
137
278
|
end
|
138
279
|
|
139
|
-
|
140
280
|
it "indgen() creates a matrix of integers as well as seq()" do
|
141
281
|
m = NMatrix.indgen(2) # 2x2 matrix.
|
142
282
|
value = 0
|
@@ -189,19 +329,19 @@ describe NMatrix do
|
|
189
329
|
it "column() returns a NMatrix" do
|
190
330
|
m = NMatrix.random(3)
|
191
331
|
|
192
|
-
expect(m.column(2).is_a?(NMatrix)).to
|
332
|
+
expect(m.column(2).is_a?(NMatrix)).to be true
|
193
333
|
end
|
194
334
|
|
195
335
|
it "row() returns a NMatrix" do
|
196
336
|
m = NMatrix.random(3)
|
197
337
|
|
198
|
-
expect(m.row(2).is_a?(NMatrix)).to
|
338
|
+
expect(m.row(2).is_a?(NMatrix)).to be true
|
199
339
|
end
|
200
340
|
|
201
341
|
it "diagonals() creates an NMatrix" do
|
202
342
|
arr = [1,2,3,4]
|
203
343
|
m = NMatrix.diagonals(arr)
|
204
|
-
expect(m.is_a?(NMatrix)).to
|
344
|
+
expect(m.is_a?(NMatrix)).to be true
|
205
345
|
end
|
206
346
|
|
207
347
|
it "diagonals() contains the seeded values on the diagonal" do
|
data/spec/spec_helper.rb
CHANGED
@@ -32,7 +32,7 @@ require "./lib/nmatrix/rspec"
|
|
32
32
|
|
33
33
|
ALL_DTYPES = [:byte,:int8,:int16,:int32,:int64, :float32,:float64, :object,
|
34
34
|
:complex64, :complex128]
|
35
|
-
|
35
|
+
|
36
36
|
NON_INTEGER_DTYPES = [:float32, :float64, :complex64, :complex128,
|
37
37
|
:object]
|
38
38
|
|
@@ -48,6 +48,29 @@ COMPLEX_MATRIX32A_ARRAY = MATRIX32A_ARRAY.zip(MATRIX32A_ARRAY.reverse).collect {
|
|
48
48
|
GETRF_EXAMPLE_ARRAY = [-1,0,10,4,9,2,3,5,7,8,1,6]
|
49
49
|
GETRF_SOLUTION_ARRAY = [9.0, 2.0, 3.0, 5.0, 7.0/9, 58.0/9, -4.0/3, 19.0/9, -1.0/9, 1.0/29, 301.0/29, 130.0/29]
|
50
50
|
|
51
|
+
TAU_SOLUTION_ARRAY = [1.8571428571428572,1.9938461538461538, 0.0]
|
52
|
+
|
53
|
+
GEQRF_SOLUTION_ARRAY =[ -14.0, -21.0, 14.000000000000002,
|
54
|
+
0.23076923076923078, -175.00000000000003, 70.00000000000001,
|
55
|
+
-0.15384615384615385, 0.055555555555555546, -35.0]
|
56
|
+
|
57
|
+
R_SOLUTION_ARRAY = [-159.2388143638353, -41.00131005172065, -56.75123892439876, -90.75048729628048,
|
58
|
+
0.0, 25.137473501580676, 2.073591725046292, 9.790607357775713,
|
59
|
+
0.0, 0.0, -20.83259700334131, -17.592414929551445]
|
60
|
+
|
61
|
+
Q_SOLUTION_ARRAY_1 = [-0.632455532033676, -0.5209522876558295, -0.3984263084135902, -0.41214704991068,
|
62
|
+
-0.42783756578748666, -0.20837937347171134, 0.876505919951498, 0.07259770177184455,
|
63
|
+
-0.48364246567281094, 0.8265854747306287,-0.015758658987033422, -0.2873988222474053,
|
64
|
+
-0.42783756578748666, 0.044081783789183565, -0.26971376257215296, 0.8615487797670971]
|
65
|
+
|
66
|
+
Q_SOLUTION_ARRAY_2 = [-0.8571428571428572, 0.3942857142857143, 0.33142857142857146,
|
67
|
+
-0.4285714285714286, -0.9028571428571428, -0.03428571428571425,
|
68
|
+
0.28571428571428575, -0.1714285714285714, 0.9428571428571428]
|
69
|
+
|
70
|
+
Q_SOLUTION_ARRAY_3 = [-0.7724247413634004, -0.026670393594597247, -0.6345460653374136,
|
71
|
+
-0.5777485870360393, -0.38541856437557026, 0.7194853024298236,
|
72
|
+
-0.26375478973384403, 0.9223563413020934, 0.28229805268947933]
|
73
|
+
|
51
74
|
def create_matrix(stype) #:nodoc:
|
52
75
|
m = NMatrix.new([3,3], 0, dtype: :int32, stype: stype, default: 0)
|
53
76
|
|
metadata
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nmatrix-lapacke
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
+
- Will Levine
|
7
8
|
- John Woods
|
8
|
-
- Chris Wailes
|
9
|
-
- Aleksey Timin
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date: 2016-
|
12
|
+
date: 2016-07-25 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: nmatrix
|
@@ -18,14 +17,14 @@ dependencies:
|
|
18
17
|
requirements:
|
19
18
|
- - '='
|
20
19
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.2.
|
20
|
+
version: 0.2.3
|
22
21
|
type: :runtime
|
23
22
|
prerelease: false
|
24
23
|
version_requirements: !ruby/object:Gem::Requirement
|
25
24
|
requirements:
|
26
25
|
- - '='
|
27
26
|
- !ruby/object:Gem::Version
|
28
|
-
version: 0.2.
|
27
|
+
version: 0.2.3
|
29
28
|
description: For using linear algebra fuctions provided by LAPACK and BLAS
|
30
29
|
email:
|
31
30
|
- john.o.woods@gmail.com
|
@@ -48,6 +47,7 @@ files:
|
|
48
47
|
- ext/nmatrix/math/imax.h
|
49
48
|
- ext/nmatrix/math/laswp.h
|
50
49
|
- ext/nmatrix/math/long_dtype.h
|
50
|
+
- ext/nmatrix/math/magnitude.h
|
51
51
|
- ext/nmatrix/math/math.h
|
52
52
|
- ext/nmatrix/math/nrm2.h
|
53
53
|
- ext/nmatrix/math/rot.h
|
@@ -84,6 +84,8 @@ files:
|
|
84
84
|
- ext/nmatrix_lapacke/lapacke/include/lapacke_utils.h
|
85
85
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_cgeev.c
|
86
86
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_cgeev_work.c
|
87
|
+
- ext/nmatrix_lapacke/lapacke/src/lapacke_cgeqrf.c
|
88
|
+
- ext/nmatrix_lapacke/lapacke/src/lapacke_cgeqrf_work.c
|
87
89
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_cgesdd.c
|
88
90
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_cgesdd_work.c
|
89
91
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_cgesvd.c
|
@@ -100,8 +102,12 @@ files:
|
|
100
102
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_cpotri_work.c
|
101
103
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_cpotrs.c
|
102
104
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_cpotrs_work.c
|
105
|
+
- ext/nmatrix_lapacke/lapacke/src/lapacke_cunmqr.c
|
106
|
+
- ext/nmatrix_lapacke/lapacke/src/lapacke_cunmqr_work.c
|
103
107
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_dgeev.c
|
104
108
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_dgeev_work.c
|
109
|
+
- ext/nmatrix_lapacke/lapacke/src/lapacke_dgeqrf.c
|
110
|
+
- ext/nmatrix_lapacke/lapacke/src/lapacke_dgeqrf_work.c
|
105
111
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_dgesdd.c
|
106
112
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_dgesdd_work.c
|
107
113
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_dgesvd.c
|
@@ -112,6 +118,8 @@ files:
|
|
112
118
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_dgetri_work.c
|
113
119
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_dgetrs.c
|
114
120
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_dgetrs_work.c
|
121
|
+
- ext/nmatrix_lapacke/lapacke/src/lapacke_dormqr.c
|
122
|
+
- ext/nmatrix_lapacke/lapacke/src/lapacke_dormqr_work.c
|
115
123
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_dpotrf.c
|
116
124
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_dpotrf_work.c
|
117
125
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_dpotri.c
|
@@ -120,6 +128,8 @@ files:
|
|
120
128
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_dpotrs_work.c
|
121
129
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_sgeev.c
|
122
130
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_sgeev_work.c
|
131
|
+
- ext/nmatrix_lapacke/lapacke/src/lapacke_sgeqrf.c
|
132
|
+
- ext/nmatrix_lapacke/lapacke/src/lapacke_sgeqrf_work.c
|
123
133
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_sgesdd.c
|
124
134
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_sgesdd_work.c
|
125
135
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_sgesvd.c
|
@@ -130,6 +140,8 @@ files:
|
|
130
140
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_sgetri_work.c
|
131
141
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_sgetrs.c
|
132
142
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_sgetrs_work.c
|
143
|
+
- ext/nmatrix_lapacke/lapacke/src/lapacke_sormqr.c
|
144
|
+
- ext/nmatrix_lapacke/lapacke/src/lapacke_sormqr_work.c
|
133
145
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_spotrf.c
|
134
146
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_spotrf_work.c
|
135
147
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_spotri.c
|
@@ -138,6 +150,8 @@ files:
|
|
138
150
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_spotrs_work.c
|
139
151
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_zgeev.c
|
140
152
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_zgeev_work.c
|
153
|
+
- ext/nmatrix_lapacke/lapacke/src/lapacke_zgeqrf.c
|
154
|
+
- ext/nmatrix_lapacke/lapacke/src/lapacke_zgeqrf_work.c
|
141
155
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_zgesdd.c
|
142
156
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_zgesdd_work.c
|
143
157
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_zgesvd.c
|
@@ -154,12 +168,16 @@ files:
|
|
154
168
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_zpotri_work.c
|
155
169
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_zpotrs.c
|
156
170
|
- ext/nmatrix_lapacke/lapacke/src/lapacke_zpotrs_work.c
|
171
|
+
- ext/nmatrix_lapacke/lapacke/src/lapacke_zunmqr.c
|
172
|
+
- ext/nmatrix_lapacke/lapacke/src/lapacke_zunmqr_work.c
|
173
|
+
- ext/nmatrix_lapacke/lapacke/utils/lapacke_c_nancheck.c
|
157
174
|
- ext/nmatrix_lapacke/lapacke/utils/lapacke_cge_nancheck.c
|
158
175
|
- ext/nmatrix_lapacke/lapacke/utils/lapacke_cge_trans.c
|
159
176
|
- ext/nmatrix_lapacke/lapacke/utils/lapacke_cpo_nancheck.c
|
160
177
|
- ext/nmatrix_lapacke/lapacke/utils/lapacke_cpo_trans.c
|
161
178
|
- ext/nmatrix_lapacke/lapacke/utils/lapacke_ctr_nancheck.c
|
162
179
|
- ext/nmatrix_lapacke/lapacke/utils/lapacke_ctr_trans.c
|
180
|
+
- ext/nmatrix_lapacke/lapacke/utils/lapacke_d_nancheck.c
|
163
181
|
- ext/nmatrix_lapacke/lapacke/utils/lapacke_dge_nancheck.c
|
164
182
|
- ext/nmatrix_lapacke/lapacke/utils/lapacke_dge_trans.c
|
165
183
|
- ext/nmatrix_lapacke/lapacke/utils/lapacke_dpo_nancheck.c
|
@@ -167,6 +185,7 @@ files:
|
|
167
185
|
- ext/nmatrix_lapacke/lapacke/utils/lapacke_dtr_nancheck.c
|
168
186
|
- ext/nmatrix_lapacke/lapacke/utils/lapacke_dtr_trans.c
|
169
187
|
- ext/nmatrix_lapacke/lapacke/utils/lapacke_lsame.c
|
188
|
+
- ext/nmatrix_lapacke/lapacke/utils/lapacke_s_nancheck.c
|
170
189
|
- ext/nmatrix_lapacke/lapacke/utils/lapacke_sge_nancheck.c
|
171
190
|
- ext/nmatrix_lapacke/lapacke/utils/lapacke_sge_trans.c
|
172
191
|
- ext/nmatrix_lapacke/lapacke/utils/lapacke_spo_nancheck.c
|
@@ -174,6 +193,7 @@ files:
|
|
174
193
|
- ext/nmatrix_lapacke/lapacke/utils/lapacke_str_nancheck.c
|
175
194
|
- ext/nmatrix_lapacke/lapacke/utils/lapacke_str_trans.c
|
176
195
|
- ext/nmatrix_lapacke/lapacke/utils/lapacke_xerbla.c
|
196
|
+
- ext/nmatrix_lapacke/lapacke/utils/lapacke_z_nancheck.c
|
177
197
|
- ext/nmatrix_lapacke/lapacke/utils/lapacke_zge_nancheck.c
|
178
198
|
- ext/nmatrix_lapacke/lapacke/utils/lapacke_zge_trans.c
|
179
199
|
- ext/nmatrix_lapacke/lapacke/utils/lapacke_zpo_nancheck.c
|
@@ -219,7 +239,7 @@ files:
|
|
219
239
|
- spec/utm5940.mtx
|
220
240
|
homepage: http://sciruby.com
|
221
241
|
licenses:
|
222
|
-
- BSD
|
242
|
+
- BSD-3-Clause
|
223
243
|
metadata: {}
|
224
244
|
post_install_message:
|
225
245
|
rdoc_options: []
|
@@ -237,7 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
257
|
version: '0'
|
238
258
|
requirements: []
|
239
259
|
rubyforge_project:
|
240
|
-
rubygems_version: 2.
|
260
|
+
rubygems_version: 2.5.1
|
241
261
|
signing_key:
|
242
262
|
specification_version: 4
|
243
263
|
summary: general LAPACK backend for nmatrix using LAPACKE interface
|
@@ -246,17 +266,27 @@ test_files:
|
|
246
266
|
- spec/01_enum_spec.rb
|
247
267
|
- spec/02_slice_spec.rb
|
248
268
|
- spec/03_nmatrix_monkeys_spec.rb
|
269
|
+
- spec/2x2_dense_double.mat
|
270
|
+
- spec/4x4_sparse.mat
|
271
|
+
- spec/4x5_dense.mat
|
249
272
|
- spec/blas_spec.rb
|
250
273
|
- spec/elementwise_spec.rb
|
251
274
|
- spec/homogeneous_spec.rb
|
252
275
|
- spec/io/fortran_format_spec.rb
|
253
276
|
- spec/io/harwell_boeing_spec.rb
|
277
|
+
- spec/io/test.rua
|
254
278
|
- spec/io_spec.rb
|
255
279
|
- spec/lapack_core_spec.rb
|
280
|
+
- spec/leakcheck.rb
|
256
281
|
- spec/math_spec.rb
|
282
|
+
- spec/nmatrix_yale_resize_test_associations.yaml
|
257
283
|
- spec/nmatrix_yale_spec.rb
|
284
|
+
- spec/rspec_monkeys.rb
|
258
285
|
- spec/rspec_spec.rb
|
259
286
|
- spec/shortcuts_spec.rb
|
260
287
|
- spec/slice_set_spec.rb
|
288
|
+
- spec/spec_helper.rb
|
261
289
|
- spec/stat_spec.rb
|
290
|
+
- spec/test.pcd
|
291
|
+
- spec/utm5940.mtx
|
262
292
|
- spec/plugins/lapacke/lapacke_spec.rb
|