@@ -483,10 +483,12 @@ PMMatrix >> elementwiseProductWithMatrix: aMatrix [
483483
484484{ #category : #' as yet unclassified' }
485485PMMatrix >> equalsTo: aMatrix [
486- self rows
487- with: aMatrix rows
488- do: [:a :b | (a equalsTo: b) ifFalse: [ ^ false ] ].
489- ^ true
486+
487+ self
488+ deprecated: ' Use closeTo: instead'
489+ transformWith: ' `@rec equalsTo: `@arg' - > ' `@rec closeTo: `@arg' .
490+
491+ ^ self closeTo: aMatrix
490492]
491493
492494{ #category : #' as yet unclassified' }
@@ -746,35 +748,50 @@ PMMatrix >> productWithVector: aVector [
746748
747749{ #category : #' as yet unclassified' }
748750PMMatrix >> qrFactorization [
749- |identMat q r hh colSize i |
750- self numberOfRows < self numberOfColumns ifTrue: [ self error: ' numberOfRows<numberOfColumns' ].
751- r := PMMatrix rows: (rows deepCopy).
751+
752+ | identMat q r hh colSize i |
753+ self numberOfRows < self numberOfColumns ifTrue: [
754+ self error: ' numberOfRows<numberOfColumns' ].
755+ r := PMMatrix rows: rows deepCopy.
752756 colSize := self numberOfRows.
753- q := PMSymmetricMatrix identity: colSize.
757+ q := PMSymmetricMatrix identity: colSize.
754758 identMat := q deepCopy.
755- 1 to: self numberOfColumns do: [:col |
759+ 1 to: self numberOfColumns do: [ :col |
756760 hh := ((r columnAt: col) copyFrom: col to: colSize) householder.
757- i := (PMVector new : col- 1withAll: 0 ) , (hh at: 2 ).
758- q := q* (identMat - ((hh at: 1 )* i tensorProduct: i ))." not really necessary, should be simplified"
759- i := PMMatrix rows: ( (r rows allButFirst: (col - 1 )) collect: [:aRow | aRow allButFirst: (col - 1 )] ).
760- i := i - ((hh at: 2 ) tensorProduct: ( (hh at: 1 )* (hh at: 2 )* i ) ) .
761- i rows withIndexDo: [ :aRow :index |
762- aRow withIndexDo: [ :n :c | r rowAt: (col + index - 1 ) columnAt: (col + c - 1 ) put: ((n equalsTo: 0 ) ifTrue: [0 ] ifFalse: [n] ) ] ] .
763- " 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" ].
764- " r rows allButFirst withIndexDo: [:aRow :ri|1 to: (ri min: self numberOfColumns ) do: [:ci|aRow at: ci put:0 ] ] " " not necessary with equalsTo:0"
765- i := 0 .
766- [(r rowAt: colSize) allSatisfy: [:n | n= 0 ] ]whileTrue: [i := i+ 1 .colSize := colSize - 1 ].
767- i> 0 ifTrue: [ r := PMMatrix rows: (r rows copyFrom: 1 to: colSize).
768- i := q numberOfColumns - i.
769- q := PMMatrix rows: ( q rows collect: [:row | row copyFrom: 1 to: i]) ].
770- ^ Array with: q with: r
761+ i := (PMVector new : col - 1 withAll: 0 ) , (hh at: 2 ).
762+ q := q * (identMat - ((hh at: 1 ) * i tensorProduct: i)). " not really necessary, should be simplified"
763+ i := PMMatrix rows:
764+ ((r rows allButFirst: col - 1 ) collect: [ :aRow |
765+ aRow allButFirst: col - 1 ]).
766+ i := i - ((hh at: 2 ) tensorProduct: (hh at: 1 ) * (hh at: 2 ) * i).
767+ i rows withIndexDo: [ :aRow :index |
768+ aRow withIndexDo: [ :n :c |
769+ r
770+ rowAt: col + index - 1
771+ columnAt: col + c - 1
772+ put: ((n closeTo: 0 )
773+ ifTrue: [ 0 ]
774+ ifFalse: [ n ]) ] ]
775+ " 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" ].
776+ " r rows allButFirst withIndexDo: [:aRow :ri|1 to: (ri min: self numberOfColumns ) do: [:ci|aRow at: ci put:0 ] ] " " not necessary with equalsTo:0"
777+ i := 0 .
778+ [ (r rowAt: colSize) allSatisfy: [ :n | n = 0 ] ] whileTrue: [
779+ i := i + 1 .
780+ colSize := colSize - 1 ].
781+ i > 0 ifTrue: [
782+ r := PMMatrix rows: (r rows copyFrom: 1 to: colSize).
783+ i := q numberOfColumns - i.
784+ q := PMMatrix rows:
785+ (q rows collect: [ :row | row copyFrom: 1 to: i ]) ].
786+ ^ Array with: q with: r
771787]
772788
773789{ #category : #' as yet unclassified' }
774790PMMatrix >> qrFactorizationWithPivoting [
791+
775792 | identMat q r hh colSize i lengthArray rank mx pivot |
776- self numberOfRows < self numberOfColumns
777- ifTrue: [ self error: ' numberOfRows<numberOfColumns' ].
793+ self numberOfRows < self numberOfColumns ifTrue: [
794+ self error: ' numberOfRows<numberOfColumns' ].
778795 lengthArray := self columnsCollect: [ :col | col * col ].
779796 mx := lengthArray indexOf: lengthArray max.
780797 pivot := Array new : lengthArray size.
@@ -791,41 +808,41 @@ PMMatrix >> qrFactorizationWithPivoting [
791808 hh := ((r columnAt: rank) copyFrom: rank to: colSize) householder.
792809 i := (PMVector new : rank - 1 withAll: 0 ) , (hh at: 2 ).
793810 q := q * (identMat - ((hh at: 1 ) * i tensorProduct: i)).
794- i := PMMatrix rows: ((r rows allButFirst: rank - 1 ) collect: [ :aRow | aRow allButFirst: rank - 1 ]).
811+ i := PMMatrix rows:
812+ ((r rows allButFirst: rank - 1 ) collect: [ :aRow |
813+ aRow allButFirst: rank - 1 ]).
795814 i := i - ((hh at: 2 ) tensorProduct: (hh at: 1 ) * (hh at: 2 ) * i).
796- i rows
797- withIndexDo: [ :aRow :index |
798- aRow
799- withIndexDo: [ :n :c |
800- r
801- rowAt: rank + index - 1
802- columnAt: rank + c - 1
803- put:
804- ((n equalsTo: 0 )
805- ifTrue: [ 0 ]
806- ifFalse: [ n ]) ] ].
807- rank + 1 to: lengthArray size do: [ :ind | lengthArray at: ind put: (lengthArray at: ind) - (r rowAt: rank columnAt: ind) squared ].
815+ i rows withIndexDo: [ :aRow :index |
816+ aRow withIndexDo: [ :n :c |
817+ r
818+ rowAt: rank + index - 1
819+ columnAt: rank + c - 1
820+ put: ((n closeTo: 0 )
821+ ifTrue: [ 0 ]
822+ ifFalse: [ n ]) ] ].
823+ rank + 1 to: lengthArray size do: [ :ind |
824+ lengthArray
825+ at: ind
826+ put: (lengthArray at: ind) - (r rowAt: rank columnAt: ind) squared ].
808827 rank < lengthArray size
809828 ifTrue: [
810829 mx := (lengthArray copyFrom: rank + 1 to: lengthArray size) max.
811- (mx equalsTo: 0 )
812- ifTrue: [ mx := 0 ].
830+ (mx closeTo: 0 ) ifTrue: [ mx := 0 ].
813831 mx := mx > 0
814- ifTrue: [ lengthArray indexOf: mx startingAt: rank + 1 ]
815- ifFalse: [ 0 ] ]
832+ ifTrue: [ lengthArray indexOf: mx startingAt: rank + 1 ]
833+ ifFalse: [ 0 ] ]
816834 ifFalse: [ mx := 0 ].
817835 mx > 0 ] whileTrue.
818836 i := 0 .
819- [ (r rowAt: colSize) allSatisfy: [ :n | n = 0 ] ]
820- whileTrue: [
821- i := i + 1 .
822- colSize := colSize - 1 ].
823- i > 0
824- ifTrue: [
825- r := PMMatrix rows: (r rows copyFrom: 1 to: colSize).
826- i := q numberOfColumns - i.
827- pivot := pivot copyFrom: 1 to: i.
828- q := PMMatrix rows: (q rows collect: [ :row | row copyFrom: 1 to: i ]) ].
837+ [ (r rowAt: colSize) allSatisfy: [ :n | n = 0 ] ] whileTrue: [
838+ i := i + 1 .
839+ colSize := colSize - 1 ].
840+ i > 0 ifTrue: [
841+ r := PMMatrix rows: (r rows copyFrom: 1 to: colSize).
842+ i := q numberOfColumns - i.
843+ pivot := pivot copyFrom: 1 to: i.
844+ q := PMMatrix rows:
845+ (q rows collect: [ :row | row copyFrom: 1 to: i ]) ].
829846 ^ Array with: q with: r with: pivot
830847]
831848
0 commit comments