Browse Source

LA: Drop redundant sparse vector ToColumn/RowMatrix overrides

pull/98/head
Christoph Ruegg 13 years ago
parent
commit
418cb8cf22
  1. 30
      src/Numerics/LinearAlgebra/Complex/SparseVector.cs
  2. 30
      src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
  3. 36
      src/Numerics/LinearAlgebra/Double/SparseVector.cs
  4. 4
      src/Numerics/LinearAlgebra/Generic/Vector.cs
  5. 30
      src/Numerics/LinearAlgebra/Single/SparseVector.cs
  6. 40
      src/Numerics/LinearAlgebra/Storage/SparseVectorStorage.cs

30
src/Numerics/LinearAlgebra/Complex/SparseVector.cs

@ -145,36 +145,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
#endregion
/// <summary>
/// Create a matrix based on this vector in column form (one single column).
/// </summary>
/// <returns>This vector as a column matrix.</returns>
public override Matrix<Complex> ToColumnMatrix()
{
var matrix = new SparseMatrix(Count, 1);
for (var i = 0; i < _storage.ValueCount; i++)
{
matrix.At(_storage.Indices[i], 0, _storage.Values[i]);
}
return matrix;
}
/// <summary>
/// Create a matrix based on this vector in row form (one single row).
/// </summary>
/// <returns>This vector as a row matrix.</returns>
public override Matrix<Complex> ToRowMatrix()
{
var matrix = new SparseMatrix(1, Count);
for (var i = 0; i < _storage.ValueCount; i++)
{
matrix.At(0, _storage.Indices[i], _storage.Values[i]);
}
return matrix;
}
/// <summary>
/// Creates a matrix with the given dimensions using the same storage type
/// as this vector.

30
src/Numerics/LinearAlgebra/Complex32/SparseVector.cs

@ -145,36 +145,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
#endregion
/// <summary>
/// Create a matrix based on this vector in column form (one single column).
/// </summary>
/// <returns>This vector as a column matrix.</returns>
public override Matrix<Complex32> ToColumnMatrix()
{
var matrix = new SparseMatrix(Count, 1);
for (var i = 0; i < _storage.ValueCount; i++)
{
matrix.At(_storage.Indices[i], 0, _storage.Values[i]);
}
return matrix;
}
/// <summary>
/// Create a matrix based on this vector in row form (one single row).
/// </summary>
/// <returns>This vector as a row matrix.</returns>
public override Matrix<Complex32> ToRowMatrix()
{
var matrix = new SparseMatrix(1, Count);
for (var i = 0; i < _storage.ValueCount; i++)
{
matrix.At(0, _storage.Indices[i], _storage.Values[i]);
}
return matrix;
}
/// <summary>
/// Creates a matrix with the given dimensions using the same storage type
/// as this vector.

36
src/Numerics/LinearAlgebra/Double/SparseVector.cs

@ -145,42 +145,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
#endregion
/// <summary>
/// Create a matrix based on this vector in column form (one single column).
/// </summary>
/// <returns>This vector as a column matrix.</returns>
public override Matrix<double> ToColumnMatrix()
{
var indices = _storage.Indices;
var values = _storage.Values;
var matrix = new SparseMatrix(Count, 1);
for (var i = 0; i < _storage.ValueCount; i++)
{
matrix.At(indices[i], 0, values[i]);
}
return matrix;
}
/// <summary>
/// Create a matrix based on this vector in row form (one single row).
/// </summary>
/// <returns>This vector as a row matrix.</returns>
public override Matrix<double> ToRowMatrix()
{
var indices = _storage.Indices;
var values = _storage.Values;
var matrix = new SparseMatrix(1, Count);
for (var i = 0; i < _storage.ValueCount; i++)
{
matrix.At(0, indices[i], values[i]);
}
return matrix;
}
/// <summary>
/// Creates a matrix with the given dimensions using the same storage type
/// as this vector.

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

@ -1173,7 +1173,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <returns>
/// This vector as a column matrix.
/// </returns>
public virtual Matrix<T> ToColumnMatrix()
public Matrix<T> ToColumnMatrix()
{
var result = CreateMatrix(Count, 1);
Storage.CopyToColumnUnchecked(result.Storage, 0, skipClearing: true);
@ -1186,7 +1186,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <returns>
/// This vector as a row matrix.
/// </returns>
public virtual Matrix<T> ToRowMatrix()
public Matrix<T> ToRowMatrix()
{
var result = CreateMatrix(1, Count);
Storage.CopyToRowUnchecked(result.Storage, 0, skipClearing: true);

30
src/Numerics/LinearAlgebra/Single/SparseVector.cs

@ -145,36 +145,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
#endregion
/// <summary>
/// Create a matrix based on this vector in column form (one single column).
/// </summary>
/// <returns>This vector as a column matrix.</returns>
public override Matrix<float> ToColumnMatrix()
{
var matrix = new SparseMatrix(Count, 1);
for (var i = 0; i < _storage.ValueCount; i++)
{
matrix.At(_storage.Indices[i], 0, _storage.Values[i]);
}
return matrix;
}
/// <summary>
/// Create a matrix based on this vector in row form (one single row).
/// </summary>
/// <returns>This vector as a row matrix.</returns>
public override Matrix<float> ToRowMatrix()
{
var matrix = new SparseMatrix(1, Count);
for (var i = 0; i < _storage.ValueCount; i++)
{
matrix.At(0, _storage.Indices[i], _storage.Values[i]);
}
return matrix;
}
/// <summary>
/// Creates a matrix with the given dimensions using the same storage type
/// as this vector.

40
src/Numerics/LinearAlgebra/Storage/SparseVectorStorage.cs

@ -335,6 +335,46 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
}
}
// Row COPY
internal override void CopyToRowUnchecked(MatrixStorage<T> target, int rowIndex, bool skipClearing = false)
{
if (!skipClearing)
{
target.Clear(rowIndex, 1, 0, Length);
}
if (ValueCount == 0)
{
return;
}
for (int i = 0; i < ValueCount; i++)
{
target.At(rowIndex, Indices[i], Values[i]);
}
}
// COLUMN COPY
internal override void CopyToColumnUnchecked(MatrixStorage<T> target, int columnIndex, bool skipClearing = false)
{
if (!skipClearing)
{
target.Clear(0, Length, columnIndex, 1);
}
if (ValueCount == 0)
{
return;
}
for (int i = 0; i < ValueCount; i++)
{
target.At(Indices[i], columnIndex, Values[i]);
}
}
// SUB-VECTOR COPY
internal override void CopySubVectorToUnchecked(VectorStorage<T> target,

Loading…
Cancel
Save