Browse Source

LA: create of column/row arrays/vectors IEnumerable overload #139; F# workaround no longer needed

pull/163/head
Christoph Ruegg 13 years ago
parent
commit
a5503f8563
  1. 21
      src/FSharp/LinearAlgebra.Matrix.fs
  2. 2
      src/FSharp/LinearAlgebra.Vector.fs
  3. 80
      src/Numerics/LinearAlgebra/Builder.cs
  4. 40
      src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
  5. 40
      src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
  6. 40
      src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
  7. 40
      src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
  8. 40
      src/Numerics/LinearAlgebra/Double/DenseMatrix.cs
  9. 40
      src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
  10. 40
      src/Numerics/LinearAlgebra/Single/DenseMatrix.cs
  11. 40
      src/Numerics/LinearAlgebra/Single/SparseMatrix.cs

21
src/FSharp/LinearAlgebra.Matrix.fs

@ -346,19 +346,6 @@ module Matrix =
// Workaround an issue when passing generic arguments to a params-array. Get rid of this once we're on F# > 3.1.
type internal ParamsInvokeWorkaround<'T when 'T : (new: unit -> 'T) and 'T: struct and 'T :> ValueType and 'T :> IEquatable<'T> and 'T :> IFormattable> private ()=
static let build = Matrix<'T>.Build
static let dr = Delegate.CreateDelegate(typeof<Func<'T[][],Matrix<'T>>>, build, typeof<Builder<'T>>.GetMethod("DenseMatrixOfRowArrays")) :?> Func<'T[][],Matrix<'T>>
static let dc = Delegate.CreateDelegate(typeof<Func<'T[][],Matrix<'T>>>, build, typeof<Builder<'T>>.GetMethod("DenseMatrixOfColumnArrays")) :?> Func<'T[][],Matrix<'T>>
static let sr = Delegate.CreateDelegate(typeof<Func<'T[][],Matrix<'T>>>, build, typeof<Builder<'T>>.GetMethod("SparseMatrixOfRowArrays")) :?> Func<'T[][],Matrix<'T>>
static let sc = Delegate.CreateDelegate(typeof<Func<'T[][],Matrix<'T>>>, build, typeof<Builder<'T>>.GetMethod("SparseMatrixOfColumnArrays")) :?> Func<'T[][],Matrix<'T>>
static member DenseMatrixOfRowArrays(array) = dr.Invoke array
static member DenseMatrixOfColumnArrays(array) = dc.Invoke array
static member SparseMatrixOfRowArrays(array) = sr.Invoke array
static member SparseMatrixOfColumnArrays(array) = sc.Invoke array
/// A module which helps constructing generic dense matrices.
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module DenseMatrix =
@ -400,7 +387,7 @@ module DenseMatrix =
let inline ofRows (rows: Vector<'T> list) = Matrix<'T>.Build.DenseMatrixOfRowVectors(Array.ofList rows)
/// Create a matrix from a list of row arrays.
let ofRowArrays (rows: 'T[][]) = ParamsInvokeWorkaround<'T>.DenseMatrixOfRowArrays(rows)
let inline ofRowArrays (rows: 'T[][]) = Matrix<'T>.Build.DenseMatrixOfRowArrays(rows :> seq<'T[]>) // workaround params issue - impl detects it's actually an array
/// Create a matrix from a list of float lists. Every list in the master list specifies a row.
let inline ofRowList (rows: 'T list list) = rows |> List.map List.toArray |> List.toArray |> ofRowArrays
@ -415,7 +402,7 @@ module DenseMatrix =
let inline ofColumns (columns: Vector<'T> list) = Matrix<'T>.Build.DenseMatrixOfColumnVectors(Array.ofList columns)
/// Create a matrix from a list of column arrays.
let ofColumnArrays (columns: 'T[][]) = ParamsInvokeWorkaround<'T>.DenseMatrixOfColumnArrays(columns)
let inline ofColumnArrays (columns: 'T[][]) = Matrix<'T>.Build.DenseMatrixOfColumnArrays(columns :> seq<'T[]>) // workaround params issue - impl detects it's actually an array
/// Create a matrix from a list of float lists. Every list in the master list specifies a column.
let inline ofColumnList (columns: 'T list list) = columns |> List.map List.toArray |> List.toArray |> ofColumnArrays
@ -480,7 +467,7 @@ module SparseMatrix =
let inline ofRows (rows: Vector<'T> list) = Matrix<'T>.Build.SparseMatrixOfRowVectors(Array.ofList rows)
/// Create a matrix from a list of row arrays.
let ofRowArrays (rows: 'T[][]) = ParamsInvokeWorkaround<'T>.SparseMatrixOfRowArrays(rows)
let inline ofRowArrays (rows: 'T[][]) = Matrix<'T>.Build.SparseMatrixOfRowArrays(rows :> seq<'T[]>) // workaround params issue - impl detects it's actually an array
/// Create a matrix from a list of float lists. Every list in the master list specifies a row.
let inline ofRowList (rows: 'T list list) = rows |> List.map List.toArray |> List.toArray |> ofRowArrays
@ -495,7 +482,7 @@ module SparseMatrix =
let inline ofColumns (columns: Vector<'T> list) = Matrix<'T>.Build.SparseMatrixOfColumnVectors(Array.ofList columns)
/// Create a matrix from a list of column arrays.
let ofColumnArrays (columns: 'T[][]) = ParamsInvokeWorkaround<'T>.SparseMatrixOfColumnArrays(columns)
let inline ofColumnArrays (columns: 'T[][]) = Matrix<'T>.Build.SparseMatrixOfColumnArrays(columns :> seq<'T[]>) // workaround params issue - impl detects it's actually an array
/// Create a matrix from a list of float lists. Every list in the master list specifies a column.
let inline ofColumnList (columns: 'T list list) = columns |> List.map List.toArray |> List.toArray |> ofColumnArrays

2
src/FSharp/LinearAlgebra.Vector.fs

@ -272,7 +272,7 @@ module SparseVector =
let inline init (n: int) (f: int -> 'T) = Vector<'T>.Build.SparseVector(n, f)
/// Create a sparse vector from a float array.
let inline ofArray (fl: 'T array) = Vector<'T>.Build.SparseVectorOfEnumerable(Seq.ofArray fl)
let inline ofArray (fl: 'T array) = Vector<'T>.Build.SparseVectorOfEnumerable(fl :> seq<'T>)
/// Create a sparse vector from a float list.
let inline ofList (fl: 'T list) = Vector<'T>.Build.SparseVectorOfEnumerable(Seq.ofList fl)

80
src/Numerics/LinearAlgebra/Builder.cs

@ -500,6 +500,16 @@ namespace MathNet.Numerics.LinearAlgebra
return DenseMatrix(DenseColumnMajorMatrixStorage<T>.OfColumnArrays(columns));
}
/// <summary>
/// Create a new dense matrix of T as a copy of the given column arrays.
/// This new matrix will be independent from the arrays.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public Matrix<T> DenseMatrixOfColumnArrays(IEnumerable<T[]> columns)
{
return DenseMatrix(DenseColumnMajorMatrixStorage<T>.OfColumnArrays((columns as T[][]) ?? columns.ToArray()));
}
/// <summary>
/// Create a new dense matrix as a copy of the given column vectors.
/// This new matrix will be independent from the vectors.
@ -515,6 +525,16 @@ namespace MathNet.Numerics.LinearAlgebra
return DenseMatrix(DenseColumnMajorMatrixStorage<T>.OfColumnVectors(storage));
}
/// <summary>
/// Create a new dense matrix as a copy of the given column vectors.
/// This new matrix will be independent from the vectors.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public Matrix<T> DenseMatrixOfColumnVectors(IEnumerable<Vector<T>> columns)
{
return DenseMatrix(DenseColumnMajorMatrixStorage<T>.OfColumnVectors(columns.Select(c => c.Storage).ToArray()));
}
/// <summary>
/// Create a new dense matrix as a copy of the given enumerable of enumerable rows.
/// Each enumerable in the master enumerable specifies a row.
@ -547,6 +567,16 @@ namespace MathNet.Numerics.LinearAlgebra
return DenseMatrix(DenseColumnMajorMatrixStorage<T>.OfRowArrays(rows));
}
/// <summary>
/// Create a new dense matrix of T as a copy of the given row arrays.
/// This new matrix will be independent from the arrays.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public Matrix<T> DenseMatrixOfRowArrays(IEnumerable<T[]> rows)
{
return DenseMatrix(DenseColumnMajorMatrixStorage<T>.OfRowArrays((rows as T[][]) ?? rows.ToArray()));
}
/// <summary>
/// Create a new dense matrix as a copy of the given row vectors.
/// This new matrix will be independent from the vectors.
@ -562,6 +592,16 @@ namespace MathNet.Numerics.LinearAlgebra
return DenseMatrix(DenseColumnMajorMatrixStorage<T>.OfRowVectors(storage));
}
/// <summary>
/// Create a new dense matrix as a copy of the given row vectors.
/// This new matrix will be independent from the vectors.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public Matrix<T> DenseMatrixOfRowVectors(IEnumerable<Vector<T>> rows)
{
return DenseMatrix(DenseColumnMajorMatrixStorage<T>.OfRowVectors(rows.Select(r => r.Storage).ToArray()));
}
/// <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.
@ -749,6 +789,16 @@ namespace MathNet.Numerics.LinearAlgebra
return SparseMatrix(SparseCompressedRowMatrixStorage<T>.OfColumnArrays(columns));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given column arrays.
/// This new matrix will be independent from the arrays.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public Matrix<T> SparseMatrixOfColumnArrays(IEnumerable<T[]> columns)
{
return SparseMatrix(SparseCompressedRowMatrixStorage<T>.OfColumnArrays((columns as T[][]) ?? columns.ToArray()));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given column vectors.
/// This new matrix will be independent from the vectors.
@ -764,6 +814,16 @@ namespace MathNet.Numerics.LinearAlgebra
return SparseMatrix(SparseCompressedRowMatrixStorage<T>.OfColumnVectors(storage));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given column vectors.
/// This new matrix will be independent from the vectors.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public Matrix<T> SparseMatrixOfColumnVectors(IEnumerable<Vector<T>> columns)
{
return SparseMatrix(SparseCompressedRowMatrixStorage<T>.OfColumnVectors(columns.Select(c => c.Storage).ToArray()));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given enumerable of enumerable rows.
/// Each enumerable in the master enumerable specifies a row.
@ -796,6 +856,16 @@ namespace MathNet.Numerics.LinearAlgebra
return SparseMatrix(SparseCompressedRowMatrixStorage<T>.OfRowArrays(rows));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given row arrays.
/// This new matrix will be independent from the arrays.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public Matrix<T> SparseMatrixOfRowArrays(IEnumerable<T[]> rows)
{
return SparseMatrix(SparseCompressedRowMatrixStorage<T>.OfRowArrays((rows as T[][]) ?? rows.ToArray()));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given row vectors.
/// This new matrix will be independent from the vectors.
@ -811,6 +881,16 @@ namespace MathNet.Numerics.LinearAlgebra
return SparseMatrix(SparseCompressedRowMatrixStorage<T>.OfRowVectors(storage));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given row vectors.
/// This new matrix will be independent from the vectors.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public Matrix<T> SparseMatrixOfRowVectors(IEnumerable<Vector<T>> rows)
{
return SparseMatrix(SparseCompressedRowMatrixStorage<T>.OfRowVectors(rows.Select(r => r.Storage).ToArray()));
}
/// <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.

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

@ -197,6 +197,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return new DenseMatrix(DenseColumnMajorMatrixStorage<Complex>.OfColumnArrays(columns));
}
/// <summary>
/// Create a new dense matrix as a copy of the given column arrays.
/// This new matrix will be independent from the arrays.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfColumnArrays(IEnumerable<Complex[]> columns)
{
return new DenseMatrix(DenseColumnMajorMatrixStorage<Complex>.OfColumnArrays((columns as Complex[][]) ?? columns.ToArray()));
}
/// <summary>
/// Create a new dense matrix as a copy of the given column vectors.
/// This new matrix will be independent from the vectors.
@ -212,6 +222,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return new DenseMatrix(DenseColumnMajorMatrixStorage<Complex>.OfColumnVectors(storage));
}
/// <summary>
/// Create a new dense matrix as a copy of the given column vectors.
/// This new matrix will be independent from the vectors.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfColumnVectors(IEnumerable<Vector<Complex>> columns)
{
return new DenseMatrix(DenseColumnMajorMatrixStorage<Complex>.OfColumnVectors(columns.Select(c => c.Storage).ToArray()));
}
/// <summary>
/// Create a new dense matrix as a copy of the given enumerable of enumerable rows.
/// Each enumerable in the master enumerable specifies a row.
@ -244,6 +264,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return new DenseMatrix(DenseColumnMajorMatrixStorage<Complex>.OfRowArrays(rows));
}
/// <summary>
/// Create a new dense matrix as a copy of the given row arrays.
/// This new matrix will be independent from the arrays.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfRowArrays(IEnumerable<Complex[]> rows)
{
return new DenseMatrix(DenseColumnMajorMatrixStorage<Complex>.OfRowArrays((rows as Complex[][]) ?? rows.ToArray()));
}
/// <summary>
/// Create a new dense matrix as a copy of the given row vectors.
/// This new matrix will be independent from the vectors.
@ -259,6 +289,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return new DenseMatrix(DenseColumnMajorMatrixStorage<Complex>.OfRowVectors(storage));
}
/// <summary>
/// Create a new dense matrix as a copy of the given row vectors.
/// This new matrix will be independent from the vectors.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfRowVectors(IEnumerable<Vector<Complex>> rows)
{
return new DenseMatrix(DenseColumnMajorMatrixStorage<Complex>.OfRowVectors(rows.Select(r => r.Storage).ToArray()));
}
/// <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.

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

@ -184,6 +184,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return new SparseMatrix(SparseCompressedRowMatrixStorage<Complex>.OfColumnArrays(columns));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given column arrays.
/// This new matrix will be independent from the arrays.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfColumnArrays(IEnumerable<Complex[]> columns)
{
return new SparseMatrix(SparseCompressedRowMatrixStorage<Complex>.OfColumnArrays((columns as Complex[][]) ?? columns.ToArray()));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given column vectors.
/// This new matrix will be independent from the vectors.
@ -199,6 +209,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return new SparseMatrix(SparseCompressedRowMatrixStorage<Complex>.OfColumnVectors(storage));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given column vectors.
/// This new matrix will be independent from the vectors.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfColumnVectors(IEnumerable<Vector<Complex>> columns)
{
return new SparseMatrix(SparseCompressedRowMatrixStorage<Complex>.OfColumnVectors(columns.Select(c => c.Storage).ToArray()));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given enumerable of enumerable rows.
/// Each enumerable in the master enumerable specifies a row.
@ -231,6 +251,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return new SparseMatrix(SparseCompressedRowMatrixStorage<Complex>.OfRowArrays(rows));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given row arrays.
/// This new matrix will be independent from the arrays.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfRowArrays(IEnumerable<Complex[]> rows)
{
return new SparseMatrix(SparseCompressedRowMatrixStorage<Complex>.OfRowArrays((rows as Complex[][]) ?? rows.ToArray()));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given row vectors.
/// This new matrix will be independent from the vectors.
@ -246,6 +276,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return new SparseMatrix(SparseCompressedRowMatrixStorage<Complex>.OfRowVectors(storage));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given row vectors.
/// This new matrix will be independent from the vectors.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfRowVectors(IEnumerable<Vector<Complex>> rows)
{
return new SparseMatrix(SparseCompressedRowMatrixStorage<Complex>.OfRowVectors(rows.Select(r => r.Storage).ToArray()));
}
/// <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.

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

@ -192,6 +192,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return new DenseMatrix(DenseColumnMajorMatrixStorage<Complex32>.OfColumnArrays(columns));
}
/// <summary>
/// Create a new dense matrix as a copy of the given column arrays.
/// This new matrix will be independent from the arrays.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfColumnArrays(IEnumerable<Complex32[]> columns)
{
return new DenseMatrix(DenseColumnMajorMatrixStorage<Complex32>.OfColumnArrays((columns as Complex32[][]) ?? columns.ToArray()));
}
/// <summary>
/// Create a new dense matrix as a copy of the given column vectors.
/// This new matrix will be independent from the vectors.
@ -207,6 +217,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return new DenseMatrix(DenseColumnMajorMatrixStorage<Complex32>.OfColumnVectors(storage));
}
/// <summary>
/// Create a new dense matrix as a copy of the given column vectors.
/// This new matrix will be independent from the vectors.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfColumnVectors(IEnumerable<Vector<Complex32>> columns)
{
return new DenseMatrix(DenseColumnMajorMatrixStorage<Complex32>.OfColumnVectors(columns.Select(c => c.Storage).ToArray()));
}
/// <summary>
/// Create a new dense matrix as a copy of the given enumerable of enumerable rows.
/// Each enumerable in the master enumerable specifies a row.
@ -239,6 +259,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return new DenseMatrix(DenseColumnMajorMatrixStorage<Complex32>.OfRowArrays(rows));
}
/// <summary>
/// Create a new dense matrix as a copy of the given row arrays.
/// This new matrix will be independent from the arrays.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfRowArrays(IEnumerable<Complex32[]> rows)
{
return new DenseMatrix(DenseColumnMajorMatrixStorage<Complex32>.OfRowArrays((rows as Complex32[][]) ?? rows.ToArray()));
}
/// <summary>
/// Create a new dense matrix as a copy of the given row vectors.
/// This new matrix will be independent from the vectors.
@ -254,6 +284,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return new DenseMatrix(DenseColumnMajorMatrixStorage<Complex32>.OfRowVectors(storage));
}
/// <summary>
/// Create a new dense matrix as a copy of the given row vectors.
/// This new matrix will be independent from the vectors.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfRowVectors(IEnumerable<Vector<Complex32>> rows)
{
return new DenseMatrix(DenseColumnMajorMatrixStorage<Complex32>.OfRowVectors(rows.Select(r => r.Storage).ToArray()));
}
/// <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.

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

@ -179,6 +179,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return new SparseMatrix(SparseCompressedRowMatrixStorage<Complex32>.OfColumnArrays(columns));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given column arrays.
/// This new matrix will be independent from the arrays.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfColumnArrays(IEnumerable<Complex32[]> columns)
{
return new SparseMatrix(SparseCompressedRowMatrixStorage<Complex32>.OfColumnArrays((columns as Complex32[][]) ?? columns.ToArray()));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given column vectors.
/// This new matrix will be independent from the vectors.
@ -194,6 +204,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return new SparseMatrix(SparseCompressedRowMatrixStorage<Complex32>.OfColumnVectors(storage));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given column vectors.
/// This new matrix will be independent from the vectors.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfColumnVectors(IEnumerable<Vector<Complex32>> columns)
{
return new SparseMatrix(SparseCompressedRowMatrixStorage<Complex32>.OfColumnVectors(columns.Select(c => c.Storage).ToArray()));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given enumerable of enumerable rows.
/// Each enumerable in the master enumerable specifies a row.
@ -226,6 +246,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return new SparseMatrix(SparseCompressedRowMatrixStorage<Complex32>.OfRowArrays(rows));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given row arrays.
/// This new matrix will be independent from the arrays.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfRowArrays(IEnumerable<Complex32[]> rows)
{
return new SparseMatrix(SparseCompressedRowMatrixStorage<Complex32>.OfRowArrays((rows as Complex32[][]) ?? rows.ToArray()));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given row vectors.
/// This new matrix will be independent from the vectors.
@ -241,6 +271,16 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return new SparseMatrix(SparseCompressedRowMatrixStorage<Complex32>.OfRowVectors(storage));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given row vectors.
/// This new matrix will be independent from the vectors.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfRowVectors(IEnumerable<Vector<Complex32>> rows)
{
return new SparseMatrix(SparseCompressedRowMatrixStorage<Complex32>.OfRowVectors(rows.Select(r => r.Storage).ToArray()));
}
/// <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.

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

@ -190,6 +190,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return new DenseMatrix(DenseColumnMajorMatrixStorage<double>.OfColumnArrays(columns));
}
/// <summary>
/// Create a new dense matrix as a copy of the given column arrays.
/// This new matrix will be independent from the arrays.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfColumnArrays(IEnumerable<double[]> columns)
{
return new DenseMatrix(DenseColumnMajorMatrixStorage<double>.OfColumnArrays((columns as double[][]) ?? columns.ToArray()));
}
/// <summary>
/// Create a new dense matrix as a copy of the given column vectors.
/// This new matrix will be independent from the vectors.
@ -205,6 +215,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return new DenseMatrix(DenseColumnMajorMatrixStorage<double>.OfColumnVectors(storage));
}
/// <summary>
/// Create a new dense matrix as a copy of the given column vectors.
/// This new matrix will be independent from the vectors.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfColumnVectors(IEnumerable<Vector<double>> columns)
{
return new DenseMatrix(DenseColumnMajorMatrixStorage<double>.OfColumnVectors(columns.Select(c => c.Storage).ToArray()));
}
/// <summary>
/// Create a new dense matrix as a copy of the given enumerable of enumerable rows.
/// Each enumerable in the master enumerable specifies a row.
@ -237,6 +257,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return new DenseMatrix(DenseColumnMajorMatrixStorage<double>.OfRowArrays(rows));
}
/// <summary>
/// Create a new dense matrix as a copy of the given row arrays.
/// This new matrix will be independent from the arrays.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfRowArrays(IEnumerable<double[]> rows)
{
return new DenseMatrix(DenseColumnMajorMatrixStorage<double>.OfRowArrays((rows as double[][]) ?? rows.ToArray()));
}
/// <summary>
/// Create a new dense matrix as a copy of the given row vectors.
/// This new matrix will be independent from the vectors.
@ -252,6 +282,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return new DenseMatrix(DenseColumnMajorMatrixStorage<double>.OfRowVectors(storage));
}
/// <summary>
/// Create a new dense matrix as a copy of the given row vectors.
/// This new matrix will be independent from the vectors.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfRowVectors(IEnumerable<Vector<double>> rows)
{
return new DenseMatrix(DenseColumnMajorMatrixStorage<double>.OfRowVectors(rows.Select(r => r.Storage).ToArray()));
}
/// <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.

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

@ -177,6 +177,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return new SparseMatrix(SparseCompressedRowMatrixStorage<double>.OfColumnArrays(columns));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given column arrays.
/// This new matrix will be independent from the arrays.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfColumnArrays(IEnumerable<double[]> columns)
{
return new SparseMatrix(SparseCompressedRowMatrixStorage<double>.OfColumnArrays((columns as double[][]) ?? columns.ToArray()));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given column vectors.
/// This new matrix will be independent from the vectors.
@ -192,6 +202,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return new SparseMatrix(SparseCompressedRowMatrixStorage<double>.OfColumnVectors(storage));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given column vectors.
/// This new matrix will be independent from the vectors.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfColumnVectors(IEnumerable<Vector<double>> columns)
{
return new SparseMatrix(SparseCompressedRowMatrixStorage<double>.OfColumnVectors(columns.Select(c => c.Storage).ToArray()));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given enumerable of enumerable rows.
/// Each enumerable in the master enumerable specifies a row.
@ -224,6 +244,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return new SparseMatrix(SparseCompressedRowMatrixStorage<double>.OfRowArrays(rows));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given row arrays.
/// This new matrix will be independent from the arrays.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfRowArrays(IEnumerable<double[]> rows)
{
return new SparseMatrix(SparseCompressedRowMatrixStorage<double>.OfRowArrays((rows as double[][]) ?? rows.ToArray()));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given row vectors.
/// This new matrix will be independent from the vectors.
@ -239,6 +269,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return new SparseMatrix(SparseCompressedRowMatrixStorage<double>.OfRowVectors(storage));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given row vectors.
/// This new matrix will be independent from the vectors.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfRowVectors(IEnumerable<Vector<double>> rows)
{
return new SparseMatrix(SparseCompressedRowMatrixStorage<double>.OfRowVectors(rows.Select(r => r.Storage).ToArray()));
}
/// <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.

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

@ -190,6 +190,16 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return new DenseMatrix(DenseColumnMajorMatrixStorage<float>.OfColumnArrays(columns));
}
/// <summary>
/// Create a new dense matrix as a copy of the given column arrays.
/// This new matrix will be independent from the arrays.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfColumnArrays(IEnumerable<float[]> columns)
{
return new DenseMatrix(DenseColumnMajorMatrixStorage<float>.OfColumnArrays((columns as float[][]) ?? columns.ToArray()));
}
/// <summary>
/// Create a new dense matrix as a copy of the given column vectors.
/// This new matrix will be independent from the vectors.
@ -205,6 +215,16 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return new DenseMatrix(DenseColumnMajorMatrixStorage<float>.OfColumnVectors(storage));
}
/// <summary>
/// Create a new dense matrix as a copy of the given column vectors.
/// This new matrix will be independent from the vectors.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfColumnVectors(IEnumerable<Vector<float>> columns)
{
return new DenseMatrix(DenseColumnMajorMatrixStorage<float>.OfColumnVectors(columns.Select(c => c.Storage).ToArray()));
}
/// <summary>
/// Create a new dense matrix as a copy of the given enumerable of enumerable rows.
/// Each enumerable in the master enumerable specifies a row.
@ -237,6 +257,16 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return new DenseMatrix(DenseColumnMajorMatrixStorage<float>.OfRowArrays(rows));
}
/// <summary>
/// Create a new dense matrix as a copy of the given row arrays.
/// This new matrix will be independent from the arrays.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfRowArrays(IEnumerable<float[]> rows)
{
return new DenseMatrix(DenseColumnMajorMatrixStorage<float>.OfRowArrays((rows as float[][]) ?? rows.ToArray()));
}
/// <summary>
/// Create a new dense matrix as a copy of the given row vectors.
/// This new matrix will be independent from the vectors.
@ -252,6 +282,16 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return new DenseMatrix(DenseColumnMajorMatrixStorage<float>.OfRowVectors(storage));
}
/// <summary>
/// Create a new dense matrix as a copy of the given row vectors.
/// This new matrix will be independent from the vectors.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static DenseMatrix OfRowVectors(IEnumerable<Vector<float>> rows)
{
return new DenseMatrix(DenseColumnMajorMatrixStorage<float>.OfRowVectors(rows.Select(r => r.Storage).ToArray()));
}
/// <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.

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

@ -177,6 +177,16 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return new SparseMatrix(SparseCompressedRowMatrixStorage<float>.OfColumnArrays(columns));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given column arrays.
/// This new matrix will be independent from the arrays.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfColumnArrays(IEnumerable<float[]> columns)
{
return new SparseMatrix(SparseCompressedRowMatrixStorage<float>.OfColumnArrays((columns as float[][]) ?? columns.ToArray()));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given column vectors.
/// This new matrix will be independent from the vectors.
@ -192,6 +202,16 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return new SparseMatrix(SparseCompressedRowMatrixStorage<float>.OfColumnVectors(storage));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given column vectors.
/// This new matrix will be independent from the vectors.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfColumnVectors(IEnumerable<Vector<float>> columns)
{
return new SparseMatrix(SparseCompressedRowMatrixStorage<float>.OfColumnVectors(columns.Select(c => c.Storage).ToArray()));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given enumerable of enumerable rows.
/// Each enumerable in the master enumerable specifies a row.
@ -224,6 +244,16 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return new SparseMatrix(SparseCompressedRowMatrixStorage<float>.OfRowArrays(rows));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given row arrays.
/// This new matrix will be independent from the arrays.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfRowArrays(IEnumerable<float[]> rows)
{
return new SparseMatrix(SparseCompressedRowMatrixStorage<float>.OfRowArrays((rows as float[][]) ?? rows.ToArray()));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given row vectors.
/// This new matrix will be independent from the vectors.
@ -239,6 +269,16 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return new SparseMatrix(SparseCompressedRowMatrixStorage<float>.OfRowVectors(storage));
}
/// <summary>
/// Create a new sparse matrix as a copy of the given row vectors.
/// This new matrix will be independent from the vectors.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfRowVectors(IEnumerable<Vector<float>> rows)
{
return new SparseMatrix(SparseCompressedRowMatrixStorage<float>.OfRowVectors(rows.Select(r => r.Storage).ToArray()));
}
/// <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.

Loading…
Cancel
Save