Browse Source

Providers: drop unused matrix-norm work-array version, simplifications

pull/163/merge
Christoph Ruegg 13 years ago
parent
commit
48d03189be
  1. 1
      src/Numerics/Numerics.csproj
  2. 27
      src/Numerics/Providers/LinearAlgebra/ILinearAlgebraProvider.cs
  3. 17
      src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs
  4. 15
      src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs
  5. 16
      src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs
  6. 17
      src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs
  7. 39
      src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Complex.cs
  8. 39
      src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Complex32.cs
  9. 39
      src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Single.cs
  10. 367
      src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs
  11. 39
      src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.double.cs
  12. 45
      src/UnitTests/LinearAlgebraProviderTests/Complex/LinearAlgebraProviderTests.cs
  13. 43
      src/UnitTests/LinearAlgebraProviderTests/Complex32/LinearAlgebraProviderTests.cs
  14. 45
      src/UnitTests/LinearAlgebraProviderTests/Double/LinearAlgebraProviderTests.cs
  15. 45
      src/UnitTests/LinearAlgebraProviderTests/Single/LinearAlgebraProviderTests.cs

1
src/Numerics/Numerics.csproj

@ -154,7 +154,6 @@
<Compile Include="Providers\LinearAlgebra\ManagedLinearAlgebraProvider.Single.cs" />
<Compile Include="Providers\LinearAlgebra\ILinearAlgebraProvider.cs" />
<Compile Include="Providers\LinearAlgebra\ManagedLinearAlgebraProvider.Double.cs" />
<Compile Include="Providers\LinearAlgebra\Mkl\MklLinearAlgebraProvider.cs" />
<Compile Include="Providers\LinearAlgebra\Mkl\MklLinearAlgebraProvider.Complex.cs" />
<Compile Include="Providers\LinearAlgebra\Mkl\MklLinearAlgebraProvider.Complex32.cs" />
<Compile Include="Providers\LinearAlgebra\Mkl\MklLinearAlgebraProvider.Double.cs" />

27
src/Numerics/Providers/LinearAlgebra/ILinearAlgebraProvider.cs

