NetFabric.Numerics.Tensors 4.0.0

Prefix Reserved
dotnet add package NetFabric.Numerics.Tensors --version 4.0.0                
NuGet\Install-Package NetFabric.Numerics.Tensors -Version 4.0.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="NetFabric.Numerics.Tensors" Version="4.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetFabric.Numerics.Tensors --version 4.0.0                
#r "nuget: NetFabric.Numerics.Tensors, 4.0.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 NetFabric.Numerics.Tensors as a Cake Addin
#addin nuget:?package=NetFabric.Numerics.Tensors&version=4.0.0

// Install NetFabric.Numerics.Tensors as a Cake Tool
#tool nuget:?package=NetFabric.Numerics.Tensors&version=4.0.0                

NetFabric.Numerics.Tensors

Working with SIMD in .NET to optimize code can be challenging, but this library offers a straightforward solution. It delivers reusable and highly optimized iterations over Span<T>, allowing for the application of both pre-defined and custom operations to each element or aggregation of elements.

Using generics, the library accommodates any type embracing .NET generic math.

Within the library, you'll find pre-defined operations such as Sqrt(), Sin(), Negate(), Add(), Divide(), Multiply(), AddMultiply(), Sum(), Average(), Min(), Max(), and many more.

For custom operations, the library allows the definition of operators through interfaces like IUnaryOperator<T>, IBinaryOperator<T>, ITernaryOperator<T>, or IAggregationOperator<T>. These operators can be applied seamlessly using the Apply(), Aggregate(), IndexOfAggregate(), First(), or IndexOfFirst() methods.

Usage

The library includes methods tailored for operations involving one, two, or three ReadOnlySpan<T>. Results are provided in a Span<T>, with the condition that the destination Span<T> must be of the same size or larger than the sources. Inplace operations are supported when the destination parameter matches any of the sources.

For example, given a variable data of type Span<int>, the following code snippet replaces each element of the span with its square root:

TensorOperations.Sqrt(data, data);

Note that since data serves as both the source and destination, the operation is performed in-place.

Given variables x, y, and result, all of type Span<float> and of the same size, the following example updates each element in result with the sum of the corresponding elements in x and y:

TensorOperations.Add(x, y, result);

In addition to working with individual elements, this library supports various aggregation operations. For example:

var sum = TensorOperations.Sum(data);
var min = TensorOperations.Min(data);
var (min, max) = TensorOperations.MinMax(data);

It also helps find the index of specific elements:

var index = TensorOperations.IndexOfMin(data);

Additionally, it can quickly locate the first element meeting certain criteria:

var value = FirstGreaterThan(data, 0);

And it simplifies finding the index of such elements:

var index = IndexOfFirstGreaterThan(data, 0);

Custom Operations

While NetFabric.Numerics.Tensors provides various pre-defined operations, combining them might not be efficient. Custom operators can be implemented, allowing the definition of specific operations for each element of the source, while still benefiting from high-performance reusable iteration code.

The aggregation methods support transformation operators that allow composite operations to be performed in a single data iteration.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on NetFabric.Numerics.Tensors:

Repository Stars
JasonBock/Rocks
A mocking library based on the Compiler APIs (Roslyn + Mocks)
Version Downloads Last updated
4.0.0 289 4/9/2024
3.1.0 120 3/21/2024
3.0.0 112 2/16/2024
2.1.0 124 2/4/2024
2.0.0 125 1/26/2024
1.1.0 227 1/6/2024
1.0.0 142 1/3/2024

BREAKING CHANGES:

- The method AggregatePropagateNaN has been renamed to only Aggregate. The previous Aggregate has been renamed to AggregateNumber. All aggregation methods and operators that don't propagate NaN have the suffix Number.
- The method IndexOfPredicate has been renamed to IndexOfFirst.

UPDATES AND ADDITIONS:

- Added methods: First and IndexOfAggregate.
- Added operations: Contains, IndexOfFirstEquals, FirstGreaterThan, IndexOfFirstGreaterThan, FirstGreaterThanOrEqual, IndexOfFirstGreaterThanOrEqual, FirstLessThan, IndexOfFirstLessThan, FirstLessThanOrEqual, IndexOfFirstLessThanOrEqual, IndexOfMax, IndexOfMaxMagnitude, IndexOfMin, IndexOfMinMagnitude, IndexOfMaxNumber, IndexOfMaxMagnitudeNumber, IndexOfMinNumber, IndexOfMinMagnitudeNumber, SumNumber.