diff --git a/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
index 4648158e..f37efa12 100644
--- a/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex/DenseMatrix.cs
@@ -28,6 +28,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
{
using System;
using System.Numerics;
+ using Algorithms.LinearAlgebra;
using Generic;
using Properties;
using Threading;
@@ -222,55 +223,21 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// The L1 norm of the matrix.
public override Complex L1Norm()
{
- var norm = 0.0;
- for (var j = 0; j < ColumnCount; j++)
- {
- var s = 0.0;
- for (var i = 0; i < RowCount; i++)
- {
- s += Data[(j * RowCount) + i].Magnitude;
- }
-
- norm = Math.Max(norm, s);
- }
-
- return norm;
+ return Control.LinearAlgebraProvider.MatrixNorm(Norm.OneNorm, RowCount, ColumnCount, Data);
}
/// Calculates the Frobenius norm of this matrix.
/// The Frobenius norm of this matrix.
public override Complex FrobeniusNorm()
{
- var transpose = (DenseMatrix)Transpose();
- var aat = (DenseMatrix)(this * transpose);
-
- var norm = 0.0;
- for (var i = 0; i < RowCount; i++)
- {
- norm += aat.Data[(i * RowCount) + i].Magnitude;
- }
-
- norm = Math.Sqrt(norm);
- return norm;
+ return Control.LinearAlgebraProvider.MatrixNorm(Norm.FrobeniusNorm, RowCount, ColumnCount, Data);
}
/// Calculates the infinity norm of this matrix.
/// The infinity norm of this matrix.
public override Complex InfinityNorm()
{
- var norm = 0.0;
- for (var i = 0; i < RowCount; i++)
- {
- var s = 0.0;
- for (var j = 0; j < ColumnCount; j++)
- {
- s += Data[(j * RowCount) + i].Magnitude;
- }
-
- norm = Math.Max(norm, s);
- }
-
- return norm;
+ return Control.LinearAlgebraProvider.MatrixNorm(Norm.InfinityNorm, RowCount, ColumnCount, Data);
}
#region Elementary operations
diff --git a/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
index bf89b3c5..da8d2a34 100644
--- a/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/DenseMatrix.cs
@@ -27,6 +27,7 @@
namespace MathNet.Numerics.LinearAlgebra.Complex32
{
using System;
+ using Algorithms.LinearAlgebra;
using Generic;
using Numerics;
using Properties;
@@ -222,55 +223,21 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// The L1 norm of the matrix.
public override Complex32 L1Norm()
{
- var norm = 0.0f;
- for (var j = 0; j < ColumnCount; j++)
- {
- var s = 0.0f;
- for (var i = 0; i < RowCount; i++)
- {
- s += Data[(j * RowCount) + i].Magnitude;
- }
-
- norm = Math.Max(norm, s);
- }
-
- return norm;
+ return Control.LinearAlgebraProvider.MatrixNorm(Norm.OneNorm, RowCount, ColumnCount, Data);
}
/// Calculates the Frobenius norm of this matrix.
/// The Frobenius norm of this matrix.
public override Complex32 FrobeniusNorm()
{
- var transpose = (DenseMatrix)Transpose();
- var aat = (DenseMatrix)(this * transpose);
-
- var norm = 0.0f;
- for (var i = 0; i < RowCount; i++)
- {
- norm += aat.Data[(i * RowCount) + i].Magnitude;
- }
-
- norm = Convert.ToSingle(Math.Sqrt(norm));
- return norm;
+ return Control.LinearAlgebraProvider.MatrixNorm(Norm.FrobeniusNorm, RowCount, ColumnCount, Data);
}
/// Calculates the infinity norm of this matrix.
/// The infinity norm of this matrix.
public override Complex32 InfinityNorm()
{
- var norm = 0.0f;
- for (var i = 0; i < RowCount; i++)
- {
- var s = 0.0f;
- for (var j = 0; j < ColumnCount; j++)
- {
- s += Data[(j * RowCount) + i].Magnitude;
- }
-
- norm = Math.Max(norm, s);
- }
-
- return norm;
+ return Control.LinearAlgebraProvider.MatrixNorm(Norm.InfinityNorm, RowCount, ColumnCount, Data);
}
#region Elementary operations
diff --git a/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs b/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs
index 6ff55030..7bc1d3b8 100644
--- a/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Single/DenseMatrix.cs
@@ -27,6 +27,7 @@
namespace MathNet.Numerics.LinearAlgebra.Single
{
using System;
+ using Algorithms.LinearAlgebra;
using Generic;
using Properties;
using Threading;
@@ -221,55 +222,21 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// The L1 norm of the matrix.
public override float L1Norm()
{
- var norm = 0.0f;
- for (var j = 0; j < ColumnCount; j++)
- {
- var s = 0.0f;
- for (var i = 0; i < RowCount; i++)
- {
- s += Math.Abs(Data[(j * RowCount) + i]);
- }
-
- norm = Math.Max(norm, s);
- }
-
- return norm;
+ return Control.LinearAlgebraProvider.MatrixNorm(Norm.OneNorm, RowCount, ColumnCount, Data);
}
/// Calculates the Frobenius norm of this matrix.
/// The Frobenius norm of this matrix.
public override float FrobeniusNorm()
{
- var transpose = (DenseMatrix)Transpose();
- var aat = (DenseMatrix)(this * transpose);
-
- var norm = 0.0f;
- for (var i = 0; i < RowCount; i++)
- {
- norm += Math.Abs(aat.Data[(i * RowCount) + i]);
- }
-
- norm = Convert.ToSingle(Math.Sqrt(norm));
- return norm;
+ return Control.LinearAlgebraProvider.MatrixNorm(Norm.FrobeniusNorm, RowCount, ColumnCount, Data);
}
/// Calculates the infinity norm of this matrix.
/// The infinity norm of this matrix.
public override float InfinityNorm()
{
- var norm = 0.0f;
- for (var i = 0; i < RowCount; i++)
- {
- var s = 0.0f;
- for (var j = 0; j < ColumnCount; j++)
- {
- s += Math.Abs(Data[(j * RowCount) + i]);
- }
-
- norm = Math.Max(norm, s);
- }
-
- return norm;
+ return Control.LinearAlgebraProvider.MatrixNorm(Norm.InfinityNorm, RowCount, ColumnCount, Data);
}
#region Elementary operations