diff --git a/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
index 0253b556..1f285089 100644
--- a/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
@@ -187,30 +187,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return new DenseVector(size);
}
- ///
- /// Copies the elements of this matrix to the given matrix.
- ///
- ///
- /// The matrix to copy values into.
- ///
- ///
- /// If target is .
- ///
- ///
- /// If this and the target matrix do not have the same dimensions..
- ///
- public override void CopyTo(Matrix target)
- {
- var denseTarget = target as DenseMatrix;
- if (denseTarget != null)
- {
- _storage.CopyTo(denseTarget.Raw);
- return;
- }
-
- base.CopyTo(target);
- }
-
///
/// Creates a matrix that contains the values from the requested sub-matrix.
///
diff --git a/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
index e31ff9ae..d26e2265 100644
--- a/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
@@ -724,44 +724,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
#endregion
- ///
- /// Copies the elements of this matrix to the given matrix.
- ///
- ///
- /// The matrix to copy values into.
- ///
- ///
- /// If target is .
- ///
- ///
- /// If this and the target matrix do not have the same dimensions..
- ///
- public override void CopyTo(Matrix target)
- {
- var diagonalTarget = target as DiagonalMatrix;
- if (diagonalTarget != null)
- {
- _storage.CopyTo(diagonalTarget.Raw);
- return;
- }
-
- var denseTarget = target as DenseMatrix;
- if (denseTarget != null)
- {
- _storage.CopyTo(denseTarget.Raw);
- return;
- }
-
- var sparseTarget = target as SparseMatrix;
- if (sparseTarget != null)
- {
- _storage.CopyTo(sparseTarget.Raw);
- return;
- }
-
- base.CopyTo(target);
- }
-
///
/// Returns the transpose of this matrix.
///
diff --git a/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
index f44ca9af..857dc40b 100644
--- a/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
@@ -613,37 +613,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return ret;
}
- ///
- /// Copies the elements of this matrix to the given matrix.
- ///
- ///
- /// The matrix to copy values into.
- ///
- ///
- /// If target is .
- ///
- ///
- /// If this and the target matrix do not have the same dimensions..
- ///
- public override void CopyTo(Matrix target)
- {
- var sparseTarget = target as SparseMatrix;
- if (sparseTarget != null)
- {
- _storage.CopyTo(sparseTarget.Raw);
- return;
- }
-
- var denseTarget = target as DenseMatrix;
- if (denseTarget != null)
- {
- _storage.CopyTo(denseTarget.Raw);
- return;
- }
-
- base.CopyTo(target);
- }
-
///
/// Returns a hash code for this instance.
///
diff --git a/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
index ba91ef2e..80dfdc35 100644
--- a/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
@@ -187,30 +187,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return new DenseVector(size);
}
- ///
- /// Copies the elements of this matrix to the given matrix.
- ///
- ///
- /// The matrix to copy values into.
- ///
- ///
- /// If target is .
- ///
- ///
- /// If this and the target matrix do not have the same dimensions..
- ///
- public override void CopyTo(Matrix target)
- {
- var denseTarget = target as DenseMatrix;
- if (denseTarget != null)
- {
- _storage.CopyTo(denseTarget.Raw);
- return;
- }
-
- base.CopyTo(target);
- }
-
///
/// Creates a matrix that contains the values from the requested sub-matrix.
///
diff --git a/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
index 38d859f1..298111f5 100644
--- a/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
@@ -724,44 +724,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
#endregion
- ///
- /// Copies the elements of this matrix to the given matrix.
- ///
- ///
- /// The matrix to copy values into.
- ///
- ///
- /// If target is .
- ///
- ///
- /// If this and the target matrix do not have the same dimensions..
- ///
- public override void CopyTo(Matrix target)
- {
- var diagonalTarget = target as DiagonalMatrix;
- if (diagonalTarget != null)
- {
- _storage.CopyTo(diagonalTarget.Raw);
- return;
- }
-
- var denseTarget = target as DenseMatrix;
- if (denseTarget != null)
- {
- _storage.CopyTo(denseTarget.Raw);
- return;
- }
-
- var sparseTarget = target as SparseMatrix;
- if (sparseTarget != null)
- {
- _storage.CopyTo(sparseTarget.Raw);
- return;
- }
-
- base.CopyTo(target);
- }
-
///
/// Returns the transpose of this matrix.
///
diff --git a/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
index c7e5d95c..be25719a 100644
--- a/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
@@ -613,37 +613,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return ret;
}
- ///
- /// Copies the elements of this matrix to the given matrix.
- ///
- ///
- /// The matrix to copy values into.
- ///
- ///
- /// If target is .
- ///
- ///
- /// If this and the target matrix do not have the same dimensions..
- ///
- public override void CopyTo(Matrix target)
- {
- var sparseTarget = target as SparseMatrix;
- if (sparseTarget != null)
- {
- _storage.CopyTo(sparseTarget.Raw);
- return;
- }
-
- var denseTarget = target as DenseMatrix;
- if (denseTarget != null)
- {
- _storage.CopyTo(denseTarget.Raw);
- return;
- }
-
- base.CopyTo(target);
- }
-
///
/// Returns a hash code for this instance.
///
diff --git a/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs
index 24732e24..7bb83338 100644
--- a/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Double/DenseMatrix.cs
@@ -187,30 +187,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return new DenseVector(size);
}
- ///
- /// Copies the elements of this matrix to the given matrix.
- ///
- ///
- /// The matrix to copy values into.
- ///
- ///
- /// If target is .
- ///
- ///
- /// If this and the target matrix do not have the same dimensions..
- ///
- public override void CopyTo(Matrix target)
- {
- var denseTarget = target as DenseMatrix;
- if (denseTarget != null)
- {
- _storage.CopyTo(denseTarget.Raw);
- return;
- }
-
- base.CopyTo(target);
- }
-
///
/// Creates a matrix that contains the values from the requested sub-matrix.
///
diff --git a/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
index b6613928..b3b6bbe8 100644
--- a/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
@@ -718,44 +718,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
#endregion
- ///
- /// Copies the elements of this matrix to the given matrix.
- ///
- ///
- /// The matrix to copy values into.
- ///
- ///
- /// If target is .
- ///
- ///
- /// If this and the target matrix do not have the same dimensions..
- ///
- public override void CopyTo(Matrix target)
- {
- var diagonalTarget = target as DiagonalMatrix;
- if (diagonalTarget != null)
- {
- _storage.CopyTo(diagonalTarget.Raw);
- return;
- }
-
- var denseTarget = target as DenseMatrix;
- if (denseTarget != null)
- {
- _storage.CopyTo(denseTarget.Raw);
- return;
- }
-
- var sparseTarget = target as SparseMatrix;
- if (sparseTarget != null)
- {
- _storage.CopyTo(sparseTarget.Raw);
- return;
- }
-
- base.CopyTo(target);
- }
-
///
/// Returns the transpose of this matrix.
///
diff --git a/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
index e3971bff..b9323970 100644
--- a/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
@@ -611,37 +611,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return ret;
}
-
- ///
- /// Copies the elements of this matrix to the given matrix.
- ///
- ///
- /// The matrix to copy values into.
- ///
- ///
- /// If target is .
- ///
- ///
- /// If this and the target matrix do not have the same dimensions..
- ///
- public override void CopyTo(Matrix target)
- {
- var sparseTarget = target as SparseMatrix;
- if (sparseTarget != null)
- {
- _storage.CopyTo(sparseTarget.Raw);
- return;
- }
-
- var denseTarget = target as DenseMatrix;
- if (denseTarget != null)
- {
- _storage.CopyTo(denseTarget.Raw);
- return;
- }
-
- base.CopyTo(target);
- }
///
/// Returns a hash code for this instance.
diff --git a/src/Numerics/LinearAlgebra/Generic/Matrix.cs b/src/Numerics/LinearAlgebra/Generic/Matrix.cs
index 55c19cd5..7d6377ab 100644
--- a/src/Numerics/LinearAlgebra/Generic/Matrix.cs
+++ b/src/Numerics/LinearAlgebra/Generic/Matrix.cs
@@ -237,33 +237,25 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
///
/// If this and the target matrix do not have the same dimensions..
///
- public virtual void CopyTo(Matrix target)
+ public void CopyTo(Matrix target)
{
if (target == null)
{
throw new ArgumentNullException("target");
}
- if (RowCount != target.RowCount || ColumnCount != target.ColumnCount)
+ if (ReferenceEquals(this, target) || ReferenceEquals(Storage, target.Storage))
{
- throw DimensionsDontMatch(this, target);
+ return;
}
- if (ReferenceEquals(this, target))
+ if (RowCount != target.RowCount || ColumnCount != target.ColumnCount)
{
- return;
+ var message = string.Format(Resources.ArgumentMatrixDimensions2, RowCount + "x" + ColumnCount, target.RowCount + "x" + target.ColumnCount);
+ throw new ArgumentException(message, "target");
}
- CommonParallel.For(
- 0,
- RowCount,
- row =>
- {
- for (var j = 0; j < ColumnCount; j++)
- {
- target.At(row, j, At(row, j));
- }
- });
+ Storage.CopyTo(target.Storage);
}
///
diff --git a/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs
index 9ead7f02..42d2f8c3 100644
--- a/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs
@@ -187,30 +187,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return new DenseVector(size);
}
- ///
- /// Copies the elements of this matrix to the given matrix.
- ///
- ///
- /// The matrix to copy values into.
- ///
- ///
- /// If target is .
- ///
- ///
- /// If this and the target matrix do not have the same dimensions..
- ///
- public override void CopyTo(Matrix target)
- {
- var denseTarget = target as DenseMatrix;
- if (denseTarget != null)
- {
- _storage.CopyTo(denseTarget.Raw);
- return;
- }
-
- base.CopyTo(target);
- }
-
///
/// Creates a matrix that contains the values from the requested sub-matrix.
///
diff --git a/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
index 3789185e..4b74c7ae 100644
--- a/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
@@ -718,44 +718,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
#endregion
- ///
- /// Copies the elements of this matrix to the given matrix.
- ///
- ///
- /// The matrix to copy values into.
- ///
- ///
- /// If target is .
- ///
- ///
- /// If this and the target matrix do not have the same dimensions..
- ///
- public override void CopyTo(Matrix target)
- {
- var diagonalTarget = target as DiagonalMatrix;
- if (diagonalTarget != null)
- {
- _storage.CopyTo(diagonalTarget.Raw);
- return;
- }
-
- var denseTarget = target as DenseMatrix;
- if (denseTarget != null)
- {
- _storage.CopyTo(denseTarget.Raw);
- return;
- }
-
- var sparseTarget = target as SparseMatrix;
- if (sparseTarget != null)
- {
- _storage.CopyTo(sparseTarget.Raw);
- return;
- }
-
- base.CopyTo(target);
- }
-
///
/// Returns the transpose of this matrix.
///
diff --git a/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs
index 65a5763d..b356c696 100644
--- a/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs
@@ -611,37 +611,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return ret;
}
-
- ///
- /// Copies the elements of this matrix to the given matrix.
- ///
- ///
- /// The matrix to copy values into.
- ///
- ///
- /// If target is .
- ///
- ///
- /// If this and the target matrix do not have the same dimensions..
- ///
- public override void CopyTo(Matrix target)
- {
- var sparseTarget = target as SparseMatrix;
- if (sparseTarget != null)
- {
- _storage.CopyTo(sparseTarget.Raw);
- return;
- }
-
- var denseTarget = target as DenseMatrix;
- if (denseTarget != null)
- {
- _storage.CopyTo(denseTarget.Raw);
- return;
- }
-
- base.CopyTo(target);
- }
///
/// Returns a hash code for this instance.
diff --git a/src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs b/src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs
index a0ee24bc..5907e90d 100644
--- a/src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs
+++ b/src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs
@@ -43,7 +43,8 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
Array.Clear(Data, 0, Data.Length);
}
- public void CopyTo(MatrixStorage target, bool skipClearing = false)
+ /// Parameters assumed to be validated already.
+ public override void CopyTo(MatrixStorage target, bool skipClearing = false)
{
var denseTarget = target as DenseColumnMajorMatrixStorage;
if (denseTarget != null)
@@ -54,22 +55,6 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
// FALL BACK
- if (ReferenceEquals(this, target))
- {
- return;
- }
-
- if (target == null)
- {
- throw new ArgumentNullException("target");
- }
-
- if (RowCount != target.RowCount || ColumnCount != target.ColumnCount)
- {
- var message = string.Format(Resources.ArgumentMatrixDimensions2, RowCount + "x" + ColumnCount, target.RowCount + "x" + target.ColumnCount);
- throw new ArgumentException(message, "target");
- }
-
for (int j = 0, offset = 0; j < ColumnCount; j++, offset += RowCount)
{
for (int i = 0; i < RowCount; i++)
@@ -79,6 +64,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
}
}
+
public void CopyTo(DenseColumnMajorMatrixStorage target)
{
if (ReferenceEquals(this, target))
diff --git a/src/Numerics/LinearAlgebra/Storage/MatrixStorage.cs b/src/Numerics/LinearAlgebra/Storage/MatrixStorage.cs
index 614fbf8c..6c85843a 100644
--- a/src/Numerics/LinearAlgebra/Storage/MatrixStorage.cs
+++ b/src/Numerics/LinearAlgebra/Storage/MatrixStorage.cs
@@ -1,5 +1,6 @@
using System;
using MathNet.Numerics.Properties;
+using MathNet.Numerics.Threading;
namespace MathNet.Numerics.LinearAlgebra.Storage
{
@@ -87,5 +88,17 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
}
}
}
+
+ /// Parameters assumed to be validated already.
+ public virtual void CopyTo(MatrixStorage target, bool skipClearing = false)
+ {
+ for (int j = 0; j < ColumnCount; j++)
+ {
+ for (int i = 0; i < RowCount; i++)
+ {
+ target.At(i, j, At(i, j));
+ }
+ }
+ }
}
}
diff --git a/src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs b/src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs
index a15a9645..75bb574b 100644
--- a/src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs
+++ b/src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs
@@ -217,7 +217,8 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return delta;
}
- public void CopyTo(MatrixStorage target, bool skipClearing = false)
+ /// Parameters assumed to be validated already.
+ public override void CopyTo(MatrixStorage target, bool skipClearing = false)
{
var sparseTarget = target as SparseCompressedRowMatrixStorage;
if (sparseTarget != null)
@@ -235,17 +236,6 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
// FALL BACK
- if (target == null)
- {
- throw new ArgumentNullException("target");
- }
-
- if (RowCount != target.RowCount || ColumnCount != target.ColumnCount)
- {
- var message = string.Format(Resources.ArgumentMatrixDimensions2, RowCount + "x" + ColumnCount, target.RowCount + "x" + target.ColumnCount);
- throw new ArgumentException(message, "target");
- }
-
if (!skipClearing)
{
target.Clear();
diff --git a/src/Numerics/LinearAlgebra/Storage/SparseDiagonalMatrixStorage.cs b/src/Numerics/LinearAlgebra/Storage/SparseDiagonalMatrixStorage.cs
index 39c5f9cf..7d23424d 100644
--- a/src/Numerics/LinearAlgebra/Storage/SparseDiagonalMatrixStorage.cs
+++ b/src/Numerics/LinearAlgebra/Storage/SparseDiagonalMatrixStorage.cs
@@ -53,7 +53,8 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
Array.Clear(Data, 0, Data.Length);
}
- public void CopyTo(MatrixStorage target, bool skipClearing = false)
+ /// Parameters assumed to be validated already.
+ public override void CopyTo(MatrixStorage target, bool skipClearing = false)
{
var diagonalTarget = target as SparseDiagonalMatrixStorage;
if (diagonalTarget != null)
@@ -78,17 +79,6 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
// FALL BACK
- if (target == null)
- {
- throw new ArgumentNullException("target");
- }
-
- if (RowCount != target.RowCount || ColumnCount != target.ColumnCount)
- {
- var message = string.Format(Resources.ArgumentMatrixDimensions2, RowCount + "x" + ColumnCount, target.RowCount + "x" + target.ColumnCount);
- throw new ArgumentException(message, "target");
- }
-
if (!skipClearing)
{
target.Clear();