From 8ac6bb151f48a1ca92fcbfd489fb89796cba9d7d Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Sat, 6 Apr 2013 15:07:54 +0200 Subject: [PATCH] LA: Improving ctor xml doc based on user feedback --- .../LinearAlgebra/Complex/DenseMatrix.cs | 68 ++++++++-------- .../LinearAlgebra/Complex/DenseVector.cs | 58 ++++++-------- .../LinearAlgebra/Complex/DiagonalMatrix.cs | 77 +++++++++---------- src/Numerics/LinearAlgebra/Complex/Matrix.cs | 6 +- .../LinearAlgebra/Complex/SparseMatrix.cs | 64 ++++++++------- .../LinearAlgebra/Complex/SparseVector.cs | 59 ++++++-------- .../LinearAlgebra/Complex32/DenseMatrix.cs | 68 ++++++++-------- .../LinearAlgebra/Complex32/DenseVector.cs | 58 ++++++-------- .../LinearAlgebra/Complex32/DiagonalMatrix.cs | 75 +++++++++--------- .../LinearAlgebra/Complex32/Matrix.cs | 6 +- .../LinearAlgebra/Complex32/SparseMatrix.cs | 64 ++++++++------- .../LinearAlgebra/Complex32/SparseVector.cs | 59 ++++++-------- .../LinearAlgebra/Double/DenseMatrix.cs | 68 ++++++++-------- .../LinearAlgebra/Double/DenseVector.cs | 58 ++++++-------- .../LinearAlgebra/Double/DiagonalMatrix.cs | 77 +++++++++---------- .../LinearAlgebra/Double/SparseMatrix.cs | 64 ++++++++------- .../LinearAlgebra/Double/SparseVector.cs | 59 ++++++-------- .../LinearAlgebra/Single/DenseMatrix.cs | 68 ++++++++-------- .../LinearAlgebra/Single/DenseVector.cs | 58 ++++++-------- .../LinearAlgebra/Single/DiagonalMatrix.cs | 75 +++++++++--------- src/Numerics/LinearAlgebra/Single/Matrix.cs | 6 +- .../LinearAlgebra/Single/SparseMatrix.cs | 64 ++++++++------- .../LinearAlgebra/Single/SparseVector.cs | 59 ++++++-------- 23 files changed, 609 insertions(+), 709 deletions(-) diff --git a/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs index 49ea658e..9e2e9796 100644 --- a/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs +++ b/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; /// - /// Initializes a new instance of the 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. /// public DenseMatrix(DenseColumnMajorMatrixStorage storage) : base(storage) @@ -74,41 +81,33 @@ namespace MathNet.Numerics.LinearAlgebra.Complex } /// - /// Initializes a new instance of the 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. /// - /// the size of the square matrix. - /// - /// If is less than one. - /// + /// If the order is less than one. public DenseMatrix(int order) : this(new DenseColumnMajorMatrixStorage(order, order)) { } /// - /// Initializes a new instance of the 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. /// - /// - /// The number of rows. - /// - /// - /// The number of columns. - /// + /// If the row or column count is less than one. public DenseMatrix(int rows, int columns) : this(new DenseColumnMajorMatrixStorage(rows, columns)) { } /// - /// Initializes a new instance of the 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. /// - /// - /// The number of rows. - /// - /// - /// The number of columns. - /// - /// The value which we assign to each element of the matrix. + /// If the row or column count is less than one. public DenseMatrix(int rows, int columns, Complex value) : this(rows, columns) { @@ -119,22 +118,21 @@ namespace MathNet.Numerics.LinearAlgebra.Complex } /// - /// Initializes a new instance of the 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. /// - /// The number of rows. - /// The number of columns. - /// 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 - public DenseMatrix(int rows, int columns, Complex[] array) - : this(new DenseColumnMajorMatrixStorage(rows, columns, array)) + /// + public DenseMatrix(int rows, int columns, Complex[] storage) + : this(new DenseColumnMajorMatrixStorage(rows, columns, storage)) { } /// - /// Initializes a new instance of the 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. /// - /// The 2D array to create this matrix from. public DenseMatrix(Complex[,] array) : this(array.GetLength(0), array.GetLength(1)) { @@ -148,10 +146,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex } /// - /// Initializes a new instance of the 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. /// - /// The matrix to copy. public DenseMatrix(Matrix matrix) : this(matrix.RowCount, matrix.ColumnCount) { diff --git a/src/Numerics/LinearAlgebra/Complex/DenseVector.cs b/src/Numerics/LinearAlgebra/Complex/DenseVector.cs index 37ce904c..4dc7a5e5 100644 --- a/src/Numerics/LinearAlgebra/Complex/DenseVector.cs +++ b/src/Numerics/LinearAlgebra/Complex/DenseVector.cs @@ -58,7 +58,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex readonly Complex[] _values; /// - /// Initializes a new instance of the 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. /// public DenseVector(DenseVectorStorage storage) : base(storage) @@ -68,34 +71,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex } /// - /// Initializes a new instance of the 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. /// - /// - /// the size of the vector. - /// - /// - /// If is less than one. - /// - public DenseVector(int size) - : this(new DenseVectorStorage(size)) + /// If length is less than one. + public DenseVector(int length) + : this(new DenseVectorStorage(length)) { } /// - /// Initializes a new instance of the 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. /// - /// - /// the size of the vector. - /// - /// - /// the value to set each element to. - /// - /// - /// If is less than one. - /// - public DenseVector(int size, Complex value) - : this(size) + /// If length is less than one. + 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 } /// - /// Initializes a new instance of the 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. /// - /// - /// The vector to create the new vector from. - /// public DenseVector(Vector other) : this(other.Count) { @@ -117,13 +108,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex } /// - /// Initializes a new instance of the 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. /// - /// The array to create this vector from. - /// The vector does not copy the array, but keeps a reference to it. Any - /// changes to the vector will also change the array. - public DenseVector(Complex[] array) - : this(new DenseVectorStorage(array.Length, array)) + public DenseVector(Complex[] storage) + : this(new DenseVectorStorage(storage.Length, storage)) { } diff --git a/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs index e4f99a27..fbae4c03 100644 --- a/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs +++ b/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; /// - /// Initializes a new instance of the 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. /// public DiagonalMatrix(DiagonalMatrixStorage storage) : base(storage) @@ -65,70 +72,59 @@ namespace MathNet.Numerics.LinearAlgebra.Complex _data = _storage.Data; } - /// - /// Initializes a new instance of the 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. /// - /// the size of the square matrix. - /// - /// If is less than one. - /// + /// If the order is less than one. public DiagonalMatrix(int order) : this(new DiagonalMatrixStorage(order, order)) { } /// - /// Initializes a new instance of the 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. /// - /// - /// The number of rows. - /// - /// - /// The number of columns. - /// + /// If the row or column count is less than one. public DiagonalMatrix(int rows, int columns) : this(new DiagonalMatrixStorage(rows, columns)) { } /// - /// Initializes a new instance of the 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. /// - /// - /// The number of rows. - /// - /// - /// The number of columns. - /// - /// The value which we assign to each diagonal element of the matrix. - public DiagonalMatrix(int rows, int columns, Complex value) + /// If the row or column count is less than one. + 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; } } /// - /// Initializes a new instance of the 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. /// - /// The number of rows. - /// The number of columns. - /// The one dimensional array which contain diagonal elements. - public DiagonalMatrix(int rows, int columns, Complex[] diagonalArray) - : this(new DiagonalMatrixStorage(rows, columns, diagonalArray)) + public DiagonalMatrix(int rows, int columns, Complex[] diagonalStorage) + : this(new DiagonalMatrixStorage(rows, columns, diagonalStorage)) { } /// - /// Initializes a new instance of the 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. /// - /// The 2D array to create this matrix from. - /// When contains an off-diagonal element. - /// Depending on the implementation, an - /// may be thrown if one of the indices is outside the dimensions of the matrix. public DiagonalMatrix(Complex[,] array) : this(array.GetLength(0), array.GetLength(1)) { @@ -149,10 +145,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex } /// - /// Initializes a new instance of the 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. /// - /// The matrix to copy. public DiagonalMatrix(Matrix matrix) : this(matrix.RowCount, matrix.ColumnCount) { diff --git a/src/Numerics/LinearAlgebra/Complex/Matrix.cs b/src/Numerics/LinearAlgebra/Complex/Matrix.cs index d842bd52..96c79790 100644 --- a/src/Numerics/LinearAlgebra/Complex/Matrix.cs +++ b/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 diff --git a/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs index 28846e08..f88b6b4b 100644 --- a/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs +++ b/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; /// - /// 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. /// Wikipedia - CSR. /// [Serializable] @@ -58,7 +59,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex } /// - /// Initializes a new instance of the 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. /// public SparseMatrix(SparseCompressedRowMatrixStorage storage) : base(storage) @@ -67,41 +71,33 @@ namespace MathNet.Numerics.LinearAlgebra.Complex } /// - /// Initializes a new instance of the 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. /// - /// - /// The number of rows. - /// - /// - /// The number of columns. - /// + /// If the row or column count is less than one. public SparseMatrix(int rows, int columns) : this(new SparseCompressedRowMatrixStorage(rows, columns)) { } /// - /// Initializes a new instance of the 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. /// - /// the size of the square matrix. - /// - /// If is less than one. - /// + /// If the order is less than one. public SparseMatrix(int order) : this(order, order) { } /// - /// Initializes a new instance of the 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. /// - /// - /// The number of rows. - /// - /// - /// The number of columns. - /// - /// The value which we assign to each element of the matrix. + /// If the row or column count is less than one. [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 } /// - /// Initializes a new instance of the 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. /// - /// The number of rows. - /// The number of columns. - /// 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 - /// If length is less than * . - /// + /// public SparseMatrix(int rows, int columns, Complex[] array) : this(rows, columns) { @@ -161,9 +156,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex } /// - /// Initializes a new instance of the 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. /// - /// The 2D array to create this matrix from. public SparseMatrix(Complex[,] array) : this(array.GetLength(0), array.GetLength(1)) { @@ -177,10 +173,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex } /// - /// Initializes a new instance of the 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. /// - /// The matrix to copy. public SparseMatrix(Matrix matrix) : this(matrix.RowCount, matrix.ColumnCount) { diff --git a/src/Numerics/LinearAlgebra/Complex/SparseVector.cs b/src/Numerics/LinearAlgebra/Complex/SparseVector.cs index d7bd7535..cb68186b 100644 --- a/src/Numerics/LinearAlgebra/Complex/SparseVector.cs +++ b/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; /// - /// A vector with sparse storage. + /// A vector with sparse storage, intended for very large vectors where most of the cells are zero. /// /// The sparse vector is not thread safe. [Serializable] @@ -59,7 +59,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex } /// - /// Initializes a new instance of the 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. /// public SparseVector(SparseVectorStorage storage) : base(storage) @@ -68,42 +71,32 @@ namespace MathNet.Numerics.LinearAlgebra.Complex } /// - /// Initializes a new instance of the 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. /// - /// - /// the size of the vector. - /// - /// - /// If is less than one. - /// - public SparseVector(int size) - : this(new SparseVectorStorage(size)) + /// If length is less than one. + public SparseVector(int length) + : this(new SparseVectorStorage(length)) { } /// - /// Initializes a new instance of the 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. /// - /// - /// the size of the vector. - /// - /// - /// the value to set each element to. - /// - /// - /// If is less than one. - /// + /// If length is less than one. [Obsolete("Use a dense vector instead. Scheduled for removal in v3.0.")] - public SparseVector(int size, Complex value) - : this(new SparseVectorStorage(size)) + public SparseVector(int length, Complex value) + : this(new SparseVectorStorage(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 } /// - /// Initializes a new instance of the 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. /// - /// - /// The vector to create the new vector from. - /// public SparseVector(Vector other) : this(new SparseVectorStorage(other.Count)) { @@ -128,10 +119,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex } /// - /// Initializes a new instance of the 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. /// - /// The array to create this vector from. - /// The vector copy the array. Any changes to the vector will NOT change the array. public SparseVector(IList array) : this(new SparseVectorStorage(array.Count)) { diff --git a/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs index bfd57689..d0448480 100644 --- a/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs +++ b/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; /// - /// Initializes a new instance of the 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. /// public DenseMatrix(DenseColumnMajorMatrixStorage storage) : base(storage) @@ -74,41 +81,33 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 } /// - /// Initializes a new instance of the 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. /// - /// the size of the square matrix. - /// - /// If is less than one. - /// + /// If the order is less than one. public DenseMatrix(int order) : this(new DenseColumnMajorMatrixStorage(order, order)) { } /// - /// Initializes a new instance of the 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. /// - /// - /// The number of rows. - /// - /// - /// The number of columns. - /// + /// If the row or column count is less than one. public DenseMatrix(int rows, int columns) : this(new DenseColumnMajorMatrixStorage(rows, columns)) { } /// - /// Initializes a new instance of the 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. /// - /// - /// The number of rows. - /// - /// - /// The number of columns. - /// - /// The value which we assign to each element of the matrix. + /// If the row or column count is less than one. public DenseMatrix(int rows, int columns, Complex32 value) : this(rows, columns) { @@ -119,22 +118,21 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 } /// - /// Initializes a new instance of the 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. /// - /// The number of rows. - /// The number of columns. - /// 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 - public DenseMatrix(int rows, int columns, Complex32[] array) - : this(new DenseColumnMajorMatrixStorage(rows, columns, array)) + /// + public DenseMatrix(int rows, int columns, Complex32[] storage) + : this(new DenseColumnMajorMatrixStorage(rows, columns, storage)) { } /// - /// Initializes a new instance of the 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. /// - /// The 2D array to create this matrix from. public DenseMatrix(Complex32[,] array) : this(array.GetLength(0), array.GetLength(1)) { @@ -148,10 +146,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 } /// - /// Initializes a new instance of the 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. /// - /// The matrix to copy. public DenseMatrix(Matrix matrix) : this(matrix.RowCount, matrix.ColumnCount) { diff --git a/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs b/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs index ac607077..c86a9cd4 100644 --- a/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs +++ b/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs @@ -58,7 +58,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 readonly Complex32[] _values; /// - /// Initializes a new instance of the 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. /// public DenseVector(DenseVectorStorage storage) : base(storage) @@ -68,34 +71,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 } /// - /// Initializes a new instance of the 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. /// - /// - /// the size of the vector. - /// - /// - /// If is less than one. - /// - public DenseVector(int size) - : this(new DenseVectorStorage(size)) + /// If length is less than one. + public DenseVector(int length) + : this(new DenseVectorStorage(length)) { } /// - /// Initializes a new instance of the 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. /// - /// - /// the size of the vector. - /// - /// - /// the value to set each element to. - /// - /// - /// If is less than one. - /// - public DenseVector(int size, Complex32 value) - : this(size) + /// If length is less than one. + 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 } /// - /// Initializes a new instance of the 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. /// - /// - /// The vector to create the new vector from. - /// public DenseVector(Vector other) : this(other.Count) { @@ -117,13 +108,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 } /// - /// Initializes a new instance of the 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. /// - /// The array to create this vector from. - /// The vector does not copy the array, but keeps a reference to it. Any - /// changes to the vector will also change the array. - public DenseVector(Complex32[] array) - : this(new DenseVectorStorage(array.Length, array)) + public DenseVector(Complex32[] storage) + : this(new DenseVectorStorage(storage.Length, storage)) { } diff --git a/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs index 0dc6b3f5..1d9827f9 100644 --- a/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs +++ b/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; /// - /// Initializes a new instance of the 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. /// public DiagonalMatrix(DiagonalMatrixStorage storage) : base(storage) @@ -66,69 +73,58 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 } /// - /// Initializes a new instance of the 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. /// - /// the size of the square matrix. - /// - /// If is less than one. - /// + /// If the order is less than one. public DiagonalMatrix(int order) : this(new DiagonalMatrixStorage(order, order)) { } /// - /// Initializes a new instance of the 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. /// - /// - /// The number of rows. - /// - /// - /// The number of columns. - /// + /// If the row or column count is less than one. public DiagonalMatrix(int rows, int columns) : this(new DiagonalMatrixStorage(rows, columns)) { } /// - /// Initializes a new instance of the 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. /// - /// - /// The number of rows. - /// - /// - /// The number of columns. - /// - /// The value which we assign to each diagonal element of the matrix. - public DiagonalMatrix(int rows, int columns, Complex32 value) + /// If the row or column count is less than one. + 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; } } /// - /// Initializes a new instance of the 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. /// - /// The number of rows. - /// The number of columns. - /// The one dimensional array which contain diagonal elements. - public DiagonalMatrix(int rows, int columns, Complex32[] diagonalArray) - : this(new DiagonalMatrixStorage(rows, columns, diagonalArray)) + public DiagonalMatrix(int rows, int columns, Complex32[] diagonalStorage) + : this(new DiagonalMatrixStorage(rows, columns, diagonalStorage)) { } /// - /// Initializes a new instance of the 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. /// - /// The 2D array to create this matrix from. - /// When contains an off-diagonal element. - /// Depending on the implementation, an - /// may be thrown if one of the indices is outside the dimensions of the matrix. public DiagonalMatrix(Complex32[,] array) : this(array.GetLength(0), array.GetLength(1)) { @@ -149,10 +145,11 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 } /// - /// Initializes a new instance of the 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. /// - /// The matrix to copy. public DiagonalMatrix(Matrix matrix) : this(matrix.RowCount, matrix.ColumnCount) { diff --git a/src/Numerics/LinearAlgebra/Complex32/Matrix.cs b/src/Numerics/LinearAlgebra/Complex32/Matrix.cs index 4c4165cd..04a496be 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Matrix.cs +++ b/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 diff --git a/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs index 85063f7b..6d7e4ad2 100644 --- a/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs +++ b/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; /// - /// 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. /// Wikipedia - CSR. /// [Serializable] @@ -58,7 +59,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 } /// - /// Initializes a new instance of the 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. /// public SparseMatrix(SparseCompressedRowMatrixStorage storage) : base(storage) @@ -67,41 +71,33 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 } /// - /// Initializes a new instance of the 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. /// - /// - /// The number of rows. - /// - /// - /// The number of columns. - /// + /// If the row or column count is less than one. public SparseMatrix(int rows, int columns) : this(new SparseCompressedRowMatrixStorage(rows, columns)) { } /// - /// Initializes a new instance of the 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. /// - /// the size of the square matrix. - /// - /// If is less than one. - /// + /// If the order is less than one. public SparseMatrix(int order) : this(order, order) { } /// - /// Initializes a new instance of the 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. /// - /// - /// The number of rows. - /// - /// - /// The number of columns. - /// - /// The value which we assign to each element of the matrix. + /// If the row or column count is less than one. [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 } /// - /// Initializes a new instance of the 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. /// - /// The number of rows. - /// The number of columns. - /// 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 - /// If length is less than * . - /// + /// public SparseMatrix(int rows, int columns, Complex32[] array) : this(rows, columns) { @@ -161,9 +156,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 } /// - /// Initializes a new instance of the 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. /// - /// The 2D array to create this matrix from. public SparseMatrix(Complex32[,] array) : this(array.GetLength(0), array.GetLength(1)) { @@ -177,10 +173,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 } /// - /// Initializes a new instance of the 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. /// - /// The matrix to copy. public SparseMatrix(Matrix matrix) : this(matrix.RowCount, matrix.ColumnCount) { diff --git a/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs b/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs index d17f7faf..37bb2c20 100644 --- a/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs +++ b/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; /// - /// A vector with sparse storage. + /// A vector with sparse storage, intended for very large vectors where most of the cells are zero. /// /// The sparse vector is not thread safe. [Serializable] @@ -59,7 +59,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 } /// - /// Initializes a new instance of the 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. /// public SparseVector(SparseVectorStorage storage) : base(storage) @@ -68,42 +71,32 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 } /// - /// Initializes a new instance of the 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. /// - /// - /// the size of the vector. - /// - /// - /// If is less than one. - /// - public SparseVector(int size) - : this(new SparseVectorStorage(size)) + /// If length is less than one. + public SparseVector(int length) + : this(new SparseVectorStorage(length)) { } /// - /// Initializes a new instance of the 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. /// - /// - /// the size of the vector. - /// - /// - /// the value to set each element to. - /// - /// - /// If is less than one. - /// + /// If length is less than one. [Obsolete("Use a dense vector instead. Scheduled for removal in v3.0.")] - public SparseVector(int size, Complex32 value) - : this(new SparseVectorStorage(size)) + public SparseVector(int length, Complex32 value) + : this(new SparseVectorStorage(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 } /// - /// Initializes a new instance of the 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. /// - /// - /// The vector to create the new vector from. - /// public SparseVector(Vector other) : this(new SparseVectorStorage(other.Count)) { @@ -128,10 +119,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 } /// - /// Initializes a new instance of the 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. /// - /// The array to create this vector from. - /// The vector copy the array. Any changes to the vector will NOT change the array. public SparseVector(IList array) : this(new SparseVectorStorage(array.Count)) { diff --git a/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs index 17da0bd7..29398b2b 100644 --- a/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs +++ b/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; /// - /// Initializes a new instance of the 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. /// public DenseMatrix(DenseColumnMajorMatrixStorage storage) : base(storage) @@ -74,41 +81,33 @@ namespace MathNet.Numerics.LinearAlgebra.Double } /// - /// Initializes a new instance of the 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. /// - /// the size of the square matrix. - /// - /// If is less than one. - /// + /// If the order is less than one. public DenseMatrix(int order) : this(new DenseColumnMajorMatrixStorage(order, order)) { } /// - /// Initializes a new instance of the 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. /// - /// - /// The number of rows. - /// - /// - /// The number of columns. - /// + /// If the row or column count is less than one. public DenseMatrix(int rows, int columns) : this(new DenseColumnMajorMatrixStorage(rows, columns)) { } /// - /// Initializes a new instance of the 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. /// - /// - /// The number of rows. - /// - /// - /// The number of columns. - /// - /// The value which we assign to each element of the matrix. + /// If the row or column count is less than one. public DenseMatrix(int rows, int columns, double value) : this(rows, columns) { @@ -119,22 +118,21 @@ namespace MathNet.Numerics.LinearAlgebra.Double } /// - /// Initializes a new instance of the 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. /// - /// The number of rows. - /// The number of columns. - /// 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 - public DenseMatrix(int rows, int columns, double[] array) - : this(new DenseColumnMajorMatrixStorage(rows, columns, array)) + /// + public DenseMatrix(int rows, int columns, double[] storage) + : this(new DenseColumnMajorMatrixStorage(rows, columns, storage)) { } /// - /// Initializes a new instance of the 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. /// - /// The 2D array to create this matrix from. public DenseMatrix(double[,] array) : this(array.GetLength(0), array.GetLength(1)) { @@ -148,10 +146,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double } /// - /// Initializes a new instance of the 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. /// - /// The matrix to copy. public DenseMatrix(Matrix matrix) : this(matrix.RowCount, matrix.ColumnCount) { diff --git a/src/Numerics/LinearAlgebra/Double/DenseVector.cs b/src/Numerics/LinearAlgebra/Double/DenseVector.cs index 8b0f6e3b..cac1b120 100644 --- a/src/Numerics/LinearAlgebra/Double/DenseVector.cs +++ b/src/Numerics/LinearAlgebra/Double/DenseVector.cs @@ -58,7 +58,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double readonly double[] _values; /// - /// Initializes a new instance of the 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. /// public DenseVector(DenseVectorStorage storage) : base(storage) @@ -68,34 +71,24 @@ namespace MathNet.Numerics.LinearAlgebra.Double } /// - /// Initializes a new instance of the 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. /// - /// - /// the size of the vector. - /// - /// - /// If is less than one. - /// - public DenseVector(int size) - : this(new DenseVectorStorage(size)) + /// If length is less than one. + public DenseVector(int length) + : this(new DenseVectorStorage(length)) { } /// - /// Initializes a new instance of the 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. /// - /// - /// the size of the vector. - /// - /// - /// the value to set each element to. - /// - /// - /// If is less than one. - /// - public DenseVector(int size, double value) - : this(size) + /// If length is less than one. + 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 } /// - /// Initializes a new instance of the 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. /// - /// - /// The vector to create the new vector from. - /// public DenseVector(Vector other) : this(other.Count) { @@ -117,13 +108,12 @@ namespace MathNet.Numerics.LinearAlgebra.Double } /// - /// Initializes a new instance of the 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. /// - /// The array to create this vector from. - /// The vector does not copy the array, but keeps a reference to it. Any - /// changes to the vector will also change the array. - public DenseVector(double[] array) - : this(new DenseVectorStorage(array.Length, array)) + public DenseVector(double[] storage) + : this(new DenseVectorStorage(storage.Length, storage)) { } diff --git a/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs index 18c31bfb..fd8150f1 100644 --- a/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs +++ b/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; /// - /// Initializes a new instance of the 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. /// public DiagonalMatrix(DiagonalMatrixStorage storage) : base(storage) @@ -64,70 +71,59 @@ namespace MathNet.Numerics.LinearAlgebra.Double _data = _storage.Data; } - /// - /// Initializes a new instance of the 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. /// - /// the size of the square matrix. - /// - /// If is less than one. - /// + /// If the order is less than one. public DiagonalMatrix(int order) : this(new DiagonalMatrixStorage(order, order)) { } /// - /// Initializes a new instance of the 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. /// - /// - /// The number of rows. - /// - /// - /// The number of columns. - /// + /// If the row or column count is less than one. public DiagonalMatrix(int rows, int columns) : this(new DiagonalMatrixStorage(rows, columns)) { } /// - /// Initializes a new instance of the 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. /// - /// - /// The number of rows. - /// - /// - /// The number of columns. - /// - /// The value which we assign to each diagonal element of the matrix. - public DiagonalMatrix(int rows, int columns, double value) + /// If the row or column count is less than one. + 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; } } /// - /// Initializes a new instance of the 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. /// - /// The number of rows. - /// The number of columns. - /// The one dimensional array which contain diagonal elements. - public DiagonalMatrix(int rows, int columns, double[] diagonalArray) - : this(new DiagonalMatrixStorage(rows, columns, diagonalArray)) + public DiagonalMatrix(int rows, int columns, double[] diagonalStorage) + : this(new DiagonalMatrixStorage(rows, columns, diagonalStorage)) { } /// - /// Initializes a new instance of the 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. /// - /// The 2D array to create this matrix from. - /// When contains an off-diagonal element. - /// Depending on the implementation, an - /// may be thrown if one of the indices is outside the dimensions of the matrix. public DiagonalMatrix(double[,] array) : this(array.GetLength(0), array.GetLength(1)) { @@ -148,10 +144,11 @@ namespace MathNet.Numerics.LinearAlgebra.Double } /// - /// Initializes a new instance of the 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. /// - /// The matrix to copy. public DiagonalMatrix(Matrix matrix) : this(matrix.RowCount, matrix.ColumnCount) { diff --git a/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs index 9bf9612a..9a0f91a5 100644 --- a/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs +++ b/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; /// - /// 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. /// Wikipedia - CSR. /// [Serializable] @@ -57,7 +58,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double } /// - /// Initializes a new instance of the 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. /// public SparseMatrix(SparseCompressedRowMatrixStorage storage) : base(storage) @@ -66,41 +70,33 @@ namespace MathNet.Numerics.LinearAlgebra.Double } /// - /// Initializes a new instance of the 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. /// - /// - /// The number of rows. - /// - /// - /// The number of columns. - /// + /// If the row or column count is less than one. public SparseMatrix(int rows, int columns) : this(new SparseCompressedRowMatrixStorage(rows, columns)) { } /// - /// Initializes a new instance of the 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. /// - /// the size of the square matrix. - /// - /// If is less than one. - /// + /// If the order is less than one. public SparseMatrix(int order) : this(order, order) { } /// - /// Initializes a new instance of the 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. /// - /// - /// The number of rows. - /// - /// - /// The number of columns. - /// - /// The value which we assign to each element of the matrix. + /// If the row or column count is less than one. [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 } /// - /// Initializes a new instance of the 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. /// - /// The number of rows. - /// The number of columns. - /// 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 - /// If length is less than * . - /// + /// public SparseMatrix(int rows, int columns, double[] array) : this(rows, columns) { @@ -160,9 +155,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double } /// - /// Initializes a new instance of the 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. /// - /// The 2D array to create this matrix from. public SparseMatrix(double[,] array) : this(array.GetLength(0), array.GetLength(1)) { @@ -176,10 +172,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double } /// - /// Initializes a new instance of the 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. /// - /// The matrix to copy. public SparseMatrix(Matrix matrix) : this(matrix.RowCount, matrix.ColumnCount) { diff --git a/src/Numerics/LinearAlgebra/Double/SparseVector.cs b/src/Numerics/LinearAlgebra/Double/SparseVector.cs index bc104a21..fc323bfc 100644 --- a/src/Numerics/LinearAlgebra/Double/SparseVector.cs +++ b/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; /// - /// A vector with sparse storage. + /// A vector with sparse storage, intended for very large vectors where most of the cells are zero. /// /// The sparse vector is not thread safe. [Serializable] @@ -59,7 +59,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double } /// - /// Initializes a new instance of the 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. /// public SparseVector(SparseVectorStorage storage) : base(storage) @@ -68,42 +71,32 @@ namespace MathNet.Numerics.LinearAlgebra.Double } /// - /// Initializes a new instance of the 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. /// - /// - /// the size of the vector. - /// - /// - /// If is less than one. - /// - public SparseVector(int size) - : this(new SparseVectorStorage(size)) + /// If length is less than one. + public SparseVector(int length) + : this(new SparseVectorStorage(length)) { } /// - /// Initializes a new instance of the 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. /// - /// - /// the size of the vector. - /// - /// - /// the value to set each element to. - /// - /// - /// If is less than one. - /// + /// If length is less than one. [Obsolete("Use a dense vector instead. Scheduled for removal in v3.0.")] - public SparseVector(int size, double value) - : this(new SparseVectorStorage(size)) + public SparseVector(int length, double value) + : this(new SparseVectorStorage(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 } /// - /// Initializes a new instance of the 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. /// - /// - /// The vector to create the new vector from. - /// public SparseVector(Vector other) : this(new SparseVectorStorage(other.Count)) { @@ -128,10 +119,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double } /// - /// Initializes a new instance of the 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. /// - /// The array to create this vector from. - /// The vector copy the array. Any changes to the vector will NOT change the array. public SparseVector(IList array) : this(new SparseVectorStorage(array.Count)) { diff --git a/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs index a4c84e08..97f2ad9b 100644 --- a/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs +++ b/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; /// - /// Initializes a new instance of the 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. /// public DenseMatrix(DenseColumnMajorMatrixStorage storage) : base(storage) @@ -74,41 +81,33 @@ namespace MathNet.Numerics.LinearAlgebra.Single } /// - /// Initializes a new instance of the 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. /// - /// the size of the square matrix. - /// - /// If is less than one. - /// + /// If the order is less than one. public DenseMatrix(int order) : this(new DenseColumnMajorMatrixStorage(order, order)) { } /// - /// Initializes a new instance of the 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. /// - /// - /// The number of rows. - /// - /// - /// The number of columns. - /// + /// If the row or column count is less than one. public DenseMatrix(int rows, int columns) : this(new DenseColumnMajorMatrixStorage(rows, columns)) { } /// - /// Initializes a new instance of the 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. /// - /// - /// The number of rows. - /// - /// - /// The number of columns. - /// - /// The value which we assign to each element of the matrix. + /// If the row or column count is less than one. public DenseMatrix(int rows, int columns, float value) : this(rows, columns) { @@ -119,22 +118,21 @@ namespace MathNet.Numerics.LinearAlgebra.Single } /// - /// Initializes a new instance of the 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. /// - /// The number of rows. - /// The number of columns. - /// 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 - public DenseMatrix(int rows, int columns, float[] array) - : this(new DenseColumnMajorMatrixStorage(rows, columns, array)) + /// + public DenseMatrix(int rows, int columns, float[] storage) + : this(new DenseColumnMajorMatrixStorage(rows, columns, storage)) { } /// - /// Initializes a new instance of the 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. /// - /// The 2D array to create this matrix from. public DenseMatrix(float[,] array) : this(array.GetLength(0), array.GetLength(1)) { @@ -148,10 +146,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single } /// - /// Initializes a new instance of the 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. /// - /// The matrix to copy. public DenseMatrix(Matrix matrix) : this(matrix.RowCount, matrix.ColumnCount) { diff --git a/src/Numerics/LinearAlgebra/Single/DenseVector.cs b/src/Numerics/LinearAlgebra/Single/DenseVector.cs index 6d5b28fe..2e142c9d 100644 --- a/src/Numerics/LinearAlgebra/Single/DenseVector.cs +++ b/src/Numerics/LinearAlgebra/Single/DenseVector.cs @@ -57,7 +57,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single readonly float[] _values; /// - /// Initializes a new instance of the 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. /// public DenseVector(DenseVectorStorage storage) : base(storage) @@ -67,34 +70,24 @@ namespace MathNet.Numerics.LinearAlgebra.Single } /// - /// Initializes a new instance of the 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. /// - /// - /// the size of the vector. - /// - /// - /// If is less than one. - /// - public DenseVector(int size) - : this(new DenseVectorStorage(size)) + /// If length is less than one. + public DenseVector(int length) + : this(new DenseVectorStorage(length)) { } /// - /// Initializes a new instance of the 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. /// - /// - /// the size of the vector. - /// - /// - /// the value to set each element to. - /// - /// - /// If is less than one. - /// - public DenseVector(int size, float value) - : this(size) + /// If length is less than one. + 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 } /// - /// Initializes a new instance of the 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. /// - /// - /// The vector to create the new vector from. - /// public DenseVector(Vector other) : this(other.Count) { @@ -116,13 +107,12 @@ namespace MathNet.Numerics.LinearAlgebra.Single } /// - /// Initializes a new instance of the 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. /// - /// The array to create this vector from. - /// The vector does not copy the array, but keeps a reference to it. Any - /// changes to the vector will also change the array. - public DenseVector(float[] array) - : this(new DenseVectorStorage(array.Length, array)) + public DenseVector(float[] storage) + : this(new DenseVectorStorage(storage.Length, storage)) { } diff --git a/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs index 2722bc53..45ff9cd8 100644 --- a/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs +++ b/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; /// - /// Initializes a new instance of the 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. /// public DiagonalMatrix(DiagonalMatrixStorage storage) : base(storage) @@ -65,69 +72,58 @@ namespace MathNet.Numerics.LinearAlgebra.Single } /// - /// Initializes a new instance of the 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. /// - /// the size of the square matrix. - /// - /// If is less than one. - /// + /// If the order is less than one. public DiagonalMatrix(int order) : this(new DiagonalMatrixStorage(order, order)) { } /// - /// Initializes a new instance of the 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. /// - /// - /// The number of rows. - /// - /// - /// The number of columns. - /// + /// If the row or column count is less than one. public DiagonalMatrix(int rows, int columns) : this(new DiagonalMatrixStorage(rows, columns)) { } /// - /// Initializes a new instance of the 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. /// - /// - /// The number of rows. - /// - /// - /// The number of columns. - /// - /// The value which we assign to each diagonal element of the matrix. - public DiagonalMatrix(int rows, int columns, float value) + /// If the row or column count is less than one. + 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; } } /// - /// Initializes a new instance of the 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. /// - /// The number of rows. - /// The number of columns. - /// The one dimensional array which contain diagonal elements. - public DiagonalMatrix(int rows, int columns, float[] diagonalArray) - : this(new DiagonalMatrixStorage(rows, columns, diagonalArray)) + public DiagonalMatrix(int rows, int columns, float[] diagonalStorage) + : this(new DiagonalMatrixStorage(rows, columns, diagonalStorage)) { } /// - /// Initializes a new instance of the 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. /// - /// The 2D array to create this matrix from. - /// When contains an off-diagonal element. - /// Depending on the implementation, an - /// may be thrown if one of the indices is outside the dimensions of the matrix. public DiagonalMatrix(float[,] array) : this(array.GetLength(0), array.GetLength(1)) { @@ -148,10 +144,11 @@ namespace MathNet.Numerics.LinearAlgebra.Single } /// - /// Initializes a new instance of the 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. /// - /// The matrix to copy. public DiagonalMatrix(Matrix matrix) : this(matrix.RowCount, matrix.ColumnCount) { diff --git a/src/Numerics/LinearAlgebra/Single/Matrix.cs b/src/Numerics/LinearAlgebra/Single/Matrix.cs index 9d46ce06..9f781a28 100644 --- a/src/Numerics/LinearAlgebra/Single/Matrix.cs +++ b/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 diff --git a/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs index 496539ae..b4a6924c 100644 --- a/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs +++ b/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; /// - /// 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. /// Wikipedia - CSR. /// [Serializable] @@ -57,7 +58,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single } /// - /// Initializes a new instance of the 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. /// public SparseMatrix(SparseCompressedRowMatrixStorage storage) : base(storage) @@ -66,41 +70,33 @@ namespace MathNet.Numerics.LinearAlgebra.Single } /// - /// Initializes a new instance of the 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. /// - /// - /// The number of rows. - /// - /// - /// The number of columns. - /// + /// If the row or column count is less than one. public SparseMatrix(int rows, int columns) : this(new SparseCompressedRowMatrixStorage(rows, columns)) { } /// - /// Initializes a new instance of the 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. /// - /// the size of the square matrix. - /// - /// If is less than one. - /// + /// If the order is less than one. public SparseMatrix(int order) : this(order, order) { } /// - /// Initializes a new instance of the 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. /// - /// - /// The number of rows. - /// - /// - /// The number of columns. - /// - /// The value which we assign to each element of the matrix. + /// If the row or column count is less than one. [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 } /// - /// Initializes a new instance of the 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. /// - /// The number of rows. - /// The number of columns. - /// 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 - /// If length is less than * . - /// + /// public SparseMatrix(int rows, int columns, float[] array) : this(rows, columns) { @@ -160,9 +155,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single } /// - /// Initializes a new instance of the 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. /// - /// The 2D array to create this matrix from. public SparseMatrix(float[,] array) : this(array.GetLength(0), array.GetLength(1)) { @@ -176,10 +172,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single } /// - /// Initializes a new instance of the 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. /// - /// The matrix to copy. public SparseMatrix(Matrix matrix) : this(matrix.RowCount, matrix.ColumnCount) { diff --git a/src/Numerics/LinearAlgebra/Single/SparseVector.cs b/src/Numerics/LinearAlgebra/Single/SparseVector.cs index 8c1e1db4..dcf44748 100644 --- a/src/Numerics/LinearAlgebra/Single/SparseVector.cs +++ b/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; /// - /// A vector with sparse storage. + /// A vector with sparse storage, intended for very large vectors where most of the cells are zero. /// /// The sparse vector is not thread safe. [Serializable] @@ -59,7 +59,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single } /// - /// Initializes a new instance of the 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. /// public SparseVector(SparseVectorStorage storage) : base(storage) @@ -68,42 +71,32 @@ namespace MathNet.Numerics.LinearAlgebra.Single } /// - /// Initializes a new instance of the 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. /// - /// - /// the size of the vector. - /// - /// - /// If is less than one. - /// - public SparseVector(int size) - : this(new SparseVectorStorage(size)) + /// If length is less than one. + public SparseVector(int length) + : this(new SparseVectorStorage(length)) { } /// - /// Initializes a new instance of the 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. /// - /// - /// the size of the vector. - /// - /// - /// the value to set each element to. - /// - /// - /// If is less than one. - /// + /// If length is less than one. [Obsolete("Use a dense vector instead. Scheduled for removal in v3.0.")] - public SparseVector(int size, float value) - : this(new SparseVectorStorage(size)) + public SparseVector(int length, float value) + : this(new SparseVectorStorage(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 } /// - /// Initializes a new instance of the 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. /// - /// - /// The vector to create the new vector from. - /// public SparseVector(Vector other) : this(new SparseVectorStorage(other.Count)) { @@ -128,10 +119,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single } /// - /// Initializes a new instance of the 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. /// - /// The array to create this vector from. - /// The vector copy the array. Any changes to the vector will NOT change the array. public SparseVector(IList array) : this(new SparseVectorStorage(array.Count)) {