Skip to content

Commit

Permalink
Support Native Providers also in .Net 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
cdrnet committed Jul 3, 2017
1 parent a872a13 commit 7825e7f
Show file tree
Hide file tree
Showing 18 changed files with 73 additions and 28 deletions.
8 changes: 4 additions & 4 deletions src/Numerics/Numerics-Net35.csproj
Expand Up @@ -40,7 +40,7 @@
<!-- Conditional Strong Name: NO -->
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<DefineConstants>TRACE;NET35;NOSYSNUMERICS</DefineConstants>
<DefineConstants>TRACE;NET35;NOSYSNUMERICS;NATIVE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
Expand All @@ -54,7 +54,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<DefineConstants>TRACE;DEBUG;NET35;NOSYSNUMERICS</DefineConstants>
<DefineConstants>TRACE;DEBUG;NET35;NOSYSNUMERICS;NATIVE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
Expand All @@ -69,7 +69,7 @@
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<Optimize>true</Optimize>
<DefineConstants>TRACE;NET35;NOSYSNUMERICS;STRONGNAME</DefineConstants>
<DefineConstants>TRACE;NET35;NOSYSNUMERICS;NATIVE;STRONGNAME</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
Expand Down Expand Up @@ -111,4 +111,4 @@
</ItemGroup>
</When>
</Choose>
</Project>
</Project>
2 changes: 1 addition & 1 deletion src/Numerics/Providers/Common/Cuda/CudaProvider.cs
Expand Up @@ -103,7 +103,7 @@ public static string Describe()
if (_nativeIA64) parts.Add("IA64");
parts.Add("revision " + _nativeRevision);

return string.Concat("Nvidia CUDA (", string.Join("; ", parts), ")");
return string.Concat("Nvidia CUDA (", string.Join("; ", parts.ToArray()), ")");
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Numerics/Providers/Common/Cuda/SafeNativeMethods.cs
Expand Up @@ -29,13 +29,16 @@
#if NATIVE

using System;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Security;
using MathNet.Numerics.Providers.LinearAlgebra;

namespace MathNet.Numerics.Providers.Common.Cuda
{
#if !NOSYSNUMERICS
using Complex = System.Numerics.Complex;
#endif

/// <summary>
/// P/Invoke methods to the native math libraries.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Numerics/Providers/Common/Mkl/MklProvider.cs
Expand Up @@ -234,7 +234,7 @@ public static string Describe()
: string.Concat("MKL ", _mklVersion.ToString(2), " Update ", _mklVersion.Build));
}

return string.Concat("Intel MKL (", string.Join("; ", parts), ")");
return string.Concat("Intel MKL (", string.Join("; ", parts.ToArray()), ")");
}

enum MklMemoryRequestMode : int
Expand Down
5 changes: 4 additions & 1 deletion src/Numerics/Providers/Common/Mkl/SafeNativeMethods.cs
Expand Up @@ -29,13 +29,16 @@
#if NATIVE

using System;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Security;
using MathNet.Numerics.Providers.LinearAlgebra;

