Browse Source

native: finished matrix norms

pull/36/head
Marcus Cuda 16 years ago
parent
commit
07162fb76f
  1. 19
      src/MSUnitTests/LinearAlgebraProviderTests/Double/LinearAlgebraProviderTests.cs
  2. 4
      src/NativeWrappers/.gitignore
  3. 20
      src/NativeWrappers/MKL/lapack.cpp
  4. 22
      src/NativeWrappers/Windows/Local.testsettings
  5. 22
      src/NativeWrappers/Windows/MKLWrapper32Tests/MKLWrapper32Tests.csproj
  6. 27
      src/NativeWrappers/Windows/MKLWrapper64Tests/MKLWrapper64Tests.csproj
  7. 8
      src/NativeWrappers/Windows/NativeWrappers.sln
  8. 24
      src/NativeWrappers/Windows/TraceAndTestImpact.testsettings
  9. 8
      src/Numerics/Algorithms/LinearAlgebra/native.common.include
  10. 8
      src/Numerics/Algorithms/LinearAlgebra/safe.native.common.include

19
src/MSUnitTests/LinearAlgebraProviderTests/Double/LinearAlgebraProviderTests.cs

@ -187,7 +187,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double
var matrix = _matrices["Square3x3"];
var work = new double[matrix.RowCount];
var norm = Provider.MatrixNorm(Norm.OneNorm, matrix.RowCount, matrix.ColumnCount, matrix.Data, work);
Assert.AreEqual(1.1, norm);
AssertHelpers.AlmostEqual(12.1, norm, 6);
}
/// <summary>
@ -196,6 +196,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double
[TestMethod]
public void CanComputeMatrixFrobeniusNorm()
{
var matrix = _matrices["Square3x3"];
var work = new double[matrix.RowCount];
var norm = Provider.MatrixNorm(Norm.FrobeniusNorm, matrix.RowCount, matrix.ColumnCount, matrix.Data, work);
AssertHelpers.AlmostEqual(10.777754868246, norm, 8);
}
/// <summary>
@ -204,6 +208,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double
[TestMethod]
public void CanComputeMatrixInfinityNorm()
{
var matrix = _matrices["Square3x3"];
var work = new double[matrix.RowCount];
var norm = Provider.MatrixNorm(Norm.InfinityNorm, matrix.RowCount, matrix.ColumnCount, matrix.Data, work);
Assert.AreEqual(16.5, norm);
}
/// <summary>
@ -212,6 +220,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double
[TestMethod]
public void CanComputeMatrixL1NormWithWorkArray()
{
var matrix = _matrices["Square3x3"];
var norm = Provider.MatrixNorm(Norm.OneNorm, matrix.RowCount, matrix.ColumnCount, matrix.Data);
AssertHelpers.AlmostEqual(12.1, norm, 6);
}
/// <summary>
@ -220,6 +231,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double
[TestMethod]
public void CanComputeMatrixFrobeniusNormWithWorkArray()
{
var matrix = _matrices["Square3x3"];
var norm = Provider.MatrixNorm(Norm.FrobeniusNorm, matrix.RowCount, matrix.ColumnCount, matrix.Data);
AssertHelpers.AlmostEqual(10.777754868246, norm, 8);
}
/// <summary>
@ -228,6 +242,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double
[TestMethod]
public void CanComputeMatrixInfinityNormWithWorkArray()
{
var matrix = _matrices["Square3x3"];
var norm = Provider.MatrixNorm(Norm.InfinityNorm, matrix.RowCount, matrix.ColumnCount, matrix.Data);
Assert.AreEqual(16.5, norm);
}
/// <summary>

4
src/NativeWrappers/.gitignore

@ -1,3 +1,5 @@
*.aps
Debug
Release
Release
ipch
*.opensdf

20
src/NativeWrappers/MKL/lapack.cpp

@ -69,4 +69,24 @@ extern "C" {
}
return info;
}
DLLEXPORT float s_matrix_norm(char norm, int m, int n, float a[], float work[])
{
return SLANGE(&norm, &m, &n, a, &m, work);
}
DLLEXPORT double d_matrix_norm(char norm, int m, int n, double a[], double work[])
{
return DLANGE(&norm, &m, &n, a, &m, work);
}
DLLEXPORT float c_matrix_norm(char norm, int m, int n, MKL_Complex8 a[], float work[])
{
return CLANGE(&norm, &m, &n, a, &m, work);
}
DLLEXPORT double z_matrix_norm(char norm, int m, int n, MKL_Complex16 a[], double work[])
{
return ZLANGE(&norm, &m, &n, a, &m, work);
}
}

22
src/NativeWrappers/Windows/Local.testsettings

