diff --git a/src/Math-Core/PMVector.class.st b/src/Math-Core/PMVector.class.st index 7515f4613..1bc96b8e6 100644 --- a/src/Math-Core/PMVector.class.st +++ b/src/Math-Core/PMVector.class.st @@ -122,6 +122,18 @@ PMVector >> asPMVector [ ^ self ] +{ #category : #'as yet unclassified' } +PMVector >> checkDimensionalCompatibility: dimensionArray [ + |prod| + prod := 1. + + dimensionArray do: [ :each | prod := prod * each ]. + + self assert: (self size = prod) description: 'Imcompatible combination of Dimensions provided'. + + ^true +] + { #category : #comparing } PMVector >> closeTo: aPMVector [ "Compare two vectors using the default precision from Float >> #closeTo:." @@ -237,6 +249,17 @@ 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 [ diff --git a/src/Math-Matrix/PMJacobiTransformationHelper.class.st b/src/Math-Matrix/PMJacobiTransformationHelper.class.st index 7675cc075..be6f6f9ce 100644 --- a/src/Math-Matrix/PMJacobiTransformationHelper.class.st +++ b/src/Math-Matrix/PMJacobiTransformationHelper.class.st @@ -8,7 +8,7 @@ Class { 'eigenvalues', 'eigenvectors' ], - #category : #'Math-Matrix' + #category : 'Math-Matrix' } { #category : #creation } diff --git a/src/Math-Matrix/PMLUPDecomposition.class.st b/src/Math-Matrix/PMLUPDecomposition.class.st index fe6392d72..75dbe790d 100644 --- a/src/Math-Matrix/PMLUPDecomposition.class.st +++ b/src/Math-Matrix/PMLUPDecomposition.class.st @@ -26,7 +26,7 @@ Class { 'permutation', 'parity' ], - #category : #'Math-Matrix' + #category : 'Math-Matrix' } { #category : #creation } diff --git a/src/Math-Matrix/PMLargestEigenValueFinder.class.st b/src/Math-Matrix/PMLargestEigenValueFinder.class.st index 81478c9ab..06dfac388 100644 --- a/src/Math-Matrix/PMLargestEigenValueFinder.class.st +++ b/src/Math-Matrix/PMLargestEigenValueFinder.class.st @@ -20,7 +20,7 @@ Class { 'eigenvector', 'transposeEigenvector' ], - #category : #'Math-Matrix' + #category : 'Math-Matrix' } { #category : #information } diff --git a/src/Math-Matrix/PMLinearEquationSystem.class.st b/src/Math-Matrix/PMLinearEquationSystem.class.st index 3e5b8e3b6..8b021c459 100644 --- a/src/Math-Matrix/PMLinearEquationSystem.class.st +++ b/src/Math-Matrix/PMLinearEquationSystem.class.st @@ -22,7 +22,7 @@ Class { 'rows', 'solutions' ], - #category : #'Math-Matrix' + #category : 'Math-Matrix' } { #category : #creation } diff --git a/src/Math-Matrix/PMMatrix.class.st b/src/Math-Matrix/PMMatrix.class.st index 597b1158c..c4042dd64 100644 --- a/src/Math-Matrix/PMMatrix.class.st +++ b/src/Math-Matrix/PMMatrix.class.st @@ -15,7 +15,7 @@ Class { 'rows', 'lupDecomposition' ], - #category : #'Math-Matrix' + #category : 'Math-Matrix' } { #category : #example } @@ -243,6 +243,11 @@ PMMatrix >> asSymmetricMatrix [ ^ PMSymmetricMatrix rows: rows ] +{ #category : #converting } +PMMatrix >> asVector [ + ^ self flattenRows. +] + { #category : #'cell accessing' } PMMatrix >> at: aRowIndex at: aColumnIndex [ "Answers the aRowIndex-th, aColumnIndex-th entry in the receiver." diff --git a/src/Math-Matrix/PMSingularMatrixError.class.st b/src/Math-Matrix/PMSingularMatrixError.class.st index 6aa9392a8..6bf7cc4d7 100644 --- a/src/Math-Matrix/PMSingularMatrixError.class.st +++ b/src/Math-Matrix/PMSingularMatrixError.class.st @@ -5,7 +5,7 @@ some calculations dont work with singular matrices and result eg with errors lik Class { #name : #PMSingularMatrixError, #superclass : #ArithmeticError, - #category : #'Math-Matrix' + #category : 'Math-Matrix' } { #category : #accessing } diff --git a/src/Math-Matrix/PMSingularValueDecomposition.class.st b/src/Math-Matrix/PMSingularValueDecomposition.class.st index 65a2723e3..9753ef804 100644 --- a/src/Math-Matrix/PMSingularValueDecomposition.class.st +++ b/src/Math-Matrix/PMSingularValueDecomposition.class.st @@ -40,7 +40,7 @@ Class { 'signU', 'signV' ], - #category : #'Math-Matrix' + #category : 'Math-Matrix' } { #category : #'instance creation' } diff --git a/src/Math-Matrix/PMSymmetricMatrix.class.st b/src/Math-Matrix/PMSymmetricMatrix.class.st index 2e8a34764..fbfce867b 100644 --- a/src/Math-Matrix/PMSymmetricMatrix.class.st +++ b/src/Math-Matrix/PMSymmetricMatrix.class.st @@ -4,7 +4,7 @@ This class can be instantiated like DhbMatrix via #rows:, but the user has to ma Class { #name : #PMSymmetricMatrix, #superclass : #PMMatrix, - #category : #'Math-Matrix' + #category : 'Math-Matrix' } { #category : #'instance creation' } diff --git a/src/Math-Tests-Core/PMVectorTest.class.st b/src/Math-Tests-Core/PMVectorTest.class.st index 80fb47bc2..6624f6f8b 100644 --- a/src/Math-Tests-Core/PMVectorTest.class.st +++ b/src/Math-Tests-Core/PMVectorTest.class.st @@ -59,6 +59,17 @@ PMVectorTest >> testAsArray [ self assert: #(1 2 3 4) asPMVector asArray equals: #(1 2 3 4) ] +{ #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 | @@ -299,6 +310,17 @@ 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 | diff --git a/src/Math-Tests-Matrix/PMAdditionalTest.class.st b/src/Math-Tests-Matrix/PMAdditionalTest.class.st index 8b32fa46b..eea0c4266 100644 --- a/src/Math-Tests-Matrix/PMAdditionalTest.class.st +++ b/src/Math-Tests-Matrix/PMAdditionalTest.class.st @@ -5,7 +5,7 @@ here are tests that would be in Math-Tests-DHB-Numerical, if it could construct Class { #name : #PMAdditionalTest, #superclass : #TestCase, - #category : #'Math-Tests-Matrix' + #category : 'Math-Tests-Matrix' } { #category : #tests } diff --git a/src/Math-Tests-Matrix/PMMatrixTest.class.st b/src/Math-Tests-Matrix/PMMatrixTest.class.st index 3b277e0f6..32a26fd66 100644 --- a/src/Math-Tests-Matrix/PMMatrixTest.class.st +++ b/src/Math-Tests-Matrix/PMMatrixTest.class.st @@ -1,7 +1,7 @@ Class { #name : #PMMatrixTest, #superclass : #TestCase, - #category : #'Math-Tests-Matrix' + #category : 'Math-Tests-Matrix' } { #category : #tests } @@ -672,6 +672,13 @@ PMMatrixTest >> testSymmetricMatrixAdd3 [ self assert: ((c rowAt: 3) at: 1) equals: 31 ] +{ #category : #tests } +PMMatrixTest >> testVectorConversion [ + | m | + m := PMMatrix rows: #(#(1 2 3) #(4 5 6) #(7 8 9)). + self assert: m asVector equals: #(1 2 3 4 5 6 7 8 9) asPMVector +] + { #category : #'linear algebra' } PMMatrixTest >> testVectorMatrixOperation [ "Code Example 8.1" diff --git a/src/Math-Tests-Matrix/PMQRTest.class.st b/src/Math-Tests-Matrix/PMQRTest.class.st index 930267b70..6f8a23303 100644 --- a/src/Math-Tests-Matrix/PMQRTest.class.st +++ b/src/Math-Tests-Matrix/PMQRTest.class.st @@ -1,7 +1,7 @@ Class { #name : #PMQRTest, #superclass : #TestCase, - #category : #'Math-Tests-Matrix' + #category : 'Math-Tests-Matrix' } { #category : #running } diff --git a/src/Math-Tests-Matrix/PMRestTest.class.st b/src/Math-Tests-Matrix/PMRestTest.class.st index 667530dd8..d4db439f1 100644 --- a/src/Math-Tests-Matrix/PMRestTest.class.st +++ b/src/Math-Tests-Matrix/PMRestTest.class.st @@ -1,7 +1,7 @@ Class { #name : #PMRestTest, #superclass : #TestCase, - #category : #'Math-Tests-Matrix' + #category : 'Math-Tests-Matrix' } { #category : #tests } diff --git a/src/Math-Tests-Matrix/PMSingularValueDecompositionTest.class.st b/src/Math-Tests-Matrix/PMSingularValueDecompositionTest.class.st index 43e06794e..d3f6d1b79 100644 --- a/src/Math-Tests-Matrix/PMSingularValueDecompositionTest.class.st +++ b/src/Math-Tests-Matrix/PMSingularValueDecompositionTest.class.st @@ -35,7 +35,7 @@ Class { 'actualV', 'actualS' ], - #category : #'Math-Tests-Matrix' + #category : 'Math-Tests-Matrix' } { #category : #'as yet unclassified' } diff --git a/src/Math-Tests-Matrix/PMSymmetricMatrixTest.class.st b/src/Math-Tests-Matrix/PMSymmetricMatrixTest.class.st index f0a1e2870..0d6ad00be 100644 --- a/src/Math-Tests-Matrix/PMSymmetricMatrixTest.class.st +++ b/src/Math-Tests-Matrix/PMSymmetricMatrixTest.class.st @@ -1,7 +1,7 @@ Class { #name : #PMSymmetricMatrixTest, #superclass : #TestCase, - #category : #'Math-Tests-Matrix' + #category : 'Math-Tests-Matrix' } { #category : #tests }