diff --git a/src/Numerics/Distributions/Multivariate/MatrixNormal.cs b/src/Numerics/Distributions/Multivariate/MatrixNormal.cs index 638fc761..b2fa27c8 100644 --- a/src/Numerics/Distributions/Multivariate/MatrixNormal.cs +++ b/src/Numerics/Distributions/Multivariate/MatrixNormal.cs @@ -238,7 +238,7 @@ namespace MathNet.Numerics.Distributions { if (x.RowCount != _m.RowCount || x.ColumnCount != _m.ColumnCount) { - throw new ArgumentOutOfRangeException("x", Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(x, _m, "x"); } var a = x - _m; diff --git a/src/Numerics/Distributions/Multivariate/Wishart.cs b/src/Numerics/Distributions/Multivariate/Wishart.cs index 4480cde3..c16afd0c 100644 --- a/src/Numerics/Distributions/Multivariate/Wishart.cs +++ b/src/Numerics/Distributions/Multivariate/Wishart.cs @@ -247,7 +247,7 @@ namespace MathNet.Numerics.Distributions if (x.RowCount != p || x.ColumnCount != p) { - throw new ArgumentOutOfRangeException("x", Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(x, _s, "x"); } var dX = x.Determinant(); diff --git a/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs index f88f614a..2311f42b 100644 --- a/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs @@ -666,7 +666,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (leftSide.RowCount != rightSide.RowCount || leftSide.ColumnCount != rightSide.ColumnCount) { - throw new ArgumentOutOfRangeException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return (DenseMatrix)leftSide.Add(rightSide); @@ -713,7 +713,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (leftSide.RowCount != rightSide.RowCount || leftSide.ColumnCount != rightSide.ColumnCount) { - throw new ArgumentOutOfRangeException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return (DenseMatrix)leftSide.Subtract(rightSide); @@ -794,7 +794,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (leftSide.ColumnCount != rightSide.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return (DenseMatrix)leftSide.Multiply(rightSide); diff --git a/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs index e9373592..51172498 100644 --- a/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs +++ b/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs @@ -296,7 +296,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (other.RowCount != RowCount || other.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("other", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, "other"); } Matrix result; @@ -334,12 +334,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (other.RowCount != RowCount || other.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("other", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, "other"); } if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("result", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, result, "result"); } var diagOther = other as DiagonalMatrix; @@ -371,7 +371,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (other.RowCount != RowCount || other.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("other", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, "other"); } Matrix result; @@ -409,12 +409,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (other.RowCount != RowCount || other.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("other", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, "other"); } if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("result", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, "other"); } var diagOther = other as DiagonalMatrix; @@ -542,12 +542,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (ColumnCount != other.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other); } if (result.RowCount != RowCount || result.ColumnCount != other.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, result); } var m = other as DiagonalMatrix; @@ -584,7 +584,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (ColumnCount != other.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other); } var m = other as DiagonalMatrix; @@ -616,7 +616,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (ColumnCount != rightSide.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "rightSide"); + throw DimensionsDontMatch(this, rightSide, "rightSide"); } if (result == null) @@ -626,7 +626,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (RowCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(rightSide, result)) @@ -666,7 +666,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (RowCount != leftSide.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "leftSide"); + throw DimensionsDontMatch(this, leftSide, "leftSide"); } if (result == null) @@ -676,7 +676,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(leftSide, result)) @@ -765,7 +765,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (ColumnCount != otherDiagonal.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, otherDiagonal); } var result = (DiagonalMatrix)CreateMatrix(RowCount, other.RowCount); @@ -804,7 +804,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (RowCount != target.RowCount || ColumnCount != target.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "target"); + throw DimensionsDontMatch(this, target); } Array.Copy(Data, diagonalTarget.Data, Data.Length); @@ -1028,7 +1028,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(this, result)) @@ -1068,7 +1068,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } result.Clear(); @@ -1098,7 +1098,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } result.Clear(); @@ -1133,7 +1133,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } result.Clear(); @@ -1368,7 +1368,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (result.RowCount != (RowCount + lower.RowCount) || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } // Clear the result matrix @@ -1500,7 +1500,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (result.RowCount != RowCount + lower.RowCount || result.ColumnCount != ColumnCount + lower.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } // Clear the result matrix diff --git a/src/Numerics/LinearAlgebra/Complex/Factorization/DenseCholesky.cs b/src/Numerics/LinearAlgebra/Complex/Factorization/DenseCholesky.cs index 13d71b61..fdf78d58 100644 --- a/src/Numerics/LinearAlgebra/Complex/Factorization/DenseCholesky.cs +++ b/src/Numerics/LinearAlgebra/Complex/Factorization/DenseCholesky.cs @@ -104,7 +104,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization if (input.RowCount != CholeskyFactor.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, CholeskyFactor); } var dinput = input as DenseMatrix; @@ -153,7 +153,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization if (input.Count != CholeskyFactor.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, CholeskyFactor); } var dinput = input as DenseVector; diff --git a/src/Numerics/LinearAlgebra/Complex/Factorization/DenseEvd.cs b/src/Numerics/LinearAlgebra/Complex/Factorization/DenseEvd.cs index 188a8d45..6eb340f7 100644 --- a/src/Numerics/LinearAlgebra/Complex/Factorization/DenseEvd.cs +++ b/src/Numerics/LinearAlgebra/Complex/Factorization/DenseEvd.cs @@ -906,7 +906,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization // Check that x is a column vector with n entries if (VectorEv.Count != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(VectorEv, result); } if (IsSymmetric) diff --git a/src/Numerics/LinearAlgebra/Complex/Factorization/DenseGramSchmidt.cs b/src/Numerics/LinearAlgebra/Complex/Factorization/DenseGramSchmidt.cs index bab4bd16..eebf5f39 100644 --- a/src/Numerics/LinearAlgebra/Complex/Factorization/DenseGramSchmidt.cs +++ b/src/Numerics/LinearAlgebra/Complex/Factorization/DenseGramSchmidt.cs @@ -66,7 +66,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization if (matrix.RowCount < matrix.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix); } MatrixQ = matrix.Clone(); @@ -202,7 +202,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization // Check that x is a column vector with n entries if (MatrixQ.ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(MatrixQ, result); } var dinput = input as DenseVector; diff --git a/src/Numerics/LinearAlgebra/Complex/Factorization/DenseLU.cs b/src/Numerics/LinearAlgebra/Complex/Factorization/DenseLU.cs index fad99084..501649a0 100644 --- a/src/Numerics/LinearAlgebra/Complex/Factorization/DenseLU.cs +++ b/src/Numerics/LinearAlgebra/Complex/Factorization/DenseLU.cs @@ -106,7 +106,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization if (input.RowCount != Factors.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, Factors); } var dinput = input as DenseMatrix; @@ -155,7 +155,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization if (input.Count != Factors.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, Factors); } var dinput = input as DenseVector; diff --git a/src/Numerics/LinearAlgebra/Complex/Factorization/DenseQR.cs b/src/Numerics/LinearAlgebra/Complex/Factorization/DenseQR.cs index ab386b87..8cd0e2e4 100644 --- a/src/Numerics/LinearAlgebra/Complex/Factorization/DenseQR.cs +++ b/src/Numerics/LinearAlgebra/Complex/Factorization/DenseQR.cs @@ -71,7 +71,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization if (matrix.RowCount < matrix.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix); } MatrixR = matrix.Clone(); @@ -158,7 +158,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization // Check that x is a column vector with n entries if (MatrixR.ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(MatrixR, result); } var dinput = input as DenseVector; diff --git a/src/Numerics/LinearAlgebra/Complex/Factorization/DenseSvd.cs b/src/Numerics/LinearAlgebra/Complex/Factorization/DenseSvd.cs index 783df203..6571eb6c 100644 --- a/src/Numerics/LinearAlgebra/Complex/Factorization/DenseSvd.cs +++ b/src/Numerics/LinearAlgebra/Complex/Factorization/DenseSvd.cs @@ -161,7 +161,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization // Check that x is a column vector with n entries if (MatrixVT.ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(MatrixVT, result); } var dinput = input as DenseVector; diff --git a/src/Numerics/LinearAlgebra/Complex/Factorization/UserCholesky.cs b/src/Numerics/LinearAlgebra/Complex/Factorization/UserCholesky.cs index ef82e2f0..9d63eff4 100644 --- a/src/Numerics/LinearAlgebra/Complex/Factorization/UserCholesky.cs +++ b/src/Numerics/LinearAlgebra/Complex/Factorization/UserCholesky.cs @@ -171,7 +171,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization if (input.RowCount != CholeskyFactor.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, CholeskyFactor); } input.CopyTo(result); @@ -232,7 +232,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization if (input.Count != CholeskyFactor.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, CholeskyFactor); } input.CopyTo(result); diff --git a/src/Numerics/LinearAlgebra/Complex/Factorization/UserEvd.cs b/src/Numerics/LinearAlgebra/Complex/Factorization/UserEvd.cs index 3d73f2e1..82b91585 100644 --- a/src/Numerics/LinearAlgebra/Complex/Factorization/UserEvd.cs +++ b/src/Numerics/LinearAlgebra/Complex/Factorization/UserEvd.cs @@ -901,7 +901,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization // Check that x is a column vector with n entries if (VectorEv.Count != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(VectorEv, result); } if (IsSymmetric) diff --git a/src/Numerics/LinearAlgebra/Complex/Factorization/UserGramSchmidt.cs b/src/Numerics/LinearAlgebra/Complex/Factorization/UserGramSchmidt.cs index ea8bb7c6..537d2a3d 100644 --- a/src/Numerics/LinearAlgebra/Complex/Factorization/UserGramSchmidt.cs +++ b/src/Numerics/LinearAlgebra/Complex/Factorization/UserGramSchmidt.cs @@ -61,7 +61,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization if (matrix.RowCount < matrix.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix); } MatrixQ = matrix.Clone(); @@ -211,7 +211,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization // Check that x is a column vector with n entries if (MatrixQ.ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(MatrixQ, result); } var inputCopy = input.Clone(); diff --git a/src/Numerics/LinearAlgebra/Complex/Factorization/UserLU.cs b/src/Numerics/LinearAlgebra/Complex/Factorization/UserLU.cs index 17118574..65060cb7 100644 --- a/src/Numerics/LinearAlgebra/Complex/Factorization/UserLU.cs +++ b/src/Numerics/LinearAlgebra/Complex/Factorization/UserLU.cs @@ -162,7 +162,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization if (input.RowCount != Factors.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, Factors); } // Copy the contents of input to result. @@ -243,7 +243,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization if (input.Count != Factors.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, Factors); } // Copy the contents of input to result. diff --git a/src/Numerics/LinearAlgebra/Complex/Factorization/UserQR.cs b/src/Numerics/LinearAlgebra/Complex/Factorization/UserQR.cs index 68db066d..9051fa9f 100644 --- a/src/Numerics/LinearAlgebra/Complex/Factorization/UserQR.cs +++ b/src/Numerics/LinearAlgebra/Complex/Factorization/UserQR.cs @@ -63,7 +63,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization if (matrix.RowCount < matrix.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix); } MatrixR = matrix.Clone(); @@ -297,7 +297,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization // Check that x is a column vector with n entries if (MatrixR.ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(MatrixR, result); } var inputCopy = input.Clone(); diff --git a/src/Numerics/LinearAlgebra/Complex/Factorization/UserSvd.cs b/src/Numerics/LinearAlgebra/Complex/Factorization/UserSvd.cs index 49556ca9..eeb8c96d 100644 --- a/src/Numerics/LinearAlgebra/Complex/Factorization/UserSvd.cs +++ b/src/Numerics/LinearAlgebra/Complex/Factorization/UserSvd.cs @@ -903,7 +903,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization // Check that x is a column vector with n entries if (MatrixVT.ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(MatrixVT, result); } var mn = Math.Min(MatrixU.RowCount, MatrixVT.ColumnCount); diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/BiCgStab.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/BiCgStab.cs index b39dd009..85297fd7 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/BiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/BiCgStab.cs @@ -260,7 +260,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative if (input.Count != matrix.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, result); } // Initialize the solver fields @@ -520,7 +520,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix, input, result); } for (var column = 0; column < input.ColumnCount; column++) diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/CompositeSolver.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/CompositeSolver.cs index 9f6cb109..6b5da13b 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/CompositeSolver.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/CompositeSolver.cs @@ -616,7 +616,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix, input, result); } for (var column = 0; column < input.ColumnCount; column++) diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/GpBiCg.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/GpBiCg.cs index e72ca2de..a0432dbc 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/GpBiCg.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/GpBiCg.cs @@ -307,14 +307,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative throw new ArgumentNullException("result"); } - if (result.Count != input.Count) + if (input.Count != matrix.RowCount || result.Count != input.Count) { - throw new ArgumentException(Resources.ArgumentVectorsSameLength); - } - - if (input.Count != matrix.RowCount) - { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix, input, result); } // Initialize the solver fields @@ -630,7 +625,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix, input, result); } for (var column = 0; column < input.ColumnCount; column++) diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/MlkBiCgStab.cs index 022ac9d4..544529fd 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/MlkBiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/MlkBiCgStab.cs @@ -329,14 +329,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative throw new ArgumentNullException("result"); } - if (result.Count != input.Count) + if (input.Count != matrix.RowCount || result.Count != input.Count) { - throw new ArgumentException(Resources.ArgumentVectorsSameLength); - } - - if (input.Count != matrix.RowCount) - { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix, input, result); } // Initialize the solver fields @@ -797,7 +792,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix, input, result); } for (var column = 0; column < input.ColumnCount; column++) diff --git a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/TFQMR.cs b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/TFQMR.cs index a6115316..43c5d407 100644 --- a/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/TFQMR.cs +++ b/src/Numerics/LinearAlgebra/Complex/Solvers/Iterative/TFQMR.cs @@ -240,14 +240,9 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative throw new ArgumentNullException("result"); } - if (result.Count != input.Count) + if (input.Count != matrix.RowCount || result.Count != input.Count) { - throw new ArgumentException(Resources.ArgumentVectorsSameLength); - } - - if (input.Count != matrix.RowCount) - { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix, input, result); } // Initialize the solver fields @@ -525,7 +520,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Solvers.Iterative if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix, input, result); } for (var column = 0; column < input.ColumnCount; column++) diff --git a/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs index fdab532d..a4203773 100644 --- a/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs @@ -275,7 +275,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result); } if (ReferenceEquals(this, result)) @@ -337,7 +337,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result); } if (ReferenceEquals(this, result)) @@ -471,7 +471,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result); } if (ReferenceEquals(this, result)) @@ -534,7 +534,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result); } if (ReferenceEquals(this, result)) @@ -817,7 +817,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (RowCount != target.RowCount || ColumnCount != target.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "target"); + throw DimensionsDontMatch(this, target, "target"); } // Lets copy only needed data. Portion of needed data is determined by NonZerosCount value @@ -1042,7 +1042,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex { if (resultSparseMatrix.RowCount != RowCount + lowerSparseMatrix.RowCount || resultSparseMatrix.ColumnCount != ColumnCount + lowerSparseMatrix.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, resultSparseMatrix, lowerSparseMatrix); } resultSparseMatrix.NonZerosCount = NonZerosCount + lowerSparseMatrix.NonZerosCount; @@ -1622,7 +1622,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (leftSide.RowCount != rightSide.RowCount || leftSide.ColumnCount != rightSide.ColumnCount) { - throw new ArgumentOutOfRangeException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return (SparseMatrix)leftSide.Add(rightSide); @@ -1669,7 +1669,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (leftSide.RowCount != rightSide.RowCount || leftSide.ColumnCount != rightSide.ColumnCount) { - throw new ArgumentOutOfRangeException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return (SparseMatrix)leftSide.Subtract(rightSide); @@ -1750,7 +1750,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex if (leftSide.ColumnCount != rightSide.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return (SparseMatrix)leftSide.Multiply(rightSide); diff --git a/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs index b2e16a64..4ee493cd 100644 --- a/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs @@ -666,7 +666,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (leftSide.RowCount != rightSide.RowCount || leftSide.ColumnCount != rightSide.ColumnCount) { - throw new ArgumentOutOfRangeException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return (DenseMatrix)leftSide.Add(rightSide); @@ -713,7 +713,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (leftSide.RowCount != rightSide.RowCount || leftSide.ColumnCount != rightSide.ColumnCount) { - throw new ArgumentOutOfRangeException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return (DenseMatrix)leftSide.Subtract(rightSide); @@ -794,7 +794,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (leftSide.ColumnCount != rightSide.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return (DenseMatrix)leftSide.Multiply(rightSide); diff --git a/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs index 9efc6f09..78fd384d 100644 --- a/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs +++ b/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs @@ -301,7 +301,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (other.RowCount != RowCount || other.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("other", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, "other"); } Matrix result; @@ -339,12 +339,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (other.RowCount != RowCount || other.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("other", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, "other"); } if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("result", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, "other"); } var diagOther = other as DiagonalMatrix; @@ -376,7 +376,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (other.RowCount != RowCount || other.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("other", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, "other"); } Matrix result; @@ -414,12 +414,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (other.RowCount != RowCount || other.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("other", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, "other"); } if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("result", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, "result"); } var diagOther = other as DiagonalMatrix; @@ -547,12 +547,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (ColumnCount != other.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other); } if (result.RowCount != RowCount || result.ColumnCount != other.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other); } var m = other as DiagonalMatrix; @@ -589,7 +589,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (ColumnCount != other.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other); } var m = other as DiagonalMatrix; @@ -621,7 +621,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (ColumnCount != rightSide.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "rightSide"); + throw DimensionsDontMatch(this, rightSide, "rightSide"); } if (result == null) @@ -631,7 +631,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (RowCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(rightSide, result)) @@ -671,7 +671,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (RowCount != leftSide.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "leftSide"); + throw DimensionsDontMatch(this, leftSide, "leftSide"); } if (result == null) @@ -681,7 +681,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(leftSide, result)) @@ -770,7 +770,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (ColumnCount != otherDiagonal.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, otherDiagonal); } var result = (DiagonalMatrix)CreateMatrix(RowCount, other.RowCount); @@ -809,7 +809,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (RowCount != target.RowCount || ColumnCount != target.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "target"); + throw DimensionsDontMatch(this, target, "target"); } Array.Copy(Data, diagonalTarget.Data, Data.Length); @@ -1033,7 +1033,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(this, result)) @@ -1073,7 +1073,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } result.Clear(); @@ -1103,7 +1103,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } result.Clear(); @@ -1138,7 +1138,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } result.Clear(); @@ -1373,7 +1373,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (result.RowCount != (RowCount + lower.RowCount) || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, lower, result); } // Clear the result matrix @@ -1505,7 +1505,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (result.RowCount != RowCount + lower.RowCount || result.ColumnCount != ColumnCount + lower.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, lower, result); } // Clear the result matrix diff --git a/src/Numerics/LinearAlgebra/Complex32/Factorization/DenseCholesky.cs b/src/Numerics/LinearAlgebra/Complex32/Factorization/DenseCholesky.cs index 14ce07ff..4365c98e 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Factorization/DenseCholesky.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Factorization/DenseCholesky.cs @@ -104,7 +104,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization if (input.RowCount != CholeskyFactor.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, CholeskyFactor); } var dinput = input as DenseMatrix; @@ -153,7 +153,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization if (input.Count != CholeskyFactor.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, CholeskyFactor); } var dinput = input as DenseVector; diff --git a/src/Numerics/LinearAlgebra/Complex32/Factorization/DenseGramSchmidt.cs b/src/Numerics/LinearAlgebra/Complex32/Factorization/DenseGramSchmidt.cs index 79a147b2..36919fc8 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Factorization/DenseGramSchmidt.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Factorization/DenseGramSchmidt.cs @@ -66,7 +66,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization if (matrix.RowCount < matrix.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix); } MatrixQ = matrix.Clone(); @@ -202,7 +202,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization // Check that x is a column vector with n entries if (MatrixQ.ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(MatrixQ, result); } var dinput = input as DenseVector; diff --git a/src/Numerics/LinearAlgebra/Complex32/Factorization/DenseLU.cs b/src/Numerics/LinearAlgebra/Complex32/Factorization/DenseLU.cs index ed68310f..336bfe23 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Factorization/DenseLU.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Factorization/DenseLU.cs @@ -106,7 +106,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization if (input.RowCount != Factors.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, Factors); } var dinput = input as DenseMatrix; @@ -155,7 +155,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization if (input.Count != Factors.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, Factors); } var dinput = input as DenseVector; diff --git a/src/Numerics/LinearAlgebra/Complex32/Factorization/DenseQR.cs b/src/Numerics/LinearAlgebra/Complex32/Factorization/DenseQR.cs index 0d5bfb00..5a54f50a 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Factorization/DenseQR.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Factorization/DenseQR.cs @@ -71,7 +71,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization if (matrix.RowCount < matrix.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix); } MatrixR = matrix.Clone(); @@ -158,7 +158,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization // Check that x is a column vector with n entries if (MatrixR.ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(MatrixR, result); } var dinput = input as DenseVector; diff --git a/src/Numerics/LinearAlgebra/Complex32/Factorization/DenseSvd.cs b/src/Numerics/LinearAlgebra/Complex32/Factorization/DenseSvd.cs index c7b5cb05..515a5f0a 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Factorization/DenseSvd.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Factorization/DenseSvd.cs @@ -161,7 +161,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization // Check that x is a column vector with n entries if (MatrixVT.ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(MatrixVT, result); } var dinput = input as DenseVector; diff --git a/src/Numerics/LinearAlgebra/Complex32/Factorization/UserCholesky.cs b/src/Numerics/LinearAlgebra/Complex32/Factorization/UserCholesky.cs index c3866922..418c3cdc 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Factorization/UserCholesky.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Factorization/UserCholesky.cs @@ -171,7 +171,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization if (input.RowCount != CholeskyFactor.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, CholeskyFactor); } input.CopyTo(result); @@ -232,7 +232,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization if (input.Count != CholeskyFactor.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, CholeskyFactor); } input.CopyTo(result); diff --git a/src/Numerics/LinearAlgebra/Complex32/Factorization/UserGramSchmidt.cs b/src/Numerics/LinearAlgebra/Complex32/Factorization/UserGramSchmidt.cs index 3973c6dc..01bb3013 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Factorization/UserGramSchmidt.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Factorization/UserGramSchmidt.cs @@ -61,7 +61,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization if (matrix.RowCount < matrix.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix); } MatrixQ = matrix.Clone(); @@ -211,7 +211,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization // Check that x is a column vector with n entries if (MatrixQ.ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(MatrixQ, result); } var inputCopy = input.Clone(); diff --git a/src/Numerics/LinearAlgebra/Complex32/Factorization/UserLU.cs b/src/Numerics/LinearAlgebra/Complex32/Factorization/UserLU.cs index 864c94e3..b62ef19f 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Factorization/UserLU.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Factorization/UserLU.cs @@ -162,7 +162,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization if (input.RowCount != Factors.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, Factors); } // Copy the contents of input to result. @@ -243,7 +243,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization if (input.Count != Factors.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, Factors); } // Copy the contents of input to result. diff --git a/src/Numerics/LinearAlgebra/Complex32/Factorization/UserQR.cs b/src/Numerics/LinearAlgebra/Complex32/Factorization/UserQR.cs index 333c64b8..cba8adab 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Factorization/UserQR.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Factorization/UserQR.cs @@ -63,7 +63,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization if (matrix.RowCount < matrix.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix); } MatrixR = matrix.Clone(); @@ -297,7 +297,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization // Check that x is a column vector with n entries if (MatrixR.ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(MatrixR, result); } var inputCopy = input.Clone(); diff --git a/src/Numerics/LinearAlgebra/Complex32/Factorization/UserSvd.cs b/src/Numerics/LinearAlgebra/Complex32/Factorization/UserSvd.cs index d0c21b42..fb3785b7 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Factorization/UserSvd.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Factorization/UserSvd.cs @@ -903,7 +903,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization // Check that x is a column vector with n entries if (MatrixVT.ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(MatrixVT, result); } var mn = Math.Min(MatrixU.RowCount, MatrixVT.ColumnCount); diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/BiCgStab.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/BiCgStab.cs index 2d7309c2..b23b4b24 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/BiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/BiCgStab.cs @@ -259,7 +259,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative if (input.Count != matrix.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, matrix); } // Initialize the solver fields @@ -519,7 +519,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix, input, result); } for (var column = 0; column < input.ColumnCount; column++) diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/CompositeSolver.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/CompositeSolver.cs index c4ec532a..e9e2a179 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/CompositeSolver.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/CompositeSolver.cs @@ -613,7 +613,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix, input, result); } for (var column = 0; column < input.ColumnCount; column++) diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/GpBiCg.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/GpBiCg.cs index 7f9b2fe0..eb21e1a3 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/GpBiCg.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/GpBiCg.cs @@ -314,7 +314,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative if (input.Count != matrix.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, matrix); } // Initialize the solver fields @@ -630,7 +630,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix, input, result); } for (var column = 0; column < input.ColumnCount; column++) diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/MlkBiCgStab.cs index f7e311eb..450a7ce7 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/MlkBiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/MlkBiCgStab.cs @@ -335,7 +335,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative if (input.Count != matrix.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, matrix); } // Initialize the solver fields @@ -796,7 +796,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix, input, result); } for (var column = 0; column < input.ColumnCount; column++) diff --git a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/TFQMR.cs b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/TFQMR.cs index fed7f844..b642c26b 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/TFQMR.cs +++ b/src/Numerics/LinearAlgebra/Complex32/Solvers/Iterative/TFQMR.cs @@ -247,7 +247,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative if (input.Count != matrix.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, matrix); } // Initialize the solver fields @@ -525,7 +525,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Solvers.Iterative if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, matrix, result); } for (var column = 0; column < input.ColumnCount; column++) diff --git a/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs index 7444a165..1ec92341 100644 --- a/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs @@ -275,7 +275,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(this, result)) @@ -337,7 +337,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(this, result)) @@ -472,7 +472,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(this, result)) @@ -535,7 +535,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(this, result)) @@ -818,7 +818,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (RowCount != target.RowCount || ColumnCount != target.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "target"); + throw DimensionsDontMatch(this, target, "target"); } // Lets copy only needed data. Portion of needed data is determined by NonZerosCount value @@ -1043,7 +1043,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 { if (resultSparseMatrix.RowCount != RowCount + lowerSparseMatrix.RowCount || resultSparseMatrix.ColumnCount != ColumnCount + lowerSparseMatrix.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, lowerSparseMatrix, resultSparseMatrix); } resultSparseMatrix.NonZerosCount = NonZerosCount + lowerSparseMatrix.NonZerosCount; @@ -1624,7 +1624,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (leftSide.RowCount != rightSide.RowCount || leftSide.ColumnCount != rightSide.ColumnCount) { - throw new ArgumentOutOfRangeException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return (SparseMatrix)leftSide.Add(rightSide); @@ -1671,7 +1671,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (leftSide.RowCount != rightSide.RowCount || leftSide.ColumnCount != rightSide.ColumnCount) { - throw new ArgumentOutOfRangeException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return (SparseMatrix)leftSide.Subtract(rightSide); @@ -1752,7 +1752,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 if (leftSide.ColumnCount != rightSide.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return (SparseMatrix)leftSide.Multiply(rightSide); diff --git a/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs index 2f8d6cd0..64f233d9 100644 --- a/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs @@ -684,7 +684,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (leftSide.RowCount != rightSide.RowCount || leftSide.ColumnCount != rightSide.ColumnCount) { - throw new ArgumentOutOfRangeException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return (DenseMatrix)leftSide.Add(rightSide); @@ -731,7 +731,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (leftSide.RowCount != rightSide.RowCount || leftSide.ColumnCount != rightSide.ColumnCount) { - throw new ArgumentOutOfRangeException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return (DenseMatrix)leftSide.Subtract(rightSide); @@ -812,7 +812,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (leftSide.ColumnCount != rightSide.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return (DenseMatrix)leftSide.Multiply(rightSide); diff --git a/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs index e44e13e9..7da0f0ba 100644 --- a/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs +++ b/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs @@ -295,7 +295,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (other.RowCount != RowCount || other.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("other", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, "other"); } Matrix result; @@ -333,12 +333,12 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (other.RowCount != RowCount || other.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("other", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, "other"); } if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("result", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, result, "result"); } var diagOther = other as DiagonalMatrix; @@ -370,7 +370,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (other.RowCount != RowCount || other.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("other", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, "other"); } Matrix result; @@ -408,12 +408,12 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (other.RowCount != RowCount || other.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("other", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, "other"); } if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("result", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, result, "result"); } var diagOther = other as DiagonalMatrix; @@ -539,14 +539,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double throw new ArgumentNullException("result"); } - if (ColumnCount != other.RowCount) - { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); - } - - if (result.RowCount != RowCount || result.ColumnCount != other.ColumnCount) + if (ColumnCount != other.RowCount || result.RowCount != RowCount || result.ColumnCount != other.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, result); } var m = other as DiagonalMatrix; @@ -583,7 +578,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (ColumnCount != other.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other); } var m = other as DiagonalMatrix; @@ -615,7 +610,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (ColumnCount != rightSide.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "rightSide"); + throw DimensionsDontMatch(this, rightSide); } if (result == null) @@ -625,7 +620,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (RowCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(rightSide, result)) @@ -665,7 +660,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (RowCount != leftSide.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "leftSide"); + throw DimensionsDontMatch(this, leftSide, "leftSide"); } if (result == null) @@ -675,7 +670,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(leftSide, result)) @@ -764,7 +759,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (ColumnCount != otherDiagonal.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, otherDiagonal); } var result = (DiagonalMatrix)CreateMatrix(RowCount, other.RowCount); @@ -803,7 +798,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (RowCount != target.RowCount || ColumnCount != target.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "target"); + throw DimensionsDontMatch(this, target, "target"); } Buffer.BlockCopy(Data, 0, diagonalTarget.Data, 0, Data.Length * Constants.SizeOfDouble); @@ -1027,7 +1022,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(this, result)) @@ -1067,7 +1062,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } result.Clear(); @@ -1097,7 +1092,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } result.Clear(); @@ -1132,7 +1127,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } result.Clear(); @@ -1367,7 +1362,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (result.RowCount != (RowCount + lower.RowCount) || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, lower, result); } // Clear the result matrix @@ -1499,7 +1494,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (result.RowCount != RowCount + lower.RowCount || result.ColumnCount != ColumnCount + lower.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, lower, result); } // Clear the result matrix diff --git a/src/Numerics/LinearAlgebra/Double/Factorization/DenseCholesky.cs b/src/Numerics/LinearAlgebra/Double/Factorization/DenseCholesky.cs index 0562a2b2..60fcedd5 100644 --- a/src/Numerics/LinearAlgebra/Double/Factorization/DenseCholesky.cs +++ b/src/Numerics/LinearAlgebra/Double/Factorization/DenseCholesky.cs @@ -102,7 +102,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization if (input.RowCount != CholeskyFactor.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, CholeskyFactor); } var dinput = input as DenseMatrix; @@ -151,7 +151,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization if (input.Count != CholeskyFactor.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, CholeskyFactor); } var dinput = input as DenseVector; diff --git a/src/Numerics/LinearAlgebra/Double/Factorization/DenseGramSchmidt.cs b/src/Numerics/LinearAlgebra/Double/Factorization/DenseGramSchmidt.cs index c3f6593b..63d6da6c 100644 --- a/src/Numerics/LinearAlgebra/Double/Factorization/DenseGramSchmidt.cs +++ b/src/Numerics/LinearAlgebra/Double/Factorization/DenseGramSchmidt.cs @@ -65,7 +65,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization if (matrix.RowCount < matrix.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix); } MatrixQ = matrix.Clone(); @@ -201,7 +201,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization // Check that x is a column vector with n entries if (MatrixQ.ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(MatrixQ, result); } var dinput = input as DenseVector; diff --git a/src/Numerics/LinearAlgebra/Double/Factorization/DenseLU.cs b/src/Numerics/LinearAlgebra/Double/Factorization/DenseLU.cs index 78628204..e4c495f1 100644 --- a/src/Numerics/LinearAlgebra/Double/Factorization/DenseLU.cs +++ b/src/Numerics/LinearAlgebra/Double/Factorization/DenseLU.cs @@ -104,7 +104,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization if (input.RowCount != Factors.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, Factors); } var dinput = input as DenseMatrix; @@ -153,7 +153,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization if (input.Count != Factors.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, Factors); } var dinput = input as DenseVector; diff --git a/src/Numerics/LinearAlgebra/Double/Factorization/DenseQR.cs b/src/Numerics/LinearAlgebra/Double/Factorization/DenseQR.cs index d7b8f3c7..0feb4858 100644 --- a/src/Numerics/LinearAlgebra/Double/Factorization/DenseQR.cs +++ b/src/Numerics/LinearAlgebra/Double/Factorization/DenseQR.cs @@ -70,7 +70,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization if (matrix.RowCount < matrix.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix); } MatrixR = matrix.Clone(); @@ -157,7 +157,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization // Check that x is a column vector with n entries if (MatrixR.ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(MatrixR, result); } var dinput = input as DenseVector; diff --git a/src/Numerics/LinearAlgebra/Double/Factorization/DenseSvd.cs b/src/Numerics/LinearAlgebra/Double/Factorization/DenseSvd.cs index 7c544c69..a0440f5b 100644 --- a/src/Numerics/LinearAlgebra/Double/Factorization/DenseSvd.cs +++ b/src/Numerics/LinearAlgebra/Double/Factorization/DenseSvd.cs @@ -160,7 +160,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization // Check that x is a column vector with n entries if (MatrixVT.ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(MatrixVT, result); } var dinput = input as DenseVector; diff --git a/src/Numerics/LinearAlgebra/Double/Factorization/UserCholesky.cs b/src/Numerics/LinearAlgebra/Double/Factorization/UserCholesky.cs index a0ceebba..b2a04d44 100644 --- a/src/Numerics/LinearAlgebra/Double/Factorization/UserCholesky.cs +++ b/src/Numerics/LinearAlgebra/Double/Factorization/UserCholesky.cs @@ -170,7 +170,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization if (input.RowCount != CholeskyFactor.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, CholeskyFactor); } input.CopyTo(result); @@ -231,7 +231,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization if (input.Count != CholeskyFactor.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, CholeskyFactor); } input.CopyTo(result); diff --git a/src/Numerics/LinearAlgebra/Double/Factorization/UserGramSchmidt.cs b/src/Numerics/LinearAlgebra/Double/Factorization/UserGramSchmidt.cs index 81b91085..c3c6fe6a 100644 --- a/src/Numerics/LinearAlgebra/Double/Factorization/UserGramSchmidt.cs +++ b/src/Numerics/LinearAlgebra/Double/Factorization/UserGramSchmidt.cs @@ -60,7 +60,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization if (matrix.RowCount < matrix.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix); } MatrixQ = matrix.Clone(); @@ -205,7 +205,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization // Check that x is a column vector with n entries if (MatrixQ.ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(MatrixQ, result); } var inputCopy = input.Clone(); diff --git a/src/Numerics/LinearAlgebra/Double/Factorization/UserLU.cs b/src/Numerics/LinearAlgebra/Double/Factorization/UserLU.cs index d6e1701b..af9edc69 100644 --- a/src/Numerics/LinearAlgebra/Double/Factorization/UserLU.cs +++ b/src/Numerics/LinearAlgebra/Double/Factorization/UserLU.cs @@ -161,7 +161,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization if (input.RowCount != Factors.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, Factors); } // Copy the contents of input to result. @@ -242,7 +242,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization if (input.Count != Factors.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, Factors); } // Copy the contents of input to result. diff --git a/src/Numerics/LinearAlgebra/Double/Factorization/UserQR.cs b/src/Numerics/LinearAlgebra/Double/Factorization/UserQR.cs index f9fcdc6a..591bc5a3 100644 --- a/src/Numerics/LinearAlgebra/Double/Factorization/UserQR.cs +++ b/src/Numerics/LinearAlgebra/Double/Factorization/UserQR.cs @@ -62,7 +62,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization if (matrix.RowCount < matrix.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix); } MatrixR = matrix.Clone(); @@ -297,7 +297,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization // Check that x is a column vector with n entries if (MatrixR.ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(MatrixR, result); } var inputCopy = input.Clone(); diff --git a/src/Numerics/LinearAlgebra/Double/Factorization/UserSvd.cs b/src/Numerics/LinearAlgebra/Double/Factorization/UserSvd.cs index 96f82f33..75b98b2d 100644 --- a/src/Numerics/LinearAlgebra/Double/Factorization/UserSvd.cs +++ b/src/Numerics/LinearAlgebra/Double/Factorization/UserSvd.cs @@ -887,7 +887,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization // Check that x is a column vector with n entries if (MatrixVT.ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(MatrixVT, result); } var mn = Math.Min(MatrixU.RowCount, MatrixVT.ColumnCount); diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/BiCgStab.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/BiCgStab.cs index 9bf21fca..b400b5ac 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/BiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/BiCgStab.cs @@ -258,7 +258,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative if (input.Count != matrix.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, matrix); } // Initialize the solver fields @@ -518,7 +518,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix, input, result); } for (var column = 0; column < input.ColumnCount; column++) diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/CompositeSolver.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/CompositeSolver.cs index f3b8f902..4d9a0ab8 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/CompositeSolver.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/CompositeSolver.cs @@ -611,7 +611,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix, input, result); } for (var column = 0; column < input.ColumnCount; column++) diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/GpBiCg.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/GpBiCg.cs index f85d2c49..9af36204 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/GpBiCg.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/GpBiCg.cs @@ -313,7 +313,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative if (input.Count != matrix.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, matrix); } // Initialize the solver fields @@ -629,7 +629,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix, input, result); } for (var column = 0; column < input.ColumnCount; column++) diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/MlkBiCgStab.cs index b2090c1a..d80ce285 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/MlkBiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/MlkBiCgStab.cs @@ -335,7 +335,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative if (input.Count != matrix.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, matrix); } // Initialize the solver fields @@ -790,7 +790,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix, input, result); } for (var column = 0; column < input.ColumnCount; column++) diff --git a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/TFQMR.cs b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/TFQMR.cs index e122a3f5..1a70a9be 100644 --- a/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/TFQMR.cs +++ b/src/Numerics/LinearAlgebra/Double/Solvers/Iterative/TFQMR.cs @@ -246,7 +246,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative if (input.Count != matrix.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, matrix); } // Initialize the solver fields @@ -524,7 +524,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Solvers.Iterative if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix, input, result); } for (var column = 0; column < input.ColumnCount; column++) diff --git a/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs index 2abb2231..1a20251d 100644 --- a/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs @@ -268,7 +268,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(this, result)) @@ -330,7 +330,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(this, result)) @@ -465,7 +465,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(this, result)) @@ -528,7 +528,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(this, result)) @@ -829,7 +829,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (RowCount != target.RowCount || ColumnCount != target.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "target"); + throw DimensionsDontMatch(this, target, "target"); } // Lets copy only needed data. Portion of needed data is determined by NonZerosCount value @@ -1054,7 +1054,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double { if (resultSparseMatrix.RowCount != RowCount + lowerSparseMatrix.RowCount || resultSparseMatrix.ColumnCount != ColumnCount + lowerSparseMatrix.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, lowerSparseMatrix, resultSparseMatrix); } resultSparseMatrix.NonZerosCount = NonZerosCount + lowerSparseMatrix.NonZerosCount; @@ -1662,7 +1662,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (leftSide.RowCount != rightSide.RowCount || leftSide.ColumnCount != rightSide.ColumnCount) { - throw new ArgumentOutOfRangeException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return (SparseMatrix)leftSide.Add(rightSide); @@ -1709,7 +1709,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (leftSide.RowCount != rightSide.RowCount || leftSide.ColumnCount != rightSide.ColumnCount) { - throw new ArgumentOutOfRangeException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return (SparseMatrix)leftSide.Subtract(rightSide); @@ -1790,7 +1790,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (leftSide.ColumnCount != rightSide.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return (SparseMatrix)leftSide.Multiply(rightSide); diff --git a/src/Numerics/LinearAlgebra/Generic/Matrix.Arithmetic.cs b/src/Numerics/LinearAlgebra/Generic/Matrix.Arithmetic.cs index 69899694..58180ebc 100644 --- a/src/Numerics/LinearAlgebra/Generic/Matrix.Arithmetic.cs +++ b/src/Numerics/LinearAlgebra/Generic/Matrix.Arithmetic.cs @@ -62,7 +62,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (other.RowCount != RowCount || other.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other); } var result = CreateMatrix(RowCount, ColumnCount); @@ -86,12 +86,12 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (other.RowCount != RowCount || other.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("other", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, "other"); } if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("result", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, result, "result"); } DoAdd(other, result); @@ -122,7 +122,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (other.RowCount != RowCount || other.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other); } var result = CreateMatrix(RowCount, ColumnCount); @@ -146,7 +146,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (other.RowCount != RowCount || other.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other); } DoSubtract(other, result); @@ -326,7 +326,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (ColumnCount != rightSide.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "rightSide"); + throw DimensionsDontMatch(this, rightSide, "rightSide"); } if (result == null) @@ -336,7 +336,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (RowCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(rightSide, result)) @@ -390,7 +390,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (RowCount != leftSide.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "leftSide"); + throw DimensionsDontMatch(this, leftSide, "leftSide"); } if (result == null) @@ -400,7 +400,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(leftSide, result)) @@ -446,14 +446,9 @@ namespace MathNet.Numerics.LinearAlgebra.Generic throw new ArgumentNullException("result"); } - if (ColumnCount != other.RowCount) - { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); - } - - if (result.RowCount != RowCount || result.ColumnCount != other.ColumnCount) + if (ColumnCount != other.RowCount || result.RowCount != RowCount || result.ColumnCount != other.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, result); } if (ReferenceEquals(this, result) || ReferenceEquals(other, result)) @@ -481,10 +476,9 @@ namespace MathNet.Numerics.LinearAlgebra.Generic { throw new ArgumentNullException("other"); } - if (ColumnCount != other.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other); } var result = CreateMatrix(RowCount, other.ColumnCount); @@ -520,14 +514,9 @@ namespace MathNet.Numerics.LinearAlgebra.Generic throw new ArgumentNullException("result"); } - if (ColumnCount != other.ColumnCount) - { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); - } - - if ((result.RowCount != RowCount) || (result.ColumnCount != other.RowCount)) + if (ColumnCount != other.ColumnCount || result.RowCount != RowCount || result.ColumnCount != other.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, result); } if (ReferenceEquals(this, result) || ReferenceEquals(other, result)) @@ -558,7 +547,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (ColumnCount != other.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other); } var result = CreateMatrix(RowCount, other.RowCount); @@ -605,7 +594,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (RowCount != rightSide.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "rightSide"); + throw DimensionsDontMatch(this, rightSide, "rightSide"); } if (result == null) @@ -615,7 +604,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(rightSide, result)) @@ -658,14 +647,9 @@ namespace MathNet.Numerics.LinearAlgebra.Generic throw new ArgumentNullException("result"); } - if (RowCount != other.RowCount) + if (RowCount != other.RowCount || result.RowCount != ColumnCount || result.ColumnCount != other.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); - } - - if ((result.RowCount != ColumnCount) || (result.ColumnCount != other.ColumnCount)) - { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, result); } if (ReferenceEquals(this, result) || ReferenceEquals(other, result)) @@ -696,7 +680,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (RowCount != other.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other); } var result = CreateMatrix(ColumnCount, other.ColumnCount); @@ -737,7 +721,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, result); } DoNegate(result); @@ -774,7 +758,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (leftSide.RowCount != rightSide.RowCount || leftSide.ColumnCount != rightSide.ColumnCount) { - throw new ArgumentOutOfRangeException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return leftSide.Add(rightSide); @@ -821,7 +805,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (leftSide.RowCount != rightSide.RowCount || leftSide.ColumnCount != rightSide.ColumnCount) { - throw new ArgumentOutOfRangeException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return leftSide.Subtract(rightSide); @@ -902,7 +886,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (leftSide.ColumnCount != rightSide.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return leftSide.Multiply(rightSide); @@ -958,7 +942,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (ColumnCount != other.ColumnCount || RowCount != other.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "other"); + throw DimensionsDontMatch(this, other, "other"); } var result = CreateMatrix(RowCount, ColumnCount); @@ -987,14 +971,9 @@ namespace MathNet.Numerics.LinearAlgebra.Generic throw new ArgumentNullException("result"); } - if (ColumnCount != other.ColumnCount || RowCount != other.RowCount) + if (ColumnCount != result.ColumnCount || RowCount != result.RowCount || ColumnCount != other.ColumnCount || RowCount != other.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); - } - - if (ColumnCount != result.ColumnCount || RowCount != result.RowCount) - { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, other, result); } DoPointwiseMultiply(other, result); @@ -1016,7 +995,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (ColumnCount != other.ColumnCount || RowCount != other.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "other"); + throw DimensionsDontMatch(this, other); } var result = CreateMatrix(RowCount, ColumnCount); @@ -1052,14 +1031,9 @@ namespace MathNet.Numerics.LinearAlgebra.Generic throw new ArgumentNullException("result"); } - if (ColumnCount != other.ColumnCount || RowCount != other.RowCount) + if (ColumnCount != result.ColumnCount || RowCount != result.RowCount || ColumnCount != other.ColumnCount || RowCount != other.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); - } - - if (ColumnCount != result.ColumnCount || RowCount != result.RowCount) - { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, other, result); } DoPointwiseDivide(other, result); @@ -1098,7 +1072,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (ColumnCount != result.ColumnCount || RowCount != result.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result); } DoModulus(divisor, result); @@ -1288,7 +1262,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (result.RowCount != (RowCount * other.RowCount) || result.ColumnCount != (ColumnCount * other.ColumnCount)) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, other, result); } for (var j = 0; j < ColumnCount; j++) @@ -1345,5 +1319,68 @@ namespace MathNet.Numerics.LinearAlgebra.Generic return ret; } + + #region Exceptions - possibly move elsewhere? + + public static Exception DimensionsDontMatch(Matrix left, Matrix right, Matrix result, string paramName = null) + where TException : Exception + { + var message = string.Format(Resources.ArgumentMatrixDimensions3, left.RowCount + "x" + left.ColumnCount, right.RowCount + "x" + right.ColumnCount, result.RowCount + "x" + result.ColumnCount); + return CreateException(message, paramName); + } + + public static Exception DimensionsDontMatch(Matrix left, Matrix right, string paramName = null) + where TException : Exception + { + var message = string.Format(Resources.ArgumentMatrixDimensions2, left.RowCount + "x" + left.ColumnCount, right.RowCount + "x" + right.ColumnCount); + return CreateException(message, paramName); + } + + public static Exception DimensionsDontMatch(Matrix matrix) + where TException : Exception + { + var message = string.Format(Resources.ArgumentMatrixDimensions1, matrix.RowCount + "x" + matrix.ColumnCount); + return CreateException(message); + } + + public static Exception DimensionsDontMatch(Matrix left, Vector right, Vector result, string paramName = null) + where TException : Exception + { + return DimensionsDontMatch(left, right.ToColumnMatrix(), result.ToColumnMatrix(), paramName); + } + + public static Exception DimensionsDontMatch(Matrix left, Vector right, string paramName = null) + where TException : Exception + { + return DimensionsDontMatch(left, right.ToColumnMatrix(), paramName); + } + + public static Exception DimensionsDontMatch(Vector left, Matrix right, string paramName = null) + where TException : Exception + { + return DimensionsDontMatch(left.ToColumnMatrix(), right, paramName); + } + + public static Exception DimensionsDontMatch(Vector left, Vector right, string paramName = null) + where TException : Exception + { + return DimensionsDontMatch(left.ToColumnMatrix(), right.ToColumnMatrix(), paramName); + } + + private static Exception CreateException(string message, string paramName = null) + where TException : Exception + { + if (typeof(TException) == typeof(ArgumentException)) + { + return new ArgumentException(message, paramName); + } + if (typeof(TException) == typeof(ArgumentOutOfRangeException)) + { + return new ArgumentOutOfRangeException(paramName, message); + } + return new Exception(message); + } + + #endregion } } diff --git a/src/Numerics/LinearAlgebra/Generic/Matrix.cs b/src/Numerics/LinearAlgebra/Generic/Matrix.cs index 1f0322a5..de09f0b8 100644 --- a/src/Numerics/LinearAlgebra/Generic/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Generic/Matrix.cs @@ -280,7 +280,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (RowCount != target.RowCount || ColumnCount != target.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "target"); + throw DimensionsDontMatch(this, target); } for (var i = 0; i < RowCount; i++) @@ -573,7 +573,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } for (var row = 0; row < RowCount; row++) @@ -619,7 +619,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } for (var row = 0; row < RowCount; row++) @@ -848,7 +848,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } for (var row = 0; row < RowCount; row++) @@ -895,7 +895,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } for (var row = 0; row < RowCount; row++) @@ -1717,7 +1717,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (result.RowCount != (RowCount + lower.RowCount) || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } for (var i = 0; i < RowCount; i++) @@ -1779,7 +1779,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic if (result.RowCount != RowCount + lower.RowCount || result.ColumnCount != ColumnCount + lower.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } for (var i = 0; i < RowCount; i++) diff --git a/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs index 663b1033..bbabcc2c 100644 --- a/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs @@ -683,7 +683,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (leftSide.RowCount != rightSide.RowCount || leftSide.ColumnCount != rightSide.ColumnCount) { - throw new ArgumentOutOfRangeException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return (DenseMatrix)leftSide.Add(rightSide); @@ -730,7 +730,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (leftSide.RowCount != rightSide.RowCount || leftSide.ColumnCount != rightSide.ColumnCount) { - throw new ArgumentOutOfRangeException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return (DenseMatrix)leftSide.Subtract(rightSide); @@ -811,7 +811,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (leftSide.ColumnCount != rightSide.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return (DenseMatrix)leftSide.Multiply(rightSide); diff --git a/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs index 41e81e76..de0bb4c0 100644 --- a/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs +++ b/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs @@ -295,7 +295,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (other.RowCount != RowCount || other.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("other", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, "other"); } Matrix result; @@ -333,12 +333,12 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (other.RowCount != RowCount || other.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("other", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, "other"); } if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("result", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, result, "result"); } var diagOther = other as DiagonalMatrix; @@ -370,7 +370,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (other.RowCount != RowCount || other.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("other", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, "other"); } Matrix result; @@ -408,12 +408,12 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (other.RowCount != RowCount || other.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("other", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, "other"); } if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentOutOfRangeException("result", Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, result, "result"); } var diagOther = other as DiagonalMatrix; @@ -539,14 +539,9 @@ namespace MathNet.Numerics.LinearAlgebra.Single throw new ArgumentNullException("result"); } - if (ColumnCount != other.RowCount) - { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); - } - - if (result.RowCount != RowCount || result.ColumnCount != other.ColumnCount) + if (ColumnCount != other.RowCount || result.RowCount != RowCount || result.ColumnCount != other.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other, result); } var m = other as DiagonalMatrix; @@ -583,7 +578,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (ColumnCount != other.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, other); } var m = other as DiagonalMatrix; @@ -615,7 +610,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (ColumnCount != rightSide.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "rightSide"); + throw DimensionsDontMatch(this, rightSide, "rightSide"); } if (result == null) @@ -625,7 +620,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (RowCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(rightSide, result)) @@ -665,7 +660,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (RowCount != leftSide.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "leftSide"); + throw DimensionsDontMatch(this, leftSide, "leftSide"); } if (result == null) @@ -675,7 +670,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(leftSide, result)) @@ -764,7 +759,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (ColumnCount != otherDiagonal.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(this, otherDiagonal); } var result = (DiagonalMatrix)CreateMatrix(RowCount, other.RowCount); @@ -803,7 +798,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (RowCount != target.RowCount || ColumnCount != target.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "target"); + throw DimensionsDontMatch(this, target, "target"); } Buffer.BlockCopy(Data, 0, diagonalTarget.Data, 0, Data.Length * Constants.SizeOfFloat); @@ -1027,7 +1022,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(this, result)) @@ -1067,7 +1062,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } result.Clear(); @@ -1097,7 +1092,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } result.Clear(); @@ -1132,7 +1127,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } result.Clear(); @@ -1367,7 +1362,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (result.RowCount != (RowCount + lower.RowCount) || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, lower, result); } // Clear the result matrix @@ -1499,7 +1494,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (result.RowCount != RowCount + lower.RowCount || result.ColumnCount != ColumnCount + lower.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, lower, result); } // Clear the result matrix diff --git a/src/Numerics/LinearAlgebra/Single/Factorization/DenseCholesky.cs b/src/Numerics/LinearAlgebra/Single/Factorization/DenseCholesky.cs index 4ef94134..e5c29589 100644 --- a/src/Numerics/LinearAlgebra/Single/Factorization/DenseCholesky.cs +++ b/src/Numerics/LinearAlgebra/Single/Factorization/DenseCholesky.cs @@ -102,7 +102,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization if (input.RowCount != CholeskyFactor.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, CholeskyFactor); } var dinput = input as DenseMatrix; @@ -151,7 +151,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization if (input.Count != CholeskyFactor.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, CholeskyFactor); } var dinput = input as DenseVector; diff --git a/src/Numerics/LinearAlgebra/Single/Factorization/DenseGramSchmidt.cs b/src/Numerics/LinearAlgebra/Single/Factorization/DenseGramSchmidt.cs index 16271835..9460a9d7 100644 --- a/src/Numerics/LinearAlgebra/Single/Factorization/DenseGramSchmidt.cs +++ b/src/Numerics/LinearAlgebra/Single/Factorization/DenseGramSchmidt.cs @@ -65,7 +65,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization if (matrix.RowCount < matrix.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix); } MatrixQ = matrix.Clone(); @@ -201,7 +201,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization // Check that x is a column vector with n entries if (MatrixQ.ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(MatrixQ, result); } var dinput = input as DenseVector; diff --git a/src/Numerics/LinearAlgebra/Single/Factorization/DenseLU.cs b/src/Numerics/LinearAlgebra/Single/Factorization/DenseLU.cs index 8b27c976..edc45b7e 100644 --- a/src/Numerics/LinearAlgebra/Single/Factorization/DenseLU.cs +++ b/src/Numerics/LinearAlgebra/Single/Factorization/DenseLU.cs @@ -104,7 +104,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization if (input.RowCount != Factors.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, Factors); } var dinput = input as DenseMatrix; @@ -153,7 +153,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization if (input.Count != Factors.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, Factors); } var dinput = input as DenseVector; diff --git a/src/Numerics/LinearAlgebra/Single/Factorization/DenseQR.cs b/src/Numerics/LinearAlgebra/Single/Factorization/DenseQR.cs index c9fdd468..05c4a593 100644 --- a/src/Numerics/LinearAlgebra/Single/Factorization/DenseQR.cs +++ b/src/Numerics/LinearAlgebra/Single/Factorization/DenseQR.cs @@ -70,7 +70,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization if (matrix.RowCount < matrix.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix); } MatrixR = matrix.Clone(); @@ -157,7 +157,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization // Check that x is a column vector with n entries if (MatrixR.ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(MatrixR, result); } var dinput = input as DenseVector; diff --git a/src/Numerics/LinearAlgebra/Single/Factorization/DenseSvd.cs b/src/Numerics/LinearAlgebra/Single/Factorization/DenseSvd.cs index 6c9208e6..c210034b 100644 --- a/src/Numerics/LinearAlgebra/Single/Factorization/DenseSvd.cs +++ b/src/Numerics/LinearAlgebra/Single/Factorization/DenseSvd.cs @@ -160,7 +160,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization // Check that x is a column vector with n entries if (MatrixVT.ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(MatrixVT, result); } var dinput = input as DenseVector; diff --git a/src/Numerics/LinearAlgebra/Single/Factorization/UserCholesky.cs b/src/Numerics/LinearAlgebra/Single/Factorization/UserCholesky.cs index 3bff9b46..d813d63b 100644 --- a/src/Numerics/LinearAlgebra/Single/Factorization/UserCholesky.cs +++ b/src/Numerics/LinearAlgebra/Single/Factorization/UserCholesky.cs @@ -170,7 +170,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization if (input.RowCount != CholeskyFactor.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, CholeskyFactor); } input.CopyTo(result); @@ -231,7 +231,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization if (input.Count != CholeskyFactor.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, CholeskyFactor); } input.CopyTo(result); diff --git a/src/Numerics/LinearAlgebra/Single/Factorization/UserGramSchmidt.cs b/src/Numerics/LinearAlgebra/Single/Factorization/UserGramSchmidt.cs index 89453454..0dbd9ca3 100644 --- a/src/Numerics/LinearAlgebra/Single/Factorization/UserGramSchmidt.cs +++ b/src/Numerics/LinearAlgebra/Single/Factorization/UserGramSchmidt.cs @@ -60,7 +60,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization if (matrix.RowCount < matrix.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix); } MatrixQ = matrix.Clone(); @@ -205,7 +205,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization // Check that x is a column vector with n entries if (MatrixQ.ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(MatrixQ, result); } var inputCopy = input.Clone(); diff --git a/src/Numerics/LinearAlgebra/Single/Factorization/UserLU.cs b/src/Numerics/LinearAlgebra/Single/Factorization/UserLU.cs index 2fbf8294..5bab394e 100644 --- a/src/Numerics/LinearAlgebra/Single/Factorization/UserLU.cs +++ b/src/Numerics/LinearAlgebra/Single/Factorization/UserLU.cs @@ -161,7 +161,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization if (input.RowCount != Factors.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, Factors); } // Copy the contents of input to result. @@ -242,7 +242,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization if (input.Count != Factors.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, Factors); } // Copy the contents of input to result. diff --git a/src/Numerics/LinearAlgebra/Single/Factorization/UserQR.cs b/src/Numerics/LinearAlgebra/Single/Factorization/UserQR.cs index 11fe1b93..af3bc5aa 100644 --- a/src/Numerics/LinearAlgebra/Single/Factorization/UserQR.cs +++ b/src/Numerics/LinearAlgebra/Single/Factorization/UserQR.cs @@ -62,7 +62,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization if (matrix.RowCount < matrix.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix); } MatrixR = matrix.Clone(); @@ -297,7 +297,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization // Check that x is a column vector with n entries if (MatrixR.ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(MatrixR, result); } var inputCopy = input.Clone(); diff --git a/src/Numerics/LinearAlgebra/Single/Factorization/UserSvd.cs b/src/Numerics/LinearAlgebra/Single/Factorization/UserSvd.cs index aead860f..0fc4ac63 100644 --- a/src/Numerics/LinearAlgebra/Single/Factorization/UserSvd.cs +++ b/src/Numerics/LinearAlgebra/Single/Factorization/UserSvd.cs @@ -887,7 +887,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization // Check that x is a column vector with n entries if (MatrixVT.ColumnCount != result.Count) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(MatrixVT, result); } var mn = Math.Min(MatrixU.RowCount, MatrixVT.ColumnCount); diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/BiCgStab.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/BiCgStab.cs index 26c6aaf9..209a24aa 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/BiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/BiCgStab.cs @@ -258,7 +258,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative if (input.Count != matrix.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, matrix); } // Initialize the solver fields @@ -518,7 +518,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix, input, result); } for (var column = 0; column < input.ColumnCount; column++) diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/CompositeSolver.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/CompositeSolver.cs index 1f8cbb19..caf74438 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/CompositeSolver.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/CompositeSolver.cs @@ -613,7 +613,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix, input, result); } for (var column = 0; column < input.ColumnCount; column++) diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/GpBiCg.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/GpBiCg.cs index 48951507..cef9d85b 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/GpBiCg.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/GpBiCg.cs @@ -313,7 +313,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative if (input.Count != matrix.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, matrix); } // Initialize the solver fields @@ -629,7 +629,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix, input, result); } for (var column = 0; column < input.ColumnCount; column++) diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/MlkBiCgStab.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/MlkBiCgStab.cs index 0eaae0c2..0b3c20f2 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/MlkBiCgStab.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/MlkBiCgStab.cs @@ -333,7 +333,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative if (input.Count != matrix.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, matrix); } // Initialize the solver fields @@ -792,7 +792,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix, input, result); } for (var column = 0; column < input.ColumnCount; column++) diff --git a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/TFQMR.cs b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/TFQMR.cs index acbbffd6..2c922a0d 100644 --- a/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/TFQMR.cs +++ b/src/Numerics/LinearAlgebra/Single/Solvers/Iterative/TFQMR.cs @@ -246,7 +246,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative if (input.Count != matrix.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(input, matrix); } // Initialize the solver fields @@ -524,7 +524,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Solvers.Iterative if (matrix.RowCount != input.RowCount || input.RowCount != result.RowCount || input.ColumnCount != result.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw Matrix.DimensionsDontMatch(matrix, input, result); } for (var column = 0; column < input.ColumnCount; column++) diff --git a/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs index fae0fb6f..2f02cb9e 100644 --- a/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs +++ b/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs @@ -269,7 +269,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(this, result)) @@ -331,7 +331,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(this, result)) @@ -466,7 +466,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(this, result)) @@ -529,7 +529,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (result.RowCount != RowCount || result.ColumnCount != ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, result, "result"); } if (ReferenceEquals(this, result)) @@ -812,7 +812,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (RowCount != target.RowCount || ColumnCount != target.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "target"); + throw DimensionsDontMatch(this, target, "target"); } // Lets copy only needed data. Portion of needed data is determined by NonZerosCount value @@ -1037,7 +1037,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single { if (resultSparseMatrix.RowCount != RowCount + lowerSparseMatrix.RowCount || resultSparseMatrix.ColumnCount != ColumnCount + lowerSparseMatrix.ColumnCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions, "result"); + throw DimensionsDontMatch(this, lowerSparseMatrix, resultSparseMatrix, "result"); } resultSparseMatrix.NonZerosCount = NonZerosCount + lowerSparseMatrix.NonZerosCount; @@ -1645,7 +1645,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (leftSide.RowCount != rightSide.RowCount || leftSide.ColumnCount != rightSide.ColumnCount) { - throw new ArgumentOutOfRangeException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return (SparseMatrix)leftSide.Add(rightSide); @@ -1692,7 +1692,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (leftSide.RowCount != rightSide.RowCount || leftSide.ColumnCount != rightSide.ColumnCount) { - throw new ArgumentOutOfRangeException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return (SparseMatrix)leftSide.Subtract(rightSide); @@ -1773,7 +1773,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single if (leftSide.ColumnCount != rightSide.RowCount) { - throw new ArgumentException(Resources.ArgumentMatrixDimensions); + throw DimensionsDontMatch(leftSide, rightSide); } return (SparseMatrix)leftSide.Multiply(rightSide); diff --git a/src/Numerics/Numerics.csproj b/src/Numerics/Numerics.csproj index 2828f2cc..3a64023c 100644 --- a/src/Numerics/Numerics.csproj +++ b/src/Numerics/Numerics.csproj @@ -443,6 +443,7 @@ ResXFileCodeGenerator Resources.Designer.cs + Designer diff --git a/src/Numerics/Properties/Resources.Designer.cs b/src/Numerics/Properties/Resources.Designer.cs index afac0b4e..37163f68 100644 --- a/src/Numerics/Properties/Resources.Designer.cs +++ b/src/Numerics/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.225 +// Runtime Version:4.0.30319.239 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -159,6 +159,33 @@ namespace MathNet.Numerics.Properties { } } + /// + /// Looks up a localized string similar to Matrix dimensions must agree: {0}.. + /// + internal static string ArgumentMatrixDimensions1 { + get { + return ResourceManager.GetString("ArgumentMatrixDimensions1", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Matrix dimensions must agree: op1 is {0}, op2 is {1}.. + /// + internal static string ArgumentMatrixDimensions2 { + get { + return ResourceManager.GetString("ArgumentMatrixDimensions2", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Matrix dimensions must agree: op1 is {0}, op2 is {1}, op3 is {2}.. + /// + internal static string ArgumentMatrixDimensions3 { + get { + return ResourceManager.GetString("ArgumentMatrixDimensions3", resourceCulture); + } + } + /// /// Looks up a localized string similar to The requested matrix does not exist.. /// diff --git a/src/Numerics/Properties/Resources.resx b/src/Numerics/Properties/Resources.resx index 969bb57e..b6925415 100644 --- a/src/Numerics/Properties/Resources.resx +++ b/src/Numerics/Properties/Resources.resx @@ -138,6 +138,15 @@ Matrix dimensions must agree. + + Matrix dimensions must agree: {0}. + + + Matrix dimensions must agree: op1 is {0}, op2 is {1}. + + + Matrix dimensions must agree: op1 is {0}, op2 is {1}, op3 is {2}. + Matrix row dimensions must agree.