@ -2,9 +2,25 @@
<TestSettings name="Local" id="466e1bf9-0b4f-4d66-af47-5969229ecf32" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Description>These are default test settings for a local test run.</Description>
<Deployment enabled="false" />
<Execution>
<TestTypeSpecific />
<AgentRule name="Execution Agents">
<Execution hostProcessPlatform="MSIL">
<TestTypeSpecific>
<UnitTestRunConfig testTypeId="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b">
<AssemblyResolution>
<TestDirectory useLoadContext="true" />
</AssemblyResolution>
</UnitTestRunConfig>
<WebTestRunConfiguration testTypeId="4e7599fa-5ecb-43e9-a887-cd63cf72d207">
<Browser name="Internet Explorer 7.0">
<Headers>
<Header name="User-Agent" value="Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)" />
<Header name="Accept" value="*/*" />
<Header name="Accept-Language" value="{{$IEAcceptLanguage}}" />
<Header name="Accept-Encoding" value="GZIP" />
</Headers>
</Browser>
</WebTestRunConfiguration>
</TestTypeSpecific>
<AgentRule name="LocalMachineDefaultRole">
</AgentRule>
</Execution>
</TestSettings>

22
src/NativeWrappers/Windows/MKLWrapper32Tests/MKLWrapper32Tests.csproj

@ -56,16 +56,14 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="MathNet.Numerics">
<HintPath>..\..\..\MSUnitTests\bin\Debug\MathNet.Numerics.dll</HintPath>
</Reference>
<Reference Include="MathNet.Numerics.MSUnitTests">
<HintPath>..\..\..\MSUnitTests\bin\Debug\MathNet.Numerics.MSUnitTests.dll</HintPath>
<HintPath>..\..\..\..\out\debug\Net40\MathNet.Numerics.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
@ -76,6 +74,12 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\MSUnitTests\AssertHelpers.cs">
<Link>AssertHelpers.cs</Link>
</Compile>
<Compile Include="..\..\..\MSUnitTests\LinearAlgebraProviderTests\Double\LinearAlgebraProviderTests.cs">
<Link>LinearAlgebra\Double\LinearAlgebraProviderTests.cs</Link>
</Compile>
<Compile Include="LinearAlgebra\Double\MklLinearAlgebraProviderTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
@ -96,6 +100,16 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Content Include="..\Win32\Debug\libiomp5md.dll">
<Link>libiomp5md.dll</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\Win32\Debug\MathNET.Numerics.MKL.dll">
<Link>MathNET.Numerics.MKL.dll</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

27
src/NativeWrappers/Windows/MKLWrapper64Tests/MKLWrapper64Tests.csproj

@ -41,7 +41,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
<PlatformTarget>AnyCPU</PlatformTarget>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
@ -55,17 +55,16 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="MathNet.Numerics">
<HintPath>..\..\..\MSUnitTests\bin\Debug\MathNet.Numerics.dll</HintPath>
</Reference>
<Reference Include="MathNet.Numerics.MSUnitTests">
<HintPath>..\..\..\MSUnitTests\bin\Debug\MathNet.Numerics.MSUnitTests.dll</HintPath>
<Reference Include="MathNet.Numerics, Version=2010.7.9.1414, Culture=neutral, PublicKeyToken=cd8b63ad3d691a37, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\out\debug\Net40\MathNet.Numerics.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
@ -76,6 +75,12 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\MSUnitTests\AssertHelpers.cs">
<Link>AssertHelpers.cs</Link>
</Compile>
<Compile Include="..\..\..\MSUnitTests\LinearAlgebraProviderTests\Double\LinearAlgebraProviderTests.cs">
<Link>LinearAlgebra\Double\LinearAlgebraProviderTests.cs</Link>
</Compile>
<Compile Include="..\MKLWrapper32Tests\LinearAlgebra\Double\MklLinearAlgebraProviderTests.cs">
<Link>LinearAlgebra\Double\MklLinearAlgebraProviderTests.cs</Link>
</Compile>
@ -98,6 +103,16 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Content Include="..\x64\Debug\libiomp5md.dll">
<Link>libiomp5md.dll</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\x64\Debug\MathNET.Numerics.MKL.dll">
<Link>MathNET.Numerics.MKL.dll</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

8
src/NativeWrappers/Windows/NativeWrappers.sln

@ -19,13 +19,13 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{953422F5-A946-434B-81FD-A5A0AF92AAE1}"
ProjectSection(SolutionItems) = preProject
Local.testsettings = Local.testsettings
NativeWrappers1.vsmdi = NativeWrappers1.vsmdi
NativeWrappers.vsmdi = NativeWrappers.vsmdi
TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings
EndProjectSection
EndProject
Global
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = NativeWrappers1.vsmdi
CategoryFile = NativeWrappers.vsmdi
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -39,8 +39,8 @@ Global
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Debug|Any CPU.ActiveCfg = Debug|x64
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Debug|Mixed Platforms.ActiveCfg = Debug|x64
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Debug|Mixed Platforms.Build.0 = Debug|x64
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Debug|Win32.ActiveCfg = Debug|Win32
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Debug|Win32.Build.0 = Debug|Win32
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Debug|x64.ActiveCfg = Debug|x64

