@@ -485,10 +485,12 @@ PMMatrix >> elementwiseProductWithMatrix: aMatrix [
485485
486486{ #category : #' as yet unclassified' }
487487PMMatrix >> equalsTo: aMatrix [
488- self rows
489- with: aMatrix rows
490- do: [:a :b | (a equalsTo: b) ifFalse: [ ^ false ] ].
491- ^ true
488+
489+ self
490+ deprecated: ' Use closeTo: instead'
491+ transformWith: ' `@rec equalsTo: `@arg' - > ' `@rec closeTo: `@arg' .
492+
493+ ^ self closeTo: aMatrix
492494]
493495
494496{ #category : #' as yet unclassified' }
@@ -748,35 +750,50 @@ PMMatrix >> productWithVector: aVector [
748750
749751{ #category : #' as yet unclassified' }
750752PMMatrix >> qrFactorization [
751- |identMat q r hh colSize i |
752- self numberOfRows < self numberOfColumns ifTrue: [ self error: ' numberOfRows<numberOfColumns' ].
753- r := PMMatrix rows: (rows deepCopy).
753+
754+ | identMat q r hh colSize i |
755+ self numberOfRows < self numberOfColumns ifTrue: [
756+ self error: ' numberOfRows<numberOfColumns' ].
757+ r := PMMatrix rows: rows deepCopy.
754758 colSize := self numberOfRows.
755- q := PMSymmetricMatrix identity: colSize.
759+ q := PMSymmetricMatrix identity: colSize.
756760 identMat := q deepCopy.
757- 1 to: self numberOfColumns do: [:col |
761+ 1 to: self numberOfColumns do: [ :col |
758762 hh := ((r columnAt: col) copyFrom: col to: colSize) householder.
759- i := (PMVector new : col- 1withAll: 0 ) , (hh at: 2 ).
760- q := q* (identMat - ((hh at: 1 )* i tensorProduct: i ))." not really necessary, should be simplified"
761- i := PMMatrix rows: ( (r rows allButFirst: (col - 1 )) collect: [:aRow | aRow allButFirst: (col - 1 )] ).
762- i := i - ((hh at: 2 ) tensorProduct: ( (hh at: 1 )* (hh at: 2 )* i ) ) .
763- i rows withIndexDo: [ :aRow :index |
764- aRow withIndexDo: [ :n :c | r rowAt: (col + index - 1 ) columnAt: (col + c - 1 ) put: ((n equalsTo: 0 ) ifTrue: [0 ] ifFalse: [n] ) ] ] .
765- " col <colSize ifTrue: [i :=(hh at: 2) copyFrom: 2 to: colSize -col +1. i withIndexDo: [:n :index| r rowAt: col columnAt: index put: n ] ]" " and this part is not correct, dont uncomment before the bug is corrected! useful if q is not explicitely necessary" ].
766- " r rows allButFirst withIndexDo: [:aRow :ri|1 to: (ri min: self numberOfColumns ) do: [:ci|aRow at: ci put:0 ] ] " " not necessary with equalsTo:0"
767- i := 0 .
768- [(r rowAt: colSize) allSatisfy: [:n | n= 0 ] ]whileTrue: [i := i+ 1 .colSize := colSize - 1 ].
769- i> 0 ifTrue: [ r := PMMatrix rows: (r rows copyFrom: 1 to: colSize).
770- i := q numberOfColumns - i.
771- q := PMMatrix rows: ( q rows collect: [:row | row copyFrom: 1 to: i]) ].
772- ^ Array with: q with: r
763+ i := (PMVector new : col - 1 withAll: 0 ) , (hh at: 2 ).
764+ q := q * (identMat - ((hh at: 1 ) * i tensorProduct: i)). " not really necessary, should be simplified"
765+ i := PMMatrix rows:
766+ ((r rows allButFirst: col - 1 ) collect: [ :aRow |
767+ aRow allButFirst: col - 1 ]).
768+ i := i - ((hh at: 2 ) tensorProduct: (hh at: 1 ) * (hh at: 2 ) * i).
769+ i rows withIndexDo: [ :aRow :index |
770+ aRow withIndexDo: [ :n :c |
771+ r
772+ rowAt: col + index - 1
773+ columnAt: col + c - 1
774+ put: ((n closeTo: 0 )
775+ ifTrue: [ 0 ]
776+ ifFalse: [ n ]) ] ]
777+ " col <colSize ifTrue: [i :=(hh at: 2) copyFrom: 2 to: colSize -col +1. i withIndexDo: [:n :index| r rowAt: col columnAt: index put: n ] ]" " and this part is not correct, dont uncomment before the bug is corrected! useful if q is not explicitely necessary" ].
778+ " r rows allButFirst withIndexDo: [:aRow :ri|1 to: (ri min: self numberOfColumns ) do: [:ci|aRow at: ci put:0 ] ] " " not necessary with equalsTo:0"
779+ i := 0 .
780+ [ (r rowAt: colSize) allSatisfy: [ :n | n = 0 ] ] whileTrue: [
781+ i := i + 1 .
782+ colSize := colSize - 1 ].
783+ i > 0 ifTrue: [
784+ r := PMMatrix rows: (r rows copyFrom: 1 to: colSize).
785+ i := q numberOfColumns - i.
786+ q := PMMatrix rows:
787+ (q rows collect: [ :row | row copyFrom: 1 to: i ]) ].
788+ ^ Array with: q with: r
773789]
774790
775791{ #category : #' as yet unclassified' }
776792PMMatrix >> qrFactorizationWithPivoting [
793+
777794 | identMat q r hh colSize i lengthArray rank mx pivot |
778- self numberOfRows < self numberOfColumns
779- ifTrue: [ self error: ' numberOfRows<numberOfColumns' ].
795+ self numberOfRows < self numberOfColumns ifTrue: [
796+ self error: ' numberOfRows<numberOfColumns' ].
780797 lengthArray := self columnsCollect: [ :col | col * col ].
781798 mx := lengthArray indexOf: lengthArray max.
782799 pivot := Array new : lengthArray size.
@@ -793,41 +810,41 @@ PMMatrix >> qrFactorizationWithPivoting [
793810 hh := ((r columnAt: rank) copyFrom: rank to: colSize) householder.
794811 i := (PMVector new : rank - 1 withAll: 0 ) , (hh at: 2 ).
795812 q := q * (identMat - ((hh at: 1 ) * i tensorProduct: i)).
796- i := PMMatrix rows: ((r rows allButFirst: rank - 1 ) collect: [ :aRow | aRow allButFirst: rank - 1 ]).
813+ i := PMMatrix rows:
814+ ((r rows allButFirst: rank - 1 ) collect: [ :aRow |
815+ aRow allButFirst: rank - 1 ]).
797816 i := i - ((hh at: 2 ) tensorProduct: (hh at: 1 ) * (hh at: 2 ) * i).
798- i rows
799- withIndexDo: [ :aRow :index |
800- aRow
801- withIndexDo: [ :n :c |
802- r
803- rowAt: rank + index - 1
804- columnAt: rank + c - 1
805- put:
806- ((n equalsTo: 0 )
807- ifTrue: [ 0 ]
808- ifFalse: [ n ]) ] ].
809- rank + 1 to: lengthArray size do: [ :ind | lengthArray at: ind put: (lengthArray at: ind) - (r rowAt: rank columnAt: ind) squared ].
817+ i rows withIndexDo: [ :aRow :index |
818+ aRow withIndexDo: [ :n :c |
819+ r
820+ rowAt: rank + index - 1
821+ columnAt: rank + c - 1
822+ put: ((n closeTo: 0 )
823+ ifTrue: [ 0 ]
824+ ifFalse: [ n ]) ] ].
825+ rank + 1 to: lengthArray size do: [ :ind |
826+ lengthArray
827+ at: ind
828+ put: (lengthArray at: ind) - (r rowAt: rank columnAt: ind) squared ].
810829 rank < lengthArray size
811830 ifTrue: [
812831 mx := (lengthArray copyFrom: rank + 1 to: lengthArray size) max.
813- (mx equalsTo: 0 )
814- ifTrue: [ mx := 0 ].
832+ (mx closeTo: 0 ) ifTrue: [ mx := 0 ].
815833 mx := mx > 0
816- ifTrue: [ lengthArray indexOf: mx startingAt: rank + 1 ]
817- ifFalse: [ 0 ] ]
834+ ifTrue: [ lengthArray indexOf: mx startingAt: rank + 1 ]
835+ ifFalse: [ 0 ] ]
818836 ifFalse: [ mx := 0 ].
819837 mx > 0 ] whileTrue.
820838 i := 0 .
821- [ (r rowAt: colSize) allSatisfy: [ :n | n = 0 ] ]
822- whileTrue: [
823- i := i + 1 .
824- colSize := colSize - 1 ].
825- i > 0
826- ifTrue: [
827- r := PMMatrix rows: (r rows copyFrom: 1 to: colSize).
828- i := q numberOfColumns - i.
829- pivot := pivot copyFrom: 1 to: i.
830- q := PMMatrix rows: (q rows collect: [ :row | row copyFrom: 1 to: i ]) ].
839+ [ (r rowAt: colSize) allSatisfy: [ :n | n = 0 ] ] whileTrue: [
840+ i := i + 1 .
841+ colSize := colSize - 1 ].
842+ i > 0 ifTrue: [
843+ r := PMMatrix rows: (r rows copyFrom: 1 to: colSize).
844+ i := q numberOfColumns - i.
845+ pivot := pivot copyFrom: 1 to: i.
846+ q := PMMatrix rows:
847+ (q rows collect: [ :row | row copyFrom: 1 to: i ]) ].
831848 ^ Array with: q with: r with: pivot
832849]
833850
0 commit comments