Skip to content

Commit 6a58d2d

Browse files
committed
added more tests
1 parent cf2b92d commit 6a58d2d

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

src/Math-Matrix-Tests/PMQRTest.class.st

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,51 @@ PMQRTest >> testOrthogonalize [
118118
i < 10 ] whileTrue
119119
]
120120

121+
{ #category : 'tests' }
122+
PMQRTest >> testQRDecompositionOnRankDeficientMatrix [
123+
124+
| a qrDecomposition reconstruction |
125+
a := PMMatrix rows: {
126+
{ 1. 2. 3 }.
127+
{ 4. 5. 6 }.
128+
{ 7. 8. 9 } }.
129+
130+
qrDecomposition := PMQRDecomposition of: a.
131+
qrDecomposition decompose.
132+
133+
self assert: qrDecomposition q rank equals: a rank.
134+
self assert: qrDecomposition r rank equals: a rank.
135+
136+
reconstruction := qrDecomposition q * qrDecomposition r.
137+
self assert: reconstruction closeTo: a
138+
]
139+
140+
{ #category : 'tests' }
141+
PMQRTest >> testQRDecompositionWithPivotOnRankDeficientMatrix [
142+
143+
| a qrDecomposition expectedQR expectedPivot reconstruction |
144+
a := PMMatrix rows: {
145+
{ 1. 2. 3 }.
146+
{ 4. 5. 6 }.
147+
{ 7. 8. 9 } }.
148+
expectedQR := PMMatrix rows: {
149+
{ 3. 1. 2 }.
150+
{ 6. 4. 5 }.
151+
{ 9. 7. 8 } }.
152+
expectedPivot := #( 3 1 2 ).
153+
154+
qrDecomposition := PMQRDecomposition of: a.
155+
qrDecomposition decomposeWithPivot.
156+
157+
self assert: qrDecomposition q rank equals: a rank.
158+
self assert: qrDecomposition r rank equals: a rank.
159+
self assert: qrDecomposition q * qrDecomposition r closeTo: expectedQR.
160+
self assert: qrDecomposition pivot equals: expectedPivot.
161+
162+
reconstruction := qrDecomposition q * qrDecomposition r * qrDecomposition permutationMatrixFromPivot inverse.
163+
self assert: reconstruction closeTo: a
164+
]
165+
121166
{ #category : 'tests' }
122167
PMQRTest >> testQRFactorization [
123168

0 commit comments

Comments
 (0)