Browse Source

LA: storage OfVector/OfMatrix

pull/112/head
Christoph Ruegg 14 years ago
parent
commit
29d2a3454e
  1. 4
      src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
  2. 3
      src/Numerics/LinearAlgebra/Complex/DenseVector.cs
  3. 12
      src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
  4. 4
      src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
  5. 3
      src/Numerics/LinearAlgebra/Complex/SparseVector.cs
  6. 4
      src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
  7. 3
      src/Numerics/LinearAlgebra/Complex32/DenseVector.cs
  8. 12
      src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
  9. 4
      src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
  10. 3
      src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
  11. 4
      src/Numerics/LinearAlgebra/Double/DenseMatrix.cs
  12. 3
      src/Numerics/LinearAlgebra/Double/DenseVector.cs
  13. 12
      src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
  14. 4
      src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
  15. 3
      src/Numerics/LinearAlgebra/Double/SparseVector.cs
  16. 4
      src/Numerics/LinearAlgebra/Single/DenseMatrix.cs
  17. 3
      src/Numerics/LinearAlgebra/Single/DenseVector.cs
  18. 12
      src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
  19. 4
      src/Numerics/LinearAlgebra/Single/SparseMatrix.cs
  20. 3
      src/Numerics/LinearAlgebra/Single/SparseVector.cs
  21. 7
      src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs
  22. 7
      src/Numerics/LinearAlgebra/Storage/DenseVectorStorage.cs
  23. 11
      src/Numerics/LinearAlgebra/Storage/DiagonalMatrixStorage.cs
  24. 7
      src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs
  25. 7
      src/Numerics/LinearAlgebra/Storage/SparseVectorStorage.cs

4
src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs

@ -121,9 +121,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// </summary>
public static DenseMatrix OfMatrix(Matrix<Complex> matrix)
{
var storage = new DenseColumnMajorMatrixStorage<Complex>(matrix.RowCount, matrix.ColumnCount);
matrix.Storage.CopyToUnchecked(storage, skipClearing: true);
return new DenseMatrix(storage);
return new DenseMatrix(DenseColumnMajorMatrixStorage<Complex>.OfMatrix(matrix.Storage));
}
/// <summary>

3
src/Numerics/LinearAlgebra/Complex/DenseVector.cs

@ -102,9 +102,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// A new memory block will be allocated for storing the vector.
/// </summary>
public DenseVector(Vector<Complex> other)
: this(other.Count)
: this(DenseVectorStorage<Complex>.OfVector(other.Storage))
{
other.Storage.CopyToUnchecked(Storage, skipClearing: true);
}
/// <summary>

12
src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs

