OpenBlasSharp 0.3.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package OpenBlasSharp --version 0.3.1                
NuGet\Install-Package OpenBlasSharp -Version 0.3.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OpenBlasSharp" Version="0.3.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OpenBlasSharp --version 0.3.1                
#r "nuget: OpenBlasSharp, 0.3.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install OpenBlasSharp as a Cake Addin
#addin nuget:?package=OpenBlasSharp&version=0.3.1

// Install OpenBlasSharp as a Cake Tool
#tool nuget:?package=OpenBlasSharp&version=0.3.1                

OpenBlasSharp

The purpose of this project is to provide a .NET wrapper for OpenBLAS.

Features

  • Thin wrapper using raw pointers.
  • Most functions and arguments are annotated with doc comments taken from the original FORTRAN code. This is very helpful when working with the BLAS and LAPACK functions, which often require a large number of arguments.

Installation

The NuGet package is available.

Install-Package OpenBlasSharp

This package does not include the native DLL. You must download the compiled binary and put libopenblas.dll at the directory of the executable file.

All the classes are in the OpenBlasSharp namespace.

using OpenBlasSharp;

Examples

Dot product

var len = 3;

var rnd = new Random(42);

var x = Enumerable.Range(0, len).Select(i => rnd.NextDouble()).ToArray();
var y = Enumerable.Range(0, len).Select(i => rnd.NextDouble()).ToArray();

fixed (double* px = x)
fixed (double* py = y)
{
    // Calculate x^T * y.
    var result = Blas.Ddot(len, px, 1, py, 1);
}

Matrix multiplication

var m = 3;
var n = 5;
var k = 4;

var rnd = new Random(42);

var a = Enumerable.Range(0, m * k).Select(i => rnd.NextDouble()).ToArray();
var b = Enumerable.Range(0, k * n).Select(i => rnd.NextDouble()).ToArray();
var c = new double[m * n];

fixed (double* pa = a)
fixed (double* pb = b)
fixed (double* pc = c)
{
    // Calculate c = a * b.
    Blas.Dgemm(
        Order.ColMajor,
        Transpose.NoTrans,
        Transpose.NoTrans,
        m, n, k,
        1.0,
        pa, m,
        pb, k,
        1.0,
        pc, m);
}

Inverse matrix using LU decomposition

var n = 3;

var random = new Random(42);

var a = Enumerable.Range(0, n * n).Select(i => random.NextDouble()).ToArray();
var piv = new int[n];

fixed (double* pa = a)
fixed (int* ppiv = piv)
{
    Lapack.Dgetrf(
        MatrixLayout.ColMajor,
        n, n,
        pa, n,
        ppiv);

    Lapack.Dgetri(
        MatrixLayout.ColMajor,
        n,
        pa, n, // pa will be the inverse matrix.
        ppiv);
}

Singular value decomposition

var m = 4;
var n = 3;

var rnd = new Random(42);

var a = Enumerable.Range(0, m * n).Select(i => rnd.NextDouble()).ToArray();
var s = new double[Math.Min(m, n)];
var u = new double[m * m];
var vt = new double[n * n];
var work = new double[Math.Min(m, n) - 1];

fixed (double* pa = a)
fixed (double* ps = s)
fixed (double* pu = u)
fixed (double* pvt = vt)
fixed (double* pwork = work)
{
    Lapack.Dgesvd(
        MatrixLayout.ColMajor,
        'A', 'A',
        m, n,
        pa, m, // Note that pa will be destroyed.
        ps,
        pu, m,
        pvt, n,
        pwork);
}

OpenBLAS specific functions

var numThreads = OpenBlas.GetNumThreads();

Development status

  • Low-level LAPACK functions with the _work suffix are not supported.
  • LAPACK functions that require function pointers are not supported.

License

OpenBlasSharp is available under the BSD-3-Clause license.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.3.4 130 8/15/2024
0.3.3 129 4/13/2024
0.3.2 355 1/25/2024
0.3.1 106 1/23/2024
0.3.0 105 1/23/2024
0.2.0 115 1/22/2024
0.1.0 110 1/22/2024