From cebbce91de007cbd6c0c1502e557086b1eab3a29 Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Sun, 3 Mar 2013 13:00:55 +0100 Subject: [PATCH] LA: Arithmetics design pattern: collect abstract decls at top --- .../Generic/Matrix.Arithmetic.cs | 184 +++++++++--------- src/Numerics/LinearAlgebra/Generic/Vector.cs | 165 ++++++++-------- 2 files changed, 175 insertions(+), 174 deletions(-) diff --git a/src/Numerics/LinearAlgebra/Generic/Matrix.Arithmetic.cs b/src/Numerics/LinearAlgebra/Generic/Matrix.Arithmetic.cs index 66cef3a1..93888595 100644 --- a/src/Numerics/LinearAlgebra/Generic/Matrix.Arithmetic.cs +++ b/src/Numerics/LinearAlgebra/Generic/Matrix.Arithmetic.cs @@ -50,6 +50,98 @@ namespace MathNet.Numerics.LinearAlgebra.Generic /// static readonly T Zero = Common.ZeroOf(); + /// + /// Negate each element of this matrix and place the results into the result matrix. + /// + /// The result of the negation. + protected abstract void DoNegate(Matrix result); + + /// + /// Adds another matrix to this matrix. + /// + /// The matrix to add to this matrix. + /// The matrix to store the result of the addition. + /// If the other matrix is . + /// If the two matrices don't have the same dimensions. + protected abstract void DoAdd(Matrix other, Matrix result); + + /// + /// Subtracts another matrix from this matrix. + /// + /// The matrix to subtract. + /// The matrix to store the result of the subtraction. + protected abstract void DoSubtract(Matrix other, Matrix result); + + /// + /// Multiplies each element of the matrix by a scalar and places results into the result matrix. + /// + /// The scalar to multiply the matrix with. + /// The matrix to store the result of the multiplication. + protected abstract void DoMultiply(T scalar, Matrix result); + + /// + /// Multiplies this matrix with a vector and places the results into the result vector. + /// + /// The vector to multiply with. + /// The result of the multiplication. + protected abstract void DoMultiply(Vector rightSide, Vector result); + + /// + /// Multiplies this matrix with another matrix and places the results into the result matrix. + /// + /// The matrix to multiply with. + /// The result of the multiplication. + protected abstract void DoMultiply(Matrix other, Matrix result); + + /// + /// Multiplies this matrix with transpose of another matrix and places the results into the result matrix. + /// + /// The matrix to multiply with. + /// The result of the multiplication. + protected abstract void DoTransposeAndMultiply(Matrix other, Matrix result); + + /// + /// Multiplies the transpose of this matrix with a vector and places the results into the result vector. + /// + /// The vector to multiply with. + /// The result of the multiplication. + protected abstract void DoTransposeThisAndMultiply(Vector rightSide, Vector result); + + /// + /// Multiplies the transpose of this matrix with another matrix and places the results into the result matrix. + /// + /// The matrix to multiply with. + /// The result of the multiplication. + protected abstract void DoTransposeThisAndMultiply(Matrix other, Matrix result); + + /// + /// Divides each element of the matrix by a scalar and places results into the result matrix. + /// + /// The scalar to divide the matrix with. + /// The matrix to store the result of the division. + protected abstract void DoDivide(T scalar, Matrix result); + + /// + /// Computes the modulus for each element of the matrix. + /// + /// The divisor to use. + /// Matrix to store the results in. + protected abstract void DoModulus(T divisor, Matrix result); + + /// + /// Pointwise multiplies this matrix with another matrix and stores the result into the result matrix. + /// + /// The matrix to pointwise multiply with this one. + /// The matrix to store the result of the pointwise multiplication. + protected abstract void DoPointwiseMultiply(Matrix other, Matrix result); + + /// + /// Pointwise divide this matrix by another matrix and stores the result into the result matrix. + /// + /// The matrix to pointwise divide this one by. + /// The matrix to store the result of the pointwise division. + protected abstract void DoPointwiseDivide(Matrix other, Matrix result); + /// /// Adds another matrix to this matrix. /// @@ -106,15 +198,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic DoAdd(other, result); } - /// - /// Adds another matrix to this matrix. - /// - /// The matrix to add to this matrix. - /// The matrix to store the result of the addition. - /// If the other matrix is . - /// If the two matrices don't have the same dimensions. - protected abstract void DoAdd(Matrix other, Matrix result); - /// /// Subtracts another matrix from this matrix. /// @@ -171,13 +254,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic DoSubtract(other, result); } - /// - /// Subtracts another matrix from this matrix. - /// - /// The matrix to subtract. - /// The matrix to store the result of the subtraction. - protected abstract void DoSubtract(Matrix other, Matrix result); - /// /// Multiplies each element of this matrix with a scalar. /// @@ -299,20 +375,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic DoDivide(scalar, result); } - /// - /// Divides each element of the matrix by a scalar and places results into the result matrix. - /// - /// The scalar to divide the matrix with. - /// The matrix to store the result of the division. - protected abstract void DoDivide(T scalar, Matrix result); - - /// - /// Multiplies each element of the matrix by a scalar and places results into the result matrix. - /// - /// The scalar to multiply the matrix with. - /// The matrix to store the result of the multiplication. - protected abstract void DoMultiply(T scalar, Matrix result); - /// /// Multiplies this matrix by a vector and returns the result. /// @@ -370,13 +432,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic } } - /// - /// Multiplies this matrix with a vector and places the results into the result vector. - /// - /// The vector to multiply with. - /// The result of the multiplication. - protected abstract void DoMultiply(Vector rightSide, Vector result); - /// /// Left multiply a matrix with a vector ( = vector * matrix ). /// @@ -505,13 +560,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic return result; } - /// - /// Multiplies this matrix with another matrix and places the results into the result matrix. - /// - /// The matrix to multiply with. - /// The result of the multiplication. - protected abstract void DoMultiply(Matrix other, Matrix result); - /// /// Multiplies this matrix with transpose of another matrix and places the results into the result matrix. /// @@ -574,13 +622,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic return result; } - /// - /// Multiplies this matrix with transpose of another matrix and places the results into the result matrix. - /// - /// The matrix to multiply with. - /// The result of the multiplication. - protected abstract void DoTransposeAndMultiply(Matrix other, Matrix result); - /// /// Multiplies the transpose of this matrix by a vector and returns the result. /// @@ -638,13 +679,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic } } - /// - /// Multiplies the transpose of this matrix with a vector and places the results into the result vector. - /// - /// The vector to multiply with. - /// The result of the multiplication. - protected abstract void DoTransposeThisAndMultiply(Vector rightSide, Vector result); - /// /// Multiplies the transpose of this matrix with another matrix and places the results into the result matrix. /// @@ -707,13 +741,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic return result; } - /// - /// Multiplies the transpose of this matrix with another matrix and places the results into the result matrix. - /// - /// The matrix to multiply with. - /// The result of the multiplication. - protected abstract void DoTransposeThisAndMultiply(Matrix other, Matrix result); - /// /// Negate each element of this matrix. /// @@ -746,12 +773,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic DoNegate(result); } - /// - /// Negate each element of this matrix and place the results into the result matrix. - /// - /// The result of the negation. - protected abstract void DoNegate(Matrix result); - /// /// Adds two matrices together and returns the results. /// @@ -1022,13 +1043,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic return result; } - /// - /// Pointwise multiplies this matrix with another matrix and stores the result into the result matrix. - /// - /// The matrix to pointwise multiply with this one. - /// The matrix to store the result of the pointwise multiplication. - protected abstract void DoPointwiseMultiply(Matrix other, Matrix result); - /// /// Pointwise divide this matrix by another matrix and stores the result into the result matrix. /// @@ -1058,13 +1072,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic DoPointwiseDivide(other, result); } - /// - /// Pointwise divide this matrix by another matrix and stores the result into the result matrix. - /// - /// The matrix to pointwise divide this one by. - /// The matrix to store the result of the pointwise division. - protected abstract void DoPointwiseDivide(Matrix other, Matrix result); - /// /// Computes the modulus for each element of the matrix. /// @@ -1097,13 +1104,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic DoModulus(divisor, result); } - /// - /// Computes the modulus for each element of the matrix. - /// - /// The divisor to use. - /// Matrix to store the results in. - protected abstract void DoModulus(T divisor, Matrix result); - /// /// Multiplies a Matrix by a constant and returns the result. /// diff --git a/src/Numerics/LinearAlgebra/Generic/Vector.cs b/src/Numerics/LinearAlgebra/Generic/Vector.cs index 45df3f47..e547a34a 100644 --- a/src/Numerics/LinearAlgebra/Generic/Vector.cs +++ b/src/Numerics/LinearAlgebra/Generic/Vector.cs @@ -159,6 +159,89 @@ namespace MathNet.Numerics.LinearAlgebra.Generic /// The new Vector. public abstract Vector CreateVector(int size); + + /// + /// Negates vector and save result to + /// + /// Target vector + protected abstract void DoNegate(Vector target); + + /// + /// Complex conjugates vector and save result to + /// + /// Target vector + protected abstract void DoConjugate(Vector target); + + /// + /// Adds a scalar to each element of the vector and stores the result in the result vector. + /// + /// The scalar to add. + /// The vector to store the result of the addition. + protected abstract void DoAdd(T scalar, Vector result); + + /// + /// Adds another vector to this vector and stores the result into the result vector. + /// + /// The vector to add to this one. + /// The vector to store the result of the addition. + protected abstract void DoAdd(Vector other, Vector result); + + /// + /// Subtracts a scalar from each element of the vector and stores the result in the result vector. + /// + /// The scalar to subtract. + /// The vector to store the result of the subtraction. + protected abstract void DoSubtract(T scalar, Vector result); + + /// + /// Subtracts another vector to this vector and stores the result into the result vector. + /// + /// The vector to subtract from this one. + /// The vector to store the result of the subtraction. + protected abstract void DoSubtract(Vector other, Vector result); + + /// + /// Multiplies a scalar to each element of the vector and stores the result in the result vector. + /// + /// The scalar to multiply. + /// The vector to store the result of the multiplication. + protected abstract void DoMultiply(T scalar, Vector result); + + /// + /// Computes the dot product between this vector and another vector. + /// + /// The other vector to add. + /// The result of the addition. + protected abstract T DoDotProduct(Vector other); + + /// + /// Divides each element of the vector by a scalar and stores the result in the result vector. + /// + /// The scalar to divide with. + /// The vector to store the result of the division. + protected abstract void DoDivide(T scalar, Vector result); + + /// + /// Computes the modulus for each element of the vector for the given divisor. + /// + /// The divisor to use. + /// A vector to store the results in. + protected abstract void DoModulus(T divisor, Vector result); + + /// + /// Pointwise multiplies this vector with another vector and stores the result into the result vector. + /// + /// The vector to pointwise multiply with this one. + /// The vector to store the result of the pointwise multiplication. + protected abstract void DoPointwiseMultiply(Vector other, Vector result); + + /// + /// Pointwise divide this vector with another vector and stores the result into the result vector. + /// + /// The vector to pointwise divide this one by. + /// The result of the division. + protected abstract void DoPointwiseDivide(Vector other, Vector result); + /// /// Adds a scalar to each element of the vector. /// @@ -204,13 +287,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic DoAdd(scalar, result); } - /// - /// Adds a scalar to each element of the vector and stores the result in the result vector. - /// - /// The scalar to add. - /// The vector to store the result of the addition. - protected abstract void DoAdd(T scalar, Vector result); - /// /// Returns a copy of this vector. /// @@ -271,13 +347,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic DoAdd(other, result); } - /// - /// Adds another vector to this vector and stores the result into the result vector. - /// - /// The vector to add to this one. - /// The vector to store the result of the addition. - protected abstract void DoAdd(Vector other, Vector result); - /// /// Subtracts a scalar from each element of the vector. /// @@ -323,13 +392,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic DoSubtract(scalar, result); } - /// - /// Subtracts a scalar from each element of the vector and stores the result in the result vector. - /// - /// The scalar to subtract. - /// The vector to store the result of the subtraction. - protected abstract void DoSubtract(T scalar, Vector result); - /// /// Returns a negated vector. /// @@ -361,12 +423,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic DoNegate(target); } - /// - /// Negates vector and save result to - /// - /// Target vector - protected abstract void DoNegate(Vector target); - /// /// Subtracts another vector from this vector. /// @@ -415,13 +471,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic DoSubtract(other, result); } - /// - /// Subtracts another vector to this vector and stores the result into the result vector. - /// - /// The vector to subtract from this one. - /// The vector to store the result of the subtraction. - protected abstract void DoSubtract(Vector other, Vector result); - /// /// Return vector with complex conjugate values of the source vector /// @@ -452,12 +501,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic DoConjugate(target); } - /// - /// Complex conjugates vector and save result to - /// - /// Target vector - protected abstract void DoConjugate(Vector target); - /// /// Multiplies a scalar to each element of the vector. /// @@ -514,13 +557,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic DoMultiply(scalar, result); } - /// - /// Multiplies a scalar to each element of the vector and stores the result in the result vector. - /// - /// The scalar to multiply. - /// The vector to store the result of the multiplication. - protected abstract void DoMultiply(T scalar, Vector result); - /// /// Computes the dot product between this vector and another vector. /// @@ -543,13 +579,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic return DoDotProduct(other); } - /// - /// Computes the dot product between this vector and another vector. - /// - /// The other vector to add. - /// The result of the addition. - protected abstract T DoDotProduct(Vector other); - /// /// Divides each element of the vector by a scalar. /// @@ -595,13 +624,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic DoDivide(scalar, result); } - /// - /// Divides each element of the vector by a scalar and stores the result in the result vector. - /// - /// The scalar to divide with. - /// The vector to store the result of the division. - protected abstract void DoDivide(T scalar, Vector result); - /// /// Computes the modulus for each element of the vector for the given divisor. /// @@ -634,13 +656,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic DoModulus(divisor, result); } - /// - /// Computes the modulus for each element of the vector for the given divisor. - /// - /// The divisor to use. - /// A vector to store the results in. - protected abstract void DoModulus(T divisor, Vector result); - /// /// Pointwise multiplies this vector with another vector. /// @@ -699,13 +714,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic DoPointwiseMultiply(other, result); } - /// - /// Pointwise multiplies this vector with another vector and stores the result into the result vector. - /// - /// The vector to pointwise multiply with this one. - /// The vector to store the result of the pointwise multiplication. - protected abstract void DoPointwiseMultiply(Vector other, Vector result); - /// /// Pointwise divide this vector with another vector. /// @@ -764,13 +772,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic DoPointwiseDivide(other, result); } - /// - /// Pointwise divide this vector with another vector and stores the result into the result vector. - /// - /// The vector to pointwise divide this one by. - /// The result of the division. - protected abstract void DoPointwiseDivide(Vector other, Vector result); - /// /// Outer product of two vectors ///