namespace MathNet.Numerics.Providers.Common.Mkl
{
#if !NOSYSNUMERICS
using Complex = System.Numerics.Complex;
#endif

/// <summary>
/// P/Invoke methods to the native math libraries.
/// </summary>
Expand Down
8 changes: 7 additions & 1 deletion src/Numerics/Providers/Common/NativeProviderLoader.cs
Expand Up @@ -79,10 +79,15 @@ static bool IsUnix

static string EvaluateArchitectureKey()
{
#if NET35
return (IntPtr.Size == 8) ? X64 : X86;
#else
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");
Expand Down Expand Up @@ -110,6 +115,7 @@ static string EvaluateArchitectureKey()

// Fallback if unknown
return architecture;
#endif
}

/// <summary>
Expand Down Expand Up @@ -162,7 +168,7 @@ public static bool TryLoad(string fileName, string 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(directory, architecture, fileName))))
if (!string.IsNullOrEmpty(architecture) && TryLoadFile(new FileInfo(Path.Combine(Path.Combine(directory, architecture), fileName))))
{
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Numerics/Providers/Common/OpenBlas/OpenBlasProvider.cs
Expand Up @@ -117,7 +117,7 @@ public static string Describe()
if (_nativeARM) parts.Add("ARM");
parts.Add("revision " + _nativeRevision);

return string.Concat("OpenBLAS (", string.Join("; ", parts), ")");
return string.Concat("OpenBLAS (", string.Join("; ", parts.ToArray()), ")");
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Numerics/Providers/Common/OpenBlas/SafeNativeMethods.cs
Expand Up @@ -28,14 +28,17 @@

#if NATIVE

using System.Numerics;
using System.Runtime.InteropServices;
using System.Security;
using MathNet.Numerics.Providers.LinearAlgebra;
using MathNet.Numerics.Providers.LinearAlgebra.OpenBlas;

namespace MathNet.Numerics.Providers.Common.OpenBlas
{
#if !NOSYSNUMERICS
using Complex = System.Numerics.Complex;
#endif

/// <summary>
/// P/Invoke methods to the native math libraries.
/// </summary>
Expand Down
Expand Up @@ -29,12 +29,15 @@
#if NATIVE

using System;
using System.Numerics;
using System.Threading;
using MathNet.Numerics.Providers.Common.Mkl;

namespace MathNet.Numerics.Providers.FourierTransform.Mkl
{
#if !NOSYSNUMERICS
using Complex = System.Numerics.Complex;
#endif

public class MklFourierTransformProvider : IFourierTransformProvider, IDisposable
{
class Kernel
Expand Down Expand Up @@ -230,7 +233,7 @@ Kernel Configure(int[] dimensions, FourierTransformScaling scaling, bool single)
{
SafeNativeMethods.z_fft_create_multidim(out kernel.Handle, dimensions.Length, dimensions, ForwardScaling(scaling, length), BackwardScaling(scaling, length));
}

return kernel;
}

Expand Down Expand Up @@ -406,4 +409,4 @@ public void Dispose()
}
}

#endif
#endif
Expand Up @@ -30,13 +30,16 @@
#if NATIVE

using System;
using System.Numerics;
using System.Security;
using MathNet.Numerics.Properties;
using MathNet.Numerics.Providers.Common.Cuda;

namespace MathNet.Numerics.Providers.LinearAlgebra.Cuda
{
#if !NOSYSNUMERICS
using Complex = System.Numerics.Complex;
#endif

/// <summary>
/// NVidia's CUDA Toolkit linear algebra provider.
/// </summary>
Expand Down
Expand Up @@ -30,14 +30,17 @@
#if NATIVE

using System;
using System.Numerics;
using System.Security;
using MathNet.Numerics.LinearAlgebra.Factorization;
using MathNet.Numerics.Properties;
using MathNet.Numerics.Providers.Common.Mkl;

namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
{
#if !NOSYSNUMERICS
using Complex = System.Numerics.Complex;
#endif

/// <summary>
/// Intel's Math Kernel Library (MKL) linear algebra provider.
/// </summary>
Expand Down Expand Up @@ -358,7 +361,7 @@ public override void LUInverseFactored(Complex[] a, int order, int[] ipiv)
if (info > 0)
{
throw new SingularUMatrixException(info);
}
}
}

/// <summary>
Expand Down
Expand Up @@ -30,14 +30,17 @@
#if NATIVE

using System;
using System.Numerics;
using System.Security;
using MathNet.Numerics.LinearAlgebra.Factorization;
using MathNet.Numerics.Properties;
using MathNet.Numerics.Providers.Common.Mkl;

namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
{
#if !NOSYSNUMERICS
using Complex = System.Numerics.Complex;
#endif

/// <summary>
/// Intel's Math Kernel Library (MKL) linear algebra provider.
/// </summary>
Expand Down Expand Up @@ -358,7 +361,7 @@ public override void LUInverseFactored(Complex32[] a, int order, int[] ipiv)
if (info > 0)
{
throw new SingularUMatrixException(info);
}
}
}

