Browse Source

native wrappers: finished wrapping cholesky factor, dot product, and vector add/subtract/pointwisemultiply. Works with MKL, but I'm unable to build ATLAS on Windows 7.

la-knuth
Marcus Cuda 17 years ago
parent
commit
a6a56dfcbc
  1. 2
      src/NativeWrappers/ATLASWrapperTests/LinearAlgebra/Double/AtlasLinearAlgebraProviderTests.cs
  2. 4
      src/NativeWrappers/MKL/MKLWrapper.vcproj
  3. 50
      src/NativeWrappers/MKL/vector_functions.c
  4. 4
      src/NativeWrappers/MKLWrapper32Tests/LinearAlgebra/Double/MklLinearAlgebraProviderTests.cs
  5. 9
      src/NativeWrappers/MKLWrapper32Tests/MKLWrapper32Tests.csproj
  6. 9
      src/NativeWrappers/MKLWrapper64Tests/MKLWrapper64Tests.csproj
  7. 318
      src/Numerics/Algorithms/LinearAlgebra/Atlas/AtlasLinearAlgebraProvider.cs
  8. 22
      src/Numerics/Algorithms/LinearAlgebra/Atlas/SafeNativeMethods.cs
  9. 5
      src/Numerics/Algorithms/LinearAlgebra/Atlas/SafeNativeMethods.tt
  10. 317
      src/Numerics/Algorithms/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs
  11. 61
      src/Numerics/Algorithms/LinearAlgebra/Mkl/SafeNativeMethods.cs
  12. 44
      src/Numerics/Algorithms/LinearAlgebra/Mkl/SafeNativeMethods.tt
  13. 366
      src/Numerics/Algorithms/LinearAlgebra/NativeAlgebraProvider.include
  14. 18
      src/Numerics/Algorithms/LinearAlgebra/SafeNativeMethods.include
  15. 2
      src/UnitTests/LinearAlgebraTests/Double/LinearAlgebraProviderTests.cs

2
src/NativeWrappers/ATLASWrapperTests/LinearAlgebra/Double/AtlasLinearAlgebraProviderTests.cs

@ -8,7 +8,7 @@
[FixtureSetUp]
public void SetUpProvider()
{
Control.LinearAlgebraProvider = new Algorithms.LinearAlgebra.Atlas.AtlasLinearAlgebraProvider();
Provider = new Algorithms.LinearAlgebra.Atlas.AtlasLinearAlgebraProvider();
}
}
}

4
src/NativeWrappers/MKL/MKLWrapper.vcproj

@ -43,7 +43,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;C:\source\mathnet-marcus\src\NativeWrappers\MKL&quot;;&quot;C:\Program Files (x86)\Intel\Compiler\11.1\046\mkl\include&quot;"
AdditionalIncludeDirectories="&quot;C:\source\mathnet-marcus\src\NativeWrappers\Common&quot;;&quot;C:\source\mathnet-marcus\src\NativeWrappers\MKL&quot;;&quot;C:\Program Files (x86)\Intel\Compiler\11.1\046\mkl\include&quot;"
PreprocessorDefinitions="_WINDOWS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
@ -194,7 +194,7 @@
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="&quot;C:\source\mathnet-marcus\src\NativeWrappers\MKL&quot;;&quot;C:\Program Files (x86)\Intel\Compiler\11.1\046\mkl\include&quot;"
AdditionalIncludeDirectories="&quot;C:\source\mathnet-marcus\src\NativeWrappers\Common&quot;;&quot;C:\source\mathnet-marcus\src\NativeWrappers\MKL&quot;;&quot;C:\Program Files (x86)\Intel\Compiler\11.1\046\mkl\include&quot;"
PreprocessorDefinitions="_WINDOWS"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"

50
src/NativeWrappers/MKL/vector_functions.c

