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
6 changes: 0 additions & 6 deletions src/Math-Core/Number.extension.st
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
Extension { #name : #Number }

{ #category : #'*Math-Core' }
Number >> addWithRegularMatrix: aMatrix [
"Adds itself to every row of the matrix"
^ PMMatrix rows: (aMatrix rowsCollect: [ :row | row + self ])
]

{ #category : #'*Math-Core' }
Number >> addWithVector: aVector [
"Adds itself to each element of the vector"
Expand Down
17 changes: 0 additions & 17 deletions src/Math-Core/PMVector.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,6 @@ PMVector >> normalized [
^ (1 / self norm) * self
]

{ #category : #operation }
PMVector >> productWithMatrix: aMatrix [
"Answers the product of aMatrix with the receiver."
^aMatrix rowsCollect: [ :each | each * self]
]

{ #category : #operation }
PMVector >> productWithVector: aVector [
"Answers the scalar product of aVector with the receiver."
Expand All @@ -268,17 +262,6 @@ PMVector >> productWithVector: aVector [
into: [ :sum :each | n := n + 1. (aVector at: n) * each + sum]
]

{ #category : #'as yet unclassified' }
PMVector >> reshapeWithDimensions: dimensionArray [
| computedRows rowNum colNum |
self checkDimensionalCompatibility: dimensionArray.
rowNum := dimensionArray at: 1.
colNum := dimensionArray at: 2.
computedRows := ((1 to: rowNum) collect: [ :i | (1 to: colNum) collect: [ :j | self at: (i-1*colNum)+j ] ]).

^PMMatrix rows: computedRows
]

{ #category : #operation }
PMVector >> scalarProduct: aVector [

Expand Down
6 changes: 6 additions & 0 deletions src/Math-Matrix/Number.extension.st
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Extension { #name : #Number }

{ #category : #'*Math-Matrix' }
Number >> addWithRegularMatrix: aMatrix [
"Adds itself to every row of the matrix"
^ PMMatrix rows: (aMatrix rowsCollect: [ :row | row + self ])
]

{ #category : #'*Math-Matrix' }
Number >> productWithMatrix: aMatrix [
^aMatrix class rows: (aMatrix rowsCollect: [:r| self productWithVector: r])
Expand Down
20 changes: 20 additions & 0 deletions src/Math-Matrix/PMVector.extension.st
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
Extension { #name : #PMVector }

{ #category : #'*Math-Matrix' }
PMVector >> productWithMatrix: aMatrix [

"Answers the product of aMatrix with the receiver."

^ aMatrix rowsCollect: [ :each | each * self ]
]

{ #category : #'*Math-Matrix' }
PMVector >> reshapeWithDimensions: dimensionArray [

| computedRows rowNum colNum |
self checkDimensionalCompatibility: dimensionArray.
rowNum := dimensionArray at: 1.
colNum := dimensionArray at: 2.
computedRows := (1 to: rowNum) collect: [ :i | (1 to: colNum) collect: [ :j | self at: i - 1 * colNum + j ] ].

^ PMMatrix rows: computedRows
]

{ #category : #'*Math-Matrix' }
PMVector >> tensorProduct: aVector [
"Answers the tensor product of the receiver with aVector."
Expand Down
22 changes: 0 additions & 22 deletions src/Math-Tests-Core/PMVectorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,6 @@ PMVectorTest >> testLessThan [
self assert: vec equals: vecCopy asPMVector.
]

{ #category : #tests }
PMVectorTest >> testMatrixConversionWithBothDims [
| vect result expected |
vect := #(1 0.5 0.2 3 1 -1 7 3 2 12 13 3) asPMVector .
result := vect reshapeWithDimensions: #(6 2).

expected := PMMatrix rows: #(#(1 0.5) #(0.2 3) #(1 -1) #(7 3) #(2 12) #(13 3)).

self assert: result equals: expected.
]

{ #category : #tests }
PMVectorTest >> testScalarProduct [
| u v |
Expand Down Expand Up @@ -375,17 +364,6 @@ PMVectorTest >> testVectorSum [
self assert: (u sum) equals: 6.
]

{ #category : #tests }
PMVectorTest >> testVectorToVectorConversion [
| vect result expected |
vect := #(1 0.5 0.2 3 1 -1 7 3 2 12 13 3) asPMVector .
result := vect reshapeWithDimensions: #(1 12).

expected := PMMatrix rows: #(#(1 0.5 0.2 3 1 -1 7 3 2 12 13 3)).

self assert: result equals: expected.
]

{ #category : #tests }
PMVectorTest >> testVectorZeros [
| v |
Expand Down
26 changes: 25 additions & 1 deletion src/Math-Tests-Matrix/PMMatrixTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,18 @@ PMMatrixTest >> testMatrixCloseToPrecision [
self deny: (a closeTo: b precision: 0.2)
]

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

| vect result expected |
vect := #( 1 0.5 0.2 3 1 -1 7 3 2 12 13 3 ) asPMVector.
result := vect reshapeWithDimensions: #( 6 2 ).

expected := PMMatrix rows: #( #( 1 0.5 ) #( 0.2 3 ) #( 1 -1 ) #( 7 3 ) #( 2 12 ) #( 13 3 ) ).

self assert: result equals: expected
]

{ #category : #comparing }
PMMatrixTest >> testMatrixCos [
| a |
Expand Down Expand Up @@ -930,7 +942,7 @@ PMMatrixTest >> testSymmetricMatrixAdd3 [
self assert: ((c rowAt: 3) at: 1) equals: 31
]

{ #category : #test }
{ #category : #tests }
PMMatrixTest >> testTake [

| m expected |
Expand Down Expand Up @@ -967,6 +979,18 @@ PMMatrixTest >> testVectorMatrixOperation [
self assert: (v at: 2) equals: 4
]

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

| vect result expected |
vect := #( 1 0.5 0.2 3 1 -1 7 3 2 12 13 3 ) asPMVector.
result := vect reshapeWithDimensions: #( 1 12 ).

expected := PMMatrix rows: #( #( 1 0.5 0.2 3 1 -1 7 3 2 12 13 3 ) ).

self assert: result equals: expected
]

{ #category : #'linear algebra' }
PMMatrixTest >> testVectorTransposeMatrixOperation [
"Code Example 8.1"
Expand Down