Popularity
1.4
Growing
Activity
0.0
-
26
4
1

Programming language: C#
License: GNU General Public License v3.0 or later
Tags: Mathematics    

MKL.NET alternatives and similar packages

Based on the "Mathematics" category.
Alternatively, view MKL.NET alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of MKL.NET or a related project?

Add another 'Mathematics' Package

README

MKL.NET

A simple cross platform .NET API for Intel MKL.

Exposing functions from MKL keeping the syntax as close to the c developer reference as possible.

Reference the MKL.NET package and required runtime packages and use the static MKL functions. The correct native libraries will be included and loaded at runtime.

MKL.NET runtimes: MKL.NET.win-x64 MKL.NET.win-x86 MKL.NET.linux-x64 MKL.NET.linux-x86 MKL.NET.osx-x64 libraries: MKL.NET.Matrix

Rationale

  • Use freely available Intel MKL packages repackaged to work for each runtime.
  • The MKL.NET API is just a thin .NET wrapper around the native API keeping the syntax as close as possible.
  • The project is well defined with no business logic and could benefit from external input.
  • Cross platform testing is easy and free using Github actions.
  • MKL.NET native packages can just be referenced for needed runtimes at library or application level.

MKL.NET.Matrix

  • Performance and memory optimised matrix algebra library.
  • Scale and Transpose deferred and unlikely to result in allocations (Can perform these together for +, *, and inplace for functions).
  • ArrayPool underlying memory model using IDisposable and Finalizers.
  • Uses the Pinned Object Heap for net5.0.

The following examples only create one new matrix (using ArrayPool) without mutating inputs.

public static matrix Example1(matrix m)
{
    return 0.5 * m * m.T;
}

public static matrix Example2(matrix a, matrix b, double w)
{
    return w * a + (1.0 - w) * b.T;
}

public static matrix Example3(matrix m)
{
    return Matrix.Round(100.0 * m.T);
}

public static matrix Example4(matrix m)
{
    matrix r = Example1(m);
    Matrix.Inplace.Log1p(r);
    return r;
}

Example statistics matrix function:

public static (vector, matrix) MeanAndCovariance(matrix samples, vector weights)
{
    if (samples.Rows != weights.Length) ThrowHelper.ThrowIncorrectDimensionsForOperation();
    var mean = new vector(samples.Cols);
    var cov = new matrix(samples.Cols, samples.Cols);
    var task = Vsl.SSNewTask(samples.Cols, samples.Rows, VslStorage.ROWS, samples.Array, weights.Array);
    ThrowHelper.Check(Vsl.SSEditCovCor(task, mean.Array, cov.Array, VslFormat.FULL, null, VslFormat.FULL));
    ThrowHelper.Check(Vsl.SSCompute(task, VslEstimate.COV, VslMethod.FAST));
    ThrowHelper.Check(Vsl.SSDeleteTask(task));
    return (mean, cov);
}

Note: arrays need to be pinned across all MKL function calls when there are multiple as above as MKL stores native pointers and the arrays could be moved between calls. MKL.NET handles pinning internally unpinning when the task is deleted. This is a common bug when using MKL from .NET which causes occasional crashes.