Browse Source

LA: Arithmetics design pattern: collect abstract decls at top

pull/103/head
Christoph Ruegg 13 years ago
parent
commit
cebbce91de
  1. 184
      src/Numerics/LinearAlgebra/Generic/Matrix.Arithmetic.cs
  2. 165
      src/Numerics/LinearAlgebra/Generic/Vector.cs

184
src/Numerics/LinearAlgebra/Generic/Matrix.Arithmetic.cs

@ -50,6 +50,98 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// </summary>
static readonly T Zero = Common.ZeroOf<T>();
/// <summary>
/// Negate each element of this matrix and place the results into the result matrix.
/// </summary>
/// <param name="result">The result of the negation.</param>
protected abstract void DoNegate(Matrix<T> result);
/// <summary>
/// Adds another matrix to this matrix.
/// </summary>
/// <param name="other">The matrix to add to this matrix.</param>
/// <param name="result">The matrix to store the result of the addition.</param>
/// <exception cref="ArgumentNullException">If the other matrix is <see langword="null"/>.</exception>
/// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception>
protected abstract void DoAdd(Matrix<T> other, Matrix<T> result);
/// <summary>
/// Subtracts another matrix from this matrix.
/// </summary>
/// <param name="other">The matrix to subtract.</param>
/// <param name="result">The matrix to store the result of the subtraction.</param>
protected abstract void DoSubtract(Matrix<T> other, Matrix<T> result);
/// <summary>
/// Multiplies each element of the matrix by a scalar and places results into the result matrix.
/// </summary>
/// <param name="scalar">The scalar to multiply the matrix with.</param>
/// <param name="result">The matrix to store the result of the multiplication.</param>
protected abstract void DoMultiply(T scalar, Matrix<T> result);
/// <summary>
/// Multiplies this matrix with a vector and places the results into the result vector.
/// </summary>
/// <param name="rightSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected abstract void DoMultiply(Vector<T> rightSide, Vector<T> result);
/// <summary>
/// Multiplies this matrix with another matrix and places the results into the result matrix.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected abstract void DoMultiply(Matrix<T> other, Matrix<T> result);
/// <summary>
/// Multiplies this matrix with transpose of another matrix and places the results into the result matrix.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected abstract void DoTransposeAndMultiply(Matrix<T> other, Matrix<T> result);
/// <summary>
/// Multiplies the transpose of this matrix with a vector and places the results into the result vector.
/// </summary>
/// <param name="rightSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected abstract void DoTransposeThisAndMultiply(Vector<T> rightSide, Vector<T> result);
/// <summary>
/// Multiplies the transpose of this matrix with another matrix and places the results into the result matrix.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected abstract void DoTransposeThisAndMultiply(Matrix<T> other, Matrix<T> result);
/// <summary>
/// Divides each element of the matrix by a scalar and places results into the result matrix.
/// </summary>
/// <param name="scalar">The scalar to divide the matrix with.</param>
/// <param name="result">The matrix to store the result of the division.</param>
protected abstract void DoDivide(T scalar, Matrix<T> result);
/// <summary>
/// Computes the modulus for each element of the matrix.
/// </summary>
/// <param name="divisor">The divisor to use.</param>
/// <param name="result">Matrix to store the results in.</param>
protected abstract void DoModulus(T divisor, Matrix<T> result);
/// <summary>
/// Pointwise multiplies this matrix with another matrix and stores the result into the result matrix.
/// </summary>
/// <param name="other">The matrix to pointwise multiply with this one.</param>
/// <param name="result">The matrix to store the result of the pointwise multiplication.</param>
protected abstract void DoPointwiseMultiply(Matrix<T> other, Matrix<T> result);
/// <summary>
/// Pointwise divide this matrix by another matrix and stores the result into the result matrix.
/// </summary>
/// <param name="other">The matrix to pointwise divide this one by.</param>
/// <param name="result">The matrix to store the result of the pointwise division.</param>
protected abstract void DoPointwiseDivide(Matrix<T> other, Matrix<T> result);
/// <summary>
/// Adds another matrix to this matrix.
/// </summary>
@ -106,15 +198,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
DoAdd(other, result);
}
/// <summary>
/// Adds another matrix to this matrix.
/// </summary>
/// <param name="other">The matrix to add to this matrix.</param>
/// <param name="result">The matrix to store the result of the addition.</param>
/// <exception cref="ArgumentNullException">If the other matrix is <see langword="null"/>.</exception>
/// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception>
protected abstract void DoAdd(Matrix<T> other, Matrix<T> result);
/// <summary>
/// Subtracts another matrix from this matrix.
/// </summary>
@ -171,13 +254,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
DoSubtract(other, result);
}
/// <summary>
/// Subtracts another matrix from this matrix.
/// </summary>
/// <param name="other">The matrix to subtract.</param>
/// <param name="result">The matrix to store the result of the subtraction.</param>
protected abstract void DoSubtract(Matrix<T> other, Matrix<T> result);
/// <summary>
/// Multiplies each element of this matrix with a scalar.
/// </summary>
@ -299,20 +375,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
DoDivide(scalar, result);
}
/// <summary>
/// Divides each element of the matrix by a scalar and places results into the result matrix.
/// </summary>
/// <param name="scalar">The scalar to divide the matrix with.</param>
/// <param name="result">The matrix to store the result of the division.</param>
protected abstract void DoDivide(T scalar, Matrix<T> result);
/// <summary>
/// Multiplies each element of the matrix by a scalar and places results into the result matrix.
/// </summary>
/// <param name="scalar">The scalar to multiply the matrix with.</param>
/// <param name="result">The matrix to store the result of the multiplication.</param>
protected abstract void DoMultiply(T scalar, Matrix<T> result);
/// <summary>
/// Multiplies this matrix by a vector and returns the result.
/// </summary>
@ -370,13 +432,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
}
}
/// <summary>
/// Multiplies this matrix with a vector and places the results into the result vector.
/// </summary>
/// <param name="rightSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected abstract void DoMultiply(Vector<T> rightSide, Vector<T> result);
/// <summary>
/// Left multiply a matrix with a vector ( = vector * matrix ).
/// </summary>
@ -505,13 +560,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
return result;
}
/// <summary>
/// Multiplies this matrix with another matrix and places the results into the result matrix.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected abstract void DoMultiply(Matrix<T> other, Matrix<T> result);
/// <summary>
/// Multiplies this matrix with transpose of another matrix and places the results into the result matrix.
/// </summary>
@ -574,13 +622,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
return result;
}
/// <summary>
/// Multiplies this matrix with transpose of another matrix and places the results into the result matrix.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected abstract void DoTransposeAndMultiply(Matrix<T> other, Matrix<T> result);
/// <summary>
/// Multiplies the transpose of this matrix by a vector and returns the result.
/// </summary>
@ -638,13 +679,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
}
}
/// <summary>
/// Multiplies the transpose of this matrix with a vector and places the results into the result vector.
/// </summary>
/// <param name="rightSide">The vector to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected abstract void DoTransposeThisAndMultiply(Vector<T> rightSide, Vector<T> result);
/// <summary>
/// Multiplies the transpose of this matrix with another matrix and places the results into the result matrix.
/// </summary>
@ -707,13 +741,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
return result;
}
/// <summary>
/// Multiplies the transpose of this matrix with another matrix and places the results into the result matrix.
/// </summary>
/// <param name="other">The matrix to multiply with.</param>
/// <param name="result">The result of the multiplication.</param>
protected abstract void DoTransposeThisAndMultiply(Matrix<T> other, Matrix<T> result);
/// <summary>
/// Negate each element of this matrix.
/// </summary>
@ -746,12 +773,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
DoNegate(result);
}
/// <summary>
/// Negate each element of this matrix and place the results into the result matrix.
/// </summary>
/// <param name="result">The result of the negation.</param>
protected abstract void DoNegate(Matrix<T> result);
/// <summary>
/// Adds two matrices together and returns the results.
/// </summary>
@ -1022,13 +1043,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
return result;
}
/// <summary>
/// Pointwise multiplies this matrix with another matrix and stores the result into the result matrix.
/// </summary>
/// <param name="other">The matrix to pointwise multiply with this one.</param>
/// <param name="result">The matrix to store the result of the pointwise multiplication.</param>
protected abstract void DoPointwiseMultiply(Matrix<T> other, Matrix<T> result);
/// <summary>
/// Pointwise divide this matrix by another matrix and stores the result into the result matrix.
/// </summary>
@ -1058,13 +1072,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
DoPointwiseDivide(other, result);
}
/// <summary>
/// Pointwise divide this matrix by another matrix and stores the result into the result matrix.
/// </summary>
/// <param name="other">The matrix to pointwise divide this one by.</param>
/// <param name="result">The matrix to store the result of the pointwise division.</param>
protected abstract void DoPointwiseDivide(Matrix<T> other, Matrix<T> result);
/// <summary>
/// Computes the modulus for each element of the matrix.
/// </summary>
@ -1097,13 +1104,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
DoModulus(divisor, result);
}
/// <summary>
/// Computes the modulus for each element of the matrix.
/// </summary>
/// <param name="divisor">The divisor to use.</param>
/// <param name="result">Matrix to store the results in.</param>
protected abstract void DoModulus(T divisor, Matrix<T> result);
/// <summary>
/// Multiplies a <strong>Matrix</strong> by a constant and returns the result.
/// </summary>

