Skip to content

Commit 1bd0578

Browse files
Extracted a key computation step to an intention-revealing method.
1 parent bc7c95d commit 1bd0578

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/Math-Matrix/PMQRDecomposition.class.st

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ that describes the mechanics:
2929
https://en.wikipedia.org/wiki/QR_decomposition#Using_Householder_reflections
3030
"
3131

32-
| i matrixOfMinor |
32+
| i matrixOfMinor householderReflection |
3333
1 to: self numberOfColumns do: [ :col |
34-
| householderVector householderMatrix columnVectorFromRMatrix identityMatrix v |
34+
| householderVector householderMatrix columnVectorFromRMatrix |
3535
columnVectorFromRMatrix := r columnVectorAt: col size: colSize.
36-
householderVector := columnVectorFromRMatrix householder.
37-
v := (PMVector zeros: col - 1) , (householderVector at: 2).
38-
identityMatrix := PMSymmetricMatrix identity: colSize.
39-
householderMatrix := identityMatrix
40-
-
41-
((householderVector at: 1) * v tensorProduct: v).
36+
householderReflection := self
37+
householderReflectionOf:
38+
columnVectorFromRMatrix
39+
atColumnNumber: col.
40+
householderVector := householderReflection at: 1.
41+
householderMatrix := householderReflection at: 2.
4242
q := q * householderMatrix.
4343
matrixOfMinor := r minor: col - 1 and: col - 1.
4444
matrixOfMinor := matrixOfMinor
@@ -138,6 +138,19 @@ PMQRDecomposition >> decomposeWithPivot [
138138
^ Array with: q with: r with: pivot
139139
]
140140

141+
{ #category : #private }
142+
PMQRDecomposition >> householderReflectionOf: columnVector atColumnNumber: columnNumber [
143+
144+
| householderVector v identityMatrix householderMatrix |
145+
householderVector := columnVector householder.
146+
v := (PMVector zeros: columnNumber - 1) , (householderVector at: 2).
147+
identityMatrix := PMSymmetricMatrix identity: colSize.
148+
householderMatrix := identityMatrix
149+
-
150+
((householderVector at: 1) * v tensorProduct: v).
151+
^ Array with: householderVector with: householderMatrix .
152+
]
153+
141154
{ #category : #private }
142155
PMQRDecomposition >> initialQMatrix [
143156

0 commit comments

Comments
 (0)