@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
//
// 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
@ -12,8 +14,10 @@
// 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
@ -26,17 +30,12 @@
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
{
using System ;
using System.Collections.Generic ;
using System.Linq ;
using LinearAlgebra.Complex32 ;
using NUnit.Framework ;
using System ;
using System.Collections.Generic ;
using Complex32 = Numerics . Complex32 ;
#if PORTABLE
using Threading ;
#endif
/// <summary>
/// Diagonal matrix tests.
/// </summary>
@ -49,14 +48,14 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
public override void SetupMatrices ( )
{
TestData2D = new Dictionary < string , Complex32 [ , ] >
{
{ "Singular3x3" , new [ , ] { { new Complex32 ( 1.0f , 1 ) , Complex32 . Zero , Complex32 . Zero } , { Complex32 . Zero , Complex32 . Zero , Complex32 . Zero } , { Complex32 . Zero , Complex32 . Zero , new Complex32 ( 3.0f , 1 ) } } } ,
{ "Square3x3" , new [ , ] { { new Complex32 ( - 1.1f , 1 ) , Complex32 . Zero , Complex32 . Zero } , { Complex32 . Zero , new Complex32 ( 1.1f , 1 ) , Complex32 . Zero } , { Complex32 . Zero , Complex32 . Zero , new Complex32 ( 6.6f , 1 ) } } } ,
{ "Square4x4" , new [ , ] { { new Complex32 ( - 1.1f , 1 ) , Complex32 . Zero , Complex32 . Zero , Complex32 . Zero } , { Complex32 . Zero , new Complex32 ( 1.1f , 1 ) , Complex32 . Zero , Complex32 . Zero } , { Complex32 . Zero , Complex32 . Zero , new Complex32 ( 6.2f , 1 ) , Complex32 . Zero } , { Complex32 . Zero , Complex32 . Zero , Complex32 . Zero , new Complex32 ( - 7.7f , 1 ) } } } ,
{ "Singular4x4" , new [ , ] { { new Complex32 ( - 1.1f , 1 ) , Complex32 . Zero , Complex32 . Zero , Complex32 . Zero } , { Complex32 . Zero , new Complex32 ( - 2.2f , 1 ) , Complex32 . Zero , Complex32 . Zero } , { Complex32 . Zero , Complex32 . Zero , Complex32 . Zero , Complex32 . Zero } , { Complex32 . Zero , Complex32 . Zero , Complex32 . Zero , new Complex32 ( - 4.4f , 1 ) } } } ,
{ "Tall3x2" , new [ , ] { { new Complex32 ( - 1.1f , 1 ) , Complex32 . Zero } , { Complex32 . Zero , new Complex32 ( 1.1f , 1 ) } , { Complex32 . Zero , Complex32 . Zero } } } ,
{ "Wide2x3" , new [ , ] { { new Complex32 ( - 1.1f , 1 ) , Complex32 . Zero , Complex32 . Zero } , { Complex32 . Zero , new Complex32 ( 1.1f , 1 ) , Complex32 . Zero } } }
} ;
{
{ "Singular3x3" , new [ , ] { { new Complex32 ( 1.0f , 1 ) , Complex32 . Zero , Complex32 . Zero } , { Complex32 . Zero , Complex32 . Zero , Complex32 . Zero } , { Complex32 . Zero , Complex32 . Zero , new Complex32 ( 3.0f , 1 ) } } } ,
{ "Square3x3" , new [ , ] { { new Complex32 ( - 1.1f , 1 ) , Complex32 . Zero , Complex32 . Zero } , { Complex32 . Zero , new Complex32 ( 1.1f , 1 ) , Complex32 . Zero } , { Complex32 . Zero , Complex32 . Zero , new Complex32 ( 6.6f , 1 ) } } } ,
{ "Square4x4" , new [ , ] { { new Complex32 ( - 1.1f , 1 ) , Complex32 . Zero , Complex32 . Zero , Complex32 . Zero } , { Complex32 . Zero , new Complex32 ( 1.1f , 1 ) , Complex32 . Zero , Complex32 . Zero } , { Complex32 . Zero , Complex32 . Zero , new Complex32 ( 6.2f , 1 ) , Complex32 . Zero } , { Complex32 . Zero , Complex32 . Zero , Complex32 . Zero , new Complex32 ( - 7.7f , 1 ) } } } ,
{ "Singular4x4" , new [ , ] { { new Complex32 ( - 1.1f , 1 ) , Complex32 . Zero , Complex32 . Zero , Complex32 . Zero } , { Complex32 . Zero , new Complex32 ( - 2.2f , 1 ) , Complex32 . Zero , Complex32 . Zero } , { Complex32 . Zero , Complex32 . Zero , Complex32 . Zero , Complex32 . Zero } , { Complex32 . Zero , Complex32 . Zero , Complex32 . Zero , new Complex32 ( - 4.4f , 1 ) } } } ,
{ "Tall3x2" , new [ , ] { { new Complex32 ( - 1.1f , 1 ) , Complex32 . Zero } , { Complex32 . Zero , new Complex32 ( 1.1f , 1 ) } , { Complex32 . Zero , Complex32 . Zero } } } ,
{ "Wide2x3" , new [ , ] { { new Complex32 ( - 1.1f , 1 ) , Complex32 . Zero , Complex32 . Zero } , { Complex32 . Zero , new Complex32 ( 1.1f , 1 ) , Complex32 . Zero } } }
} ;
TestMatrices = new Dictionary < string , Matrix > ( ) ;
foreach ( var name in TestData2D . Keys )
@ -114,13 +113,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
public void CanCreateMatrixFromDiagonalArray ( )
{
var testData = new Dictionary < string , Matrix >
{
{ "Singular3x3" , new DiagonalMatrix ( 3 , 3 , new [ ] { new Complex32 ( 1.0f , 1 ) , Complex32 . Zero , new Complex32 ( 3.0f , 1 ) } ) } ,
{ "Square3x3" , new DiagonalMatrix ( 3 , 3 , new [ ] { new Complex32 ( - 1.1f , 1 ) , new Complex32 ( 1.1f , 1 ) , new Complex32 ( 6.6f , 1 ) } ) } ,
{ "Square4x4" , new DiagonalMatrix ( 4 , 4 , new [ ] { new Complex32 ( - 1.1f , 1 ) , new Complex32 ( 1.1f , 1 ) , new Complex32 ( 6.2f , 1 ) , new Complex32 ( - 7.7f , 1 ) } ) } ,
{ "Tall3x2" , new DiagonalMatrix ( 3 , 2 , new [ ] { new Complex32 ( - 1.1f , 1 ) , new Complex32 ( 1.1f , 1 ) } ) } ,
{ "Wide2x3" , new DiagonalMatrix ( 2 , 3 , new [ ] { new Complex32 ( - 1.1f , 1 ) , new Complex32 ( 1.1f , 1 ) } ) } ,
} ;
{
{ "Singular3x3" , new DiagonalMatrix ( 3 , 3 , new [ ] { new Complex32 ( 1.0f , 1 ) , Complex32 . Zero , new Complex32 ( 3.0f , 1 ) } ) } ,
{ "Square3x3" , new DiagonalMatrix ( 3 , 3 , new [ ] { new Complex32 ( - 1.1f , 1 ) , new Complex32 ( 1.1f , 1 ) , new Complex32 ( 6.6f , 1 ) } ) } ,
{ "Square4x4" , new DiagonalMatrix ( 4 , 4 , new [ ] { new Complex32 ( - 1.1f , 1 ) , new Complex32 ( 1.1f , 1 ) , new Complex32 ( 6.2f , 1 ) , new Complex32 ( - 7.7f , 1 ) } ) } ,
{ "Tall3x2" , new DiagonalMatrix ( 3 , 2 , new [ ] { new Complex32 ( - 1.1f , 1 ) , new Complex32 ( 1.1f , 1 ) } ) } ,
{ "Wide2x3" , new DiagonalMatrix ( 2 , 3 , new [ ] { new Complex32 ( - 1.1f , 1 ) , new Complex32 ( 1.1f , 1 ) } ) } ,
} ;
foreach ( var name in testData . Keys )
{
@ -134,7 +133,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
[Test]
public void MatrixFrom1DArrayIsReference ( )
{
var data = new [ ] { new Complex32 ( 1.0f , 1 ) , new Complex32 ( 2.0f , 1 ) , new Complex32 ( 3.0f , 1 ) , new Complex32 ( 4.0f , 1 ) , new Complex32 ( 5.0f , 1 ) } ;
var data = new [ ] { new Complex32 ( 1.0f , 1 ) , new Complex32 ( 2.0f , 1 ) , new Complex32 ( 3.0f , 1 ) , new Complex32 ( 4.0f , 1 ) , new Complex32 ( 5.0f , 1 ) } ;
var matrix = new DiagonalMatrix ( 5 , 5 , data ) ;
matrix [ 0 , 0 ] = new Complex32 ( 1 0.0f , 1 ) ;
Assert . AreEqual ( new Complex32 ( 1 0.0f , 1 ) , data [ 0 ] ) ;
@ -221,7 +220,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
{
for ( var j = 0 ; j < matrixC . ColumnCount ; j + + )
{
AssertHelpers . AlmostEqual ( matrixA . Row ( i ) * matrixB . Column ( j ) , matrixC [ i , j ] , 1 5 ) ;
AssertHelpers . AlmostEqual ( matrixA . Row ( i ) * matrixB . Column ( j ) , matrixC [ i , j ] , 1 5 ) ;
}
}
}
@ -233,7 +232,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
public void PermuteMatrixRowsThrowsInvalidOperationException ( )
{
var matrixp = CreateMatrix ( TestData2D [ "Singular3x3" ] ) ;
var permutation = new Permutation ( new [ ] { 2 , 0 , 1 } ) ;
var permutation = new Permutation ( new [ ] { 2 , 0 , 1 } ) ;
Assert . Throws < InvalidOperationException > ( ( ) = > matrixp . PermuteRows ( permutation ) ) ;
}
@ -244,7 +243,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
public void PermuteMatrixColumnsThrowsInvalidOperationException ( )
{
var matrixp = CreateMatrix ( TestData2D [ "Singular3x3" ] ) ;
var permutation = new Permutation ( new [ ] { 2 , 0 , 1 } ) ;
var permutation = new Permutation ( new [ ] { 2 , 0 , 1 } ) ;
Assert . Throws < InvalidOperationException > ( ( ) = > matrixp . PermuteColumns ( permutation ) ) ;
}
@ -261,13 +260,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
var min = Math . Min ( data . RowCount , data . ColumnCount ) ;
for ( var i = 0 ; i < min ; i + + )
{
Assert . AreEqual ( data [ i , i ] / other [ i , i ] , result [ i , i ] ) ;
Assert . AreEqual ( data [ i , i ] / other [ i , i ] , result [ i , i ] ) ;
}
result = data . PointwiseDivide ( other ) ;
for ( var i = 0 ; i < min ; i + + )
{
Assert . AreEqual ( data [ i , i ] / other [ i , i ] , result [ i , i ] ) ;
Assert . AreEqual ( data [ i , i ] / other [ i , i ] , result [ i , i ] ) ;
}
}
}
@ -278,15 +277,15 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
public override void CanComputeFrobeniusNorm ( )
{
var matrix = TestMatrices [ "Square3x3" ] ;
var denseMatrix = new DenseMatrix ( TestData2D [ "Square3x3" ] ) ;
var denseMatrix = DenseMatrix . OfArray ( TestData2D [ "Square3x3" ] ) ;
AssertHelpers . AlmostEqual ( denseMatrix . FrobeniusNorm ( ) , matrix . FrobeniusNorm ( ) , 1 4 ) ;
matrix = TestMatrices [ "Wide2x3" ] ;
denseMatrix = new DenseMatrix ( TestData2D [ "Wide2x3" ] ) ;
denseMatrix = DenseMatrix . OfArray ( TestData2D [ "Wide2x3" ] ) ;
AssertHelpers . AlmostEqual ( denseMatrix . FrobeniusNorm ( ) , matrix . FrobeniusNorm ( ) , 1 4 ) ;
matrix = TestMatrices [ "Tall3x2" ] ;
denseMatrix = new DenseMatrix ( TestData2D [ "Tall3x2" ] ) ;
denseMatrix = DenseMatrix . OfArray ( TestData2D [ "Tall3x2" ] ) ;
AssertHelpers . AlmostEqual ( denseMatrix . FrobeniusNorm ( ) , matrix . FrobeniusNorm ( ) , 1 4 ) ;
}
@ -296,15 +295,15 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
public override void CanComputeInfinityNorm ( )
{
var matrix = TestMatrices [ "Square3x3" ] ;
var denseMatrix = new DenseMatrix ( TestData2D [ "Square3x3" ] ) ;
var denseMatrix = DenseMatrix . OfArray ( TestData2D [ "Square3x3" ] ) ;
AssertHelpers . AlmostEqual ( denseMatrix . InfinityNorm ( ) , matrix . InfinityNorm ( ) , 1 4 ) ;
matrix = TestMatrices [ "Wide2x3" ] ;
denseMatrix = new DenseMatrix ( TestData2D [ "Wide2x3" ] ) ;
denseMatrix = DenseMatrix . OfArray ( TestData2D [ "Wide2x3" ] ) ;
AssertHelpers . AlmostEqual ( denseMatrix . InfinityNorm ( ) , matrix . InfinityNorm ( ) , 1 4 ) ;
matrix = TestMatrices [ "Tall3x2" ] ;
denseMatrix = new DenseMatrix ( TestData2D [ "Tall3x2" ] ) ;
denseMatrix = DenseMatrix . OfArray ( TestData2D [ "Tall3x2" ] ) ;
AssertHelpers . AlmostEqual ( denseMatrix . InfinityNorm ( ) , matrix . InfinityNorm ( ) , 1 4 ) ;
}
@ -314,15 +313,15 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
public override void CanComputeL1Norm ( )
{
var matrix = TestMatrices [ "Square3x3" ] ;
var denseMatrix = new DenseMatrix ( TestData2D [ "Square3x3" ] ) ;
var denseMatrix = DenseMatrix . OfArray ( TestData2D [ "Square3x3" ] ) ;
AssertHelpers . AlmostEqual ( denseMatrix . L1Norm ( ) , matrix . L1Norm ( ) , 1 4 ) ;
matrix = TestMatrices [ "Wide2x3" ] ;
denseMatrix = new DenseMatrix ( TestData2D [ "Wide2x3" ] ) ;
denseMatrix = DenseMatrix . OfArray ( TestData2D [ "Wide2x3" ] ) ;
AssertHelpers . AlmostEqual ( denseMatrix . L1Norm ( ) , matrix . L1Norm ( ) , 1 4 ) ;
matrix = TestMatrices [ "Tall3x2" ] ;
denseMatrix = new DenseMatrix ( TestData2D [ "Tall3x2" ] ) ;
denseMatrix = DenseMatrix . OfArray ( TestData2D [ "Tall3x2" ] ) ;
AssertHelpers . AlmostEqual ( denseMatrix . L1Norm ( ) , matrix . L1Norm ( ) , 1 4 ) ;
}
@ -332,15 +331,15 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
public override void CanComputeL2Norm ( )
{
var matrix = TestMatrices [ "Square3x3" ] ;
var denseMatrix = new DenseMatrix ( TestData2D [ "Square3x3" ] ) ;
var denseMatrix = DenseMatrix . OfArray ( TestData2D [ "Square3x3" ] ) ;
AssertHelpers . AlmostEqual ( denseMatrix . L2Norm ( ) , matrix . L2Norm ( ) , 1 4 ) ;
matrix = TestMatrices [ "Wide2x3" ] ;
denseMatrix = new DenseMatrix ( TestData2D [ "Wide2x3" ] ) ;
denseMatrix = DenseMatrix . OfArray ( TestData2D [ "Wide2x3" ] ) ;
AssertHelpers . AlmostEqual ( denseMatrix . L2Norm ( ) , matrix . L2Norm ( ) , 1 4 ) ;
matrix = TestMatrices [ "Tall3x2" ] ;
denseMatrix = new DenseMatrix ( TestData2D [ "Tall3x2" ] ) ;
denseMatrix = DenseMatrix . OfArray ( TestData2D [ "Tall3x2" ] ) ;
AssertHelpers . AlmostEqual ( denseMatrix . L2Norm ( ) , matrix . L2Norm ( ) , 1 4 ) ;
}
@ -351,11 +350,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
public void CanComputeDeterminant ( )
{
var matrix = TestMatrices [ "Square3x3" ] ;
var denseMatrix = new DenseMatrix ( TestData2D [ "Square3x3" ] ) ;
var denseMatrix = DenseMatrix . OfArray ( TestData2D [ "Square3x3" ] ) ;
AssertHelpers . AlmostEqual ( denseMatrix . Determinant ( ) , matrix . Determinant ( ) , 1 4 ) ;
matrix = TestMatrices [ "Square4x4" ] ;
denseMatrix = new DenseMatrix ( TestData2D [ "Square4x4" ] ) ;
denseMatrix = DenseMatrix . OfArray ( TestData2D [ "Square4x4" ] ) ;
AssertHelpers . AlmostEqual ( denseMatrix . Determinant ( ) , matrix . Determinant ( ) , 1 4 ) ;
}