/// <summary>
Expand Down
Expand Up @@ -30,14 +30,17 @@
#if NATIVE

using System;
using System.Numerics;
using System.Security;
using MathNet.Numerics.LinearAlgebra.Factorization;
using MathNet.Numerics.Properties;
using MathNet.Numerics.Providers.Common.Mkl;

namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
{
#if !NOSYSNUMERICS
using Complex = System.Numerics.Complex;
#endif

/// <summary>
/// Intel's Math Kernel Library (MKL) linear algebra provider.
/// </summary>
Expand Down Expand Up @@ -358,7 +361,7 @@ public override void LUInverseFactored(double[] a, int order, int[] ipiv)
if (info > 0)
{
throw new SingularUMatrixException(info);
}
}
}

/// <summary>
Expand Down
Expand Up @@ -30,14 +30,17 @@
#if NATIVE

using System;
using System.Numerics;
using System.Security;
using MathNet.Numerics.LinearAlgebra.Factorization;
using MathNet.Numerics.Properties;
using MathNet.Numerics.Providers.Common.Mkl;

namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
{
#if !NOSYSNUMERICS
using Complex = System.Numerics.Complex;
#endif

/// <summary>
/// Intel's Math Kernel Library (MKL) linear algebra provider.
/// </summary>
Expand Down Expand Up @@ -358,7 +361,7 @@ public override void LUInverseFactored(float[] a, int order, int[] ipiv)
if (info > 0)
{
throw new SingularUMatrixException(info);
}
}
}

/// <summary>
Expand Down Expand Up @@ -812,7 +815,7 @@ public override void QRSolveFactored(float[] q, float[] r, int rowsA, int column
if (method == QRMethod.Full)
{
var info = SafeNativeMethods.s_qr_solve_factored(rowsA, columnsA, columnsB, r, b, tau, x);

if (info == (int)MklError.MemoryAllocation)
{
throw new MemoryAllocationException();
Expand Down
Expand Up @@ -32,12 +32,15 @@
using MathNet.Numerics.LinearAlgebra.Factorization;
using MathNet.Numerics.Properties;
using System;
using System.Numerics;
using System.Security;
using MathNet.Numerics.Providers.Common.OpenBlas;

namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
{
#if !NOSYSNUMERICS
using Complex = System.Numerics.Complex;
#endif

/// <summary>
/// OpenBLAS linear algebra provider.
/// </summary>
Expand Down
Expand Up @@ -32,12 +32,15 @@
using MathNet.Numerics.LinearAlgebra.Factorization;
using MathNet.Numerics.Properties;
using System;
using System.Numerics;
using System.Security;
using MathNet.Numerics.Providers.Common.OpenBlas;

namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
{
#if !NOSYSNUMERICS
using Complex = System.Numerics.Complex;
#endif

/// <summary>
/// OpenBLAS linear algebra provider.
/// </summary>
Expand Down
Expand Up @@ -32,12 +32,15 @@
using MathNet.Numerics.LinearAlgebra.Factorization;
using MathNet.Numerics.Properties;
using System;
using System.Numerics;
using System.Security;
using MathNet.Numerics.Providers.Common.OpenBlas;

namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
{
#if !NOSYSNUMERICS
using Complex = System.Numerics.Complex;
#endif

/// <summary>
/// OpenBLAS linear algebra provider.
/// </summary>
Expand Down
Expand Up @@ -32,12 +32,15 @@
using MathNet.Numerics.LinearAlgebra.Factorization;
using MathNet.Numerics.Properties;
using System;
using System.Numerics;
using System.Security;
using MathNet.Numerics.Providers.Common.OpenBlas;

namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
{
#if !NOSYSNUMERICS
using Complex = System.Numerics.Complex;
#endif

/// <summary>
/// OpenBLAS linear algebra provider.
/// </summary>
Expand Down

0 comments on commit 7825e7f

Please sign in to comment.