Browse Source

LA: rework create matrix from diagonal array or vector

optimization-1
Christoph Ruegg 13 years ago
parent
commit
1d0c49086c
  1. 30
      src/FSharp/LinearAlgebra.Double.Matrix.fs
  2. 48
      src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
  3. 48
      src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
  4. 48
      src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
  5. 48
      src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
  6. 48
      src/Numerics/LinearAlgebra/Double/DenseMatrix.cs
  7. 48
      src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
  8. 48
      src/Numerics/LinearAlgebra/Single/DenseMatrix.cs
  9. 48
      src/Numerics/LinearAlgebra/Single/SparseMatrix.cs

30
src/FSharp/LinearAlgebra.Double.Matrix.fs

@ -135,14 +135,17 @@ module DenseMatrix =
/// Create a matrix with a given dimension from an indexed sequences of row, column, value tuples.
let inline ofSeqi (rows: int) (cols: int) (indexed: #seq<int * int * float>) = DenseMatrix.OfIndexed(rows, cols, indexed) :> _ Matrix
/// Create a square matrix with the vector elements on the diagonal.
let inline ofDiag (v: Vector<float>) = DenseMatrix.OfDiagonalVector(v) :> _ Matrix
/// Create a matrix with the vector elements on the diagonal.
let ofDiag2 (rows: int) (cols: int) (v: Vector<float>) =
let A = DenseMatrix(rows,cols)
A.SetDiagonal(v)
A :> _ Matrix
let inline ofDiag2 (rows: int) (cols: int) (v: Vector<float>) = DenseMatrix.OfDiagonalVector(rows, cols, v) :> _ Matrix
/// Create a square matrix with the vector elements on the diagonal.
let inline ofDiag (v: Vector<float>) = ofDiag2 v.Count v.Count v
/// Create a square matrix with the array elements on the diagonal.
let inline ofDiagArray (array: float array) = DenseMatrix.OfDiagonalArray(array) :> _ Matrix
/// Create a matrix with the array elements on the diagonal.
let inline ofDiagArray2 (rows: int) (cols: int) (array: float array) = DenseMatrix.OfDiagonalArray(rows, cols, array) :> _ Matrix
/// A module which implements functional sparse vector operations.
@ -212,11 +215,14 @@ module SparseMatrix =
/// Create a matrix with a given dimension from an indexed sequences of row, column, value tuples.
let inline ofSeqi (rows: int) (cols: int) (indexed: #seq<int * int * float>) = SparseMatrix.OfIndexed(rows, cols, indexed) :> _ Matrix
/// Create a square matrix with the vector elements on the diagonal.
let inline ofDiag (v: Vector<float>) = SparseMatrix.OfDiagonalVector(v) :> _ Matrix
/// Create a matrix with the vector elements on the diagonal.
let ofDiag2 (rows: int) (cols: int) (v: Vector<float>) =
let A = SparseMatrix(rows,cols)
A.SetDiagonal(v)
A :> _ Matrix
let inline ofDiag2 (rows: int) (cols: int) (v: Vector<float>) = SparseMatrix.OfDiagonalVector(rows, cols, v) :> _ Matrix
/// Create a square matrix with the vector elements on the diagonal.
let inline ofDiag (v: Vector<float>) = ofDiag2 v.Count v.Count v
/// Create a square matrix with the array elements on the diagonal.
let inline ofDiagArray (array: float array) = SparseMatrix.OfDiagonalArray(array) :> _ Matrix
/// Create a matrix with the array elements on the diagonal.
let inline ofDiagArray2 (rows: int) (cols: int) (array: float array) = SparseMatrix.OfDiagonalArray(rows, cols, array) :> _ Matrix

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

@ -234,6 +234,54 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return new DenseMatrix(DenseColumnMajorMatrixStorage<Complex>.OfRowVectors(storage));
}
/// <summary>
/// Create a new dense matrix with the diagonal as a copy of the given vector.
/// This new matrix will be independent from the vector.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfDiagonalVector(Vector<Complex> diagonal)
{
var m = new DenseMatrix(diagonal.Count, diagonal.Count);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new dense matrix with the diagonal as a copy of the given vector.
/// This new matrix will be independent from the vector.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfDiagonalVector(int rows, int columns, Vector<Complex> diagonal)
{
var m = new DenseMatrix(rows, columns);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new dense matrix with the diagonal as a copy of the given array.
/// This new matrix will be independent from the array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfDiagonalArray(Complex[] diagonal)
{
var m = new DenseMatrix(diagonal.Length, diagonal.Length);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new dense matrix with the diagonal as a copy of the given array.
/// This new matrix will be independent from the array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfDiagonalArray(int rows, int columns, Complex[] diagonal)
{
var m = new DenseMatrix(rows, columns);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new dense matrix and initialize each value to the same provided value.
/// </summary>

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

@ -223,6 +223,54 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return new SparseMatrix(SparseCompressedRowMatrixStorage<Complex>.OfRowVectors(storage));
}
/// <summary>
/// Create a new sparse matrix with the diagonal as a copy of the given vector.
/// This new matrix will be independent from the vector.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfDiagonalVector(Vector<Complex> diagonal)
{
var m = new SparseMatrix(diagonal.Count, diagonal.Count);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new sparse matrix with the diagonal as a copy of the given vector.
/// This new matrix will be independent from the vector.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfDiagonalVector(int rows, int columns, Vector<Complex> diagonal)
{
var m = new SparseMatrix(rows, columns);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new sparse matrix with the diagonal as a copy of the given array.
/// This new matrix will be independent from the array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfDiagonalArray(Complex[] diagonal)
{
var m = new SparseMatrix(diagonal.Length, diagonal.Length);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new sparse matrix with the diagonal as a copy of the given array.
/// This new matrix will be independent from the array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfDiagonalArray(int rows, int columns, Complex[] diagonal)
{
var m = new SparseMatrix(rows, columns);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new sparse matrix and initialize each value to the same provided value.
/// </summary>

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

@ -229,6 +229,54 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return new DenseMatrix(DenseColumnMajorMatrixStorage<Complex32>.OfRowVectors(storage));
}
/// <summary>
/// Create a new dense matrix with the diagonal as a copy of the given vector.
/// This new matrix will be independent from the vector.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfDiagonalVector(Vector<Complex32> diagonal)
{
var m = new DenseMatrix(diagonal.Count, diagonal.Count);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new dense matrix with the diagonal as a copy of the given vector.
/// This new matrix will be independent from the vector.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfDiagonalVector(int rows, int columns, Vector<Complex32> diagonal)
{
var m = new DenseMatrix(rows, columns);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new dense matrix with the diagonal as a copy of the given array.
/// This new matrix will be independent from the array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfDiagonalArray(Complex32[] diagonal)
{
var m = new DenseMatrix(diagonal.Length, diagonal.Length);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new dense matrix with the diagonal as a copy of the given array.
/// This new matrix will be independent from the array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfDiagonalArray(int rows, int columns, Complex32[] diagonal)
{
var m = new DenseMatrix(rows, columns);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new dense matrix and initialize each value to the same provided value.
/// </summary>

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

@ -218,6 +218,54 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return new SparseMatrix(SparseCompressedRowMatrixStorage<Complex32>.OfRowVectors(storage));
}
/// <summary>
/// Create a new sparse matrix with the diagonal as a copy of the given vector.
/// This new matrix will be independent from the vector.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfDiagonalVector(Vector<Complex32> diagonal)
{
var m = new SparseMatrix(diagonal.Count, diagonal.Count);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new sparse matrix with the diagonal as a copy of the given vector.
/// This new matrix will be independent from the vector.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfDiagonalVector(int rows, int columns, Vector<Complex32> diagonal)
{
var m = new SparseMatrix(rows, columns);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new sparse matrix with the diagonal as a copy of the given array.
/// This new matrix will be independent from the array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfDiagonalArray(Complex32[] diagonal)
{
var m = new SparseMatrix(diagonal.Length, diagonal.Length);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new sparse matrix with the diagonal as a copy of the given array.
/// This new matrix will be independent from the array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfDiagonalArray(int rows, int columns, Complex32[] diagonal)
{
var m = new SparseMatrix(rows, columns);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new sparse matrix and initialize each value to the same provided value.
/// </summary>

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

@ -227,6 +227,54 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return new DenseMatrix(DenseColumnMajorMatrixStorage<double>.OfRowVectors(storage));
}
/// <summary>
/// Create a new dense matrix with the diagonal as a copy of the given vector.
/// This new matrix will be independent from the vector.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfDiagonalVector(Vector<double> diagonal)
{
var m = new DenseMatrix(diagonal.Count, diagonal.Count);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new dense matrix with the diagonal as a copy of the given vector.
/// This new matrix will be independent from the vector.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfDiagonalVector(int rows, int columns, Vector<double> diagonal)
{
var m = new DenseMatrix(rows, columns);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new dense matrix with the diagonal as a copy of the given array.
/// This new matrix will be independent from the array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfDiagonalArray(double[] diagonal)
{
var m = new DenseMatrix(diagonal.Length, diagonal.Length);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new dense matrix with the diagonal as a copy of the given array.
/// This new matrix will be independent from the array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfDiagonalArray(int rows, int columns, double[] diagonal)
{
var m = new DenseMatrix(rows, columns);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new dense matrix and initialize each value to the same provided value.
/// </summary>

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

@ -216,6 +216,54 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return new SparseMatrix(SparseCompressedRowMatrixStorage<double>.OfRowVectors(storage));
}
/// <summary>
/// Create a new sparse matrix with the diagonal as a copy of the given vector.
/// This new matrix will be independent from the vector.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfDiagonalVector(Vector<double> diagonal)
{
var m = new SparseMatrix(diagonal.Count, diagonal.Count);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new sparse matrix with the diagonal as a copy of the given vector.
/// This new matrix will be independent from the vector.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfDiagonalVector(int rows, int columns, Vector<double> diagonal)
{
var m = new SparseMatrix(rows, columns);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new sparse matrix with the diagonal as a copy of the given array.
/// This new matrix will be independent from the array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfDiagonalArray(double[] diagonal)
{
var m = new SparseMatrix(diagonal.Length, diagonal.Length);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new sparse matrix with the diagonal as a copy of the given array.
/// This new matrix will be independent from the array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfDiagonalArray(int rows, int columns, double[] diagonal)
{
var m = new SparseMatrix(rows, columns);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new sparse matrix and initialize each value to the same provided value.
/// </summary>

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

@ -227,6 +227,54 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return new DenseMatrix(DenseColumnMajorMatrixStorage<float>.OfRowVectors(storage));
}
/// <summary>
/// Create a new dense matrix with the diagonal as a copy of the given vector.
/// This new matrix will be independent from the vector.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfDiagonalVector(Vector<float> diagonal)
{
var m = new DenseMatrix(diagonal.Count, diagonal.Count);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new dense matrix with the diagonal as a copy of the given vector.
/// This new matrix will be independent from the vector.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfDiagonalVector(int rows, int columns, Vector<float> diagonal)
{
var m = new DenseMatrix(rows, columns);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new dense matrix with the diagonal as a copy of the given array.
/// This new matrix will be independent from the array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfDiagonalArray(float[] diagonal)
{
var m = new DenseMatrix(diagonal.Length, diagonal.Length);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new dense matrix with the diagonal as a copy of the given array.
/// This new matrix will be independent from the array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfDiagonalArray(int rows, int columns, float[] diagonal)
{
var m = new DenseMatrix(rows, columns);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new dense matrix and initialize each value to the same provided value.
/// </summary>

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

@ -216,6 +216,54 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return new SparseMatrix(SparseCompressedRowMatrixStorage<float>.OfRowVectors(storage));
}
/// <summary>
/// Create a new sparse matrix with the diagonal as a copy of the given vector.
/// This new matrix will be independent from the vector.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfDiagonalVector(Vector<float> diagonal)
{
var m = new SparseMatrix(diagonal.Count, diagonal.Count);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new sparse matrix with the diagonal as a copy of the given vector.
/// This new matrix will be independent from the vector.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfDiagonalVector(int rows, int columns, Vector<float> diagonal)
{
var m = new SparseMatrix(rows, columns);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new sparse matrix with the diagonal as a copy of the given array.
/// This new matrix will be independent from the array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfDiagonalArray(float[] diagonal)
{
var m = new SparseMatrix(diagonal.Length, diagonal.Length);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new sparse matrix with the diagonal as a copy of the given array.
/// This new matrix will be independent from the array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfDiagonalArray(int rows, int columns, float[] diagonal)
{
var m = new SparseMatrix(rows, columns);
m.SetDiagonal(diagonal);
return m;
}
/// <summary>
/// Create a new sparse matrix and initialize each value to the same provided value.
/// </summary>

Loading…
Cancel
Save