Kolbe.LitMath 0.4.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Kolbe.LitMath --version 0.4.0                
NuGet\Install-Package Kolbe.LitMath -Version 0.4.0                
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="Kolbe.LitMath" Version="0.4.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Kolbe.LitMath --version 0.4.0                
#r "nuget: Kolbe.LitMath, 0.4.0"                
#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 Kolbe.LitMath as a Cake Addin
#addin nuget:?package=Kolbe.LitMath&version=0.4.0

// Install Kolbe.LitMath as a Cake Tool
#tool nuget:?package=Kolbe.LitMath&version=0.4.0                

LitMath

A collection of AVX-256 accelerated mathematical functions for .NET

I rewrote Exp, Log, Sin and a few other useful functions using pure AVX intrinsics, so instead of doing one calculation per core, you can now do 4 doubles or 8 floats per core. I added the Sqrt, ERF function and a Normal Distribution CDF as well. On doubles, the following accuracies apply:

  • Exp and Sqrt run at double precision limits
  • ERF at 1e-13
  • Sin and Cos at 1e-15
  • Tan in $[0,\pi/4]$ at 2e-16
  • ATan at 1e-10 (working on it)

There are examples in the benchmark and tests. But here is one to get you started anyway.

Calculate n $e^x$'s in chunks of 4 and store the result in y.

int n = 40;
Span<double> x = new Span<double>(Enumerable.Range(0 , n).Select(z => (double)z/n).ToArray());
Span<double> y = new Span<double>(new double[n]);
LitExp.Exp(ref x, ref y);

Parallel Processing

LitMath leverages SIMD for instruction level parallelism, but not compute cores. For array sizes large enough, it would be a really good idea to do multicore processing. There's an example called LitExpDoubleParallel in the ExpBenchmark.cs file to see one way to go about this.

Non-Math Things

Making a library like this involves reinventing the wheel so to speak on very basic concepts. LitUtilities includes methods like Max and Min and IfElse, which are key to many programming problems in AVX programming, because it needs to be branch-free.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.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.7.0 500 11/16/2023
0.6.4 149 10/13/2023
0.6.3 360 1/5/2023
0.6.2 304 1/3/2023
0.6.1 309 1/3/2023
0.6.0 293 12/8/2022
0.5.8 328 12/4/2022
0.5.7 333 11/27/2022
0.5.6 312 11/26/2022
0.5.5 329 11/26/2022
0.5.4 344 11/26/2022
0.5.3 340 11/26/2022
0.5.2 344 11/22/2022
0.5.1 319 11/22/2022
0.5.0 411 9/24/2022
0.4.1 429 9/21/2022
0.4.0 434 9/21/2022
0.3.8 442 9/15/2022
0.3.7 463 9/14/2022
0.3.6 461 9/14/2022
0.3.5 467 9/14/2022
0.3.4 427 7/22/2022
0.3.3 431 7/21/2022
0.3.2 427 7/20/2022
0.3.1 453 7/20/2022
0.3.0 455 7/18/2022
0.2.1 457 7/9/2022
0.2.0 467 6/5/2022
0.1.2 439 6/3/2022
0.1.1 405 6/2/2022
0.1.0 440 6/2/2022

BREAKING CHANGES made to polynomial from v0.3.8. The interfaces are the same, but renamed.