Skip to content

Commit cd53694

Browse files
committed
add identity matrix instance creation for PMMatrix
1 parent 86d6f02 commit cd53694

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

src/Math-Matrix/PMMatrix.class.st

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ a tr.
6767
"15"
6868
]
6969

70+
{ #category : #'instance creation' }
71+
PMMatrix class >> identity: anInteger [
72+
^ PMSymmetricMatrix identity: anInteger
73+
]
74+
7075
{ #category : #'instance creation' }
7176
PMMatrix class >> join: anArrayOfMatrices [
7277
"Inverse of the split operation."

src/Math-Tests-Matrix/PMMatrixTest.class.st

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,20 @@ PMMatrixTest >> testFlattenRows [
197197
self assert: m flattenRows equals: #(1 2 3 4 5 6 7 8 9) asPMVector
198198
]
199199

200+
{ #category : #tests }
201+
PMMatrixTest >> testIdentityMatrix [
202+
|a a2|
203+
204+
a := PMMatrix zerosRows: 3 cols: 3.
205+
206+
a at: 1 at: 1 put: 1.
207+
a at: 2 at: 2 put: 1.
208+
a at: 3 at: 3 put: 1.
209+
210+
a2 := PMMatrix identity: 3.
211+
self assert: a2 equals: a.
212+
]
213+
200214
{ #category : #tests }
201215
PMMatrixTest >> testIsRealOnComplexMatrix [
202216
| matrix |

src/Math-Tests-Matrix/PMSymmetricMatrixTest.class.st

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Class {
22
#name : #PMSymmetricMatrixTest,
33
#superclass : #TestCase,
4-
#category : 'Math-Tests-Matrix'
4+
#category : #'Math-Tests-Matrix'
55
}
66

77
{ #category : #tests }
@@ -38,6 +38,16 @@ PMSymmetricMatrixTest >> testEqual [
3838
self assert: b ~= a
3939
]
4040

41+
{ #category : #tests }
42+
PMSymmetricMatrixTest >> testIdentityMatrix [
43+
|a a1|
44+
45+
a := PMSymmetricMatrix identity: 3.
46+
a1 := PMSymmetricMatrix rows: #(#(1 0 0) #(0 1 0) #(0 0 1)).
47+
48+
self assert: a equals: a1.
49+
]
50+
4151
{ #category : #tests }
4252
PMSymmetricMatrixTest >> testInversePureLUP [
4353
| m i |

0 commit comments

Comments
 (0)