Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/AI-LinearAlgebra-Tests/AIDiagonalMatrixTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,18 @@ AIDiagonalMatrixTest >> testDimension [
self assert: m columnSize equals: 5.

]

{ #category : #tests }
AIDiagonalMatrixTest >> testproductFromDiagonalMatrix [


| aDiagonalMatrix aRowMatrix|
aDiagonalMatrix := AIDiagonalMatrix withDiagonal: #(1 2).
aRowMatrix := AIRowMatrix new rows: #( #(5 3) #(3 2)).
aDiagonalMatrix := aDiagonalMatrix * aRowMatrix.
self assert: (aDiagonalMatrix at: 1 and: 1) equals: 5.
self assert: (aDiagonalMatrix at: 1 and: 2) equals: 0.
self assert: (aDiagonalMatrix at: 2 and: 1) equals: 0.
self assert: (aDiagonalMatrix at: 2 and: 2) equals: 4.

]
8 changes: 8 additions & 0 deletions src/AI-LinearAlgebra/AIDiagonalMatrix.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ AIDiagonalMatrix class >> withDiagonal: vector [
^newMatrix
]

{ #category : #arithmetic }
AIDiagonalMatrix >> * aMatrixOrNumber [



^ aMatrixOrNumber productFromDiagonalMatrix: self.
]

{ #category : #accessing }
AIDiagonalMatrix >> at: row and: column [

Expand Down
9 changes: 9 additions & 0 deletions src/AI-LinearAlgebra/AIMatrix.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,15 @@ AIMatrix >> printOn: aStream [
aStream nextPut: $)
]

{ #category : #'double dispatching' }
AIMatrix >> productFromDiagonalMatrix: aDiagonalMatrix [

1 to: aDiagonalMatrix rowSize do: [:i|
aDiagonalMatrix at: i and: i put: (aDiagonalMatrix at:i and: i)*(self at: i and: i ) ].

^aDiagonalMatrix
]

{ #category : #'double dispatching' }
AIMatrix >> productFromDouble: aNumber [

Expand Down