File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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' }
122167PMQRTest >> testQRFactorization [
123168
You can’t perform that action at this time.
0 commit comments