Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
Merged
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
43 changes: 43 additions & 0 deletions src/Math-Matrix/PMMatrix.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,22 @@ PMMatrix class >> rows: anArrayOrVector [
^ self new initializeRows: anArrayOrVector
]

{ #category : #'instance creation' }
PMMatrix class >> rows: rowsInteger columns: columnsInteger [

^ self new initializeRows: rowsInteger columns: columnsInteger
]

{ #category : #'instance creation' }
PMMatrix class >> rows: nRows columns: nCols element: fillElement [
" Answer a new matrix of nRows x nCols initialized with fillElement in all cells "

^ (self new initializeRows: nRows columns: nCols)
atAllPut: fillElement;
yourself

]

{ #category : #'as yet unclassified' }
PMMatrix class >> rows: rows columns: columns random: aMaxNumber [
"Answer a new Matrix of the given dimensions filled with random numbers"
Expand Down Expand Up @@ -231,6 +247,13 @@ PMMatrix >> at: rowIndex at: columnIndex put: value [

]

{ #category : #'cell accessing' }
PMMatrix >> atAllPut: element [
"Put element at every one of the receiver's cells."

self rowsDo: [ : row | row atAllPut: element ]
]

{ #category : #'cell accessing' }
PMMatrix >> atColumn: anInteger [

Expand All @@ -246,6 +269,19 @@ PMMatrix >> atColumn: aColumnIndex put: aCollection [

]

{ #category : #'cell accessing' }
PMMatrix >> atColumn: columnIndex put: aValue repeat: repNumber [
" Example: self atColumn: 1 fillWith: 'BM1818' repeat: 3
produces
[ 'BM1818' nil nil nil
'BM1818' nil nil nil
'BM1818' nil nil nil
nil nil nil nil
nil nil nil nil ]
"
1 to: repNumber do: [ : index | self rowAt: index columnAt: columnIndex put: aValue ].
]

{ #category : #'cell accessing' }
PMMatrix >> atColumn: aColumnNumber put: aCollection startingAt: rowNumber [
" Fill the receiver with aCollection at aColumnNumber begining at rowNumber. "
Expand Down Expand Up @@ -415,6 +451,13 @@ PMMatrix >> initializeRows: anArrayOrVector [
rows := anArrayOrVector asPMVector collect: [ :each | each asPMVector].
]

{ #category : #initialization }
PMMatrix >> initializeRows: rowsInteger columns: columnsInteger [
"Build empty components for a matrix."

rows := (1 to: rowsInteger) asPMVector collect: [ :each | PMVector new: columnsInteger ].
]

{ #category : #operation }
PMMatrix >> inverse [
"Answer the inverse of the receiver."
Expand Down
45 changes: 45 additions & 0 deletions src/Math-Tests-Matrix/PMMatrixTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@ Class {
#category : 'Math-Tests-Matrix'
}

{ #category : #tests }
PMMatrixTest >> testAtAllPut [

| a |
a := PMMatrix new: 3.
a atAllPut: 4.
self assert: a equals: (PMMatrix rows: #(#(4 4 4) #(4 4 4) #(4 4 4))).

]

{ #category : #tests }
PMMatrixTest >> testAtColumnPutRepeat [

| a |
a := PMMatrix new: 3.
a
atColumn: 1 put: 1 repeat: 3;
atColumn: 2 put: 2 repeat: 3;
atColumn: 3 put: 3 repeat: 3.
self assert: a equals: (PMMatrix rows: #(#(1 2 3) #(1 2 3) #(1 2 3))).
a := PMMatrix new: 3.
a
atColumn: 1 put: 1 repeat: 2.
self assert: a equals: (PMMatrix rows: #(#(1 nil nil) #(1 nil nil) #(nil nil nil))).
]

{ #category : #'linear algebra' }
PMMatrixTest >> testAtRowPutAtColumnPut [
| a |
Expand Down Expand Up @@ -432,6 +458,25 @@ PMMatrixTest >> testPrintOn [
self shouldnt: [m printOn: stream] raise: Error
]

{ #category : #comparing }
PMMatrixTest >> testRowsColumns [
| a |

a := PMMatrix rows: 3 columns: 4.
self assert: a dimension equals: 3 @ 4.
]

{ #category : #tests }
PMMatrixTest >> testRowsColumnsElement [

| a |

a := PMMatrix rows: 3 columns: 4 element: 1.
self assert: a dimension equals: 3 @ 4.
self assert: a equals: (PMMatrix rows: #(#(1 1 1 1) #(1 1 1 1) #(1 1 1 1)))

]

{ #category : #tests }
PMMatrixTest >> testSimpleMatrixOperations [
| s m s2 r r2 |
Expand Down