From 52e58d6abdf0b3c0ebb96c4e53116d0512f4303d Mon Sep 17 00:00:00 2001 From: Marcus Cuda Date: Mon, 4 Jan 2010 18:43:38 +0800 Subject: [PATCH] matrix: corrected CopyTo and StyleCop errors --- src/Numerics/LinearAlgebra/Double/Matrix.cs | 55 ++++++++++--------- .../Double/UserDefinedVectorTests.cs | 2 +- src/UnitTests/UnitTests.csproj | 1 + 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/Numerics/LinearAlgebra/Double/Matrix.cs b/src/Numerics/LinearAlgebra/Double/Matrix.cs index 87dfdd5b..6adb3f11 100644 --- a/src/Numerics/LinearAlgebra/Double/Matrix.cs +++ b/src/Numerics/LinearAlgebra/Double/Matrix.cs @@ -30,9 +30,8 @@ namespace MathNet.Numerics.LinearAlgebra.Double { using System; using System.Text; - using Threading; - using Properties; + using Threading; /// /// Defines the base class for Matrix classes. @@ -195,23 +194,17 @@ namespace MathNet.Numerics.LinearAlgebra.Double if (RowCount != target.RowCount || ColumnCount != target.ColumnCount) { - throw new ArgumentException("target", Resources.ArgumentMatrixSameDimensions); + throw new ArgumentException(Resources.ArgumentMatrixSameDimensions, "target"); } - var denseMatrix = target as DenseMatrix; - if (denseMatrix != null) + // TODO this assumes that all entries matter; if "this" is a sparse matrix, + // we might be able to optimize the copying a bit. + for (int i = 0; i < RowCount; i++) { - // TODO this assumes that all entries matter; if "this" is a sparse matrix, - // we might be able to optimize the copying a bit. - for (int i = 0; i < RowCount; i++) + for (int j = 0; j < ColumnCount; j++) { - for (int j = 0; j < ColumnCount; j++) - { - denseMatrix.At(i, j, this.At(i, j)); - } + target.At(i, j, At(i, j)); } - - return; } } @@ -240,7 +233,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double /// public override string ToString() { - return this.ToString(null, null); + return ToString(null, null); } #region Implemented Interfaces @@ -446,13 +439,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double throw new ArgumentOutOfRangeException(Resources.ArgumentMatrixSameDimensions); } - Parallel.For(0, RowCount, i => - { - for (int j = 0; j < ColumnCount; j++) + Parallel.For( + 0, + RowCount, + i => { - At(i, j, At(i, j) + other.At(i, j)); - } - }); + for (int j = 0; j < ColumnCount; j++) + { + At(i, j, At(i, j) + other.At(i, j)); + } + }); } /// @@ -472,6 +468,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double { throw new ArgumentNullException("rightSide"); } + if (leftSide == null) { throw new ArgumentNullException("leftSide"); @@ -505,13 +502,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double throw new ArgumentOutOfRangeException(Resources.ArgumentMatrixSameDimensions); } - Parallel.For(0, RowCount, i => - { - for(int j = 0; j < ColumnCount; j++) + Parallel.For( + 0, + RowCount, + i => { - At(i, j, At(i, j) - other.At(i, j)); - } - }); + for (int j = 0; j < ColumnCount; j++) + { + At(i, j, At(i, j) - other.At(i, j)); + } + }); } /// @@ -531,6 +531,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double { throw new ArgumentNullException("rightSide"); } + if (leftSide == null) { throw new ArgumentNullException("leftSide"); diff --git a/src/UnitTests/LinearAlgebraTests/Double/UserDefinedVectorTests.cs b/src/UnitTests/LinearAlgebraTests/Double/UserDefinedVectorTests.cs index 781c19b9..320a7d4f 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/UserDefinedVectorTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/UserDefinedVectorTests.cs @@ -30,7 +30,7 @@ public override Matrix CreateMatrix(int rows, int columns) { - throw new NotImplementedException(); + return new UserDefinedMatrix(rows, columns); } public override Vector CreateVector(int size) diff --git a/src/UnitTests/UnitTests.csproj b/src/UnitTests/UnitTests.csproj index a14a4c56..9afa63cb 100644 --- a/src/UnitTests/UnitTests.csproj +++ b/src/UnitTests/UnitTests.csproj @@ -90,6 +90,7 @@ +