@ -35,7 +35,6 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
#if !NOSYSNUMERICS
using Complex = System.Numerics.Complex;
#endif
/// <summary>
@ -90,10 +89,10 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
/// Interface to linear algebra algorithms that work off 1-D arrays.
/// </summary>
public interface ILinearAlgebraProvider :
ILinearAlgebraProvider<double, double>,
ILinearAlgebraProvider<float, float>,
ILinearAlgebraProvider<Complex, double>,
ILinearAlgebraProvider<Complex32, float>
ILinearAlgebraProvider<double>,
ILinearAlgebraProvider<float>,
ILinearAlgebraProvider<Complex>,
ILinearAlgebraProvider<Complex32>
{
}
@ -101,10 +100,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
/// Interface to linear algebra algorithms that work off 1-D arrays.
/// </summary>
/// <typeparam name="T">Supported data types are Double, Single, Complex, and Complex32.</typeparam>
/// <typeparam name="TNorm">Supported data types are Double and Single, must correspond to T.</typeparam>
public interface ILinearAlgebraProvider<T, TNorm>
public interface ILinearAlgebraProvider<T>
where T : struct
where TNorm : struct
{
/*/// <summary>
/// Queries the provider for the optimal, workspace block size
@ -203,20 +200,6 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
/// </returns>
double MatrixNorm(Norm norm, int rows, int columns, T[] matrix);
/// <summary>
/// Computes the requested <see cref="Norm"/> of the matrix.
/// </summary>
/// <param name="norm">The type of norm to compute.</param>
/// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param>
/// <param name="matrix">The matrix to compute the norm from.</param>
/// <param name="work">The work array. Only used when <see cref="Norm.InfinityNorm"/>
/// and needs to be have a length of at least M (number of rows of <paramref name="matrix"/>.</param>
/// <returns>
/// The requested <see cref="Norm"/> of the matrix.
/// </returns>
double MatrixNorm(Norm norm, int rows, int columns, T[] matrix, TNorm[] work);
/// <summary>
/// Multiples two matrices. <c>result = x * y</c>
/// </summary>

17
src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs

@ -465,23 +465,6 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
}
}
/// <summary>
/// Computes the requested <see cref="Norm"/> of the matrix.
/// </summary>
/// <param name="norm">The type of norm to compute.</param>
/// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param>
/// <param name="matrix">The matrix to compute the norm from.</param>
/// <param name="work">The work array. Only used when <see cref="Norm.InfinityNorm"/>
/// and needs to be have a length of at least M (number of rows of <paramref name="matrix"/>.</param>
/// <returns>
/// The requested <see cref="Norm"/> of the matrix.
/// </returns>
public virtual double MatrixNorm(Norm norm, int rows, int columns, Complex[] matrix, double[] work)
{
return MatrixNorm(norm, rows, columns, matrix);
}
/// <summary>
/// Multiples two matrices. <c>result = x * y</c>
/// </summary>

15
src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs

@ -462,21 +462,6 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
}
}
/// <summary>
/// Computes the requested <see cref="Norm"/> of the matrix.
/// </summary>
/// <param name="norm">The type of norm to compute.</param>
/// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param>
/// <param name="matrix">The matrix to compute the norm from.</param>
/// <param name="work">The work array. Only used when <see cref="Norm.InfinityNorm"/>
/// and needs to be have a length of at least M (number of rows of <paramref name="matrix"/>.</param>
/// <returns>The requested <see cref="Norm"/> of the matrix.</returns>
public virtual double MatrixNorm(Norm norm, int rows, int columns, Complex32[] matrix, float[] work)
{
return MatrixNorm(norm, rows, columns, matrix);
}
/// <summary>
/// Multiples two matrices. <c>result = x * y</c>
/// </summary>

16
src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs

@ -460,22 +460,6 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
}
}
/// <summary>
/// Computes the requested <see cref="Norm"/> of the matrix.
/// </summary>
/// <param name="norm">The type of norm to compute.</param>
/// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param>
/// <param name="matrix">The matrix to compute the norm from.</param>
/// <param name="work">The work array. Not used in the managed provider.</param>
/// <returns>
/// The requested <see cref="Norm"/> of the matrix.
/// </returns>
public virtual double MatrixNorm(Norm norm, int rows, int columns, double[] matrix, double[] work)
{
return MatrixNorm(norm, rows, columns, matrix);
}
/// <summary>
/// Multiples two matrices. <c>result = x * y</c>
/// </summary>

17
src/Numerics/Providers/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs

@ -460,23 +460,6 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
}
}
/// <summary>
/// Computes the requested <see cref="Norm"/> of the matrix.
/// </summary>
/// <param name="norm">The type of norm to compute.</param>
/// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param>
/// <param name="matrix">The matrix to compute the norm from.</param>
/// <param name="work">The work array. Only used when <see cref="Norm.InfinityNorm"/>
/// and needs to be have a length of at least M (number of rows of <paramref name="matrix"/>.</param>
/// <returns>
/// The requested <see cref="Norm"/> of the matrix.
/// </returns>
public virtual double MatrixNorm(Norm norm, int rows, int columns, float[] matrix, float[] work)
{
return MatrixNorm(norm, rows, columns, matrix);
}
/// <summary>
/// Multiples two matrices. <c>result = x * y</c>
/// </summary>

39
src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Complex.cs

@ -41,8 +41,45 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
/// <summary>
/// Intel's Math Kernel Library (MKL) linear algebra provider.
/// </summary>
public partial class MklLinearAlgebraProvider
public partial class MklLinearAlgebraProvider : ManagedLinearAlgebraProvider
{
/// <summary>
/// Computes the requested <see cref="Norm"/> of the matrix.
/// </summary>
/// <param name="norm">The type of norm to compute.</param>
/// <param name="rows">The number of rows in the matrix.</param>
/// <param name="columns">The number of columns in the matrix.</param>
/// <param name="matrix">The matrix to compute the norm from.</param>
/// <returns>
/// The requested <see cref="Norm"/> of the matrix.
/// </returns>
[SecuritySafeCritical]
public override double MatrixNorm(Norm norm, int rows, int columns, Complex[] matrix)
{
if (matrix == null)
{
throw new ArgumentNullException("matrix");
}
if (rows <= 0)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "rows");
}
if (columns <= 0)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "columns");
}
if (matrix.Length < rows * columns)
{
throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows * columns), "matrix");
}
var work = new double[rows];
return SafeNativeMethods.z_matrix_norm((byte)norm, rows, columns, matrix, work);
}
/// <summary>
/// Computes the dot product of x and y.
/// </summary>

39
src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Complex32.cs

@ -40,8 +40,45 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
/// <summary>
/// Intel's Math Kernel Library (MKL) linear algebra provider.
/// </summary>
public partial class MklLinearAlgebraProvider
public partial class MklLinearAlgebraProvider : ManagedLinearAlgebraProvider
{
/// <summary>
/// Computes the requested <see cref="Norm"/> of the matrix.
/// </summary>
/// <param name="norm">The type of norm to compute.</param>
/// <param name="rows">The number of rows in the matrix.</param>
/// <param name="columns">The number of columns in the matrix.</param>
/// <param name="matrix">The matrix to compute the norm from.</param>
/// <returns>
/// The requested <see cref="Norm"/> of the matrix.
/// </returns>
[SecuritySafeCritical]
public override double MatrixNorm(Norm norm, int rows, int columns, Complex32[] matrix)
{
if (matrix == null)
{
throw new ArgumentNullException("matrix");
}
if (rows <= 0)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "rows");
}
if (columns <= 0)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "columns");
}
if (matrix.Length < rows * columns)
{
throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows * columns), "matrix");
}
var work = new float[rows];
return SafeNativeMethods.c_matrix_norm((byte)norm, rows, columns, matrix, work);
}
/// <summary>
/// Computes the dot product of x and y.
/// </summary>

39
src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Single.cs

@ -41,8 +41,45 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
/// <summary>
/// Intel's Math Kernel Library (MKL) linear algebra provider.
/// </summary>
public partial class MklLinearAlgebraProvider
public partial class MklLinearAlgebraProvider : ManagedLinearAlgebraProvider
{
/// <summary>
/// Computes the requested <see cref="Norm"/> of the matrix.
/// </summary>
/// <param name="norm">The type of norm to compute.</param>
/// <param name="rows">The number of rows in the matrix.</param>
/// <param name="columns">The number of columns in the matrix.</param>
/// <param name="matrix">The matrix to compute the norm from.</param>
/// <returns>
/// The requested <see cref="Norm"/> of the matrix.
/// </returns>
[SecuritySafeCritical]
public override double MatrixNorm(Norm norm, int rows, int columns, float[] matrix)
{
if (matrix == null)
{
throw new ArgumentNullException("matrix");
}
if (rows <= 0)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "rows");
}
if (columns <= 0)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "columns");
}
if (matrix.Length < rows * columns)
{
throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows * columns), "matrix");
}
var work = new float[rows];
return SafeNativeMethods.s_matrix_norm((byte)norm, rows, columns, matrix, work);
}
/// <summary>
/// Computes the dot product of x and y.
/// </summary>

367
src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs

@ -1,367 +0,0 @@
// <copyright file="MklLinearAlgebraProvider.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
#if NATIVEMKL
using MathNet.Numerics.Properties;
using System;
using System.Numerics;
using System.Security;
namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
{
/// <summary>
/// Intel's Math Kernel Library (MKL) linear algebra provider.
/// </summary>
public partial class MklLinearAlgebraProvider : ManagedLinearAlgebraProvider
{
/// <summary>
/// Computes the requested <see cref="Norm"/> of the matrix.
/// </summary>
/// <param name="norm">The type of norm to compute.</param>
/// <param name="rows">The number of rows in the matrix.</param>
/// <param name="columns">The number of columns in the matrix.</param>
/// <param name="matrix">The matrix to compute the norm from.</param>
/// <returns>
/// The requested <see cref="Norm"/> of the matrix.
/// </returns>
[SecuritySafeCritical]
public override double MatrixNorm(Norm norm, int rows, int columns, float[] matrix)
{
if (matrix == null)
{
throw new ArgumentNullException("matrix");
}
if (rows <= 0)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "rows");
}
if (columns <= 0)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "columns");
}
if (matrix.Length < rows*columns)
{
throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows*columns), "matrix");
}
var work = new float[rows];
return MatrixNorm(norm, rows, columns, matrix, work);
}
/// <summary>
/// Computes the requested <see cref="Norm"/> of the matrix.
/// </summary>
/// <param name="norm">The type of norm to compute.</param>
/// <param name="rows">The number of rows in the matrix.</param>
/// <param name="columns">The number of columns in the matrix.</param>
/// <param name="matrix">The matrix to compute the norm from.</param>
/// <param name="work">The work array. Only used when <see cref="Norm.InfinityNorm"/>
/// and needs to be have a length of at least M (number of rows of <paramref name="matrix"/>.</param>
/// <returns>
/// The requested <see cref="Norm"/> of the matrix.
/// </returns>
[SecuritySafeCritical]
public override double MatrixNorm(Norm norm, int rows, int columns, float[] matrix, float[] work)
{
if (matrix == null)
{
throw new ArgumentNullException("matrix");
}
if (rows <= 0)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "rows");
}
if (columns <= 0)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "columns");
}
if (matrix.Length < rows*columns)
{
throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows*columns), "matrix");
}
if (work.Length < rows)
{
throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows), "work");
}
return SafeNativeMethods.s_matrix_norm((byte) norm, rows, columns, matrix, work);
}
/// <summary>
/// Computes the requested <see cref="Norm"/> of the matrix.
/// </summary>
/// <param name="norm">The type of norm to compute.</param>
/// <param name="rows">The number of rows in the matrix.</param>
/// <param name="columns">The number of columns in the matrix.</param>
/// <param name="matrix">The matrix to compute the norm from.</param>
/// <returns>
/// The requested <see cref="Norm"/> of the matrix.
/// </returns>
[SecuritySafeCritical]
public override double MatrixNorm(Norm norm, int rows, int columns, double[] matrix)
{
if (matrix == null)
{
throw new ArgumentNullException("matrix");
}
if (rows <= 0)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "rows");
}
if (columns <= 0)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "columns");
}
if (matrix.Length < rows*columns)
{
throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows*columns), "matrix");
}
var work = new double[rows];
return MatrixNorm(norm, rows, columns, matrix, work);
}
/// <summary>
/// Computes the requested <see cref="Norm"/> of the matrix.
/// </summary>
/// <param name="norm">The type of norm to compute.</param>
/// <param name="rows">The number of rows in the matrix.</param>
/// <param name="columns">The number of columns in the matrix.</param>
/// <param name="matrix">The matrix to compute the norm from.</param>
/// <param name="work">The work array. Only used when <see cref="Norm.InfinityNorm"/>
/// and needs to be have a length of at least M (number of rows of <paramref name="matrix"/>.</param>
/// <returns>
/// The requested <see cref="Norm"/> of the matrix.
/// </returns>
[SecuritySafeCritical]
public override double MatrixNorm(Norm norm, int rows, int columns, double[] matrix, double[] work)
{
if (matrix == null)
{
throw new ArgumentNullException("matrix");
}
if (rows <= 0)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "rows");
}
if (columns <= 0)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "columns");
}
if (matrix.Length < rows*columns)
{
throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows*columns), "matrix");
}
if (work.Length < rows)
{
throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows), "work");
}
return SafeNativeMethods.d_matrix_norm((byte) norm, rows, columns, matrix, work);
}
/// <summary>
/// Computes the requested <see cref="Norm"/> of the matrix.
/// </summary>
/// <param name="norm">The type of norm to compute.</param>
/// <param name="rows">The number of rows in the matrix.</param>
/// <param name="columns">The number of columns in the matrix.</param>
/// <param name="matrix">The matrix to compute the norm from.</param>
/// <returns>
/// The requested <see cref="Norm"/> of the matrix.
/// </returns>
[SecuritySafeCritical]
public override double MatrixNorm(Norm norm, int rows, int columns, Complex32[] matrix)
{
if (matrix == null)
{
throw new ArgumentNullException("matrix");
}
if (rows <= 0)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "rows");
}
if (columns <= 0)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "columns");
}
if (matrix.Length < rows*columns)
{
throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows*columns), "matrix");
}
var work = new float[rows];
return MatrixNorm(norm, rows, columns, matrix, work);
}
/// <summary>
/// Computes the requested <see cref="Norm"/> of the matrix.
/// </summary>
/// <param name="norm">The type of norm to compute.</param>
/// <param name="rows">The number of rows in the matrix.</param>
/// <param name="columns">The number of columns in the matrix.</param>
/// <param name="matrix">The matrix to compute the norm from.</param>
/// <param name="work">The work array. Only used when <see cref="Norm.InfinityNorm"/>
/// and needs to be have a length of at least M (number of rows of <paramref name="matrix"/>.</param>
/// <returns>
/// The requested <see cref="Norm"/> of the matrix.
/// </returns>
[SecuritySafeCritical]
public override double MatrixNorm(Norm norm, int rows, int columns, Complex32[] matrix, float[] work)
{
if (matrix == null)
{
throw new ArgumentNullException("matrix");
}
if (rows <= 0)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "rows");
}
if (columns <= 0)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "columns");
}
if (matrix.Length < rows*columns)
{
throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows*columns), "matrix");
}
if (work.Length < rows)
{
throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows), "work");
}
return SafeNativeMethods.c_matrix_norm((byte) norm, rows, columns, matrix, work);
}
/// <summary>
/// Computes the requested <see cref="Norm"/> of the matrix.
/// </summary>
/// <param name="norm">The type of norm to compute.</param>
/// <param name="rows">The number of rows in the matrix.</param>
/// <param name="columns">The number of columns in the matrix.</param>
/// <param name="matrix">The matrix to compute the norm from.</param>
/// <returns>
/// The requested <see cref="Norm"/> of the matrix.
/// </returns>
[SecuritySafeCritical]
public override double MatrixNorm(Norm norm, int rows, int columns, Complex[] matrix)
{
if (matrix == null)
{
throw new ArgumentNullException("matrix");
}
if (rows <= 0)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "rows");
}
if (columns <= 0)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "columns");
}
if (matrix.Length < rows*columns)
{
throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows*columns), "matrix");
}
var work = new double[rows];
return MatrixNorm(norm, rows, columns, matrix, work);
}
/// <summary>
/// Computes the requested <see cref="Norm"/> of the matrix.
/// </summary>
/// <param name="norm">The type of norm to compute.</param>
/// <param name="rows">The number of rows in the matrix.</param>
/// <param name="columns">The number of columns in the matrix.</param>
/// <param name="matrix">The matrix to compute the norm from.</param>
/// <param name="work">The work array. Only used when <see cref="Norm.InfinityNorm"/>
/// and needs to be have a length of at least M (number of rows of <paramref name="matrix"/>.</param>
/// <returns>
/// The requested <see cref="Norm"/> of the matrix.
/// </returns>
[SecuritySafeCritical]
public override double MatrixNorm(Norm norm, int rows, int columns, Complex[] matrix, double[] work)
{
if (matrix == null)
{
throw new ArgumentNullException("matrix");
}
if (rows <= 0)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "rows");
}
if (columns <= 0)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "columns");
}
if (matrix.Length < rows*columns)
{
throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows*columns), "matrix");
}
if (work.Length < rows)
{
throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows), "work");
}
return SafeNativeMethods.z_matrix_norm((byte) norm, rows, columns, matrix, work);
}
}
}
#endif

39
src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.double.cs

@ -41,8 +41,45 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
/// <summary>
/// Intel's Math Kernel Library (MKL) linear algebra provider.
/// </summary>
public partial class MklLinearAlgebraProvider
public partial class MklLinearAlgebraProvider : ManagedLinearAlgebraProvider
{
/// <summary>
/// Computes the requested <see cref="Norm"/> of the matrix.
/// </summary>
/// <param name="norm">The type of norm to compute.</param>
/// <param name="rows">The number of rows in the matrix.</param>
/// <param name="columns">The number of columns in the matrix.</param>
/// <param name="matrix">The matrix to compute the norm from.</param>
/// <returns>
/// The requested <see cref="Norm"/> of the matrix.
/// </returns>
[SecuritySafeCritical]
public override double MatrixNorm(Norm norm, int rows, int columns, double[] matrix)
{
if (matrix == null)
{
throw new ArgumentNullException("matrix");
}
if (rows <= 0)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "rows");
}
if (columns <= 0)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "columns");
}
if (matrix.Length < rows * columns)
{
throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows * columns), "matrix");
}
var work = new double[rows];
return SafeNativeMethods.d_matrix_norm((byte)norm, rows, columns, matrix, work);
}
/// <summary>
/// Computes the dot product of x and y.
/// </summary>

45
src/UnitTests/LinearAlgebraProviderTests/Complex/LinearAlgebraProviderTests.cs

@ -203,8 +203,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
public void CanComputeMatrixL1Norm()
{
var matrix = _matrices["Square3x3"];
var work = new double[matrix.RowCount];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.OneNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.OneNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values);
AssertHelpers.AlmostEqualRelative(12.1, norm, 6);
}
@ -215,8 +214,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
public void CanComputeMatrixFrobeniusNorm()
{
var matrix = _matrices["Square3x3"];
var work = new double[matrix.RowCount];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.FrobeniusNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.FrobeniusNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values);
AssertHelpers.AlmostEqualRelative(10.777754868246, norm, 8);
}
@ -227,44 +225,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
public void CanComputeMatrixInfinityNorm()
{
var matrix = _matrices["Square3x3"];
var work = new double[matrix.RowCount];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.InfinityNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
Assert.AreEqual(16.5, norm);
}
/// <summary>
/// Can compute L1 norm using a work array.
/// </summary>
[Test]
public void CanComputeMatrixL1NormWithWorkArray()
{
var matrix = _matrices["Square3x3"];
var work = new double[18];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.OneNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
AssertHelpers.AlmostEqualRelative(12.1, norm, 6);
}
/// <summary>
/// Can compute Frobenius norm using a work array.
/// </summary>
[Test]
public void CanComputeMatrixFrobeniusNormWithWorkArray()
{
var matrix = _matrices["Square3x3"];
var work = new double[18];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.FrobeniusNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
AssertHelpers.AlmostEqualRelative(10.777754868246, norm, 8);
}
/// <summary>
/// Can compute Infinity norm using a work array.
/// </summary>
[Test]
public void CanComputeMatrixInfinityNormWithWorkArray()
{
var matrix = _matrices["Square3x3"];
var work = new double[18];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.InfinityNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.InfinityNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values);
Assert.AreEqual(16.5, norm);
}

43
src/UnitTests/LinearAlgebraProviderTests/Complex32/LinearAlgebraProviderTests.cs

@ -199,8 +199,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex32
public void CanComputeMatrixL1Norm()
{
var matrix = _matrices["Square3x3"];
var work = new float[matrix.RowCount];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.OneNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.OneNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values);
AssertHelpers.AlmostEqualRelative(12.1f, norm, 5);
}
@ -211,8 +210,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex32
public void CanComputeMatrixFrobeniusNorm()
{
var matrix = _matrices["Square3x3"];
var work = new float[matrix.RowCount];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.FrobeniusNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.FrobeniusNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values);
AssertHelpers.AlmostEqualRelative(10.777754868246f, norm, 5);
}
@ -223,43 +221,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex32
public void CanComputeMatrixInfinityNorm()
{
var matrix = _matrices["Square3x3"];
var work = new float[matrix.RowCount];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.InfinityNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
Assert.AreEqual(16.5, norm);
}
/// <summary>
/// Can compute L1 norm using a work array.
/// </summary>
[Test]
public void CanComputeMatrixL1NormWithWorkArray()
{
var matrix = _matrices["Square3x3"];
var work = new float[18];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.OneNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
AssertHelpers.AlmostEqualRelative(12.1f, norm, 5);
}
/// <summary>
/// Can compute Frobenius norm using a work array.
/// </summary>
[Test]
public void CanComputeMatrixFrobeniusNormWithWorkArray()
{
var matrix = _matrices["Square3x3"];
var work = new float[18];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.FrobeniusNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
AssertHelpers.AlmostEqualRelative(10.777754868246f, norm, 5);
}
/// <summary>
/// Can compute Infinity norm using a work array.
/// </summary>
[Test]
public void CanComputeMatrixInfinityNormWithWorkArray()
{
var matrix = _matrices["Square3x3"];
var work = new float[18];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.InfinityNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values);
Assert.AreEqual(16.5, norm);
}

45
src/UnitTests/LinearAlgebraProviderTests/Double/LinearAlgebraProviderTests.cs

@ -197,8 +197,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double
public void CanComputeMatrixL1Norm()
{
var matrix = _matrices["Square3x3"];
var work = new double[matrix.RowCount];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.OneNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.OneNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values);
AssertHelpers.AlmostEqualRelative(12.1, norm, 6);
}
@ -209,8 +208,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double
public void CanComputeMatrixFrobeniusNorm()
{
var matrix = _matrices["Square3x3"];
var work = new double[matrix.RowCount];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.FrobeniusNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.FrobeniusNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values);
AssertHelpers.AlmostEqualRelative(10.777754868246, norm, 8);
}
@ -221,44 +219,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double
public void CanComputeMatrixInfinityNorm()
{
var matrix = _matrices["Square3x3"];
var work = new double[matrix.RowCount];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.InfinityNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
Assert.AreEqual(16.5, norm);
}
/// <summary>
/// Can compute L1 norm using a work array.
/// </summary>
[Test]
public void CanComputeMatrixL1NormWithWorkArray()
{
var matrix = _matrices["Square3x3"];
var work = new double[18];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.OneNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
AssertHelpers.AlmostEqualRelative(12.1, norm, 6);
}
/// <summary>
/// Can compute Frobenius norm using a work array.
/// </summary>
[Test]
public void CanComputeMatrixFrobeniusNormWithWorkArray()
{
var matrix = _matrices["Square3x3"];
var work = new double[18];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.FrobeniusNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
AssertHelpers.AlmostEqualRelative(10.777754868246, norm, 8);
}
/// <summary>
/// Can compute Infinity norm using a work array.
/// </summary>
[Test]
public void CanComputeMatrixInfinityNormWithWorkArray()
{
var matrix = _matrices["Square3x3"];
var work = new double[18];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.InfinityNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.InfinityNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values);
Assert.AreEqual(16.5, norm);
}

45
src/UnitTests/LinearAlgebraProviderTests/Single/LinearAlgebraProviderTests.cs

@ -197,8 +197,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Single
public void CanComputeMatrixL1Norm()
{
var matrix = _matrices["Square3x3"];
var work = new float[matrix.RowCount];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.OneNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.OneNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values);
AssertHelpers.AlmostEqualRelative(12.1, norm, 5);
}
@ -209,8 +208,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Single
public void CanComputeMatrixFrobeniusNorm()
{
var matrix = _matrices["Square3x3"];
var work = new float[matrix.RowCount];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.FrobeniusNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.FrobeniusNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values);
AssertHelpers.AlmostEqual(10.777754868246, norm, 5);
}
@ -221,44 +219,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Single
public void CanComputeMatrixInfinityNorm()
{
var matrix = _matrices["Square3x3"];
var work = new float[matrix.RowCount];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.InfinityNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
Assert.AreEqual(16.5, norm);
}
/// <summary>
/// Can compute L1 norm using a work array.
/// </summary>
[Test]
public void CanComputeMatrixL1NormWithWorkArray()
{
var matrix = _matrices["Square3x3"];
var work = new float[18];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.OneNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
AssertHelpers.AlmostEqualRelative(12.1, norm, 5);
}
/// <summary>
/// Can compute Frobenius norm using a work array.
/// </summary>
[Test]
public void CanComputeMatrixFrobeniusNormWithWorkArray()
{
var matrix = _matrices["Square3x3"];
var work = new float[18];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.FrobeniusNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
AssertHelpers.AlmostEqual(10.777754868246, norm, 5);
}
/// <summary>
/// Can compute Infinity norm using a work array.
/// </summary>
[Test]
public void CanComputeMatrixInfinityNormWithWorkArray()
{
var matrix = _matrices["Square3x3"];
var work = new float[18];
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.InfinityNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values, work);
var norm = Control.LinearAlgebraProvider.MatrixNorm(Norm.InfinityNorm, matrix.RowCount, matrix.ColumnCount, matrix.Values);
Assert.AreEqual(16.5, norm);
}

Loading…
Cancel
Save