Browse Source

LA Storage: drop redundant CopyTo overrides

pull/47/head
Christoph Ruegg 14 years ago
parent
commit
4f207c2fc9
  1. 24
      src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
  2. 38
      src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
  3. 31
      src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
  4. 24
      src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
  5. 38
      src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
  6. 31
      src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
  7. 24
      src/Numerics/LinearAlgebra/Double/DenseMatrix.cs
  8. 38
      src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
  9. 31
      src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
  10. 22
      src/Numerics/LinearAlgebra/Generic/Matrix.cs
  11. 24
      src/Numerics/LinearAlgebra/Single/DenseMatrix.cs
  12. 38
      src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
  13. 31
      src/Numerics/LinearAlgebra/Single/SparseMatrix.cs
  14. 20
      src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs
  15. 13
      src/Numerics/LinearAlgebra/Storage/MatrixStorage.cs
  16. 14
      src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs
  17. 14
      src/Numerics/LinearAlgebra/Storage/SparseDiagonalMatrixStorage.cs

24
src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs

@ -187,30 +187,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return new DenseVector(size);
}
/// <summary>
/// Copies the elements of this matrix to the given matrix.
/// </summary>
/// <param name="target">
/// The matrix to copy values into.
/// </param>
/// <exception cref="ArgumentNullException">
/// If target is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// If this and the target matrix do not have the same dimensions..
/// </exception>
public override void CopyTo(Matrix<Complex> target)
{
var denseTarget = target as DenseMatrix;
if (denseTarget != null)
{
_storage.CopyTo(denseTarget.Raw);
return;
}
base.CopyTo(target);
}
/// <summary>
/// Creates a matrix that contains the values from the requested sub-matrix.
/// </summary>

38
src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs

@ -724,44 +724,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
#endregion
/// <summary>
/// Copies the elements of this matrix to the given matrix.
/// </summary>
/// <param name="target">
/// The matrix to copy values into.
/// </param>
/// <exception cref="ArgumentNullException">
/// If target is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// If this and the target matrix do not have the same dimensions..
/// </exception>
public override void CopyTo(Matrix<Complex> 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);
}
/// <summary>
/// Returns the transpose of this matrix.
/// </summary>

31
src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs

@ -613,37 +613,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return ret;
}
/// <summary>
/// Copies the elements of this matrix to the given matrix.
/// </summary>
/// <param name="target">
/// The matrix to copy values into.
/// </param>
/// <exception cref="ArgumentNullException">
/// If target is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// If this and the target matrix do not have the same dimensions..
/// </exception>
public override void CopyTo(Matrix<Complex> 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);
}
/// <summary>
/// Returns a hash code for this instance.
/// </summary>

24
src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs

@ -187,30 +187,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return new DenseVector(size);
}
/// <summary>
/// Copies the elements of this matrix to the given matrix.
/// </summary>
/// <param name="target">
/// The matrix to copy values into.
/// </param>
/// <exception cref="ArgumentNullException">
/// If target is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// If this and the target matrix do not have the same dimensions..
/// </exception>
public override void CopyTo(Matrix<Complex32> target)
{
var denseTarget = target as DenseMatrix;
if (denseTarget != null)
{
_storage.CopyTo(denseTarget.Raw);
return;
}
base.CopyTo(target);
}
/// <summary>
/// Creates a matrix that contains the values from the requested sub-matrix.
/// </summary>

38
src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs

@ -724,44 +724,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
#endregion
/// <summary>
/// Copies the elements of this matrix to the given matrix.
/// </summary>
/// <param name="target">
/// The matrix to copy values into.
/// </param>
/// <exception cref="ArgumentNullException">
/// If target is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// If this and the target matrix do not have the same dimensions..
/// </exception>
public override void CopyTo(Matrix<Complex32> 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);
}
/// <summary>
/// Returns the transpose of this matrix.
/// </summary>

31
src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs

@ -613,37 +613,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return ret;
}
/// <summary>
/// Copies the elements of this matrix to the given matrix.
/// </summary>
/// <param name="target">
/// The matrix to copy values into.
/// </param>
/// <exception cref="ArgumentNullException">
/// If target is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// If this and the target matrix do not have the same dimensions..
/// </exception>
public override void CopyTo(Matrix<Complex32> 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);
}
/// <summary>
/// Returns a hash code for this instance.
/// </summary>

24
src/Numerics/LinearAlgebra/Double/DenseMatrix.cs