165
src/Numerics/LinearAlgebra/Generic/Vector.cs

@ -159,6 +159,89 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <returns>The new <c>Vector</c>.</returns>
public abstract Vector<T> CreateVector(int size);
/// <summary>
/// Negates vector and save result to <paramref name="target"/>
/// </summary>
/// <param name="target">Target vector</param>
protected abstract void DoNegate(Vector<T> target);
/// <summary>
/// Complex conjugates vector and save result to <paramref name="target"/>
/// </summary>
/// <param name="target">Target vector</param>
protected abstract void DoConjugate(Vector<T> target);
/// <summary>
/// Adds a scalar to each element of the vector and stores the result in the result vector.
/// </summary>
/// <param name="scalar">The scalar to add.</param>
/// <param name="result">The vector to store the result of the addition.</param>
protected abstract void DoAdd(T scalar, Vector<T> result);
/// <summary>
/// Adds another vector to this vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to add to this one.</param>
/// <param name="result">The vector to store the result of the addition.</param>
protected abstract void DoAdd(Vector<T> other, Vector<T> result);
/// <summary>
/// Subtracts a scalar from each element of the vector and stores the result in the result vector.
/// </summary>
/// <param name="scalar">The scalar to subtract.</param>
/// <param name="result">The vector to store the result of the subtraction.</param>
protected abstract void DoSubtract(T scalar, Vector<T> result);
/// <summary>
/// Subtracts another vector to this vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to subtract from this one.</param>
/// <param name="result">The vector to store the result of the subtraction.</param>
protected abstract void DoSubtract(Vector<T> other, Vector<T> result);
/// <summary>
/// Multiplies a scalar to each element of the vector and stores the result in the result vector.
/// </summary>
/// <param name="scalar">The scalar to multiply.</param>
/// <param name="result">The vector to store the result of the multiplication.</param>
protected abstract void DoMultiply(T scalar, Vector<T> result);
/// <summary>
/// Computes the dot product between this vector and another vector.
/// </summary>
/// <param name="other">The other vector to add.</param>
/// <returns>The result of the addition.</returns>
protected abstract T DoDotProduct(Vector<T> other);
/// <summary>
/// Divides each element of the vector by a scalar and stores the result in the result vector.
/// </summary>
/// <param name="scalar">The scalar to divide with.</param>
/// <param name="result">The vector to store the result of the division.</param>
protected abstract void DoDivide(T scalar, Vector<T> result);
/// <summary>
/// Computes the modulus for each element of the vector for the given divisor.
/// </summary>
/// <param name="divisor">The divisor to use.</param>
/// <param name="result">A vector to store the results in.</param>
protected abstract void DoModulus(T divisor, Vector<T> result);
/// <summary>
/// Pointwise multiplies this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise multiply with this one.</param>
/// <param name="result">The vector to store the result of the pointwise multiplication.</param>
protected abstract void DoPointwiseMultiply(Vector<T> other, Vector<T> result);
/// <summary>
/// Pointwise divide this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise divide this one by.</param>
/// <param name="result">The result of the division.</param>
protected abstract void DoPointwiseDivide(Vector<T> other, Vector<T> result);
/// <summary>
/// Adds a scalar to each element of the vector.
/// </summary>
@ -204,13 +287,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
DoAdd(scalar, result);
}
/// <summary>
/// Adds a scalar to each element of the vector and stores the result in the result vector.
/// </summary>
/// <param name="scalar">The scalar to add.</param>
/// <param name="result">The vector to store the result of the addition.</param>
protected abstract void DoAdd(T scalar, Vector<T> result);
/// <summary>
/// Returns a copy of this vector.
/// </summary>
@ -271,13 +347,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
DoAdd(other, result);
}
/// <summary>
/// Adds another vector to this vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to add to this one.</param>
/// <param name="result">The vector to store the result of the addition.</param>
protected abstract void DoAdd(Vector<T> other, Vector<T> result);
/// <summary>
/// Subtracts a scalar from each element of the vector.
/// </summary>
@ -323,13 +392,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
DoSubtract(scalar, result);
}
/// <summary>
/// Subtracts a scalar from each element of the vector and stores the result in the result vector.
/// </summary>
/// <param name="scalar">The scalar to subtract.</param>
/// <param name="result">The vector to store the result of the subtraction.</param>
protected abstract void DoSubtract(T scalar, Vector<T> result);
/// <summary>
/// Returns a negated vector.
/// </summary>
@ -361,12 +423,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
DoNegate(target);
}
/// <summary>
/// Negates vector and save result to <paramref name="target"/>
/// </summary>
/// <param name="target">Target vector</param>
protected abstract void DoNegate(Vector<T> target);
/// <summary>
/// Subtracts another vector from this vector.
/// </summary>
@ -415,13 +471,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
DoSubtract(other, result);
}
/// <summary>
/// Subtracts another vector to this vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to subtract from this one.</param>
/// <param name="result">The vector to store the result of the subtraction.</param>
protected abstract void DoSubtract(Vector<T> other, Vector<T> result);
/// <summary>
/// Return vector with complex conjugate values of the source vector
/// </summary>
@ -452,12 +501,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
DoConjugate(target);
}
/// <summary>
/// Complex conjugates vector and save result to <paramref name="target"/>
/// </summary>
/// <param name="target">Target vector</param>
protected abstract void DoConjugate(Vector<T> target);
/// <summary>
/// Multiplies a scalar to each element of the vector.
/// </summary>
@ -514,13 +557,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
DoMultiply(scalar, result);
}
/// <summary>
/// Multiplies a scalar to each element of the vector and stores the result in the result vector.
/// </summary>
/// <param name="scalar">The scalar to multiply.</param>
/// <param name="result">The vector to store the result of the multiplication.</param>
protected abstract void DoMultiply(T scalar, Vector<T> result);
/// <summary>
/// Computes the dot product between this vector and another vector.
/// </summary>
@ -543,13 +579,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
return DoDotProduct(other);
}
/// <summary>
/// Computes the dot product between this vector and another vector.
/// </summary>
/// <param name="other">The other vector to add.</param>
/// <returns>The result of the addition.</returns>
protected abstract T DoDotProduct(Vector<T> other);
/// <summary>
/// Divides each element of the vector by a scalar.
/// </summary>
@ -595,13 +624,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
DoDivide(scalar, result);
}
/// <summary>
/// Divides each element of the vector by a scalar and stores the result in the result vector.
/// </summary>
/// <param name="scalar">The scalar to divide with.</param>
/// <param name="result">The vector to store the result of the division.</param>
protected abstract void DoDivide(T scalar, Vector<T> result);
/// <summary>
/// Computes the modulus for each element of the vector for the given divisor.
/// </summary>
@ -634,13 +656,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
DoModulus(divisor, result);
}
/// <summary>
/// Computes the modulus for each element of the vector for the given divisor.
/// </summary>
/// <param name="divisor">The divisor to use.</param>
/// <param name="result">A vector to store the results in.</param>
protected abstract void DoModulus(T divisor, Vector<T> result);
/// <summary>
/// Pointwise multiplies this vector with another vector.
/// </summary>
@ -699,13 +714,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
DoPointwiseMultiply(other, result);
}
/// <summary>
/// Pointwise multiplies this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise multiply with this one.</param>
/// <param name="result">The vector to store the result of the pointwise multiplication.</param>
protected abstract void DoPointwiseMultiply(Vector<T> other, Vector<T> result);
/// <summary>
/// Pointwise divide this vector with another vector.
/// </summary>
@ -764,13 +772,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
DoPointwiseDivide(other, result);
}
/// <summary>
/// Pointwise divide this vector with another vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to pointwise divide this one by.</param>
/// <param name="result">The result of the division.</param>
protected abstract void DoPointwiseDivide(Vector<T> other, Vector<T> result);
/// <summary>
/// Outer product of two vectors
/// </summary>

Loading…
Cancel
Save