24
src/NativeWrappers/Windows/TraceAndTestImpact.testsettings

@ -1,14 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="Trace and Test Impact" id="f807a470-def4-441b-a830-7c65f8ac1ec3" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Description>These are test settings for Trace and Test Impact.</Description>
<Execution>
<TestTypeSpecific />
<AgentRule name="Execution Agents">
<Execution hostProcessPlatform="MSIL">
<TestTypeSpecific>
<UnitTestRunConfig testTypeId="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b">
<AssemblyResolution>
<TestDirectory useLoadContext="true" />
</AssemblyResolution>
</UnitTestRunConfig>
<WebTestRunConfiguration testTypeId="4e7599fa-5ecb-43e9-a887-cd63cf72d207">
<Browser name="Internet Explorer 7.0">
<Headers>
<Header name="User-Agent" value="Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)" />
<Header name="Accept" value="*/*" />
<Header name="Accept-Language" value="{{$IEAcceptLanguage}}" />
<Header name="Accept-Encoding" value="GZIP" />
</Headers>
</Browser>
</WebTestRunConfiguration>
</TestTypeSpecific>
<AgentRule name="LocalMachineDefaultRole">
<DataCollectors>
<DataCollector uri="datacollector://microsoft/SystemInfo/1.0" assemblyQualifiedName="Microsoft.VisualStudio.TestTools.DataCollection.SystemInfo.SystemInfoDataCollector, Microsoft.VisualStudio.TestTools.DataCollection.SystemInfo, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" friendlyName="System Information">
</DataCollector>
<DataCollector uri="datacollector://microsoft/ActionLog/1.0" assemblyQualifiedName="Microsoft.VisualStudio.TestTools.ManualTest.ActionLog.ActionLogPlugin, Microsoft.VisualStudio.TestTools.ManualTest.ActionLog, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" friendlyName="Actions">
</DataCollector>
<DataCollector uri="datacollector://microsoft/HttpProxy/1.0" assemblyQualifiedName="Microsoft.VisualStudio.TraceCollector.HttpProxyCollector, Microsoft.VisualStudio.TraceCollector, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" friendlyName="ASP.NET Client Proxy for IntelliTrace and Test Impact">
</DataCollector>
<DataCollector uri="datacollector://microsoft/TestImpact/1.0" assemblyQualifiedName="Microsoft.VisualStudio.TraceCollector.TestImpactDataCollector, Microsoft.VisualStudio.TraceCollector, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" friendlyName="Test Impact">

8
src/Numerics/Algorithms/LinearAlgebra/native.common.include

@ -73,7 +73,7 @@
throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows), "work");
}
return SafeNativeMethods.s_norm((byte)norm, rows, columns, matrix, work);
return SafeNativeMethods.s_matrix_norm((byte)norm, rows, columns, matrix, work);
}
/// <summary>
@ -151,7 +151,7 @@
throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows), "work");
}
return SafeNativeMethods.d_norm((byte)norm, rows, columns, matrix, work);
return SafeNativeMethods.d_matrix_norm((byte)norm, rows, columns, matrix, work);
}
/// <summary>
@ -229,7 +229,7 @@
throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows), "work");
}
return SafeNativeMethods.c_norm((byte)norm, rows, columns, matrix, work);
return SafeNativeMethods.c_matrix_norm((byte)norm, rows, columns, matrix, work);
}
/// <summary>
@ -307,5 +307,5 @@
throw new ArgumentException(string.Format(Resources.ArrayTooSmall, rows), "work");
}
return SafeNativeMethods.z_norm((byte)norm, rows, columns, matrix, work);
return SafeNativeMethods.z_matrix_norm((byte)norm, rows, columns, matrix, work);
}

8
src/Numerics/Algorithms/LinearAlgebra/safe.native.common.include

@ -114,15 +114,15 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#= namespaceSuffix #>
internal static extern void z_cholesky_factor(int n, [In, Out] Complex[] a);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern float s_norm(byte norm, int rows, int columns, [In] float[] a, [In, Out] float[] work);
internal static extern float s_matrix_norm(byte norm, int rows, int columns, [In] float[] a, [In, Out] float[] work);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern float d_norm(byte norm, int rows, int columns, [In] double[] a, [In, Out] double[] work);
internal static extern float d_matrix_norm(byte norm, int rows, int columns, [In] double[] a, [In, Out] double[] work);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern float c_norm(byte norm, int rows, int columns, [In] Complex32[] a, [In, Out] float[] work);
internal static extern float c_matrix_norm(byte norm, int rows, int columns, [In] Complex32[] a, [In, Out] float[] work);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern double z_norm(byte norm, int rows, int columns, [In] Complex[] a, [In, Out] double[] work);
internal static extern double z_matrix_norm(byte norm, int rows, int columns, [In] Complex[] a, [In, Out] double[] work);
#endregion LAPACK

Loading…
Cancel
Save