Skip to content

Commit 6733ef2

Browse files
committed
Remove dependency of Math-Core to Math-Matrix to cut circular dependency
1 parent be4dc1e commit 6733ef2

File tree

7 files changed

+53
-40
lines changed

7 files changed

+53
-40
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 & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -268,17 +268,6 @@ PMVector >> productWithVector: aVector [
268268
into: [ :sum :each | n := n + 1. (aVector at: n) * each + sum]
269269
]
270270

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-
282271
{ #category : #operation }
283272
PMVector >> scalarProduct: aVector [
284273

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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
Extension { #name : #PMVector }
22

3+
{ #category : #'*Math-Matrix' }
4+
PMVector >> reshapeWithDimensions: dimensionArray [
5+
6+
| computedRows rowNum colNum |
7+
self checkDimensionalCompatibility: dimensionArray.
8+
rowNum := dimensionArray at: 1.
9+
colNum := dimensionArray at: 2.
10+
computedRows := (1 to: rowNum) collect: [ :i | (1 to: colNum) collect: [ :j | self at: i - 1 * colNum + j ] ].
11+
12+
^ PMMatrix rows: computedRows
13+
]
14+
315
{ #category : #'*Math-Matrix' }
416
PMVector >> tensorProduct: aVector [
517
"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/PMAdditionalTest.class.st

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ Class {
88
#category : #'Math-Tests-Matrix'
99
}
1010

11+
{ #category : #tests }
12+
PMAdditionalTest >> testMatrixConversionWithBothDims [
13+
| vect result expected |
14+
vect := #(1 0.5 0.2 3 1 -1 7 3 2 12 13 3) asPMVector .
15+
result := vect reshapeWithDimensions: #(6 2).
16+
17+
expected := PMMatrix rows: #(#(1 0.5) #(0.2 3) #(1 -1) #(7 3) #(2 12) #(13 3)).
18+
19+
self assert: result equals: expected.
20+
]
21+
1122
{ #category : #tests }
1223
PMAdditionalTest >> testMatrixInversionSmall [
1324
"it is here since it uses random matrices"

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

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

386+
{ #category : #tests }
387+
PMMatrixTest >> testMatrixConversionWithBothDims [
388+
| vect result expected |
389+
vect := #(1 0.5 0.2 3 1 -1 7 3 2 12 13 3) asPMVector .
390+
result := vect reshapeWithDimensions: #(6 2).
391+
392+
expected := PMMatrix rows: #(#(1 0.5) #(0.2 3) #(1 -1) #(7 3) #(2 12) #(13 3)).
393+
394+
self assert: result equals: expected.
395+
]
396+
386397
{ #category : #comparing }
387398
PMMatrixTest >> testMatrixCos [
388399
| a |
@@ -930,7 +941,7 @@ PMMatrixTest >> testSymmetricMatrixAdd3 [
930941
self assert: ((c rowAt: 3) at: 1) equals: 31
931942
]
932943

933-
{ #category : #test }
944+
{ #category : #tests }
934945
PMMatrixTest >> testTake [
935946

936947
| m expected |
@@ -967,6 +978,18 @@ PMMatrixTest >> testVectorMatrixOperation [
967978
self assert: (v at: 2) equals: 4
968979
]
969980

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

0 commit comments

Comments
 (0)