diff --git a/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs index dc5d55b1..8b001712 100644 --- a/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs @@ -29,6 +29,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex using System; using System.Numerics; using Algorithms.LinearAlgebra; + using Distributions; using Generic; using Properties; using Storage; @@ -152,6 +153,19 @@ namespace MathNet.Numerics.LinearAlgebra.Complex matrix.Storage.CopyTo(Storage, skipClearing: true); } + /// + /// Create a new dense matrix with values sampled from the provided random distribution. + /// + public static DenseMatrix CreateRandom(int rows, int columns, IContinuousDistribution distribution) + { + var storage = new DenseColumnMajorMatrixStorage(rows, columns); + for (var i = 0; i < storage.Data.Length; i++) + { + storage.Data[i] = new Complex(distribution.Sample(), distribution.Sample()); + } + return new DenseMatrix(storage); + } + /// /// Gets the matrix's data. /// diff --git a/src/Numerics/LinearAlgebra/Complex/DenseVector.cs b/src/Numerics/LinearAlgebra/Complex/DenseVector.cs index 9562ced0..e3923458 100644 --- a/src/Numerics/LinearAlgebra/Complex/DenseVector.cs +++ b/src/Numerics/LinearAlgebra/Complex/DenseVector.cs @@ -30,6 +30,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex using System.Collections.Generic; using System.Linq; using System.Numerics; + using Distributions; using Generic; using NumberTheory; using Properties; @@ -119,6 +120,19 @@ namespace MathNet.Numerics.LinearAlgebra.Complex { } + /// + /// Create a new dense vector with values sampled from the provided random distribution. + /// + public static DenseVector CreateRandom(int size, IContinuousDistribution distribution) + { + var storage = new DenseVectorStorage(size); + for (var i = 0; i < storage.Data.Length; i++) + { + storage.Data[i] = new Complex(distribution.Sample(), distribution.Sample()); + } + return new DenseVector(storage); + } + /// /// Gets the vector's data. /// diff --git a/src/Numerics/LinearAlgebra/Complex/Matrix.cs b/src/Numerics/LinearAlgebra/Complex/Matrix.cs index 4a3aa454..077e374b 100644 --- a/src/Numerics/LinearAlgebra/Complex/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Complex/Matrix.cs @@ -28,7 +28,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex { using System; using System.Numerics; - using Distributions; using Generic; using Properties; using Storage; @@ -370,37 +369,5 @@ namespace MathNet.Numerics.LinearAlgebra.Complex return sum; } - - /// - /// Populates a matrix with random elements. - /// - /// The matrix to populate. - /// Continuous Random Distribution to generate elements from. - protected override void DoRandom(Matrix matrix, IContinuousDistribution distribution) - { - for (var i = 0; i < matrix.RowCount; i++) - { - for (var j = 0; j < matrix.ColumnCount; j++) - { - matrix.At(i, j, distribution.Sample()); - } - } - } - - /// - /// Populates a matrix with random elements. - /// - /// The matrix to populate. - /// Continuous Random Distribution to generate elements from. - protected override void DoRandom(Matrix matrix, IDiscreteDistribution distribution) - { - for (var i = 0; i < matrix.RowCount; i++) - { - for (var j = 0; j < matrix.ColumnCount; j++) - { - matrix.At(i, j, distribution.Sample()); - } - } - } } } diff --git a/src/Numerics/LinearAlgebra/Complex/Vector.cs b/src/Numerics/LinearAlgebra/Complex/Vector.cs index 6459df39..ac4b07c2 100644 --- a/src/Numerics/LinearAlgebra/Complex/Vector.cs +++ b/src/Numerics/LinearAlgebra/Complex/Vector.cs @@ -357,58 +357,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex return result; } - /// - /// Generates a vector with random elements - /// - /// Number of elements in the vector. - /// Continuous Random Distribution or Source - /// - /// A vector with n-random elements distributed according - /// to the specified random distribution. - /// - /// If the n vector is non-positive. - public override Vector Random(int length, IContinuousDistribution randomDistribution) - { - if (length < 1) - { - throw new ArgumentException(Resources.ArgumentMustBePositive, "length"); - } - - var vector = CreateVector(length); - for (var index = 0; index < length; index++) - { - vector.At(index, new Complex(randomDistribution.Sample(), randomDistribution.Sample())); - } - - return vector; - } - - /// - /// Generates a vector with random elements - /// - /// Number of elements in the vector. - /// Continuous Random Distribution or Source - /// - /// A vector with n-random elements distributed according - /// to the specified random distribution. - /// - /// If the n vector is not positive. - public override Vector Random(int length, IDiscreteDistribution randomDistribution) - { - if (length < 1) - { - throw new ArgumentException(Resources.ArgumentMustBePositive, "length"); - } - - var vector = CreateVector(length); - for (var index = 0; index < length; index++) - { - vector.At(index, new Complex(randomDistribution.Sample(), randomDistribution.Sample())); - } - - return vector; - } - /// /// Returns the index of the absolute maximum element. /// diff --git a/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs index 2e325ddf..b5cf03fe 100644 --- a/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs @@ -28,6 +28,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 { using System; using Algorithms.LinearAlgebra; + using Distributions; using Generic; using Numerics; using Properties; @@ -152,6 +153,19 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 matrix.Storage.CopyTo(Storage, skipClearing: true); } + /// + /// Create a new dense matrix with values sampled from the provided random distribution. + /// + public static DenseMatrix CreateRandom(int rows, int columns, IContinuousDistribution distribution) + { + var storage = new DenseColumnMajorMatrixStorage(rows, columns); + for (var i = 0; i < storage.Data.Length; i++) + { + storage.Data[i] = new Complex32((float)distribution.Sample(), (float)distribution.Sample()); + } + return new DenseMatrix(storage); + } + /// /// Gets the matrix's data. /// diff --git a/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs b/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs index 0886cc90..749ce364 100644 --- a/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs +++ b/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs @@ -120,6 +120,19 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 { } + /// + /// Create a new dense vector with values sampled from the provided random distribution. + /// + public static DenseVector CreateRandom(int size, IContinuousDistribution distribution) + { + var storage = new DenseVectorStorage(size); + for (var i = 0; i < storage.Data.Length; i++) + { + storage.Data[i] = new Complex32((float)distribution.Sample(), (float)distribution.Sample()); + } + return new DenseVector(storage); + } + /// /// Gets the vector's data. /// @@ -753,58 +766,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 return matrix; } - /// - /// Generates a vector with random elements - /// - /// Number of elements in the vector. - /// Continuous Random Distribution or Source - /// - /// A vector with n-random elements distributed according - /// to the specified random distribution. - /// - /// If the n vector is non positive. - public override Vector Random(int length, IContinuousDistribution randomDistribution) - { - if (length < 1) - { - throw new ArgumentException(Resources.ArgumentMustBePositive, "length"); - } - - var v = (DenseVector)CreateVector(length); - for (var index = 0; index < v._values.Length; index++) - { - v._values[index] = new Complex32((float)randomDistribution.Sample(), (float)randomDistribution.Sample()); - } - - return v; - } - - /// - /// Generates a vector with random elements - /// - /// Number of elements in the vector. - /// Continuous Random Distribution or Source - /// - /// A vector with n-random elements distributed according - /// to the specified random distribution. - /// - /// If the n vector is non positive. - public override Vector Random(int length, IDiscreteDistribution randomDistribution) - { - if (length < 1) - { - throw new ArgumentException(Resources.ArgumentMustBePositive, "length"); - } - - var v = (DenseVector)CreateVector(length); - for (var index = 0; index < v._values.Length; index++) - { - v._values[index] = new Complex32(randomDistribution.Sample(), randomDistribution.Sample()); - } - - return v; - } - /// /// Outer product of this and another vector. /// diff --git a/src/Numerics/LinearAlgebra/Complex32/Matrix.cs b/src/Numerics/LinearAlgebra/Complex32/Matrix.cs index e3d9ce41..8adaf587 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Matrix.cs @@ -27,7 +27,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 { using System; - using Distributions; using Generic; using Numerics; using Properties; @@ -364,37 +363,5 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 return sum; } - - /// - /// Populates a matrix with random elements. - /// - /// The matrix to populate. - /// Continuous Random Distribution to generate elements from. - protected override void DoRandom(Matrix matrix, IContinuousDistribution distribution) - { - for (var i = 0; i < matrix.RowCount; i++) - { - for (var j = 0; j < matrix.ColumnCount; j++) - { - matrix.At(i, j, Convert.ToSingle(distribution.Sample())); - } - } - } - - /// - /// Populates a matrix with random elements. - /// - /// The matrix to populate. - /// Continuous Random Distribution to generate elements from. - protected override void DoRandom(Matrix matrix, IDiscreteDistribution distribution) - { - for (var i = 0; i < matrix.RowCount; i++) - { - for (var j = 0; j < matrix.ColumnCount; j++) - { - matrix.At(i, j, distribution.Sample()); - } - } - } } } diff --git a/src/Numerics/LinearAlgebra/Complex32/Vector.cs b/src/Numerics/LinearAlgebra/Complex32/Vector.cs index 3beb431e..64133ede 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Vector.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Vector.cs @@ -402,57 +402,5 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 return clone; } - - /// - /// Generates a vector with random elements - /// - /// Number of elements in the vector. - /// Continuous Random Distribution or Source - /// - /// A vector with n-random elements distributed according - /// to the specified random distribution. - /// - /// If the n vector is non-positive. - public override Vector Random(int length, IContinuousDistribution randomDistribution) - { - if (length < 1) - { - throw new ArgumentException(Resources.ArgumentMustBePositive, "length"); - } - - var vector = CreateVector(length); - for (var index = 0; index < length; index++) - { - vector.At(index, new Complex32(Convert.ToSingle(randomDistribution.Sample()), Convert.ToSingle(randomDistribution.Sample()))); - } - - return vector; - } - - /// - /// Generates a vector with random elements - /// - /// Number of elements in the vector. - /// Continuous Random Distribution or Source - /// - /// A vector with n-random elements distributed according - /// to the specified random distribution. - /// - /// If the n vector is not positive. - public override Vector Random(int length, IDiscreteDistribution randomDistribution) - { - if (length < 1) - { - throw new ArgumentException(Resources.ArgumentMustBePositive, "length"); - } - - var vector = CreateVector(length); - for (var index = 0; index < length; index++) - { - vector.At(index, new Complex32(Convert.ToSingle(randomDistribution.Sample()), Convert.ToSingle(randomDistribution.Sample()))); - } - - return vector; - } } } diff --git a/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs index 752dd089..e8126208 100644 --- a/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs @@ -28,6 +28,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double { using System; using Algorithms.LinearAlgebra; + using Distributions; using Generic; using Properties; using Storage; @@ -152,6 +153,19 @@ namespace MathNet.Numerics.LinearAlgebra.Double matrix.Storage.CopyTo(Storage, skipClearing: true); } + /// + /// Create a new dense matrix with values sampled from the provided random distribution. + /// + public static DenseMatrix CreateRandom(int rows, int columns, IContinuousDistribution distribution) + { + var storage = new DenseColumnMajorMatrixStorage(rows, columns); + for (var i = 0; i < storage.Data.Length; i++) + { + storage.Data[i] = distribution.Sample(); + } + return new DenseMatrix(storage); + } + /// /// Gets the matrix's data. /// diff --git a/src/Numerics/LinearAlgebra/Double/DenseVector.cs b/src/Numerics/LinearAlgebra/Double/DenseVector.cs index 5aded844..c27ec628 100644 --- a/src/Numerics/LinearAlgebra/Double/DenseVector.cs +++ b/src/Numerics/LinearAlgebra/Double/DenseVector.cs @@ -30,6 +30,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double using System.Collections.Generic; using System.Globalization; using System.Linq; + using Distributions; using Generic; using NumberTheory; using Properties; @@ -119,6 +120,19 @@ namespace MathNet.Numerics.LinearAlgebra.Double { } + /// + /// Create a new dense vector with values sampled from the provided random distribution. + /// + public static DenseVector CreateRandom(int size, IContinuousDistribution distribution) + { + var storage = new DenseVectorStorage(size); + for (var i = 0; i < storage.Data.Length; i++) + { + storage.Data[i] = distribution.Sample(); + } + return new DenseVector(storage); + } + /// /// Gets the vector's data. /// diff --git a/src/Numerics/LinearAlgebra/Double/Matrix.cs b/src/Numerics/LinearAlgebra/Double/Matrix.cs index 4e072807..7363e26d 100644 --- a/src/Numerics/LinearAlgebra/Double/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Double/Matrix.cs @@ -24,14 +24,12 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using MathNet.Numerics.LinearAlgebra.Storage; - namespace MathNet.Numerics.LinearAlgebra.Double { using System; - using Distributions; using Generic; using Properties; + using Storage; /// /// double version of the class. @@ -361,37 +359,5 @@ namespace MathNet.Numerics.LinearAlgebra.Double return sum; } - - /// - /// Populates a matrix with random elements. - /// - /// The matrix to populate. - /// Continuous Random Distribution to generate elements from. - protected override void DoRandom(Matrix matrix, IContinuousDistribution distribution) - { - for (var i = 0; i < matrix.RowCount; i++) - { - for (var j = 0; j < matrix.ColumnCount; j++) - { - matrix.At(i, j, distribution.Sample()); - } - } - } - - /// - /// Populates a matrix with random elements. - /// - /// The matrix to populate. - /// Continuous Random Distribution to generate elements from. - protected override void DoRandom(Matrix matrix, IDiscreteDistribution distribution) - { - for (var i = 0; i < matrix.RowCount; i++) - { - for (var j = 0; j < matrix.ColumnCount; j++) - { - matrix.At(i, j, distribution.Sample()); - } - } - } } } diff --git a/src/Numerics/LinearAlgebra/Double/Vector.cs b/src/Numerics/LinearAlgebra/Double/Vector.cs index b873887e..fe04fa58 100644 --- a/src/Numerics/LinearAlgebra/Double/Vector.cs +++ b/src/Numerics/LinearAlgebra/Double/Vector.cs @@ -430,57 +430,5 @@ namespace MathNet.Numerics.LinearAlgebra.Double return clone; } - - /// - /// Generates a vector with random elements - /// - /// Number of elements in the vector. - /// Continuous Random Distribution or Source - /// - /// A vector with n-random elements distributed according - /// to the specified random distribution. - /// - /// If the n vector is non positive. - public override Vector Random(int length, IContinuousDistribution randomDistribution) - { - if (length < 1) - { - throw new ArgumentException(Resources.ArgumentMustBePositive, "length"); - } - - var v = CreateVector(length); - for (var index = 0; index < Count; index++) - { - v.At(index, randomDistribution.Sample()); - } - - return v; - } - - /// - /// Generates a vector with random elements - /// - /// Number of elements in the vector. - /// Continuous Random Distribution or Source - /// - /// A vector with n-random elements distributed according - /// to the specified random distribution. - /// - /// If the n vector is non positive. - public override Vector Random(int length, IDiscreteDistribution randomDistribution) - { - if (length < 1) - { - throw new ArgumentException(Resources.ArgumentMustBePositive, "length"); - } - - var v = CreateVector(length); - for (var index = 0; index < Count; index++) - { - At(index, randomDistribution.Sample()); - } - - return v; - } } } diff --git a/src/Numerics/LinearAlgebra/Generic/Matrix.Arithmetic.cs b/src/Numerics/LinearAlgebra/Generic/Matrix.Arithmetic.cs index 58180ebc..62593b3f 100644 --- a/src/Numerics/LinearAlgebra/Generic/Matrix.Arithmetic.cs +++ b/src/Numerics/LinearAlgebra/Generic/Matrix.Arithmetic.cs @@ -1102,76 +1102,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic return leftSide.Modulus(rightSide); } - /// - /// Generates a matrix with random elements. - /// - /// Number of rows. - /// Number of columns. - /// Continuous Random Distribution to generate elements from. - /// - /// An numberOfRows-by-numberOfColumns matrix with elements distributed according to the provided distribution. - /// - /// If the parameter is not positive. - /// If the parameter is not positive. - public virtual Matrix Random(int numberOfRows, int numberOfColumns, IContinuousDistribution distribution) - { - if (numberOfRows < 1) - { - throw new ArgumentException(Resources.ArgumentMustBePositive, "numberOfRows"); - } - - if (numberOfColumns < 1) - { - throw new ArgumentException(Resources.ArgumentMustBePositive, "numberOfColumns"); - } - - var matrix = CreateMatrix(numberOfRows, numberOfColumns); - DoRandom(matrix, distribution); - return matrix; - } - - /// - /// Populates a matrix with random elements. - /// - /// The matrix to populate. - /// Continuous Random Distribution to generate elements from. - protected abstract void DoRandom(Matrix matrix, IContinuousDistribution distribution); - - /// - /// Generates a matrix with random elements. - /// - /// Number of rows. - /// Number of columns. - /// Continuous Random Distribution or Source - /// - /// An numberOfRows-by-numberOfColumns matrix with elements distributed according to the provided distribution. - /// - /// If the parameter is not positive. - /// If the parameter is not positive. - public virtual Matrix Random(int numberOfRows, int numberOfColumns, IDiscreteDistribution distribution) - { - if (numberOfRows < 1) - { - throw new ArgumentException(Resources.ArgumentMustBePositive, "numberOfRows"); - } - - if (numberOfColumns < 1) - { - throw new ArgumentException(Resources.ArgumentMustBePositive, "numberOfColumns"); - } - - var matrix = CreateMatrix(numberOfRows, numberOfColumns); - DoRandom(matrix, distribution); - return matrix; - } - - /// - /// Populates a matrix with random elements. - /// - /// The matrix to populate. - /// Continuous Random Distribution to generate elements from. - protected abstract void DoRandom(Matrix matrix, IDiscreteDistribution distribution); - /// /// Computes the trace of this matrix. /// diff --git a/src/Numerics/LinearAlgebra/Generic/Vector.cs b/src/Numerics/LinearAlgebra/Generic/Vector.cs index 370793c6..a0296eb3 100644 --- a/src/Numerics/LinearAlgebra/Generic/Vector.cs +++ b/src/Numerics/LinearAlgebra/Generic/Vector.cs @@ -862,30 +862,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic return matrix; } - /// - /// Generates a vector with random elements - /// - /// Number of elements in the vector. - /// Continuous Random Distribution or Source - /// - /// A vector with n-random elements distributed according - /// to the specified random distribution. - /// - /// If the n vector is non-positive. - public abstract Vector Random(int length, IContinuousDistribution randomDistribution); - - /// - /// Generates a vector with random elements - /// - /// Number of elements in the vector. - /// Continuous Random Distribution or Source - /// - /// A vector with n-random elements distributed according - /// to the specified random distribution. - /// - /// If the n vector is not positive. - public abstract Vector Random(int length, IDiscreteDistribution randomDistribution); - /// /// Outer product of this and another vector. /// diff --git a/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs index 0ecc0917..cde0f437 100644 --- a/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs @@ -28,6 +28,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single { using System; using Algorithms.LinearAlgebra; + using Distributions; using Generic; using Properties; using Storage; @@ -152,6 +153,19 @@ namespace MathNet.Numerics.LinearAlgebra.Single matrix.Storage.CopyTo(Storage, skipClearing: true); } + /// + /// Create a new dense matrix with values sampled from the provided random distribution. + /// + public static DenseMatrix CreateRandom(int rows, int columns, IContinuousDistribution distribution) + { + var storage = new DenseColumnMajorMatrixStorage(rows, columns); + for (var i = 0; i < storage.Data.Length; i++) + { + storage.Data[i] = (float)distribution.Sample(); + } + return new DenseMatrix(storage); + } + /// /// Gets the matrix's data. /// diff --git a/src/Numerics/LinearAlgebra/Single/DenseVector.cs b/src/Numerics/LinearAlgebra/Single/DenseVector.cs index ac1bd409..91ab2584 100644 --- a/src/Numerics/LinearAlgebra/Single/DenseVector.cs +++ b/src/Numerics/LinearAlgebra/Single/DenseVector.cs @@ -30,6 +30,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single using System.Collections.Generic; using System.Globalization; using System.Linq; + using Distributions; using Generic; using NumberTheory; using Properties; @@ -119,6 +120,19 @@ namespace MathNet.Numerics.LinearAlgebra.Single { } + /// + /// Create a new dense vector with values sampled from the provided random distribution. + /// + public static DenseVector CreateRandom(int size, IContinuousDistribution distribution) + { + var storage = new DenseVectorStorage(size); + for (var i = 0; i < storage.Data.Length; i++) + { + storage.Data[i] = (float)distribution.Sample(); + } + return new DenseVector(storage); + } + /// /// Gets the vector's data. /// diff --git a/src/Numerics/LinearAlgebra/Single/Matrix.cs b/src/Numerics/LinearAlgebra/Single/Matrix.cs index 608ec3c2..c4c67f92 100644 --- a/src/Numerics/LinearAlgebra/Single/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Single/Matrix.cs @@ -27,7 +27,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single { using System; - using Distributions; using Generic; using Properties; using Storage; @@ -360,37 +359,5 @@ namespace MathNet.Numerics.LinearAlgebra.Single return sum; } - - /// - /// Populates a matrix with random elements. - /// - /// The matrix to populate. - /// Continuous Random Distribution to generate elements from. - protected override void DoRandom(Matrix matrix, IContinuousDistribution distribution) - { - for (var i = 0; i < matrix.RowCount; i++) - { - for (var j = 0; j < matrix.ColumnCount; j++) - { - matrix.At(i, j, Convert.ToSingle(distribution.Sample())); - } - } - } - - /// - /// Populates a matrix with random elements. - /// - /// The matrix to populate. - /// Continuous Random Distribution to generate elements from. - protected override void DoRandom(Matrix matrix, IDiscreteDistribution distribution) - { - for (var i = 0; i < matrix.RowCount; i++) - { - for (var j = 0; j < matrix.ColumnCount; j++) - { - matrix.At(i, j, distribution.Sample()); - } - } - } } } diff --git a/src/Numerics/LinearAlgebra/Single/Vector.cs b/src/Numerics/LinearAlgebra/Single/Vector.cs index 8cc9e8e7..3e5c4473 100644 --- a/src/Numerics/LinearAlgebra/Single/Vector.cs +++ b/src/Numerics/LinearAlgebra/Single/Vector.cs @@ -430,57 +430,5 @@ namespace MathNet.Numerics.LinearAlgebra.Single return clone; } - - /// - /// Generates a vector with random elements - /// - /// Number of elements in the vector. - /// Continuous Random Distribution or Source - /// - /// A vector with n-random elements distributed according - /// to the specified random distribution. - /// - /// If the n vector is non positive. - public override Vector Random(int length, IContinuousDistribution randomDistribution) - { - if (length < 1) - { - throw new ArgumentException(Resources.ArgumentMustBePositive, "length"); - } - - var v = CreateVector(length); - for (var index = 0; index < Count; index++) - { - v.At(index, Convert.ToSingle(randomDistribution.Sample())); - } - - return v; - } - - /// - /// Generates a vector with random elements - /// - /// Number of elements in the vector. - /// Continuous Random Distribution or Source - /// - /// A vector with n-random elements distributed according - /// to the specified random distribution. - /// - /// If the n vector is non positive. - public override Vector Random(int length, IDiscreteDistribution randomDistribution) - { - if (length < 1) - { - throw new ArgumentException(Resources.ArgumentMustBePositive, "length"); - } - - var v = CreateVector(length); - for (var index = 0; index < Count; index++) - { - v.At(index, Convert.ToSingle(randomDistribution.Sample())); - } - - return v; - } } } diff --git a/src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.Arithmetic.cs b/src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.Arithmetic.cs index 93bb191d..f7aefa6e 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.Arithmetic.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.Arithmetic.cs @@ -1212,9 +1212,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex [TestCase(-2)] public void RandomWithNonPositiveNumberOfRowsThrowsArgumentException(int numberOfRows) { - var matrix = CreateMatrix(2, 3); - Assert.Throws(() => matrix.Random(numberOfRows, 4, new ContinuousUniform())); - Assert.Throws(() => matrix.Random(numberOfRows, 4, new DiscreteUniform(0, 2))); + Assert.Throws(() => DenseMatrix.CreateRandom(numberOfRows, 4, new ContinuousUniform())); } /// diff --git a/src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs index b5c962a6..d1720ab5 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs @@ -33,6 +33,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex using System.Linq; using System.Numerics; using Distributions; + using LinearAlgebra.Complex; using LinearAlgebra.Generic; using NUnit.Framework; @@ -475,8 +476,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex [Test] public void RandomWithNumberOfElementsLessThanZeroThrowsArgumentException() { - var vector = CreateVector(4); - Assert.Throws(() => vector.Random(-2, new ContinuousUniform())); + Assert.Throws(() => DenseVector.CreateRandom(-2, new ContinuousUniform())); } /// diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/MatrixTests.Arithmetic.cs b/src/UnitTests/LinearAlgebraTests/Complex32/MatrixTests.Arithmetic.cs index 821b5e42..cfc83158 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/MatrixTests.Arithmetic.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/MatrixTests.Arithmetic.cs @@ -1212,9 +1212,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 [TestCase(-2)] public void RandomWithNonPositiveNumberOfRowsThrowsArgumentException(int numberOfRows) { - var matrix = CreateMatrix(2, 3); - Assert.Throws(() => matrix.Random(numberOfRows, 4, new ContinuousUniform())); - Assert.Throws(() => matrix.Random(numberOfRows, 4, new DiscreteUniform(0, 2))); + Assert.Throws(() => DenseMatrix.CreateRandom(numberOfRows, 4, new ContinuousUniform())); } /// diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs index 46f6fb57..ac0b98f4 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs @@ -32,6 +32,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 using System.Globalization; using System.Linq; using Distributions; + using LinearAlgebra.Complex32; using LinearAlgebra.Generic; using NUnit.Framework; using Complex32 = Numerics.Complex32; @@ -475,8 +476,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 [Test] public void RandomWithNumberOfElementsLessThanZeroThrowsArgumentException() { - var vector = CreateVector(4); - Assert.Throws(() => vector.Random(-2, new ContinuousUniform())); + Assert.Throws(() => DenseVector.CreateRandom(-2, new ContinuousUniform())); } /// diff --git a/src/UnitTests/LinearAlgebraTests/Double/MatrixTests.Arithmetic.cs b/src/UnitTests/LinearAlgebraTests/Double/MatrixTests.Arithmetic.cs index a2bedd61..b4354ebe 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/MatrixTests.Arithmetic.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/MatrixTests.Arithmetic.cs @@ -1207,9 +1207,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double [TestCase(-2)] public void RandomWithNonPositiveNumberOfRowsThrowsArgumentException(int numberOfRows) { - var matrix = CreateMatrix(2, 3); - Assert.Throws(() => matrix.Random(numberOfRows, 4, new ContinuousUniform())); - Assert.Throws(() => matrix.Random(numberOfRows, 4, new DiscreteUniform(0, 2))); + Assert.Throws(() => DenseMatrix.CreateRandom(numberOfRows, 4, new ContinuousUniform())); } /// diff --git a/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs index 3c128ea3..0c718a5a 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs @@ -31,6 +31,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double using System.Collections.Generic; using System.Globalization; using Distributions; + using LinearAlgebra.Double; using LinearAlgebra.Generic; using NUnit.Framework; @@ -489,8 +490,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double [Test] public void RandomWithNumberOfElementsLessThanZeroThrowsArgumentException() { - var vector = CreateVector(4); - Assert.Throws(() => vector.Random(-2, new ContinuousUniform())); + Assert.Throws(() => DenseVector.CreateRandom(-2, new ContinuousUniform())); } /// diff --git a/src/UnitTests/LinearAlgebraTests/Single/MatrixTests.Arithmetic.cs b/src/UnitTests/LinearAlgebraTests/Single/MatrixTests.Arithmetic.cs index 1d1162e6..bf4f08bc 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/MatrixTests.Arithmetic.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/MatrixTests.Arithmetic.cs @@ -1201,9 +1201,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single [TestCase(-2)] public void RandomWithNonPositiveNumberOfRowsThrowsArgumentException(int numberOfRows) { - var matrix = CreateMatrix(2, 3); - Assert.Throws(() => matrix.Random(numberOfRows, 4, new ContinuousUniform())); - Assert.Throws(() => matrix.Random(numberOfRows, 4, new DiscreteUniform(0, 2))); + Assert.Throws(() => DenseMatrix.CreateRandom(numberOfRows, 4, new ContinuousUniform())); } /// diff --git a/src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs index a84ef969..80be2d66 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs @@ -32,6 +32,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single using System.Globalization; using Distributions; using LinearAlgebra.Generic; + using LinearAlgebra.Single; using NUnit.Framework; /// @@ -489,8 +490,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single [Test] public void RandomWithNumberOfElementsLessThanZeroThrowsArgumentException() { - var vector = CreateVector(4); - Assert.Throws(() => vector.Random(-2, new ContinuousUniform())); + Assert.Throws(() => DenseVector.CreateRandom(-2, new ContinuousUniform())); } ///