Browse Source

LA: Improving ctor xml doc based on user feedback

pull/112/head
Christoph Ruegg 13 years ago
parent
commit
8ac6bb151f
  1. 68
      src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
  2. 58
      src/Numerics/LinearAlgebra/Complex/DenseVector.cs
  3. 77
      src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
  4. 6
      src/Numerics/LinearAlgebra/Complex/Matrix.cs
  5. 64
      src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
  6. 59
      src/Numerics/LinearAlgebra/Complex/SparseVector.cs
  7. 68
      src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
  8. 58
      src/Numerics/LinearAlgebra/Complex32/DenseVector.cs
  9. 75
      src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
  10. 6
      src/Numerics/LinearAlgebra/Complex32/Matrix.cs
  11. 64
      src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
  12. 59
      src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
  13. 68
      src/Numerics/LinearAlgebra/Double/DenseMatrix.cs
  14. 58
      src/Numerics/LinearAlgebra/Double/DenseVector.cs
  15. 77
      src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
  16. 64
      src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
  17. 59
      src/Numerics/LinearAlgebra/Double/SparseVector.cs
  18. 68
      src/Numerics/LinearAlgebra/Single/DenseMatrix.cs
  19. 58
      src/Numerics/LinearAlgebra/Single/DenseVector.cs
  20. 75
      src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
  21. 6
      src/Numerics/LinearAlgebra/Single/Matrix.cs
  22. 64
      src/Numerics/LinearAlgebra/Single/SparseMatrix.cs
  23. 59
      src/Numerics/LinearAlgebra/Single/SparseVector.cs

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

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -63,7 +67,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
readonly Complex[] _values;
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class.
/// Create a new dense matrix straight from an initialized matrix storage instance.
/// The storage is used directly without copying.
/// Intended for advanced scenarios where you're working directly with
/// storage for performance or interop reasons.
/// </summary>
public DenseMatrix(DenseColumnMajorMatrixStorage<Complex> storage)
: base(storage)
@ -74,41 +81,33 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class. This matrix is square with a given size.
/// Create a new square dense matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="order">the size of the square matrix.</param>
/// <exception cref="ArgumentException">
/// If <paramref name="order"/> is less than one.
/// </exception>
/// <exception cref="ArgumentException">If the order is less than one.</exception>
public DenseMatrix(int order)
: this(new DenseColumnMajorMatrixStorage<Complex>(order, order))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class.
/// Create a new dense matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="rows">
/// The number of rows.
/// </param>
/// <param name="columns">
/// The number of columns.
/// </param>
/// <exception cref="ArgumentException">If the row or column count is less than one.</exception>
public DenseMatrix(int rows, int columns)
: this(new DenseColumnMajorMatrixStorage<Complex>(rows, columns))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class with all entries set to a particular value.
/// Create a new dense matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to the provided value.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="rows">
/// The number of rows.
/// </param>
/// <param name="columns">
/// The number of columns.
/// </param>
/// <param name="value">The value which we assign to each element of the matrix.</param>
/// <exception cref="ArgumentException">If the row or column count is less than one.</exception>
public DenseMatrix(int rows, int columns, Complex value)
: this(rows, columns)
{
@ -119,22 +118,21 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class from a one dimensional array. This constructor
/// will reference the one dimensional array and not copy it.
/// Create a new dense matrix with the given number of rows and columns directly binding to a raw array.
/// The array is assumed to be in column-major order and is used directly without copying.
/// Very efficient, but changes to the array and the matrix will affect each other.
/// </summary>
/// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param>
/// <param name="array">The one dimensional array to create this matrix from. This array should store the matrix in column-major order. see: http://en.wikipedia.org/wiki/Row-major_order </param>
public DenseMatrix(int rows, int columns, Complex[] array)
: this(new DenseColumnMajorMatrixStorage<Complex>(rows, columns, array))
/// <seealso cref="http://en.wikipedia.org/wiki/Row-major_order"/>
public DenseMatrix(int rows, int columns, Complex[] storage)
: this(new DenseColumnMajorMatrixStorage<Complex>(rows, columns, storage))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class from a 2D array. This constructor
/// will allocate a completely new memory block for storing the dense matrix.
/// Create a new dense matrix as a copy of the given two-dimensional array.
/// This new matrix will be independent from the provided array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="array">The 2D array to create this matrix from.</param>
public DenseMatrix(Complex[,] array)
: this(array.GetLength(0), array.GetLength(1))
{
@ -148,10 +146,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class, copying
/// the values from the given matrix.
/// Create a new dense matrix as a copy of the given other matrix.
/// This new matrix will be independent from the other matrix.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="matrix">The matrix to copy.</param>
public DenseMatrix(Matrix<Complex> matrix)
: this(matrix.RowCount, matrix.ColumnCount)
{

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

@ -58,7 +58,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
readonly Complex[] _values;
/// <summary>
/// Initializes a new instance of the <see cref="DenseVector"/> class.
/// Create a new dense vector straight from an initialized vector storage instance.
/// The storage is used directly without copying.
/// Intended for advanced scenarios where you're working directly with
/// storage for performance or interop reasons.
/// </summary>
public DenseVector(DenseVectorStorage<Complex> storage)
: base(storage)
@ -68,34 +71,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseVector"/> class with a given size.
/// Create a new dense vector with the given length.
/// All cells of the vector will be initialized to zero.
/// Zero-length vectors are not supported.
/// </summary>
/// <param name="size">
/// the size of the vector.
/// </param>
/// <exception cref="ArgumentException">
/// If <paramref name="size"/> is less than one.
/// </exception>
public DenseVector(int size)
: this(new DenseVectorStorage<Complex>(size))
/// <exception cref="ArgumentException">If length is less than one.</exception>
public DenseVector(int length)
: this(new DenseVectorStorage<Complex>(length))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseVector"/> class with a given size
/// and each element set to the given value;
/// Create a new dense vector with the given length.
/// All cells of the vector will be initialized with the provided value.
/// Zero-length vectors are not supported.
/// </summary>
/// <param name="size">
/// the size of the vector.
/// </param>
/// <param name="value">
/// the value to set each element to.
/// </param>
/// <exception cref="ArgumentException">
/// If <paramref name="size"/> is less than one.
/// </exception>
public DenseVector(int size, Complex value)
: this(size)
/// <exception cref="ArgumentException">If length is less than one.</exception>
public DenseVector(int length, Complex value)
: this(length)
{
for (var index = 0; index < _values.Length; index++)
{
@ -104,12 +97,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseVector"/> class by
/// copying the values from another.
/// Create a new dense vector as a copy of the given other vector.
/// This new vector will be independent from the other vector.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="other">
/// The vector to create the new vector from.
/// </param>
public DenseVector(Vector<Complex> other)
: this(other.Count)
{
@ -117,13 +108,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseVector"/> class for an array.
/// Create a new dense vector directly binding to a raw array.
/// The array is used directly without copying.
/// Very efficient, but changes to the array and the vector will affect each other.
/// </summary>
/// <param name="array">The array to create this vector from.</param>
/// <remarks>The vector does not copy the array, but keeps a reference to it. Any
/// changes to the vector will also change the array.</remarks>
public DenseVector(Complex[] array)
: this(new DenseVectorStorage<Complex>(array.Length, array))
public DenseVector(Complex[] storage)
: this(new DenseVectorStorage<Complex>(storage.Length, storage))
{
}

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

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -56,7 +60,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
readonly Complex[] _data;
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class.
/// Create a new diagonal matrix straight from an initialized matrix storage instance.
/// The storage is used directly without copying.
/// Intended for advanced scenarios where you're working directly with
/// storage for performance or interop reasons.
/// </summary>
public DiagonalMatrix(DiagonalMatrixStorage<Complex> storage)
: base(storage)
@ -65,70 +72,59 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
_data = _storage.Data;
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class. This matrix is square with a given size.
/// <summary>
/// Create a new square diagonal matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="order">the size of the square matrix.</param>
/// <exception cref="ArgumentException">
/// If <paramref name="order"/> is less than one.
/// </exception>
/// <exception cref="ArgumentException">If the order is less than one.</exception>
public DiagonalMatrix(int order)
: this(new DiagonalMatrixStorage<Complex>(order, order))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class.
/// Create a new diagonal matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="rows">
/// The number of rows.
/// </param>
/// <param name="columns">
/// The number of columns.
/// </param>
/// <exception cref="ArgumentException">If the row or column count is less than one.</exception>
public DiagonalMatrix(int rows, int columns)
: this(new DiagonalMatrixStorage<Complex>(rows, columns))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class with all diagonal entries set to a particular value.
/// Create a new diagonal matrix with the given number of rows and columns.
/// All diagonal cells of the matrix will be initialized to the provided value, all non-diagonal ones to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="rows">
/// The number of rows.
/// </param>
/// <param name="columns">
/// The number of columns.
/// </param>
/// <param name="value">The value which we assign to each diagonal element of the matrix.</param>
public DiagonalMatrix(int rows, int columns, Complex value)
/// <exception cref="ArgumentException">If the row or column count is less than one.</exception>
public DiagonalMatrix(int rows, int columns, Complex diagonalValue)
: this(rows, columns)
{
for (var i = 0; i < _data.Length; i++)
{
_data[i] = value;
_data[i] = diagonalValue;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class from a one dimensional array with diagonal elements. This constructor
/// will reference the one dimensional array and not copy it.
/// Create a new diagonal matrix with the given number of rows and columns directly binding to a raw array.
/// The array is assumed to contain the diagonal elements only and is used directly without copying.
/// Very efficient, but changes to the array and the matrix will affect each other.
/// </summary>
/// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param>
/// <param name="diagonalArray">The one dimensional array which contain diagonal elements.</param>
public DiagonalMatrix(int rows, int columns, Complex[] diagonalArray)
: this(new DiagonalMatrixStorage<Complex>(rows, columns, diagonalArray))
public DiagonalMatrix(int rows, int columns, Complex[] diagonalStorage)
: this(new DiagonalMatrixStorage<Complex>(rows, columns, diagonalStorage))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class from a 2D array.
/// Create a new diagonal matrix as a copy of the given two-dimensional array.
/// This new matrix will be independent from the provided array.
/// The array to copy from must be diagonal as well.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="array">The 2D array to create this matrix from.</param>
/// <exception cref="IndexOutOfRangeException">When <paramref name="array"/> contains an off-diagonal element.</exception>
/// <exception cref="IndexOutOfRangeException">Depending on the implementation, an <see cref="IndexOutOfRangeException"/>
/// may be thrown if one of the indices is outside the dimensions of the matrix.</exception>
public DiagonalMatrix(Complex[,] array)
: this(array.GetLength(0), array.GetLength(1))
{
@ -149,10 +145,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class, copying
/// the values from the given matrix.
/// 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>
/// <param name="matrix">The matrix to copy.</param>
public DiagonalMatrix(Matrix<Complex> matrix)
: this(matrix.RowCount, matrix.ColumnCount)
{

6
src/Numerics/LinearAlgebra/Complex/Matrix.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND

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

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2010 Math.NET
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -39,7 +39,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
using System.Numerics;
/// <summary>
/// A Matrix class with sparse storage. The underlying storage scheme is 3-array compressed-sparse-row (CSR) Format.
/// A Matrix with sparse storage, intended for very large matrices where most of the cells are zero.
/// The underlying storage scheme is 3-array compressed-sparse-row (CSR) Format.
/// <a href="http://en.wikipedia.org/wiki/Sparse_matrix#Compressed_sparse_row_.28CSR_or_CRS.29">Wikipedia - CSR</a>.
/// </summary>
[Serializable]
@ -58,7 +59,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class.
/// Create a new sparse matrix straight from an initialized matrix storage instance.
/// The storage is used directly without copying.
/// Intended for advanced scenarios where you're working directly with
/// storage for performance or interop reasons.
/// </summary>
public SparseMatrix(SparseCompressedRowMatrixStorage<Complex> storage)
: base(storage)
@ -67,41 +71,33 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class.
/// Create a new sparse matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="rows">
/// The number of rows.
/// </param>
/// <param name="columns">
/// The number of columns.
/// </param>
/// <exception cref="ArgumentException">If the row or column count is less than one.</exception>
public SparseMatrix(int rows, int columns)
: this(new SparseCompressedRowMatrixStorage<Complex>(rows, columns))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class. This matrix is square with a given size.
/// Create a new square sparse matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="order">the size of the square matrix.</param>
/// <exception cref="ArgumentException">
/// If <paramref name="order"/> is less than one.
/// </exception>
/// <exception cref="ArgumentException">If the order is less than one.</exception>
public SparseMatrix(int order)
: this(order, order)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class with all entries set to a particular value.
/// Create a new sparse matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to the provided value.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="rows">
/// The number of rows.
/// </param>
/// <param name="columns">
/// The number of columns.
/// </param>
/// <param name="value">The value which we assign to each element of the matrix.</param>
/// <exception cref="ArgumentException">If the row or column count is less than one.</exception>
[Obsolete("Use a dense matrix instead. Scheduled for removal in v3.0.")]
public SparseMatrix(int rows, int columns, Complex value)
: this(rows, columns)
@ -136,13 +132,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class from a one dimensional array.
/// Create a new sparse matrix with the given number of rows and columns as a copy of the given array.
/// The array is assumed to be in column-major order.
/// This new matrix will be independent from the provided array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param>
/// <param name="array">The one dimensional array to create this matrix from. This array should store the matrix in column-major order. see: http://en.wikipedia.org/wiki/Column-major_order </param>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="array"/> length is less than <paramref name="rows"/> * <paramref name="columns"/>.
/// </exception>
/// <seealso cref="http://en.wikipedia.org/wiki/Row-major_order"/>
public SparseMatrix(int rows, int columns, Complex[] array)
: this(rows, columns)
{
@ -161,9 +156,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class from a 2D array.
/// Create a new sparse matrix as a copy of the given two-dimensional array.
/// This new matrix will be independent from the provided array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="array">The 2D array to create this matrix from.</param>
public SparseMatrix(Complex[,] array)
: this(array.GetLength(0), array.GetLength(1))
{
@ -177,10 +173,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class, copying
/// the values from the given matrix.
/// Create a new sparse matrix as a copy of the given other matrix.
/// This new matrix will be independent from the other matrix.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="matrix">The matrix to copy.</param>
public SparseMatrix(Matrix<Complex> matrix)
: this(matrix.RowCount, matrix.ColumnCount)
{

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

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2011 Math.NET
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -40,7 +40,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
using Threading;
/// <summary>
/// A vector with sparse storage.
/// A vector with sparse storage, intended for very large vectors where most of the cells are zero.
/// </summary>
/// <remarks>The sparse vector is not thread safe.</remarks>
[Serializable]
@ -59,7 +59,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseVector"/> class.
/// Create a new sparse vector straight from an initialized vector storage instance.
/// The storage is used directly without copying.
/// Intended for advanced scenarios where you're working directly with
/// storage for performance or interop reasons.
/// </summary>
public SparseVector(SparseVectorStorage<Complex> storage)
: base(storage)
@ -68,42 +71,32 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseVector"/> class with a given size.
/// Create a new sparse vector with the given length.
/// All cells of the vector will be initialized to zero.
/// Zero-length vectors are not supported.
/// </summary>
/// <param name="size">
/// the size of the vector.
/// </param>
/// <exception cref="ArgumentException">
/// If <paramref name="size"/> is less than one.
/// </exception>
public SparseVector(int size)
: this(new SparseVectorStorage<Complex>(size))
/// <exception cref="ArgumentException">If length is less than one.</exception>
public SparseVector(int length)
: this(new SparseVectorStorage<Complex>(length))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseVector"/> class with a given size
/// and each element set to the given value;
/// Create a new sparse vector with the given length.
/// All cells of the vector will be initialized with the provided value.
/// Zero-length vectors are not supported.
/// </summary>
/// <param name="size">
/// the size of the vector.
/// </param>
/// <param name="value">
/// the value to set each element to.
/// </param>
/// <exception cref="ArgumentException">
/// If <paramref name="size"/> is less than one.
/// </exception>
/// <exception cref="ArgumentException">If length is less than one.</exception>
[Obsolete("Use a dense vector instead. Scheduled for removal in v3.0.")]
public SparseVector(int size, Complex value)
: this(new SparseVectorStorage<Complex>(size))
public SparseVector(int length, Complex value)
: this(new SparseVectorStorage<Complex>(length))
{
if (value == Complex.Zero)
{
return;
}
var valueCount = _storage.ValueCount = size;
var valueCount = _storage.ValueCount = length;
var indices = _storage.Indices = new int[valueCount];
var values = _storage.Values = new Complex[valueCount];
@ -115,12 +108,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseVector"/> class by
/// copying the values from another.
/// Create a new sparse vector as a copy of the given other vector.
/// This new vector will be independent from the other vector.
/// A new memory block will be allocated for storing the vector.
/// </summary>
/// <param name="other">
/// The vector to create the new vector from.
/// </param>
public SparseVector(Vector<Complex> other)
: this(new SparseVectorStorage<Complex>(other.Count))
{
@ -128,10 +119,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseVector"/> class for an array.
/// Create a new sparse vector as a copy of the given array.
/// This new vector will be independent from the array.
/// A new memory block will be allocated for storing the vector.
/// </summary>
/// <param name="array">The array to create this vector from.</param>
/// <remarks>The vector copy the array. Any changes to the vector will NOT change the array.</remarks>
public SparseVector(IList<Complex> array)
: this(new SparseVectorStorage<Complex>(array.Count))
{

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

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -63,7 +67,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
readonly Complex32[] _values;
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class.
/// Create a new dense matrix straight from an initialized matrix storage instance.
/// The storage is used directly without copying.
/// Intended for advanced scenarios where you're working directly with
/// storage for performance or interop reasons.
/// </summary>
public DenseMatrix(DenseColumnMajorMatrixStorage<Complex32> storage)
: base(storage)
@ -74,41 +81,33 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class. This matrix is square with a given size.
/// Create a new square dense matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="order">the size of the square matrix.</param>
/// <exception cref="ArgumentException">
/// If <paramref name="order"/> is less than one.
/// </exception>
/// <exception cref="ArgumentException">If the order is less than one.</exception>
public DenseMatrix(int order)
: this(new DenseColumnMajorMatrixStorage<Complex32>(order, order))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class.
/// Create a new dense matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="rows">
/// The number of rows.
/// </param>
/// <param name="columns">
/// The number of columns.
/// </param>
/// <exception cref="ArgumentException">If the row or column count is less than one.</exception>
public DenseMatrix(int rows, int columns)
: this(new DenseColumnMajorMatrixStorage<Complex32>(rows, columns))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class with all entries set to a particular value.
/// Create a new dense matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to the provided value.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="rows">
/// The number of rows.
/// </param>
/// <param name="columns">
/// The number of columns.
/// </param>
/// <param name="value">The value which we assign to each element of the matrix.</param>
/// <exception cref="ArgumentException">If the row or column count is less than one.</exception>
public DenseMatrix(int rows, int columns, Complex32 value)
: this(rows, columns)
{
@ -119,22 +118,21 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class from a one dimensional array. This constructor
/// will reference the one dimensional array and not copy it.
/// Create a new dense matrix with the given number of rows and columns directly binding to a raw array.
/// The array is assumed to be in column-major order and is used directly without copying.
/// Very efficient, but changes to the array and the matrix will affect each other.
/// </summary>
/// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param>
/// <param name="array">The one dimensional array to create this matrix from. This array should store the matrix in column-major order. see: http://en.wikipedia.org/wiki/Row-major_order </param>
public DenseMatrix(int rows, int columns, Complex32[] array)
: this(new DenseColumnMajorMatrixStorage<Complex32>(rows, columns, array))
/// <seealso cref="http://en.wikipedia.org/wiki/Row-major_order"/>
public DenseMatrix(int rows, int columns, Complex32[] storage)
: this(new DenseColumnMajorMatrixStorage<Complex32>(rows, columns, storage))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class from a 2D array. This constructor
/// will allocate a completely new memory block for storing the dense matrix.
/// Create a new dense matrix as a copy of the given two-dimensional array.
/// This new matrix will be independent from the provided array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="array">The 2D array to create this matrix from.</param>
public DenseMatrix(Complex32[,] array)
: this(array.GetLength(0), array.GetLength(1))
{
@ -148,10 +146,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class, copying
/// the values from the given matrix.
/// Create a new dense matrix as a copy of the given other matrix.
/// This new matrix will be independent from the other matrix.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="matrix">The matrix to copy.</param>
public DenseMatrix(Matrix<Complex32> matrix)
: this(matrix.RowCount, matrix.ColumnCount)
{

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

@ -58,7 +58,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
readonly Complex32[] _values;
/// <summary>
/// Initializes a new instance of the <see cref="DenseVector"/> class.
/// Create a new dense vector straight from an initialized vector storage instance.
/// The storage is used directly without copying.
/// Intended for advanced scenarios where you're working directly with
/// storage for performance or interop reasons.
/// </summary>
public DenseVector(DenseVectorStorage<Complex32> storage)
: base(storage)
@ -68,34 +71,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseVector"/> class with a given size.
/// Create a new dense vector with the given length.
/// All cells of the vector will be initialized to zero.
/// Zero-length vectors are not supported.
/// </summary>
/// <param name="size">
/// the size of the vector.
/// </param>
/// <exception cref="ArgumentException">
/// If <paramref name="size"/> is less than one.
/// </exception>
public DenseVector(int size)
: this(new DenseVectorStorage<Complex32>(size))
/// <exception cref="ArgumentException">If length is less than one.</exception>
public DenseVector(int length)
: this(new DenseVectorStorage<Complex32>(length))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseVector"/> class with a given size
/// and each element set to the given value;
/// Create a new dense vector with the given length.
/// All cells of the vector will be initialized with the provided value.
/// Zero-length vectors are not supported.
/// </summary>
/// <param name="size">
/// the size of the vector.
/// </param>
/// <param name="value">
/// the value to set each element to.
/// </param>
/// <exception cref="ArgumentException">
/// If <paramref name="size"/> is less than one.
/// </exception>
public DenseVector(int size, Complex32 value)
: this(size)
/// <exception cref="ArgumentException">If length is less than one.</exception>
public DenseVector(int length, Complex32 value)
: this(length)
{
for (var index = 0; index < _values.Length; index++)
{
@ -104,12 +97,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseVector"/> class by
/// copying the values from another.
/// Create a new dense vector as a copy of the given other vector.
/// This new vector will be independent from the other vector.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="other">
/// The vector to create the new vector from.
/// </param>
public DenseVector(Vector<Complex32> other)
: this(other.Count)
{
@ -117,13 +108,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseVector"/> class for an array.
/// Create a new dense vector directly binding to a raw array.
/// The array is used directly without copying.
/// Very efficient, but changes to the array and the vector will affect each other.
/// </summary>
/// <param name="array">The array to create this vector from.</param>
/// <remarks>The vector does not copy the array, but keeps a reference to it. Any
/// changes to the vector will also change the array.</remarks>
public DenseVector(Complex32[] array)
: this(new DenseVectorStorage<Complex32>(array.Length, array))
public DenseVector(Complex32[] storage)
: this(new DenseVectorStorage<Complex32>(storage.Length, storage))
{
}

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

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -56,7 +60,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
readonly Complex32[] _data;
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class.
/// Create a new diagonal matrix straight from an initialized matrix storage instance.
/// The storage is used directly without copying.
/// Intended for advanced scenarios where you're working directly with
/// storage for performance or interop reasons.
/// </summary>
public DiagonalMatrix(DiagonalMatrixStorage<Complex32> storage)
: base(storage)
@ -66,69 +73,58 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class. This matrix is square with a given size.
/// Create a new square diagonal matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="order">the size of the square matrix.</param>
/// <exception cref="ArgumentException">
/// If <paramref name="order"/> is less than one.
/// </exception>
/// <exception cref="ArgumentException">If the order is less than one.</exception>
public DiagonalMatrix(int order)
: this(new DiagonalMatrixStorage<Complex32>(order, order))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class.
/// Create a new diagonal matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="rows">
/// The number of rows.
/// </param>
/// <param name="columns">
/// The number of columns.
/// </param>
/// <exception cref="ArgumentException">If the row or column count is less than one.</exception>
public DiagonalMatrix(int rows, int columns)
: this(new DiagonalMatrixStorage<Complex32>(rows, columns))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class with all diagonal entries set to a particular value.
/// Create a new diagonal matrix with the given number of rows and columns.
/// All diagonal cells of the matrix will be initialized to the provided value, all non-diagonal ones to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="rows">
/// The number of rows.
/// </param>
/// <param name="columns">
/// The number of columns.
/// </param>
/// <param name="value">The value which we assign to each diagonal element of the matrix.</param>
public DiagonalMatrix(int rows, int columns, Complex32 value)
/// <exception cref="ArgumentException">If the row or column count is less than one.</exception>
public DiagonalMatrix(int rows, int columns, Complex32 diagonalValue)
: this(rows, columns)
{
for (var i = 0; i < _data.Length; i++)
{
_data[i] = value;
_data[i] = diagonalValue;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class from a one dimensional array with diagonal elements. This constructor
/// will reference the one dimensional array and not copy it.
/// Create a new diagonal matrix with the given number of rows and columns directly binding to a raw array.
/// The array is assumed to contain the diagonal elements only and is used directly without copying.
/// Very efficient, but changes to the array and the matrix will affect each other.
/// </summary>
/// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param>
/// <param name="diagonalArray">The one dimensional array which contain diagonal elements.</param>
public DiagonalMatrix(int rows, int columns, Complex32[] diagonalArray)
: this(new DiagonalMatrixStorage<Complex32>(rows, columns, diagonalArray))
public DiagonalMatrix(int rows, int columns, Complex32[] diagonalStorage)
: this(new DiagonalMatrixStorage<Complex32>(rows, columns, diagonalStorage))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class from a 2D array.
/// Create a new diagonal matrix as a copy of the given two-dimensional array.
/// This new matrix will be independent from the provided array.
/// The array to copy from must be diagonal as well.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="array">The 2D array to create this matrix from.</param>
/// <exception cref="IndexOutOfRangeException">When <paramref name="array"/> contains an off-diagonal element.</exception>
/// <exception cref="IndexOutOfRangeException">Depending on the implementation, an <see cref="IndexOutOfRangeException"/>
/// may be thrown if one of the indices is outside the dimensions of the matrix.</exception>
public DiagonalMatrix(Complex32[,] array)
: this(array.GetLength(0), array.GetLength(1))
{
@ -149,10 +145,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class, copying
/// the values from the given matrix.
/// 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>
/// <param name="matrix">The matrix to copy.</param>
public DiagonalMatrix(Matrix<Complex32> matrix)
: this(matrix.RowCount, matrix.ColumnCount)
{

6
src/Numerics/LinearAlgebra/Complex32/Matrix.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND

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

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2010 Math.NET
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -39,7 +39,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
using System.Diagnostics;
/// <summary>
/// A Matrix class with sparse storage. The underlying storage scheme is 3-array compressed-sparse-row (CSR) Format.
/// A Matrix with sparse storage, intended for very large matrices where most of the cells are zero.
/// The underlying storage scheme is 3-array compressed-sparse-row (CSR) Format.
/// <a href="http://en.wikipedia.org/wiki/Sparse_matrix#Compressed_sparse_row_.28CSR_or_CRS.29">Wikipedia - CSR</a>.
/// </summary>
[Serializable]
@ -58,7 +59,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class.
/// Create a new sparse matrix straight from an initialized matrix storage instance.
/// The storage is used directly without copying.
/// Intended for advanced scenarios where you're working directly with
/// storage for performance or interop reasons.
/// </summary>
public SparseMatrix(SparseCompressedRowMatrixStorage<Complex32> storage)
: base(storage)
@ -67,41 +71,33 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class.
/// Create a new sparse matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="rows">
/// The number of rows.
/// </param>
/// <param name="columns">
/// The number of columns.
/// </param>
/// <exception cref="ArgumentException">If the row or column count is less than one.</exception>
public SparseMatrix(int rows, int columns)
: this(new SparseCompressedRowMatrixStorage<Complex32>(rows, columns))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class. This matrix is square with a given size.
/// Create a new square sparse matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="order">the size of the square matrix.</param>
/// <exception cref="ArgumentException">
/// If <paramref name="order"/> is less than one.
/// </exception>
/// <exception cref="ArgumentException">If the order is less than one.</exception>
public SparseMatrix(int order)
: this(order, order)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class with all entries set to a particular value.
/// Create a new sparse matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to the provided value.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="rows">
/// The number of rows.
/// </param>
/// <param name="columns">
/// The number of columns.
/// </param>
/// <param name="value">The value which we assign to each element of the matrix.</param>
/// <exception cref="ArgumentException">If the row or column count is less than one.</exception>
[Obsolete("Use a dense matrix instead. Scheduled for removal in v3.0.")]
public SparseMatrix(int rows, int columns, Complex32 value)
: this(rows, columns)
@ -136,13 +132,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class from a one dimensional array.
/// Create a new sparse matrix with the given number of rows and columns as a copy of the given array.
/// The array is assumed to be in column-major order.
/// This new matrix will be independent from the provided array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param>
/// <param name="array">The one dimensional array to create this matrix from. This array should store the matrix in column-major order. see: http://en.wikipedia.org/wiki/Column-major_order </param>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="array"/> length is less than <paramref name="rows"/> * <paramref name="columns"/>.
/// </exception>
/// <seealso cref="http://en.wikipedia.org/wiki/Row-major_order"/>
public SparseMatrix(int rows, int columns, Complex32[] array)
: this(rows, columns)
{
@ -161,9 +156,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class from a 2D array.
/// Create a new sparse matrix as a copy of the given two-dimensional array.
/// This new matrix will be independent from the provided array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="array">The 2D array to create this matrix from.</param>
public SparseMatrix(Complex32[,] array)
: this(array.GetLength(0), array.GetLength(1))
{
@ -177,10 +173,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class, copying
/// the values from the given matrix.
/// Create a new sparse matrix as a copy of the given other matrix.
/// This new matrix will be independent from the other matrix.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="matrix">The matrix to copy.</param>
public SparseMatrix(Matrix<Complex32> matrix)
: this(matrix.RowCount, matrix.ColumnCount)
{

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

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2011 Math.NET
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -40,7 +40,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
using Threading;
/// <summary>
/// A vector with sparse storage.
/// A vector with sparse storage, intended for very large vectors where most of the cells are zero.
/// </summary>
/// <remarks>The sparse vector is not thread safe.</remarks>
[Serializable]
@ -59,7 +59,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseVector"/> class.
/// Create a new sparse vector straight from an initialized vector storage instance.
/// The storage is used directly without copying.
/// Intended for advanced scenarios where you're working directly with
/// storage for performance or interop reasons.
/// </summary>
public SparseVector(SparseVectorStorage<Complex32> storage)
: base(storage)
@ -68,42 +71,32 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseVector"/> class with a given size.
/// Create a new sparse vector with the given length.
/// All cells of the vector will be initialized to zero.
/// Zero-length vectors are not supported.
/// </summary>
/// <param name="size">
/// the size of the vector.
/// </param>
/// <exception cref="ArgumentException">
/// If <paramref name="size"/> is less than one.
/// </exception>
public SparseVector(int size)
: this(new SparseVectorStorage<Complex32>(size))
/// <exception cref="ArgumentException">If length is less than one.</exception>
public SparseVector(int length)
: this(new SparseVectorStorage<Complex32>(length))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseVector"/> class with a given size
/// and each element set to the given value;
/// Create a new sparse vector with the given length.
/// All cells of the vector will be initialized with the provided value.
/// Zero-length vectors are not supported.
/// </summary>
/// <param name="size">
/// the size of the vector.
/// </param>
/// <param name="value">
/// the value to set each element to.
/// </param>
/// <exception cref="ArgumentException">
/// If <paramref name="size"/> is less than one.
/// </exception>
/// <exception cref="ArgumentException">If length is less than one.</exception>
[Obsolete("Use a dense vector instead. Scheduled for removal in v3.0.")]
public SparseVector(int size, Complex32 value)
: this(new SparseVectorStorage<Complex32>(size))
public SparseVector(int length, Complex32 value)
: this(new SparseVectorStorage<Complex32>(length))
{
if (value == Complex32.Zero)
{
return;
}
var valueCount = _storage.ValueCount = size;
var valueCount = _storage.ValueCount = length;
var indices = _storage.Indices = new int[valueCount];
var values = _storage.Values = new Complex32[valueCount];
@ -115,12 +108,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseVector"/> class by
/// copying the values from another.
/// Create a new sparse vector as a copy of the given other vector.
/// This new vector will be independent from the other vector.
/// A new memory block will be allocated for storing the vector.
/// </summary>
/// <param name="other">
/// The vector to create the new vector from.
/// </param>
public SparseVector(Vector<Complex32> other)
: this(new SparseVectorStorage<Complex32>(other.Count))
{
@ -128,10 +119,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseVector"/> class for an array.
/// Create a new sparse vector as a copy of the given array.
/// This new vector will be independent from the array.
/// A new memory block will be allocated for storing the vector.
/// </summary>
/// <param name="array">The array to create this vector from.</param>
/// <remarks>The vector copy the array. Any changes to the vector will NOT change the array.</remarks>
public SparseVector(IList<Complex32> array)
: this(new SparseVectorStorage<Complex32>(array.Count))
{

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

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -63,7 +67,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double
readonly double[] _values;
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class.
/// Create a new dense matrix straight from an initialized matrix storage instance.
/// The storage is used directly without copying.
/// Intended for advanced scenarios where you're working directly with
/// storage for performance or interop reasons.
/// </summary>
public DenseMatrix(DenseColumnMajorMatrixStorage<double> storage)
: base(storage)
@ -74,41 +81,33 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class. This matrix is square with a given size.
/// Create a new square dense matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="order">the size of the square matrix.</param>
/// <exception cref="ArgumentException">
/// If <paramref name="order"/> is less than one.
/// </exception>
/// <exception cref="ArgumentException">If the order is less than one.</exception>
public DenseMatrix(int order)
: this(new DenseColumnMajorMatrixStorage<double>(order, order))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class.
/// Create a new dense matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="rows">
/// The number of rows.
/// </param>
/// <param name="columns">
/// The number of columns.
/// </param>
/// <exception cref="ArgumentException">If the row or column count is less than one.</exception>
public DenseMatrix(int rows, int columns)
: this(new DenseColumnMajorMatrixStorage<double>(rows, columns))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class with all entries set to a particular value.
/// Create a new dense matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to the provided value.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="rows">
/// The number of rows.
/// </param>
/// <param name="columns">
/// The number of columns.
/// </param>
/// <param name="value">The value which we assign to each element of the matrix.</param>
/// <exception cref="ArgumentException">If the row or column count is less than one.</exception>
public DenseMatrix(int rows, int columns, double value)
: this(rows, columns)
{
@ -119,22 +118,21 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class from a one dimensional array. This constructor
/// will reference the one dimensional array and not copy it.
/// Create a new dense matrix with the given number of rows and columns directly binding to a raw array.
/// The array is assumed to be in column-major order and is used directly without copying.
/// Very efficient, but changes to the array and the matrix will affect each other.
/// </summary>
/// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param>
/// <param name="array">The one dimensional array to create this matrix from. This array should store the matrix in column-major order. see: http://en.wikipedia.org/wiki/Row-major_order </param>
public DenseMatrix(int rows, int columns, double[] array)
: this(new DenseColumnMajorMatrixStorage<double>(rows, columns, array))
/// <seealso cref="http://en.wikipedia.org/wiki/Row-major_order"/>
public DenseMatrix(int rows, int columns, double[] storage)
: this(new DenseColumnMajorMatrixStorage<double>(rows, columns, storage))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class from a 2D array. This constructor
/// will allocate a completely new memory block for storing the dense matrix.
/// Create a new dense matrix as a copy of the given two-dimensional array.
/// This new matrix will be independent from the provided array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="array">The 2D array to create this matrix from.</param>
public DenseMatrix(double[,] array)
: this(array.GetLength(0), array.GetLength(1))
{
@ -148,10 +146,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class, copying
/// the values from the given matrix.
/// Create a new dense matrix as a copy of the given other matrix.
/// This new matrix will be independent from the other matrix.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="matrix">The matrix to copy.</param>
public DenseMatrix(Matrix<double> matrix)
: this(matrix.RowCount, matrix.ColumnCount)
{

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

@ -58,7 +58,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double
readonly double[] _values;
/// <summary>
/// Initializes a new instance of the <see cref="DenseVector"/> class.
/// Create a new dense vector straight from an initialized vector storage instance.
/// The storage is used directly without copying.
/// Intended for advanced scenarios where you're working directly with
/// storage for performance or interop reasons.
/// </summary>
public DenseVector(DenseVectorStorage<double> storage)
: base(storage)
@ -68,34 +71,24 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseVector"/> class with a given size.
/// Create a new dense vector with the given length.
/// All cells of the vector will be initialized to zero.
/// Zero-length vectors are not supported.
/// </summary>
/// <param name="size">
/// the size of the vector.
/// </param>
/// <exception cref="ArgumentException">
/// If <paramref name="size"/> is less than one.
/// </exception>
public DenseVector(int size)
: this(new DenseVectorStorage<double>(size))
/// <exception cref="ArgumentException">If length is less than one.</exception>
public DenseVector(int length)
: this(new DenseVectorStorage<double>(length))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseVector"/> class with a given size
/// and each element set to the given value;
/// Create a new dense vector with the given length.
/// All cells of the vector will be initialized with the provided value.
/// Zero-length vectors are not supported.
/// </summary>
/// <param name="size">
/// the size of the vector.
/// </param>
/// <param name="value">
/// the value to set each element to.
/// </param>
/// <exception cref="ArgumentException">
/// If <paramref name="size"/> is less than one.
/// </exception>
public DenseVector(int size, double value)
: this(size)
/// <exception cref="ArgumentException">If length is less than one.</exception>
public DenseVector(int length, double value)
: this(length)
{
for (var index = 0; index < _values.Length; index++)
{
@ -104,12 +97,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseVector"/> class by
/// copying the values from another.
/// Create a new dense vector as a copy of the given other vector.
/// This new vector will be independent from the other vector.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="other">
/// The vector to create the new vector from.
/// </param>
public DenseVector(Vector<double> other)
: this(other.Count)
{
@ -117,13 +108,12 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseVector"/> class for an array.
/// Create a new dense vector directly binding to a raw array.
/// The array is used directly without copying.
/// Very efficient, but changes to the array and the vector will affect each other.
/// </summary>
/// <param name="array">The array to create this vector from.</param>
/// <remarks>The vector does not copy the array, but keeps a reference to it. Any
/// changes to the vector will also change the array.</remarks>
public DenseVector(double[] array)
: this(new DenseVectorStorage<double>(array.Length, array))
public DenseVector(double[] storage)
: this(new DenseVectorStorage<double>(storage.Length, storage))
{
}

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

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -55,7 +59,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double
readonly double[] _data;
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class.
/// Create a new diagonal matrix straight from an initialized matrix storage instance.
/// The storage is used directly without copying.
/// Intended for advanced scenarios where you're working directly with
/// storage for performance or interop reasons.
/// </summary>
public DiagonalMatrix(DiagonalMatrixStorage<double> storage)
: base(storage)
@ -64,70 +71,59 @@ namespace MathNet.Numerics.LinearAlgebra.Double
_data = _storage.Data;
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class. This matrix is square with a given size.
/// <summary>
/// Create a new square diagonal matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="order">the size of the square matrix.</param>
/// <exception cref="ArgumentException">
/// If <paramref name="order"/> is less than one.
/// </exception>
/// <exception cref="ArgumentException">If the order is less than one.</exception>
public DiagonalMatrix(int order)
: this(new DiagonalMatrixStorage<double>(order, order))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class.
/// Create a new diagonal matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="rows">
/// The number of rows.
/// </param>
/// <param name="columns">
/// The number of columns.
/// </param>
/// <exception cref="ArgumentException">If the row or column count is less than one.</exception>
public DiagonalMatrix(int rows, int columns)
: this(new DiagonalMatrixStorage<double>(rows, columns))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class with all diagonal entries set to a particular value.
/// Create a new diagonal matrix with the given number of rows and columns.
/// All diagonal cells of the matrix will be initialized to the provided value, all non-diagonal ones to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="rows">
/// The number of rows.
/// </param>
/// <param name="columns">
/// The number of columns.
/// </param>
/// <param name="value">The value which we assign to each diagonal element of the matrix.</param>
public DiagonalMatrix(int rows, int columns, double value)
/// <exception cref="ArgumentException">If the row or column count is less than one.</exception>
public DiagonalMatrix(int rows, int columns, double diagonalValue)
: this(rows, columns)
{
for (var i = 0; i < _data.Length; i++)
{
_data[i] = value;
_data[i] = diagonalValue;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class from a one dimensional array with diagonal elements. This constructor
/// will reference the one dimensional array and not copy it.
/// Create a new diagonal matrix with the given number of rows and columns directly binding to a raw array.
/// The array is assumed to contain the diagonal elements only and is used directly without copying.
/// Very efficient, but changes to the array and the matrix will affect each other.
/// </summary>
/// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param>
/// <param name="diagonalArray">The one dimensional array which contain diagonal elements.</param>
public DiagonalMatrix(int rows, int columns, double[] diagonalArray)
: this(new DiagonalMatrixStorage<double>(rows, columns, diagonalArray))
public DiagonalMatrix(int rows, int columns, double[] diagonalStorage)
: this(new DiagonalMatrixStorage<double>(rows, columns, diagonalStorage))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class from a 2D array.
/// Create a new diagonal matrix as a copy of the given two-dimensional array.
/// This new matrix will be independent from the provided array.
/// The array to copy from must be diagonal as well.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="array">The 2D array to create this matrix from.</param>
/// <exception cref="IndexOutOfRangeException">When <paramref name="array"/> contains an off-diagonal element.</exception>
/// <exception cref="IndexOutOfRangeException">Depending on the implementation, an <see cref="IndexOutOfRangeException"/>
/// may be thrown if one of the indices is outside the dimensions of the matrix.</exception>
public DiagonalMatrix(double[,] array)
: this(array.GetLength(0), array.GetLength(1))
{
@ -148,10 +144,11 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class, copying
/// the values from the given matrix.
/// 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>
/// <param name="matrix">The matrix to copy.</param>
public DiagonalMatrix(Matrix<double> matrix)
: this(matrix.RowCount, matrix.ColumnCount)
{

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

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2010 Math.NET
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -38,7 +38,8 @@ namespace MathNet.Numerics.LinearAlgebra.Double
using System.Diagnostics;
/// <summary>
/// A Matrix class with sparse storage. The underlying storage scheme is 3-array compressed-sparse-row (CSR) Format.
/// A Matrix with sparse storage, intended for very large matrices where most of the cells are zero.
/// The underlying storage scheme is 3-array compressed-sparse-row (CSR) Format.
/// <a href="http://en.wikipedia.org/wiki/Sparse_matrix#Compressed_sparse_row_.28CSR_or_CRS.29">Wikipedia - CSR</a>.
/// </summary>
[Serializable]
@ -57,7 +58,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class.
/// Create a new sparse matrix straight from an initialized matrix storage instance.
/// The storage is used directly without copying.
/// Intended for advanced scenarios where you're working directly with
/// storage for performance or interop reasons.
/// </summary>
public SparseMatrix(SparseCompressedRowMatrixStorage<double> storage)
: base(storage)
@ -66,41 +70,33 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class.
/// Create a new sparse matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="rows">
/// The number of rows.
/// </param>
/// <param name="columns">
/// The number of columns.
/// </param>
/// <exception cref="ArgumentException">If the row or column count is less than one.</exception>
public SparseMatrix(int rows, int columns)
: this(new SparseCompressedRowMatrixStorage<double>(rows, columns))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class. This matrix is square with a given size.
/// Create a new square sparse matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="order">the size of the square matrix.</param>
/// <exception cref="ArgumentException">
/// If <paramref name="order"/> is less than one.
/// </exception>
/// <exception cref="ArgumentException">If the order is less than one.</exception>
public SparseMatrix(int order)
: this(order, order)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class with all entries set to a particular value.
/// Create a new sparse matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to the provided value.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="rows">
/// The number of rows.
/// </param>
/// <param name="columns">
/// The number of columns.
/// </param>
/// <param name="value">The value which we assign to each element of the matrix.</param>
/// <exception cref="ArgumentException">If the row or column count is less than one.</exception>
[Obsolete("Use a dense matrix instead. Scheduled for removal in v3.0.")]
public SparseMatrix(int rows, int columns, double value)
: this(rows, columns)
@ -135,13 +131,12 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class from a one dimensional array.
/// Create a new sparse matrix with the given number of rows and columns as a copy of the given array.
/// The array is assumed to be in column-major order.
/// This new matrix will be independent from the provided array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param>
/// <param name="array">The one dimensional array to create this matrix from. This array should store the matrix in column-major order. see: http://en.wikipedia.org/wiki/Column-major_order </param>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="array"/> length is less than <paramref name="rows"/> * <paramref name="columns"/>.
/// </exception>
/// <seealso cref="http://en.wikipedia.org/wiki/Row-major_order"/>
public SparseMatrix(int rows, int columns, double[] array)
: this(rows, columns)
{
@ -160,9 +155,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class from a 2D array.
/// Create a new sparse matrix as a copy of the given two-dimensional array.
/// This new matrix will be independent from the provided array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="array">The 2D array to create this matrix from.</param>
public SparseMatrix(double[,] array)
: this(array.GetLength(0), array.GetLength(1))
{
@ -176,10 +172,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class, copying
/// the values from the given matrix.
/// Create a new sparse matrix as a copy of the given other matrix.
/// This new matrix will be independent from the other matrix.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="matrix">The matrix to copy.</param>
public SparseMatrix(Matrix<double> matrix)
: this(matrix.RowCount, matrix.ColumnCount)
{

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

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2011 Math.NET
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -40,7 +40,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
using Threading;
/// <summary>
/// A vector with sparse storage.
/// A vector with sparse storage, intended for very large vectors where most of the cells are zero.
/// </summary>
/// <remarks>The sparse vector is not thread safe.</remarks>
[Serializable]
@ -59,7 +59,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseVector"/> class.
/// Create a new sparse vector straight from an initialized vector storage instance.
/// The storage is used directly without copying.
/// Intended for advanced scenarios where you're working directly with
/// storage for performance or interop reasons.
/// </summary>
public SparseVector(SparseVectorStorage<double> storage)
: base(storage)
@ -68,42 +71,32 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseVector"/> class with a given size.
/// Create a new sparse vector with the given length.
/// All cells of the vector will be initialized to zero.
/// Zero-length vectors are not supported.
/// </summary>
/// <param name="size">
/// the size of the vector.
/// </param>
/// <exception cref="ArgumentException">
/// If <paramref name="size"/> is less than one.
/// </exception>
public SparseVector(int size)
: this(new SparseVectorStorage<double>(size))
/// <exception cref="ArgumentException">If length is less than one.</exception>
public SparseVector(int length)
: this(new SparseVectorStorage<double>(length))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseVector"/> class with a given size
/// and each element set to the given value;
/// Create a new sparse vector with the given length.
/// All cells of the vector will be initialized with the provided value.
/// Zero-length vectors are not supported.
/// </summary>
/// <param name="size">
/// the size of the vector.
/// </param>
/// <param name="value">
/// the value to set each element to.
/// </param>
/// <exception cref="ArgumentException">
/// If <paramref name="size"/> is less than one.
/// </exception>
/// <exception cref="ArgumentException">If length is less than one.</exception>
[Obsolete("Use a dense vector instead. Scheduled for removal in v3.0.")]
public SparseVector(int size, double value)
: this(new SparseVectorStorage<double>(size))
public SparseVector(int length, double value)
: this(new SparseVectorStorage<double>(length))
{
if (value == 0.0)
{
return;
}
var valueCount = _storage.ValueCount = size;
var valueCount = _storage.ValueCount = length;
var indices = _storage.Indices = new int[valueCount];
var values = _storage.Values = new double[valueCount];
@ -115,12 +108,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseVector"/> class by
/// copying the values from another.
/// Create a new sparse vector as a copy of the given other vector.
/// This new vector will be independent from the other vector.
/// A new memory block will be allocated for storing the vector.
/// </summary>
/// <param name="other">
/// The vector to create the new vector from.
/// </param>
public SparseVector(Vector<double> other)
: this(new SparseVectorStorage<double>(other.Count))
{
@ -128,10 +119,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseVector"/> class for an array.
/// Create a new sparse vector as a copy of the given array.
/// This new vector will be independent from the array.
/// A new memory block will be allocated for storing the vector.
/// </summary>
/// <param name="array">The array to create this vector from.</param>
/// <remarks>The vector copy the array. Any changes to the vector will NOT change the array.</remarks>
public SparseVector(IList<double> array)
: this(new SparseVectorStorage<double>(array.Count))
{

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

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -63,7 +67,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single
readonly float[] _values;
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class.
/// Create a new dense matrix straight from an initialized matrix storage instance.
/// The storage is used directly without copying.
/// Intended for advanced scenarios where you're working directly with
/// storage for performance or interop reasons.
/// </summary>
public DenseMatrix(DenseColumnMajorMatrixStorage<float> storage)
: base(storage)
@ -74,41 +81,33 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class. This matrix is square with a given size.
/// Create a new square dense matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="order">the size of the square matrix.</param>
/// <exception cref="ArgumentException">
/// If <paramref name="order"/> is less than one.
/// </exception>
/// <exception cref="ArgumentException">If the order is less than one.</exception>
public DenseMatrix(int order)
: this(new DenseColumnMajorMatrixStorage<float>(order, order))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class.
/// Create a new dense matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="rows">
/// The number of rows.
/// </param>
/// <param name="columns">
/// The number of columns.
/// </param>
/// <exception cref="ArgumentException">If the row or column count is less than one.</exception>
public DenseMatrix(int rows, int columns)
: this(new DenseColumnMajorMatrixStorage<float>(rows, columns))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class with all entries set to a particular value.
/// Create a new dense matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to the provided value.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="rows">
/// The number of rows.
/// </param>
/// <param name="columns">
/// The number of columns.
/// </param>
/// <param name="value">The value which we assign to each element of the matrix.</param>
/// <exception cref="ArgumentException">If the row or column count is less than one.</exception>
public DenseMatrix(int rows, int columns, float value)
: this(rows, columns)
{
@ -119,22 +118,21 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class from a one dimensional array. This constructor
/// will reference the one dimensional array and not copy it.
/// Create a new dense matrix with the given number of rows and columns directly binding to a raw array.
/// The array is assumed to be in column-major order and is used directly without copying.
/// Very efficient, but changes to the array and the matrix will affect each other.
/// </summary>
/// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param>
/// <param name="array">The one dimensional array to create this matrix from. This array should store the matrix in column-major order. see: http://en.wikipedia.org/wiki/Row-major_order </param>
public DenseMatrix(int rows, int columns, float[] array)
: this(new DenseColumnMajorMatrixStorage<float>(rows, columns, array))
/// <seealso cref="http://en.wikipedia.org/wiki/Row-major_order"/>
public DenseMatrix(int rows, int columns, float[] storage)
: this(new DenseColumnMajorMatrixStorage<float>(rows, columns, storage))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class from a 2D array. This constructor
/// will allocate a completely new memory block for storing the dense matrix.
/// Create a new dense matrix as a copy of the given two-dimensional array.
/// This new matrix will be independent from the provided array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="array">The 2D array to create this matrix from.</param>
public DenseMatrix(float[,] array)
: this(array.GetLength(0), array.GetLength(1))
{
@ -148,10 +146,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseMatrix"/> class, copying
/// the values from the given matrix.
/// Create a new dense matrix as a copy of the given other matrix.
/// This new matrix will be independent from the other matrix.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="matrix">The matrix to copy.</param>
public DenseMatrix(Matrix<float> matrix)
: this(matrix.RowCount, matrix.ColumnCount)
{

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

@ -57,7 +57,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single
readonly float[] _values;
/// <summary>
/// Initializes a new instance of the <see cref="DenseVector"/> class.
/// Create a new dense vector straight from an initialized vector storage instance.
/// The storage is used directly without copying.
/// Intended for advanced scenarios where you're working directly with
/// storage for performance or interop reasons.
/// </summary>
public DenseVector(DenseVectorStorage<float> storage)
: base(storage)
@ -67,34 +70,24 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseVector"/> class with a given size.
/// Create a new dense vector with the given length.
/// All cells of the vector will be initialized to zero.
/// Zero-length vectors are not supported.
/// </summary>
/// <param name="size">
/// the size of the vector.
/// </param>
/// <exception cref="ArgumentException">
/// If <paramref name="size"/> is less than one.
/// </exception>
public DenseVector(int size)
: this(new DenseVectorStorage<float>(size))
/// <exception cref="ArgumentException">If length is less than one.</exception>
public DenseVector(int length)
: this(new DenseVectorStorage<float>(length))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseVector"/> class with a given size
/// and each element set to the given value;
/// Create a new dense vector with the given length.
/// All cells of the vector will be initialized with the provided value.
/// Zero-length vectors are not supported.
/// </summary>
/// <param name="size">
/// the size of the vector.
/// </param>
/// <param name="value">
/// the value to set each element to.
/// </param>
/// <exception cref="ArgumentException">
/// If <paramref name="size"/> is less than one.
/// </exception>
public DenseVector(int size, float value)
: this(size)
/// <exception cref="ArgumentException">If length is less than one.</exception>
public DenseVector(int length, float value)
: this(length)
{
for (var index = 0; index < _values.Length; index++)
{
@ -103,12 +96,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseVector"/> class by
/// copying the values from another.
/// Create a new dense vector as a copy of the given other vector.
/// This new vector will be independent from the other vector.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="other">
/// The vector to create the new vector from.
/// </param>
public DenseVector(Vector<float> other)
: this(other.Count)
{
@ -116,13 +107,12 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
/// <summary>
/// Initializes a new instance of the <see cref="DenseVector"/> class for an array.
/// Create a new dense vector directly binding to a raw array.
/// The array is used directly without copying.
/// Very efficient, but changes to the array and the vector will affect each other.
/// </summary>
/// <param name="array">The array to create this vector from.</param>
/// <remarks>The vector does not copy the array, but keeps a reference to it. Any
/// changes to the vector will also change the array.</remarks>
public DenseVector(float[] array)
: this(new DenseVectorStorage<float>(array.Length, array))
public DenseVector(float[] storage)
: this(new DenseVectorStorage<float>(storage.Length, storage))
{
}

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

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -55,7 +59,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single
readonly float[] _data;
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class.
/// Create a new diagonal matrix straight from an initialized matrix storage instance.
/// The storage is used directly without copying.
/// Intended for advanced scenarios where you're working directly with
/// storage for performance or interop reasons.
/// </summary>
public DiagonalMatrix(DiagonalMatrixStorage<float> storage)
: base(storage)
@ -65,69 +72,58 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class. This matrix is square with a given size.
/// Create a new square diagonal matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="order">the size of the square matrix.</param>
/// <exception cref="ArgumentException">
/// If <paramref name="order"/> is less than one.
/// </exception>
/// <exception cref="ArgumentException">If the order is less than one.</exception>
public DiagonalMatrix(int order)
: this(new DiagonalMatrixStorage<float>(order, order))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class.
/// Create a new diagonal matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="rows">
/// The number of rows.
/// </param>
/// <param name="columns">
/// The number of columns.
/// </param>
/// <exception cref="ArgumentException">If the row or column count is less than one.</exception>
public DiagonalMatrix(int rows, int columns)
: this(new DiagonalMatrixStorage<float>(rows, columns))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class with all diagonal entries set to a particular value.
/// Create a new diagonal matrix with the given number of rows and columns.
/// All diagonal cells of the matrix will be initialized to the provided value, all non-diagonal ones to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="rows">
/// The number of rows.
/// </param>
/// <param name="columns">
/// The number of columns.
/// </param>
/// <param name="value">The value which we assign to each diagonal element of the matrix.</param>
public DiagonalMatrix(int rows, int columns, float value)
/// <exception cref="ArgumentException">If the row or column count is less than one.</exception>
public DiagonalMatrix(int rows, int columns, float diagonalValue)
: this(rows, columns)
{
for (var i = 0; i < _data.Length; i++)
{
_data[i] = value;
_data[i] = diagonalValue;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class from a one dimensional array with diagonal elements. This constructor
/// will reference the one dimensional array and not copy it.
/// Create a new diagonal matrix with the given number of rows and columns directly binding to a raw array.
/// The array is assumed to contain the diagonal elements only and is used directly without copying.
/// Very efficient, but changes to the array and the matrix will affect each other.
/// </summary>
/// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param>
/// <param name="diagonalArray">The one dimensional array which contain diagonal elements.</param>
public DiagonalMatrix(int rows, int columns, float[] diagonalArray)
: this(new DiagonalMatrixStorage<float>(rows, columns, diagonalArray))
public DiagonalMatrix(int rows, int columns, float[] diagonalStorage)
: this(new DiagonalMatrixStorage<float>(rows, columns, diagonalStorage))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class from a 2D array.
/// Create a new diagonal matrix as a copy of the given two-dimensional array.
/// This new matrix will be independent from the provided array.
/// The array to copy from must be diagonal as well.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="array">The 2D array to create this matrix from.</param>
/// <exception cref="IndexOutOfRangeException">When <paramref name="array"/> contains an off-diagonal element.</exception>
/// <exception cref="IndexOutOfRangeException">Depending on the implementation, an <see cref="IndexOutOfRangeException"/>
/// may be thrown if one of the indices is outside the dimensions of the matrix.</exception>
public DiagonalMatrix(float[,] array)
: this(array.GetLength(0), array.GetLength(1))
{
@ -148,10 +144,11 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class, copying
/// the values from the given matrix.
/// 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>
/// <param name="matrix">The matrix to copy.</param>
public DiagonalMatrix(Matrix<float> matrix)
: this(matrix.RowCount, matrix.ColumnCount)
{

6
src/Numerics/LinearAlgebra/Single/Matrix.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND

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

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2010 Math.NET
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -38,7 +38,8 @@ namespace MathNet.Numerics.LinearAlgebra.Single
using System.Diagnostics;
/// <summary>
/// A Matrix class with sparse storage. The underlying storage scheme is 3-array compressed-sparse-row (CSR) Format.
/// A Matrix with sparse storage, intended for very large matrices where most of the cells are zero.
/// The underlying storage scheme is 3-array compressed-sparse-row (CSR) Format.
/// <a href="http://en.wikipedia.org/wiki/Sparse_matrix#Compressed_sparse_row_.28CSR_or_CRS.29">Wikipedia - CSR</a>.
/// </summary>
[Serializable]
@ -57,7 +58,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class.
/// Create a new sparse matrix straight from an initialized matrix storage instance.
/// The storage is used directly without copying.
/// Intended for advanced scenarios where you're working directly with
/// storage for performance or interop reasons.
/// </summary>
public SparseMatrix(SparseCompressedRowMatrixStorage<float> storage)
: base(storage)
@ -66,41 +70,33 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class.
/// Create a new sparse matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="rows">
/// The number of rows.
/// </param>
/// <param name="columns">
/// The number of columns.
/// </param>
/// <exception cref="ArgumentException">If the row or column count is less than one.</exception>
public SparseMatrix(int rows, int columns)
: this(new SparseCompressedRowMatrixStorage<float>(rows, columns))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class. This matrix is square with a given size.
/// Create a new square sparse matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to zero.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="order">the size of the square matrix.</param>
/// <exception cref="ArgumentException">
/// If <paramref name="order"/> is less than one.
/// </exception>
/// <exception cref="ArgumentException">If the order is less than one.</exception>
public SparseMatrix(int order)
: this(order, order)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class with all entries set to a particular value.
/// Create a new sparse matrix with the given number of rows and columns.
/// All cells of the matrix will be initialized to the provided value.
/// Zero-length matrices are not supported.
/// </summary>
/// <param name="rows">
/// The number of rows.
/// </param>
/// <param name="columns">
/// The number of columns.
/// </param>
/// <param name="value">The value which we assign to each element of the matrix.</param>
/// <exception cref="ArgumentException">If the row or column count is less than one.</exception>
[Obsolete("Use a dense matrix instead. Scheduled for removal in v3.0.")]
public SparseMatrix(int rows, int columns, float value)
: this(rows, columns)
@ -135,13 +131,12 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class from a one dimensional array.
/// Create a new sparse matrix with the given number of rows and columns as a copy of the given array.
/// The array is assumed to be in column-major order.
/// This new matrix will be independent from the provided array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param>
/// <param name="array">The one dimensional array to create this matrix from. This array should store the matrix in column-major order. see: http://en.wikipedia.org/wiki/Column-major_order </param>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="array"/> length is less than <paramref name="rows"/> * <paramref name="columns"/>.
/// </exception>
/// <seealso cref="http://en.wikipedia.org/wiki/Row-major_order"/>
public SparseMatrix(int rows, int columns, float[] array)
: this(rows, columns)
{
@ -160,9 +155,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class from a 2D array.
/// Create a new sparse matrix as a copy of the given two-dimensional array.
/// This new matrix will be independent from the provided array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="array">The 2D array to create this matrix from.</param>
public SparseMatrix(float[,] array)
: this(array.GetLength(0), array.GetLength(1))
{
@ -176,10 +172,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseMatrix"/> class, copying
/// the values from the given matrix.
/// Create a new sparse matrix as a copy of the given other matrix.
/// This new matrix will be independent from the other matrix.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
/// <param name="matrix">The matrix to copy.</param>
public SparseMatrix(Matrix<float> matrix)
: this(matrix.RowCount, matrix.ColumnCount)
{

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

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2011 Math.NET
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -40,7 +40,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
using Threading;
/// <summary>
/// A vector with sparse storage.
/// A vector with sparse storage, intended for very large vectors where most of the cells are zero.
/// </summary>
/// <remarks>The sparse vector is not thread safe.</remarks>
[Serializable]
@ -59,7 +59,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseVector"/> class.
/// Create a new sparse vector straight from an initialized vector storage instance.
/// The storage is used directly without copying.
/// Intended for advanced scenarios where you're working directly with
/// storage for performance or interop reasons.
/// </summary>
public SparseVector(SparseVectorStorage<float> storage)
: base(storage)
@ -68,42 +71,32 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseVector"/> class with a given size.
/// Create a new sparse vector with the given length.
/// All cells of the vector will be initialized to zero.
/// Zero-length vectors are not supported.
/// </summary>
/// <param name="size">
/// the size of the vector.
/// </param>
/// <exception cref="ArgumentException">
/// If <paramref name="size"/> is less than one.
/// </exception>
public SparseVector(int size)
: this(new SparseVectorStorage<float>(size))
/// <exception cref="ArgumentException">If length is less than one.</exception>
public SparseVector(int length)
: this(new SparseVectorStorage<float>(length))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseVector"/> class with a given size
/// and each element set to the given value;
/// Create a new sparse vector with the given length.
/// All cells of the vector will be initialized with the provided value.
/// Zero-length vectors are not supported.
/// </summary>
/// <param name="size">
/// the size of the vector.
/// </param>
/// <param name="value">
/// the value to set each element to.
/// </param>
/// <exception cref="ArgumentException">
/// If <paramref name="size"/> is less than one.
/// </exception>
/// <exception cref="ArgumentException">If length is less than one.</exception>
[Obsolete("Use a dense vector instead. Scheduled for removal in v3.0.")]
public SparseVector(int size, float value)
: this(new SparseVectorStorage<float>(size))
public SparseVector(int length, float value)
: this(new SparseVectorStorage<float>(length))
{
if (value == 0.0)
{
return;
}
var valueCount = _storage.ValueCount = size;
var valueCount = _storage.ValueCount = length;
var indices = _storage.Indices = new int[valueCount];
var values = _storage.Values = new float[valueCount];
@ -115,12 +108,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseVector"/> class by
/// copying the values from another.
/// Create a new sparse vector as a copy of the given other vector.
/// This new vector will be independent from the other vector.
/// A new memory block will be allocated for storing the vector.
/// </summary>
/// <param name="other">
/// The vector to create the new vector from.
/// </param>
public SparseVector(Vector<float> other)
: this(new SparseVectorStorage<float>(other.Count))
{
@ -128,10 +119,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
/// <summary>
/// Initializes a new instance of the <see cref="SparseVector"/> class for an array.
/// Create a new sparse vector as a copy of the given array.
/// This new vector will be independent from the array.
/// A new memory block will be allocated for storing the vector.
/// </summary>
/// <param name="array">The array to create this vector from.</param>
/// <remarks>The vector copy the array. Any changes to the vector will NOT change the array.</remarks>
public SparseVector(IList<float> array)
: this(new SparseVectorStorage<float>(array.Count))
{

Loading…
Cancel
Save