Skip to content

Commit 03cf163

Browse files
committed
Wriet tests for geqrf, orgqr and potrf
1 parent 1754c32 commit 03cf163

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

test/lapack_test.rb

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ class NMatrix::LapackTest < Minitest::Test
44

55
def setup
66
@input = NMatrix.new [2,2], [2, -1, -4, 3]
7+
@matrix1 = NMatrix.new [2, 3], [4, -1, 4, 0, 7, -5]
8+
@matrix2 = NMatrix.new [3, 2], [4, -1, 4, 0, 7, -5]
9+
@matrix3 = NMatrix.new [3, 3], [1, 0, -5, 3, 5, 2, 0, -1, -1]
710
@left = NMatrix.new [2,2],[2.2, 2.2, 4, 5]
811
@right = NMatrix.new [2,2],[2, 2, 2, 2]
912
@dtypes = [:nm_float64]
@@ -43,6 +46,86 @@ def test_least_square
4346
end
4447
end
4548

49+
def test_geqrf
50+
qr, tau = NumRuby::Lapack.geqrf(@matrix1)
51+
qr_soln = NMatrix.new [2, 3], [4.0, -1.0, 4.0, 0.0, 7.0, -5.0]
52+
tau_soln = NMatrix.new [2], [0.0, 0.0]
53+
assert_equal qr, qr_soln
54+
assert_equal tau, tau_soln
55+
56+
qr, tau = NumRuby::Lapack.geqrf(@matrix2)
57+
qr_soln = NMatrix.new [3, 2], [-9.0, 4.333333, 0.307692, -2.687419, 0.538461, -0.491678]
58+
tau_soln = NMatrix.new [2], [1.444444, 1.610632]
59+
assert_equal qr, qr_soln
60+
assert_equal tau, tau_soln
61+
62+
qr, tau = NumRuby::Lapack.geqrf(@matrix3)
63+
qr_soln = NMatrix.new [3, 3], [-3.162277, -4.743416, -0.316227, 0.720759, -1.870828, -5.077963, 0.0, -0.289689, 2.028370]
64+
tau_soln = NMatrix.new [3], [1.316227, 1.845154, 0.0]
65+
assert_equal qr, qr_soln
66+
assert_equal tau, tau_soln
67+
end
68+
69+
def test_orgqr
70+
qr = NMatrix.new [3, 2], [-9.0, 4.333333, 0.307692, -2.687419, 0.538461, -0.491678]
71+
tau = NMatrix.new [2], [1.444444, 1.610632]
72+
q = NumRuby::Lapack.orgqr(qr, tau)
73+
q_soln = NMatrix.new [3, 2], [-0.444444, -0.344540, -0.444444, -0.716645, -0.777777, 0.606392]
74+
assert_equal q, q_soln
75+
end
76+
77+
def test_geqp3
78+
## doesn't give same output on each run
79+
end
80+
81+
def test_potrf
82+
matrix = NMatrix.new [3, 3], [2, -1, 0, -1, 2, -1, 0, -1, 2]
83+
84+
c = NumRuby::Lapack.potrf(matrix, true)
85+
c_soln = NMatrix.new [3, 3], [1.414213, -1.0, 0.0, -0.707106, 1.224744, -1.0, 0.0, -0.816496, 1.154700]
86+
assert_equal c, c_soln
87+
88+
c = NumRuby::Lapack.potrf(matrix, false)
89+
c_soln = NMatrix.new [3, 3], [1.414213, -0.707106, 0.0, -1.0, 1.224744, -0.816496, 0.0, -1.0, 1.154700]
90+
assert_equal c, c_soln
91+
end
92+
93+
def test_potrs
94+
95+
end
96+
97+
def test_gesdd
98+
99+
end
100+
101+
def test_getrf
102+
103+
end
104+
105+
def test_getrs
106+
107+
end
108+
109+
def test_getri
110+
111+
end
112+
113+
def test_gelss
114+
115+
end
116+
117+
def test_posv
118+
119+
end
120+
121+
def test_gesv
122+
123+
end
124+
125+
def test_lange
126+
127+
end
128+
46129
def test_pinv
47130

48131
end

0 commit comments

Comments
 (0)