85 changed files with 2003 additions and 5149 deletions
@ -0,0 +1,36 @@ |
|||
// <copyright file="IProviderCreator.cs" company="Math.NET">
|
|||
// 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.
|
|||
// </copyright>
|
|||
|
|||
namespace MathNet.Numerics.Providers |
|||
{ |
|||
public interface IProviderCreator<T> where T : class |
|||
{ |
|||
T CreateProvider(); |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
File diff suppressed because it is too large
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -1,263 +0,0 @@ |
|||
// <copyright file="SafeNativeMethods.cs" company="Math.NET">
|
|||
// 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.
|
|||
// </copyright>
|
|||
|
|||
#if NATIVEACML
|
|||
|
|||
using System.Runtime.InteropServices; |
|||
using System.Security; |
|||
using Complex = System.Numerics.Complex; |
|||
|
|||
namespace MathNet.Numerics.Providers.LinearAlgebra.Acml |
|||
{ |
|||
/// <summary>
|
|||
/// P/Invoke methods to the native math libraries.
|
|||
/// </summary>
|
|||
[SuppressUnmanagedCodeSecurity] |
|||
[SecurityCritical] |
|||
internal static class SafeNativeMethods |
|||
{ |
|||
/// <summary>
|
|||
/// Name of the native DLL.
|
|||
/// </summary>
|
|||
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
|
|||
@ -0,0 +1,88 @@ |
|||
// <copyright file="ProviderProbe.cs" company="Math.NET">
|
|||
// 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.
|
|||
// </copyright>
|
|||
|
|||
using System; |
|||
using System.Threading; |
|||
|
|||
namespace MathNet.Numerics.Providers |
|||
{ |
|||
public class ProviderProbe<T> where T : class |
|||
{ |
|||
readonly bool _disabled; |
|||
readonly Lazy<IProviderCreator<T>> _creator; |
|||
|
|||
public ProviderProbe(string typeName, bool disabled = false) |
|||
{ |
|||
_disabled = disabled; |
|||
_creator = new Lazy<IProviderCreator<T>>(() => |
|||
{ |
|||
var type = Type.GetType(typeName); |
|||
return Activator.CreateInstance(type) as IProviderCreator<T>; |
|||
}, 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; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,80 @@ |
|||
// <copyright file="ArrayExtensions.cs" company="Math.NET">
|
|||
// 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.
|
|||
// </copyright>
|
|||
|
|||
using System; |
|||
using Complex = System.Numerics.Complex; |
|||
|
|||
namespace MathNet.Numerics.Providers.CUDA |
|||
{ |
|||
/// <summary>
|
|||
/// Useful extension methods for Arrays.
|
|||
/// </summary>
|
|||
internal static class ArrayExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Copies the values from on array to another.
|
|||
/// </summary>
|
|||
/// <param name="source">The source array.</param>
|
|||
/// <param name="dest">The destination array.</param>
|
|||
public static void Copy(this double[] source, double[] dest) |
|||
{ |
|||
Buffer.BlockCopy(source, 0, dest, 0, source.Length * Constants.SizeOfDouble); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Copies the values from on array to another.
|
|||
/// </summary>
|
|||
/// <param name="source">The source array.</param>
|
|||
/// <param name="dest">The destination array.</param>
|
|||
public static void Copy(this float[] source, float[] dest) |
|||
{ |
|||
Buffer.BlockCopy(source, 0, dest, 0, source.Length * Constants.SizeOfFloat); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Copies the values from on array to another.
|
|||
/// </summary>
|
|||
/// <param name="source">The source array.</param>
|
|||
/// <param name="dest">The destination array.</param>
|
|||
public static void Copy(this Complex[] source, Complex[] dest) |
|||
{ |
|||
Array.Copy(source, 0, dest, 0, source.Length); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Copies the values from on array to another.
|
|||
/// </summary>
|
|||
/// <param name="source">The source array.</param>
|
|||
/// <param name="dest">The destination array.</param>
|
|||
public static void Copy(this Complex32[] source, Complex32[] dest) |
|||
{ |
|||
Array.Copy(source, 0, dest, 0, source.Length); |
|||
} |
|||
} |
|||
} |
|||
@ -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
|
|||
@ -0,0 +1,60 @@ |
|||
// <copyright file="CudaControl.cs" company="Math.NET">
|
|||
// 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.
|
|||
// </copyright>
|
|||
|
|||
using MathNet.Numerics.Providers.CUDA.LinearAlgebra; |
|||
|
|||
namespace MathNet.Numerics.Providers.CUDA |
|||
{ |
|||
public static class CudaControl |
|||
{ |
|||
internal const string EnvVarCUDAProviderPath = "MathNetNumericsCUDAProviderPath"; |
|||
|
|||
/// <summary>
|
|||
/// 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.
|
|||
/// </summary>
|
|||
public static void UseNativeCUDA() |
|||
{ |
|||
CudaLinearAlgebraControl.UseNativeCUDA(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Try to use the OpenBLAS native provider for linear algebra.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// True if the provider was found and initialized successfully.
|
|||
/// False if it failed and the previous provider is still active.
|
|||
/// </returns>
|
|||
public static bool TryUseNativeCUDA() |
|||
{ |
|||
bool linearAlgebra = CudaLinearAlgebraControl.TryUseNativeCUDA(); |
|||
return linearAlgebra; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,93 @@ |
|||
// <copyright file="CudaLinearAlgebraControl.cs" company="Math.NET">
|
|||
// 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.
|
|||
// </copyright>
|
|||
|
|||
using System; |
|||
using MathNet.Numerics.Providers.LinearAlgebra; |
|||
|
|||
namespace MathNet.Numerics.Providers.CUDA.LinearAlgebra |
|||
{ |
|||
public class CudaLinearAlgebraControl : IProviderCreator<ILinearAlgebraProvider> |
|||
{ |
|||
const string EnvVarLAProviderPath = "MathNetNumericsLAProviderPath"; |
|||
|
|||
/// <summary>
|
|||
/// 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.
|
|||
/// </summary>
|
|||
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(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
<PropertyGroup> |
|||
<OutputType>Library</OutputType> |
|||
<TargetFrameworks>net5.0;net461;net40;netstandard2.0</TargetFrameworks> |
|||
<AssemblyName>MathNet.Numerics.Providers.CUDA</AssemblyName> |
|||
<RootNamespace>MathNet.Numerics.Providers.CUDA</RootNamespace> |
|||
<IsPackable>true</IsPackable> |
|||
<PackageId>MathNet.Numerics.Providers.CUDA$(PackageIdSuffix)</PackageId> |
|||
<VersionPrefix>4.15.0</VersionPrefix> |
|||
<VersionSuffix></VersionSuffix> |
|||
<Title>Math.NET Numerics CUDA Provider$(TitleSuffix)</Title> |
|||
<Description>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)</Description> |
|||
<PackageReleaseNotes>Precision: Round (with integer part rounding) ~Jon Larborn |
|||
Precision: RoundToMultiple, RoundToPower |
|||
F#: BigRational.FromDecimal ~Brian Berns</PackageReleaseNotes> |
|||
<GenerateAssemblyInfo>true</GenerateAssemblyInfo> |
|||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild> |
|||
<GenerateDocumentationFile>true</GenerateDocumentationFile> |
|||
<EnableDefaultCompileItems>true</EnableDefaultCompileItems> |
|||
<NoWarn>1701;1702;1705;1591;1573</NoWarn> |
|||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> |
|||
</PropertyGroup> |
|||
<ItemGroup Condition="'$(TargetFramework)' == 'net40'"> |
|||
<Reference Include="System" /> |
|||
<Reference Include="System.Core" /> |
|||
<Reference Include="System.Numerics" /> |
|||
<Reference Include="System.Runtime.Serialization" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Numerics\Numerics.csproj" /> |
|||
</ItemGroup> |
|||
<Import Project="..\..\.paket\Paket.Restore.targets" /> |
|||
</Project> |
|||
@ -0,0 +1 @@ |
|||
Microsoft.NETFramework.ReferenceAssemblies |
|||
@ -0,0 +1,80 @@ |
|||
// <copyright file="ArrayExtensions.cs" company="Math.NET">
|
|||
// 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.
|
|||
// </copyright>
|
|||
|
|||
using System; |
|||
using Complex = System.Numerics.Complex; |
|||
|
|||
namespace MathNet.Numerics.Providers.MKL |
|||
{ |
|||
/// <summary>
|
|||
/// Useful extension methods for Arrays.
|
|||
/// </summary>
|
|||
internal static class ArrayExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Copies the values from on array to another.
|
|||
/// </summary>
|
|||
/// <param name="source">The source array.</param>
|
|||
/// <param name="dest">The destination array.</param>
|
|||
public static void Copy(this double[] source, double[] dest) |
|||
{ |
|||
Buffer.BlockCopy(source, 0, dest, 0, source.Length * Constants.SizeOfDouble); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Copies the values from on array to another.
|
|||
/// </summary>
|
|||
/// <param name="source">The source array.</param>
|
|||
/// <param name="dest">The destination array.</param>
|
|||
public static void Copy(this float[] source, float[] dest) |
|||
{ |
|||
Buffer.BlockCopy(source, 0, dest, 0, source.Length * Constants.SizeOfFloat); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Copies the values from on array to another.
|
|||
/// </summary>
|
|||
/// <param name="source">The source array.</param>
|
|||
/// <param name="dest">The destination array.</param>
|
|||
public static void Copy(this Complex[] source, Complex[] dest) |
|||
{ |
|||
Array.Copy(source, 0, dest, 0, source.Length); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Copies the values from on array to another.
|
|||
/// </summary>
|
|||
/// <param name="source">The source array.</param>
|
|||
/// <param name="dest">The destination array.</param>
|
|||
public static void Copy(this Complex32[] source, Complex32[] dest) |
|||
{ |
|||
Array.Copy(source, 0, dest, 0, source.Length); |
|||
} |
|||
} |
|||
} |
|||
@ -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
|
|||
@ -0,0 +1,93 @@ |
|||
// <copyright file="MklFourierTransformControl.cs" company="Math.NET">
|
|||
// 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.
|
|||
// </copyright>
|
|||
|
|||
using System; |
|||
using MathNet.Numerics.Providers.FourierTransform; |
|||
|
|||
namespace MathNet.Numerics.Providers.MKL.FourierTransform |
|||
{ |
|||
public class MklFourierTransformControl : IProviderCreator<IFourierTransformProvider> |
|||
{ |
|||
const string EnvVarFFTProviderPath = "MathNetNumericsFFTProviderPath"; |
|||
|
|||
/// <summary>
|
|||
/// 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.
|
|||
/// </summary>
|
|||
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(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,102 @@ |
|||
// <copyright file="MklLinearAlgebraControl.cs" company="Math.NET">
|
|||
// 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.
|
|||
// </copyright>
|
|||
|
|||
using System; |
|||
using MathNet.Numerics.Providers.LinearAlgebra; |
|||
|
|||
namespace MathNet.Numerics.Providers.MKL.LinearAlgebra |
|||
{ |
|||
public class MklLinearAlgebraControl : IProviderCreator<ILinearAlgebraProvider> |
|||
{ |
|||
const string EnvVarLAProviderPath = "MathNetNumericsLAProviderPath"; |
|||
|
|||
/// <summary>
|
|||
/// 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.
|
|||
/// </summary>
|
|||
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(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,80 @@ |
|||
// <copyright file="MklControl.cs" company="Math.NET">
|
|||
// 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.
|
|||
// </copyright>
|
|||
|
|||
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"; |
|||
|
|||
/// <summary>
|
|||
/// 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.
|
|||
/// </summary>
|
|||
public static void UseNativeMKL() |
|||
{ |
|||
MklLinearAlgebraControl.UseNativeMKL(); |
|||
MklFourierTransformControl.UseNativeMKL(); |
|||
MklSparseSolverControl.UseNativeMKL(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 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.
|
|||
/// </summary>
|
|||
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(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Try to use the Intel MKL native provider for linear algebra.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// True if the provider was found and initialized successfully.
|
|||
/// False if it failed and the previous provider is still active.
|
|||
/// </returns>
|
|||
public static bool TryUseNativeMKL() |
|||
{ |
|||
bool linearAlgebra = MklLinearAlgebraControl.TryUseNativeMKL(); |
|||
bool fourierTransform = MklFourierTransformControl.TryUseNativeMKL(); |
|||
bool directSparseSolver = MklSparseSolverControl.TryUseNativeMKL(); |
|||
return linearAlgebra || fourierTransform || directSparseSolver; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,252 @@ |
|||
// <copyright file="NativeProviderLoader.cs" company="Math.NET">
|
|||
// 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.
|
|||
// </copyright>
|
|||
|
|||
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 |
|||
{ |
|||
/// <summary>
|
|||
/// Helper class to load native libraries depending on the architecture of the OS and process.
|
|||
/// </summary>
|
|||
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"; |
|||
|
|||
/// <summary>
|
|||
/// Dictionary of handles to previously loaded libraries,
|
|||
/// </summary>
|
|||
static readonly Lazy<Dictionary<string, IntPtr>> NativeHandles = new Lazy<Dictionary<string, IntPtr>>(LazyThreadSafetyMode.PublicationOnly); |
|||
|
|||
/// <summary>
|
|||
/// Gets a string indicating the architecture and bitness of the current process.
|
|||
/// </summary>
|
|||
static readonly Lazy<string> ArchitectureKey = new Lazy<string>(EvaluateArchitectureKey, LazyThreadSafetyMode.PublicationOnly); |
|||
|
|||
/// <summary>
|
|||
/// If the last native library failed to load then gets the corresponding exception
|
|||
/// which occurred or null if the library was successfully loaded.
|
|||
/// </summary>
|
|||
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; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Load the native library with the given filename.
|
|||
/// </summary>
|
|||
/// <param name="fileName">The file name of the library to load.</param>
|
|||
/// <param name="hintPath">Hint path where to look for the native binaries. Can be null.</param>
|
|||
/// <returns>True if the library was successfully loaded or if it has already been loaded.</returns>
|
|||
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; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 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.
|
|||
/// </summary>
|
|||
/// <returns>True if the library was successfully loaded or if it has already been loaded.</returns>
|
|||
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))); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Try to load a native library by providing the full path including the file name of the library.
|
|||
/// </summary>
|
|||
/// <returns>True if the library was successfully loaded or if it has already been loaded.</returns>
|
|||
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); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
<PropertyGroup> |
|||
<OutputType>Library</OutputType> |
|||
<TargetFrameworks>net5.0;net461;net40;netstandard2.0</TargetFrameworks> |
|||
<AssemblyName>MathNet.Numerics.Providers.MKL</AssemblyName> |
|||
<RootNamespace>MathNet.Numerics.Providers.MKL</RootNamespace> |
|||
<IsPackable>true</IsPackable> |
|||
<PackageId>MathNet.Numerics.Providers.MKL$(PackageIdSuffix)</PackageId> |
|||
<VersionPrefix>4.15.0</VersionPrefix> |
|||
<VersionSuffix></VersionSuffix> |
|||
<Title>Math.NET Numerics MKL Provider$(TitleSuffix)</Title> |
|||
<Description>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)</Description> |
|||
<PackageReleaseNotes>Precision: Round (with integer part rounding) ~Jon Larborn |
|||
Precision: RoundToMultiple, RoundToPower |
|||
F#: BigRational.FromDecimal ~Brian Berns</PackageReleaseNotes> |
|||
<GenerateAssemblyInfo>true</GenerateAssemblyInfo> |
|||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild> |
|||
<GenerateDocumentationFile>true</GenerateDocumentationFile> |
|||
<EnableDefaultCompileItems>true</EnableDefaultCompileItems> |
|||
<NoWarn>1701;1702;1705;1591;1573</NoWarn> |
|||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> |
|||
</PropertyGroup> |
|||
<ItemGroup Condition="'$(TargetFramework)' == 'net40'"> |
|||
<Reference Include="System" /> |
|||
<Reference Include="System.Core" /> |
|||
<Reference Include="System.Numerics" /> |
|||
<Reference Include="System.Runtime.Serialization" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Numerics\Numerics.csproj" /> |
|||
</ItemGroup> |
|||
<Import Project="..\..\.paket\Paket.Restore.targets" /> |
|||
</Project> |
|||
@ -0,0 +1,93 @@ |
|||
// <copyright file="MklSparseSolverControl.cs" company="Math.NET">
|
|||
// 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.
|
|||
// </copyright>
|
|||
|
|||
using System; |
|||
using MathNet.Numerics.Providers.SparseSolver; |
|||
|
|||
namespace MathNet.Numerics.Providers.MKL.SparseSolver |
|||
{ |
|||
public class MklSparseSolverControl : IProviderCreator<ISparseSolverProvider> |
|||
{ |
|||
const string EnvVarSSProviderPath = "MathNetNumericsSSProviderPath"; |
|||
|
|||
/// <summary>
|
|||
/// 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.
|
|||
/// </summary>
|
|||
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(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1 @@ |
|||
Microsoft.NETFramework.ReferenceAssemblies |
|||
@ -0,0 +1,80 @@ |
|||
// <copyright file="ArrayExtensions.cs" company="Math.NET">
|
|||
// 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.
|
|||
// </copyright>
|
|||
|
|||
using System; |
|||
using Complex = System.Numerics.Complex; |
|||
|
|||
namespace MathNet.Numerics.Providers.OpenBLAS |
|||
{ |
|||
/// <summary>
|
|||
/// Useful extension methods for Arrays.
|
|||
/// </summary>
|
|||
internal static class ArrayExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Copies the values from on array to another.
|
|||
/// </summary>
|
|||
/// <param name="source">The source array.</param>
|
|||
/// <param name="dest">The destination array.</param>
|
|||
public static void Copy(this double[] source, double[] dest) |
|||
{ |
|||
Buffer.BlockCopy(source, 0, dest, 0, source.Length * Constants.SizeOfDouble); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Copies the values from on array to another.
|
|||
/// </summary>
|
|||
/// <param name="source">The source array.</param>
|
|||
/// <param name="dest">The destination array.</param>
|
|||
public static void Copy(this float[] source, float[] dest) |
|||
{ |
|||
Buffer.BlockCopy(source, 0, dest, 0, source.Length * Constants.SizeOfFloat); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Copies the values from on array to another.
|
|||
/// </summary>
|
|||
/// <param name="source">The source array.</param>
|
|||
/// <param name="dest">The destination array.</param>
|
|||
public static void Copy(this Complex[] source, Complex[] dest) |
|||
{ |
|||
Array.Copy(source, 0, dest, 0, source.Length); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Copies the values from on array to another.
|
|||
/// </summary>
|
|||
/// <param name="source">The source array.</param>
|
|||
/// <param name="dest">The destination array.</param>
|
|||
public static void Copy(this Complex32[] source, Complex32[] dest) |
|||
{ |
|||
Array.Copy(source, 0, dest, 0, source.Length); |
|||
} |
|||
} |
|||
} |
|||
@ -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
|
|||
@ -0,0 +1,93 @@ |
|||
// <copyright file="OpenBlasLinearAlgebraControl.cs" company="Math.NET">
|
|||
// 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.
|
|||
// </copyright>
|
|||
|
|||
using System; |
|||
using MathNet.Numerics.Providers.LinearAlgebra; |
|||
|
|||
namespace MathNet.Numerics.Providers.OpenBLAS.LinearAlgebra |
|||
{ |
|||
public class OpenBlasLinearAlgebraControl : IProviderCreator<ILinearAlgebraProvider> |
|||
{ |
|||
const string EnvVarLAProviderPath = "MathNetNumericsLAProviderPath"; |
|||
|
|||
/// <summary>
|
|||
/// 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.
|
|||
/// </summary>
|
|||
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(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,252 @@ |
|||
// <copyright file="NativeProviderLoader.cs" company="Math.NET">
|
|||
// 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.
|
|||
// </copyright>
|
|||
|
|||
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 |
|||
{ |
|||
/// <summary>
|
|||
/// Helper class to load native libraries depending on the architecture of the OS and process.
|
|||
/// </summary>
|
|||
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"; |
|||
|
|||
/// <summary>
|
|||
/// Dictionary of handles to previously loaded libraries,
|
|||
/// </summary>
|
|||
static readonly Lazy<Dictionary<string, IntPtr>> NativeHandles = new Lazy<Dictionary<string, IntPtr>>(LazyThreadSafetyMode.PublicationOnly); |
|||
|
|||
/// <summary>
|
|||
/// Gets a string indicating the architecture and bitness of the current process.
|
|||
/// </summary>
|
|||
static readonly Lazy<string> ArchitectureKey = new Lazy<string>(EvaluateArchitectureKey, LazyThreadSafetyMode.PublicationOnly); |
|||
|
|||
/// <summary>
|
|||
/// If the last native library failed to load then gets the corresponding exception
|
|||
/// which occurred or null if the library was successfully loaded.
|
|||
/// </summary>
|
|||
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; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Load the native library with the given filename.
|
|||
/// </summary>
|
|||
/// <param name="fileName">The file name of the library to load.</param>
|
|||
/// <param name="hintPath">Hint path where to look for the native binaries. Can be null.</param>
|
|||
/// <returns>True if the library was successfully loaded or if it has already been loaded.</returns>
|
|||
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; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 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.
|
|||
/// </summary>
|
|||
/// <returns>True if the library was successfully loaded or if it has already been loaded.</returns>
|
|||
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))); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Try to load a native library by providing the full path including the file name of the library.
|
|||
/// </summary>
|
|||
/// <returns>True if the library was successfully loaded or if it has already been loaded.</returns>
|
|||
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); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,60 @@ |
|||
// <copyright file="OpenBlasControl.cs" company="Math.NET">
|
|||
// 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.
|
|||
// </copyright>
|
|||
|
|||
using MathNet.Numerics.Providers.OpenBLAS.LinearAlgebra; |
|||
|
|||
namespace MathNet.Numerics.Providers.OpenBLAS |
|||
{ |
|||
public static class OpenBlasControl |
|||
{ |
|||
internal const string EnvVarOpenBLASProviderPath = "MathNetNumericsOpenBLASProviderPath"; |
|||
|
|||
/// <summary>
|
|||
/// 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.
|
|||
/// </summary>
|
|||
public static void UseNativeOpenBLAS() |
|||
{ |
|||
OpenBlasLinearAlgebraControl.UseNativeOpenBLAS(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Try to use the OpenBLAS native provider for linear algebra.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// True if the provider was found and initialized successfully.
|
|||
/// False if it failed and the previous provider is still active.
|
|||
/// </returns>
|
|||
public static bool TryUseNativeOpenBLAS() |
|||
{ |
|||
bool linearAlgebra = OpenBlasLinearAlgebraControl.TryUseNativeOpenBLAS(); |
|||
return linearAlgebra; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
<PropertyGroup> |
|||
<OutputType>Library</OutputType> |
|||
<TargetFrameworks>net5.0;net461;net40;netstandard2.0</TargetFrameworks> |
|||
<AssemblyName>MathNet.Numerics.Providers.OpenBLAS</AssemblyName> |
|||
<RootNamespace>MathNet.Numerics.Providers.OpenBLAS</RootNamespace> |
|||
<IsPackable>true</IsPackable> |
|||
<PackageId>MathNet.Numerics.Providers.OpenBLAS$(PackageIdSuffix)</PackageId> |
|||
<VersionPrefix>4.15.0</VersionPrefix> |
|||
<VersionSuffix></VersionSuffix> |
|||
<Title>Math.NET Numerics OpenBLAS Provider$(TitleSuffix)</Title> |
|||
<Description>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)</Description> |
|||
<PackageReleaseNotes>Precision: Round (with integer part rounding) ~Jon Larborn |
|||
Precision: RoundToMultiple, RoundToPower |
|||
F#: BigRational.FromDecimal ~Brian Berns</PackageReleaseNotes> |
|||
<GenerateAssemblyInfo>true</GenerateAssemblyInfo> |
|||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild> |
|||
<GenerateDocumentationFile>true</GenerateDocumentationFile> |
|||
<EnableDefaultCompileItems>true</EnableDefaultCompileItems> |
|||
<NoWarn>1701;1702;1705;1591;1573</NoWarn> |
|||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> |
|||
</PropertyGroup> |
|||
<ItemGroup Condition="'$(TargetFramework)' == 'net40'"> |
|||
<Reference Include="System" /> |
|||
<Reference Include="System.Core" /> |
|||
<Reference Include="System.Numerics" /> |
|||
<Reference Include="System.Runtime.Serialization" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Numerics\Numerics.csproj" /> |
|||
</ItemGroup> |
|||
<Import Project="..\..\.paket\Paket.Restore.targets" /> |
|||
</Project> |
|||
@ -0,0 +1 @@ |
|||
Microsoft.NETFramework.ReferenceAssemblies |
|||
Loading…
Reference in new issue