Skip to content

Commit 95f6f9a

Browse files
authored
Merge pull request #291 from jecisc/move-matrix-metds-from-Core-to-Matrix
Move matrix metods from core to matrix
2 parents be4dc1e + eb3d2c2 commit 95f6f9a

File tree

6 files changed

+51
-46
lines changed

6 files changed

+51
-46
lines changed

src/Math-Core/Number.extension.st

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
Extension { #name : #Number }
22

3-
{ #category : #'*Math-Core' }
4-
Number >> addWithRegularMatrix: aMatrix [
5-
"Adds itself to every row of the matrix"
6-
^ PMMatrix rows: (aMatrix rowsCollect: [ :row | row + self ])
7-
]
8-
93
{ #category : #'*Math-Core' }
104
Number >> addWithVector: aVector [
115
"Adds itself to each element of the vector"

src/Math-Core/PMVector.class.st

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,6 @@ PMVector >> normalized [
253253
^ (1 / self norm) * self
254254
]
255255

256-
{ #category : #operation }
257-
PMVector >> productWithMatrix: aMatrix [
258-
"Answers the product of aMatrix with the receiver."
259-
^aMatrix rowsCollect: [ :each | each * self]
260-
]
261-
262256
{ #category : #operation }
263257
PMVector >> productWithVector: aVector [
264258
"Answers the scalar product of aVector with the receiver."
@@ -268,17 +262,6 @@ PMVector >> productWithVector: aVector [
268262
into: [ :sum :each | n := n + 1. (aVector at: n) * each + sum]
269263
]
270264

271-
{ #category : #'as yet unclassified' }
272-
PMVector >> reshapeWithDimensions: dimensionArray [
273-
| computedRows rowNum colNum |
274-
self checkDimensionalCompatibility: dimensionArray.
275-
rowNum := dimensionArray at: 1.
276-
colNum := dimensionArray at: 2.
277-
computedRows := ((1 to: rowNum) collect: [ :i | (1 to: colNum) collect: [ :j | self at: (i-1*colNum)+j ] ]).
278-
279-
^PMMatrix rows: computedRows
280-
]
281-
282265
{ #category : #operation }
283266
PMVector >> scalarProduct: aVector [
284267

src/Math-Matrix/Number.extension.st

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
Extension { #name : #Number }
22

3+
{ #category : #'*Math-Matrix' }
4+
Number >> addWithRegularMatrix: aMatrix [
5+
"Adds itself to every row of the matrix"
6+
^ PMMatrix rows: (aMatrix rowsCollect: [ :row | row + self ])
7+
]
8+
39
{ #category : #'*Math-Matrix' }
410
Number >> productWithMatrix: aMatrix [
511
^aMatrix class rows: (aMatrix rowsCollect: [:r| self productWithVector: r])

src/Math-Matrix/PMVector.extension.st

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
Extension { #name : #PMVector }
22

3+
{ #category : #'*Math-Matrix' }
4+
PMVector >> productWithMatrix: aMatrix [
5+
6+
"Answers the product of aMatrix with the receiver."
7+
8+
^ aMatrix rowsCollect: [ :each | each * self ]
9+
]
10+
11+
{ #category : #'*Math-Matrix' }
12+
PMVector >> reshapeWithDimensions: dimensionArray [
13+
14+
| computedRows rowNum colNum |
15+
self checkDimensionalCompatibility: dimensionArray.
16+
rowNum := dimensionArray at: 1.
17+
colNum := dimensionArray at: 2.
18+
computedRows := (1 to: rowNum) collect: [ :i | (1 to: colNum) collect: [ :j | self at: i - 1 * colNum + j ] ].
19+
20+
^ PMMatrix rows: computedRows
21+
]
22+
323
{ #category : #'*Math-Matrix' }
424
PMVector >> tensorProduct: aVector [
525
"Answers the tensor product of the receiver with aVector."

src/Math-Tests-Core/PMVectorTest.class.st

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,6 @@ PMVectorTest >> testLessThan [
108108
self assert: vec equals: vecCopy asPMVector.
109109
]
110110

111-
{ #category : #tests }
112-
PMVectorTest >> testMatrixConversionWithBothDims [
113-
| vect result expected |
114-
vect := #(1 0.5 0.2 3 1 -1 7 3 2 12 13 3) asPMVector .
115-
result := vect reshapeWithDimensions: #(6 2).
116-
117-
expected := PMMatrix rows: #(#(1 0.5) #(0.2 3) #(1 -1) #(7 3) #(2 12) #(13 3)).
118-
119-
self assert: result equals: expected.
120-
]
121-
122111
{ #category : #tests }
123112
PMVectorTest >> testScalarProduct [
124113
| u v |
@@ -375,17 +364,6 @@ PMVectorTest >> testVectorSum [
375364
self assert: (u sum) equals: 6.
376365
]
377366

378-
{ #category : #tests }
379-
PMVectorTest >> testVectorToVectorConversion [
380-
| vect result expected |
381-
vect := #(1 0.5 0.2 3 1 -1 7 3 2 12 13 3) asPMVector .
382-
result := vect reshapeWithDimensions: #(1 12).
383-
384-
expected := PMMatrix rows: #(#(1 0.5 0.2 3 1 -1 7 3 2 12 13 3)).
385-
386-
self assert: result equals: expected.
387-
]
388-
389367
{ #category : #tests }
390368
PMVectorTest >> testVectorZeros [
391369
| v |

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,18 @@ PMMatrixTest >> testMatrixCloseToPrecision [
383383
self deny: (a closeTo: b precision: 0.2)
384384
]
385385

386+
{ #category : #tests }
387+
PMMatrixTest >> testMatrixConversionWithBothDims [
388+
389+
| vect result expected |
390+
vect := #( 1 0.5 0.2 3 1 -1 7 3 2 12 13 3 ) asPMVector.
391+
result := vect reshapeWithDimensions: #( 6 2 ).
392+
393+
expected := PMMatrix rows: #( #( 1 0.5 ) #( 0.2 3 ) #( 1 -1 ) #( 7 3 ) #( 2 12 ) #( 13 3 ) ).
394+
395+
self assert: result equals: expected
396+
]
397+
386398
{ #category : #comparing }
387399
PMMatrixTest >> testMatrixCos [
388400
| a |
@@ -930,7 +942,7 @@ PMMatrixTest >> testSymmetricMatrixAdd3 [
930942
self assert: ((c rowAt: 3) at: 1) equals: 31
931943
]
932944

933-
{ #category : #test }
945+
{ #category : #tests }
934946
PMMatrixTest >> testTake [
935947

936948
| m expected |
@@ -967,6 +979,18 @@ PMMatrixTest >> testVectorMatrixOperation [
967979
self assert: (v at: 2) equals: 4
968980
]
969981

982+
{ #category : #tests }
983+
PMMatrixTest >> testVectorToVectorConversion [
984+
985+
| vect result expected |
986+
vect := #( 1 0.5 0.2 3 1 -1 7 3 2 12 13 3 ) asPMVector.
987+
result := vect reshapeWithDimensions: #( 1 12 ).
988+
989+
expected := PMMatrix rows: #( #( 1 0.5 0.2 3 1 -1 7 3 2 12 13 3 ) ).
990+
991+
self assert: result equals: expected
992+
]
993+
970994
{ #category : #'linear algebra' }
971995
PMMatrixTest >> testVectorTransposeMatrixOperation [
972996
"Code Example 8.1"

0 commit comments

Comments
 (0)