@ -187,30 +187,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return new DenseVector(size);
}
/// <summary>
/// Copies the elements of this matrix to the given matrix.
/// </summary>
/// <param name="target">
/// The matrix to copy values into.
/// </param>
/// <exception cref="ArgumentNullException">
/// If target is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// If this and the target matrix do not have the same dimensions..
/// </exception>
public override void CopyTo(Matrix<double> target)
{
var denseTarget = target as DenseMatrix;
if (denseTarget != null)
{
_storage.CopyTo(denseTarget.Raw);
return;
}
base.CopyTo(target);
}
/// <summary>
/// Creates a matrix that contains the values from the requested sub-matrix.
/// </summary>

38
src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs

@ -718,44 +718,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
#endregion
/// <summary>
/// Copies the elements of this matrix to the given matrix.
/// </summary>
/// <param name="target">
/// The matrix to copy values into.
/// </param>
/// <exception cref="ArgumentNullException">
/// If target is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// If this and the target matrix do not have the same dimensions..
/// </exception>
public override void CopyTo(Matrix<double> 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);
}
/// <summary>
/// Returns the transpose of this matrix.
/// </summary>

31
src/Numerics/LinearAlgebra/Double/SparseMatrix.cs

@ -611,37 +611,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return ret;
}
/// <summary>
/// Copies the elements of this matrix to the given matrix.
/// </summary>
/// <param name="target">
/// The matrix to copy values into.
/// </param>
/// <exception cref="ArgumentNullException">
/// If target is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// If this and the target matrix do not have the same dimensions..
/// </exception>
public override void CopyTo(Matrix<double> 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);
}
/// <summary>
/// Returns a hash code for this instance.

22
src/Numerics/LinearAlgebra/Generic/Matrix.cs

@ -237,33 +237,25 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <exception cref="ArgumentException">
/// If this and the target matrix do not have the same dimensions..
/// </exception>
public virtual void CopyTo(Matrix<T> target)
public void CopyTo(Matrix<T> 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<ArgumentException>(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);
}
/// <summary>

24
src/Numerics/LinearAlgebra/Single/DenseMatrix.cs

@ -187,30 +187,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return new DenseVector(size);
}
/// <summary>
/// Copies the elements of this matrix to the given matrix.
/// </summary>
/// <param name="target">
/// The matrix to copy values into.
/// </param>
/// <exception cref="ArgumentNullException">
/// If target is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// If this and the target matrix do not have the same dimensions..
/// </exception>
public override void CopyTo(Matrix<float> target)
{
var denseTarget = target as DenseMatrix;
if (denseTarget != null)
{
_storage.CopyTo(denseTarget.Raw);
return;
}
base.CopyTo(target);
}
/// <summary>
/// Creates a matrix that contains the values from the requested sub-matrix.
/// </summary>

38
src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs

@ -718,44 +718,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
#endregion
/// <summary>
/// Copies the elements of this matrix to the given matrix.
/// </summary>
/// <param name="target">
/// The matrix to copy values into.
/// </param>
/// <exception cref="ArgumentNullException">
/// If target is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// If this and the target matrix do not have the same dimensions..
/// </exception>
public override void CopyTo(Matrix<float> 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);
}
/// <summary>
/// Returns the transpose of this matrix.
/// </summary>

31
src/Numerics/LinearAlgebra/Single/SparseMatrix.cs

@ -611,37 +611,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return ret;
}
/// <summary>
/// Copies the elements of this matrix to the given matrix.
/// </summary>
/// <param name="target">
/// The matrix to copy values into.
/// </param>
/// <exception cref="ArgumentNullException">
/// If target is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentException">
/// If this and the target matrix do not have the same dimensions..
/// </exception>
public override void CopyTo(Matrix<float> 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);
}
/// <summary>
/// Returns a hash code for this instance.

20
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<T> target, bool skipClearing = false)
/// <remarks>Parameters assumed to be validated already.</remarks>
public override void CopyTo(MatrixStorage<T> target, bool skipClearing = false)
{
var denseTarget = target as DenseColumnMajorMatrixStorage<T>;
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<T> target)
{
if (ReferenceEquals(this, target))

13
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
}
}
}
/// <remarks>Parameters assumed to be validated already.</remarks>
public virtual void CopyTo(MatrixStorage<T> 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));
}
}
}
}
}

14
src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs

@ -217,7 +217,8 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return delta;
}
public void CopyTo(MatrixStorage<T> target, bool skipClearing = false)
/// <remarks>Parameters assumed to be validated already.</remarks>
public override void CopyTo(MatrixStorage<T> target, bool skipClearing = false)
{
var sparseTarget = target as SparseCompressedRowMatrixStorage<T>;
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();

14
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<T> target, bool skipClearing = false)
/// <remarks>Parameters assumed to be validated already.</remarks>
public override void CopyTo(MatrixStorage<T> target, bool skipClearing = false)
{
var diagonalTarget = target as SparseDiagonalMatrixStorage<T>;
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();

Loading…
Cancel
Save