From a6a56dfcbc4eeb318b7761d2ffc37fa6ad46894d Mon Sep 17 00:00:00 2001 From: Marcus Cuda Date: Tue, 9 Feb 2010 18:32:41 +0800 Subject: [PATCH] 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. --- .../Double/AtlasLinearAlgebraProviderTests.cs | 2 +- src/NativeWrappers/MKL/MKLWrapper.vcproj | 4 +- src/NativeWrappers/MKL/vector_functions.c | 50 ++- .../Double/MklLinearAlgebraProviderTests.cs | 4 +- .../MKLWrapper32Tests.csproj | 9 +- .../MKLWrapper64Tests.csproj | 9 +- .../Atlas/AtlasLinearAlgebraProvider.cs | 318 ++++++++++++++- .../LinearAlgebra/Atlas/SafeNativeMethods.cs | 22 +- .../LinearAlgebra/Atlas/SafeNativeMethods.tt | 5 +- .../Mkl/MklLinearAlgebraProvider.cs | 317 ++++++++++++++- .../LinearAlgebra/Mkl/SafeNativeMethods.cs | 61 ++- .../LinearAlgebra/Mkl/SafeNativeMethods.tt | 44 ++- .../NativeAlgebraProvider.include | 366 +++++++++++++++++- .../LinearAlgebra/SafeNativeMethods.include | 18 +- .../Double/LinearAlgebraProviderTests.cs | 2 - 15 files changed, 1149 insertions(+), 82 deletions(-) diff --git a/src/NativeWrappers/ATLASWrapperTests/LinearAlgebra/Double/AtlasLinearAlgebraProviderTests.cs b/src/NativeWrappers/ATLASWrapperTests/LinearAlgebra/Double/AtlasLinearAlgebraProviderTests.cs index f2a9b7b4..d5aab186 100644 --- a/src/NativeWrappers/ATLASWrapperTests/LinearAlgebra/Double/AtlasLinearAlgebraProviderTests.cs +++ b/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(); } } } diff --git a/src/NativeWrappers/MKL/MKLWrapper.vcproj b/src/NativeWrappers/MKL/MKLWrapper.vcproj index d3244cad..2c56974d 100644 --- a/src/NativeWrappers/MKL/MKLWrapper.vcproj +++ b/src/NativeWrappers/MKL/MKLWrapper.vcproj @@ -43,7 +43,7 @@ TRACE prompt 4 + x86 False ..\..\UnitTests\bin\Debug\Gallio.dll - + False - ..\..\UnitTests\bin\Debug\MathNet.Numerics.dll + ..\..\Numerics\bin\Debug\MathNet.Numerics.dll False @@ -72,11 +73,11 @@ libiomp5md.dll - PreserveNewest + Always MathNET.Numerics.MKL.dll - PreserveNewest + Always diff --git a/src/NativeWrappers/MKLWrapper64Tests/MKLWrapper64Tests.csproj b/src/NativeWrappers/MKLWrapper64Tests/MKLWrapper64Tests.csproj index 92f68496..c60f847c 100644 --- a/src/NativeWrappers/MKLWrapper64Tests/MKLWrapper64Tests.csproj +++ b/src/NativeWrappers/MKLWrapper64Tests/MKLWrapper64Tests.csproj @@ -30,6 +30,7 @@ TRACE prompt 4 + x64 @@ -40,9 +41,9 @@ False ..\..\UnitTests\bin\Debug\Gallio35.dll - + False - ..\..\UnitTests\bin\Debug\MathNet.Numerics.dll + ..\..\Numerics\bin\Debug\MathNet.Numerics.dll False @@ -78,11 +79,11 @@ libiomp5md.dll - PreserveNewest + Always MathNET.Numerics.MKL.dll - PreserveNewest + Always diff --git a/src/Numerics/Algorithms/LinearAlgebra/Atlas/AtlasLinearAlgebraProvider.cs b/src/Numerics/Algorithms/LinearAlgebra/Atlas/AtlasLinearAlgebraProvider.cs index ee69b843..dcc8352d 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/Atlas/AtlasLinearAlgebraProvider.cs +++ b/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 /// public class AtlasLinearAlgebraProvider : ILinearAlgebraProvider { - #region ILinearAlgebraProvider Members + private readonly ILinearAlgebraProvider _managedProvider = new ManagedLinearAlgebraProvider(); + + #region ILinearAlgebraProvider Members /// /// Adds a scaled vector to another: y += alpha*x. @@ -130,7 +132,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// routine. 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); } /// @@ -145,7 +167,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// routine. 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); } /// @@ -160,7 +202,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// routine. 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); } /// @@ -350,7 +412,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// This is equivalent to the POTRF LAPACK routine. 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); } /// @@ -627,7 +699,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// routine. 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); } /// @@ -642,7 +734,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// routine. 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); } /// @@ -657,7 +769,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// routine. 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); } /// @@ -847,7 +979,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// This is equivalent to the POTRF LAPACK routine. 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); } /// @@ -1124,7 +1266,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// routine. 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); } /// @@ -1139,7 +1301,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// routine. 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); } /// @@ -1154,7 +1336,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// routine. 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); } /// @@ -1344,7 +1546,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// This is equivalent to the POTRF LAPACK routine. 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); } /// @@ -1621,7 +1833,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// routine. 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); } /// @@ -1636,7 +1868,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// routine. 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); } /// @@ -1651,7 +1903,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// routine. 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); } /// @@ -1841,7 +2113,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas /// This is equivalent to the POTRF LAPACK routine. 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); } /// diff --git a/src/Numerics/Algorithms/LinearAlgebra/Atlas/SafeNativeMethods.cs b/src/Numerics/Algorithms/LinearAlgebra/Atlas/SafeNativeMethods.cs index 9c38066c..403d7666 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/Atlas/SafeNativeMethods.cs +++ b/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 + + } -} +} \ No newline at end of file diff --git a/src/Numerics/Algorithms/LinearAlgebra/Atlas/SafeNativeMethods.tt b/src/Numerics/Algorithms/LinearAlgebra/Atlas/SafeNativeMethods.tt index 5f17c830..3aced9d3 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/Atlas/SafeNativeMethods.tt +++ b/src/Numerics/Algorithms/LinearAlgebra/Atlas/SafeNativeMethods.tt @@ -3,4 +3,7 @@ <# string namespaceSuffix = "Atlas"; string library = "ATLAS"; #> -<#@ include file="..\SafeNativeMethods.include" #> \ No newline at end of file +<#@ include file="..\SafeNativeMethods.include" #> + + } +} \ No newline at end of file diff --git a/src/Numerics/Algorithms/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs b/src/Numerics/Algorithms/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs index 79e766ee..7e2771f3 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs +++ b/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 /// public class MklLinearAlgebraProvider : ILinearAlgebraProvider { - #region ILinearAlgebraProvider Members + + #region ILinearAlgebraProvider Members /// /// Adds a scaled vector to another: y += alpha*x. @@ -130,7 +131,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// routine. 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 ); } /// @@ -145,7 +166,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// routine. 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 ); } /// @@ -160,7 +201,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// routine. 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 ); } /// @@ -350,7 +411,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// This is equivalent to the POTRF LAPACK routine. 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); } /// @@ -627,7 +698,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// routine. 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 ); } /// @@ -642,7 +733,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// routine. 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 ); } /// @@ -657,7 +768,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// routine. 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 ); } /// @@ -847,7 +978,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// This is equivalent to the POTRF LAPACK routine. 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); } /// @@ -1124,7 +1265,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// routine. 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 ); } /// @@ -1139,7 +1300,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// routine. 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 ); } /// @@ -1154,7 +1335,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// routine. 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 ); } /// @@ -1344,7 +1545,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// This is equivalent to the POTRF LAPACK routine. 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); } /// @@ -1621,7 +1832,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// routine. 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 ); } /// @@ -1636,7 +1867,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// routine. 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 ); } /// @@ -1651,7 +1902,27 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// routine. 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 ); } /// @@ -1841,7 +2112,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl /// This is equivalent to the POTRF LAPACK routine. 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); } /// diff --git a/src/Numerics/Algorithms/LinearAlgebra/Mkl/SafeNativeMethods.cs b/src/Numerics/Algorithms/LinearAlgebra/Mkl/SafeNativeMethods.cs index fc782365..b09bf224 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/Mkl/SafeNativeMethods.cs +++ b/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 } -} +} \ No newline at end of file diff --git a/src/Numerics/Algorithms/LinearAlgebra/Mkl/SafeNativeMethods.tt b/src/Numerics/Algorithms/LinearAlgebra/Mkl/SafeNativeMethods.tt index 993a9ac7..27578188 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/Mkl/SafeNativeMethods.tt +++ b/src/Numerics/Algorithms/LinearAlgebra/Mkl/SafeNativeMethods.tt @@ -3,4 +3,46 @@ <# string namespaceSuffix = "Mkl"; string library = "MKL"; #> -<#@ include file="..\SafeNativeMethods.include" #> \ No newline at end of file +<#@ 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 + } +} \ No newline at end of file diff --git a/src/Numerics/Algorithms/LinearAlgebra/NativeAlgebraProvider.include b/src/Numerics/Algorithms/LinearAlgebra/NativeAlgebraProvider.include index 60be35f5..c6bdd1ec 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/NativeAlgebraProvider.include +++ b/src/Numerics/Algorithms/LinearAlgebra/NativeAlgebraProvider.include @@ -36,7 +36,11 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// public class <#=library#>LinearAlgebraProvider : ILinearAlgebraProvider { - #region ILinearAlgebraProvider Members +<# if( !library.Equals("Mkl") ){ #> + private readonly ILinearAlgebraProvider _managedProvider = new ManagedLinearAlgebraProvider(); +<#} #> + + #region ILinearAlgebraProvider Members /// /// Adds a scaled vector to another: y += alpha*x. @@ -130,7 +134,31 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// routine. 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); +<#} #> } /// @@ -145,7 +173,31 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// routine. 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); +<#} #> } /// @@ -160,7 +212,31 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// routine. 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); +<#} #> } /// @@ -350,7 +426,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// This is equivalent to the POTRF LAPACK routine. 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); } /// @@ -627,7 +713,31 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// routine. 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); +<#} #> } /// @@ -642,7 +752,31 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// routine. 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); +<#} #> } /// @@ -657,7 +791,31 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// routine. 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); +<#} #> } /// @@ -847,7 +1005,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// This is equivalent to the POTRF LAPACK routine. 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); } /// @@ -1124,7 +1292,31 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// routine. 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); +<#} #> } /// @@ -1139,7 +1331,31 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// routine. 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); +<#} #> } /// @@ -1154,7 +1370,31 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// routine. 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); +<#} #> } /// @@ -1344,7 +1584,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// This is equivalent to the POTRF LAPACK routine. 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); } /// @@ -1621,7 +1871,31 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// routine. 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); +<#} #> } /// @@ -1636,7 +1910,31 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// routine. 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); +<#} #> } /// @@ -1651,7 +1949,31 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// routine. 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); +<#} #> } /// @@ -1841,7 +2163,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#> /// This is equivalent to the POTRF LAPACK routine. 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); } /// diff --git a/src/Numerics/Algorithms/LinearAlgebra/SafeNativeMethods.include b/src/Numerics/Algorithms/LinearAlgebra/SafeNativeMethods.include index cf4605cc..f662b87c 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/SafeNativeMethods.include +++ b/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 diff --git a/src/UnitTests/LinearAlgebraTests/Double/LinearAlgebraProviderTests.cs b/src/UnitTests/LinearAlgebraTests/Double/LinearAlgebraProviderTests.cs index 64084e68..b047f380 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/LinearAlgebraProviderTests.cs +++ b/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]