@ -119,6 +119,17 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
{
}
/// <summary>
/// Create a new diagonal matrix as a copy of the given other matrix.
/// This new matrix will be independent from the other matrix.
/// The matrix to copy from must be diagonal as well.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DiagonalMatrix OfMatrix(Matrix<Complex> matrix)
{
return new DiagonalMatrix(DiagonalMatrixStorage<Complex>.OfMatrix(matrix.Storage));
}
/// <summary>
/// Create a new diagonal matrix as a copy of the given two-dimensional array.
/// This new matrix will be independent from the provided array.
@ -150,6 +161,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// The matrix to copy from must be diagonal as well.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
[Obsolete("Use DiagonalMatrix.OfMatrix instead. Scheduled for removal in v3.0.")]
public DiagonalMatrix(Matrix<Complex> matrix)
: this(matrix.RowCount, matrix.ColumnCount)
{

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

@ -99,9 +99,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// </summary>
public static SparseMatrix OfMatrix(Matrix<Complex> matrix)
{
var storage = new SparseCompressedRowMatrixStorage<Complex>(matrix.RowCount, matrix.ColumnCount);
matrix.Storage.CopyToUnchecked(storage, skipClearing: true);
return new SparseMatrix(storage);
return new SparseMatrix(SparseCompressedRowMatrixStorage<Complex>.OfMatrix(matrix.Storage));
}
/// <summary>

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

@ -113,9 +113,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// A new memory block will be allocated for storing the vector.
/// </summary>
public SparseVector(Vector<Complex> other)
: this(new SparseVectorStorage<Complex>(other.Count))
: this(SparseVectorStorage<Complex>.OfVector(other.Storage))
{
other.Storage.CopyToUnchecked(Storage, skipClearing: true);
}
/// <summary>

4
src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs

@ -121,9 +121,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// </summary>
public static DenseMatrix OfMatrix(Matrix<Complex32> matrix)
{
var storage = new DenseColumnMajorMatrixStorage<Complex32>(matrix.RowCount, matrix.ColumnCount);
matrix.Storage.CopyToUnchecked(storage, skipClearing: true);
return new DenseMatrix(storage);
return new DenseMatrix(DenseColumnMajorMatrixStorage<Complex32>.OfMatrix(matrix.Storage));
}
/// <summary>

3
src/Numerics/LinearAlgebra/Complex32/DenseVector.cs

@ -102,9 +102,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// A new memory block will be allocated for storing the vector.
/// </summary>
public DenseVector(Vector<Complex32> other)
: this(other.Count)
: this(DenseVectorStorage<Complex32>.OfVector(other.Storage))
{
other.Storage.CopyToUnchecked(Storage, skipClearing: true);
}
/// <summary>

12
src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs

@ -119,6 +119,17 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
{
}
/// <summary>
/// Create a new diagonal matrix as a copy of the given other matrix.
/// This new matrix will be independent from the other matrix.
/// The matrix to copy from must be diagonal as well.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DiagonalMatrix OfMatrix(Matrix<Complex32> matrix)
{
return new DiagonalMatrix(DiagonalMatrixStorage<Complex32>.OfMatrix(matrix.Storage));
}
/// <summary>
/// Create a new diagonal matrix as a copy of the given two-dimensional array.
/// This new matrix will be independent from the provided array.
@ -150,6 +161,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// The matrix to copy from must be diagonal as well.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
[Obsolete("Use DiagonalMatrix.OfMatrix instead. Scheduled for removal in v3.0.")]
public DiagonalMatrix(Matrix<Complex32> matrix)
: this(matrix.RowCount, matrix.ColumnCount)
{

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

@ -99,9 +99,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// </summary>
public static SparseMatrix OfMatrix(Matrix<Complex32> matrix)
{
var storage = new SparseCompressedRowMatrixStorage<Complex32>(matrix.RowCount, matrix.ColumnCount);
matrix.Storage.CopyToUnchecked(storage, skipClearing: true);
return new SparseMatrix(storage);
return new SparseMatrix(SparseCompressedRowMatrixStorage<Complex32>.OfMatrix(matrix.Storage));
}
/// <summary>

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

@ -113,9 +113,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// A new memory block will be allocated for storing the vector.
/// </summary>
public SparseVector(Vector<Complex32> other)
: this(new SparseVectorStorage<Complex32>(other.Count))
: this(SparseVectorStorage<Complex32>.OfVector(other.Storage))
{
other.Storage.CopyToUnchecked(Storage, skipClearing: true);
}
/// <summary>

4
src/Numerics/LinearAlgebra/Double/DenseMatrix.cs

@ -121,9 +121,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// </summary>
public static DenseMatrix OfMatrix(Matrix<double> matrix)
{
var storage = new DenseColumnMajorMatrixStorage<double>(matrix.RowCount, matrix.ColumnCount);
matrix.Storage.CopyToUnchecked(storage, skipClearing: true);
return new DenseMatrix(storage);
return new DenseMatrix(DenseColumnMajorMatrixStorage<double>.OfMatrix(matrix.Storage));
}
/// <summary>

3
src/Numerics/LinearAlgebra/Double/DenseVector.cs

@ -103,9 +103,8 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// A new memory block will be allocated for storing the vector.
/// </summary>
public DenseVector(Vector<double> other)
: this(other.Count)
: this(DenseVectorStorage<double>.OfVector(other.Storage))
{
other.Storage.CopyToUnchecked(Storage, skipClearing: true);
}
/// <summary>

12
src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs

@ -118,6 +118,17 @@ namespace MathNet.Numerics.LinearAlgebra.Double
{
}
/// <summary>
/// Create a new diagonal matrix as a copy of the given other matrix.
/// This new matrix will be independent from the other matrix.
/// The matrix to copy from must be diagonal as well.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DiagonalMatrix OfMatrix(Matrix<double> matrix)
{
return new DiagonalMatrix(DiagonalMatrixStorage<double>.OfMatrix(matrix.Storage));
}
/// <summary>
/// Create a new diagonal matrix as a copy of the given two-dimensional array.
/// This new matrix will be independent from the provided array.
@ -149,6 +160,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// The matrix to copy from must be diagonal as well.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
[Obsolete("Use DiagonalMatrix.OfMatrix instead. Scheduled for removal in v3.0.")]
public DiagonalMatrix(Matrix<double> matrix)
: this(matrix.RowCount, matrix.ColumnCount)
{

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

@ -98,9 +98,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// </summary>
public static SparseMatrix OfMatrix(Matrix<double> matrix)
{
var storage = new SparseCompressedRowMatrixStorage<double>(matrix.RowCount, matrix.ColumnCount);
matrix.Storage.CopyToUnchecked(storage, skipClearing: true);
return new SparseMatrix(storage);
return new SparseMatrix(SparseCompressedRowMatrixStorage<double>.OfMatrix(matrix.Storage));
}
/// <summary>

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

@ -113,9 +113,8 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// A new memory block will be allocated for storing the vector.
/// </summary>
public SparseVector(Vector<double> other)
: this(new SparseVectorStorage<double>(other.Count))
: this(SparseVectorStorage<double>.OfVector(other.Storage))
{
other.Storage.CopyToUnchecked(Storage, skipClearing: true);
}
/// <summary>

4
src/Numerics/LinearAlgebra/Single/DenseMatrix.cs

@ -121,9 +121,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// </summary>
public static DenseMatrix OfMatrix(Matrix<float> matrix)
{
var storage = new DenseColumnMajorMatrixStorage<float>(matrix.RowCount, matrix.ColumnCount);
matrix.Storage.CopyToUnchecked(storage, skipClearing: true);
return new DenseMatrix(storage);
return new DenseMatrix(DenseColumnMajorMatrixStorage<float>.OfMatrix(matrix.Storage));
}
/// <summary>

3
src/Numerics/LinearAlgebra/Single/DenseVector.cs

@ -102,9 +102,8 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// A new memory block will be allocated for storing the vector.
/// </summary>
public DenseVector(Vector<float> other)
: this(other.Count)
: this(DenseVectorStorage<float>.OfVector(other.Storage))
{
other.Storage.CopyToUnchecked(Storage, skipClearing: true);
}
/// <summary>

12
src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs

@ -118,6 +118,17 @@ namespace MathNet.Numerics.LinearAlgebra.Single
{
}
/// <summary>
/// Create a new diagonal matrix as a copy of the given other matrix.
/// This new matrix will be independent from the other matrix.
/// The matrix to copy from must be diagonal as well.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DiagonalMatrix OfMatrix(Matrix<float> matrix)
{
return new DiagonalMatrix(DiagonalMatrixStorage<float>.OfMatrix(matrix.Storage));
}
/// <summary>
/// Create a new diagonal matrix as a copy of the given two-dimensional array.
/// This new matrix will be independent from the provided array.
@ -149,6 +160,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// The matrix to copy from must be diagonal as well.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
[Obsolete("Use DiagonalMatrix.OfMatrix instead. Scheduled for removal in v3.0.")]
public DiagonalMatrix(Matrix<float> matrix)
: this(matrix.RowCount, matrix.ColumnCount)
{

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

@ -98,9 +98,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// </summary>
public static SparseMatrix OfMatrix(Matrix<float> matrix)
{
var storage = new SparseCompressedRowMatrixStorage<float>(matrix.RowCount, matrix.ColumnCount);
matrix.Storage.CopyToUnchecked(storage, skipClearing: true);
return new SparseMatrix(storage);
return new SparseMatrix(SparseCompressedRowMatrixStorage<float>.OfMatrix(matrix.Storage));
}
/// <summary>

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

@ -113,9 +113,8 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// A new memory block will be allocated for storing the vector.
/// </summary>
public SparseVector(Vector<float> other)
: this(new SparseVectorStorage<float>(other.Count))
: this(SparseVectorStorage<float>.OfVector(other.Storage))
{
other.Storage.CopyToUnchecked(Storage, skipClearing: true);
}
/// <summary>

7
src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs

@ -101,6 +101,13 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
// INITIALIZATION
public static DenseColumnMajorMatrixStorage<T> OfMatrix(MatrixStorage<T> matrix)
{
var storage = new DenseColumnMajorMatrixStorage<T>(matrix.RowCount, matrix.ColumnCount);
matrix.CopyToUnchecked(storage, skipClearing: true);
return storage;
}
public static DenseColumnMajorMatrixStorage<T> OfColumnMajorEnumerable(int rows, int columns, IEnumerable<T> data)
{
if (data == null)

7
src/Numerics/LinearAlgebra/Storage/DenseVectorStorage.cs

@ -92,6 +92,13 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
// INITIALIZATION
public static DenseVectorStorage<T> OfVector(VectorStorage<T> vector)
{
var storage = new DenseVectorStorage<T>(vector.Length);
vector.CopyToUnchecked(storage, skipClearing: true);
return storage;
}
public static DenseVectorStorage<T> OfEnumerable(IEnumerable<T> data)
{
if (data == null)

11
src/Numerics/LinearAlgebra/Storage/DiagonalMatrixStorage.cs

@ -170,6 +170,17 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return hash;
}
// INITIALIZATION
public static DiagonalMatrixStorage<T> OfMatrix(MatrixStorage<T> matrix)
{
var storage = new DiagonalMatrixStorage<T>(matrix.RowCount, matrix.ColumnCount);
matrix.CopyToUnchecked(storage, skipClearing: true);
return storage;
}
// MATRIX COPY
internal override void CopyToUnchecked(MatrixStorage<T> target, bool skipClearing = false)
{
var diagonalTarget = target as DiagonalMatrixStorage<T>;

7
src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs

@ -363,6 +363,13 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
// INITIALIZATION
public static SparseCompressedRowMatrixStorage<T> OfMatrix(MatrixStorage<T> matrix)
{
var storage = new SparseCompressedRowMatrixStorage<T>(matrix.RowCount, matrix.ColumnCount);
matrix.CopyToUnchecked(storage, skipClearing: true);
return storage;
}
public static SparseCompressedRowMatrixStorage<T> OfRowMajorEnumerable(int rows, int columns, IEnumerable<T> data)
{
if (data == null)

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

@ -284,6 +284,13 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
// INITIALIZATION
public static SparseVectorStorage<T> OfVector(VectorStorage<T> vector)
{
var storage = new SparseVectorStorage<T>(vector.Length);
vector.CopyToUnchecked(storage, skipClearing: true);
return storage;
}
public static SparseVectorStorage<T> OfEnumerable(IEnumerable<T> data)
{
if (data == null)

Loading…
Cancel
Save