diff --git a/MathNet.Numerics.sln b/MathNet.Numerics.sln
index 1f720d96..159cdb95 100644
--- a/MathNet.Numerics.sln
+++ b/MathNet.Numerics.sln
@@ -70,6 +70,12 @@ ProjectSection(SolutionItems) = preProject
README.md = README.md
EndProjectSection
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Providers.MKL", "src\Providers.MKL\Providers.MKL.csproj", "{0B5FAFAA-4286-4D92-B5AB-CBA75ADDA0BB}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Providers.CUDA", "src\Providers.CUDA\Providers.CUDA.csproj", "{3C0D4A87-CC89-43B6-B028-4122099D692F}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Providers.OpenBLAS", "src\Providers.OpenBLAS\Providers.OpenBLAS.csproj", "{FBE18DF3-EEC3-4812-9FB4-B9EA6EAEC029}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -113,6 +119,24 @@ Global
{82444930-9FD7-41B6-B476-CCE41A0C0A0B}.Release|Any CPU.Build.0 = Release|Any CPU
{82444930-9FD7-41B6-B476-CCE41A0C0A0B}.Release-Signed|Any CPU.ActiveCfg = Release|Any CPU
{82444930-9FD7-41B6-B476-CCE41A0C0A0B}.Release-Signed|Any CPU.Build.0 = Release|Any CPU
+ {0B5FAFAA-4286-4D92-B5AB-CBA75ADDA0BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0B5FAFAA-4286-4D92-B5AB-CBA75ADDA0BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0B5FAFAA-4286-4D92-B5AB-CBA75ADDA0BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0B5FAFAA-4286-4D92-B5AB-CBA75ADDA0BB}.Release|Any CPU.Build.0 = Release|Any CPU
+ {0B5FAFAA-4286-4D92-B5AB-CBA75ADDA0BB}.Release-Signed|Any CPU.ActiveCfg = Debug|Any CPU
+ {0B5FAFAA-4286-4D92-B5AB-CBA75ADDA0BB}.Release-Signed|Any CPU.Build.0 = Debug|Any CPU
+ {3C0D4A87-CC89-43B6-B028-4122099D692F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {3C0D4A87-CC89-43B6-B028-4122099D692F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {3C0D4A87-CC89-43B6-B028-4122099D692F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {3C0D4A87-CC89-43B6-B028-4122099D692F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {3C0D4A87-CC89-43B6-B028-4122099D692F}.Release-Signed|Any CPU.ActiveCfg = Debug|Any CPU
+ {3C0D4A87-CC89-43B6-B028-4122099D692F}.Release-Signed|Any CPU.Build.0 = Debug|Any CPU
+ {FBE18DF3-EEC3-4812-9FB4-B9EA6EAEC029}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {FBE18DF3-EEC3-4812-9FB4-B9EA6EAEC029}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FBE18DF3-EEC3-4812-9FB4-B9EA6EAEC029}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {FBE18DF3-EEC3-4812-9FB4-B9EA6EAEC029}.Release|Any CPU.Build.0 = Release|Any CPU
+ {FBE18DF3-EEC3-4812-9FB4-B9EA6EAEC029}.Release-Signed|Any CPU.ActiveCfg = Debug|Any CPU
+ {FBE18DF3-EEC3-4812-9FB4-B9EA6EAEC029}.Release-Signed|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/MathNet.Numerics.sln.DotSettings b/MathNet.Numerics.sln.DotSettings
index 61294516..569d8949 100644
--- a/MathNet.Numerics.sln.DotSettings
+++ b/MathNet.Numerics.sln.DotSettings
@@ -59,17 +59,20 @@ OTHER DEALINGS IN THE SOFTWARE.
FFT
ILU
ILUTP
+ LA
LU
MAE
MC
MCMC
MILU
+ MKL
MSE
PDF
QR
SAD
SAS
SPSS
+ SS
SSD
SVD
TFQMR
diff --git a/build.fsx b/build.fsx
index b2ba54c0..5eee58b7 100644
--- a/build.fsx
+++ b/build.fsx
@@ -51,10 +51,16 @@ let numericsNuGetPackage = nugetPackage "MathNet.Numerics" numericsRelease
let numericsFSharpNuGetPackage = nugetPackage "MathNet.Numerics.FSharp" numericsRelease
let numericsStrongNameNuGetPackage = nugetPackage "MathNet.Numerics.Signed" numericsRelease
let numericsFSharpStrongNameNuGetPackage = nugetPackage "MathNet.Numerics.FSharp.Signed" numericsRelease
+let numericsProvidersMklNuGetPackage = nugetPackage "MathNet.Numerics.Providers.MKL" numericsRelease
+let numericsProvidersOpenBlasNuGetPackage = nugetPackage "MathNet.Numerics.Providers.OpenBLAS" numericsRelease
+let numericsProvidersCudaNuGetPackage = nugetPackage "MathNet.Numerics.Providers.CUDA" numericsRelease
let numericsProject = project "MathNet.Numerics" "src/Numerics/Numerics.csproj" [numericsNuGetPackage; numericsStrongNameNuGetPackage]
let numericsFsharpProject = project "MathNet.Numerics.FSharp" "src/FSharp/FSharp.fsproj" [numericsFSharpNuGetPackage; numericsFSharpStrongNameNuGetPackage]
-let numericsSolution = solution "Numerics" "MathNet.Numerics.sln" [numericsProject; numericsFsharpProject] [numericsZipPackage; numericsStrongNameZipPackage]
+let numericsProvidersMklProject = project "MathNet.Numerics.Providers.MKL" "src/Providers.MKL/Providers.MKL.csproj" [numericsProvidersMklNuGetPackage]
+let numericsProvidersOpenBlasProject = project "MathNet.Numerics.Providers.OpenBLAS" "src/Providers.OpenBLAS/Providers.OpenBLAS.csproj" [numericsProvidersOpenBlasNuGetPackage]
+let numericsProvidersCudaProject = project "MathNet.Numerics.Providers.CUDA" "src/Providers.CUDA/Providers.CUDA.csproj" [numericsProvidersCudaNuGetPackage]
+let numericsSolution = solution "Numerics" "MathNet.Numerics.sln" [numericsProject; numericsFsharpProject; numericsProvidersMklProject; numericsProvidersOpenBlasProject; numericsProvidersCudaProject] [numericsZipPackage; numericsStrongNameZipPackage]
// DATA EXTENSION PACKAGES
diff --git a/src/Benchmark/Benchmark.csproj b/src/Benchmark/Benchmark.csproj
index 1a6eefa9..8588246f 100644
--- a/src/Benchmark/Benchmark.csproj
+++ b/src/Benchmark/Benchmark.csproj
@@ -16,6 +16,7 @@
+
diff --git a/src/Benchmark/LinearAlgebra/DenseMatrixProduct.cs b/src/Benchmark/LinearAlgebra/DenseMatrixProduct.cs
index a7c8c0b9..2d683cd4 100644
--- a/src/Benchmark/LinearAlgebra/DenseMatrixProduct.cs
+++ b/src/Benchmark/LinearAlgebra/DenseMatrixProduct.cs
@@ -5,7 +5,7 @@ using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using MathNet.Numerics;
using MathNet.Numerics.LinearAlgebra;
-using MathNet.Numerics.Providers.Common.Mkl;
+using MathNet.Numerics.Providers.MKL;
namespace Benchmark.LinearAlgebra
{
@@ -77,16 +77,16 @@ namespace Benchmark.LinearAlgebra
Control.UseManaged();
break;
case ProviderId.NativeMKLAutoHigh:
- Control.UseNativeMKL(MklConsistency.Auto, MklPrecision.Double, MklAccuracy.High);
+ MklControl.UseNativeMKL(MklConsistency.Auto, MklPrecision.Double, MklAccuracy.High);
break;
case ProviderId.NativeMKLAutoLow:
- Control.UseNativeMKL(MklConsistency.Auto, MklPrecision.Double, MklAccuracy.Low);
+ MklControl.UseNativeMKL(MklConsistency.Auto, MklPrecision.Double, MklAccuracy.Low);
break;
case ProviderId.NativeMKLAvx2High:
- Control.UseNativeMKL(MklConsistency.AVX2, MklPrecision.Double, MklAccuracy.High);
+ MklControl.UseNativeMKL(MklConsistency.AVX2, MklPrecision.Double, MklAccuracy.High);
break;
case ProviderId.NativeMKLAvx2Low:
- Control.UseNativeMKL(MklConsistency.AVX2, MklPrecision.Double, MklAccuracy.Low);
+ MklControl.UseNativeMKL(MklConsistency.AVX2, MklPrecision.Double, MklAccuracy.Low);
break;
}
}
diff --git a/src/Benchmark/LinearAlgebra/DenseVector.cs b/src/Benchmark/LinearAlgebra/DenseVector.cs
index 0732d6ab..ac77db5f 100644
--- a/src/Benchmark/LinearAlgebra/DenseVector.cs
+++ b/src/Benchmark/LinearAlgebra/DenseVector.cs
@@ -3,9 +3,8 @@ using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using MathNet.Numerics;
-using MathNet.Numerics.Providers.Common.Mkl;
using MathNet.Numerics.Providers.LinearAlgebra;
-
+using MathNet.Numerics.Providers.MKL;
using Complex = System.Numerics.Complex;
namespace Benchmark.LinearAlgebra
@@ -57,7 +56,7 @@ namespace Benchmark.LinearAlgebra
Control.UseManagedReference();
break;
case ProviderId.NativeMKL:
- Control.UseNativeMKL(MklConsistency.Auto, MklPrecision.Double, MklAccuracy.High);
+ MklControl.UseNativeMKL(MklConsistency.Auto, MklPrecision.Double, MklAccuracy.High);
break;
}
diff --git a/src/Benchmark/Transforms/FFT.cs b/src/Benchmark/Transforms/FFT.cs
index 27d74276..137b2054 100644
--- a/src/Benchmark/Transforms/FFT.cs
+++ b/src/Benchmark/Transforms/FFT.cs
@@ -4,7 +4,7 @@ using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using MathNet.Numerics;
using MathNet.Numerics.IntegralTransforms;
-using MathNet.Numerics.Providers.Common.Mkl;
+using MathNet.Numerics.Providers.MKL;
using Complex = System.Numerics.Complex;
namespace Benchmark.Transforms
@@ -47,7 +47,7 @@ namespace Benchmark.Transforms
Control.UseManaged();
break;
case ProviderId.NativeMKL:
- Control.UseNativeMKL(MklConsistency.Auto, MklPrecision.Double, MklAccuracy.High);
+ MklControl.UseNativeMKL(MklConsistency.Auto, MklPrecision.Double, MklAccuracy.High);
break;
}
diff --git a/src/Numerics.Tests/Numerics.Tests.CUDA.csproj b/src/Numerics.Tests/Numerics.Tests.CUDA.csproj
index e729f710..830552df 100644
--- a/src/Numerics.Tests/Numerics.Tests.CUDA.csproj
+++ b/src/Numerics.Tests/Numerics.Tests.CUDA.csproj
@@ -3,7 +3,7 @@
Exe
false
- net461;netcoreapp3.1
+ net5.0;net48
false
MathNet.Numerics.Tests.CUDA
MathNet.Numerics.Tests
@@ -23,6 +23,7 @@
+
diff --git a/src/Numerics.Tests/Numerics.Tests.MKL.csproj b/src/Numerics.Tests/Numerics.Tests.MKL.csproj
index a6e8f3d9..637fb05b 100644
--- a/src/Numerics.Tests/Numerics.Tests.MKL.csproj
+++ b/src/Numerics.Tests/Numerics.Tests.MKL.csproj
@@ -3,7 +3,7 @@
Exe
false
- net461;netcoreapp3.1
+ net5.0;net48
false
MathNet.Numerics.Tests.MKL
MathNet.Numerics.Tests
@@ -23,6 +23,7 @@
+
diff --git a/src/Numerics.Tests/Numerics.Tests.OpenBLAS.csproj b/src/Numerics.Tests/Numerics.Tests.OpenBLAS.csproj
index 5f79f184..d3d7c884 100644
--- a/src/Numerics.Tests/Numerics.Tests.OpenBLAS.csproj
+++ b/src/Numerics.Tests/Numerics.Tests.OpenBLAS.csproj
@@ -3,7 +3,7 @@
Exe
false
- net461;netcoreapp3.1
+ net5.0;net48
false
MathNet.Numerics.Tests.OpenBLAS
MathNet.Numerics.Tests
@@ -23,6 +23,7 @@
+
diff --git a/src/Numerics.Tests/Providers/SparseSolver/double/SparseSolverProviderTests.cs b/src/Numerics.Tests/Providers/SparseSolver/double/SparseSolverProviderTests.cs
index 0bc86a34..aadef992 100644
--- a/src/Numerics.Tests/Providers/SparseSolver/double/SparseSolverProviderTests.cs
+++ b/src/Numerics.Tests/Providers/SparseSolver/double/SparseSolverProviderTests.cs
@@ -9,7 +9,6 @@ using System.Collections.Generic;
namespace MathNet.Numerics.UnitTests.Providers.SparseSolver.Double
{
-#if NATIVE
#if MKL
///
@@ -20,7 +19,7 @@ namespace MathNet.Numerics.UnitTests.Providers.SparseSolver.Double
{
readonly double[] _b4 = { 1.0, 2.0, 3.0, 4.0};
readonly double[] _b5 = { 1.0, 2.0, 3.0, 4.0, 5.0 };
-
+
///
/// Test matrix to use.
///
@@ -245,11 +244,11 @@ namespace MathNet.Numerics.UnitTests.Providers.SparseSolver.Double
// for Node1, u = -1 gives -a + b = x1
// for Node2, u = +1 gives a + b = x2
//
- // So,
+ // So,
// x = (x2 - x1)/2*u + (x2 + x1)/2
// u = 2*(x - x1)/(x2 - x1) - 1
//
- // This gives
+ // This gives
// dx = l/2*du where l = x2 - x1 = x21 is length of the line
//
// Interpolation function, Ni(u) = ai + bi*u for i = 1, 2
@@ -257,11 +256,11 @@ namespace MathNet.Numerics.UnitTests.Providers.SparseSolver.Double
// N1(+1) = a1 + b1 = 0 -> a1 = 1/2, b1 = -1/2
// N2(-1) = a2 - b2 = 0
// N2(+1) = a2 + b2 = 1 -> a2 = 1/2, b2 = 1/2
- // so,
+ // so,
// N1 = (1 - u) / 2
// N2 = (1 + u) / 2
//
- // Using the chain rule of differentiation,
+ // Using the chain rule of differentiation,
// ∂Ni(x)/∂u = ∂Ni/∂x ∂x/∂u
//
// Here,
@@ -273,7 +272,7 @@ namespace MathNet.Numerics.UnitTests.Providers.SparseSolver.Double
// ∂N1/∂x = 2/l ∂N1/∂u = - 1/l
// ∂N2/∂x = 2/l ∂N2/∂u = 1/l
//-----------------------------------------------------------------------------
- // By using V(u) = Σ Vi*Ni(u) and ω = Ni for i = 1, 2
+ // By using V(u) = Σ Vi*Ni(u) and ω = Ni for i = 1, 2
// the weak form of the master equation is given as
//
// ∫ ω [d/dx(α dV/dx) + γ] dx = 0
@@ -328,7 +327,7 @@ namespace MathNet.Numerics.UnitTests.Providers.SparseSolver.Double
{
// V(u) can be described with interpolation functions
// V(u) = V1*N1(u) + V2*N2(u)
- // where
+ // where
// N1 = (1 - u) / 2
// N2 = (1 + u) / 2
// The transformation from x to u,
@@ -345,7 +344,7 @@ namespace MathNet.Numerics.UnitTests.Providers.SparseSolver.Double
var Vx = V1 * (1 - u) * 0.5 + V2 * (1 + u) * 0.5;
- // Electric field,
+ // Electric field,
// E = -∇V
// where
// ∇V = [ (∂/∂x) ∑ViNi ]
@@ -385,7 +384,7 @@ namespace MathNet.Numerics.UnitTests.Providers.SparseSolver.Double
public Node[] Nodes;
public Element[] Elements;
- public Matrix Kmatrix;
+ public Matrix Kmatrix;
public Vector Rhs;
public Domain(int elementCount = 4, double length = 0.08, double relativePermittivity = 1, double chargeDensity = 1E-8)
@@ -395,7 +394,7 @@ namespace MathNet.Numerics.UnitTests.Providers.SparseSolver.Double
Permittivity = Constants.ElectricPermittivity * relativePermittivity;
ChargeDensity = chargeDensity;
- // Create nodes and elements
+ // Create nodes and elements
Nodes = new Node[elementCount + 1];
Elements = new Element[elementCount];
@@ -466,7 +465,7 @@ namespace MathNet.Numerics.UnitTests.Providers.SparseSolver.Double
// Imposition of Dirichlet boundary conditions
//
- // If xn is given, i.e. x2 = b0, then the linear equations,
+ // If xn is given, i.e. x2 = b0, then the linear equations,
// [ K11 K12 K13 K14 ][ x1 ] = [ b1 ]
// [ K21 K22 K23 K24 ][ x2 ] [ b2 ]
// [ K31 K32 K33 K34 ][ x3 ] [ b3 ]
@@ -579,7 +578,6 @@ namespace MathNet.Numerics.UnitTests.Providers.SparseSolver.Double
}
#endif
-#endif
}
diff --git a/src/Numerics.Tests/StatisticsTests/StatisticsTests.cs b/src/Numerics.Tests/StatisticsTests/StatisticsTests.cs
index 00a834e8..ca140f58 100644
--- a/src/Numerics.Tests/StatisticsTests/StatisticsTests.cs
+++ b/src/Numerics.Tests/StatisticsTests/StatisticsTests.cs
@@ -1004,9 +1004,6 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests
Assert.That(new RunningStatistics(new[] { 2d, 3d }).PopulationVariance, Is.Not.NaN);
}
- ///
- /// URL http://mathnetnumerics.codeplex.com/workitem/5667
- ///
[Test]
public void Median_CodeplexIssue5667()
{
diff --git a/src/Numerics.Tests/UseLinearAlgebraProvider.cs b/src/Numerics.Tests/UseLinearAlgebraProvider.cs
index d2dbed04..94a4c2b3 100644
--- a/src/Numerics.Tests/UseLinearAlgebraProvider.cs
+++ b/src/Numerics.Tests/UseLinearAlgebraProvider.cs
@@ -28,10 +28,17 @@
//
using System;
-using MathNet.Numerics.Providers.Common.Mkl;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
+#if MKL
+using MathNet.Numerics.Providers.MKL;
+#elif CUDA
+using MathNet.Numerics.Providers.CUDA;
+#elif OPENBLAS
+using MathNet.Numerics.Providers.OpenBLAS;
+#endif
+
namespace MathNet.Numerics.UnitTests
{
[AttributeUsage(AttributeTargets.Assembly)]
@@ -39,19 +46,14 @@ namespace MathNet.Numerics.UnitTests
{
public void BeforeTest(ITest testDetails)
{
-
-#if NATIVE
string outDir = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), @"../../../../../out/");
#if MKL
Control.NativeProviderPath = System.IO.Path.Combine(outDir, @"MKL/Windows/");
- Control.UseNativeMKL(MklConsistency.AVX, MklPrecision.Double, MklAccuracy.High);
+ MklControl.UseNativeMKL(MklConsistency.AVX, MklPrecision.Double, MklAccuracy.High);
#elif CUDA
- Control.UseNativeCUDA();
+ CudaControl.UseNativeCUDA();
#elif OPENBLAS
- Control.UseNativeOpenBLAS();
-#else
- Control.UseManaged();
-#endif
+ OpenBlasControl.UseNativeOpenBLAS();
#else
Control.UseManaged();
#endif
diff --git a/src/Numerics/AppSwitches.cs b/src/Numerics/AppSwitches.cs
index ce8f9246..430f4679 100644
--- a/src/Numerics/AppSwitches.cs
+++ b/src/Numerics/AppSwitches.cs
@@ -1,8 +1,7 @@
//
// Math.NET Numerics, part of the Math.NET Project
-// https://numerics.mathdotnet.com
-// https://github.com/mathnet/mathnet-numerics
-// https://mathnetnumerics.codeplex.com
+// http://numerics.mathdotnet.com
+// http://github.com/mathnet/mathnet-numerics
//
// Copyright (c) 2009-2020 Math.NET
//
@@ -44,7 +43,6 @@ namespace MathNet.Numerics
const string AppSwitchDisableNativeProviderProbing = "Switch.MathNet.Numerics.Providers.DisableNativeProviderProbing";
const string AppSwitchDisableNativeProviders = "Switch.MathNet.Numerics.Providers.DisableNativeProviders";
const string AppSwitchDisableMklNativeProvider = "Switch.MathNet.Numerics.Providers.DisableMklNativeProvider";
- const string AppSwitchDisableAcmlNativeProvider = "Switch.MathNet.Numerics.Providers.DisableAcmlNativeProvider";
const string AppSwitchDisableCudaNativeProvider = "Switch.MathNet.Numerics.Providers.DisableCudaNativeProvider";
const string AppSwitchDisableOpenBlasNativeProvider = "Switch.MathNet.Numerics.Providers.DisableOpenBlasNativeProvider";
@@ -88,12 +86,6 @@ namespace MathNet.Numerics
set => SetSwitch(AppSwitchDisableMklNativeProvider, value);
}
- public static bool DisableAcmlNativeProvider
- {
- get => IsEnabled(AppSwitchDisableAcmlNativeProvider);
- set => SetSwitch(AppSwitchDisableAcmlNativeProvider, value);
- }
-
public static bool DisableCudaNativeProvider
{
get => IsEnabled(AppSwitchDisableCudaNativeProvider);
diff --git a/src/Numerics/Control.cs b/src/Numerics/Control.cs
index 484c350f..8b37f1bd 100644
--- a/src/Numerics/Control.cs
+++ b/src/Numerics/Control.cs
@@ -3,7 +3,7 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
//
-// Copyright (c) 2009-2018 Math.NET
+// Copyright (c) 2009-2021 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@@ -114,8 +114,6 @@ namespace MathNet.Numerics
SparseSolverControl.UseBest();
}
-#if NATIVE
-
///
/// Use the Intel MKL native provider for linear algebra.
/// Throws if it is not available or failed to initialize, in which case the previous provider is still active.
@@ -127,20 +125,6 @@ namespace MathNet.Numerics
SparseSolverControl.UseNativeMKL();
}
- ///
- /// Use the Intel MKL native provider for linear algebra, with the specified configuration parameters.
- /// Throws if it is not available or failed to initialize, in which case the previous provider is still active.
- ///
- [CLSCompliant(false)]
- public static void UseNativeMKL(
- Providers.Common.Mkl.MklConsistency consistency = Providers.Common.Mkl.MklConsistency.Auto,
- Providers.Common.Mkl.MklPrecision precision = Providers.Common.Mkl.MklPrecision.Double,
- Providers.Common.Mkl.MklAccuracy accuracy = Providers.Common.Mkl.MklAccuracy.High)
- {
- LinearAlgebraControl.UseNativeMKL(consistency, precision, accuracy);
- FourierTransformControl.UseNativeMKL();
- SparseSolverControl.UseNativeMKL();
- }
///
/// Try to use the Intel MKL native provider for linear algebra.
@@ -220,7 +204,6 @@ namespace MathNet.Numerics
bool directSparseSolver = SparseSolverControl.TryUseNative();
return linearAlgebra || fourierTransform || directSparseSolver;
}
-#endif
public static void FreeResources()
{
@@ -351,9 +334,7 @@ namespace MathNet.Numerics
#elif NET40
sb.AppendLine("Built for .Net Framework 4.0");
#endif
-#if !NATIVE
- sb.AppendLine("No Native Provider Support");
-#endif
+
sb.AppendLine($"Linear Algebra Provider: {LinearAlgebraControl.Provider}");
sb.AppendLine($"Fourier Transform Provider: {FourierTransformControl.Provider}");
sb.AppendLine($"Sparse Solver Provider: {SparseSolverControl.Provider}");
diff --git a/src/Numerics/Providers/FourierTransform/FourierTransformControl.cs b/src/Numerics/Providers/FourierTransform/FourierTransformControl.cs
index ae755db7..5d1e18fb 100644
--- a/src/Numerics/Providers/FourierTransform/FourierTransformControl.cs
+++ b/src/Numerics/Providers/FourierTransform/FourierTransformControl.cs
@@ -3,7 +3,7 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
//
-// Copyright (c) 2009-2020 Math.NET
+// Copyright (c) 2009-2021 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@@ -34,11 +34,20 @@ namespace MathNet.Numerics.Providers.FourierTransform
public static class FourierTransformControl
{
const string EnvVarFFTProvider = "MathNetNumericsFFTProvider";
- const string EnvVarFFTProviderPath = "MathNetNumericsFFTProviderPath";
static IFourierTransformProvider _fourierTransformProvider;
static readonly object StaticLock = new object();
+ const string MklTypeName = "MathNet.Numerics.Providers.MKL.FourierTransform.MklFourierTransformControl, MathNet.Numerics.Providers.MKL";
+ static readonly ProviderProbe MklProbe = new ProviderProbe(MklTypeName, AppSwitches.DisableMklNativeProvider);
+
+ ///
+ /// Optional path to try to load native provider binaries from.
+ /// If not set, Numerics will fall back to the environment variable
+ /// `MathNetNumericsFFTProviderPath` or the default probing paths.
+ ///
+ public static string HintPath { get; set; }
+
///
/// Gets or sets the Fourier transform provider. Consider to use UseNativeMKL or UseManaged instead.
///
@@ -69,38 +78,12 @@ namespace MathNet.Numerics.Providers.FourierTransform
}
}
- ///
- /// Optional path to try to load native provider binaries from.
- /// If not set, Numerics will fall back to the environment variable
- /// `MathNetNumericsFFTProviderPath` or the default probing paths.
- ///
- public static string HintPath { get; set; }
-
- public static IFourierTransformProvider CreateManaged()
- {
- return new Managed.ManagedFourierTransformProvider();
- }
-
- public static void UseManaged()
- {
- Provider = CreateManaged();
- }
-
-#if NATIVE
- public static IFourierTransformProvider CreateNativeMKL()
- {
- return new Mkl.MklFourierTransformProvider(GetCombinedHintPath());
- }
+ public static IFourierTransformProvider CreateManaged() => new Managed.ManagedFourierTransformProvider();
+ public static void UseManaged() => Provider = CreateManaged();
- public static void UseNativeMKL()
- {
- Provider = CreateNativeMKL();
- }
+ public static void UseNativeMKL() => Provider = MklProbe.Create();
+ public static bool TryUseNativeMKL() => TryUse(MklProbe.TryCreate());
- public static bool TryUseNativeMKL()
- {
- return TryUse(CreateNativeMKL());
- }
///
/// Try to use a native provider, if available.
@@ -114,13 +97,12 @@ namespace MathNet.Numerics.Providers.FourierTransform
return TryUseNativeMKL();
}
-#endif
- static bool TryUse(IFourierTransformProvider provider)
+ public static bool TryUse(IFourierTransformProvider provider)
{
try
{
- if (!provider.IsAvailable())
+ if (provider == null || !provider.IsAvailable())
{
return false;
}
@@ -146,14 +128,10 @@ namespace MathNet.Numerics.Providers.FourierTransform
return;
}
-#if NATIVE
if (!TryUseNative())
{
UseManaged();
}
-#else
- UseManaged();
-#endif
}
///
@@ -169,7 +147,6 @@ namespace MathNet.Numerics.Providers.FourierTransform
return;
}
-#if NATIVE
var value = Environment.GetEnvironmentVariable(EnvVarFFTProvider);
switch (value != null ? value.ToUpperInvariant() : string.Empty)
{
@@ -182,30 +159,8 @@ namespace MathNet.Numerics.Providers.FourierTransform
UseBest();
break;
}
-#else
- UseBest();
-#endif
}
- public static void FreeResources()
- {
- Provider.FreeResources();
- }
-
- static string GetCombinedHintPath()
- {
- if (!String.IsNullOrEmpty(HintPath))
- {
- return HintPath;
- }
-
- var value = Environment.GetEnvironmentVariable(EnvVarFFTProviderPath);
- if (!String.IsNullOrEmpty(value))
- {
- return value;
- }
-
- return null;
- }
+ public static void FreeResources() => Provider.FreeResources();
}
}
diff --git a/src/Numerics/Providers/IProviderCreator.cs b/src/Numerics/Providers/IProviderCreator.cs
new file mode 100644
index 00000000..5f76805f
--- /dev/null
+++ b/src/Numerics/Providers/IProviderCreator.cs
@@ -0,0 +1,36 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// https://numerics.mathdotnet.com
+// https://github.com/mathnet/mathnet-numerics
+//
+// Copyright (c) 2009-2021 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace MathNet.Numerics.Providers
+{
+ public interface IProviderCreator where T : class
+ {
+ T CreateProvider();
+ }
+}
diff --git a/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.Complex.cs b/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.Complex.cs
deleted file mode 100644
index ca94ec59..00000000
--- a/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.Complex.cs
+++ /dev/null
@@ -1,1092 +0,0 @@
-//
-// Math.NET Numerics, part of the Math.NET Project
-// http://numerics.mathdotnet.com
-// http://github.com/mathnet/mathnet-numerics
-// Copyright (c) 2009-2011 Math.NET
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#if NATIVEACML
-
-using MathNet.Numerics.LinearAlgebra.Factorization;
-using System;
-using System.Security;
-using Complex = System.Numerics.Complex;
-
-namespace MathNet.Numerics.Providers.LinearAlgebra.Acml
-{
- ///
- /// AMD Core Math Library (ACML) linear algebra provider.
- ///
- internal partial class AcmlLinearAlgebraProvider : ManagedLinearAlgebraProvider
- {
- ///
- /// Computes the dot product of x and y.
- ///
- /// The vector x.
- /// The vector y.
- /// The dot product of x and y.
- /// This is equivalent to the DOT BLAS routine.
- [SecuritySafeCritical]
- public override Complex DotProduct(Complex[] x, Complex[] y)
- {
- if (y == null)
- {
- throw new ArgumentNullException(nameof(y));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(x));
- }
-
- if (x.Length != y.Length)
- {
- throw new ArgumentException("The array arguments must have the same length.");
- }
-
- return SafeNativeMethods.z_dot_product(x.Length, x, y);
- }
-
- ///
- /// Adds a scaled vector to another: result = y + alpha*x.
- ///
- /// The vector to update.
- /// The value to scale by.
- /// The vector to add to .
- /// The result of the addition.
- /// This is similar to the AXPY BLAS routine.
- [SecuritySafeCritical]
- public override void AddVectorToScaledVector(Complex[] y, Complex alpha, Complex[] x, Complex[] result)
- {
- if (y == null)
- {
- throw new ArgumentNullException(nameof(y));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(x));
- }
-
- if (y.Length != x.Length)
- {
- throw new ArgumentException("All vectors must have the same dimensionality.");
- }
-
- if (!ReferenceEquals(y, result))
- {
- Array.Copy(y, 0, result, 0, y.Length);
- }
-
- if (alpha == Complex.Zero)
- {
- return;
- }
-
- SafeNativeMethods.z_axpy(y.Length, alpha, x, result);
- }
-
- ///
- /// Scales an array. Can be used to scale a vector and a matrix.
- ///
- /// The scalar.
- /// The values to scale.
- /// This result of the scaling.
- /// This is similar to the SCAL BLAS routine.
- [SecuritySafeCritical]
- public override void ScaleArray(Complex alpha, Complex[] x, Complex[] result)
- {
- if (x == null)
- {
- throw new ArgumentNullException(nameof(x));
- }
-
- if (!ReferenceEquals(x, result))
- {
- Array.Copy(x, 0, result, 0, x.Length);
- }
-
- if (alpha == Complex.One)
- {
- return;
- }
-
- SafeNativeMethods.z_scale(x.Length, alpha, result);
- }
-
- ///
- /// Multiples two matrices. result = x * y
- ///
- /// The x matrix.
- /// The number of rows in the x matrix.
- /// The number of columns in the x matrix.
- /// The y matrix.
- /// The number of rows in the y matrix.
- /// The number of columns in the y matrix.
- /// Where to store the result of the multiplication.
- /// This is a simplified version of the BLAS GEMM routine with alpha
- /// set to Complex.One and beta set to Complex.Zero, and x and y are not transposed.
- public override void MatrixMultiply(Complex[] x, int rowsX, int columnsX, Complex[] y, int rowsY, int columnsY, Complex[] result)
- {
- MatrixMultiplyWithUpdate(Transpose.DontTranspose, Transpose.DontTranspose, Complex.One, x, rowsX, columnsX, y, rowsY, columnsY, Complex.Zero, result);
- }
-
- ///
- /// Multiplies two matrices and updates another with the result. c = alpha*op(a)*op(b) + beta*c
- ///
- /// How to transpose the matrix.
- /// How to transpose the matrix.
- /// The value to scale matrix.
- /// The a matrix.
- /// The number of rows in the matrix.
- /// The number of columns in the matrix.
- /// The b matrix
- /// The number of rows in the matrix.
- /// The number of columns in the matrix.
- /// The value to scale the matrix.
- /// The c matrix.
- [SecuritySafeCritical]
- public override void MatrixMultiplyWithUpdate(Transpose transposeA, Transpose transposeB, Complex alpha, Complex[] a, int rowsA, int columnsA, Complex[] b, int rowsB, int columnsB, Complex beta, Complex[] c)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(b));
- }
-
- if (c == null)
- {
- throw new ArgumentNullException(nameof(c));
- }
-
- var m = transposeA == Transpose.DontTranspose ? rowsA : columnsA;
- var n = transposeB == Transpose.DontTranspose ? columnsB : rowsB;
- var k = transposeA == Transpose.DontTranspose ? columnsA : rowsA;
- var l = transposeB == Transpose.DontTranspose ? rowsB : columnsB;
-
- if (c.Length != m*n)
- {
- throw new ArgumentException("Matrix dimensions must agree.");
- }
-
- if (k != l)
- {
- throw new ArgumentException("Matrix dimensions must agree.");
- }
-
- SafeNativeMethods.z_matrix_multiply(transposeA, transposeB, m, n, k, alpha, a, b, beta, c);
- }
-
- ///
- /// Computes the LUP factorization of A. P*A = L*U.
- ///
- /// An by matrix. The matrix is overwritten with the
- /// the LU factorization on exit. The lower triangular factor L is stored in under the diagonal of (the diagonal is always Complex.One
- /// for the L factor). The upper triangular factor U is stored on and above the diagonal of .
- /// The order of the square matrix .
- /// On exit, it contains the pivot indices. The size of the array must be .
- /// This is equivalent to the GETRF LAPACK routine.
- [SecuritySafeCritical]
- public override void LUFactor(Complex[] data, int order, int[] ipiv)
- {
- if (data == null)
- {
- throw new ArgumentNullException(nameof(data));
- }
-
- if (ipiv == null)
- {
- throw new ArgumentNullException(nameof(ipiv));
- }
-
- if (data.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(data));
- }
-
- if (ipiv.Length != order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(ipiv));
- }
-
- SafeNativeMethods.z_lu_factor(order, data, ipiv);
- }
-
- ///
- /// Computes the inverse of matrix using LU factorization.
- ///
- /// The N by N matrix to invert. Contains the inverse On exit.
- /// The order of the square matrix .
- /// This is equivalent to the GETRF and GETRI LAPACK routines.
- [SecuritySafeCritical]
- public override void LUInverse(Complex[] a, int order)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- var work = new Complex[order];
- SafeNativeMethods.z_lu_inverse(order, a, work, work.Length);
- }
-
- ///
- /// Computes the inverse of a previously factored matrix.
- ///
- /// The LU factored N by N matrix. Contains the inverse On exit.
- /// The order of the square matrix .
- /// The pivot indices of .
- /// This is equivalent to the GETRI LAPACK routine.
- [SecuritySafeCritical]
- public override void LUInverseFactored(Complex[] a, int order, int[] ipiv)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (ipiv == null)
- {
- throw new ArgumentNullException(nameof(ipiv));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (ipiv.Length != order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(ipiv));
- }
-
- var work = new Complex[order];
- SafeNativeMethods.z_lu_inverse_factored(order, a, ipiv, work, order);
- }
-
- ///
- /// Computes the inverse of matrix using LU factorization.
- ///
- /// The N by N matrix to invert. Contains the inverse On exit.
- /// The order of the square matrix .
- /// The work array. The array must have a length of at least N,
- /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal
- /// work size value.
- /// This is equivalent to the GETRF and GETRI LAPACK routines.
- [SecuritySafeCritical]
- public override void LUInverse(Complex[] a, int order, Complex[] work)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (work == null)
- {
- throw new ArgumentNullException(nameof(work));
- }
-
- if (work.Length < order)
- {
- throw new ArgumentException(Resources.WorkArrayTooSmall, nameof(work));
- }
-
- SafeNativeMethods.z_lu_inverse(order, a, work, work.Length);
- }
-
- ///
- /// Computes the inverse of a previously factored matrix.
- ///
- /// The LU factored N by N matrix. Contains the inverse On exit.
- /// The order of the square matrix .
- /// The pivot indices of .
- /// The work array. The array must have a length of at least N,
- /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal
- /// work size value.
- /// This is equivalent to the GETRI LAPACK routine.
- [SecuritySafeCritical]
- public override void LUInverseFactored(Complex[] a, int order, int[] ipiv, Complex[] work)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (ipiv == null)
- {
- throw new ArgumentNullException(nameof(ipiv));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (ipiv.Length != order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(ipiv));
- }
-
- if (work == null)
- {
- throw new ArgumentNullException(nameof(work));
- }
-
- if (work.Length < order)
- {
- throw new ArgumentException(Resources.WorkArrayTooSmall, nameof(work));
- }
-
- SafeNativeMethods.z_lu_inverse_factored(order, a, ipiv, work, order);
- }
-
- ///
- /// Solves A*X=B for X using LU factorization.
- ///
- /// The number of columns of B.
- /// The square matrix A.
- /// The order of the square matrix .
- /// On entry the B matrix; on exit the X matrix.
- /// This is equivalent to the GETRF and GETRS LAPACK routines.
- [SecuritySafeCritical]
- public override void LUSolve(int columnsOfB, Complex[] a, int order, Complex[] b)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (b.Length != columnsOfB*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (ReferenceEquals(a, b))
- {
- throw new ArgumentException("Arguments must be different objects.");
- }
-
- SafeNativeMethods.z_lu_solve(order, columnsOfB, a, b);
- }
-
- ///
- /// Solves A*X=B for X using a previously factored A matrix.
- ///
- /// The number of columns of B.
- /// The factored A matrix.
- /// The order of the square matrix .
- /// The pivot indices of .
- /// On entry the B matrix; on exit the X matrix.
- /// This is equivalent to the GETRS LAPACK routine.
- [SecuritySafeCritical]
- public override void LUSolveFactored(int columnsOfB, Complex[] a, int order, int[] ipiv, Complex[] b)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (ipiv == null)
- {
- throw new ArgumentNullException(nameof(ipiv));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (ipiv.Length != order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(ipiv));
- }
-
- if (b.Length != columnsOfB*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (ReferenceEquals(a, b))
- {
- throw new ArgumentException("Arguments must be different objects.");
- }
-
- SafeNativeMethods.z_lu_solve_factored(order, columnsOfB, a, ipiv, b);
- }
-
- ///
- /// Computes the Cholesky factorization of A.
- ///
- /// On entry, a square, positive definite matrix. On exit, the matrix is overwritten with the
- /// the Cholesky factorization.
- /// The number of rows or columns in the matrix.
- /// This is equivalent to the POTRF LAPACK routine.
- [SecuritySafeCritical]
- public override void CholeskyFactor(Complex[] a, int order)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (order < 1)
- {
- throw new ArgumentException("Value must be positive.", nameof(order));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- var info = SafeNativeMethods.z_cholesky_factor(order, a);
-
- if (info > 0)
- {
- throw new ArgumentException("Matrix must be positive definite.");
- }
- }
-
- ///
- /// Solves A*X=B for X using Cholesky factorization.
- ///
- /// The square, positive definite matrix A.
- /// The number of rows and columns in A.
- /// On entry the B matrix; on exit the X matrix.
- /// The number of columns in the B matrix.
- /// This is equivalent to the POTRF add POTRS LAPACK routines.
- ///
- [SecuritySafeCritical]
- public override void CholeskySolve(Complex[] a, int orderA, Complex[] b, int columnsB)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(b));
- }
-
- if (b.Length != orderA*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (ReferenceEquals(a, b))
- {
- throw new ArgumentException("Arguments must be different objects.");
- }
-
- SafeNativeMethods.z_cholesky_solve(orderA, columnsB, a, b);
- }
-
- ///
- /// Solves A*X=B for X using a previously factored A matrix.
- ///
- /// The square, positive definite matrix A.
- /// The number of rows and columns in A.
- /// On entry the B matrix; on exit the X matrix.
- /// The number of columns in the B matrix.
- /// This is equivalent to the POTRS LAPACK routine.
- [SecuritySafeCritical]
- public override void CholeskySolveFactored(Complex[] a, int orderA, Complex[] b, int columnsB)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(b));
- }
-
- if (b.Length != orderA*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (ReferenceEquals(a, b))
- {
- throw new ArgumentException("Arguments must be different objects.");
- }
-
- SafeNativeMethods.z_cholesky_solve_factored(orderA, columnsB, a, b);
- }
-
- ///
- /// Computes the QR factorization of A.
- ///
- /// On entry, it is the M by N A matrix to factor. On exit,
- /// it is overwritten with the R matrix of the QR factorization.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// On exit, A M by M matrix that holds the Q matrix of the
- /// QR factorization.
- /// A min(m,n) vector. On exit, contains additional information
- /// to be used by the QR solve routine.
- /// This is similar to the GEQRF and ORGQR LAPACK routines.
- [SecuritySafeCritical]
- public override void QRFactor(Complex[] r, int rowsR, int columnsR, Complex[] q, Complex[] tau)
- {
- if (r == null)
- {
- throw new ArgumentNullException(nameof(r));
- }
-
- if (q == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (r.Length != rowsR*columnsR)
- {
- throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r");
- }
-
- if (tau.Length < Math.Min(rowsR, columnsR))
- {
- throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau");
- }
-
- if (q.Length != rowsR*rowsR)
- {
- throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q");
- }
-
- var work = new Complex[columnsR*Control.BlockSize];
- SafeNativeMethods.z_qr_factor(rowsR, columnsR, r, tau, q, work, work.Length);
- }
-
- ///
- /// Computes the QR factorization of A.
- ///
- /// On entry, it is the M by N A matrix to factor. On exit,
- /// it is overwritten with the R matrix of the QR factorization.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// On exit, A M by M matrix that holds the Q matrix of the
- /// QR factorization.
- /// A min(m,n) vector. On exit, contains additional information
- /// to be used by the QR solve routine.
- /// The work array. The array must have a length of at least N,
- /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal
- /// work size value.
- /// This is similar to the GEQRF and ORGQR LAPACK routines.
- [SecuritySafeCritical]
- public override void QRFactor(Complex[] r, int rowsR, int columnsR, Complex[] q, Complex[] tau, Complex[] work)
- {
- if (r == null)
- {
- throw new ArgumentNullException(nameof(r));
- }
-
- if (q == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (work == null)
- {
- throw new ArgumentNullException(nameof(work));
- }
-
- if (r.Length != rowsR*columnsR)
- {
- throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r");
- }
-
- if (tau.Length < Math.Min(rowsR, columnsR))
- {
- throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau");
- }
-
- if (q.Length != rowsR*rowsR)
- {
- throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q");
- }
-
- if (work.Length < columnsR*Control.BlockSize)
- {
- work[0] = columnsR*Control.BlockSize;
- throw new ArgumentException(Resources.WorkArrayTooSmall, nameof(work));
- }
-
- SafeNativeMethods.z_qr_factor(rowsR, columnsR, r, tau, q, work, work.Length);
- }
-
- ///
- /// Solves A*X=B for X using QR factorization of A.
- ///
- /// The A matrix.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// The B matrix.
- /// The number of columns of B.
- /// On exit, the solution matrix.
- /// Rows must be greater or equal to columns.
- public override void QRSolve(Complex[] a, int rows, int columns, Complex[] b, int columnsB, Complex[] x, QRMethod method = QRMethod.Full)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(b));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(x));
- }
-
- if (a.Length != rows*columns)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (b.Length != rows*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (x.Length != columns*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(x));
- }
-
- if (rows < columns)
- {
- throw new ArgumentException(Resources.RowsLessThanColumns);
- }
-
- var work = new Complex[columns*Control.BlockSize];
- QRSolve(a, rows, columns, b, columnsB, x, work);
- }
-
- ///
- /// Solves A*X=B for X using QR factorization of A.
- ///
- /// The A matrix.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// The B matrix.
- /// The number of columns of B.
- /// On exit, the solution matrix.
- /// The work array. The array must have a length of at least N,
- /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal
- /// work size value.
- /// Rows must be greater or equal to columns.
- public override void QRSolve(Complex[] a, int rows, int columns, Complex[] b, int columnsB, Complex[] x, Complex[] work, QRMethod method = QRMethod.Full)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(b));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(x));
- }
-
- if (work == null)
- {
- throw new ArgumentNullException(nameof(work));
- }
-
- if (a.Length != rows*columns)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (b.Length != rows*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (x.Length != columns*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(x));
- }
-
- if (rows < columns)
- {
- throw new ArgumentException(Resources.RowsLessThanColumns);
- }
-
- if (work.Length < 1)
- {
- work[0] = rows*Control.BlockSize;
- throw new ArgumentException(Resources.WorkArrayTooSmall, nameof(work));
- }
-
- SafeNativeMethods.z_qr_solve(rows, columns, columnsB, a, b, x, work, work.Length);
- }
-
- ///
- /// Solves A*X=B for X using a previously QR factored matrix.
- ///
- /// The Q matrix obtained by calling .
- /// The R matrix obtained by calling .
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// Contains additional information on Q. Only used for the native solver
- /// and can be null for the managed provider.
- /// The B matrix.
- /// The number of columns of B.
- /// On exit, the solution matrix.
- /// Rows must be greater or equal to columns.
- [SecuritySafeCritical]
- public override void QRSolveFactored(Complex[] q, Complex[] r, int rowsR, int columnsR, Complex[] tau, Complex[] b, int columnsB, Complex[] x, QRMethod method = QRMethod.Full)
- {
- if (r == null)
- {
- throw new ArgumentNullException(nameof(r));
- }
-
- if (q == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (r.Length != rowsR*columnsR)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(r));
- }
-
- if (q.Length != rowsR*rowsR)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(q));
- }
-
- if (b.Length != rowsR*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (x.Length != columnsR*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(x));
- }
-
- if (rowsR < columnsR)
- {
- throw new ArgumentException(Resources.RowsLessThanColumns);
- }
-
- var work = new Complex[columnsR*Control.BlockSize];
- QRSolveFactored(q, r, rowsR, columnsR, tau, b, columnsB, x, work);
- }
-
- ///
- /// Solves A*X=B for X using a previously QR factored matrix.
- ///
- /// The Q matrix obtained by QR factor. This is only used for the managed provider and can be
- /// null for the native provider. The native provider uses the Q portion stored in the R matrix.
- /// The R matrix obtained by calling .
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// Contains additional information on Q. Only used for the native solver
- /// and can be null for the managed provider.
- /// On entry the B matrix; on exit the X matrix.
- /// The number of columns of B.
- /// On exit, the solution matrix.
- /// The work array - only used in the native provider. The array must have a length of at least N,
- /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal
- /// work size value.
- /// Rows must be greater or equal to columns.
- public override void QRSolveFactored(Complex[] q, Complex[] r, int rowsR, int columnsR, Complex[] tau, Complex[] b, int columnsB, Complex[] x, Complex[] work, QRMethod method = QRMethod.Full)
- {
- if (r == null)
- {
- throw new ArgumentNullException(nameof(r));
- }
-
- if (q == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (work == null)
- {
- throw new ArgumentNullException(nameof(work));
- }
-
- if (r.Length != rowsR*columnsR)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(r));
- }
-
- if (q.Length != rowsR*rowsR)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(q));
- }
-
- if (b.Length != rowsR*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (x.Length != columnsR*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(x));
- }
-
- if (rowsR < columnsR)
- {
- throw new ArgumentException(Resources.RowsLessThanColumns);
- }
-
- if (work.Length < 1)
- {
- work[0] = rowsR*Control.BlockSize;
- throw new ArgumentException(Resources.WorkArrayTooSmall, nameof(work));
- }
-
- SafeNativeMethods.z_qr_solve_factored(rowsR, columnsR, columnsB, r, b, tau, x, work, work.Length);
- }
-
- ///
- /// Computes the singular value decomposition of A.
- ///
- /// Compute the singular U and VT vectors or not.
- /// On entry, the M by N matrix to decompose. On exit, A may be overwritten.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// The singular values of A in ascending value.
- /// If is true, on exit U contains the left
- /// singular vectors.
- /// If is true, on exit VT contains the transposed
- /// right singular vectors.
- /// This is equivalent to the GESVD LAPACK routine.
- [SecuritySafeCritical]
- public override void SingularValueDecomposition(bool computeVectors, Complex[] a, int rowsA, int columnsA, Complex[] s, Complex[] u, Complex[] vt)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (s == null)
- {
- throw new ArgumentNullException(nameof(s));
- }
-
- if (u == null)
- {
- throw new ArgumentNullException(nameof(u));
- }
-
- if (vt == null)
- {
- throw new ArgumentNullException(nameof(vt));
- }
-
- if (u.Length != rowsA*rowsA)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(u));
- }
-
- if (vt.Length != columnsA*columnsA)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(vt));
- }
-
- if (s.Length != Math.Min(rowsA, columnsA))
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(s));
- }
-
- var work = new Complex[(2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)];
- SingularValueDecomposition(computeVectors, a, rowsA, columnsA, s, u, vt, work);
- }
-
- ///
- /// Solves A*X=B for X using the singular value decomposition of A.
- ///
- /// On entry, the M by N matrix to decompose.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// The B matrix.
- /// The number of columns of B.
- /// On exit, the solution matrix.
- public override void SvdSolve(Complex[] a, int rowsA, int columnsA, Complex[] b, int columnsB, Complex[] x)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(b));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(x));
- }
-
- if (b.Length != rowsA*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (x.Length != columnsA*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- var work = new Complex[(2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)];
- var s = new Complex[Math.Min(rowsA, columnsA)];
- var u = new Complex[rowsA*rowsA];
- var vt = new Complex[columnsA*columnsA];
-
- var clone = new Complex[a.Length];
- a.Copy(clone);
- SingularValueDecomposition(true, clone, rowsA, columnsA, s, u, vt, work);
- SvdSolveFactored(rowsA, columnsA, s, u, vt, b, columnsB, x);
- }
-
- ///
- /// Computes the singular value decomposition of A.
- ///
- /// Compute the singular U and VT vectors or not.
- /// On entry, the M by N matrix to decompose. On exit, A may be overwritten.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// The singular values of A in ascending value.
- /// If is true, on exit U contains the left
- /// singular vectors.
- /// If is true, on exit VT contains the transposed
- /// right singular vectors.
- /// The work array. For real matrices, the work array should be at least
- /// Max(3*Min(M, N) + Max(M, N), 5*Min(M,N)). For complex matrices, 2*Min(M, N) + Max(M, N).
- /// On exit, work[0] contains the optimal work size value.
- /// This is equivalent to the GESVD LAPACK routine.
- [SecuritySafeCritical]
- public override void SingularValueDecomposition(bool computeVectors, Complex[] a, int rowsA, int columnsA, Complex[] s, Complex[] u, Complex[] vt, Complex[] work)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (s == null)
- {
- throw new ArgumentNullException(nameof(s));
- }
-
- if (u == null)
- {
- throw new ArgumentNullException(nameof(u));
- }
-
- if (vt == null)
- {
- throw new ArgumentNullException(nameof(vt));
- }
-
- if (work == null)
- {
- throw new ArgumentNullException(nameof(work));
- }
-
- if (u.Length != rowsA*rowsA)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(u));
- }
-
- if (vt.Length != columnsA*columnsA)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(vt));
- }
-
- if (s.Length != Math.Min(rowsA, columnsA))
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(s));
- }
-
- if (work.Length == 0)
- {
- throw new ArgumentException(Resources.ArgumentSingleDimensionArray, nameof(work));
- }
-
- if (work.Length < (2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA))
- {
- work[0] = (2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA);
- throw new ArgumentException(Resources.WorkArrayTooSmall, nameof(work));
- }
-
- SafeNativeMethods.z_svd_factor(computeVectors, rowsA, columnsA, a, s, u, vt, work, work.Length);
- }
- }
-}
-
-#endif
diff --git a/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.Complex32.cs b/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.Complex32.cs
deleted file mode 100644
index 6fb0f9f6..00000000
--- a/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.Complex32.cs
+++ /dev/null
@@ -1,1095 +0,0 @@
-//
-// Math.NET Numerics, part of the Math.NET Project
-// http://numerics.mathdotnet.com
-// http://github.com/mathnet/mathnet-numerics
-//
-// Copyright (c) 2009-2011 Math.NET
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#if NATIVEACML
-
-using MathNet.Numerics.LinearAlgebra.Factorization;
-using System;
-using System.Security;
-
-namespace MathNet.Numerics.Providers.LinearAlgebra.Acml
-{
- ///
- /// AMD Core Math Library (ACML) linear algebra provider.
- ///
- internal partial class AcmlLinearAlgebraProvider
- {
- ///
- /// Computes the dot product of x and y.
- ///
- /// The vector x.
- /// The vector y.
- /// The dot product of x and y.
- /// This is equivalent to the DOT BLAS routine.
- [SecuritySafeCritical]
- public override Complex32 DotProduct(Complex32[] x, Complex32[] y)
- {
- if (y == null)
- {
- throw new ArgumentNullException(nameof(y));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(x));
- }
-
- if (x.Length != y.Length)
- {
- throw new ArgumentException("The array arguments must have the same length.");
- }
-
- return SafeNativeMethods.c_dot_product(x.Length, x, y);
- }
-
- ///
- /// Adds a scaled vector to another: result = y + alpha*x.
- ///
- /// The vector to update.
- /// The value to scale by.
- /// The vector to add to .
- /// The result of the addition.
- /// This is similar to the AXPY BLAS routine.
- [SecuritySafeCritical]
- public override void AddVectorToScaledVector(Complex32[] y, Complex32 alpha, Complex32[] x, Complex32[] result)
- {
- if (y == null)
- {
- throw new ArgumentNullException(nameof(y));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(x));
- }
-
- if (y.Length != x.Length)
- {
- throw new ArgumentException("All vectors must have the same dimensionality.");
- }
-
- if (!ReferenceEquals(y, result))
- {
- Array.Copy(y, 0, result, 0, y.Length);
- }
-
- if (alpha == Complex32.Zero)
- {
- return;
- }
-
- SafeNativeMethods.c_axpy(y.Length, alpha, x, result);
- }
-
- ///
- /// Scales an array. Can be used to scale a vector and a matrix.
- ///
- /// The scalar.
- /// The values to scale.
- /// This result of the scaling.
- /// This is similar to the SCAL BLAS routine.
- [SecuritySafeCritical]
- public override void ScaleArray(Complex32 alpha, Complex32[] x, Complex32[] result)
- {
- if (x == null)
- {
- throw new ArgumentNullException(nameof(x));
- }
-
- if (!ReferenceEquals(x, result))
- {
- Array.Copy(x, 0, result, 0, x.Length);
- }
-
- if (alpha == Complex32.One)
- {
- return;
- }
-
- SafeNativeMethods.c_scale(x.Length, alpha, result);
- }
-
- ///
- /// Multiples two matrices. result = x * y
- ///
- /// The x matrix.
- /// The number of rows in the x matrix.
- /// The number of columns in the x matrix.
- /// The y matrix.
- /// The number of rows in the y matrix.
- /// The number of columns in the y matrix.
- /// Where to store the result of the multiplication.
- /// This is a simplified version of the BLAS GEMM routine with alpha
- /// set to Complex32.One and beta set to Complex32.Zero, and x and y are not transposed.
- public override void MatrixMultiply(Complex32[] x, int rowsX, int columnsX, Complex32[] y, int rowsY, int columnsY, Complex32[] result)
- {
- MatrixMultiplyWithUpdate(Transpose.DontTranspose, Transpose.DontTranspose, Complex32.One, x, rowsX, columnsX, y, rowsY, columnsY, Complex32.Zero, result);
- }
-
- ///
- /// Multiplies two matrices and updates another with the result. c = alpha*op(a)*op(b) + beta*c
- ///
- /// How to transpose the matrix.
- /// How to transpose the matrix.
- /// The value to scale matrix.
- /// The a matrix.
- /// The number of rows in the matrix.
- /// The number of columns in the matrix.
- /// The b matrix
- /// The number of rows in the matrix.
- /// The number of columns in the matrix.
- /// The value to scale the matrix.
- /// The c matrix.
- [SecuritySafeCritical]
- public override void MatrixMultiplyWithUpdate(Transpose transposeA, Transpose transposeB, Complex32 alpha, Complex32[] a, int rowsA, int columnsA, Complex32[] b, int rowsB, int columnsB, Complex32 beta, Complex32[] c)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(b));
- }
-
- if (c == null)
- {
- throw new ArgumentNullException(nameof(c));
- }
-
- var m = transposeA == Transpose.DontTranspose ? rowsA : columnsA;
- var n = transposeB == Transpose.DontTranspose ? columnsB : rowsB;
- var k = transposeA == Transpose.DontTranspose ? columnsA : rowsA;
- var l = transposeB == Transpose.DontTranspose ? rowsB : columnsB;
-
- if (c.Length != m*n)
- {
- throw new ArgumentException("Matrix dimensions must agree.");
- }
-
- if (k != l)
- {
- throw new ArgumentException("Matrix dimensions must agree.");
- }
-
- SafeNativeMethods.c_matrix_multiply(transposeA, transposeB, m, n, k, alpha, a, b, beta, c);
- }
-
- ///
- /// Computes the LUP factorization of A. P*A = L*U.
- ///
- /// An by matrix. The matrix is overwritten with the
- /// the LU factorization on exit. The lower triangular factor L is stored in under the diagonal of (the diagonal is always Complex32.One
- /// for the L factor). The upper triangular factor U is stored on and above the diagonal of .
- /// The order of the square matrix .
- /// On exit, it contains the pivot indices. The size of the array must be .
- /// This is equivalent to the GETRF LAPACK routine.
- [SecuritySafeCritical]
- public override void LUFactor(Complex32[] data, int order, int[] ipiv)
- {
- if (data == null)
- {
- throw new ArgumentNullException(nameof(data));
- }
-
- if (ipiv == null)
- {
- throw new ArgumentNullException(nameof(ipiv));
- }
-
- if (data.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(data));
- }
-
- if (ipiv.Length != order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(ipiv));
- }
-
- SafeNativeMethods.c_lu_factor(order, data, ipiv);
- }
-
- ///
- /// Computes the inverse of matrix using LU factorization.
- ///
- /// The N by N matrix to invert. Contains the inverse On exit.
- /// The order of the square matrix .
- /// This is equivalent to the GETRF and GETRI LAPACK routines.
- [SecuritySafeCritical]
- public override void LUInverse(Complex32[] a, int order)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- var work = new Complex32[order];
- SafeNativeMethods.c_lu_inverse(order, a, work, work.Length);
- }
-
- ///
- /// Computes the inverse of a previously factored matrix.
- ///
- /// The LU factored N by N matrix. Contains the inverse On exit.
- /// The order of the square matrix .
- /// The pivot indices of .
- /// This is equivalent to the GETRI LAPACK routine.
- [SecuritySafeCritical]
- public override void LUInverseFactored(Complex32[] a, int order, int[] ipiv)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (ipiv == null)
- {
- throw new ArgumentNullException(nameof(ipiv));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (ipiv.Length != order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(ipiv));
- }
-
- var work = new Complex32[order];
- SafeNativeMethods.c_lu_inverse_factored(order, a, ipiv, work, order);
- }
-
- ///
- /// Computes the inverse of matrix using LU factorization.
- ///
- /// The N by N matrix to invert. Contains the inverse On exit.
- /// The order of the square matrix .
- /// The work array. The array must have a length of at least N,
- /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal
- /// work size value.
- /// This is equivalent to the GETRF and GETRI LAPACK routines.
- [SecuritySafeCritical]
- public override void LUInverse(Complex32[] a, int order, Complex32[] work)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (work == null)
- {
- throw new ArgumentNullException(nameof(work));
- }
-
- if (work.Length < order)
- {
- throw new ArgumentException(Resources.WorkArrayTooSmall, nameof(work));
- }
-
- SafeNativeMethods.c_lu_inverse(order, a, work, work.Length);
- }
-
- ///
- /// Computes the inverse of a previously factored matrix.
- ///
- /// The LU factored N by N matrix. Contains the inverse On exit.
- /// The order of the square matrix .
- /// The pivot indices of .
- /// The work array. The array must have a length of at least N,
- /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal
- /// work size value.
- /// This is equivalent to the GETRI LAPACK routine.
- [SecuritySafeCritical]
- public override void LUInverseFactored(Complex32[] a, int order, int[] ipiv, Complex32[] work)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (ipiv == null)
- {
- throw new ArgumentNullException(nameof(ipiv));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (ipiv.Length != order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(ipiv));
- }
-
- if (work == null)
- {
- throw new ArgumentNullException(nameof(work));
- }
-
- if (work.Length < order)
- {
- throw new ArgumentException(Resources.WorkArrayTooSmall, nameof(work));
- }
-
- SafeNativeMethods.c_lu_inverse_factored(order, a, ipiv, work, order);
- }
-
- ///
- /// Solves A*X=B for X using LU factorization.
- ///
- /// The number of columns of B.
- /// The square matrix A.
- /// The order of the square matrix .
- /// On entry the B matrix; on exit the X matrix.
- /// This is equivalent to the GETRF and GETRS LAPACK routines.
- [SecuritySafeCritical]
- public override void LUSolve(int columnsOfB, Complex32[] a, int order, Complex32[] b)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (b.Length != columnsOfB*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (ReferenceEquals(a, b))
- {
- throw new ArgumentException("Arguments must be different objects.");
- }
-
- SafeNativeMethods.c_lu_solve(order, columnsOfB, a, b);
- }
-
- ///
- /// Solves A*X=B for X using a previously factored A matrix.
- ///
- /// The number of columns of B.
- /// The factored A matrix.
- /// The order of the square matrix .
- /// The pivot indices of .
- /// On entry the B matrix; on exit the X matrix.
- /// This is equivalent to the GETRS LAPACK routine.
- [SecuritySafeCritical]
- public override void LUSolveFactored(int columnsOfB, Complex32[] a, int order, int[] ipiv, Complex32[] b)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (ipiv == null)
- {
- throw new ArgumentNullException(nameof(ipiv));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (ipiv.Length != order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(ipiv));
- }
-
- if (b.Length != columnsOfB*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (ReferenceEquals(a, b))
- {
- throw new ArgumentException("Arguments must be different objects.");
- }
-
- SafeNativeMethods.c_lu_solve_factored(order, columnsOfB, a, ipiv, b);
- }
-
- ///
- /// Computes the Cholesky factorization of A.
- ///
- /// On entry, a square, positive definite matrix. On exit, the matrix is overwritten with the
- /// the Cholesky factorization.
- /// The number of rows or columns in the matrix.
- /// This is equivalent to the POTRF LAPACK routine.
- [SecuritySafeCritical]
- public override void CholeskyFactor(Complex32[] a, int order)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (order < 1)
- {
- throw new ArgumentException("Value must be positive.", nameof(order));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- var info = SafeNativeMethods.c_cholesky_factor(order, a);
-
- if (info > 0)
- {
- throw new ArgumentException("Matrix must be positive definite.");
- }
- }
-
- ///
- /// Solves A*X=B for X using Cholesky factorization.
- ///
- /// The square, positive definite matrix A.
- /// The number of rows and columns in A.
- /// On entry the B matrix; on exit the X matrix.
- /// The number of columns in the B matrix.
- /// This is equivalent to the POTRF add POTRS LAPACK routines.
- ///
- [SecuritySafeCritical]
- public override void CholeskySolve(Complex32[] a, int orderA, Complex32[] b, int columnsB)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(b));
- }
-
- if (b.Length != orderA*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (ReferenceEquals(a, b))
- {
- throw new ArgumentException("Arguments must be different objects.");
- }
-
- SafeNativeMethods.c_cholesky_solve(orderA, columnsB, a, b);
- }
-
- ///
- /// Solves A*X=B for X using a previously factored A matrix.
- ///
- /// The square, positive definite matrix A.
- /// The number of rows and columns in A.
- /// On entry the B matrix; on exit the X matrix.
- /// The number of columns in the B matrix.
- /// This is equivalent to the POTRS LAPACK routine.
- [SecuritySafeCritical]
- public override void CholeskySolveFactored(Complex32[] a, int orderA, Complex32[] b, int columnsB)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(b));
- }
-
- if (b.Length != orderA*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (ReferenceEquals(a, b))
- {
- throw new ArgumentException("Arguments must be different objects.");
- }
-
- SafeNativeMethods.c_cholesky_solve_factored(orderA, columnsB, a, b);
- }
-
- ///
- /// Computes the QR factorization of A.
- ///
- /// On entry, it is the M by N A matrix to factor. On exit,
- /// it is overwritten with the R matrix of the QR factorization.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// On exit, A M by M matrix that holds the Q matrix of the
- /// QR factorization.
- /// A min(m,n) vector. On exit, contains additional information
- /// to be used by the QR solve routine.
- /// This is similar to the GEQRF and ORGQR LAPACK routines.
- [SecuritySafeCritical]
- public override void QRFactor(Complex32[] r, int rowsR, int columnsR, Complex32[] q, Complex32[] tau)
- {
- if (r == null)
- {
- throw new ArgumentNullException(nameof(r));
- }
-
- if (q == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (r.Length != rowsR*columnsR)
- {
- throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r");
- }
-
- if (tau.Length < Math.Min(rowsR, columnsR))
- {
- throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau");
- }
-
- if (q.Length != rowsR*rowsR)
- {
- throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q");
- }
-
- var work = new Complex32[columnsR*Control.BlockSize];
- SafeNativeMethods.c_qr_factor(rowsR, columnsR, r, tau, q, work, work.Length);
- }
-
- ///
- /// Computes the QR factorization of A.
- ///
- /// On entry, it is the M by N A matrix to factor. On exit,
- /// it is overwritten with the R matrix of the QR factorization.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// On exit, A M by M matrix that holds the Q matrix of the
- /// QR factorization.
- /// A min(m,n) vector. On exit, contains additional information
- /// to be used by the QR solve routine.
- /// The work array. The array must have a length of at least N,
- /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal
- /// work size value.
- /// This is similar to the GEQRF and ORGQR LAPACK routines.
- [SecuritySafeCritical]
- public override void QRFactor(Complex32[] r, int rowsR, int columnsR, Complex32[] q, Complex32[] tau, Complex32[] work)
- {
- if (r == null)
- {
- throw new ArgumentNullException(nameof(r));
- }
-
- if (q == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (work == null)
- {
- throw new ArgumentNullException(nameof(work));
- }
-
- if (r.Length != rowsR*columnsR)
- {
- throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r");
- }
-
- if (tau.Length < Math.Min(rowsR, columnsR))
- {
- throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau");
- }
-
- if (q.Length != rowsR*rowsR)
- {
- throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q");
- }
-
- if (work.Length < columnsR*Control.BlockSize)
- {
- work[0] = columnsR*Control.BlockSize;
- throw new ArgumentException(Resources.WorkArrayTooSmall, nameof(work));
- }
-
- SafeNativeMethods.c_qr_factor(rowsR, columnsR, r, tau, q, work, work.Length);
- }
-
- ///
- /// Solves A*X=B for X using QR factorization of A.
- ///
- /// The A matrix.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// The B matrix.
- /// The number of columns of B.
- /// On exit, the solution matrix.
- /// Rows must be greater or equal to columns.
- public override void QRSolve(Complex32[] a, int rows, int columns, Complex32[] b, int columnsB, Complex32[] x, QRMethod method = QRMethod.Full)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(b));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(x));
- }
-
- if (a.Length != rows*columns)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (b.Length != rows*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (x.Length != columns*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(x));
- }
-
- if (rows < columns)
- {
- throw new ArgumentException(Resources.RowsLessThanColumns);
- }
-
- var work = new Complex32[columns*Control.BlockSize];
- QRSolve(a, rows, columns, b, columnsB, x, work);
- }
-
- ///
- /// Solves A*X=B for X using QR factorization of A.
- ///
- /// The A matrix.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// The B matrix.
- /// The number of columns of B.
- /// On exit, the solution matrix.
- /// The work array. The array must have a length of at least N,
- /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal
- /// work size value.
- /// Rows must be greater or equal to columns.
- public override void QRSolve(Complex32[] a, int rows, int columns, Complex32[] b, int columnsB, Complex32[] x, Complex32[] work, QRMethod method = QRMethod.Full)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(b));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(x));
- }
-
- if (work == null)
- {
- throw new ArgumentNullException(nameof(work));
- }
-
- if (a.Length != rows*columns)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (b.Length != rows*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (x.Length != columns*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(x));
- }
-
- if (rows < columns)
- {
- throw new ArgumentException(Resources.RowsLessThanColumns);
- }
-
- if (work.Length < 1)
- {
- work[0] = rows*Control.BlockSize;
- throw new ArgumentException(Resources.WorkArrayTooSmall, nameof(work));
- }
-
- SafeNativeMethods.c_qr_solve(rows, columns, columnsB, a, b, x, work, work.Length);
- }
-
- ///
- /// Solves A*X=B for X using a previously QR factored matrix.
- ///
- /// The Q matrix obtained by calling .
- /// The R matrix obtained by calling .
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// Contains additional information on Q. Only used for the native solver
- /// and can be null for the managed provider.
- /// The B matrix.
- /// The number of columns of B.
- /// On exit, the solution matrix.
- /// Rows must be greater or equal to columns.
- [SecuritySafeCritical]
- public override void QRSolveFactored(Complex32[] q, Complex32[] r, int rowsR, int columnsR, Complex32[] tau, Complex32[] b, int columnsB, Complex32[] x, QRMethod method = QRMethod.Full)
- {
- if (r == null)
- {
- throw new ArgumentNullException(nameof(r));
- }
-
- if (q == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (r.Length != rowsR*columnsR)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(r));
- }
-
- if (q.Length != rowsR*rowsR)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(q));
- }
-
- if (b.Length != rowsR*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (x.Length != columnsR*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(x));
- }
-
- if (rowsR < columnsR)
- {
- throw new ArgumentException(Resources.RowsLessThanColumns);
- }
-
- var work = new Complex32[columnsR*Control.BlockSize];
- QRSolveFactored(q, r, rowsR, columnsR, tau, b, columnsB, x, work);
- }
-
- ///
- /// Solves A*X=B for X using a previously QR factored matrix.
- ///
- /// The Q matrix obtained by QR factor. This is only used for the managed provider and can be
- /// null for the native provider. The native provider uses the Q portion stored in the R matrix.
- /// The R matrix obtained by calling .
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// Contains additional information on Q. Only used for the native solver
- /// and can be null for the managed provider.
- /// On entry the B matrix; on exit the X matrix.
- /// The number of columns of B.
- /// On exit, the solution matrix.
- /// The work array - only used in the native provider. The array must have a length of at least N,
- /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal
- /// work size value.
- /// Rows must be greater or equal to columns.
- public override void QRSolveFactored(Complex32[] q, Complex32[] r, int rowsR, int columnsR, Complex32[] tau, Complex32[] b, int columnsB, Complex32[] x, Complex32[] work, QRMethod method = QRMethod.Full)
- {
- if (r == null)
- {
- throw new ArgumentNullException(nameof(r));
- }
-
- if (q == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (work == null)
- {
- throw new ArgumentNullException(nameof(work));
- }
-
- if (r.Length != rowsR*columnsR)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(r));
- }
-
- if (q.Length != rowsR*rowsR)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(q));
- }
-
- if (b.Length != rowsR*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (x.Length != columnsR*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(x));
- }
-
- if (rowsR < columnsR)
- {
- throw new ArgumentException(Resources.RowsLessThanColumns);
- }
-
- if (work.Length < 1)
- {
- work[0] = rowsR*Control.BlockSize;
- throw new ArgumentException(Resources.WorkArrayTooSmall, nameof(work));
- }
-
- SafeNativeMethods.c_qr_solve_factored(rowsR, columnsR, columnsB, r, b, tau, x, work, work.Length);
- }
-
- ///
- /// Computes the singular value decomposition of A.
- ///
- /// Compute the singular U and VT vectors or not.
- /// On entry, the M by N matrix to decompose. On exit, A may be overwritten.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// The singular values of A in ascending value.
- /// If is true, on exit U contains the left
- /// singular vectors.
- /// If is true, on exit VT contains the transposed
- /// right singular vectors.
- /// This is equivalent to the GESVD LAPACK routine.
- [SecuritySafeCritical]
- public override void SingularValueDecomposition(bool computeVectors, Complex32[] a, int rowsA, int columnsA, Complex32[] s, Complex32[] u, Complex32[] vt)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (s == null)
- {
- throw new ArgumentNullException(nameof(s));
- }
-
- if (u == null)
- {
- throw new ArgumentNullException(nameof(u));
- }
-
- if (vt == null)
- {
- throw new ArgumentNullException(nameof(vt));
- }
-
- if (u.Length != rowsA*rowsA)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(u));
- }
-
- if (vt.Length != columnsA*columnsA)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(vt));
- }
-
- if (s.Length != Math.Min(rowsA, columnsA))
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(s));
- }
-
- var work = new Complex32[(2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)];
- SingularValueDecomposition(computeVectors, a, rowsA, columnsA, s, u, vt, work);
- }
-
- ///
- /// Solves A*X=B for X using the singular value decomposition of A.
- ///
- /// On entry, the M by N matrix to decompose.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// The B matrix.
- /// The number of columns of B.
- /// On exit, the solution matrix.
- public override void SvdSolve(Complex32[] a, int rowsA, int columnsA, Complex32[] b, int columnsB, Complex32[] x)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(b));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(x));
- }
-
- if (b.Length != rowsA*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (x.Length != columnsA*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- var work = new Complex32[(2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)];
- var s = new Complex32[Math.Min(rowsA, columnsA)];
- var u = new Complex32[rowsA*rowsA];
- var vt = new Complex32[columnsA*columnsA];
-
- var clone = new Complex32[a.Length];
- a.Copy(clone);
- SingularValueDecomposition(true, clone, rowsA, columnsA, s, u, vt, work);
- SvdSolveFactored(rowsA, columnsA, s, u, vt, b, columnsB, x);
- }
-
- ///
- /// Computes the singular value decomposition of A.
- ///
- /// Compute the singular U and VT vectors or not.
- /// On entry, the M by N matrix to decompose. On exit, A may be overwritten.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// The singular values of A in ascending value.
- /// If is true, on exit U contains the left
- /// singular vectors.
- /// If is true, on exit VT contains the transposed
- /// right singular vectors.
- /// The work array. For real matrices, the work array should be at least
- /// Max(3*Min(M, N) + Max(M, N), 5*Min(M,N)). For complex matrices, 2*Min(M, N) + Max(M, N).
- /// On exit, work[0] contains the optimal work size value.
- /// This is equivalent to the GESVD LAPACK routine.
- [SecuritySafeCritical]
- public override void SingularValueDecomposition(bool computeVectors, Complex32[] a, int rowsA, int columnsA, Complex32[] s, Complex32[] u, Complex32[] vt, Complex32[] work)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (s == null)
- {
- throw new ArgumentNullException(nameof(s));
- }
-
- if (u == null)
- {
- throw new ArgumentNullException(nameof(u));
- }
-
- if (vt == null)
- {
- throw new ArgumentNullException(nameof(vt));
- }
-
- if (work == null)
- {
- throw new ArgumentNullException(nameof(work));
- }
-
- if (u.Length != rowsA*rowsA)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(u));
- }
-
- if (vt.Length != columnsA*columnsA)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(vt));
- }
-
- if (s.Length != Math.Min(rowsA, columnsA))
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(s));
- }
-
- if (work.Length == 0)
- {
- throw new ArgumentException(Resources.ArgumentSingleDimensionArray, nameof(work));
- }
-
- if (work.Length < (2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA))
- {
- work[0] = (2*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA);
- throw new ArgumentException(Resources.WorkArrayTooSmall, nameof(work));
- }
-
- SafeNativeMethods.c_svd_factor(computeVectors, rowsA, columnsA, a, s, u, vt, work, work.Length);
- }
- }
-}
-
-#endif
diff --git a/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.Double.cs b/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.Double.cs
deleted file mode 100644
index b3e157cd..00000000
--- a/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.Double.cs
+++ /dev/null
@@ -1,1096 +0,0 @@
-//
-// Math.NET Numerics, part of the Math.NET Project
-// http://numerics.mathdotnet.com
-// http://github.com/mathnet/mathnet-numerics
-//
-// Copyright (c) 2009-2011 Math.NET
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#if NATIVEACML
-
-using MathNet.Numerics.LinearAlgebra.Factorization;
-using System;
-using System.Security;
-
-namespace MathNet.Numerics.Providers.LinearAlgebra.Acml
-{
- ///
- /// AMD Core Math Library (ACML) linear algebra provider.
- ///
- internal partial class AcmlLinearAlgebraProvider
- {
- ///
- /// Computes the dot product of x and y.
- ///
- /// The vector x.
- /// The vector y.
- /// The dot product of x and y.
- /// This is equivalent to the DOT BLAS routine.
- [SecuritySafeCritical]
- public override double DotProduct(double[] x, double[] y)
- {
- if (y == null)
- {
- throw new ArgumentNullException(nameof(y));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(x));
- }
-
- if (x.Length != y.Length)
- {
- throw new ArgumentException("The array arguments must have the same length.");
- }
-
- return SafeNativeMethods.d_dot_product(x.Length, x, y);
- }
-
- ///
- /// Adds a scaled vector to another: result = y + alpha*x.
- ///
- /// The vector to update.
- /// The value to scale by.
- /// The vector to add to .
- /// The result of the addition.
- /// This is similar to the AXPY BLAS routine.
- [SecuritySafeCritical]
- public override void AddVectorToScaledVector(double[] y, double alpha, double[] x, double[] result)
- {
- if (y == null)
- {
- throw new ArgumentNullException(nameof(y));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(x));
- }
-
- if (y.Length != x.Length)
- {
- throw new ArgumentException("All vectors must have the same dimensionality.");
- }
-
- if (!ReferenceEquals(y, result))
- {
- Array.Copy(y, 0, result, 0, y.Length);
- }
-
- if (alpha == 0.0)
- {
- return;
- }
-
- SafeNativeMethods.d_axpy(y.Length, alpha, x, result);
- }
-
- ///
- /// Scales an array. Can be used to scale a vector and a matrix.
- ///
- /// The scalar.
- /// The values to scale.
- /// This result of the scaling.
- /// This is similar to the SCAL BLAS routine.
- [SecuritySafeCritical]
- public override void ScaleArray(double alpha, double[] x, double[] result)
- {
- if (x == null)
- {
- throw new ArgumentNullException(nameof(x));
- }
-
- if (!ReferenceEquals(x, result))
- {
- Array.Copy(x, 0, result, 0, x.Length);
- }
-
- if (alpha == 1.0)
- {
- return;
- }
-
- SafeNativeMethods.d_scale(x.Length, alpha, result);
- }
-
- ///
- /// Multiples two matrices. result = x * y
- ///
- /// The x matrix.
- /// The number of rows in the x matrix.
- /// The number of columns in the x matrix.
- /// The y matrix.
- /// The number of rows in the y matrix.
- /// The number of columns in the y matrix.
- /// Where to store the result of the multiplication.
- /// This is a simplified version of the BLAS GEMM routine with alpha
- /// set to 1.0 and beta set to 0.0, and x and y are not transposed.
- public override void MatrixMultiply(double[] x, int rowsX, int columnsX, double[] y, int rowsY, int columnsY, double[] result)
- {
- MatrixMultiplyWithUpdate(Transpose.DontTranspose, Transpose.DontTranspose, 1.0, x, rowsX, columnsX, y, rowsY, columnsY, 0.0, result);
- }
-
- ///
- /// Multiplies two matrices and updates another with the result. c = alpha*op(a)*op(b) + beta*c
- ///
- /// How to transpose the matrix.
- /// How to transpose the matrix.
- /// The value to scale matrix.
- /// The a matrix.
- /// The number of rows in the matrix.
- /// The number of columns in the matrix.
- /// The b matrix
- /// The number of rows in the matrix.
- /// The number of columns in the matrix.
- /// The value to scale the matrix.
- /// The c matrix.
- [SecuritySafeCritical]
- public override void MatrixMultiplyWithUpdate(Transpose transposeA, Transpose transposeB, double alpha, double[] a, int rowsA, int columnsA, double[] b, int rowsB, int columnsB, double beta, double[] c)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(b));
- }
-
- if (c == null)
- {
- throw new ArgumentNullException(nameof(c));
- }
-
- var m = transposeA == Transpose.DontTranspose ? rowsA : columnsA;
- var n = transposeB == Transpose.DontTranspose ? columnsB : rowsB;
- var k = transposeA == Transpose.DontTranspose ? columnsA : rowsA;
- var l = transposeB == Transpose.DontTranspose ? rowsB : columnsB;
-
- if (c.Length != m*n)
- {
- throw new ArgumentException("Matrix dimensions must agree.");
- }
-
- if (k != l)
- {
- throw new ArgumentException("Matrix dimensions must agree.");
- }
-
- SafeNativeMethods.d_matrix_multiply(transposeA, transposeB, m, n, k, alpha, a, b, beta, c);
- }
-
- ///
- /// Computes the LUP factorization of A. P*A = L*U.
- ///
- /// An by matrix. The matrix is overwritten with the
- /// the LU factorization on exit. The lower triangular factor L is stored in under the diagonal of (the diagonal is always 1.0
- /// for the L factor). The upper triangular factor U is stored on and above the diagonal of .
- /// The order of the square matrix .
- /// On exit, it contains the pivot indices. The size of the array must be .
- /// This is equivalent to the GETRF LAPACK routine.
- [SecuritySafeCritical]
- public override void LUFactor(double[] data, int order, int[] ipiv)
- {
- if (data == null)
- {
- throw new ArgumentNullException(nameof(data));
- }
-
- if (ipiv == null)
- {
- throw new ArgumentNullException(nameof(ipiv));
- }
-
- if (data.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(data));
- }
-
- if (ipiv.Length != order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(ipiv));
- }
-
- SafeNativeMethods.d_lu_factor(order, data, ipiv);
- }
-
- ///
- /// Computes the inverse of matrix using LU factorization.
- ///
- /// The N by N matrix to invert. Contains the inverse On exit.
- /// The order of the square matrix .
- /// This is equivalent to the GETRF and GETRI LAPACK routines.
- [SecuritySafeCritical]
- public override void LUInverse(double[] a, int order)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- var work = new double[order];
- SafeNativeMethods.d_lu_inverse(order, a, work, work.Length);
- }
-
- ///
- /// Computes the inverse of a previously factored matrix.
- ///
- /// The LU factored N by N matrix. Contains the inverse On exit.
- /// The order of the square matrix .
- /// The pivot indices of .
- /// This is equivalent to the GETRI LAPACK routine.
- [SecuritySafeCritical]
- public override void LUInverseFactored(double[] a, int order, int[] ipiv)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (ipiv == null)
- {
- throw new ArgumentNullException(nameof(ipiv));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (ipiv.Length != order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(ipiv));
- }
-
- var work = new double[order];
- SafeNativeMethods.d_lu_inverse_factored(order, a, ipiv, work, order);
- }
-
- ///
- /// Computes the inverse of matrix using LU factorization.
- ///
- /// The N by N matrix to invert. Contains the inverse On exit.
- /// The order of the square matrix .
- /// The work array. The array must have a length of at least N,
- /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal
- /// work size value.
- /// This is equivalent to the GETRF and GETRI LAPACK routines.
- [SecuritySafeCritical]
- public override void LUInverse(double[] a, int order, double[] work)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (work == null)
- {
- throw new ArgumentNullException(nameof(work));
- }
-
- if (work.Length < order)
- {
- throw new ArgumentException(Resources.WorkArrayTooSmall, nameof(work));
- }
-
- SafeNativeMethods.d_lu_inverse(order, a, work, work.Length);
- }
-
- ///
- /// Computes the inverse of a previously factored matrix.
- ///
- /// The LU factored N by N matrix. Contains the inverse On exit.
- /// The order of the square matrix .
- /// The pivot indices of .
- /// The work array. The array must have a length of at least N,
- /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal
- /// work size value.
- /// This is equivalent to the GETRI LAPACK routine.
- [SecuritySafeCritical]
- public override void LUInverseFactored(double[] a, int order, int[] ipiv, double[] work)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (ipiv == null)
- {
- throw new ArgumentNullException(nameof(ipiv));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (ipiv.Length != order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(ipiv));
- }
-
- if (work == null)
- {
- throw new ArgumentNullException(nameof(work));
- }
-
- if (work.Length < order)
- {
- throw new ArgumentException(Resources.WorkArrayTooSmall, nameof(work));
- }
-
- SafeNativeMethods.d_lu_inverse_factored(order, a, ipiv, work, order);
- }
-
- ///
- /// Solves A*X=B for X using LU factorization.
- ///
- /// The number of columns of B.
- /// The square matrix A.
- /// The order of the square matrix .
- /// On entry the B matrix; on exit the X matrix.
- /// This is equivalent to the GETRF and GETRS LAPACK routines.
- [SecuritySafeCritical]
- public override void LUSolve(int columnsOfB, double[] a, int order, double[] b)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (b.Length != columnsOfB*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (ReferenceEquals(a, b))
- {
- throw new ArgumentException("Arguments must be different objects.");
- }
-
- SafeNativeMethods.d_lu_solve(order, columnsOfB, a, b);
- }
-
- ///
- /// Solves A*X=B for X using a previously factored A matrix.
- ///
- /// The number of columns of B.
- /// The factored A matrix.
- /// The order of the square matrix .
- /// The pivot indices of .
- /// On entry the B matrix; on exit the X matrix.
- /// This is equivalent to the GETRS LAPACK routine.
- [SecuritySafeCritical]
- public override void LUSolveFactored(int columnsOfB, double[] a, int order, int[] ipiv, double[] b)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (ipiv == null)
- {
- throw new ArgumentNullException(nameof(ipiv));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (ipiv.Length != order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(ipiv));
- }
-
- if (b.Length != columnsOfB*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (ReferenceEquals(a, b))
- {
- throw new ArgumentException("Arguments must be different objects.");
- }
-
- SafeNativeMethods.d_lu_solve_factored(order, columnsOfB, a, ipiv, b);
- }
-
- ///
- /// Computes the Cholesky factorization of A.
- ///
- /// On entry, a square, positive definite matrix. On exit, the matrix is overwritten with the
- /// the Cholesky factorization.
- /// The number of rows or columns in the matrix.
- /// This is equivalent to the POTRF LAPACK routine.
- [SecuritySafeCritical]
- public override void CholeskyFactor(double[] a, int order)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (order < 1)
- {
- throw new ArgumentException("Value must be positive.", nameof(order));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- var info = SafeNativeMethods.d_cholesky_factor(order, a);
-
- if (info > 0)
- {
- throw new ArgumentException("Matrix must be positive definite.");
- }
- }
-
- ///
- /// Solves A*X=B for X using Cholesky factorization.
- ///
- /// The square, positive definite matrix A.
- /// The number of rows and columns in A.
- /// On entry the B matrix; on exit the X matrix.
- /// The number of columns in the B matrix.
- /// This is equivalent to the POTRF add POTRS LAPACK routines.
- ///
- [SecuritySafeCritical]
- public override void CholeskySolve(double[] a, int orderA, double[] b, int columnsB)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(b));
- }
-
- if (b.Length != orderA*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (ReferenceEquals(a, b))
- {
- throw new ArgumentException("Arguments must be different objects.");
- }
-
- SafeNativeMethods.d_cholesky_solve(orderA, columnsB, a, b);
- }
-
- ///
- /// Solves A*X=B for X using a previously factored A matrix.
- ///
- /// The square, positive definite matrix A.
- /// The number of rows and columns in A.
- /// On entry the B matrix; on exit the X matrix.
- /// The number of columns in the B matrix.
- /// This is equivalent to the POTRS LAPACK routine.
- [SecuritySafeCritical]
- public override void CholeskySolveFactored(double[] a, int orderA, double[] b, int columnsB)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(b));
- }
-
- if (b.Length != orderA*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (ReferenceEquals(a, b))
- {
- throw new ArgumentException("Arguments must be different objects.");
- }
-
- SafeNativeMethods.d_cholesky_solve_factored(orderA, columnsB, a, b);
- }
-
- ///
- /// Computes the QR factorization of A.
- ///
- /// On entry, it is the M by N A matrix to factor. On exit,
- /// it is overwritten with the R matrix of the QR factorization.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// On exit, A M by M matrix that holds the Q matrix of the
- /// QR factorization.
- /// A min(m,n) vector. On exit, contains additional information
- /// to be used by the QR solve routine.
- /// This is similar to the GEQRF and ORGQR LAPACK routines.
- [SecuritySafeCritical]
- public override void QRFactor(double[] r, int rowsR, int columnsR, double[] q, double[] tau)
- {
- if (r == null)
- {
- throw new ArgumentNullException(nameof(r));
- }
-
- if (q == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (r.Length != rowsR*columnsR)
- {
- throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r");
- }
-
- if (tau.Length < Math.Min(rowsR, columnsR))
- {
- throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau");
- }
-
- if (q.Length != rowsR*rowsR)
- {
- throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q");
- }
-
- var work = new double[columnsR*Control.BlockSize];
- SafeNativeMethods.d_qr_factor(rowsR, columnsR, r, tau, q, work, work.Length);
- }
-
- ///
- /// Computes the QR factorization of A.
- ///
- /// On entry, it is the M by N A matrix to factor. On exit,
- /// it is overwritten with the R matrix of the QR factorization.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// On exit, A M by M matrix that holds the Q matrix of the
- /// QR factorization.
- /// A min(m,n) vector. On exit, contains additional information
- /// to be used by the QR solve routine.
- /// The work array. The array must have a length of at least N,
- /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal
- /// work size value.
- /// This is similar to the GEQRF and ORGQR LAPACK routines.
- [SecuritySafeCritical]
- public override void QRFactor(double[] r, int rowsR, int columnsR, double[] q, double[] tau, double[] work)
- {
- if (r == null)
- {
- throw new ArgumentNullException(nameof(r));
- }
-
- if (q == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (work == null)
- {
- throw new ArgumentNullException(nameof(work));
- }
-
- if (r.Length != rowsR*columnsR)
- {
- throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r");
- }
-
- if (tau.Length < Math.Min(rowsR, columnsR))
- {
- throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau");
- }
-
- if (q.Length != rowsR*rowsR)
- {
- throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q");
- }
-
- if (work.Length < columnsR*Control.BlockSize)
- {
- work[0] = columnsR*Control.BlockSize;
- throw new ArgumentException(Resources.WorkArrayTooSmall, nameof(work));
- }
-
- SafeNativeMethods.d_qr_factor(rowsR, columnsR, r, tau, q, work, work.Length);
- }
-
- ///
- /// Solves A*X=B for X using QR factorization of A.
- ///
- /// The A matrix.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// The B matrix.
- /// The number of columns of B.
- /// On exit, the solution matrix.
- /// Rows must be greater or equal to columns.
- public override void QRSolve(double[] a, int rows, int columns, double[] b, int columnsB, double[] x, QRMethod method = QRMethod.Full)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(b));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(x));
- }
-
- if (a.Length != rows*columns)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (b.Length != rows*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (x.Length != columns*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(x));
- }
-
- if (rows < columns)
- {
- throw new ArgumentException(Resources.RowsLessThanColumns);
- }
-
- var work = new double[columns*Control.BlockSize];
- QRSolve(a, rows, columns, b, columnsB, x, work);
- }
-
- ///
- /// Solves A*X=B for X using QR factorization of A.
- ///
- /// The A matrix.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// The B matrix.
- /// The number of columns of B.
- /// On exit, the solution matrix.
- /// The work array. The array must have a length of at least N,
- /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal
- /// work size value.
- /// Rows must be greater or equal to columns.
- public override void QRSolve(double[] a, int rows, int columns, double[] b, int columnsB, double[] x, double[] work, QRMethod method = QRMethod.Full)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(b));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(x));
- }
-
- if (work == null)
- {
- throw new ArgumentNullException(nameof(work));
- }
-
- if (a.Length != rows*columns)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (b.Length != rows*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (x.Length != columns*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(x));
- }
-
- if (rows < columns)
- {
- throw new ArgumentException(Resources.RowsLessThanColumns);
- }
-
- if (work.Length < 1)
- {
- work[0] = rows*Control.BlockSize;
- throw new ArgumentException(Resources.WorkArrayTooSmall, nameof(work));
- }
-
- SafeNativeMethods.d_qr_solve(rows, columns, columnsB, a, b, x, work, work.Length);
- }
-
- ///
- /// Solves A*X=B for X using a previously QR factored matrix.
- ///
- /// The Q matrix obtained by calling .
- /// The R matrix obtained by calling .
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// Contains additional information on Q. Only used for the native solver
- /// and can be null for the managed provider.
- /// The B matrix.
- /// The number of columns of B.
- /// On exit, the solution matrix.
- /// Rows must be greater or equal to columns.
- [SecuritySafeCritical]
- public override void QRSolveFactored(double[] q, double[] r, int rowsR, int columnsR, double[] tau, double[] b, int columnsB, double[] x, QRMethod method = QRMethod.Full)
- {
- if (r == null)
- {
- throw new ArgumentNullException(nameof(r));
- }
-
- if (q == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (r.Length != rowsR*columnsR)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(r));
- }
-
- if (q.Length != rowsR*rowsR)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(q));
- }
-
- if (b.Length != rowsR*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (x.Length != columnsR*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(x));
- }
-
- if (rowsR < columnsR)
- {
- throw new ArgumentException(Resources.RowsLessThanColumns);
- }
-
- var work = new double[columnsR*Control.BlockSize];
- QRSolveFactored(q, r, rowsR, columnsR, tau, b, columnsB, x, work);
- }
-
- ///
- /// Solves A*X=B for X using a previously QR factored matrix.
- ///
- /// The Q matrix obtained by QR factor. This is only used for the managed provider and can be
- /// null for the native provider. The native provider uses the Q portion stored in the R matrix.
- /// The R matrix obtained by calling .
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// Contains additional information on Q. Only used for the native solver
- /// and can be null for the managed provider.
- /// On entry the B matrix; on exit the X matrix.
- /// The number of columns of B.
- /// On exit, the solution matrix.
- /// The work array - only used in the native provider. The array must have a length of at least N,
- /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal
- /// work size value.
- /// Rows must be greater or equal to columns.
- public override void QRSolveFactored(double[] q, double[] r, int rowsR, int columnsR, double[] tau, double[] b, int columnsB, double[] x, double[] work, QRMethod method = QRMethod.Full)
- {
- if (r == null)
- {
- throw new ArgumentNullException(nameof(r));
- }
-
- if (q == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (work == null)
- {
- throw new ArgumentNullException(nameof(work));
- }
-
- if (r.Length != rowsR*columnsR)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(r));
- }
-
- if (q.Length != rowsR*rowsR)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(q));
- }
-
- if (b.Length != rowsR*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (x.Length != columnsR*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(x));
- }
-
- if (rowsR < columnsR)
- {
- throw new ArgumentException(Resources.RowsLessThanColumns);
- }
-
- if (work.Length < 1)
- {
- work[0] = rowsR*Control.BlockSize;
- throw new ArgumentException(Resources.WorkArrayTooSmall, nameof(work));
- }
-
- SafeNativeMethods.d_qr_solve_factored(rowsR, columnsR, columnsB, r, b, tau, x, work, work.Length);
- }
-
- ///
- /// Computes the singular value decomposition of A.
- ///
- /// Compute the singular U and VT vectors or not.
- /// On entry, the M by N matrix to decompose. On exit, A may be overwritten.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// The singular values of A in ascending value.
- /// If is true, on exit U contains the left
- /// singular vectors.
- /// If is true, on exit VT contains the transposed
- /// right singular vectors.
- /// This is equivalent to the GESVD LAPACK routine.
- [SecuritySafeCritical]
- public override void SingularValueDecomposition(bool computeVectors, double[] a, int rowsA, int columnsA, double[] s, double[] u, double[] vt)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (s == null)
- {
- throw new ArgumentNullException(nameof(s));
- }
-
- if (u == null)
- {
- throw new ArgumentNullException(nameof(u));
- }
-
- if (vt == null)
- {
- throw new ArgumentNullException(nameof(vt));
- }
-
- if (u.Length != rowsA*rowsA)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(u));
- }
-
- if (vt.Length != columnsA*columnsA)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(vt));
- }
-
- if (s.Length != Math.Min(rowsA, columnsA))
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(s));
- }
-
- var work = new double[Math.Max((3*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA), 5*Math.Min(rowsA, columnsA))];
- SingularValueDecomposition(computeVectors, a, rowsA, columnsA, s, u, vt, work);
- }
-
- ///
- /// Solves A*X=B for X using the singular value decomposition of A.
- ///
- /// On entry, the M by N matrix to decompose.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// The B matrix.
- /// The number of columns of B.
- /// On exit, the solution matrix.
- public override void SvdSolve(double[] a, int rowsA, int columnsA, double[] b, int columnsB, double[] x)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(b));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(x));
- }
-
- if (b.Length != rowsA*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (x.Length != columnsA*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- var work = new double[Math.Max((3*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA), 5*Math.Min(rowsA, columnsA))];
- var s = new double[Math.Min(rowsA, columnsA)];
- var u = new double[rowsA*rowsA];
- var vt = new double[columnsA*columnsA];
-
- var clone = new double[a.Length];
- a.Copy(clone);
- SingularValueDecomposition(true, clone, rowsA, columnsA, s, u, vt, work);
- SvdSolveFactored(rowsA, columnsA, s, u, vt, b, columnsB, x);
- }
-
- ///
- /// Computes the singular value decomposition of A.
- ///
- /// Compute the singular U and VT vectors or not.
- /// On entry, the M by N matrix to decompose. On exit, A may be overwritten.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// The singular values of A in ascending value.
- /// If is true, on exit U contains the left
- /// singular vectors.
- /// If is true, on exit VT contains the transposed
- /// right singular vectors.
- /// The work array. For real matrices, the work array should be at least
- /// Max(3*Min(M, N) + Max(M, N), 5*Min(M,N)). For complex matrices, 2*Min(M, N) + Max(M, N).
- /// On exit, work[0] contains the optimal work size value.
- /// This is equivalent to the GESVD LAPACK routine.
- [SecuritySafeCritical]
- public override void SingularValueDecomposition(bool computeVectors, double[] a, int rowsA, int columnsA, double[] s, double[] u, double[] vt, double[] work)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (s == null)
- {
- throw new ArgumentNullException(nameof(s));
- }
-
- if (u == null)
- {
- throw new ArgumentNullException(nameof(u));
- }
-
- if (vt == null)
- {
- throw new ArgumentNullException(nameof(vt));
- }
-
- if (work == null)
- {
- throw new ArgumentNullException(nameof(work));
- }
-
- if (u.Length != rowsA*rowsA)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(u));
- }
-
- if (vt.Length != columnsA*columnsA)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(vt));
- }
-
- if (s.Length != Math.Min(rowsA, columnsA))
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(s));
- }
-
- if (work.Length == 0)
- {
- throw new ArgumentException(Resources.ArgumentSingleDimensionArray, nameof(work));
- }
-
- if (work.Length < Math.Max((3*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA), 5*Math.Min(rowsA, columnsA)))
- {
- work[0] = Math.Max((3*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA), 5*Math.Min(rowsA, columnsA));
- throw new ArgumentException(Resources.WorkArrayTooSmall, nameof(work));
- }
-
- SafeNativeMethods.d_svd_factor(computeVectors, rowsA, columnsA, a, s, u, vt, work, work.Length);
- }
-
- }
-}
-
-#endif
diff --git a/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.Single.cs b/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.Single.cs
deleted file mode 100644
index 707b03c3..00000000
--- a/src/Numerics/Providers/LinearAlgebra/Acml/AcmlLinearAlgebraProvider.Single.cs
+++ /dev/null
@@ -1,1095 +0,0 @@
-//
-// Math.NET Numerics, part of the Math.NET Project
-// http://numerics.mathdotnet.com
-// http://github.com/mathnet/mathnet-numerics
-//
-// Copyright (c) 2009-2011 Math.NET
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#if NATIVEACML
-
-using MathNet.Numerics.LinearAlgebra.Factorization;
-using System;
-using System.Security;
-
-namespace MathNet.Numerics.Providers.LinearAlgebra.Acml
-{
- ///
- /// AMD Core Math Library (ACML) linear algebra provider.
- ///
- internal partial class AcmlLinearAlgebraProvider
- {
- ///
- /// Computes the dot product of x and y.
- ///
- /// The vector x.
- /// The vector y.
- /// The dot product of x and y.
- /// This is equivalent to the DOT BLAS routine.
- [SecuritySafeCritical]
- public override float DotProduct(float[] x, float[] y)
- {
- if (y == null)
- {
- throw new ArgumentNullException(nameof(y));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(x));
- }
-
- if (x.Length != y.Length)
- {
- throw new ArgumentException("The array arguments must have the same length.");
- }
-
- return SafeNativeMethods.s_dot_product(x.Length, x, y);
- }
-
- ///
- /// Adds a scaled vector to another: result = y + alpha*x.
- ///
- /// The vector to update.
- /// The value to scale by.
- /// The vector to add to .
- /// The result of the addition.
- /// This is similar to the AXPY BLAS routine.
- [SecuritySafeCritical]
- public override void AddVectorToScaledVector(float[] y, float alpha, float[] x, float[] result)
- {
- if (y == null)
- {
- throw new ArgumentNullException(nameof(y));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(x));
- }
-
- if (y.Length != x.Length)
- {
- throw new ArgumentException("All vectors must have the same dimensionality.");
- }
-
- if (!ReferenceEquals(y, result))
- {
- Array.Copy(y, 0, result, 0, y.Length);
- }
-
- if (alpha == 0.0f)
- {
- return;
- }
-
- SafeNativeMethods.s_axpy(y.Length, alpha, x, result);
- }
-
- ///
- /// Scales an array. Can be used to scale a vector and a matrix.
- ///
- /// The scalar.
- /// The values to scale.
- /// This result of the scaling.
- /// This is similar to the SCAL BLAS routine.
- [SecuritySafeCritical]
- public override void ScaleArray(float alpha, float[] x, float[] result)
- {
- if (x == null)
- {
- throw new ArgumentNullException(nameof(x));
- }
-
- if (!ReferenceEquals(x, result))
- {
- Array.Copy(x, 0, result, 0, x.Length);
- }
-
- if (alpha == 1.0f)
- {
- return;
- }
-
- SafeNativeMethods.s_scale(x.Length, alpha, result);
- }
-
- ///
- /// Multiples two matrices. result = x * y
- ///
- /// The x matrix.
- /// The number of rows in the x matrix.
- /// The number of columns in the x matrix.
- /// The y matrix.
- /// The number of rows in the y matrix.
- /// The number of columns in the y matrix.
- /// Where to store the result of the multiplication.
- /// This is a simplified version of the BLAS GEMM routine with alpha
- /// set to 1.0f and beta set to 0.0f, and x and y are not transposed.
- public override void MatrixMultiply(float[] x, int rowsX, int columnsX, float[] y, int rowsY, int columnsY, float[] result)
- {
- MatrixMultiplyWithUpdate(Transpose.DontTranspose, Transpose.DontTranspose, 1.0f, x, rowsX, columnsX, y, rowsY, columnsY, 0.0f, result);
- }
-
- ///
- /// Multiplies two matrices and updates another with the result. c = alpha*op(a)*op(b) + beta*c
- ///
- /// How to transpose the matrix.
- /// How to transpose the matrix.
- /// The value to scale matrix.
- /// The a matrix.
- /// The number of rows in the matrix.
- /// The number of columns in the matrix.
- /// The b matrix
- /// The number of rows in the matrix.
- /// The number of columns in the matrix.
- /// The value to scale the matrix.
- /// The c matrix.
- [SecuritySafeCritical]
- public override void MatrixMultiplyWithUpdate(Transpose transposeA, Transpose transposeB, float alpha, float[] a, int rowsA, int columnsA, float[] b, int rowsB, int columnsB, float beta, float[] c)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(b));
- }
-
- if (c == null)
- {
- throw new ArgumentNullException(nameof(c));
- }
-
- var m = transposeA == Transpose.DontTranspose ? rowsA : columnsA;
- var n = transposeB == Transpose.DontTranspose ? columnsB : rowsB;
- var k = transposeA == Transpose.DontTranspose ? columnsA : rowsA;
- var l = transposeB == Transpose.DontTranspose ? rowsB : columnsB;
-
- if (c.Length != m*n)
- {
- throw new ArgumentException("Matrix dimensions must agree.");
- }
-
- if (k != l)
- {
- throw new ArgumentException("Matrix dimensions must agree.");
- }
-
- SafeNativeMethods.s_matrix_multiply(transposeA, transposeB, m, n, k, alpha, a, b, beta, c);
- }
-
- ///
- /// Computes the LUP factorization of A. P*A = L*U.
- ///
- /// An by matrix. The matrix is overwritten with the
- /// the LU factorization on exit. The lower triangular factor L is stored in under the diagonal of (the diagonal is always 1.0f
- /// for the L factor). The upper triangular factor U is stored on and above the diagonal of .
- /// The order of the square matrix .
- /// On exit, it contains the pivot indices. The size of the array must be .
- /// This is equivalent to the GETRF LAPACK routine.
- [SecuritySafeCritical]
- public override void LUFactor(float[] data, int order, int[] ipiv)
- {
- if (data == null)
- {
- throw new ArgumentNullException(nameof(data));
- }
-
- if (ipiv == null)
- {
- throw new ArgumentNullException(nameof(ipiv));
- }
-
- if (data.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(data));
- }
-
- if (ipiv.Length != order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(ipiv));
- }
-
- SafeNativeMethods.s_lu_factor(order, data, ipiv);
- }
-
- ///
- /// Computes the inverse of matrix using LU factorization.
- ///
- /// The N by N matrix to invert. Contains the inverse On exit.
- /// The order of the square matrix .
- /// This is equivalent to the GETRF and GETRI LAPACK routines.
- [SecuritySafeCritical]
- public override void LUInverse(float[] a, int order)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- var work = new float[order];
- SafeNativeMethods.s_lu_inverse(order, a, work, work.Length);
- }
-
- ///
- /// Computes the inverse of a previously factored matrix.
- ///
- /// The LU factored N by N matrix. Contains the inverse On exit.
- /// The order of the square matrix .
- /// The pivot indices of .
- /// This is equivalent to the GETRI LAPACK routine.
- [SecuritySafeCritical]
- public override void LUInverseFactored(float[] a, int order, int[] ipiv)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (ipiv == null)
- {
- throw new ArgumentNullException(nameof(ipiv));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (ipiv.Length != order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(ipiv));
- }
-
- var work = new float[order];
- SafeNativeMethods.s_lu_inverse_factored(order, a, ipiv, work, order);
- }
-
- ///
- /// Computes the inverse of matrix using LU factorization.
- ///
- /// The N by N matrix to invert. Contains the inverse On exit.
- /// The order of the square matrix .
- /// The work array. The array must have a length of at least N,
- /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal
- /// work size value.
- /// This is equivalent to the GETRF and GETRI LAPACK routines.
- [SecuritySafeCritical]
- public override void LUInverse(float[] a, int order, float[] work)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (work == null)
- {
- throw new ArgumentNullException(nameof(work));
- }
-
- if (work.Length < order)
- {
- throw new ArgumentException(Resources.WorkArrayTooSmall, nameof(work));
- }
-
- SafeNativeMethods.s_lu_inverse(order, a, work, work.Length);
- }
-
- ///
- /// Computes the inverse of a previously factored matrix.
- ///
- /// The LU factored N by N matrix. Contains the inverse On exit.
- /// The order of the square matrix .
- /// The pivot indices of .
- /// The work array. The array must have a length of at least N,
- /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal
- /// work size value.
- /// This is equivalent to the GETRI LAPACK routine.
- [SecuritySafeCritical]
- public override void LUInverseFactored(float[] a, int order, int[] ipiv, float[] work)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (ipiv == null)
- {
- throw new ArgumentNullException(nameof(ipiv));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (ipiv.Length != order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(ipiv));
- }
-
- if (work == null)
- {
- throw new ArgumentNullException(nameof(work));
- }
-
- if (work.Length < order)
- {
- throw new ArgumentException(Resources.WorkArrayTooSmall, nameof(work));
- }
-
- SafeNativeMethods.s_lu_inverse_factored(order, a, ipiv, work, order);
- }
-
- ///
- /// Solves A*X=B for X using LU factorization.
- ///
- /// The number of columns of B.
- /// The square matrix A.
- /// The order of the square matrix .
- /// On entry the B matrix; on exit the X matrix.
- /// This is equivalent to the GETRF and GETRS LAPACK routines.
- [SecuritySafeCritical]
- public override void LUSolve(int columnsOfB, float[] a, int order, float[] b)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (b.Length != columnsOfB*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (ReferenceEquals(a, b))
- {
- throw new ArgumentException("Arguments must be different objects.");
- }
-
- SafeNativeMethods.s_lu_solve(order, columnsOfB, a, b);
- }
-
- ///
- /// Solves A*X=B for X using a previously factored A matrix.
- ///
- /// The number of columns of B.
- /// The factored A matrix.
- /// The order of the square matrix .
- /// The pivot indices of .
- /// On entry the B matrix; on exit the X matrix.
- /// This is equivalent to the GETRS LAPACK routine.
- [SecuritySafeCritical]
- public override void LUSolveFactored(int columnsOfB, float[] a, int order, int[] ipiv, float[] b)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (ipiv == null)
- {
- throw new ArgumentNullException(nameof(ipiv));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (ipiv.Length != order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(ipiv));
- }
-
- if (b.Length != columnsOfB*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (ReferenceEquals(a, b))
- {
- throw new ArgumentException("Arguments must be different objects.");
- }
-
- SafeNativeMethods.s_lu_solve_factored(order, columnsOfB, a, ipiv, b);
- }
-
- ///
- /// Computes the Cholesky factorization of A.
- ///
- /// On entry, a square, positive definite matrix. On exit, the matrix is overwritten with the
- /// the Cholesky factorization.
- /// The number of rows or columns in the matrix.
- /// This is equivalent to the POTRF LAPACK routine.
- [SecuritySafeCritical]
- public override void CholeskyFactor(float[] a, int order)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (order < 1)
- {
- throw new ArgumentException("Value must be positive.", nameof(order));
- }
-
- if (a.Length != order*order)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- var info = SafeNativeMethods.s_cholesky_factor(order, a);
-
- if (info > 0)
- {
- throw new ArgumentException("Matrix must be positive definite.");
- }
- }
-
- ///
- /// Solves A*X=B for X using Cholesky factorization.
- ///
- /// The square, positive definite matrix A.
- /// The number of rows and columns in A.
- /// On entry the B matrix; on exit the X matrix.
- /// The number of columns in the B matrix.
- /// This is equivalent to the POTRF add POTRS LAPACK routines.
- ///
- [SecuritySafeCritical]
- public override void CholeskySolve(float[] a, int orderA, float[] b, int columnsB)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(b));
- }
-
- if (b.Length != orderA*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (ReferenceEquals(a, b))
- {
- throw new ArgumentException("Arguments must be different objects.");
- }
-
- SafeNativeMethods.s_cholesky_solve(orderA, columnsB, a, b);
- }
-
- ///
- /// Solves A*X=B for X using a previously factored A matrix.
- ///
- /// The square, positive definite matrix A.
- /// The number of rows and columns in A.
- /// On entry the B matrix; on exit the X matrix.
- /// The number of columns in the B matrix.
- /// This is equivalent to the POTRS LAPACK routine.
- [SecuritySafeCritical]
- public override void CholeskySolveFactored(float[] a, int orderA, float[] b, int columnsB)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(b));
- }
-
- if (b.Length != orderA*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (ReferenceEquals(a, b))
- {
- throw new ArgumentException("Arguments must be different objects.");
- }
-
- SafeNativeMethods.s_cholesky_solve_factored(orderA, columnsB, a, b);
- }
-
- ///
- /// Computes the QR factorization of A.
- ///
- /// On entry, it is the M by N A matrix to factor. On exit,
- /// it is overwritten with the R matrix of the QR factorization.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// On exit, A M by M matrix that holds the Q matrix of the
- /// QR factorization.
- /// A min(m,n) vector. On exit, contains additional information
- /// to be used by the QR solve routine.
- /// This is similar to the GEQRF and ORGQR LAPACK routines.
- [SecuritySafeCritical]
- public override void QRFactor(float[] r, int rowsR, int columnsR, float[] q, float[] tau)
- {
- if (r == null)
- {
- throw new ArgumentNullException(nameof(r));
- }
-
- if (q == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (r.Length != rowsR*columnsR)
- {
- throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r");
- }
-
- if (tau.Length < Math.Min(rowsR, columnsR))
- {
- throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau");
- }
-
- if (q.Length != rowsR*rowsR)
- {
- throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q");
- }
-
- var work = new float[columnsR*Control.BlockSize];
- SafeNativeMethods.s_qr_factor(rowsR, columnsR, r, tau, q, work, work.Length);
- }
-
- ///
- /// Computes the QR factorization of A.
- ///
- /// On entry, it is the M by N A matrix to factor. On exit,
- /// it is overwritten with the R matrix of the QR factorization.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// On exit, A M by M matrix that holds the Q matrix of the
- /// QR factorization.
- /// A min(m,n) vector. On exit, contains additional information
- /// to be used by the QR solve routine.
- /// The work array. The array must have a length of at least N,
- /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal
- /// work size value.
- /// This is similar to the GEQRF and ORGQR LAPACK routines.
- [SecuritySafeCritical]
- public override void QRFactor(float[] r, int rowsR, int columnsR, float[] q, float[] tau, float[] work)
- {
- if (r == null)
- {
- throw new ArgumentNullException(nameof(r));
- }
-
- if (q == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (work == null)
- {
- throw new ArgumentNullException(nameof(work));
- }
-
- if (r.Length != rowsR*columnsR)
- {
- throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * columnsR"), "r");
- }
-
- if (tau.Length < Math.Min(rowsR, columnsR))
- {
- throw new ArgumentException(string.Format(Resources.ArrayTooSmall, "min(m,n)"), "tau");
- }
-
- if (q.Length != rowsR*rowsR)
- {
- throw new ArgumentException(string.Format(Resources.ArgumentArrayWrongLength, "rowsR * rowsR"), "q");
- }
-
- if (work.Length < columnsR*Control.BlockSize)
- {
- work[0] = columnsR*Control.BlockSize;
- throw new ArgumentException(Resources.WorkArrayTooSmall, nameof(work));
- }
-
- SafeNativeMethods.s_qr_factor(rowsR, columnsR, r, tau, q, work, work.Length);
- }
-
- ///
- /// Solves A*X=B for X using QR factorization of A.
- ///
- /// The A matrix.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// The B matrix.
- /// The number of columns of B.
- /// On exit, the solution matrix.
- /// Rows must be greater or equal to columns.
- public override void QRSolve(float[] a, int rows, int columns, float[] b, int columnsB, float[] x, QRMethod method = QRMethod.Full)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(b));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(x));
- }
-
- if (a.Length != rows*columns)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (b.Length != rows*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (x.Length != columns*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(x));
- }
-
- if (rows < columns)
- {
- throw new ArgumentException(Resources.RowsLessThanColumns);
- }
-
- var work = new float[columns*Control.BlockSize];
- QRSolve(a, rows, columns, b, columnsB, x, work);
- }
-
- ///
- /// Solves A*X=B for X using QR factorization of A.
- ///
- /// The A matrix.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// The B matrix.
- /// The number of columns of B.
- /// On exit, the solution matrix.
- /// The work array. The array must have a length of at least N,
- /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal
- /// work size value.
- /// Rows must be greater or equal to columns.
- public override void QRSolve(float[] a, int rows, int columns, float[] b, int columnsB, float[] x, float[] work, QRMethod method = QRMethod.Full)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(b));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(x));
- }
-
- if (work == null)
- {
- throw new ArgumentNullException(nameof(work));
- }
-
- if (a.Length != rows*columns)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(a));
- }
-
- if (b.Length != rows*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (x.Length != columns*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(x));
- }
-
- if (rows < columns)
- {
- throw new ArgumentException(Resources.RowsLessThanColumns);
- }
-
- if (work.Length < 1)
- {
- work[0] = rows*Control.BlockSize;
- throw new ArgumentException(Resources.WorkArrayTooSmall, nameof(work));
- }
-
- SafeNativeMethods.s_qr_solve(rows, columns, columnsB, a, b, x, work, work.Length);
- }
-
- ///
- /// Solves A*X=B for X using a previously QR factored matrix.
- ///
- /// The Q matrix obtained by calling .
- /// The R matrix obtained by calling .
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// Contains additional information on Q. Only used for the native solver
- /// and can be null for the managed provider.
- /// The B matrix.
- /// The number of columns of B.
- /// On exit, the solution matrix.
- /// Rows must be greater or equal to columns.
- [SecuritySafeCritical]
- public override void QRSolveFactored(float[] q, float[] r, int rowsR, int columnsR, float[] tau, float[] b, int columnsB, float[] x, QRMethod method = QRMethod.Full)
- {
- if (r == null)
- {
- throw new ArgumentNullException(nameof(r));
- }
-
- if (q == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (r.Length != rowsR*columnsR)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(r));
- }
-
- if (q.Length != rowsR*rowsR)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(q));
- }
-
- if (b.Length != rowsR*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (x.Length != columnsR*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(x));
- }
-
- if (rowsR < columnsR)
- {
- throw new ArgumentException(Resources.RowsLessThanColumns);
- }
-
- var work = new float[columnsR*Control.BlockSize];
- QRSolveFactored(q, r, rowsR, columnsR, tau, b, columnsB, x, work);
- }
-
- ///
- /// Solves A*X=B for X using a previously QR factored matrix.
- ///
- /// The Q matrix obtained by QR factor. This is only used for the managed provider and can be
- /// null for the native provider. The native provider uses the Q portion stored in the R matrix.
- /// The R matrix obtained by calling .
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// Contains additional information on Q. Only used for the native solver
- /// and can be null for the managed provider.
- /// On entry the B matrix; on exit the X matrix.
- /// The number of columns of B.
- /// On exit, the solution matrix.
- /// The work array - only used in the native provider. The array must have a length of at least N,
- /// but should be N*blocksize. The blocksize is machine dependent. On exit, work[0] contains the optimal
- /// work size value.
- /// Rows must be greater or equal to columns.
- public override void QRSolveFactored(float[] q, float[] r, int rowsR, int columnsR, float[] tau, float[] b, int columnsB, float[] x, float[] work, QRMethod method = QRMethod.Full)
- {
- if (r == null)
- {
- throw new ArgumentNullException(nameof(r));
- }
-
- if (q == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(q));
- }
-
- if (work == null)
- {
- throw new ArgumentNullException(nameof(work));
- }
-
- if (r.Length != rowsR*columnsR)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(r));
- }
-
- if (q.Length != rowsR*rowsR)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(q));
- }
-
- if (b.Length != rowsR*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (x.Length != columnsR*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(x));
- }
-
- if (rowsR < columnsR)
- {
- throw new ArgumentException(Resources.RowsLessThanColumns);
- }
-
- if (work.Length < 1)
- {
- work[0] = rowsR*Control.BlockSize;
- throw new ArgumentException(Resources.WorkArrayTooSmall, nameof(work));
- }
-
- SafeNativeMethods.s_qr_solve_factored(rowsR, columnsR, columnsB, r, b, tau, x, work, work.Length);
- }
-
- ///
- /// Computes the singular value decomposition of A.
- ///
- /// Compute the singular U and VT vectors or not.
- /// On entry, the M by N matrix to decompose. On exit, A may be overwritten.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// The singular values of A in ascending value.
- /// If is true, on exit U contains the left
- /// singular vectors.
- /// If is true, on exit VT contains the transposed
- /// right singular vectors.
- /// This is equivalent to the GESVD LAPACK routine.
- [SecuritySafeCritical]
- public override void SingularValueDecomposition(bool computeVectors, float[] a, int rowsA, int columnsA, float[] s, float[] u, float[] vt)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (s == null)
- {
- throw new ArgumentNullException(nameof(s));
- }
-
- if (u == null)
- {
- throw new ArgumentNullException(nameof(u));
- }
-
- if (vt == null)
- {
- throw new ArgumentNullException(nameof(vt));
- }
-
- if (u.Length != rowsA*rowsA)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(u));
- }
-
- if (vt.Length != columnsA*columnsA)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(vt));
- }
-
- if (s.Length != Math.Min(rowsA, columnsA))
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(s));
- }
-
- var work = new float[Math.Max(((3*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)), 5*Math.Min(rowsA, columnsA))];
- SingularValueDecomposition(computeVectors, a, rowsA, columnsA, s, u, vt, work);
- }
-
- ///
- /// Solves A*X=B for X using the singular value decomposition of A.
- ///
- /// On entry, the M by N matrix to decompose.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// The B matrix.
- /// The number of columns of B.
- /// On exit, the solution matrix.
- public override void SvdSolve(float[] a, int rowsA, int columnsA, float[] b, int columnsB, float[] x)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (b == null)
- {
- throw new ArgumentNullException(nameof(b));
- }
-
- if (x == null)
- {
- throw new ArgumentNullException(nameof(x));
- }
-
- if (b.Length != rowsA*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- if (x.Length != columnsA*columnsB)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(b));
- }
-
- var work = new float[Math.Max(((3*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)), 5*Math.Min(rowsA, columnsA))];
- var s = new float[Math.Min(rowsA, columnsA)];
- var u = new float[rowsA*rowsA];
- var vt = new float[columnsA*columnsA];
-
- var clone = new float[a.Length];
- a.Copy(clone);
- SingularValueDecomposition(true, clone, rowsA, columnsA, s, u, vt, work);
- SvdSolveFactored(rowsA, columnsA, s, u, vt, b, columnsB, x);
- }
-
- ///
- /// Computes the singular value decomposition of A.
- ///
- /// Compute the singular U and VT vectors or not.
- /// On entry, the M by N matrix to decompose. On exit, A may be overwritten.
- /// The number of rows in the A matrix.
- /// The number of columns in the A matrix.
- /// The singular values of A in ascending value.
- /// If is true, on exit U contains the left
- /// singular vectors.
- /// If is true, on exit VT contains the transposed
- /// right singular vectors.
- /// The work array. For real matrices, the work array should be at least
- /// Max(3*Min(M, N) + Max(M, N), 5*Min(M,N)). For complex matrices, 2*Min(M, N) + Max(M, N).
- /// On exit, work[0] contains the optimal work size value.
- /// This is equivalent to the GESVD LAPACK routine.
- [SecuritySafeCritical]
- public override void SingularValueDecomposition(bool computeVectors, float[] a, int rowsA, int columnsA, float[] s, float[] u, float[] vt, float[] work)
- {
- if (a == null)
- {
- throw new ArgumentNullException(nameof(a));
- }
-
- if (s == null)
- {
- throw new ArgumentNullException(nameof(s));
- }
-
- if (u == null)
- {
- throw new ArgumentNullException(nameof(u));
- }
-
- if (vt == null)
- {
- throw new ArgumentNullException(nameof(vt));
- }
-
- if (work == null)
- {
- throw new ArgumentNullException(nameof(work));
- }
-
- if (u.Length != rowsA*rowsA)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(u));
- }
-
- if (vt.Length != columnsA*columnsA)
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(vt));
- }
-
- if (s.Length != Math.Min(rowsA, columnsA))
- {
- throw new ArgumentException("The array arguments must have the same length.", nameof(s));
- }
-
- if (work.Length == 0)
- {
- throw new ArgumentException(Resources.ArgumentSingleDimensionArray, nameof(work));
- }
-
- if (work.Length < Math.Max(((3*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA)), 5*Math.Min(rowsA, columnsA)))
- {
- work[0] = Math.Max((3*Math.Min(rowsA, columnsA)) + Math.Max(rowsA, columnsA), 5*Math.Min(rowsA, columnsA));
- throw new ArgumentException(Resources.WorkArrayTooSmall, nameof(work));
- }
-
- SafeNativeMethods.s_svd_factor(computeVectors, rowsA, columnsA, a, s, u, vt, work, work.Length);
- }
- }
-}
-
-#endif
diff --git a/src/Numerics/Providers/LinearAlgebra/Acml/SafeNativeMethods.cs b/src/Numerics/Providers/LinearAlgebra/Acml/SafeNativeMethods.cs
deleted file mode 100644
index 67bee70b..00000000
--- a/src/Numerics/Providers/LinearAlgebra/Acml/SafeNativeMethods.cs
+++ /dev/null
@@ -1,263 +0,0 @@
-//
-// Math.NET Numerics, part of the Math.NET Project
-// https://numerics.mathdotnet.com
-//
-// Copyright (c) 2009-2010 Math.NET
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#if NATIVEACML
-
-using System.Runtime.InteropServices;
-using System.Security;
-using Complex = System.Numerics.Complex;
-
-namespace MathNet.Numerics.Providers.LinearAlgebra.Acml
-{
- ///
- /// P/Invoke methods to the native math libraries.
- ///
- [SuppressUnmanagedCodeSecurity]
- [SecurityCritical]
- internal static class SafeNativeMethods
- {
- ///
- /// Name of the native DLL.
- ///
- const string DllName = "MathNET.Numerics.ACML.dll";
-
-#region BLAS
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void s_axpy(int n, float alpha, float[] x, [In, Out] float[] y);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void d_axpy(int n, double alpha, double[] x, [In, Out] double[] y);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void c_axpy(int n, Complex32 alpha, Complex32[] x, [In, Out] Complex32[] y);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void z_axpy(int n, Complex alpha, Complex[] x, [In, Out] Complex[] y);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void s_scale(int n, float alpha, [Out] float[] x);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void d_scale(int n, double alpha, [Out] double[] x);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void c_scale(int n, Complex32 alpha, [In, Out] Complex32[] x);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void z_scale(int n, Complex alpha, [In, Out] Complex[] x);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern float s_dot_product(int n, float[] x, float[] y);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern double d_dot_product(int n, double[] x, double[] y);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern Complex32 c_dot_product(int n, Complex32[] x, Complex32[] y);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern Complex z_dot_product(int n, Complex[] x, Complex[] y);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void s_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, float alpha, float[] x, float[] y, float beta, [In, Out] float[] c);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void d_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, double alpha, double[] x, double[] y, double beta, [In, Out] double[] c);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void c_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, Complex32 alpha, Complex32[] x, Complex32[] y, Complex32 beta, [In, Out] Complex32[] c);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void z_matrix_multiply(Transpose transA, Transpose transB, int m, int n, int k, Complex alpha, Complex[] x, Complex[] y, Complex beta, [In, Out] Complex[] c);
-
-#endregion BLAS
-
-#region LAPACK
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern float s_matrix_norm(byte norm, int rows, int columns, [In] float[] a, [In, Out] float[] work);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern float d_matrix_norm(byte norm, int rows, int columns, [In] double[] a, [In, Out] double[] work);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern float c_matrix_norm(byte norm, int rows, int columns, [In] Complex32[] a, [In, Out] float[] work);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern double z_matrix_norm(byte norm, int rows, int columns, [In] Complex[] a, [In, Out] double[] work);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int s_cholesky_factor(int n, [In, Out] float[] a);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int d_cholesky_factor(int n, [In, Out] double[] a);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int c_cholesky_factor(int n, [In, Out] Complex32[] a);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int z_cholesky_factor(int n, [In, Out] Complex[] a);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int s_lu_factor(int n, [In, Out] float[] a, [In, Out] int[] ipiv);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int d_lu_factor(int n, [In, Out] double[] a, [In, Out] int[] ipiv);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int c_lu_factor(int n, [In, Out] Complex32[] a, [In, Out] int[] ipiv);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int z_lu_factor(int n, [In, Out] Complex[] a, [In, Out] int[] ipiv);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int s_lu_inverse(int n, [In, Out] float[] a, [In, Out] float[] work, int lwork);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int d_lu_inverse(int n, [In, Out] double[] a, [In, Out] double[] work, int lwork);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int c_lu_inverse(int n, [In, Out] Complex32[] a, [In, Out] Complex32[] work, int lwork);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int z_lu_inverse(int n, [In, Out] Complex[] a, [In, Out] Complex[] work, int lwork);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int s_lu_inverse_factored(int n, [In, Out] float[] a, [In, Out] int[] ipiv, [In, Out] float[] work, int lwork);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int d_lu_inverse_factored(int n, [In, Out] double[] a, [In, Out] int[] ipiv, [In, Out] double[] work, int lwork);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int c_lu_inverse_factored(int n, [In, Out] Complex32[] a, [In, Out] int[] ipiv, [In, Out] Complex32[] work, int lwork);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int z_lu_inverse_factored(int n, [In, Out] Complex[] a, [In, Out] int[] ipiv, [In, Out] Complex[] work, int lwork);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int s_lu_solve_factored(int n, int nrhs, float[] a, [In, Out] int[] ipiv, [In, Out] float[] b);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int d_lu_solve_factored(int n, int nrhs, double[] a, [In, Out] int[] ipiv, [In, Out] double[] b);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int c_lu_solve_factored(int n, int nrhs, Complex32[] a, [In, Out] int[] ipiv, [In, Out] Complex32[] b);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int z_lu_solve_factored(int n, int nrhs, Complex[] a, [In, Out] int[] ipiv, [In, Out] Complex[] b);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int s_lu_solve(int n, int nrhs, float[] a, [In, Out] float[] b);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int d_lu_solve(int n, int nrhs, double[] a, [In, Out] double[] b);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int c_lu_solve(int n, int nrhs, Complex32[] a, [In, Out] Complex32[] b);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int z_lu_solve(int n, int nrhs, Complex[] a, [In, Out] Complex[] b);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int s_cholesky_solve(int n, int nrhs, float[] a, [In, Out] float[] b);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int d_cholesky_solve(int n, int nrhs, double[] a, [In, Out] double[] b);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int c_cholesky_solve(int n, int nrhs, Complex32[] a, [In, Out] Complex32[] b);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int z_cholesky_solve(int n, int nrhs, Complex[] a, [In, Out] Complex[] b);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int s_cholesky_solve_factored(int n, int nrhs, float[] a, [In, Out] float[] b);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int d_cholesky_solve_factored(int n, int nrhs, double[] a, [In, Out] double[] b);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int c_cholesky_solve_factored(int n, int nrhs, Complex32[] a, [In, Out] Complex32[] b);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int z_cholesky_solve_factored(int n, int nrhs, Complex[] a, [In, Out] Complex[] b);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int s_qr_factor(int m, int n, [In, Out] float[] r, [In, Out] float[] tau, [In, Out] float[] q, [In, Out] float[] work, int len);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int d_qr_factor(int m, int n, [In, Out] double[] r, [In, Out] double[] tau, [In, Out] double[] q, [In, Out] double[] work, int len);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int c_qr_factor(int m, int n, [In, Out] Complex32[] r, [In, Out] Complex32[] tau, [In, Out] Complex32[] q, [In, Out] Complex32[] work, int len);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int z_qr_factor(int m, int n, [In, Out] Complex[] r, [In, Out] Complex[] tau, [In, Out] Complex[] q, [In, Out] Complex[] work, int len);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int s_qr_solve(int m, int n, int bn, float[] r, float[] b, [In, Out] float[] x, [In, Out] float[] work, int len);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int d_qr_solve(int m, int n, int bn, double[] r, double[] b, [In, Out] double[] x, [In, Out] double[] work, int len);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int c_qr_solve(int m, int n, int bn, Complex32[] r, Complex32[] b, [In, Out] Complex32[] x, [In, Out] Complex32[] work, int len);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int z_qr_solve(int m, int n, int bn, Complex[] r, Complex[] b, [In, Out] Complex[] x, [In, Out] Complex[] work, int len);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int s_qr_solve_factored(int m, int n, int bn, float[] r, float[] b, float[] tau, [In, Out] float[] x, [In, Out] float[] work, int len);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int d_qr_solve_factored(int m, int n, int bn, double[] r, double[] b, double[] tau, [In, Out] double[] x, [In, Out] double[] work, int len);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int c_qr_solve_factored(int m, int n, int bn, Complex32[] r, Complex32[] b, Complex32[] tau, [In, Out] Complex32[] x, [In, Out] Complex32[] work, int len);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int z_qr_solve_factored(int m, int n, int bn, Complex[] r, Complex[] b, Complex[] tau, [In, Out] Complex[] x, [In, Out] Complex[] work, int len);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int s_svd_factor(bool computeVectors, int m, int n, [In, Out] float[] a, [In, Out] float[] s, [In, Out] float[] u, [In, Out] float[] v, [In, Out] float[] work, int len);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int d_svd_factor(bool computeVectors, int m, int n, [In, Out] double[] a, [In, Out] double[] s, [In, Out] double[] u, [In, Out] double[] v, [In, Out] double[] work, int len);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int c_svd_factor(bool computeVectors, int m, int n, [In, Out] Complex32[] a, [In, Out] Complex32[] s, [In, Out] Complex32[] u, [In, Out] Complex32[] v, [In, Out] Complex32[] work, int len);
-
- [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int z_svd_factor(bool computeVectors, int m, int n, [In, Out] Complex[] a, [In, Out] Complex[] s, [In, Out] Complex[] u, [In, Out] Complex[] v, [In, Out] Complex[] work, int len);
-
-#endregion LAPACK
- }
-}
-
-#endif
diff --git a/src/Numerics/Providers/LinearAlgebra/LinearAlgebraControl.cs b/src/Numerics/Providers/LinearAlgebra/LinearAlgebraControl.cs
index e2335e77..edf2d10c 100644
--- a/src/Numerics/Providers/LinearAlgebra/LinearAlgebraControl.cs
+++ b/src/Numerics/Providers/LinearAlgebra/LinearAlgebraControl.cs
@@ -3,7 +3,7 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
//
-// Copyright (c) 2009-2020 Math.NET
+// Copyright (c) 2009-2021 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@@ -34,11 +34,26 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
public static class LinearAlgebraControl
{
const string EnvVarLAProvider = "MathNetNumericsLAProvider";
- const string EnvVarLAProviderPath = "MathNetNumericsLAProviderPath";
static ILinearAlgebraProvider _linearAlgebraProvider;
static readonly object StaticLock = new object();
+ const string MklTypeName = "MathNet.Numerics.Providers.MKL.LinearAlgebra.MklLinearAlgebraControl, MathNet.Numerics.Providers.MKL";
+ static readonly ProviderProbe MklProbe = new ProviderProbe(MklTypeName, AppSwitches.DisableMklNativeProvider);
+
+ const string OpenBlasTypeName = "MathNet.Numerics.Providers.OpenBLAS.LinearAlgebra.OpenBlasLinearAlgebraControl, MathNet.Numerics.Providers.OpenBLAS";
+ static readonly ProviderProbe OpenBlasProbe = new ProviderProbe(OpenBlasTypeName, AppSwitches.DisableOpenBlasNativeProvider);
+
+ const string CudaTypeName = "MathNet.Numerics.Providers.CUDA.LinearAlgebra.CudaLinearAlgebraControl, MathNet.Numerics.Providers.CUDA";
+ static readonly ProviderProbe CudaProbe = new ProviderProbe(CudaTypeName, AppSwitches.DisableCudaNativeProvider);
+
+ ///
+ /// Optional path to try to load native provider binaries from.
+ /// If not set, Numerics will fall back to the environment variable
+ /// `MathNetNumericsLAProviderPath` or the default probing paths.
+ ///
+ public static string HintPath { get; set; }
+
///
/// Gets or sets the linear algebra provider.
/// Consider to use UseNativeMKL or UseManaged instead.
@@ -70,90 +85,20 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
}
}
- ///
- /// Optional path to try to load native provider binaries from.
- /// If not set, Numerics will fall back to the environment variable
- /// `MathNetNumericsLAProviderPath` or the default probing paths.
- ///
- public static string HintPath { get; set; }
-
- public static ILinearAlgebraProvider CreateManaged()
- {
- return new Managed.ManagedLinearAlgebraProvider();
- }
-
- public static void UseManaged()
- {
- Provider = CreateManaged();
- }
-
- internal static ILinearAlgebraProvider CreateManagedReference()
- {
- return new ManagedReference.ManagedReferenceLinearAlgebraProvider();
- }
-
- internal static void UseManagedReference()
- {
- Provider = CreateManagedReference();
- }
-
-#if NATIVE
- [CLSCompliant(false)]
- public static ILinearAlgebraProvider CreateNativeMKL(
- Common.Mkl.MklConsistency consistency = Common.Mkl.MklConsistency.Auto,
- Common.Mkl.MklPrecision precision = Common.Mkl.MklPrecision.Double,
- Common.Mkl.MklAccuracy accuracy = Common.Mkl.MklAccuracy.High)
- {
- return new Mkl.MklLinearAlgebraProvider(GetCombinedHintPath(), consistency, precision, accuracy);
- }
-
- [CLSCompliant(false)]
- public static void UseNativeMKL(
- Common.Mkl.MklConsistency consistency = Common.Mkl.MklConsistency.Auto,
- Common.Mkl.MklPrecision precision = Common.Mkl.MklPrecision.Double,
- Common.Mkl.MklAccuracy accuracy = Common.Mkl.MklAccuracy.High)
- {
- Provider = CreateNativeMKL(consistency, precision, accuracy);
- }
-
- [CLSCompliant(false)]
- public static bool TryUseNativeMKL(
- Common.Mkl.MklConsistency consistency = Common.Mkl.MklConsistency.Auto,
- Common.Mkl.MklPrecision precision = Common.Mkl.MklPrecision.Double,
- Common.Mkl.MklAccuracy accuracy = Common.Mkl.MklAccuracy.High)
- {
- return TryUse(CreateNativeMKL(consistency, precision, accuracy));
- }
+ public static ILinearAlgebraProvider CreateManaged() => new Managed.ManagedLinearAlgebraProvider();
+ public static void UseManaged() => Provider = CreateManaged();
- public static ILinearAlgebraProvider CreateNativeCUDA()
- {
- return new Cuda.CudaLinearAlgebraProvider(GetCombinedHintPath());
- }
+ internal static ILinearAlgebraProvider CreateManagedReference() => new ManagedReference.ManagedReferenceLinearAlgebraProvider();
+ internal static void UseManagedReference() => Provider = CreateManagedReference();
- public static void UseNativeCUDA()
- {
- Provider = CreateNativeCUDA();
- }
+ public static void UseNativeMKL() => Provider = MklProbe.Create();
+ public static bool TryUseNativeMKL() => TryUse(MklProbe.TryCreate());
- public static bool TryUseNativeCUDA()
- {
- return TryUse(CreateNativeCUDA());
- }
+ public static void UseNativeCUDA() => Provider = CudaProbe.Create();
+ public static bool TryUseNativeCUDA() => TryUse(CudaProbe.TryCreate());
- public static ILinearAlgebraProvider CreateNativeOpenBLAS()
- {
- return new OpenBlas.OpenBlasLinearAlgebraProvider(GetCombinedHintPath());
- }
-
- public static void UseNativeOpenBLAS()
- {
- Provider = CreateNativeOpenBLAS();
- }
-
- public static bool TryUseNativeOpenBLAS()
- {
- return TryUse(CreateNativeOpenBLAS());
- }
+ public static void UseNativeOpenBLAS() => Provider = OpenBlasProbe.Create();
+ public static bool TryUseNativeOpenBLAS() => TryUse(OpenBlasProbe.TryCreate());
///
/// Try to use a native provider, if available.
@@ -167,13 +112,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
return TryUseNativeMKL() || TryUseNativeOpenBLAS() || TryUseNativeCUDA();
}
-#endif
- static bool TryUse(ILinearAlgebraProvider provider)
+ public static bool TryUse(ILinearAlgebraProvider provider)
{
try
{
- if (!provider.IsAvailable())
+ if (provider == null || !provider.IsAvailable())
{
return false;
}
@@ -199,14 +143,10 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
return;
}
-#if NATIVE
if (!TryUseNative())
{
UseManaged();
}
-#else
- UseManaged();
-#endif
}
///
@@ -222,7 +162,6 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
return;
}
-#if NATIVE
var value = Environment.GetEnvironmentVariable(EnvVarLAProvider);
switch (value != null ? value.ToUpperInvariant() : string.Empty)
{
@@ -242,30 +181,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
UseBest();
break;
}
-#else
- UseBest();
-#endif
}
- public static void FreeResources()
- {
- Provider.FreeResources();
- }
-
- static string GetCombinedHintPath()
- {
- if (!String.IsNullOrEmpty(HintPath))
- {
- return HintPath;
- }
-
- var value = Environment.GetEnvironmentVariable(EnvVarLAProviderPath);
- if (!String.IsNullOrEmpty(value))
- {
- return value;
- }
-
- return null;
- }
+ public static void FreeResources() => Provider.FreeResources();
}
}
diff --git a/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex.cs b/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex.cs
index 77e114d3..7c93ceb4 100644
--- a/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex.cs
+++ b/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex.cs
@@ -38,7 +38,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Managed
///
/// The managed linear algebra provider.
///
- internal partial class ManagedLinearAlgebraProvider
+ public partial class ManagedLinearAlgebraProvider
{
///
/// Adds a scaled vector to another: result = y + alpha*x.
diff --git a/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex32.cs b/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex32.cs
index 32a6e33d..99271a26 100644
--- a/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex32.cs
+++ b/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex32.cs
@@ -38,7 +38,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Managed
///
/// The managed linear algebra provider.
///
- internal partial class ManagedLinearAlgebraProvider
+ public partial class ManagedLinearAlgebraProvider
{
///
/// Adds a scaled vector to another: result = y + alpha*x.
diff --git a/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Double.cs b/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Double.cs
index 636f4da9..bbda08eb 100644
--- a/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Double.cs
+++ b/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Double.cs
@@ -38,7 +38,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Managed
///
/// The managed linear algebra provider.
///
- internal partial class ManagedLinearAlgebraProvider
+ public partial class ManagedLinearAlgebraProvider
{
///
/// Adds a scaled vector to another: result = y + alpha*x.
diff --git a/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Single.cs b/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Single.cs
index 548b6aeb..e66f8b28 100644
--- a/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Single.cs
+++ b/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Single.cs
@@ -38,7 +38,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Managed
///
/// The managed linear algebra provider.
///
- internal partial class ManagedLinearAlgebraProvider
+ public partial class ManagedLinearAlgebraProvider
{
///
/// Adds a scaled vector to another: result = y + alpha*x.
diff --git a/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.cs b/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.cs
index 8c89a6b6..87ffe841 100644
--- a/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.cs
+++ b/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.cs
@@ -34,7 +34,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Managed
///
/// The managed linear algebra provider.
///
- internal partial class ManagedLinearAlgebraProvider : ILinearAlgebraProvider
+ public partial class ManagedLinearAlgebraProvider : ILinearAlgebraProvider
{
///
/// Try to find out whether the provider is available, at least in principle.
diff --git a/src/Numerics/Providers/ProviderProbe.cs b/src/Numerics/Providers/ProviderProbe.cs
new file mode 100644
index 00000000..ad26ab16
--- /dev/null
+++ b/src/Numerics/Providers/ProviderProbe.cs
@@ -0,0 +1,88 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// https://numerics.mathdotnet.com
+// https://github.com/mathnet/mathnet-numerics
+//
+// Copyright (c) 2009-2021 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Threading;
+
+namespace MathNet.Numerics.Providers
+{
+ public class ProviderProbe where T : class
+ {
+ readonly bool _disabled;
+ readonly Lazy> _creator;
+
+ public ProviderProbe(string typeName, bool disabled = false)
+ {
+ _disabled = disabled;
+ _creator = new Lazy>(() =>
+ {
+ var type = Type.GetType(typeName);
+ return Activator.CreateInstance(type) as IProviderCreator;
+ }, LazyThreadSafetyMode.ExecutionAndPublication);
+ }
+
+ public T Create()
+ {
+ if (_disabled)
+ {
+ throw new NotSupportedException("Specific Native Provider disabled by an application switch");
+ }
+
+ if (AppSwitches.DisableNativeProviders)
+ {
+ throw new NotSupportedException("Native Providers are disabled by an application switch");
+ }
+
+ if (AppSwitches.DisableNativeProviderProbing)
+ {
+ throw new NotSupportedException("Native Provider Probing is disabled by an application switch");
+ }
+
+ return _creator.Value.CreateProvider();
+ }
+
+ public T TryCreate()
+ {
+ if (_disabled || AppSwitches.DisableNativeProviderProbing || AppSwitches.DisableNativeProviders)
+ {
+ return null;
+ }
+
+ try
+ {
+ return _creator.Value.CreateProvider();
+ }
+ catch
+ {
+ // intentionally swallow exceptions here - use the explicit variants if you're interested in why
+ return null;
+ }
+ }
+ }
+}
diff --git a/src/Numerics/Providers/SparseSolver/Managed/ManagedSparseSolverProvider.cs b/src/Numerics/Providers/SparseSolver/Managed/ManagedSparseSolverProvider.cs
index 3b1e6258..ade30517 100644
--- a/src/Numerics/Providers/SparseSolver/Managed/ManagedSparseSolverProvider.cs
+++ b/src/Numerics/Providers/SparseSolver/Managed/ManagedSparseSolverProvider.cs
@@ -6,7 +6,7 @@ namespace MathNet.Numerics.Providers.SparseSolver.Managed
///
/// The managed sparse solver provider
///
- internal partial class ManagedSparseSolverProvider : ISparseSolverProvider
+ public partial class ManagedSparseSolverProvider : ISparseSolverProvider
{
///
/// Try to find out whether the provider is available, at least in principle.
diff --git a/src/Numerics/Providers/SparseSolver/SparseSolverControl.cs b/src/Numerics/Providers/SparseSolver/SparseSolverControl.cs
index 1c6b0fdb..e36aba2a 100644
--- a/src/Numerics/Providers/SparseSolver/SparseSolverControl.cs
+++ b/src/Numerics/Providers/SparseSolver/SparseSolverControl.cs
@@ -3,7 +3,7 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
//
-// Copyright (c) 2009-2020 Math.NET
+// Copyright (c) 2009-2021 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@@ -34,11 +34,20 @@ namespace MathNet.Numerics.Providers.SparseSolver
public static class SparseSolverControl
{
const string EnvVarSSProvider = "MathNetNumericsSSProvider";
- const string EnvVarSSProviderPath = "MathNetNumericsSSProviderPath";
static ISparseSolverProvider _sparseSolverProvider;
static readonly object StaticLock = new object();
+ const string MklTypeName = "MathNet.Numerics.Providers.MKL.SparseSolver.MklSparseSolverControl, MathNet.Numerics.Providers.MKL";
+ static readonly ProviderProbe MklProbe = new ProviderProbe(MklTypeName, AppSwitches.DisableMklNativeProvider);
+
+ ///
+ /// Optional path to try to load native provider binaries from.
+ /// If not set, Numerics will fall back to the environment variable
+ /// `MathNetNumericsSSProviderPath` or the default probing paths.
+ ///
+ public static string HintPath { get; set; }
+
///
/// Gets or sets the sparse solver provider. Consider to use UseNativeMKL or UseManaged instead.
///
@@ -69,38 +78,11 @@ namespace MathNet.Numerics.Providers.SparseSolver
}
}
- ///
- /// Optional path to try to load native provider binaries from.
- /// If not set, Numerics will fall back to the environment variable
- /// `MathNetNumericsSSProviderPath` or the default probing paths.
- ///
- public static string HintPath { get; set; }
-
- public static ISparseSolverProvider CreateManaged()
- {
- return new Managed.ManagedSparseSolverProvider();
- }
-
- public static void UseManaged()
- {
- Provider = CreateManaged();
- }
-
-#if NATIVE
- public static ISparseSolverProvider CreateNativeMKL()
- {
- return new Mkl.MklSparseSolverProvider(GetCombinedHintPath());
- }
-
- public static void UseNativeMKL()
- {
- Provider = CreateNativeMKL();
- }
+ public static ISparseSolverProvider CreateManaged() => new Managed.ManagedSparseSolverProvider();
+ public static void UseManaged() => Provider = CreateManaged();
- public static bool TryUseNativeMKL()
- {
- return TryUse(CreateNativeMKL());
- }
+ public static void UseNativeMKL() => Provider = MklProbe.Create();
+ public static bool TryUseNativeMKL() => TryUse(MklProbe.TryCreate());
///
/// Try to use a native provider, if available.
@@ -114,13 +96,12 @@ namespace MathNet.Numerics.Providers.SparseSolver
return TryUseNativeMKL();
}
-#endif
- static bool TryUse(ISparseSolverProvider provider)
+ public static bool TryUse(ISparseSolverProvider provider)
{
try
{
- if (!provider.IsAvailable())
+ if (provider == null || !provider.IsAvailable())
{
return false;
}
@@ -135,6 +116,19 @@ namespace MathNet.Numerics.Providers.SparseSolver
}
}
+ public static bool TryUse(Lazy> providerCreator)
+ {
+ try
+ {
+ return TryUse(providerCreator.Value?.CreateProvider());
+ }
+ catch
+ {
+ // intentionally swallow exceptions here - use the explicit variants if you're interested in why
+ return false;
+ }
+ }
+
///
/// Use the best provider available.
///
@@ -146,14 +140,10 @@ namespace MathNet.Numerics.Providers.SparseSolver
return;
}
-#if NATIVE
if (!TryUseNative())
{
UseManaged();
}
-#else
- UseManaged();
-#endif
}
///
@@ -169,7 +159,6 @@ namespace MathNet.Numerics.Providers.SparseSolver
return;
}
-#if NATIVE
var value = Environment.GetEnvironmentVariable(EnvVarSSProvider);
switch (value != null ? value.ToUpperInvariant() : string.Empty)
{
@@ -182,30 +171,8 @@ namespace MathNet.Numerics.Providers.SparseSolver
UseBest();
break;
}
-#else
- UseBest();
-#endif
- }
-
- public static void FreeResources()
- {
- Provider.FreeResources();
}
- static string GetCombinedHintPath()
- {
- if (!String.IsNullOrEmpty(HintPath))
- {
- return HintPath;
- }
-
- var value = Environment.GetEnvironmentVariable(EnvVarSSProviderPath);
- if (!String.IsNullOrEmpty(value))
- {
- return value;
- }
-
- return null;
- }
+ public static void FreeResources() => Provider.FreeResources();
}
}
diff --git a/src/Providers.CUDA/ArrayExtensions.cs b/src/Providers.CUDA/ArrayExtensions.cs
new file mode 100644
index 00000000..29af0a7d
--- /dev/null
+++ b/src/Providers.CUDA/ArrayExtensions.cs
@@ -0,0 +1,80 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// https://numerics.mathdotnet.com
+// https://github.com/mathnet/mathnet-numerics
+//
+// Copyright (c) 2009-2021 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using Complex = System.Numerics.Complex;
+
+namespace MathNet.Numerics.Providers.CUDA
+{
+ ///
+ /// Useful extension methods for Arrays.
+ ///
+ internal static class ArrayExtensions
+ {
+ ///
+ /// Copies the values from on array to another.
+ ///
+ /// The source array.
+ /// The destination array.
+ public static void Copy(this double[] source, double[] dest)
+ {
+ Buffer.BlockCopy(source, 0, dest, 0, source.Length * Constants.SizeOfDouble);
+ }
+
+ ///
+ /// Copies the values from on array to another.
+ ///
+ /// The source array.
+ /// The destination array.
+ public static void Copy(this float[] source, float[] dest)
+ {
+ Buffer.BlockCopy(source, 0, dest, 0, source.Length * Constants.SizeOfFloat);
+ }
+
+ ///
+ /// Copies the values from on array to another.
+ ///
+ /// The source array.
+ /// The destination array.
+ public static void Copy(this Complex[] source, Complex[] dest)
+ {
+ Array.Copy(source, 0, dest, 0, source.Length);
+ }
+
+ ///
+ /// Copies the values from on array to another.
+ ///
+ /// The source array.
+ /// The destination array.
+ public static void Copy(this Complex32[] source, Complex32[] dest)
+ {
+ Array.Copy(source, 0, dest, 0, source.Length);
+ }
+ }
+}
diff --git a/src/Providers.CUDA/Compatibility.cs b/src/Providers.CUDA/Compatibility.cs
new file mode 100644
index 00000000..0122997a
--- /dev/null
+++ b/src/Providers.CUDA/Compatibility.cs
@@ -0,0 +1,44 @@
+using System.Globalization;
+
+#if NET40
+namespace System.Runtime.CompilerServices
+{
+ internal class FormattableStringFactory
+ {
+ public static FormattableString Create(string format, params object[] args)
+ {
+ return new FormattableString(format, args);
+ }
+ }
+}
+
+namespace System
+{
+ internal class FormattableString
+ {
+ private readonly string format;
+ private readonly object[] args;
+
+ public FormattableString(string format, object[] args)
+ {
+ this.format = format;
+ this.args = args;
+ }
+
+ public static string Invariant(FormattableString messageFormat)
+ {
+ return messageFormat.ToString(CultureInfo.InvariantCulture);
+ }
+
+ public string ToString(IFormatProvider formatProvider)
+ {
+ return string.Format(formatProvider, format, args);
+ }
+
+ public override string ToString()
+ {
+ return string.Format(format, args);
+ }
+ }
+}
+#endif
diff --git a/src/Providers.CUDA/CudaControl.cs b/src/Providers.CUDA/CudaControl.cs
new file mode 100644
index 00000000..9f98b7d9
--- /dev/null
+++ b/src/Providers.CUDA/CudaControl.cs
@@ -0,0 +1,60 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// https://numerics.mathdotnet.com
+// https://github.com/mathnet/mathnet-numerics
+//
+// Copyright (c) 2009-2021 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using MathNet.Numerics.Providers.CUDA.LinearAlgebra;
+
+namespace MathNet.Numerics.Providers.CUDA
+{
+ public static class CudaControl
+ {
+ internal const string EnvVarCUDAProviderPath = "MathNetNumericsCUDAProviderPath";
+
+ ///
+ /// Use the OpenBLAS native provider for linear algebra.
+ /// Throws if it is not available or failed to initialize, in which case the previous provider is still active.
+ ///
+ public static void UseNativeCUDA()
+ {
+ CudaLinearAlgebraControl.UseNativeCUDA();
+ }
+
+ ///
+ /// Try to use the OpenBLAS native provider for linear algebra.
+ ///
+ ///
+ /// True if the provider was found and initialized successfully.
+ /// False if it failed and the previous provider is still active.
+ ///
+ public static bool TryUseNativeCUDA()
+ {
+ bool linearAlgebra = CudaLinearAlgebraControl.TryUseNativeCUDA();
+ return linearAlgebra;
+ }
+ }
+}
diff --git a/src/Numerics/Providers/Common/Cuda/CudaProvider.cs b/src/Providers.CUDA/CudaProvider.cs
similarity index 98%
rename from src/Numerics/Providers/Common/Cuda/CudaProvider.cs
rename to src/Providers.CUDA/CudaProvider.cs
index fc33ce60..5d8b7f09 100644
--- a/src/Numerics/Providers/Common/Cuda/CudaProvider.cs
+++ b/src/Providers.CUDA/CudaProvider.cs
@@ -27,12 +27,10 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
using System;
using System.Collections.Generic;
-namespace MathNet.Numerics.Providers.Common.Cuda
+namespace MathNet.Numerics.Providers.CUDA
{
public static class CudaProvider
{
@@ -149,5 +147,3 @@ namespace MathNet.Numerics.Providers.Common.Cuda
}
}
}
-
-#endif
diff --git a/src/Numerics/Providers/Common/Cuda/CudaProviderCapabilities.cs b/src/Providers.CUDA/CudaProviderCapabilities.cs
similarity index 95%
rename from src/Numerics/Providers/Common/Cuda/CudaProviderCapabilities.cs
rename to src/Providers.CUDA/CudaProviderCapabilities.cs
index 6856ab49..a51e7259 100644
--- a/src/Numerics/Providers/Common/Cuda/CudaProviderCapabilities.cs
+++ b/src/Providers.CUDA/CudaProviderCapabilities.cs
@@ -27,9 +27,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
-namespace MathNet.Numerics.Providers.Common.Cuda
+namespace MathNet.Numerics.Providers.CUDA
{
internal enum ProviderPlatform : int
{
@@ -49,5 +47,3 @@ namespace MathNet.Numerics.Providers.Common.Cuda
LinearAlgebraMinor = 129,
}
}
-
-#endif
diff --git a/src/Providers.CUDA/LinearAlgebra/CudaLinearAlgebraControl.cs b/src/Providers.CUDA/LinearAlgebra/CudaLinearAlgebraControl.cs
new file mode 100644
index 00000000..43b008d2
--- /dev/null
+++ b/src/Providers.CUDA/LinearAlgebra/CudaLinearAlgebraControl.cs
@@ -0,0 +1,93 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// https://numerics.mathdotnet.com
+// https://github.com/mathnet/mathnet-numerics
+//
+// Copyright (c) 2009-2021 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using MathNet.Numerics.Providers.LinearAlgebra;
+
+namespace MathNet.Numerics.Providers.CUDA.LinearAlgebra
+{
+ public class CudaLinearAlgebraControl : IProviderCreator
+ {
+ const string EnvVarLAProviderPath = "MathNetNumericsLAProviderPath";
+
+ ///
+ /// Optional path to try to load native provider binaries from.
+ /// If not set, Numerics will fall back to the environment variable
+ /// `MathNetNumericsMKLProviderPath` or the default probing paths.
+ ///
+ public static string HintPath { get; set; }
+
+ public static ILinearAlgebraProvider CreateNativeCUDA()
+ {
+ return new CudaLinearAlgebraProvider(GetCombinedHintPath());
+ }
+
+ public static void UseNativeCUDA()
+ {
+ LinearAlgebraControl.Provider = CreateNativeCUDA();
+ }
+
+ public static bool TryUseNativeCUDA()
+ {
+ return LinearAlgebraControl.TryUse(CreateNativeCUDA());
+ }
+
+ static string GetCombinedHintPath()
+ {
+ if (!String.IsNullOrEmpty(HintPath))
+ {
+ return HintPath;
+ }
+
+ if (!String.IsNullOrEmpty(LinearAlgebraControl.HintPath))
+ {
+ return LinearAlgebraControl.HintPath;
+ }
+
+ var value = Environment.GetEnvironmentVariable(CudaControl.EnvVarCUDAProviderPath);
+ if (!String.IsNullOrEmpty(value))
+ {
+ return value;
+ }
+
+ value = Environment.GetEnvironmentVariable(EnvVarLAProviderPath);
+ if (!String.IsNullOrEmpty(value))
+ {
+ return value;
+ }
+
+ return null;
+ }
+
+ public ILinearAlgebraProvider CreateProvider()
+ {
+ return CreateNativeCUDA();
+ }
+ }
+}
diff --git a/src/Numerics/Providers/LinearAlgebra/Cuda/CudaLinearAlgebraProvider.Complex.cs b/src/Providers.CUDA/LinearAlgebra/CudaLinearAlgebraProvider.Complex.cs
similarity index 99%
rename from src/Numerics/Providers/LinearAlgebra/Cuda/CudaLinearAlgebraProvider.Complex.cs
rename to src/Providers.CUDA/LinearAlgebra/CudaLinearAlgebraProvider.Complex.cs
index abc8c70a..e1cf9db1 100644
--- a/src/Numerics/Providers/LinearAlgebra/Cuda/CudaLinearAlgebraProvider.Complex.cs
+++ b/src/Providers.CUDA/LinearAlgebra/CudaLinearAlgebraProvider.Complex.cs
@@ -27,14 +27,12 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
using System;
using System.Security;
-using MathNet.Numerics.Providers.Common.Cuda;
+using MathNet.Numerics.Providers.LinearAlgebra;
using Complex = System.Numerics.Complex;
-namespace MathNet.Numerics.Providers.LinearAlgebra.Cuda
+namespace MathNet.Numerics.Providers.CUDA.LinearAlgebra
{
///
/// NVidia's CUDA Toolkit linear algebra provider.
@@ -572,5 +570,3 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Cuda
}
}
}
-
-#endif
diff --git a/src/Numerics/Providers/LinearAlgebra/Cuda/CudaLinearAlgebraProvider.Complex32.cs b/src/Providers.CUDA/LinearAlgebra/CudaLinearAlgebraProvider.Complex32.cs
similarity index 99%
rename from src/Numerics/Providers/LinearAlgebra/Cuda/CudaLinearAlgebraProvider.Complex32.cs
rename to src/Providers.CUDA/LinearAlgebra/CudaLinearAlgebraProvider.Complex32.cs
index da1b0dcd..3137a3b7 100644
--- a/src/Numerics/Providers/LinearAlgebra/Cuda/CudaLinearAlgebraProvider.Complex32.cs
+++ b/src/Providers.CUDA/LinearAlgebra/CudaLinearAlgebraProvider.Complex32.cs
@@ -27,13 +27,11 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
using System;
using System.Security;
-using MathNet.Numerics.Providers.Common.Cuda;
+using MathNet.Numerics.Providers.LinearAlgebra;
-namespace MathNet.Numerics.Providers.LinearAlgebra.Cuda
+namespace MathNet.Numerics.Providers.CUDA.LinearAlgebra
{
///
/// NVidia's CUDA Toolkit linear algebra provider.
@@ -571,5 +569,3 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Cuda
}
}
}
-
-#endif
diff --git a/src/Numerics/Providers/LinearAlgebra/Cuda/CudaLinearAlgebraProvider.Double.cs b/src/Providers.CUDA/LinearAlgebra/CudaLinearAlgebraProvider.Double.cs
similarity index 99%
rename from src/Numerics/Providers/LinearAlgebra/Cuda/CudaLinearAlgebraProvider.Double.cs
rename to src/Providers.CUDA/LinearAlgebra/CudaLinearAlgebraProvider.Double.cs
index 904b2f6a..f9b4ebed 100644
--- a/src/Numerics/Providers/LinearAlgebra/Cuda/CudaLinearAlgebraProvider.Double.cs
+++ b/src/Providers.CUDA/LinearAlgebra/CudaLinearAlgebraProvider.Double.cs
@@ -27,13 +27,11 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
using System;
using System.Security;
-using MathNet.Numerics.Providers.Common.Cuda;
+using MathNet.Numerics.Providers.LinearAlgebra;
-namespace MathNet.Numerics.Providers.LinearAlgebra.Cuda
+namespace MathNet.Numerics.Providers.CUDA.LinearAlgebra
{
///
/// NVidia's CUDA Toolkit linear algebra provider.
@@ -571,5 +569,3 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Cuda
}
}
}
-
-#endif
diff --git a/src/Numerics/Providers/LinearAlgebra/Cuda/CudaLinearAlgebraProvider.Single.cs b/src/Providers.CUDA/LinearAlgebra/CudaLinearAlgebraProvider.Single.cs
similarity index 99%
rename from src/Numerics/Providers/LinearAlgebra/Cuda/CudaLinearAlgebraProvider.Single.cs
rename to src/Providers.CUDA/LinearAlgebra/CudaLinearAlgebraProvider.Single.cs
index 3f3d69a3..38847a4c 100644
--- a/src/Numerics/Providers/LinearAlgebra/Cuda/CudaLinearAlgebraProvider.Single.cs
+++ b/src/Providers.CUDA/LinearAlgebra/CudaLinearAlgebraProvider.Single.cs
@@ -27,13 +27,11 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
using System;
using System.Security;
-using MathNet.Numerics.Providers.Common.Cuda;
+using MathNet.Numerics.Providers.LinearAlgebra;
-namespace MathNet.Numerics.Providers.LinearAlgebra.Cuda
+namespace MathNet.Numerics.Providers.CUDA.LinearAlgebra
{
///
/// NVidia's CUDA Toolkit linear algebra provider.
@@ -571,5 +569,3 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Cuda
}
}
}
-
-#endif
diff --git a/src/Numerics/Providers/LinearAlgebra/Cuda/CudaLinearAlgebraProvider.cs b/src/Providers.CUDA/LinearAlgebra/CudaLinearAlgebraProvider.cs
similarity index 97%
rename from src/Numerics/Providers/LinearAlgebra/Cuda/CudaLinearAlgebraProvider.cs
rename to src/Providers.CUDA/LinearAlgebra/CudaLinearAlgebraProvider.cs
index 864c30d0..7de4db55 100644
--- a/src/Numerics/Providers/LinearAlgebra/Cuda/CudaLinearAlgebraProvider.cs
+++ b/src/Providers.CUDA/LinearAlgebra/CudaLinearAlgebraProvider.cs
@@ -27,17 +27,15 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
using System;
-using MathNet.Numerics.Providers.Common.Cuda;
+using MathNet.Numerics.Providers.LinearAlgebra.Managed;
-namespace MathNet.Numerics.Providers.LinearAlgebra.Cuda
+namespace MathNet.Numerics.Providers.CUDA.LinearAlgebra
{
///
/// NVidia's CUDA Toolkit linear algebra provider.
///
- internal partial class CudaLinearAlgebraProvider : Managed.ManagedLinearAlgebraProvider, IDisposable
+ internal partial class CudaLinearAlgebraProvider : ManagedLinearAlgebraProvider, IDisposable
{
const int MinimumCompatibleRevision = 1;
@@ -190,5 +188,3 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Cuda
}
}
}
-
-#endif
diff --git a/src/Numerics/Providers/Common/NativeProviderLoader.cs b/src/Providers.CUDA/NativeProviderLoader.cs
similarity index 99%
rename from src/Numerics/Providers/Common/NativeProviderLoader.cs
rename to src/Providers.CUDA/NativeProviderLoader.cs
index e72c71f9..75a923b4 100644
--- a/src/Numerics/Providers/Common/NativeProviderLoader.cs
+++ b/src/Providers.CUDA/NativeProviderLoader.cs
@@ -27,8 +27,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
using System;
using System.Collections.Generic;
using System.IO;
@@ -37,7 +35,7 @@ using System.Runtime.InteropServices;
using System.Security;
using System.Threading;
-namespace MathNet.Numerics.Providers.Common
+namespace MathNet.Numerics.Providers.CUDA
{
///
/// Helper class to load native libraries depending on the architecture of the OS and process.
@@ -252,5 +250,3 @@ namespace MathNet.Numerics.Providers.Common
}
}
}
-
-#endif
diff --git a/src/Providers.CUDA/Providers.CUDA.csproj b/src/Providers.CUDA/Providers.CUDA.csproj
new file mode 100644
index 00000000..75e95cb6
--- /dev/null
+++ b/src/Providers.CUDA/Providers.CUDA.csproj
@@ -0,0 +1,34 @@
+
+
+
+ Library
+ net5.0;net461;net40;netstandard2.0
+ MathNet.Numerics.Providers.CUDA
+ MathNet.Numerics.Providers.CUDA
+ true
+ MathNet.Numerics.Providers.CUDA$(PackageIdSuffix)
+ 4.15.0
+
+ Math.NET Numerics CUDA Provider$(TitleSuffix)
+ Math.NET Numerics is the numerical foundation of the Math.NET project, aiming to provide methods and algorithms for numerical computations in science, engineering and every day use. Supports .Net 5.0 or higher, .NET Standard 2.0 and .NET Framework 4.0 or higher, on Windows, Linux and Mac.$(DescriptionSuffix)
+ Precision: Round (with integer part rounding) ~Jon Larborn
+Precision: RoundToMultiple, RoundToPower
+F#: BigRational.FromDecimal ~Brian Berns
+ true
+ false
+ true
+ true
+ 1701;1702;1705;1591;1573
+ true
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Numerics/Providers/Common/Cuda/SafeNativeMethods.cs b/src/Providers.CUDA/SafeNativeMethods.cs
similarity index 99%
rename from src/Numerics/Providers/Common/Cuda/SafeNativeMethods.cs
rename to src/Providers.CUDA/SafeNativeMethods.cs
index a072b997..8acdc8a6 100644
--- a/src/Numerics/Providers/Common/Cuda/SafeNativeMethods.cs
+++ b/src/Providers.CUDA/SafeNativeMethods.cs
@@ -26,15 +26,13 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
using System;
using System.Runtime.InteropServices;
using System.Security;
using MathNet.Numerics.Providers.LinearAlgebra;
using Complex = System.Numerics.Complex;
-namespace MathNet.Numerics.Providers.Common.Cuda
+namespace MathNet.Numerics.Providers.CUDA
{
///
/// P/Invoke methods to the native math libraries.
@@ -375,5 +373,3 @@ namespace MathNet.Numerics.Providers.Common.Cuda
// ReSharper restore InconsistentNaming
}
}
-
-#endif
diff --git a/src/Providers.CUDA/paket.references b/src/Providers.CUDA/paket.references
new file mode 100644
index 00000000..a954f0e2
--- /dev/null
+++ b/src/Providers.CUDA/paket.references
@@ -0,0 +1 @@
+Microsoft.NETFramework.ReferenceAssemblies
diff --git a/src/Providers.MKL/ArrayExtensions.cs b/src/Providers.MKL/ArrayExtensions.cs
new file mode 100644
index 00000000..5f03eea4
--- /dev/null
+++ b/src/Providers.MKL/ArrayExtensions.cs
@@ -0,0 +1,80 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// https://numerics.mathdotnet.com
+// https://github.com/mathnet/mathnet-numerics
+//
+// Copyright (c) 2009-2021 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using Complex = System.Numerics.Complex;
+
+namespace MathNet.Numerics.Providers.MKL
+{
+ ///
+ /// Useful extension methods for Arrays.
+ ///
+ internal static class ArrayExtensions
+ {
+ ///
+ /// Copies the values from on array to another.
+ ///
+ /// The source array.
+ /// The destination array.
+ public static void Copy(this double[] source, double[] dest)
+ {
+ Buffer.BlockCopy(source, 0, dest, 0, source.Length * Constants.SizeOfDouble);
+ }
+
+ ///
+ /// Copies the values from on array to another.
+ ///
+ /// The source array.
+ /// The destination array.
+ public static void Copy(this float[] source, float[] dest)
+ {
+ Buffer.BlockCopy(source, 0, dest, 0, source.Length * Constants.SizeOfFloat);
+ }
+
+ ///
+ /// Copies the values from on array to another.
+ ///
+ /// The source array.
+ /// The destination array.
+ public static void Copy(this Complex[] source, Complex[] dest)
+ {
+ Array.Copy(source, 0, dest, 0, source.Length);
+ }
+
+ ///
+ /// Copies the values from on array to another.
+ ///
+ /// The source array.
+ /// The destination array.
+ public static void Copy(this Complex32[] source, Complex32[] dest)
+ {
+ Array.Copy(source, 0, dest, 0, source.Length);
+ }
+ }
+}
diff --git a/src/Providers.MKL/Compatibility.cs b/src/Providers.MKL/Compatibility.cs
new file mode 100644
index 00000000..0122997a
--- /dev/null
+++ b/src/Providers.MKL/Compatibility.cs
@@ -0,0 +1,44 @@
+using System.Globalization;
+
+#if NET40
+namespace System.Runtime.CompilerServices
+{
+ internal class FormattableStringFactory
+ {
+ public static FormattableString Create(string format, params object[] args)
+ {
+ return new FormattableString(format, args);
+ }
+ }
+}
+
+namespace System
+{
+ internal class FormattableString
+ {
+ private readonly string format;
+ private readonly object[] args;
+
+ public FormattableString(string format, object[] args)
+ {
+ this.format = format;
+ this.args = args;
+ }
+
+ public static string Invariant(FormattableString messageFormat)
+ {
+ return messageFormat.ToString(CultureInfo.InvariantCulture);
+ }
+
+ public string ToString(IFormatProvider formatProvider)
+ {
+ return string.Format(formatProvider, format, args);
+ }
+
+ public override string ToString()
+ {
+ return string.Format(format, args);
+ }
+ }
+}
+#endif
diff --git a/src/Providers.MKL/FourierTransform/MklFourierTransformControl.cs b/src/Providers.MKL/FourierTransform/MklFourierTransformControl.cs
new file mode 100644
index 00000000..216ead6b
--- /dev/null
+++ b/src/Providers.MKL/FourierTransform/MklFourierTransformControl.cs
@@ -0,0 +1,93 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// https://numerics.mathdotnet.com
+// https://github.com/mathnet/mathnet-numerics
+//
+// Copyright (c) 2009-2021 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using MathNet.Numerics.Providers.FourierTransform;
+
+namespace MathNet.Numerics.Providers.MKL.FourierTransform
+{
+ public class MklFourierTransformControl : IProviderCreator
+ {
+ const string EnvVarFFTProviderPath = "MathNetNumericsFFTProviderPath";
+
+ ///
+ /// Optional path to try to load native provider binaries from.
+ /// If not set, Numerics will fall back to the environment variable
+ /// `MathNetNumericsMKLProviderPath` or the default probing paths.
+ ///
+ public static string HintPath { get; set; }
+
+ public static IFourierTransformProvider CreateNativeMKL()
+ {
+ return new MklFourierTransformProvider(GetCombinedHintPath());
+ }
+
+ public static void UseNativeMKL()
+ {
+ FourierTransformControl.Provider = CreateNativeMKL();
+ }
+
+ public static bool TryUseNativeMKL()
+ {
+ return FourierTransformControl.TryUse(CreateNativeMKL());
+ }
+
+ static string GetCombinedHintPath()
+ {
+ if (!String.IsNullOrEmpty(HintPath))
+ {
+ return HintPath;
+ }
+
+ if (!String.IsNullOrEmpty(FourierTransformControl.HintPath))
+ {
+ return FourierTransformControl.HintPath;
+ }
+
+ var value = Environment.GetEnvironmentVariable(MklControl.EnvVarMKLProviderPath);
+ if (!String.IsNullOrEmpty(value))
+ {
+ return value;
+ }
+
+ value = Environment.GetEnvironmentVariable(EnvVarFFTProviderPath);
+ if (!String.IsNullOrEmpty(value))
+ {
+ return value;
+ }
+
+ return null;
+ }
+
+ public IFourierTransformProvider CreateProvider()
+ {
+ return CreateNativeMKL();
+ }
+ }
+}
diff --git a/src/Numerics/Providers/FourierTransform/Mkl/MklFourierTransformProvider.cs b/src/Providers.MKL/FourierTransform/MklFourierTransformProvider.cs
similarity index 99%
rename from src/Numerics/Providers/FourierTransform/Mkl/MklFourierTransformProvider.cs
rename to src/Providers.MKL/FourierTransform/MklFourierTransformProvider.cs
index 611af5a7..b211d213 100644
--- a/src/Numerics/Providers/FourierTransform/Mkl/MklFourierTransformProvider.cs
+++ b/src/Providers.MKL/FourierTransform/MklFourierTransformProvider.cs
@@ -26,14 +26,12 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
using System;
using System.Threading;
-using MathNet.Numerics.Providers.Common.Mkl;
+using MathNet.Numerics.Providers.FourierTransform;
using Complex = System.Numerics.Complex;
-namespace MathNet.Numerics.Providers.FourierTransform.Mkl
+namespace MathNet.Numerics.Providers.MKL.FourierTransform
{
internal class MklFourierTransformProvider : IFourierTransformProvider, IDisposable
{
@@ -367,5 +365,3 @@ namespace MathNet.Numerics.Providers.FourierTransform.Mkl
}
}
}
-
-#endif
diff --git a/src/Providers.MKL/LinearAlgebra/MklLinearAlgebraControl.cs b/src/Providers.MKL/LinearAlgebra/MklLinearAlgebraControl.cs
new file mode 100644
index 00000000..ba473a11
--- /dev/null
+++ b/src/Providers.MKL/LinearAlgebra/MklLinearAlgebraControl.cs
@@ -0,0 +1,102 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// https://numerics.mathdotnet.com
+// https://github.com/mathnet/mathnet-numerics
+//
+// Copyright (c) 2009-2021 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using MathNet.Numerics.Providers.LinearAlgebra;
+
+namespace MathNet.Numerics.Providers.MKL.LinearAlgebra
+{
+ public class MklLinearAlgebraControl : IProviderCreator
+ {
+ const string EnvVarLAProviderPath = "MathNetNumericsLAProviderPath";
+
+ ///
+ /// Optional path to try to load native provider binaries from.
+ /// If not set, Numerics will fall back to the environment variable
+ /// `MathNetNumericsMKLProviderPath` or the default probing paths.
+ ///
+ public static string HintPath { get; set; }
+
+ public static ILinearAlgebraProvider CreateNativeMKL(
+ MklConsistency consistency = MklConsistency.Auto,
+ MklPrecision precision = MklPrecision.Double,
+ MklAccuracy accuracy = MklAccuracy.High)
+ {
+ return new MklLinearAlgebraProvider(GetCombinedHintPath(), consistency, precision, accuracy);
+ }
+
+ public static void UseNativeMKL(
+ MklConsistency consistency = MklConsistency.Auto,
+ MklPrecision precision = MklPrecision.Double,
+ MklAccuracy accuracy = MklAccuracy.High)
+ {
+ LinearAlgebraControl.Provider = CreateNativeMKL(consistency, precision, accuracy);
+ }
+
+ public static bool TryUseNativeMKL(
+ MklConsistency consistency = MklConsistency.Auto,
+ MklPrecision precision = MklPrecision.Double,
+ MklAccuracy accuracy = MklAccuracy.High)
+ {
+ return LinearAlgebraControl.TryUse(CreateNativeMKL(consistency, precision, accuracy));
+ }
+
+ static string GetCombinedHintPath()
+ {
+ if (!String.IsNullOrEmpty(HintPath))
+ {
+ return HintPath;
+ }
+
+ if (!String.IsNullOrEmpty(LinearAlgebraControl.HintPath))
+ {
+ return LinearAlgebraControl.HintPath;
+ }
+
+ var value = Environment.GetEnvironmentVariable(MklControl.EnvVarMKLProviderPath);
+ if (!String.IsNullOrEmpty(value))
+ {
+ return value;
+ }
+
+ value = Environment.GetEnvironmentVariable(EnvVarLAProviderPath);
+ if (!String.IsNullOrEmpty(value))
+ {
+ return value;
+ }
+
+ return null;
+ }
+
+ public ILinearAlgebraProvider CreateProvider()
+ {
+ return CreateNativeMKL();
+ }
+ }
+}
diff --git a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Complex.cs b/src/Providers.MKL/LinearAlgebra/MklLinearAlgebraProvider.Complex.cs
similarity index 99%
rename from src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Complex.cs
rename to src/Providers.MKL/LinearAlgebra/MklLinearAlgebraProvider.Complex.cs
index a632ab64..d14c5474 100644
--- a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Complex.cs
+++ b/src/Providers.MKL/LinearAlgebra/MklLinearAlgebraProvider.Complex.cs
@@ -27,15 +27,13 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
using System;
using System.Security;
using MathNet.Numerics.LinearAlgebra.Factorization;
-using MathNet.Numerics.Providers.Common.Mkl;
+using MathNet.Numerics.Providers.LinearAlgebra;
using Complex = System.Numerics.Complex;
-namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
+namespace MathNet.Numerics.Providers.MKL.LinearAlgebra
{
///
/// Intel's Math Kernel Library (MKL) linear algebra provider.
@@ -1200,5 +1198,3 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
}
}
}
-
-#endif
diff --git a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Complex32.cs b/src/Providers.MKL/LinearAlgebra/MklLinearAlgebraProvider.Complex32.cs
similarity index 99%
rename from src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Complex32.cs
rename to src/Providers.MKL/LinearAlgebra/MklLinearAlgebraProvider.Complex32.cs
index cfbdd8de..4d3c8b3a 100644
--- a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Complex32.cs
+++ b/src/Providers.MKL/LinearAlgebra/MklLinearAlgebraProvider.Complex32.cs
@@ -27,15 +27,13 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
using System;
using System.Security;
using MathNet.Numerics.LinearAlgebra.Factorization;
-using MathNet.Numerics.Providers.Common.Mkl;
+using MathNet.Numerics.Providers.LinearAlgebra;
using Complex = System.Numerics.Complex;
-namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
+namespace MathNet.Numerics.Providers.MKL.LinearAlgebra
{
///
/// Intel's Math Kernel Library (MKL) linear algebra provider.
@@ -1195,5 +1193,3 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
}
}
}
-
-#endif
diff --git a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Double.cs b/src/Providers.MKL/LinearAlgebra/MklLinearAlgebraProvider.Double.cs
similarity index 99%
rename from src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Double.cs
rename to src/Providers.MKL/LinearAlgebra/MklLinearAlgebraProvider.Double.cs
index cbb0b590..9c97195d 100644
--- a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Double.cs
+++ b/src/Providers.MKL/LinearAlgebra/MklLinearAlgebraProvider.Double.cs
@@ -27,15 +27,13 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
using System;
using System.Security;
using MathNet.Numerics.LinearAlgebra.Factorization;
-using MathNet.Numerics.Providers.Common.Mkl;
+using MathNet.Numerics.Providers.LinearAlgebra;
using Complex = System.Numerics.Complex;
-namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
+namespace MathNet.Numerics.Providers.MKL.LinearAlgebra
{
///
/// Intel's Math Kernel Library (MKL) linear algebra provider.
@@ -1200,5 +1198,3 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
}
}
}
-
-#endif
diff --git a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Single.cs b/src/Providers.MKL/LinearAlgebra/MklLinearAlgebraProvider.Single.cs
similarity index 99%
rename from src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Single.cs
rename to src/Providers.MKL/LinearAlgebra/MklLinearAlgebraProvider.Single.cs
index 6a85e797..3cbea25b 100644
--- a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Single.cs
+++ b/src/Providers.MKL/LinearAlgebra/MklLinearAlgebraProvider.Single.cs
@@ -27,15 +27,13 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
using System;
using System.Security;
using MathNet.Numerics.LinearAlgebra.Factorization;
-using MathNet.Numerics.Providers.Common.Mkl;
+using MathNet.Numerics.Providers.LinearAlgebra;
using Complex = System.Numerics.Complex;
-namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
+namespace MathNet.Numerics.Providers.MKL.LinearAlgebra
{
///
/// Intel's Math Kernel Library (MKL) linear algebra provider.
@@ -1195,5 +1193,3 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
}
}
}
-
-#endif
diff --git a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs b/src/Providers.MKL/LinearAlgebra/MklLinearAlgebraProvider.cs
similarity index 95%
rename from src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs
rename to src/Providers.MKL/LinearAlgebra/MklLinearAlgebraProvider.cs
index 7bd81b48..a663577c 100644
--- a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs
+++ b/src/Providers.MKL/LinearAlgebra/MklLinearAlgebraProvider.cs
@@ -27,12 +27,10 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
using System;
-using MathNet.Numerics.Providers.Common.Mkl;
+using MathNet.Numerics.Providers.LinearAlgebra.Managed;
-namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
+namespace MathNet.Numerics.Providers.MKL.LinearAlgebra
{
///
/// Error codes return from the MKL provider.
@@ -48,7 +46,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
///
/// Intel's Math Kernel Library (MKL) linear algebra provider.
///
- internal partial class MklLinearAlgebraProvider : Managed.ManagedLinearAlgebraProvider, IDisposable
+ internal partial class MklLinearAlgebraProvider : ManagedLinearAlgebraProvider, IDisposable
{
const int MinimumCompatibleRevision = 4;
@@ -130,5 +128,3 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
}
}
}
-
-#endif
diff --git a/src/Providers.MKL/MklControl.cs b/src/Providers.MKL/MklControl.cs
new file mode 100644
index 00000000..a6a2023c
--- /dev/null
+++ b/src/Providers.MKL/MklControl.cs
@@ -0,0 +1,80 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// https://numerics.mathdotnet.com
+// https://github.com/mathnet/mathnet-numerics
+//
+// Copyright (c) 2009-2021 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using MathNet.Numerics.Providers.MKL.FourierTransform;
+using MathNet.Numerics.Providers.MKL.LinearAlgebra;
+using MathNet.Numerics.Providers.MKL.SparseSolver;
+
+namespace MathNet.Numerics.Providers.MKL
+{
+ public static class MklControl
+ {
+ internal const string EnvVarMKLProviderPath = "MathNetNumericsMKLProviderPath";
+
+ ///
+ /// Use the Intel MKL native provider for linear algebra.
+ /// Throws if it is not available or failed to initialize, in which case the previous provider is still active.
+ ///
+ public static void UseNativeMKL()
+ {
+ MklLinearAlgebraControl.UseNativeMKL();
+ MklFourierTransformControl.UseNativeMKL();
+ MklSparseSolverControl.UseNativeMKL();
+ }
+
+ ///
+ /// Use the Intel MKL native provider for linear algebra, with the specified configuration parameters.
+ /// Throws if it is not available or failed to initialize, in which case the previous provider is still active.
+ ///
+ public static void UseNativeMKL(
+ MklConsistency consistency = MklConsistency.Auto,
+ MklPrecision precision = MklPrecision.Double,
+ MklAccuracy accuracy = MklAccuracy.High)
+ {
+ MklLinearAlgebraControl.UseNativeMKL(consistency, precision, accuracy);
+ MklFourierTransformControl.UseNativeMKL();
+ MklSparseSolverControl.UseNativeMKL();
+ }
+
+ ///
+ /// Try to use the Intel MKL native provider for linear algebra.
+ ///
+ ///
+ /// True if the provider was found and initialized successfully.
+ /// False if it failed and the previous provider is still active.
+ ///
+ public static bool TryUseNativeMKL()
+ {
+ bool linearAlgebra = MklLinearAlgebraControl.TryUseNativeMKL();
+ bool fourierTransform = MklFourierTransformControl.TryUseNativeMKL();
+ bool directSparseSolver = MklSparseSolverControl.TryUseNativeMKL();
+ return linearAlgebra || fourierTransform || directSparseSolver;
+ }
+ }
+}
diff --git a/src/Numerics/Providers/Common/Mkl/MklProvider.cs b/src/Providers.MKL/MklProvider.cs
similarity index 99%
rename from src/Numerics/Providers/Common/Mkl/MklProvider.cs
rename to src/Providers.MKL/MklProvider.cs
index e0a73908..c5659c41 100644
--- a/src/Numerics/Providers/Common/Mkl/MklProvider.cs
+++ b/src/Providers.MKL/MklProvider.cs
@@ -27,12 +27,10 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
using System;
using System.Collections.Generic;
-namespace MathNet.Numerics.Providers.Common.Mkl
+namespace MathNet.Numerics.Providers.MKL
{
public static class MklProvider
{
@@ -83,7 +81,6 @@ namespace MathNet.Numerics.Providers.Common.Mkl
}
/// Revision
- [CLSCompliant(false)]
public static int Load(
string hintPath = null,
MklConsistency consistency = MklConsistency.Auto,
@@ -346,5 +343,3 @@ namespace MathNet.Numerics.Providers.Common.Mkl
}
}
}
-
-#endif
diff --git a/src/Numerics/Providers/Common/Mkl/MklProviderCapabilities.cs b/src/Providers.MKL/MklProviderCapabilities.cs
similarity index 96%
rename from src/Numerics/Providers/Common/Mkl/MklProviderCapabilities.cs
rename to src/Providers.MKL/MklProviderCapabilities.cs
index 0e90dd2e..b177cf46 100644
--- a/src/Numerics/Providers/Common/Mkl/MklProviderCapabilities.cs
+++ b/src/Providers.MKL/MklProviderCapabilities.cs
@@ -27,9 +27,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
-namespace MathNet.Numerics.Providers.Common.Mkl
+namespace MathNet.Numerics.Providers.MKL
{
internal enum ProviderPlatform : int
{
@@ -61,5 +59,3 @@ namespace MathNet.Numerics.Providers.Common.Mkl
SparseSolverMinor = 513,
}
}
-
-#endif
diff --git a/src/Numerics/Providers/Common/Mkl/MklProviderPrecision.cs b/src/Providers.MKL/MklProviderPrecision.cs
similarity index 95%
rename from src/Numerics/Providers/Common/Mkl/MklProviderPrecision.cs
rename to src/Providers.MKL/MklProviderPrecision.cs
index 45c5ed6c..318c055c 100644
--- a/src/Numerics/Providers/Common/Mkl/MklProviderPrecision.cs
+++ b/src/Providers.MKL/MklProviderPrecision.cs
@@ -27,9 +27,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-using System;
-
-namespace MathNet.Numerics.Providers.Common.Mkl
+namespace MathNet.Numerics.Providers.MKL
{
///
/// Consistency vs. performance trade-off between runs on different machines.
@@ -50,14 +48,12 @@ namespace MathNet.Numerics.Providers.Common.Mkl
AVX2 = 10
}
- [CLSCompliant(false)]
public enum MklAccuracy : uint
{
Low = 0x1,
High = 0x2
}
- [CLSCompliant(false)]
public enum MklPrecision : uint
{
Single = 0x10,
diff --git a/src/Providers.MKL/NativeProviderLoader.cs b/src/Providers.MKL/NativeProviderLoader.cs
new file mode 100644
index 00000000..96d21224
--- /dev/null
+++ b/src/Providers.MKL/NativeProviderLoader.cs
@@ -0,0 +1,252 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// http://numerics.mathdotnet.com
+// http://github.com/mathnet/mathnet-numerics
+//
+// Copyright (c) 2009-2016 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Reflection;
+using System.Runtime.InteropServices;
+using System.Security;
+using System.Threading;
+
+namespace MathNet.Numerics.Providers.MKL
+{
+ ///
+ /// Helper class to load native libraries depending on the architecture of the OS and process.
+ ///
+ internal static class NativeProviderLoader
+ {
+ static readonly object StaticLock = new Object();
+
+ const string X86 = "x86";
+ const string X64 = "x64";
+ const string IA64 = "ia64";
+ const string ARM = "arm";
+ const string ARM64 = "arm64";
+
+ ///
+ /// Dictionary of handles to previously loaded libraries,
+ ///
+ static readonly Lazy> NativeHandles = new Lazy>(LazyThreadSafetyMode.PublicationOnly);
+
+ ///
+ /// Gets a string indicating the architecture and bitness of the current process.
+ ///
+ static readonly Lazy ArchitectureKey = new Lazy(EvaluateArchitectureKey, LazyThreadSafetyMode.PublicationOnly);
+
+ ///
+ /// If the last native library failed to load then gets the corresponding exception
+ /// which occurred or null if the library was successfully loaded.
+ ///
+ internal static Exception LastException { get; private set; }
+
+ static bool IsUnix
+ {
+ get
+ {
+ var p = Environment.OSVersion.Platform;
+ return p == PlatformID.Unix || p == PlatformID.MacOSX;
+ }
+ }
+
+ static string EvaluateArchitectureKey()
+ {
+ //return (IntPtr.Size == 8) ? X64 : X86;
+ if (IsUnix)
+ {
+
+ // Only support x86 and amd64 on Unix as there isn't a reliable way to detect the architecture
+ return Environment.Is64BitProcess ? X64 : X86;
+
+ }
+
+ var architecture = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
+
+ if (string.Equals(architecture, "x86", StringComparison.OrdinalIgnoreCase))
+ {
+ return X86;
+ }
+
+ if (string.Equals(architecture, "amd64", StringComparison.OrdinalIgnoreCase)
+ || string.Equals(architecture, "x64", StringComparison.OrdinalIgnoreCase))
+ {
+ return Environment.Is64BitProcess ? X64 : X86;
+ }
+
+ if (string.Equals(architecture, "ia64", StringComparison.OrdinalIgnoreCase))
+ {
+ return IA64;
+ }
+
+ if (string.Equals(architecture, "arm", StringComparison.OrdinalIgnoreCase))
+ {
+ return Environment.Is64BitProcess ? ARM64 : ARM;
+ }
+
+ // Fallback if unknown
+ return architecture;
+ }
+
+ ///
+ /// Load the native library with the given filename.
+ ///
+ /// The file name of the library to load.
+ /// Hint path where to look for the native binaries. Can be null.
+ /// True if the library was successfully loaded or if it has already been loaded.
+ internal static bool TryLoad(string fileName, string hintPath)
+ {
+ if (string.IsNullOrEmpty(fileName))
+ {
+ throw new ArgumentNullException(nameof(fileName));
+ }
+
+ // If we have hint path provided by the user, look there first
+ if (TryLoadFromDirectory(fileName, hintPath))
+ {
+ return true;
+ }
+
+ // If we have an overall hint path provided by the user, look there next
+ if (Control.NativeProviderPath != hintPath && TryLoadFromDirectory(fileName, Control.NativeProviderPath))
+ {
+ return true;
+ }
+
+ // Look under the current AppDomain's base directory
+ if (TryLoadFromDirectory(fileName, AppDomain.CurrentDomain.BaseDirectory))
+ {
+ return true;
+ }
+
+ // Look at this assembly's directory
+ if (TryLoadFromDirectory(fileName, Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)))
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ ///
+ /// Try to load a native library by providing its name and a directory.
+ /// Tries to load an implementation suitable for the current CPU architecture
+ /// and process mode if there is a matching subfolder.
+ ///
+ /// True if the library was successfully loaded or if it has already been loaded.
+ static bool TryLoadFromDirectory(string fileName, string directory)
+ {
+ if (!Directory.Exists(directory))
+ {
+ return false;
+ }
+
+ directory = Path.GetFullPath(directory);
+
+ // If we have a know architecture, try the matching subdirectory first
+ var architecture = ArchitectureKey.Value;
+ if (!string.IsNullOrEmpty(architecture) && TryLoadFile(new FileInfo(Path.Combine(Path.Combine(directory, architecture), fileName))))
+ {
+ return true;
+ }
+
+ // Otherwise try to load directly from the provided directory
+ return TryLoadFile(new FileInfo(Path.Combine(directory, fileName)));
+ }
+
+ ///
+ /// Try to load a native library by providing the full path including the file name of the library.
+ ///
+ /// True if the library was successfully loaded or if it has already been loaded.
+ static bool TryLoadFile(FileInfo file)
+ {
+ lock (StaticLock)
+ {
+ IntPtr libraryHandle;
+ if (NativeHandles.Value.TryGetValue(file.Name, out libraryHandle))
+ {
+ return true;
+ }
+
+ if (!file.Exists)
+ {
+ // If the library isn't found within an architecture specific folder then return false
+ // to allow normal P/Invoke searching behavior when the library is called
+ return false;
+ }
+
+ // If successful this will return a handle to the library
+ libraryHandle = IsUnix ? UnixLoader.LoadLibrary(file.FullName) : WindowsLoader.LoadLibrary(file.FullName);
+ if (libraryHandle == IntPtr.Zero)
+ {
+ int lastError = Marshal.GetLastWin32Error();
+ var exception = new System.ComponentModel.Win32Exception(lastError);
+ LastException = exception;
+ }
+ else
+ {
+ LastException = null;
+ NativeHandles.Value[file.Name] = libraryHandle;
+ }
+
+ return libraryHandle != IntPtr.Zero;
+ }
+ }
+
+ [SuppressUnmanagedCodeSecurity]
+ [SecurityCritical]
+ static class WindowsLoader
+ {
+ public static IntPtr LoadLibrary(string fileName)
+ {
+ return LoadLibraryEx(fileName, IntPtr.Zero, LOAD_WITH_ALTERED_SEARCH_PATH);
+ }
+
+ // Search for dependencies in the library's directory rather than the calling process's directory
+ const uint LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008;
+
+ [DllImport("kernel32", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode, SetLastError = true)]
+ static extern IntPtr LoadLibraryEx(string fileName, IntPtr reservedNull, uint flags);
+ }
+
+ [SuppressUnmanagedCodeSecurity]
+ [SecurityCritical]
+ static class UnixLoader
+ {
+ public static IntPtr LoadLibrary(string fileName)
+ {
+ return dlopen(fileName, RTLD_NOW);
+ }
+
+ const int RTLD_NOW = 2;
+
+ [DllImport("libdl.so", SetLastError = true)]
+ static extern IntPtr dlopen(String fileName, int flags);
+ }
+ }
+}
diff --git a/src/Providers.MKL/Providers.MKL.csproj b/src/Providers.MKL/Providers.MKL.csproj
new file mode 100644
index 00000000..87584637
--- /dev/null
+++ b/src/Providers.MKL/Providers.MKL.csproj
@@ -0,0 +1,34 @@
+
+
+
+ Library
+ net5.0;net461;net40;netstandard2.0
+ MathNet.Numerics.Providers.MKL
+ MathNet.Numerics.Providers.MKL
+ true
+ MathNet.Numerics.Providers.MKL$(PackageIdSuffix)
+ 4.15.0
+
+ Math.NET Numerics MKL Provider$(TitleSuffix)
+ Math.NET Numerics is the numerical foundation of the Math.NET project, aiming to provide methods and algorithms for numerical computations in science, engineering and every day use. Supports .Net 5.0 or higher, .NET Standard 2.0 and .NET Framework 4.0 or higher, on Windows, Linux and Mac.$(DescriptionSuffix)
+ Precision: Round (with integer part rounding) ~Jon Larborn
+Precision: RoundToMultiple, RoundToPower
+F#: BigRational.FromDecimal ~Brian Berns
+ true
+ false
+ true
+ true
+ 1701;1702;1705;1591;1573
+ true
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Numerics/Providers/Common/Mkl/SafeNativeMethods.cs b/src/Providers.MKL/SafeNativeMethods.cs
similarity index 99%
rename from src/Numerics/Providers/Common/Mkl/SafeNativeMethods.cs
rename to src/Providers.MKL/SafeNativeMethods.cs
index 1abaffea..5844b4bd 100644
--- a/src/Numerics/Providers/Common/Mkl/SafeNativeMethods.cs
+++ b/src/Providers.MKL/SafeNativeMethods.cs
@@ -26,15 +26,13 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
using System;
using System.Runtime.InteropServices;
using System.Security;
using MathNet.Numerics.Providers.LinearAlgebra;
using Complex = System.Numerics.Complex;
-namespace MathNet.Numerics.Providers.Common.Mkl
+namespace MathNet.Numerics.Providers.MKL
{
///
/// P/Invoke methods to the native math libraries.
@@ -457,5 +455,3 @@ namespace MathNet.Numerics.Providers.Common.Mkl
// ReSharper restore InconsistentNaming
}
}
-
-#endif
diff --git a/src/Providers.MKL/SparseSolver/MklSparseSolverControl.cs b/src/Providers.MKL/SparseSolver/MklSparseSolverControl.cs
new file mode 100644
index 00000000..0e06b00c
--- /dev/null
+++ b/src/Providers.MKL/SparseSolver/MklSparseSolverControl.cs
@@ -0,0 +1,93 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// https://numerics.mathdotnet.com
+// https://github.com/mathnet/mathnet-numerics
+//
+// Copyright (c) 2009-2021 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using MathNet.Numerics.Providers.SparseSolver;
+
+namespace MathNet.Numerics.Providers.MKL.SparseSolver
+{
+ public class MklSparseSolverControl : IProviderCreator
+ {
+ const string EnvVarSSProviderPath = "MathNetNumericsSSProviderPath";
+
+ ///
+ /// Optional path to try to load native provider binaries from.
+ /// If not set, Numerics will fall back to the environment variable
+ /// `MathNetNumericsMKLProviderPath` or the default probing paths.
+ ///
+ public static string HintPath { get; set; }
+
+ public static ISparseSolverProvider CreateNativeMKL()
+ {
+ return new MklSparseSolverProvider(GetCombinedHintPath());
+ }
+
+ public static void UseNativeMKL()
+ {
+ SparseSolverControl.Provider = CreateNativeMKL();
+ }
+
+ public static bool TryUseNativeMKL()
+ {
+ return SparseSolverControl.TryUse(CreateNativeMKL());
+ }
+
+ static string GetCombinedHintPath()
+ {
+ if (!String.IsNullOrEmpty(HintPath))
+ {
+ return HintPath;
+ }
+
+ if (!String.IsNullOrEmpty(SparseSolverControl.HintPath))
+ {
+ return SparseSolverControl.HintPath;
+ }
+
+ var value = Environment.GetEnvironmentVariable(MklControl.EnvVarMKLProviderPath);
+ if (!String.IsNullOrEmpty(value))
+ {
+ return value;
+ }
+
+ value = Environment.GetEnvironmentVariable(EnvVarSSProviderPath);
+ if (!String.IsNullOrEmpty(value))
+ {
+ return value;
+ }
+
+ return null;
+ }
+
+ public ISparseSolverProvider CreateProvider()
+ {
+ return CreateNativeMKL();
+ }
+ }
+}
diff --git a/src/Numerics/Providers/SparseSolver/Mkl/MklSparseSolverProvider.Complex.cs b/src/Providers.MKL/SparseSolver/MklSparseSolverProvider.Complex.cs
similarity index 96%
rename from src/Numerics/Providers/SparseSolver/Mkl/MklSparseSolverProvider.Complex.cs
rename to src/Providers.MKL/SparseSolver/MklSparseSolverProvider.Complex.cs
index 612d6701..c32a875d 100644
--- a/src/Numerics/Providers/SparseSolver/Mkl/MklSparseSolverProvider.Complex.cs
+++ b/src/Providers.MKL/SparseSolver/MklSparseSolverProvider.Complex.cs
@@ -1,11 +1,9 @@
-#if NATIVE
-
-using MathNet.Numerics.Providers.Common.Mkl;
-using System;
+using System;
using System.Security;
+using MathNet.Numerics.Providers.SparseSolver;
using Complex = System.Numerics.Complex;
-namespace MathNet.Numerics.Providers.SparseSolver.Mkl
+namespace MathNet.Numerics.Providers.MKL.SparseSolver
{
///
/// Intel's Math Kernel Library (MKL) direct sparse solver provider.
@@ -80,5 +78,3 @@ namespace MathNet.Numerics.Providers.SparseSolver.Mkl
}
}
}
-
-#endif
diff --git a/src/Numerics/Providers/SparseSolver/Mkl/MklSparseSolverProvider.Complex32.cs b/src/Providers.MKL/SparseSolver/MklSparseSolverProvider.Complex32.cs
similarity index 96%
rename from src/Numerics/Providers/SparseSolver/Mkl/MklSparseSolverProvider.Complex32.cs
rename to src/Providers.MKL/SparseSolver/MklSparseSolverProvider.Complex32.cs
index a341c4fa..2d80a63c 100644
--- a/src/Numerics/Providers/SparseSolver/Mkl/MklSparseSolverProvider.Complex32.cs
+++ b/src/Providers.MKL/SparseSolver/MklSparseSolverProvider.Complex32.cs
@@ -1,10 +1,8 @@
-#if NATIVE
-
-using MathNet.Numerics.Providers.Common.Mkl;
-using System;
+using System;
using System.Security;
+using MathNet.Numerics.Providers.SparseSolver;
-namespace MathNet.Numerics.Providers.SparseSolver.Mkl
+namespace MathNet.Numerics.Providers.MKL.SparseSolver
{
///
/// Intel's Math Kernel Library (MKL) direct sparse solver provider.
@@ -79,5 +77,3 @@ namespace MathNet.Numerics.Providers.SparseSolver.Mkl
}
}
}
-
-#endif
diff --git a/src/Numerics/Providers/SparseSolver/Mkl/MklSparseSolverProvider.Double.cs b/src/Providers.MKL/SparseSolver/MklSparseSolverProvider.Double.cs
similarity index 96%
rename from src/Numerics/Providers/SparseSolver/Mkl/MklSparseSolverProvider.Double.cs
rename to src/Providers.MKL/SparseSolver/MklSparseSolverProvider.Double.cs
index 162c8206..39fded7c 100644
--- a/src/Numerics/Providers/SparseSolver/Mkl/MklSparseSolverProvider.Double.cs
+++ b/src/Providers.MKL/SparseSolver/MklSparseSolverProvider.Double.cs
@@ -1,10 +1,8 @@
-#if NATIVE
-
-using MathNet.Numerics.Providers.Common.Mkl;
-using System;
+using System;
using System.Security;
+using MathNet.Numerics.Providers.SparseSolver;
-namespace MathNet.Numerics.Providers.SparseSolver.Mkl
+namespace MathNet.Numerics.Providers.MKL.SparseSolver
{
///
/// Intel's Math Kernel Library (MKL) direct sparse solver provider.
@@ -79,5 +77,3 @@ namespace MathNet.Numerics.Providers.SparseSolver.Mkl
}
}
}
-
-#endif
diff --git a/src/Numerics/Providers/SparseSolver/Mkl/MklSparseSolverProvider.Single.cs b/src/Providers.MKL/SparseSolver/MklSparseSolverProvider.Single.cs
similarity index 96%
rename from src/Numerics/Providers/SparseSolver/Mkl/MklSparseSolverProvider.Single.cs
rename to src/Providers.MKL/SparseSolver/MklSparseSolverProvider.Single.cs
index 468f5c4f..968d2a37 100644
--- a/src/Numerics/Providers/SparseSolver/Mkl/MklSparseSolverProvider.Single.cs
+++ b/src/Providers.MKL/SparseSolver/MklSparseSolverProvider.Single.cs
@@ -1,10 +1,8 @@
-#if NATIVE
-
-using MathNet.Numerics.Providers.Common.Mkl;
-using System;
+using System;
using System.Security;
+using MathNet.Numerics.Providers.SparseSolver;
-namespace MathNet.Numerics.Providers.SparseSolver.Mkl
+namespace MathNet.Numerics.Providers.MKL.SparseSolver
{
///
/// Intel's Math Kernel Library (MKL) direct sparse solver provider.
@@ -79,4 +77,3 @@ namespace MathNet.Numerics.Providers.SparseSolver.Mkl
}
}
}
-#endif
diff --git a/src/Numerics/Providers/SparseSolver/Mkl/MklSparseSolverProvider.cs b/src/Providers.MKL/SparseSolver/MklSparseSolverProvider.cs
similarity index 91%
rename from src/Numerics/Providers/SparseSolver/Mkl/MklSparseSolverProvider.cs
rename to src/Providers.MKL/SparseSolver/MklSparseSolverProvider.cs
index 84e92b5a..26f60afe 100644
--- a/src/Numerics/Providers/SparseSolver/Mkl/MklSparseSolverProvider.cs
+++ b/src/Providers.MKL/SparseSolver/MklSparseSolverProvider.cs
@@ -1,14 +1,12 @@
-#if NATIVE
+using System;
+using MathNet.Numerics.Providers.SparseSolver.Managed;
-using MathNet.Numerics.Providers.Common.Mkl;
-using System;
-
-namespace MathNet.Numerics.Providers.SparseSolver.Mkl
+namespace MathNet.Numerics.Providers.MKL.SparseSolver
{
///
/// Intel's Math Kernel Library (MKL) sparse solver provider.
///
- internal partial class MklSparseSolverProvider : Managed.ManagedSparseSolverProvider, IDisposable
+ internal partial class MklSparseSolverProvider : ManagedSparseSolverProvider, IDisposable
{
const int MinimumCompatibleRevision = 14;
@@ -72,6 +70,3 @@ namespace MathNet.Numerics.Providers.SparseSolver.Mkl
}
}
}
-
-#endif
-
diff --git a/src/Providers.MKL/paket.references b/src/Providers.MKL/paket.references
new file mode 100644
index 00000000..a954f0e2
--- /dev/null
+++ b/src/Providers.MKL/paket.references
@@ -0,0 +1 @@
+Microsoft.NETFramework.ReferenceAssemblies
diff --git a/src/Providers.OpenBLAS/ArrayExtensions.cs b/src/Providers.OpenBLAS/ArrayExtensions.cs
new file mode 100644
index 00000000..eeeb9dc2
--- /dev/null
+++ b/src/Providers.OpenBLAS/ArrayExtensions.cs
@@ -0,0 +1,80 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// https://numerics.mathdotnet.com
+// https://github.com/mathnet/mathnet-numerics
+//
+// Copyright (c) 2009-2021 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using Complex = System.Numerics.Complex;
+
+namespace MathNet.Numerics.Providers.OpenBLAS
+{
+ ///
+ /// Useful extension methods for Arrays.
+ ///
+ internal static class ArrayExtensions
+ {
+ ///
+ /// Copies the values from on array to another.
+ ///
+ /// The source array.
+ /// The destination array.
+ public static void Copy(this double[] source, double[] dest)
+ {
+ Buffer.BlockCopy(source, 0, dest, 0, source.Length * Constants.SizeOfDouble);
+ }
+
+ ///
+ /// Copies the values from on array to another.
+ ///
+ /// The source array.
+ /// The destination array.
+ public static void Copy(this float[] source, float[] dest)
+ {
+ Buffer.BlockCopy(source, 0, dest, 0, source.Length * Constants.SizeOfFloat);
+ }
+
+ ///
+ /// Copies the values from on array to another.
+ ///
+ /// The source array.
+ /// The destination array.
+ public static void Copy(this Complex[] source, Complex[] dest)
+ {
+ Array.Copy(source, 0, dest, 0, source.Length);
+ }
+
+ ///
+ /// Copies the values from on array to another.
+ ///
+ /// The source array.
+ /// The destination array.
+ public static void Copy(this Complex32[] source, Complex32[] dest)
+ {
+ Array.Copy(source, 0, dest, 0, source.Length);
+ }
+ }
+}
diff --git a/src/Providers.OpenBLAS/Compatibility.cs b/src/Providers.OpenBLAS/Compatibility.cs
new file mode 100644
index 00000000..0122997a
--- /dev/null
+++ b/src/Providers.OpenBLAS/Compatibility.cs
@@ -0,0 +1,44 @@
+using System.Globalization;
+
+#if NET40
+namespace System.Runtime.CompilerServices
+{
+ internal class FormattableStringFactory
+ {
+ public static FormattableString Create(string format, params object[] args)
+ {
+ return new FormattableString(format, args);
+ }
+ }
+}
+
+namespace System
+{
+ internal class FormattableString
+ {
+ private readonly string format;
+ private readonly object[] args;
+
+ public FormattableString(string format, object[] args)
+ {
+ this.format = format;
+ this.args = args;
+ }
+
+ public static string Invariant(FormattableString messageFormat)
+ {
+ return messageFormat.ToString(CultureInfo.InvariantCulture);
+ }
+
+ public string ToString(IFormatProvider formatProvider)
+ {
+ return string.Format(formatProvider, format, args);
+ }
+
+ public override string ToString()
+ {
+ return string.Format(format, args);
+ }
+ }
+}
+#endif
diff --git a/src/Providers.OpenBLAS/LinearAlgebra/OpenBlasLinearAlgebraControl.cs b/src/Providers.OpenBLAS/LinearAlgebra/OpenBlasLinearAlgebraControl.cs
new file mode 100644
index 00000000..b22b6355
--- /dev/null
+++ b/src/Providers.OpenBLAS/LinearAlgebra/OpenBlasLinearAlgebraControl.cs
@@ -0,0 +1,93 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// https://numerics.mathdotnet.com
+// https://github.com/mathnet/mathnet-numerics
+//
+// Copyright (c) 2009-2021 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using MathNet.Numerics.Providers.LinearAlgebra;
+
+namespace MathNet.Numerics.Providers.OpenBLAS.LinearAlgebra
+{
+ public class OpenBlasLinearAlgebraControl : IProviderCreator
+ {
+ const string EnvVarLAProviderPath = "MathNetNumericsLAProviderPath";
+
+ ///
+ /// Optional path to try to load native provider binaries from.
+ /// If not set, Numerics will fall back to the environment variable
+ /// `MathNetNumericsMKLProviderPath` or the default probing paths.
+ ///
+ public static string HintPath { get; set; }
+
+ public static ILinearAlgebraProvider CreateNativeOpenBLAS()
+ {
+ return new OpenBlasLinearAlgebraProvider(GetCombinedHintPath());
+ }
+
+ public static void UseNativeOpenBLAS()
+ {
+ LinearAlgebraControl.Provider = CreateNativeOpenBLAS();
+ }
+
+ public static bool TryUseNativeOpenBLAS()
+ {
+ return LinearAlgebraControl.TryUse(CreateNativeOpenBLAS());
+ }
+
+ static string GetCombinedHintPath()
+ {
+ if (!String.IsNullOrEmpty(HintPath))
+ {
+ return HintPath;
+ }
+
+ if (!String.IsNullOrEmpty(LinearAlgebraControl.HintPath))
+ {
+ return LinearAlgebraControl.HintPath;
+ }
+
+ var value = Environment.GetEnvironmentVariable(OpenBlasControl.EnvVarOpenBLASProviderPath);
+ if (!String.IsNullOrEmpty(value))
+ {
+ return value;
+ }
+
+ value = Environment.GetEnvironmentVariable(EnvVarLAProviderPath);
+ if (!String.IsNullOrEmpty(value))
+ {
+ return value;
+ }
+
+ return null;
+ }
+
+ public ILinearAlgebraProvider CreateProvider()
+ {
+ return CreateNativeOpenBLAS();
+ }
+ }
+}
diff --git a/src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasLinearAlgebraProvider.Complex.cs b/src/Providers.OpenBLAS/LinearAlgebra/OpenBlasLinearAlgebraProvider.Complex.cs
similarity index 99%
rename from src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasLinearAlgebraProvider.Complex.cs
rename to src/Providers.OpenBLAS/LinearAlgebra/OpenBlasLinearAlgebraProvider.Complex.cs
index d545cac0..c54ddee3 100644
--- a/src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasLinearAlgebraProvider.Complex.cs
+++ b/src/Providers.OpenBLAS/LinearAlgebra/OpenBlasLinearAlgebraProvider.Complex.cs
@@ -27,15 +27,13 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
using System;
using System.Security;
using MathNet.Numerics.LinearAlgebra.Factorization;
-using MathNet.Numerics.Providers.Common.OpenBlas;
+using MathNet.Numerics.Providers.LinearAlgebra;
using Complex = System.Numerics.Complex;
-namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
+namespace MathNet.Numerics.Providers.OpenBLAS.LinearAlgebra
{
///
/// OpenBLAS linear algebra provider.
@@ -1020,5 +1018,3 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
}
}
}
-
-#endif
diff --git a/src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasLinearAlgebraProvider.Complex32.cs b/src/Providers.OpenBLAS/LinearAlgebra/OpenBlasLinearAlgebraProvider.Complex32.cs
similarity index 99%
rename from src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasLinearAlgebraProvider.Complex32.cs
rename to src/Providers.OpenBLAS/LinearAlgebra/OpenBlasLinearAlgebraProvider.Complex32.cs
index 7c5cd120..0a648a42 100644
--- a/src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasLinearAlgebraProvider.Complex32.cs
+++ b/src/Providers.OpenBLAS/LinearAlgebra/OpenBlasLinearAlgebraProvider.Complex32.cs
@@ -27,15 +27,13 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
using System;
using System.Security;
using MathNet.Numerics.LinearAlgebra.Factorization;
-using MathNet.Numerics.Providers.Common.OpenBlas;
+using MathNet.Numerics.Providers.LinearAlgebra;
using Complex = System.Numerics.Complex;
-namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
+namespace MathNet.Numerics.Providers.OpenBLAS.LinearAlgebra
{
///
/// OpenBLAS linear algebra provider.
@@ -1015,5 +1013,3 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
}
}
}
-
-#endif
diff --git a/src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasLinearAlgebraProvider.Double.cs b/src/Providers.OpenBLAS/LinearAlgebra/OpenBlasLinearAlgebraProvider.Double.cs
similarity index 99%
rename from src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasLinearAlgebraProvider.Double.cs
rename to src/Providers.OpenBLAS/LinearAlgebra/OpenBlasLinearAlgebraProvider.Double.cs
index ecd06070..cc8d8b4e 100644
--- a/src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasLinearAlgebraProvider.Double.cs
+++ b/src/Providers.OpenBLAS/LinearAlgebra/OpenBlasLinearAlgebraProvider.Double.cs
@@ -27,15 +27,13 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
using System;
using System.Security;
using MathNet.Numerics.LinearAlgebra.Factorization;
-using MathNet.Numerics.Providers.Common.OpenBlas;
+using MathNet.Numerics.Providers.LinearAlgebra;
using Complex = System.Numerics.Complex;
-namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
+namespace MathNet.Numerics.Providers.OpenBLAS.LinearAlgebra
{
///
/// OpenBLAS linear algebra provider.
@@ -1020,5 +1018,3 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
}
}
}
-
-#endif
diff --git a/src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasLinearAlgebraProvider.Single.cs b/src/Providers.OpenBLAS/LinearAlgebra/OpenBlasLinearAlgebraProvider.Single.cs
similarity index 99%
rename from src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasLinearAlgebraProvider.Single.cs
rename to src/Providers.OpenBLAS/LinearAlgebra/OpenBlasLinearAlgebraProvider.Single.cs
index a439a143..ee0a7b62 100644
--- a/src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasLinearAlgebraProvider.Single.cs
+++ b/src/Providers.OpenBLAS/LinearAlgebra/OpenBlasLinearAlgebraProvider.Single.cs
@@ -27,15 +27,13 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
using System;
using System.Security;
using MathNet.Numerics.LinearAlgebra.Factorization;
-using MathNet.Numerics.Providers.Common.OpenBlas;
+using MathNet.Numerics.Providers.LinearAlgebra;
using Complex = System.Numerics.Complex;
-namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
+namespace MathNet.Numerics.Providers.OpenBLAS.LinearAlgebra
{
///
/// OpenBLAS linear algebra provider.
@@ -1015,5 +1013,3 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
}
}
}
-
-#endif
diff --git a/src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasLinearAlgebraProvider.cs b/src/Providers.OpenBLAS/LinearAlgebra/OpenBlasLinearAlgebraProvider.cs
similarity index 96%
rename from src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasLinearAlgebraProvider.cs
rename to src/Providers.OpenBLAS/LinearAlgebra/OpenBlasLinearAlgebraProvider.cs
index 949e9234..272035fe 100644
--- a/src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasLinearAlgebraProvider.cs
+++ b/src/Providers.OpenBLAS/LinearAlgebra/OpenBlasLinearAlgebraProvider.cs
@@ -27,12 +27,10 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
using System;
-using MathNet.Numerics.Providers.Common.OpenBlas;
+using MathNet.Numerics.Providers.LinearAlgebra.Managed;
-namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
+namespace MathNet.Numerics.Providers.OpenBLAS.LinearAlgebra
{
///
/// Error codes return from the native OpenBLAS provider.
@@ -55,7 +53,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
///
/// OpenBLAS linear algebra provider.
///
- internal partial class OpenBlasLinearAlgebraProvider : Managed.ManagedLinearAlgebraProvider, IDisposable
+ internal partial class OpenBlasLinearAlgebraProvider : ManagedLinearAlgebraProvider, IDisposable
{
const int MinimumCompatibleRevision = 1;
@@ -117,5 +115,3 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
}
}
}
-
-#endif
diff --git a/src/Providers.OpenBLAS/NativeProviderLoader.cs b/src/Providers.OpenBLAS/NativeProviderLoader.cs
new file mode 100644
index 00000000..17518d53
--- /dev/null
+++ b/src/Providers.OpenBLAS/NativeProviderLoader.cs
@@ -0,0 +1,252 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// http://numerics.mathdotnet.com
+// http://github.com/mathnet/mathnet-numerics
+//
+// Copyright (c) 2009-2016 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Reflection;
+using System.Runtime.InteropServices;
+using System.Security;
+using System.Threading;
+
+namespace MathNet.Numerics.Providers.OpenBLAS
+{
+ ///
+ /// Helper class to load native libraries depending on the architecture of the OS and process.
+ ///
+ internal static class NativeProviderLoader
+ {
+ static readonly object StaticLock = new Object();
+
+ const string X86 = "x86";
+ const string X64 = "x64";
+ const string IA64 = "ia64";
+ const string ARM = "arm";
+ const string ARM64 = "arm64";
+
+ ///
+ /// Dictionary of handles to previously loaded libraries,
+ ///
+ static readonly Lazy> NativeHandles = new Lazy>(LazyThreadSafetyMode.PublicationOnly);
+
+ ///
+ /// Gets a string indicating the architecture and bitness of the current process.
+ ///
+ static readonly Lazy ArchitectureKey = new Lazy(EvaluateArchitectureKey, LazyThreadSafetyMode.PublicationOnly);
+
+ ///
+ /// If the last native library failed to load then gets the corresponding exception
+ /// which occurred or null if the library was successfully loaded.
+ ///
+ internal static Exception LastException { get; private set; }
+
+ static bool IsUnix
+ {
+ get
+ {
+ var p = Environment.OSVersion.Platform;
+ return p == PlatformID.Unix || p == PlatformID.MacOSX;
+ }
+ }
+
+ static string EvaluateArchitectureKey()
+ {
+ //return (IntPtr.Size == 8) ? X64 : X86;
+ if (IsUnix)
+ {
+
+ // Only support x86 and amd64 on Unix as there isn't a reliable way to detect the architecture
+ return Environment.Is64BitProcess ? X64 : X86;
+
+ }
+
+ var architecture = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
+
+ if (string.Equals(architecture, "x86", StringComparison.OrdinalIgnoreCase))
+ {
+ return X86;
+ }
+
+ if (string.Equals(architecture, "amd64", StringComparison.OrdinalIgnoreCase)
+ || string.Equals(architecture, "x64", StringComparison.OrdinalIgnoreCase))
+ {
+ return Environment.Is64BitProcess ? X64 : X86;
+ }
+
+ if (string.Equals(architecture, "ia64", StringComparison.OrdinalIgnoreCase))
+ {
+ return IA64;
+ }
+
+ if (string.Equals(architecture, "arm", StringComparison.OrdinalIgnoreCase))
+ {
+ return Environment.Is64BitProcess ? ARM64 : ARM;
+ }
+
+ // Fallback if unknown
+ return architecture;
+ }
+
+ ///
+ /// Load the native library with the given filename.
+ ///
+ /// The file name of the library to load.
+ /// Hint path where to look for the native binaries. Can be null.
+ /// True if the library was successfully loaded or if it has already been loaded.
+ internal static bool TryLoad(string fileName, string hintPath)
+ {
+ if (string.IsNullOrEmpty(fileName))
+ {
+ throw new ArgumentNullException(nameof(fileName));
+ }
+
+ // If we have hint path provided by the user, look there first
+ if (TryLoadFromDirectory(fileName, hintPath))
+ {
+ return true;
+ }
+
+ // If we have an overall hint path provided by the user, look there next
+ if (Control.NativeProviderPath != hintPath && TryLoadFromDirectory(fileName, Control.NativeProviderPath))
+ {
+ return true;
+ }
+
+ // Look under the current AppDomain's base directory
+ if (TryLoadFromDirectory(fileName, AppDomain.CurrentDomain.BaseDirectory))
+ {
+ return true;
+ }
+
+ // Look at this assembly's directory
+ if (TryLoadFromDirectory(fileName, Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)))
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ ///
+ /// Try to load a native library by providing its name and a directory.
+ /// Tries to load an implementation suitable for the current CPU architecture
+ /// and process mode if there is a matching subfolder.
+ ///
+ /// True if the library was successfully loaded or if it has already been loaded.
+ static bool TryLoadFromDirectory(string fileName, string directory)
+ {
+ if (!Directory.Exists(directory))
+ {
+ return false;
+ }
+
+ directory = Path.GetFullPath(directory);
+
+ // If we have a know architecture, try the matching subdirectory first
+ var architecture = ArchitectureKey.Value;
+ if (!string.IsNullOrEmpty(architecture) && TryLoadFile(new FileInfo(Path.Combine(Path.Combine(directory, architecture), fileName))))
+ {
+ return true;
+ }
+
+ // Otherwise try to load directly from the provided directory
+ return TryLoadFile(new FileInfo(Path.Combine(directory, fileName)));
+ }
+
+ ///
+ /// Try to load a native library by providing the full path including the file name of the library.
+ ///
+ /// True if the library was successfully loaded or if it has already been loaded.
+ static bool TryLoadFile(FileInfo file)
+ {
+ lock (StaticLock)
+ {
+ IntPtr libraryHandle;
+ if (NativeHandles.Value.TryGetValue(file.Name, out libraryHandle))
+ {
+ return true;
+ }
+
+ if (!file.Exists)
+ {
+ // If the library isn't found within an architecture specific folder then return false
+ // to allow normal P/Invoke searching behavior when the library is called
+ return false;
+ }
+
+ // If successful this will return a handle to the library
+ libraryHandle = IsUnix ? UnixLoader.LoadLibrary(file.FullName) : WindowsLoader.LoadLibrary(file.FullName);
+ if (libraryHandle == IntPtr.Zero)
+ {
+ int lastError = Marshal.GetLastWin32Error();
+ var exception = new System.ComponentModel.Win32Exception(lastError);
+ LastException = exception;
+ }
+ else
+ {
+ LastException = null;
+ NativeHandles.Value[file.Name] = libraryHandle;
+ }
+
+ return libraryHandle != IntPtr.Zero;
+ }
+ }
+
+ [SuppressUnmanagedCodeSecurity]
+ [SecurityCritical]
+ static class WindowsLoader
+ {
+ public static IntPtr LoadLibrary(string fileName)
+ {
+ return LoadLibraryEx(fileName, IntPtr.Zero, LOAD_WITH_ALTERED_SEARCH_PATH);
+ }
+
+ // Search for dependencies in the library's directory rather than the calling process's directory
+ const uint LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008;
+
+ [DllImport("kernel32", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode, SetLastError = true)]
+ static extern IntPtr LoadLibraryEx(string fileName, IntPtr reservedNull, uint flags);
+ }
+
+ [SuppressUnmanagedCodeSecurity]
+ [SecurityCritical]
+ static class UnixLoader
+ {
+ public static IntPtr LoadLibrary(string fileName)
+ {
+ return dlopen(fileName, RTLD_NOW);
+ }
+
+ const int RTLD_NOW = 2;
+
+ [DllImport("libdl.so", SetLastError = true)]
+ static extern IntPtr dlopen(String fileName, int flags);
+ }
+ }
+}
diff --git a/src/Providers.OpenBLAS/OpenBlasControl.cs b/src/Providers.OpenBLAS/OpenBlasControl.cs
new file mode 100644
index 00000000..c2b7add5
--- /dev/null
+++ b/src/Providers.OpenBLAS/OpenBlasControl.cs
@@ -0,0 +1,60 @@
+//
+// Math.NET Numerics, part of the Math.NET Project
+// https://numerics.mathdotnet.com
+// https://github.com/mathnet/mathnet-numerics
+//
+// Copyright (c) 2009-2021 Math.NET
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using MathNet.Numerics.Providers.OpenBLAS.LinearAlgebra;
+
+namespace MathNet.Numerics.Providers.OpenBLAS
+{
+ public static class OpenBlasControl
+ {
+ internal const string EnvVarOpenBLASProviderPath = "MathNetNumericsOpenBLASProviderPath";
+
+ ///
+ /// Use the OpenBLAS native provider for linear algebra.
+ /// Throws if it is not available or failed to initialize, in which case the previous provider is still active.
+ ///
+ public static void UseNativeOpenBLAS()
+ {
+ OpenBlasLinearAlgebraControl.UseNativeOpenBLAS();
+ }
+
+ ///
+ /// Try to use the OpenBLAS native provider for linear algebra.
+ ///
+ ///
+ /// True if the provider was found and initialized successfully.
+ /// False if it failed and the previous provider is still active.
+ ///
+ public static bool TryUseNativeOpenBLAS()
+ {
+ bool linearAlgebra = OpenBlasLinearAlgebraControl.TryUseNativeOpenBLAS();
+ return linearAlgebra;
+ }
+ }
+}
diff --git a/src/Numerics/Providers/Common/OpenBlas/OpenBlasProvider.cs b/src/Providers.OpenBLAS/OpenBlasProvider.cs
similarity index 98%
rename from src/Numerics/Providers/Common/OpenBlas/OpenBlasProvider.cs
rename to src/Providers.OpenBLAS/OpenBlasProvider.cs
index 34dc4127..5070f668 100644
--- a/src/Numerics/Providers/Common/OpenBlas/OpenBlasProvider.cs
+++ b/src/Providers.OpenBLAS/OpenBlasProvider.cs
@@ -27,12 +27,10 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
using System;
using System.Collections.Generic;
-namespace MathNet.Numerics.Providers.Common.OpenBlas
+namespace MathNet.Numerics.Providers.OpenBLAS
{
public static class OpenBlasProvider
{
@@ -172,5 +170,3 @@ namespace MathNet.Numerics.Providers.Common.OpenBlas
}
}
}
-
-#endif
diff --git a/src/Numerics/Providers/Common/OpenBlas/OpenBlasProviderCapabilities.cs b/src/Providers.OpenBLAS/OpenBlasProviderCapabilities.cs
similarity index 95%
rename from src/Numerics/Providers/Common/OpenBlas/OpenBlasProviderCapabilities.cs
rename to src/Providers.OpenBLAS/OpenBlasProviderCapabilities.cs
index fdabbf03..e590dab9 100644
--- a/src/Numerics/Providers/Common/OpenBlas/OpenBlasProviderCapabilities.cs
+++ b/src/Providers.OpenBLAS/OpenBlasProviderCapabilities.cs
@@ -27,9 +27,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
-namespace MathNet.Numerics.Providers.Common.OpenBlas
+namespace MathNet.Numerics.Providers.OpenBLAS
{
internal enum ProviderPlatform : int
{
@@ -51,5 +49,3 @@ namespace MathNet.Numerics.Providers.Common.OpenBlas
LinearAlgebraMinor = 129
}
}
-
-#endif
diff --git a/src/Providers.OpenBLAS/Providers.OpenBLAS.csproj b/src/Providers.OpenBLAS/Providers.OpenBLAS.csproj
new file mode 100644
index 00000000..5067dc7c
--- /dev/null
+++ b/src/Providers.OpenBLAS/Providers.OpenBLAS.csproj
@@ -0,0 +1,34 @@
+
+
+
+ Library
+ net5.0;net461;net40;netstandard2.0
+ MathNet.Numerics.Providers.OpenBLAS
+ MathNet.Numerics.Providers.OpenBLAS
+ true
+ MathNet.Numerics.Providers.OpenBLAS$(PackageIdSuffix)
+ 4.15.0
+
+ Math.NET Numerics OpenBLAS Provider$(TitleSuffix)
+ Math.NET Numerics is the numerical foundation of the Math.NET project, aiming to provide methods and algorithms for numerical computations in science, engineering and every day use. Supports .Net 5.0 or higher, .NET Standard 2.0 and .NET Framework 4.0 or higher, on Windows, Linux and Mac.$(DescriptionSuffix)
+ Precision: Round (with integer part rounding) ~Jon Larborn
+Precision: RoundToMultiple, RoundToPower
+F#: BigRational.FromDecimal ~Brian Berns
+ true
+ false
+ true
+ true
+ 1701;1702;1705;1591;1573
+ true
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Numerics/Providers/Common/OpenBlas/SafeNativeMethods.cs b/src/Providers.OpenBLAS/SafeNativeMethods.cs
similarity index 99%
rename from src/Numerics/Providers/Common/OpenBlas/SafeNativeMethods.cs
rename to src/Providers.OpenBLAS/SafeNativeMethods.cs
index cbea5a6a..aa4cf90d 100644
--- a/src/Numerics/Providers/Common/OpenBlas/SafeNativeMethods.cs
+++ b/src/Providers.OpenBLAS/SafeNativeMethods.cs
@@ -26,15 +26,13 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#if NATIVE
-
using System.Runtime.InteropServices;
using System.Security;
using MathNet.Numerics.Providers.LinearAlgebra;
-using MathNet.Numerics.Providers.LinearAlgebra.OpenBlas;
+using MathNet.Numerics.Providers.OpenBLAS.LinearAlgebra;
using Complex = System.Numerics.Complex;
-namespace MathNet.Numerics.Providers.Common.OpenBlas
+namespace MathNet.Numerics.Providers.OpenBLAS
{
///
/// P/Invoke methods to the native math libraries.
@@ -301,5 +299,3 @@ namespace MathNet.Numerics.Providers.Common.OpenBlas
#endregion LAPACK
}
}
-
-#endif
diff --git a/src/Providers.OpenBLAS/paket.references b/src/Providers.OpenBLAS/paket.references
new file mode 100644
index 00000000..a954f0e2
--- /dev/null
+++ b/src/Providers.OpenBLAS/paket.references
@@ -0,0 +1 @@
+Microsoft.NETFramework.ReferenceAssemblies