diff --git a/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
index 21499a70..8e1a6e0a 100644
--- a/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
@@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
-// Copyright (c) 2009-2013 Math.NET
+// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@@ -28,13 +28,14 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-using MathNet.Numerics.Distributions;
-using MathNet.Numerics.LinearAlgebra.Storage;
-using MathNet.Numerics.Properties;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
+using MathNet.Numerics.Distributions;
+using MathNet.Numerics.LinearAlgebra.Storage;
+using MathNet.Numerics.Properties;
+using MathNet.Numerics.Threading;
namespace MathNet.Numerics.LinearAlgebra.Complex
{
@@ -279,51 +280,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
}
- ///
- /// Copies the values of the given array to the diagonal.
- ///
- /// The array to copy the values from. The length of the vector should be
- /// Min(Rows, Columns).
- /// If the length of does not
- /// equal Min(Rows, Columns).
- /// For non-square matrices, the elements of are copied to
- /// this[i,i].
- public override void SetDiagonal(Complex[] source)
- {
- if (source.Length != _data.Length)
- {
- throw new ArgumentException(Resources.ArgumentArraysSameLength, "source");
- }
-
- Array.Copy(source, _data, source.Length);
- }
-
- ///
- /// Copies the values of the given to the diagonal.
- ///
- /// The vector to copy the values from. The length of the vector should be
- /// Min(Rows, Columns).
- /// If the length of does not
- /// equal Min(Rows, Columns).
- /// For non-square matrices, the elements of are copied to
- /// this[i,i].
- public override void SetDiagonal(Vector source)
- {
- var denseSource = source as DenseVector;
- if (denseSource == null)
- {
- base.SetDiagonal(source);
- return;
- }
-
- if (_data.Length != denseSource.Values.Length)
- {
- throw new ArgumentException(Resources.ArgumentVectorsSameLength, "source");
- }
-
- Array.Copy(denseSource.Values, _data, denseSource.Values.Length);
- }
-
///
/// Multiplies each element of the matrix by a scalar and places results into the result matrix.
///
@@ -351,11 +307,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
else
{
- if (!ReferenceEquals(this, result))
- {
- CopyTo(diagResult);
- }
-
Control.LinearAlgebraProvider.ScaleArray(scalar, _data, diagResult._data);
}
}
@@ -700,6 +651,61 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
}
}
+ ///
+ /// Divides each element of the matrix by a scalar and places results into the result matrix.
+ ///
+ /// The scalar to divide the matrix with.
+ /// The matrix to store the result of the division.
+ protected override void DoDivide(Complex divisor, Matrix result)
+ {
+ if (divisor == Complex.One)
+ {
+ CopyTo(result);
+ return;
+ }
+
+ var diagResult = result as DiagonalMatrix;
+ if (diagResult != null)
+ {
+ Control.LinearAlgebraProvider.ScaleArray(1.0/divisor, _data, diagResult._data);
+ return;
+ }
+
+ result.Clear();
+ for (int i = 0; i < _data.Length; i++)
+ {
+ result.At(i, i, _data[i]/divisor);
+ }
+ }
+
+ ///
+ /// Divides a scalar by each element of the matrix and stores the result in the result matrix.
+ ///
+ /// The scalar to add.
+ /// The matrix to store the result of the division.
+ protected override void DoDivideByThis(Complex dividend, Matrix result)
+ {
+ var diagResult = result as DiagonalMatrix;
+ if (diagResult != null)
+ {
+ var resultData = diagResult._data;
+ CommonParallel.For(0, _data.Length, 4096, (a, b) =>
+ {
+ for (int i = a; i < b; i++)
+ {
+ resultData[i] = dividend/_data[i];
+ }
+ });
+ return;
+ }
+
+ result.Clear();
+ for (int i = 0; i < _data.Length; i++)
+ {
+ result.At(i, i, dividend/_data[i]);
+ }
+ }
+
///
/// Computes the determinant of this matrix.
///
@@ -725,6 +731,51 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return new DenseVector(_data).Clone();
}
+ ///
+ /// Copies the values of the given array to the diagonal.
+ ///
+ /// The array to copy the values from. The length of the vector should be
+ /// Min(Rows, Columns).
+ /// If the length of does not
+ /// equal Min(Rows, Columns).
+ /// For non-square matrices, the elements of are copied to
+ /// this[i,i].
+ public override void SetDiagonal(Complex[] source)
+ {
+ if (source.Length != _data.Length)
+ {
+ throw new ArgumentException(Resources.ArgumentArraysSameLength, "source");
+ }
+
+ Array.Copy(source, _data, source.Length);
+ }
+
+ ///
+ /// Copies the values of the given to the diagonal.
+ ///
+ /// The vector to copy the values from. The length of the vector should be
+ /// Min(Rows, Columns).
+ /// If the length of does not
+ /// equal Min(Rows, Columns).
+ /// For non-square matrices, the elements of are copied to
+ /// this[i,i].
+ public override void SetDiagonal(Vector source)
+ {
+ var denseSource = source as DenseVector;
+ if (denseSource == null)
+ {
+ base.SetDiagonal(source);
+ return;
+ }
+
+ if (_data.Length != denseSource.Values.Length)
+ {
+ throw new ArgumentException(Resources.ArgumentVectorsSameLength, "source");
+ }
+
+ Array.Copy(denseSource.Values, _data, denseSource.Values.Length);
+ }
+
/// Calculates the induced L1 norm of this matrix.
/// The maximum absolute column sum of the matrix.
public override double L1Norm()
diff --git a/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
index 0e360fac..55f422cd 100644
--- a/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
@@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
-// Copyright (c) 2009-2013 Math.NET
+// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@@ -28,13 +28,14 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-using MathNet.Numerics.Distributions;
-using MathNet.Numerics.LinearAlgebra.Storage;
-using MathNet.Numerics.Properties;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
+using MathNet.Numerics.Distributions;
+using MathNet.Numerics.LinearAlgebra.Storage;
+using MathNet.Numerics.Properties;
+using MathNet.Numerics.Threading;
namespace MathNet.Numerics.LinearAlgebra.Complex32
{
@@ -274,51 +275,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
}
- ///
- /// Copies the values of the given array to the diagonal.
- ///
- /// The array to copy the values from. The length of the vector should be
- /// Min(Rows, Columns).
- /// If the length of does not
- /// equal Min(Rows, Columns).
- /// For non-square matrices, the elements of are copied to
- /// this[i,i].
- public override void SetDiagonal(Complex32[] source)
- {
- if (source.Length != _data.Length)
- {
- throw new ArgumentException(Resources.ArgumentArraysSameLength, "source");
- }
-
- Array.Copy(source, _data, source.Length);
- }
-
- ///
- /// Copies the values of the given to the diagonal.
- ///
- /// The vector to copy the values from. The length of the vector should be
- /// Min(Rows, Columns).
- /// If the length of does not
- /// equal Min(Rows, Columns).
- /// For non-square matrices, the elements of are copied to
- /// this[i,i].
- public override void SetDiagonal(Vector source)
- {
- var denseSource = source as DenseVector;
- if (denseSource == null)
- {
- base.SetDiagonal(source);
- return;
- }
-
- if (_data.Length != denseSource.Values.Length)
- {
- throw new ArgumentException(Resources.ArgumentVectorsSameLength, "source");
- }
-
- Array.Copy(denseSource.Values, _data, denseSource.Values.Length);
- }
-
///
/// Multiplies each element of the matrix by a scalar and places results into the result matrix.
///
@@ -345,11 +301,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
else
{
- if (!ReferenceEquals(this, result))
- {
- CopyTo(diagResult);
- }
-
Control.LinearAlgebraProvider.ScaleArray(scalar, _data, diagResult._data);
}
}
@@ -694,6 +645,61 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
}
}
+ ///
+ /// Divides each element of the matrix by a scalar and places results into the result matrix.
+ ///
+ /// The scalar to divide the matrix with.
+ /// The matrix to store the result of the division.
+ protected override void DoDivide(Complex32 divisor, Matrix result)
+ {
+ if (divisor == Complex32.One)
+ {
+ CopyTo(result);
+ return;
+ }
+
+ var diagResult = result as DiagonalMatrix;
+ if (diagResult != null)
+ {
+ Control.LinearAlgebraProvider.ScaleArray(1.0f/divisor, _data, diagResult._data);
+ return;
+ }
+
+ result.Clear();
+ for (int i = 0; i < _data.Length; i++)
+ {
+ result.At(i, i, _data[i]/divisor);
+ }
+ }
+
+ ///
+ /// Divides a scalar by each element of the matrix and stores the result in the result matrix.
+ ///
+ /// The scalar to add.
+ /// The matrix to store the result of the division.
+ protected override void DoDivideByThis(Complex32 dividend, Matrix result)
+ {
+ var diagResult = result as DiagonalMatrix;
+ if (diagResult != null)
+ {
+ var resultData = diagResult._data;
+ CommonParallel.For(0, _data.Length, 4096, (a, b) =>
+ {
+ for (int i = a; i < b; i++)
+ {
+ resultData[i] = dividend/_data[i];
+ }
+ });
+ return;
+ }
+
+ result.Clear();
+ for (int i = 0; i < _data.Length; i++)
+ {
+ result.At(i, i, dividend/_data[i]);
+ }
+ }
+
///
/// Computes the determinant of this matrix.
///
@@ -719,6 +725,51 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return new DenseVector(_data).Clone();
}
+ ///
+ /// Copies the values of the given array to the diagonal.
+ ///
+ /// The array to copy the values from. The length of the vector should be
+ /// Min(Rows, Columns).
+ /// If the length of does not
+ /// equal Min(Rows, Columns).
+ /// For non-square matrices, the elements of are copied to
+ /// this[i,i].
+ public override void SetDiagonal(Complex32[] source)
+ {
+ if (source.Length != _data.Length)
+ {
+ throw new ArgumentException(Resources.ArgumentArraysSameLength, "source");
+ }
+
+ Array.Copy(source, _data, source.Length);
+ }
+
+ ///
+ /// Copies the values of the given to the diagonal.
+ ///
+ /// The vector to copy the values from. The length of the vector should be
+ /// Min(Rows, Columns).
+ /// If the length of does not
+ /// equal Min(Rows, Columns).
+ /// For non-square matrices, the elements of are copied to
+ /// this[i,i].
+ public override void SetDiagonal(Vector source)
+ {
+ var denseSource = source as DenseVector;
+ if (denseSource == null)
+ {
+ base.SetDiagonal(source);
+ return;
+ }
+
+ if (_data.Length != denseSource.Values.Length)
+ {
+ throw new ArgumentException(Resources.ArgumentVectorsSameLength, "source");
+ }
+
+ Array.Copy(denseSource.Values, _data, denseSource.Values.Length);
+ }
+
/// Calculates the induced L1 norm of this matrix.
/// The maximum absolute column sum of the matrix.
public override double L1Norm()
diff --git a/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
index 052bf3f7..1d809f74 100644
--- a/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
@@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
-// Copyright (c) 2009-2013 Math.NET
+// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@@ -28,14 +28,14 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-using MathNet.Numerics.Distributions;
-using MathNet.Numerics.LinearAlgebra.Storage;
-using MathNet.Numerics.Properties;
-using MathNet.Numerics.Threading;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
+using MathNet.Numerics.Distributions;
+using MathNet.Numerics.LinearAlgebra.Storage;
+using MathNet.Numerics.Properties;
+using MathNet.Numerics.Threading;
namespace MathNet.Numerics.LinearAlgebra.Double
{
@@ -253,51 +253,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
}
- ///
- /// Copies the values of the given array to the diagonal.
- ///
- /// The array to copy the values from. The length of the vector should be
- /// Min(Rows, Columns).
- /// If the length of does not
- /// equal Min(Rows, Columns).
- /// For non-square matrices, the elements of are copied to
- /// this[i,i].
- public override void SetDiagonal(double[] source)
- {
- if (source.Length != _data.Length)
- {
- throw new ArgumentException(Resources.ArgumentArraysSameLength, "source");
- }
-
- Buffer.BlockCopy(source, 0, _data, 0, source.Length * Constants.SizeOfDouble);
- }
-
- ///
- /// Copies the values of the given to the diagonal.
- ///
- /// The vector to copy the values from. The length of the vector should be
- /// Min(Rows, Columns).
- /// If the length of does not
- /// equal Min(Rows, Columns).
- /// For non-square matrices, the elements of are copied to
- /// this[i,i].
- public override void SetDiagonal(Vector source)
- {
- var denseSource = source as DenseVector;
- if (denseSource == null)
- {
- base.SetDiagonal(source);
- return;
- }
-
- if (_data.Length != denseSource.Values.Length)
- {
- throw new ArgumentException(Resources.ArgumentVectorsSameLength, "source");
- }
-
- Buffer.BlockCopy(denseSource.Values, 0, _data, 0, denseSource.Values.Length * Constants.SizeOfDouble);
- }
-
///
/// Multiplies each element of the matrix by a scalar and places results into the result matrix.
///
@@ -325,11 +280,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
else
{
- if (!ReferenceEquals(this, result))
- {
- CopyTo(diagResult);
- }
-
Control.LinearAlgebraProvider.ScaleArray(scalar, _data, diagResult._data);
}
}
@@ -544,6 +494,61 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
}
+ ///
+ /// Divides each element of the matrix by a scalar and places results into the result matrix.
+ ///
+ /// The scalar to divide the matrix with.
+ /// The matrix to store the result of the division.
+ protected override void DoDivide(double divisor, Matrix result)
+ {
+ if (divisor == 1.0)
+ {
+ CopyTo(result);
+ return;
+ }
+
+ var diagResult = result as DiagonalMatrix;
+ if (diagResult != null)
+ {
+ Control.LinearAlgebraProvider.ScaleArray(1.0/divisor, _data, diagResult._data);
+ return;
+ }
+
+ result.Clear();
+ for (int i = 0; i < _data.Length; i++)
+ {
+ result.At(i, i, _data[i]/divisor);
+ }
+ }
+
+ ///
+ /// Divides a scalar by each element of the matrix and stores the result in the result matrix.
+ ///
+ /// The scalar to add.
+ /// The matrix to store the result of the division.
+ protected override void DoDivideByThis(double dividend, Matrix result)
+ {
+ var diagResult = result as DiagonalMatrix;
+ if (diagResult != null)
+ {
+ var resultData = diagResult._data;
+ CommonParallel.For(0, _data.Length, 4096, (a, b) =>
+ {
+ for (int i = a; i < b; i++)
+ {
+ resultData[i] = dividend/_data[i];
+ }
+ });
+ return;
+ }
+
+ result.Clear();
+ for (int i = 0; i < _data.Length; i++)
+ {
+ result.At(i, i, dividend/_data[i]);
+ }
+ }
+
///
/// Computes the determinant of this matrix.
///
@@ -569,6 +574,51 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return new DenseVector(_data).Clone();
}
+ ///
+ /// Copies the values of the given array to the diagonal.
+ ///
+ /// The array to copy the values from. The length of the vector should be
+ /// Min(Rows, Columns).
+ /// If the length of does not
+ /// equal Min(Rows, Columns).
+ /// For non-square matrices, the elements of are copied to
+ /// this[i,i].
+ public override void SetDiagonal(double[] source)
+ {
+ if (source.Length != _data.Length)
+ {
+ throw new ArgumentException(Resources.ArgumentArraysSameLength, "source");
+ }
+
+ Buffer.BlockCopy(source, 0, _data, 0, source.Length * Constants.SizeOfDouble);
+ }
+
+ ///
+ /// Copies the values of the given to the diagonal.
+ ///
+ /// The vector to copy the values from. The length of the vector should be
+ /// Min(Rows, Columns).
+ /// If the length of does not
+ /// equal Min(Rows, Columns).
+ /// For non-square matrices, the elements of are copied to
+ /// this[i,i].
+ public override void SetDiagonal(Vector source)
+ {
+ var denseSource = source as DenseVector;
+ if (denseSource == null)
+ {
+ base.SetDiagonal(source);
+ return;
+ }
+
+ if (_data.Length != denseSource.Values.Length)
+ {
+ throw new ArgumentException(Resources.ArgumentVectorsSameLength, "source");
+ }
+
+ Buffer.BlockCopy(denseSource.Values, 0, _data, 0, denseSource.Values.Length * Constants.SizeOfDouble);
+ }
+
/// Calculates the induced L1 norm of this matrix.
/// The maximum absolute column sum of the matrix.
public override double L1Norm()
diff --git a/src/Numerics/LinearAlgebra/Double/Matrix.cs b/src/Numerics/LinearAlgebra/Double/Matrix.cs
index 086d097a..b4a772c0 100644
--- a/src/Numerics/LinearAlgebra/Double/Matrix.cs
+++ b/src/Numerics/LinearAlgebra/Double/Matrix.cs
@@ -439,7 +439,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
///
/// The vector to multiply with.
/// The result of the multiplication.
- protected override void DoConjugateTransposeThisAndMultiply(Vector rightSide, Vector result)
+ protected override sealed void DoConjugateTransposeThisAndMultiply(Vector rightSide, Vector result)
{
DoTransposeThisAndMultiply(rightSide, result);
}
diff --git a/src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs b/src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs
index 11fe471f..829341ba 100644
--- a/src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs
+++ b/src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs
@@ -745,7 +745,7 @@ namespace MathNet.Numerics.LinearAlgebra
/// The result of the multiplication.
/// If this.Columns != other.ColumnCount.
/// If the result matrix's dimensions are not the this.RowCount x other.RowCount.
- public virtual void TransposeAndMultiply(Matrix other, Matrix result)
+ public void TransposeAndMultiply(Matrix other, Matrix result)
{
if (ColumnCount != other.ColumnCount || result.RowCount != RowCount || result.ColumnCount != other.RowCount)
{
@@ -884,7 +884,7 @@ namespace MathNet.Numerics.LinearAlgebra
/// The result of the multiplication.
/// If this.Columns != other.ColumnCount.
/// If the result matrix's dimensions are not the this.RowCount x other.RowCount.
- public virtual void ConjugateTransposeAndMultiply(Matrix other, Matrix result)
+ public void ConjugateTransposeAndMultiply(Matrix other, Matrix result)
{
if (ColumnCount != other.ColumnCount || result.RowCount != RowCount || result.ColumnCount != other.RowCount)
{
diff --git a/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs b/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
index 8d3ddc46..dcd5056a 100644
--- a/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
@@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
-// Copyright (c) 2009-2013 Math.NET
+// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@@ -28,14 +28,14 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-using MathNet.Numerics.Distributions;
-using MathNet.Numerics.LinearAlgebra.Storage;
-using MathNet.Numerics.Properties;
-using MathNet.Numerics.Threading;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
+using MathNet.Numerics.Distributions;
+using MathNet.Numerics.LinearAlgebra.Storage;
+using MathNet.Numerics.Properties;
+using MathNet.Numerics.Threading;
namespace MathNet.Numerics.LinearAlgebra.Single
{
@@ -253,51 +253,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
}
- ///
- /// Copies the values of the given array to the diagonal.
- ///
- /// The array to copy the values from. The length of the vector should be
- /// Min(Rows, Columns).
- /// If the length of does not
- /// equal Min(Rows, Columns).
- /// For non-square matrices, the elements of are copied to
- /// this[i,i].
- public override void SetDiagonal(float[] source)
- {
- if (source.Length != _data.Length)
- {
- throw new ArgumentException(Resources.ArgumentArraysSameLength, "source");
- }
-
- Buffer.BlockCopy(source, 0, _data, 0, source.Length * Constants.SizeOfFloat);
- }
-
- ///
- /// Copies the values of the given to the diagonal.
- ///
- /// The vector to copy the values from. The length of the vector should be
- /// Min(Rows, Columns).
- /// If the length of does not
- /// equal Min(Rows, Columns).
- /// For non-square matrices, the elements of are copied to
- /// this[i,i].
- public override void SetDiagonal(Vector source)
- {
- var denseSource = source as DenseVector;
- if (denseSource == null)
- {
- base.SetDiagonal(source);
- return;
- }
-
- if (_data.Length != denseSource.Values.Length)
- {
- throw new ArgumentException(Resources.ArgumentVectorsSameLength, "source");
- }
-
- Buffer.BlockCopy(denseSource.Values, 0, _data, 0, denseSource.Values.Length * Constants.SizeOfFloat);
- }
-
///
/// Multiplies each element of the matrix by a scalar and places results into the result matrix.
///
@@ -325,11 +280,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
else
{
- if (!ReferenceEquals(this, result))
- {
- CopyTo(diagResult);
- }
-
Control.LinearAlgebraProvider.ScaleArray(scalar, _data, diagResult._data);
}
}
@@ -544,6 +494,61 @@ namespace MathNet.Numerics.LinearAlgebra.Single
}
}
+ ///
+ /// Divides each element of the matrix by a scalar and places results into the result matrix.
+ ///
+ /// The scalar to divide the matrix with.
+ /// The matrix to store the result of the division.
+ protected override void DoDivide(float divisor, Matrix result)
+ {
+ if (divisor == 1.0f)
+ {
+ CopyTo(result);
+ return;
+ }
+
+ var diagResult = result as DiagonalMatrix;
+ if (diagResult != null)
+ {
+ Control.LinearAlgebraProvider.ScaleArray(1.0f/divisor, _data, diagResult._data);
+ return;
+ }
+
+ result.Clear();
+ for (int i = 0; i < _data.Length; i++)
+ {
+ result.At(i, i, _data[i]/divisor);
+ }
+ }
+
+ ///
+ /// Divides a scalar by each element of the matrix and stores the result in the result matrix.
+ ///
+ /// The scalar to add.
+ /// The matrix to store the result of the division.
+ protected override void DoDivideByThis(float dividend, Matrix result)
+ {
+ var diagResult = result as DiagonalMatrix;
+ if (diagResult != null)
+ {
+ var resultData = diagResult._data;
+ CommonParallel.For(0, _data.Length, 4096, (a, b) =>
+ {
+ for (int i = a; i < b; i++)
+ {
+ resultData[i] = dividend/_data[i];
+ }
+ });
+ return;
+ }
+
+ result.Clear();
+ for (int i = 0; i < _data.Length; i++)
+ {
+ result.At(i, i, dividend/_data[i]);
+ }
+ }
+
///
/// Computes the determinant of this matrix.
///
@@ -569,6 +574,51 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return new DenseVector(_data).Clone();
}
+ ///
+ /// Copies the values of the given array to the diagonal.
+ ///
+ /// The array to copy the values from. The length of the vector should be
+ /// Min(Rows, Columns).
+ /// If the length of does not
+ /// equal Min(Rows, Columns).
+ /// For non-square matrices, the elements of are copied to
+ /// this[i,i].
+ public override void SetDiagonal(float[] source)
+ {
+ if (source.Length != _data.Length)
+ {
+ throw new ArgumentException(Resources.ArgumentArraysSameLength, "source");
+ }
+
+ Buffer.BlockCopy(source, 0, _data, 0, source.Length * Constants.SizeOfFloat);
+ }
+
+ ///
+ /// Copies the values of the given to the diagonal.
+ ///
+ /// The vector to copy the values from. The length of the vector should be
+ /// Min(Rows, Columns).
+ /// If the length of does not
+ /// equal Min(Rows, Columns).
+ /// For non-square matrices, the elements of are copied to
+ /// this[i,i].
+ public override void SetDiagonal(Vector source)
+ {
+ var denseSource = source as DenseVector;
+ if (denseSource == null)
+ {
+ base.SetDiagonal(source);
+ return;
+ }
+
+ if (_data.Length != denseSource.Values.Length)
+ {
+ throw new ArgumentException(Resources.ArgumentVectorsSameLength, "source");
+ }
+
+ Buffer.BlockCopy(denseSource.Values, 0, _data, 0, denseSource.Values.Length * Constants.SizeOfFloat);
+ }
+
/// Calculates the induced L1 norm of this matrix.
/// The maximum absolute column sum of the matrix.
public override double L1Norm()
diff --git a/src/Numerics/LinearAlgebra/Single/Matrix.cs b/src/Numerics/LinearAlgebra/Single/Matrix.cs
index 90e8d408..69ebdb00 100644
--- a/src/Numerics/LinearAlgebra/Single/Matrix.cs
+++ b/src/Numerics/LinearAlgebra/Single/Matrix.cs
@@ -439,7 +439,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
///
/// The vector to multiply with.
/// The result of the multiplication.
- protected override void DoConjugateTransposeThisAndMultiply(Vector rightSide, Vector result)
+ protected override sealed void DoConjugateTransposeThisAndMultiply(Vector rightSide, Vector result)
{
DoTransposeThisAndMultiply(rightSide, result);
}