@ -1,14 +1,52 @@
#include "mkl_vml.h"
#include "blas.h"
#include "common.h"
DLLEXPORT void d_vector_add( const int n, const double x[], const double y[], double ret[]){
vdAdd( n, x, y, ret );
DLLEXPORT void s_vector_add( const int n, const float x[], const float y[], float result[] ){
vsAdd( n, x, y, result );
}
DLLEXPORT void s_vector_subtract( const int n, const float x[], const float y[], float result[] ){
vsSub( n, x, y, result );
}
DLLEXPORT void s_vector_multiply( const int n, const float x[], const float y[], float result[] ){
vsMul( n, x, y, result );
}
DLLEXPORT void d_vector_add( const int n, const double x[], const double y[], double result[] ){
vdAdd( n, x, y, result );
}
DLLEXPORT void d_vector_subtract( const int n, const double x[], const double y[], double result[] ){
vdSub( n, x, y, result );
}
DLLEXPORT void d_vector_multiply( const int n, const double x[], const double y[], double result[] ){
vdMul( n, x, y, result );
}
DLLEXPORT void c_vector_add( const int n, const Complex8 x[], const Complex8 y[], Complex8 result[] ){
vcAdd( n, x, y, result );
}
DLLEXPORT void c_vector_subtract( const int n, const Complex8 x[], const Complex8 y[], Complex8 result[] ){
vcSub( n, x, y, result );
}
DLLEXPORT void c_vector_multiply( const int n, const Complex8 x[], const Complex8 y[], Complex8 result[] ){
vcMul( n, x, y, result );
}
DLLEXPORT void z_vector_add( const int n, const Complex16 x[], const Complex16 y[], Complex16 result[] ){
vzAdd( n, x, y, result );
}
DLLEXPORT void d_vector_subtract( const int n, const double x[], const double y[], double ret[]){
vdSub( n, x, y, ret );
DLLEXPORT void z_vector_subtract( const int n, const Complex16 x[], const Complex16 y[], Complex16 result[] ){
vzSub( n, x, y, result );
}
DLLEXPORT void d_vector_multiply( const int n, const double x[], const double y[], double ret[]){
vdMul( n, x, y, ret );
DLLEXPORT void z_vector_multiply( const int n, const Complex16 x[], const Complex16 y[], Complex16 result[] ){
vzMul( n, x, y, result );
}

4
src/NativeWrappers/MKLWrapper32Tests/LinearAlgebra/Double/MklLinearAlgebraProviderTests.cs

@ -1,4 +1,4 @@
namespace MathNet.Numerics.MKLWrapperTests.LinearAlgebra.Double
namespace MathNet.Numerics.MklWrapperTests.LinearAlgebra.Double
{
using MbUnit.Framework;
using UnitTests.LinearAlgebraTests.Double;
@ -8,7 +8,7 @@
[FixtureSetUp]
public void SetUpProvider()
{
Control.LinearAlgebraProvider = new Algorithms.LinearAlgebra.Mkl.MklLinearAlgebraProvider();
Provider = new Algorithms.LinearAlgebra.Mkl.MklLinearAlgebraProvider();
}
}
}

9
src/NativeWrappers/MKLWrapper32Tests/MKLWrapper32Tests.csproj

@ -30,15 +30,16 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="Gallio, Version=3.0.6.0, Culture=neutral, PublicKeyToken=eb9cfa67ee6ab36e, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\UnitTests\bin\Debug\Gallio.dll</HintPath>
</Reference>
<Reference Include="MathNet.Numerics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cd8b63ad3d691a37, processorArchitecture=MSIL">
<Reference Include="MathNet.Numerics, Version=2010.1.26.439, Culture=neutral, PublicKeyToken=cd8b63ad3d691a37, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\UnitTests\bin\Debug\MathNet.Numerics.dll</HintPath>
<HintPath>..\..\Numerics\bin\Debug\MathNet.Numerics.dll</HintPath>
</Reference>
<Reference Include="MathNet.Numerics.UnitTests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cd8b63ad3d691a37, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@ -72,11 +73,11 @@
<ItemGroup>
<Content Include="..\Win32\Release\libiomp5md.dll">
<Link>libiomp5md.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\Win32\Release\MathNET.Numerics.MKL.dll">
<Link>MathNET.Numerics.MKL.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

9
src/NativeWrappers/MKLWrapper64Tests/MKLWrapper64Tests.csproj

@ -30,6 +30,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="Gallio, Version=3.0.6.0, Culture=neutral, PublicKeyToken=eb9cfa67ee6ab36e, processorArchitecture=MSIL">
@ -40,9 +41,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\UnitTests\bin\Debug\Gallio35.dll</HintPath>
</Reference>
<Reference Include="MathNet.Numerics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cd8b63ad3d691a37, processorArchitecture=MSIL">
<Reference Include="MathNet.Numerics, Version=2010.1.26.439, Culture=neutral, PublicKeyToken=cd8b63ad3d691a37, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\UnitTests\bin\Debug\MathNet.Numerics.dll</HintPath>
<HintPath>..\..\Numerics\bin\Debug\MathNet.Numerics.dll</HintPath>
</Reference>
<Reference Include="MathNet.Numerics.UnitTests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cd8b63ad3d691a37, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@ -78,11 +79,11 @@
<ItemGroup>
<Content Include="..\x64\Release\libiomp5md.dll">
<Link>libiomp5md.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\x64\Release\MathNET.Numerics.MKL.dll">
<Link>MathNET.Numerics.MKL.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

318
src/Numerics/Algorithms/LinearAlgebra/Atlas/AtlasLinearAlgebraProvider.cs

@ -24,7 +24,7 @@
/* This file is automatically generated - do not modify it.
Change NativeLinearAlgebraProvider.include instead.
Last generated on: 1/26/2010 7:19:58 AM
Last generated on: 2/9/2010 12:24:25 PM
*/
namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
{
@ -36,7 +36,9 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
/// </summary>
public class AtlasLinearAlgebraProvider : ILinearAlgebraProvider
{
#region ILinearAlgebraProvider<double> Members
private readonly ILinearAlgebraProvider _managedProvider = new ManagedLinearAlgebraProvider();
#region ILinearAlgebraProvider<double> Members
/// <summary>
/// Adds a scaled vector to another: <c>y += alpha*x</c>.
@ -130,7 +132,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
/// routine.</remarks>
public void AddArrays(double[] x, double[] y, double[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
_managedProvider.AddArrays(x, y, result);
}
/// <summary>
@ -145,7 +167,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
/// routine.</remarks>
public void SubtractArrays(double[] x, double[] y, double[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
_managedProvider.SubtractArrays(x, y, result);
}
/// <summary>
@ -160,7 +202,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
/// routine.</remarks>
public void PointWiseMultiplyArrays(double[] x, double[] y, double[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
_managedProvider.PointWiseMultiplyArrays(x, y, result);
}
/// <summary>
@ -350,7 +412,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
/// <remarks>This is equivalent to the POTRF LAPACK routine.</remarks>
public void CholeskyFactor(double[] a, int order)
{
throw new NotImplementedException();
if (a == null)
{
throw new ArgumentNullException("a");
}
if ( order < 1)
{
throw new ArgumentException(Properties.Resources.ArgumentMustBePositive, "order");
}
SafeNativeMethods.d_cholesky_factor(order, a);
}
/// <summary>
@ -627,7 +699,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
/// routine.</remarks>
public void AddArrays(float[] x, float[] y, float[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
_managedProvider.AddArrays(x, y, result);
}
/// <summary>
@ -642,7 +734,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
/// routine.</remarks>
public void SubtractArrays(float[] x, float[] y, float[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
_managedProvider.SubtractArrays(x, y, result);
}
/// <summary>
@ -657,7 +769,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
/// routine.</remarks>
public void PointWiseMultiplyArrays(float[] x, float[] y, float[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
_managedProvider.PointWiseMultiplyArrays(x, y, result);
}
/// <summary>
@ -847,7 +979,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
/// <remarks>This is equivalent to the POTRF LAPACK routine.</remarks>
public void CholeskyFactor(float[] a, int order)
{
throw new NotImplementedException();
if (a == null)
{
throw new ArgumentNullException("a");
}
if ( order < 1)
{
throw new ArgumentException(Properties.Resources.ArgumentMustBePositive, "order");
}
SafeNativeMethods.s_cholesky_factor(order, a);
}
/// <summary>
@ -1124,7 +1266,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
/// routine.</remarks>
public void AddArrays(Complex[] x, Complex[] y, Complex[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
_managedProvider.AddArrays(x, y, result);
}
/// <summary>
@ -1139,7 +1301,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
/// routine.</remarks>
public void SubtractArrays(Complex[] x, Complex[] y, Complex[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
_managedProvider.SubtractArrays(x, y, result);
}
/// <summary>
@ -1154,7 +1336,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
/// routine.</remarks>
public void PointWiseMultiplyArrays(Complex[] x, Complex[] y, Complex[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
_managedProvider.PointWiseMultiplyArrays(x, y, result);
}
/// <summary>
@ -1344,7 +1546,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
/// <remarks>This is equivalent to the POTRF LAPACK routine.</remarks>
public void CholeskyFactor(Complex[] a, int order)
{
throw new NotImplementedException();
if (a == null)
{
throw new ArgumentNullException("a");
}
if ( order < 1)
{
throw new ArgumentException(Properties.Resources.ArgumentMustBePositive, "order");
}
SafeNativeMethods.z_cholesky_factor(order, a);
}
/// <summary>
@ -1621,7 +1833,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
/// routine.</remarks>
public void AddArrays(Complex32[] x, Complex32[] y, Complex32[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
_managedProvider.AddArrays(x, y, result);
}
/// <summary>
@ -1636,7 +1868,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
/// routine.</remarks>
public void SubtractArrays(Complex32[] x, Complex32[] y, Complex32[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
_managedProvider.SubtractArrays(x, y, result);
}
/// <summary>
@ -1651,7 +1903,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
/// routine.</remarks>
public void PointWiseMultiplyArrays(Complex32[] x, Complex32[] y, Complex32[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
_managedProvider.PointWiseMultiplyArrays(x, y, result);
}
/// <summary>
@ -1841,7 +2113,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
/// <remarks>This is equivalent to the POTRF LAPACK routine.</remarks>
public void CholeskyFactor(Complex32[] a, int order)
{
throw new NotImplementedException();
if (a == null)
{
throw new ArgumentNullException("a");
}
if ( order < 1)
{
throw new ArgumentException(Properties.Resources.ArgumentMustBePositive, "order");
}
SafeNativeMethods.c_cholesky_factor(order, a);
}
/// <summary>

22
src/Numerics/Algorithms/LinearAlgebra/Atlas/SafeNativeMethods.cs

@ -28,7 +28,7 @@
/* This file is automatically generated - do not modify it.
Change SafeNativeMethods.include instead.
Last generated on: 1/26/2010 7:19:59 AM
Last generated on: 2/9/2010 12:22:29 PM
*/
using System.Runtime.InteropServices;
@ -86,5 +86,23 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
internal static extern Complex z_dot_product(int n, Complex[] x, Complex[] y);
#endregion BLAS
#region LAPACK
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void s_cholesky_factor(int n, [In, Out] float[] a);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void d_cholesky_factor(int n, [In, Out] double[] a);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void c_cholesky_factor(int n, [In, Out] Complex32[] a);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void z_cholesky_factor(int n, [In, Out] Complex[] a);
#endregion LAPACK
}
}
}

5
src/Numerics/Algorithms/LinearAlgebra/Atlas/SafeNativeMethods.tt

@ -3,4 +3,7 @@
<# string namespaceSuffix = "Atlas";
string library = "ATLAS";
#>
<#@ include file="..\SafeNativeMethods.include" #>
<#@ include file="..\SafeNativeMethods.include" #>
}
}

317
src/Numerics/Algorithms/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs

@ -24,7 +24,7 @@
/* This file is automatically generated - do not modify it.
Change NativeLinearAlgebraProvider.include instead.
Last generated on: 1/26/2010 7:19:59 AM
Last generated on: 2/9/2010 12:24:29 PM
*/
namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
{
@ -36,7 +36,8 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
/// </summary>
public class MklLinearAlgebraProvider : ILinearAlgebraProvider
{
#region ILinearAlgebraProvider<double> Members
#region ILinearAlgebraProvider<double> Members
/// <summary>
/// Adds a scaled vector to another: <c>y += alpha*x</c>.
@ -130,7 +131,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
/// routine.</remarks>
public void AddArrays(double[] x, double[] y, double[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
SafeNativeMethods.d_vector_add( x.Length, x, y, result );
}
/// <summary>
@ -145,7 +166,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
/// routine.</remarks>
public void SubtractArrays(double[] x, double[] y, double[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
SafeNativeMethods.d_vector_subtract( x.Length, x, y, result );
}
/// <summary>
@ -160,7 +201,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
/// routine.</remarks>
public void PointWiseMultiplyArrays(double[] x, double[] y, double[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
SafeNativeMethods.d_vector_multiply( x.Length, x, y, result );
}
/// <summary>
@ -350,7 +411,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
/// <remarks>This is equivalent to the POTRF LAPACK routine.</remarks>
public void CholeskyFactor(double[] a, int order)
{
throw new NotImplementedException();
if (a == null)
{
throw new ArgumentNullException("a");
}
if ( order < 1)
{
throw new ArgumentException(Properties.Resources.ArgumentMustBePositive, "order");
}
SafeNativeMethods.d_cholesky_factor(order, a);
}
/// <summary>
@ -627,7 +698,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
/// routine.</remarks>
public void AddArrays(float[] x, float[] y, float[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
SafeNativeMethods.s_vector_add( x.Length, x, y, result );
}
/// <summary>
@ -642,7 +733,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
/// routine.</remarks>
public void SubtractArrays(float[] x, float[] y, float[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
SafeNativeMethods.s_vector_subtract( x.Length, x, y, result );
}
/// <summary>
@ -657,7 +768,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
/// routine.</remarks>
public void PointWiseMultiplyArrays(float[] x, float[] y, float[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
SafeNativeMethods.s_vector_multiply( x.Length, x, y, result );
}
/// <summary>
@ -847,7 +978,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
/// <remarks>This is equivalent to the POTRF LAPACK routine.</remarks>
public void CholeskyFactor(float[] a, int order)
{
throw new NotImplementedException();
if (a == null)
{
throw new ArgumentNullException("a");
}
if ( order < 1)
{
throw new ArgumentException(Properties.Resources.ArgumentMustBePositive, "order");
}
SafeNativeMethods.s_cholesky_factor(order, a);
}
/// <summary>
@ -1124,7 +1265,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
/// routine.</remarks>
public void AddArrays(Complex[] x, Complex[] y, Complex[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
SafeNativeMethods.z_vector_add( x.Length, x, y, result );
}
/// <summary>
@ -1139,7 +1300,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
/// routine.</remarks>
public void SubtractArrays(Complex[] x, Complex[] y, Complex[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
SafeNativeMethods.z_vector_subtract( x.Length, x, y, result );
}
/// <summary>
@ -1154,7 +1335,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
/// routine.</remarks>
public void PointWiseMultiplyArrays(Complex[] x, Complex[] y, Complex[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
SafeNativeMethods.z_vector_multiply( x.Length, x, y, result );
}
/// <summary>
@ -1344,7 +1545,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
/// <remarks>This is equivalent to the POTRF LAPACK routine.</remarks>
public void CholeskyFactor(Complex[] a, int order)
{
throw new NotImplementedException();
if (a == null)
{
throw new ArgumentNullException("a");
}
if ( order < 1)
{
throw new ArgumentException(Properties.Resources.ArgumentMustBePositive, "order");
}
SafeNativeMethods.z_cholesky_factor(order, a);
}
/// <summary>
@ -1621,7 +1832,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
/// routine.</remarks>
public void AddArrays(Complex32[] x, Complex32[] y, Complex32[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
SafeNativeMethods.c_vector_add( x.Length, x, y, result );
}
/// <summary>
@ -1636,7 +1867,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
/// routine.</remarks>
public void SubtractArrays(Complex32[] x, Complex32[] y, Complex32[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
SafeNativeMethods.c_vector_subtract( x.Length, x, y, result );
}
/// <summary>
@ -1651,7 +1902,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
/// routine.</remarks>
public void PointWiseMultiplyArrays(Complex32[] x, Complex32[] y, Complex32[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
SafeNativeMethods.c_vector_multiply( x.Length, x, y, result );
}
/// <summary>
@ -1841,7 +2112,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
/// <remarks>This is equivalent to the POTRF LAPACK routine.</remarks>
public void CholeskyFactor(Complex32[] a, int order)
{
throw new NotImplementedException();
if (a == null)
{
throw new ArgumentNullException("a");
}
if ( order < 1)
{
throw new ArgumentException(Properties.Resources.ArgumentMustBePositive, "order");
}
SafeNativeMethods.c_cholesky_factor(order, a);
}
/// <summary>

61
src/Numerics/Algorithms/LinearAlgebra/Mkl/SafeNativeMethods.cs

@ -28,7 +28,7 @@
/* This file is automatically generated - do not modify it.
Change SafeNativeMethods.include instead.
Last generated on: 1/26/2010 7:20:00 AM
Last generated on: 2/9/2010 12:22:33 PM
*/
using System.Runtime.InteropServices;
@ -86,5 +86,62 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
internal static extern Complex z_dot_product(int n, Complex[] x, Complex[] y);
#endregion BLAS
#region LAPACK
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void s_cholesky_factor(int n, [In, Out] float[] a);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void d_cholesky_factor(int n, [In, Out] double[] a);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void c_cholesky_factor(int n, [In, Out] Complex32[] a);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void z_cholesky_factor(int n, [In, Out] Complex[] a);
#endregion LAPACK
#region Vector Functions
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void s_vector_add(int n, float[] x, float[] y, [In, Out] float[] result);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void s_vector_subtract(int n, float[] x, float[] y, [In, Out] float[] result);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void s_vector_multiply(int n, float[] x, float[] y, [In, Out] float[] result);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void d_vector_add(int n, double[] x, double[] y, [In, Out] double[] result);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void d_vector_subtract(int n, double[] x, double[] y, [In, Out] double[] result);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void d_vector_multiply(int n, double[] x, double[] y, [In, Out] double[] result);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void c_vector_add(int n, Complex32[] x, Complex32[] y, [In, Out] Complex32[] result);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void c_vector_subtract(int n, Complex32[] x, Complex32[] y, [In, Out] Complex32[] result);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void c_vector_multiply(int n, Complex32[] x, Complex32[] y, [In, Out] Complex32[] result);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void z_vector_add(int n, Complex[] x, Complex[] y, [In, Out] Complex[] result);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void z_vector_subtract(int n, Complex[] x, Complex[] y, [In, Out] Complex[] result);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void z_vector_multiply(int n, Complex[] x, Complex[] y, [In, Out] Complex[] result);
#endregion Vector Functions
}
}
}

44
src/Numerics/Algorithms/LinearAlgebra/Mkl/SafeNativeMethods.tt

@ -3,4 +3,46 @@
<# string namespaceSuffix = "Mkl";
string library = "MKL";
#>
<#@ include file="..\SafeNativeMethods.include" #>
<#@ include file="..\SafeNativeMethods.include" #>
#region Vector Functions
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void s_vector_add(int n, float[] x, float[] y, [In, Out] float[] result);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void s_vector_subtract(int n, float[] x, float[] y, [In, Out] float[] result);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void s_vector_multiply(int n, float[] x, float[] y, [In, Out] float[] result);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void d_vector_add(int n, double[] x, double[] y, [In, Out] double[] result);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void d_vector_subtract(int n, double[] x, double[] y, [In, Out] double[] result);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void d_vector_multiply(int n, double[] x, double[] y, [In, Out] double[] result);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void c_vector_add(int n, Complex32[] x, Complex32[] y, [In, Out] Complex32[] result);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void c_vector_subtract(int n, Complex32[] x, Complex32[] y, [In, Out] Complex32[] result);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void c_vector_multiply(int n, Complex32[] x, Complex32[] y, [In, Out] Complex32[] result);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void z_vector_add(int n, Complex[] x, Complex[] y, [In, Out] Complex[] result);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void z_vector_subtract(int n, Complex[] x, Complex[] y, [In, Out] Complex[] result);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void z_vector_multiply(int n, Complex[] x, Complex[] y, [In, Out] Complex[] result);
#endregion Vector Functions
}
}

366
src/Numerics/Algorithms/LinearAlgebra/NativeAlgebraProvider.include

@ -36,7 +36,11 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
/// </summary>
public class <#=library#>LinearAlgebraProvider : ILinearAlgebraProvider
{
#region ILinearAlgebraProvider<double> Members
<# if( !library.Equals("Mkl") ){ #>
private readonly ILinearAlgebraProvider _managedProvider = new ManagedLinearAlgebraProvider();
<#} #>
#region ILinearAlgebraProvider<double> Members
/// <summary>
/// Adds a scaled vector to another: <c>y += alpha*x</c>.
@ -130,7 +134,31 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
/// routine.</remarks>
public void AddArrays(double[] x, double[] y, double[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
<# if( library.Equals("Mkl") ){ #>
SafeNativeMethods.d_vector_add( x.Length, x, y, result );
<#} else {#>
_managedProvider.AddArrays(x, y, result);
<#} #>
}
/// <summary>
@ -145,7 +173,31 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
/// routine.</remarks>
public void SubtractArrays(double[] x, double[] y, double[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
<# if( library.Equals("Mkl") ){ #>
SafeNativeMethods.d_vector_subtract( x.Length, x, y, result );
<#} else {#>
_managedProvider.SubtractArrays(x, y, result);
<#} #>
}
/// <summary>
@ -160,7 +212,31 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
/// routine.</remarks>
public void PointWiseMultiplyArrays(double[] x, double[] y, double[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
<# if( library.Equals("Mkl") ){ #>
SafeNativeMethods.d_vector_multiply( x.Length, x, y, result );
<#} else {#>
_managedProvider.PointWiseMultiplyArrays(x, y, result);
<#} #>
}
/// <summary>
@ -350,7 +426,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
/// <remarks>This is equivalent to the POTRF LAPACK routine.</remarks>
public void CholeskyFactor(double[] a, int order)
{
throw new NotImplementedException();
if (a == null)
{
throw new ArgumentNullException("a");
}
if ( order < 1)
{
throw new ArgumentException(Properties.Resources.ArgumentMustBePositive, "order");
}
SafeNativeMethods.d_cholesky_factor(order, a);
}
/// <summary>
@ -627,7 +713,31 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
/// routine.</remarks>
public void AddArrays(float[] x, float[] y, float[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
<# if( library.Equals("Mkl") ){ #>
SafeNativeMethods.s_vector_add( x.Length, x, y, result );
<#} else {#>
_managedProvider.AddArrays(x, y, result);
<#} #>
}
/// <summary>
@ -642,7 +752,31 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
/// routine.</remarks>
public void SubtractArrays(float[] x, float[] y, float[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
<# if( library.Equals("Mkl") ){ #>
SafeNativeMethods.s_vector_subtract( x.Length, x, y, result );
<#} else {#>
_managedProvider.SubtractArrays(x, y, result);
<#} #>
}
/// <summary>
@ -657,7 +791,31 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
/// routine.</remarks>
public void PointWiseMultiplyArrays(float[] x, float[] y, float[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
<# if( library.Equals("Mkl") ){ #>
SafeNativeMethods.s_vector_multiply( x.Length, x, y, result );
<#} else {#>
_managedProvider.PointWiseMultiplyArrays(x, y, result);
<#} #>
}
/// <summary>
@ -847,7 +1005,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
/// <remarks>This is equivalent to the POTRF LAPACK routine.</remarks>
public void CholeskyFactor(float[] a, int order)
{
throw new NotImplementedException();
if (a == null)
{
throw new ArgumentNullException("a");
}
if ( order < 1)
{
throw new ArgumentException(Properties.Resources.ArgumentMustBePositive, "order");
}
SafeNativeMethods.s_cholesky_factor(order, a);
}
/// <summary>
@ -1124,7 +1292,31 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
/// routine.</remarks>
public void AddArrays(Complex[] x, Complex[] y, Complex[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
<# if( library.Equals("Mkl") ){ #>
SafeNativeMethods.z_vector_add( x.Length, x, y, result );
<#} else {#>
_managedProvider.AddArrays(x, y, result);
<#} #>
}
/// <summary>
@ -1139,7 +1331,31 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
/// routine.</remarks>
public void SubtractArrays(Complex[] x, Complex[] y, Complex[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
<# if( library.Equals("Mkl") ){ #>
SafeNativeMethods.z_vector_subtract( x.Length, x, y, result );
<#} else {#>
_managedProvider.SubtractArrays(x, y, result);
<#} #>
}
/// <summary>
@ -1154,7 +1370,31 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
/// routine.</remarks>
public void PointWiseMultiplyArrays(Complex[] x, Complex[] y, Complex[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
<# if( library.Equals("Mkl") ){ #>
SafeNativeMethods.z_vector_multiply( x.Length, x, y, result );
<#} else {#>
_managedProvider.PointWiseMultiplyArrays(x, y, result);
<#} #>
}
/// <summary>
@ -1344,7 +1584,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
/// <remarks>This is equivalent to the POTRF LAPACK routine.</remarks>
public void CholeskyFactor(Complex[] a, int order)
{
throw new NotImplementedException();
if (a == null)
{
throw new ArgumentNullException("a");
}
if ( order < 1)
{
throw new ArgumentException(Properties.Resources.ArgumentMustBePositive, "order");
}
SafeNativeMethods.z_cholesky_factor(order, a);
}
/// <summary>
@ -1621,7 +1871,31 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
/// routine.</remarks>
public void AddArrays(Complex32[] x, Complex32[] y, Complex32[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
<# if( library.Equals("Mkl") ){ #>
SafeNativeMethods.c_vector_add( x.Length, x, y, result );
<#} else {#>
_managedProvider.AddArrays(x, y, result);
<#} #>
}
/// <summary>
@ -1636,7 +1910,31 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
/// routine.</remarks>
public void SubtractArrays(Complex32[] x, Complex32[] y, Complex32[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
<# if( library.Equals("Mkl") ){ #>
SafeNativeMethods.c_vector_subtract( x.Length, x, y, result );
<#} else {#>
_managedProvider.SubtractArrays(x, y, result);
<#} #>
}
/// <summary>
@ -1651,7 +1949,31 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
/// routine.</remarks>
public void PointWiseMultiplyArrays(Complex32[] x, Complex32[] y, Complex32[] result)
{
throw new NotImplementedException();
if (y == null)
{
throw new ArgumentNullException("y");
}
if (x == null)
{
throw new ArgumentNullException("x");
}
if (x.Length != y.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (x.Length != result.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
<# if( library.Equals("Mkl") ){ #>
SafeNativeMethods.c_vector_multiply( x.Length, x, y, result );
<#} else {#>
_managedProvider.PointWiseMultiplyArrays(x, y, result);
<#} #>
}
/// <summary>
@ -1841,7 +2163,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
/// <remarks>This is equivalent to the POTRF LAPACK routine.</remarks>
public void CholeskyFactor(Complex32[] a, int order)
{
throw new NotImplementedException();
if (a == null)
{
throw new ArgumentNullException("a");
}
if ( order < 1)
{
throw new ArgumentException(Properties.Resources.ArgumentMustBePositive, "order");
}
SafeNativeMethods.c_cholesky_factor(order, a);
}
/// <summary>

18
src/Numerics/Algorithms/LinearAlgebra/SafeNativeMethods.include

@ -86,5 +86,19 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#= namespaceSuffix #>
internal static extern Complex z_dot_product(int n, Complex[] x, Complex[] y);
#endregion BLAS
}
}
#region LAPACK
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void s_cholesky_factor(int n, [In, Out] float[] a);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void d_cholesky_factor(int n, [In, Out] double[] a);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void c_cholesky_factor(int n, [In, Out] Complex32[] a);
[DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
internal static extern void z_cholesky_factor(int n, [In, Out] Complex[] a);
#endregion LAPACK

2
src/UnitTests/LinearAlgebraTests/Double/LinearAlgebraProviderTests.cs

@ -64,9 +64,7 @@
public void CanComputeDotProduct()
{
var result = Provider.DotProduct(x, y);
Console.WriteLine(result);
AssertHelpers.AlmostEqual(152.35, result, 15);
}
[Test]

Loading…
Cancel
Save