diff --git a/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
index d0e3781d..5d5cfbaf 100644
--- a/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
@@ -327,6 +327,36 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
}
+ ///
+ /// 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 override void DoMultiply(Vector rightSide, Vector result)
+ {
+ var d = Math.Min(ColumnCount, RowCount);
+ if (d < RowCount)
+ {
+ result.ClearSubVector(ColumnCount, RowCount - ColumnCount);
+ }
+
+ if (d == ColumnCount)
+ {
+ var denseOther = rightSide.Storage as DenseVectorStorage;
+ var denseResult = result.Storage as DenseVectorStorage;
+ if (denseOther != null && denseResult != null)
+ {
+ Control.LinearAlgebraProvider.PointWiseMultiplyArrays(_data, denseOther.Data, denseResult.Data);
+ return;
+ }
+ }
+
+ for (var i = 0; i < d; i++)
+ {
+ result.At(i, _data[i]*rightSide.At(i));
+ }
+ }
+
///
/// Multiplies this matrix with another matrix and places the results into the result matrix.
///
@@ -372,131 +402,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
base.DoMultiply(other, result);
}
- ///
- /// Multiplies this matrix with a vector and places the results into the result matrix.
- ///
- /// The vector to multiply with.
- /// The result of the multiplication.
- /// If is .
- /// If is .
- /// If result.Count != this.RowCount.
- /// If this.ColumnCount != .Count.
- public override void Multiply(Vector rightSide, Vector result)
- {
- if (rightSide == null)
- {
- throw new ArgumentNullException("rightSide");
- }
-
- if (ColumnCount != rightSide.Count)
- {
- throw DimensionsDontMatch(this, rightSide, "rightSide");
- }
-
- if (result == null)
- {
- throw new ArgumentNullException("result");
- }
-
- if (RowCount != result.Count)
- {
- throw DimensionsDontMatch(this, result, "result");
- }
-
- if (ReferenceEquals(rightSide, result))
- {
- var tmp = result.CreateVector(result.Count);
- Multiply(rightSide, tmp);
- tmp.CopyTo(result);
- }
- else
- {
- // Clear the result vector
- result.Clear();
-
- // Multiply the elements in the vector with the corresponding diagonal element in this.
- for (var r = 0; r < _data.Length; r++)
- {
- result[r] = _data[r] * rightSide[r];
- }
- }
- }
-
- ///
- /// Left multiply a matrix with a vector ( = vector * matrix ) and place the result in the result vector.
- ///
- /// The vector to multiply with.
- /// The result of the multiplication.
- /// If is .
- /// If the result matrix is .
- /// If result.Count != this.ColumnCount.
- /// If this.RowCount != .Count.
- public override void LeftMultiply(Vector leftSide, Vector result)
- {
- if (leftSide == null)
- {
- throw new ArgumentNullException("leftSide");
- }
-
- if (RowCount != leftSide.Count)
- {
- throw DimensionsDontMatch(this, leftSide, "leftSide");
- }
-
- if (result == null)
- {
- throw new ArgumentNullException("result");
- }
-
- if (ColumnCount != result.Count)
- {
- throw DimensionsDontMatch(this, result, "result");
- }
-
- if (ReferenceEquals(leftSide, result))
- {
- var tmp = result.CreateVector(result.Count);
- LeftMultiply(leftSide, tmp);
- tmp.CopyTo(result);
- }
- else
- {
- // Clear the result vector
- result.Clear();
-
- // Multiply the elements in the vector with the corresponding diagonal element in this.
- for (var r = 0; r < _data.Length; r++)
- {
- result[r] = _data[r] * leftSide[r];
- }
- }
- }
-
- ///
- /// Computes the determinant of this matrix.
- ///
- /// The determinant of this matrix.
- public override Complex Determinant()
- {
- if (RowCount != ColumnCount)
- {
- throw new ArgumentException(Resources.ArgumentMatrixSquare);
- }
-
- return _data.Aggregate(Complex.One, (current, t) => current * t);
- }
-
- ///
- /// Returns the elements of the diagonal in a .
- ///
- /// The elements of the diagonal.
- /// For non-square matrices, the method returns Min(Rows, Columns) elements where
- /// i == j (i is the row index, and j is the column index).
- public override Vector Diagonal()
- {
- return new DenseVector(_data).Clone();
- }
-
///
/// Multiplies this matrix with transpose of another matrix and places the results into the result matrix.
///
@@ -586,6 +491,61 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
base.DoTransposeThisAndMultiply(other, 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 override void DoTransposeThisAndMultiply(Vector rightSide, Vector result)
+ {
+ var d = Math.Min(ColumnCount, RowCount);
+ if (d < ColumnCount)
+ {
+ result.ClearSubVector(RowCount, ColumnCount - RowCount);
+ }
+
+ if (d == RowCount)
+ {
+ var denseOther = rightSide.Storage as DenseVectorStorage;
+ var denseResult = result.Storage as DenseVectorStorage;
+ if (denseOther != null && denseResult != null)
+ {
+ Control.LinearAlgebraProvider.PointWiseMultiplyArrays(_data, denseOther.Data, denseResult.Data);
+ return;
+ }
+ }
+
+ for (var i = 0; i < d; i++)
+ {
+ result.At(i, _data[i]*rightSide.At(i));
+ }
+ }
+
+ ///
+ /// Computes the determinant of this matrix.
+ ///
+ /// The determinant of this matrix.
+ public override Complex Determinant()
+ {
+ if (RowCount != ColumnCount)
+ {
+ throw new ArgumentException(Resources.ArgumentMatrixSquare);
+ }
+
+ return _data.Aggregate(Complex.One, (current, t) => current * t);
+ }
+
+ ///
+ /// Returns the elements of the diagonal in a .
+ ///
+ /// The elements of the diagonal.
+ /// For non-square matrices, the method returns Min(Rows, Columns) elements where
+ /// i == j (i is the row index, and j is the column index).
+ public override Vector Diagonal()
+ {
+ return new DenseVector(_data).Clone();
+ }
+
///
/// Returns the transpose of this matrix.
///
diff --git a/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
index 91ccf693..4f3c3b97 100644
--- a/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
@@ -320,6 +320,36 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
}
+ ///
+ /// 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 override void DoMultiply(Vector rightSide, Vector result)
+ {
+ var d = Math.Min(ColumnCount, RowCount);
+ if (d < RowCount)
+ {
+ result.ClearSubVector(ColumnCount, RowCount - ColumnCount);
+ }
+
+ if (d == ColumnCount)
+ {
+ var denseOther = rightSide.Storage as DenseVectorStorage;
+ var denseResult = result.Storage as DenseVectorStorage;
+ if (denseOther != null && denseResult != null)
+ {
+ Control.LinearAlgebraProvider.PointWiseMultiplyArrays(_data, denseOther.Data, denseResult.Data);
+ return;
+ }
+ }
+
+ for (var i = 0; i < d; i++)
+ {
+ result.At(i, _data[i]*rightSide.At(i));
+ }
+ }
+
///
/// Multiplies this matrix with another matrix and places the results into the result matrix.
///
@@ -365,131 +395,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
base.DoMultiply(other, result);
}
- ///
- /// Multiplies this matrix with a vector and places the results into the result matrix.
- ///
- /// The vector to multiply with.
- /// The result of the multiplication.
- /// If is .
- /// If is .
- /// If result.Count != this.RowCount.
- /// If this.ColumnCount != .Count.
- public override void Multiply(Vector rightSide, Vector result)
- {
- if (rightSide == null)
- {
- throw new ArgumentNullException("rightSide");
- }
-
- if (ColumnCount != rightSide.Count)
- {
- throw DimensionsDontMatch(this, rightSide, "rightSide");
- }
-
- if (result == null)
- {
- throw new ArgumentNullException("result");
- }
-
- if (RowCount != result.Count)
- {
- throw DimensionsDontMatch(this, result, "result");
- }
-
- if (ReferenceEquals(rightSide, result))
- {
- var tmp = result.CreateVector(result.Count);
- Multiply(rightSide, tmp);
- tmp.CopyTo(result);
- }
- else
- {
- // Clear the result vector
- result.Clear();
-
- // Multiply the elements in the vector with the corresponding diagonal element in this.
- for (var r = 0; r < _data.Length; r++)
- {
- result[r] = _data[r] * rightSide[r];
- }
- }
- }
-
- ///
- /// Left multiply a matrix with a vector ( = vector * matrix ) and place the result in the result vector.
- ///
- /// The vector to multiply with.
- /// The result of the multiplication.
- /// If is .
- /// If the result matrix is .
- /// If result.Count != this.ColumnCount.
- /// If this.RowCount != .Count.
- public override void LeftMultiply(Vector leftSide, Vector result)
- {
- if (leftSide == null)
- {
- throw new ArgumentNullException("leftSide");
- }
-
- if (RowCount != leftSide.Count)
- {
- throw DimensionsDontMatch(this, leftSide, "leftSide");
- }
-
- if (result == null)
- {
- throw new ArgumentNullException("result");
- }
-
- if (ColumnCount != result.Count)
- {
- throw DimensionsDontMatch(this, result, "result");
- }
-
- if (ReferenceEquals(leftSide, result))
- {
- var tmp = result.CreateVector(result.Count);
- LeftMultiply(leftSide, tmp);
- tmp.CopyTo(result);
- }
- else
- {
- // Clear the result vector
- result.Clear();
-
- // Multiply the elements in the vector with the corresponding diagonal element in this.
- for (var r = 0; r < _data.Length; r++)
- {
- result[r] = _data[r] * leftSide[r];
- }
- }
- }
-
- ///
- /// Computes the determinant of this matrix.
- ///
- /// The determinant of this matrix.
- public override Complex32 Determinant()
- {
- if (RowCount != ColumnCount)
- {
- throw new ArgumentException(Resources.ArgumentMatrixSquare);
- }
-
- return _data.Aggregate(Complex32.One, (current, t) => current * t);
- }
-
- ///
- /// Returns the elements of the diagonal in a .
- ///
- /// The elements of the diagonal.
- /// For non-square matrices, the method returns Min(Rows, Columns) elements where
- /// i == j (i is the row index, and j is the column index).
- public override Vector Diagonal()
- {
- return new DenseVector(_data).Clone();
- }
-
///
/// Multiplies this matrix with transpose of another matrix and places the results into the result matrix.
///
@@ -579,6 +484,61 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
base.DoTransposeThisAndMultiply(other, 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 override void DoTransposeThisAndMultiply(Vector rightSide, Vector result)
+ {
+ var d = Math.Min(ColumnCount, RowCount);
+ if (d < ColumnCount)
+ {
+ result.ClearSubVector(RowCount, ColumnCount - RowCount);
+ }
+
+ if (d == RowCount)
+ {
+ var denseOther = rightSide.Storage as DenseVectorStorage;
+ var denseResult = result.Storage as DenseVectorStorage;
+ if (denseOther != null && denseResult != null)
+ {
+ Control.LinearAlgebraProvider.PointWiseMultiplyArrays(_data, denseOther.Data, denseResult.Data);
+ return;
+ }
+ }
+
+ for (var i = 0; i < d; i++)
+ {
+ result.At(i, _data[i]*rightSide.At(i));
+ }
+ }
+
+ ///
+ /// Computes the determinant of this matrix.
+ ///
+ /// The determinant of this matrix.
+ public override Complex32 Determinant()
+ {
+ if (RowCount != ColumnCount)
+ {
+ throw new ArgumentException(Resources.ArgumentMatrixSquare);
+ }
+
+ return _data.Aggregate(Complex32.One, (current, t) => current * t);
+ }
+
+ ///
+ /// Returns the elements of the diagonal in a .
+ ///
+ /// The elements of the diagonal.
+ /// For non-square matrices, the method returns Min(Rows, Columns) elements where
+ /// i == j (i is the row index, and j is the column index).
+ public override Vector Diagonal()
+ {
+ return new DenseVector(_data).Clone();
+ }
+
///
/// Returns the transpose of this matrix.
///
diff --git a/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
index 2e0b8216..81ad1356 100644
--- a/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
@@ -321,6 +321,36 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
}
+ ///
+ /// 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 override void DoMultiply(Vector rightSide, Vector result)
+ {
+ var d = Math.Min(ColumnCount, RowCount);
+ if (d < RowCount)
+ {
+ result.ClearSubVector(ColumnCount, RowCount - ColumnCount);
+ }
+
+ if (d == ColumnCount)
+ {
+ var denseOther = rightSide.Storage as DenseVectorStorage;
+ var denseResult = result.Storage as DenseVectorStorage;
+ if (denseOther != null && denseResult != null)
+ {
+ Control.LinearAlgebraProvider.PointWiseMultiplyArrays(_data, denseOther.Data, denseResult.Data);
+ return;
+ }
+ }
+
+ for (var i = 0; i < d; i++)
+ {
+ result.At(i, _data[i]*rightSide.At(i));
+ }
+ }
+
///
/// Multiplies this matrix with another matrix and places the results into the result matrix.
///
@@ -366,131 +396,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
base.DoMultiply(other, result);
}
- ///
- /// Multiplies this matrix with a vector and places the results into the result matrix.
- ///
- /// The vector to multiply with.
- /// The result of the multiplication.
- /// If is .
- /// If is .
- /// If result.Count != this.RowCount.
- /// If this.ColumnCount != .Count.
- public override void Multiply(Vector rightSide, Vector result)
- {
- if (rightSide == null)
- {
- throw new ArgumentNullException("rightSide");
- }
-
- if (ColumnCount != rightSide.Count)
- {
- throw DimensionsDontMatch(this, rightSide);
- }
-
- if (result == null)
- {
- throw new ArgumentNullException("result");
- }
-
- if (RowCount != result.Count)
- {
- throw DimensionsDontMatch(this, result, "result");
- }
-
- if (ReferenceEquals(rightSide, result))
- {
- var tmp = result.CreateVector(result.Count);
- Multiply(rightSide, tmp);
- tmp.CopyTo(result);
- }
- else
- {
- // Clear the result vector
- result.Clear();
-
- // Multiply the elements in the vector with the corresponding diagonal element in this.
- for (var r = 0; r < _data.Length; r++)
- {
- result[r] = _data[r] * rightSide[r];
- }
- }
- }
-
- ///
- /// Left multiply a matrix with a vector ( = vector * matrix ) and place the result in the result vector.
- ///
- /// The vector to multiply with.
- /// The result of the multiplication.
- /// If is .
- /// If the result matrix is .
- /// If result.Count != this.ColumnCount.
- /// If this.RowCount != .Count.
- public override void LeftMultiply(Vector leftSide, Vector result)
- {
- if (leftSide == null)
- {
- throw new ArgumentNullException("leftSide");
- }
-
- if (RowCount != leftSide.Count)
- {
- throw DimensionsDontMatch(this, leftSide, "leftSide");
- }
-
- if (result == null)
- {
- throw new ArgumentNullException("result");
- }
-
- if (ColumnCount != result.Count)
- {
- throw DimensionsDontMatch(this, result, "result");
- }
-
- if (ReferenceEquals(leftSide, result))
- {
- var tmp = result.CreateVector(result.Count);
- LeftMultiply(leftSide, tmp);
- tmp.CopyTo(result);
- }
- else
- {
- // Clear the result vector
- result.Clear();
-
- // Multiply the elements in the vector with the corresponding diagonal element in this.
- for (var r = 0; r < _data.Length; r++)
- {
- result[r] = _data[r] * leftSide[r];
- }
- }
- }
-
- ///
- /// Computes the determinant of this matrix.
- ///
- /// The determinant of this matrix.
- public override double Determinant()
- {
- if (RowCount != ColumnCount)
- {
- throw new ArgumentException(Resources.ArgumentMatrixSquare);
- }
-
- return _data.Aggregate(1.0, (current, t) => current * t);
- }
-
- ///
- /// Returns the elements of the diagonal in a .
- ///
- /// The elements of the diagonal.
- /// For non-square matrices, the method returns Min(Rows, Columns) elements where
- /// i == j (i is the row index, and j is the column index).
- public override Vector Diagonal()
- {
- return new DenseVector(_data).Clone();
- }
-
///
/// Multiplies this matrix with transpose of another matrix and places the results into the result matrix.
///
@@ -580,6 +485,61 @@ namespace MathNet.Numerics.LinearAlgebra.Double
base.DoTransposeThisAndMultiply(other, 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 override void DoTransposeThisAndMultiply(Vector rightSide, Vector result)
+ {
+ var d = Math.Min(ColumnCount, RowCount);
+ if (d < ColumnCount)
+ {
+ result.ClearSubVector(RowCount, ColumnCount - RowCount);
+ }
+
+ if (d == RowCount)
+ {
+ var denseOther = rightSide.Storage as DenseVectorStorage;
+ var denseResult = result.Storage as DenseVectorStorage;
+ if (denseOther != null && denseResult != null)
+ {
+ Control.LinearAlgebraProvider.PointWiseMultiplyArrays(_data, denseOther.Data, denseResult.Data);
+ return;
+ }
+ }
+
+ for (var i = 0; i < d; i++)
+ {
+ result.At(i, _data[i]*rightSide.At(i));
+ }
+ }
+
+ ///
+ /// Computes the determinant of this matrix.
+ ///
+ /// The determinant of this matrix.
+ public override double Determinant()
+ {
+ if (RowCount != ColumnCount)
+ {
+ throw new ArgumentException(Resources.ArgumentMatrixSquare);
+ }
+
+ return _data.Aggregate(1.0, (current, t) => current * t);
+ }
+
+ ///
+ /// Returns the elements of the diagonal in a .
+ ///
+ /// The elements of the diagonal.
+ /// For non-square matrices, the method returns Min(Rows, Columns) elements where
+ /// i == j (i is the row index, and j is the column index).
+ public override Vector Diagonal()
+ {
+ return new DenseVector(_data).Clone();
+ }
+
///
/// Returns the transpose of this matrix.
///
diff --git a/src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs b/src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs
index bd36f09a..3a976ecc 100644
--- a/src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs
+++ b/src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs
@@ -543,7 +543,7 @@ namespace MathNet.Numerics.LinearAlgebra
/// The result of the multiplication.
/// If result.Count != this.RowCount.
/// If this.ColumnCount != .Count.
- public virtual void Multiply(Vector rightSide, Vector result)
+ public void Multiply(Vector rightSide, Vector result)
{
if (ColumnCount != rightSide.Count)
{
@@ -592,7 +592,7 @@ namespace MathNet.Numerics.LinearAlgebra
/// The result of the multiplication.
/// If result.Count != this.ColumnCount.
/// If this.RowCount != .Count.
- public virtual void LeftMultiply(Vector leftSide, Vector result)
+ public void LeftMultiply(Vector leftSide, Vector result)
{
if (RowCount != leftSide.Count)
{
diff --git a/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
index 381a3f41..78288526 100644
--- a/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
@@ -321,6 +321,36 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
}
+ ///
+ /// 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 override void DoMultiply(Vector rightSide, Vector result)
+ {
+ var d = Math.Min(ColumnCount, RowCount);
+ if (d < RowCount)
+ {
+ result.ClearSubVector(ColumnCount, RowCount - ColumnCount);
+ }
+
+ if (d == ColumnCount)
+ {
+ var denseOther = rightSide.Storage as DenseVectorStorage;
+ var denseResult = result.Storage as DenseVectorStorage;
+ if (denseOther != null && denseResult != null)
+ {
+ Control.LinearAlgebraProvider.PointWiseMultiplyArrays(_data, denseOther.Data, denseResult.Data);
+ return;
+ }
+ }
+
+ for (var i = 0; i < d; i++)
+ {
+ result.At(i, _data[i]*rightSide.At(i));
+ }
+ }
+
///
/// Multiplies this matrix with another matrix and places the results into the result matrix.
///
@@ -366,131 +396,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
base.DoMultiply(other, result);
}
- ///
- /// Multiplies this matrix with a vector and places the results into the result matrix.
- ///
- /// The vector to multiply with.
- /// The result of the multiplication.
- /// If is .
- /// If is .
- /// If result.Count != this.RowCount.
- /// If this.ColumnCount != .Count.
- public override void Multiply(Vector rightSide, Vector result)
- {
- if (rightSide == null)
- {
- throw new ArgumentNullException("rightSide");
- }
-
- if (ColumnCount != rightSide.Count)
- {
- throw DimensionsDontMatch(this, rightSide, "rightSide");
- }
-
- if (result == null)
- {
- throw new ArgumentNullException("result");
- }
-
- if (RowCount != result.Count)
- {
- throw DimensionsDontMatch(this, result, "result");
- }
-
- if (ReferenceEquals(rightSide, result))
- {
- var tmp = result.CreateVector(result.Count);
- Multiply(rightSide, tmp);
- tmp.CopyTo(result);
- }
- else
- {
- // Clear the result vector
- result.Clear();
-
- // Multiply the elements in the vector with the corresponding diagonal element in this.
- for (var r = 0; r < _data.Length; r++)
- {
- result[r] = _data[r] * rightSide[r];
- }
- }
- }
-
- ///
- /// Left multiply a matrix with a vector ( = vector * matrix ) and place the result in the result vector.
- ///
- /// The vector to multiply with.
- /// The result of the multiplication.
- /// If is .
- /// If the result matrix is .
- /// If result.Count != this.ColumnCount.
- /// If this.RowCount != .Count.
- public override void LeftMultiply(Vector leftSide, Vector result)
- {
- if (leftSide == null)
- {
- throw new ArgumentNullException("leftSide");
- }
-
- if (RowCount != leftSide.Count)
- {
- throw DimensionsDontMatch(this, leftSide, "leftSide");
- }
-
- if (result == null)
- {
- throw new ArgumentNullException("result");
- }
-
- if (ColumnCount != result.Count)
- {
- throw DimensionsDontMatch(this, result, "result");
- }
-
- if (ReferenceEquals(leftSide, result))
- {
- var tmp = result.CreateVector(result.Count);
- LeftMultiply(leftSide, tmp);
- tmp.CopyTo(result);
- }
- else
- {
- // Clear the result vector
- result.Clear();
-
- // Multiply the elements in the vector with the corresponding diagonal element in this.
- for (var r = 0; r < _data.Length; r++)
- {
- result[r] = _data[r] * leftSide[r];
- }
- }
- }
-
- ///
- /// Computes the determinant of this matrix.
- ///
- /// The determinant of this matrix.
- public override float Determinant()
- {
- if (RowCount != ColumnCount)
- {
- throw new ArgumentException(Resources.ArgumentMatrixSquare);
- }
-
- return _data.Aggregate(1.0f, (current, t) => current * t);
- }
-
- ///
- /// Returns the elements of the diagonal in a .
- ///
- /// The elements of the diagonal.
- /// For non-square matrices, the method returns Min(Rows, Columns) elements where
- /// i == j (i is the row index, and j is the column index).
- public override Vector Diagonal()
- {
- return new DenseVector(_data).Clone();
- }
-
///
/// Multiplies this matrix with transpose of another matrix and places the results into the result matrix.
///
@@ -580,6 +485,61 @@ namespace MathNet.Numerics.LinearAlgebra.Single
base.DoTransposeThisAndMultiply(other, 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 override void DoTransposeThisAndMultiply(Vector rightSide, Vector result)
+ {
+ var d = Math.Min(ColumnCount, RowCount);
+ if (d < ColumnCount)
+ {
+ result.ClearSubVector(RowCount, ColumnCount - RowCount);
+ }
+
+ if (d == RowCount)
+ {
+ var denseOther = rightSide.Storage as DenseVectorStorage;
+ var denseResult = result.Storage as DenseVectorStorage;
+ if (denseOther != null && denseResult != null)
+ {
+ Control.LinearAlgebraProvider.PointWiseMultiplyArrays(_data, denseOther.Data, denseResult.Data);
+ return;
+ }
+ }
+
+ for (var i = 0; i < d; i++)
+ {
+ result.At(i, _data[i]*rightSide.At(i));
+ }
+ }
+
+ ///
+ /// Computes the determinant of this matrix.
+ ///
+ /// The determinant of this matrix.
+ public override float Determinant()
+ {
+ if (RowCount != ColumnCount)
+ {
+ throw new ArgumentException(Resources.ArgumentMatrixSquare);
+ }
+
+ return _data.Aggregate(1.0f, (current, t) => current * t);
+ }
+
+ ///
+ /// Returns the elements of the diagonal in a .
+ ///
+ /// The elements of the diagonal.
+ /// For non-square matrices, the method returns Min(Rows, Columns) elements where
+ /// i == j (i is the row index, and j is the column index).
+ public override Vector Diagonal()
+ {
+ return new DenseVector(_data).Clone();
+ }
+
///
/// Returns the transpose of this matrix.
///