Browse Source

Merge pull request #578 from RMAReader/master

SparseMatrix implementation of DoTransposeThisAndMultiply
pull/601/head
Christoph Ruegg 8 years ago
committed by GitHub
parent
commit
5c449a6959
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 29
      src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
  2. 29
      src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
  3. 29
      src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
  4. 29
      src/Numerics/LinearAlgebra/Single/SparseMatrix.cs

29
src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs

@ -1145,6 +1145,35 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
}
/// <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 override void DoTransposeThisAndMultiply(Vector<Complex> rightSide, Vector<Complex> result)
{
var rowPointers = _storage.RowPointers;
var columnIndices = _storage.ColumnIndices;
var values = _storage.Values;
for (var row = 0; row < RowCount; row++)
{
var startIndex = rowPointers[row];
var endIndex = rowPointers[row + 1];
if (startIndex == endIndex)
{
continue;
}
var rightSideValue = rightSide[row];
for (var index = startIndex; index < endIndex; index++)
{
result[columnIndices[index]] += values[index] * rightSideValue;
}
}
}
/// <summary>
/// Pointwise multiplies this matrix with another matrix and stores the result into the result matrix.
/// </summary>

29
src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs

@ -1144,6 +1144,35 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
}
/// <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 override void DoTransposeThisAndMultiply(Vector<Complex32> rightSide, Vector<Complex32> result)
{
var rowPointers = _storage.RowPointers;
var columnIndices = _storage.ColumnIndices;
var values = _storage.Values;
for (var row = 0; row < RowCount; row++)
{
var startIndex = rowPointers[row];
var endIndex = rowPointers[row + 1];
if (startIndex == endIndex)
{
continue;
}
var rightSideValue = rightSide[row];
for (var index = startIndex; index < endIndex; index++)
{
result[columnIndices[index]] += values[index] * rightSideValue;
}
}
}
/// <summary>
/// Pointwise multiplies this matrix with another matrix and stores the result into the result matrix.
/// </summary>

29
src/Numerics/LinearAlgebra/Double/SparseMatrix.cs

@ -1142,6 +1142,35 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
}
/// <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 override void DoTransposeThisAndMultiply(Vector<double> rightSide, Vector<double> result)
{
var rowPointers = _storage.RowPointers;
var columnIndices = _storage.ColumnIndices;
var values = _storage.Values;
for (var row = 0; row < RowCount; row++)
{
var startIndex = rowPointers[row];
var endIndex = rowPointers[row + 1];
if (startIndex == endIndex)
{
continue;
}
var rightSideValue = rightSide[row];
for (var index = startIndex; index < endIndex; index++)
{
result[columnIndices[index]] += values[index] * rightSideValue;
}
}
}
/// <summary>
/// Pointwise multiplies this matrix with another matrix and stores the result into the result matrix.
/// </summary>

29
src/Numerics/LinearAlgebra/Single/SparseMatrix.cs

@ -1147,6 +1147,35 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
}
/// <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 override void DoTransposeThisAndMultiply(Vector<float> rightSide, Vector<float> result)
{
var rowPointers = _storage.RowPointers;
var columnIndices = _storage.ColumnIndices;
var values = _storage.Values;
for (var row = 0; row < RowCount; row++)
{
var startIndex = rowPointers[row];
var endIndex = rowPointers[row + 1];
if (startIndex == endIndex)
{
continue;
}
var rightSideValue = rightSide[row];
for (var index = startIndex; index < endIndex; index++)
{
result[columnIndices[index]] += values[index] * rightSideValue;
}
}
}
/// <summary>
/// Pointwise multiplies this matrix with another matrix and stores the result into the result matrix.
/// </summary>

Loading…
Cancel
Save