NetFabric.Numerics.Tensors
3.1.0
Prefix Reserved
See the version list below for details.
dotnet add package NetFabric.Numerics.Tensors --version 3.1.0
NuGet\Install-Package NetFabric.Numerics.Tensors -Version 3.1.0
<PackageReference Include="NetFabric.Numerics.Tensors" Version="3.1.0" />
paket add NetFabric.Numerics.Tensors --version 3.1.0
#r "nuget: NetFabric.Numerics.Tensors, 3.1.0"
// Install NetFabric.Numerics.Tensors as a Cake Addin #addin nuget:?package=NetFabric.Numerics.Tensors&version=3.1.0 // Install NetFabric.Numerics.Tensors as a Cake Tool #tool nuget:?package=NetFabric.Numerics.Tensors&version=3.1.0
NetFabric.Numerics.Tensors
Dealing with SIMD in .NET for optimized code can be complex, but this library offers a practical solution. It provides a reusable and highly-optimized iterations on Span<T>
, enabling the application of both pre-defined and custom operations to each element.
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()
, 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()
or Aggregate()
methods.
Documentation for this library is available at NetFabric.Numerics.Tensors Documentation.
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 per-element operations, the library also supports various aggregation operations, including:
var sum = TensorOperations.Sum(values);
var average = TensorOperations.Average(values);
var product = TensorOperations.Product(values);
var min = TensorOperations.Min(values);
var max = TensorOperations.Max(values);
var (min, max) = TensorOperations.MinMax(values);
The library offers functionality to retrieve the index of the first element meeting a specific condition:
var indexOfEqual = IndexOfEquals(values, 0);
var indexOfGreaterThan = IndexOfGreaterThan(values, 0);
var indexOfGreaterThanOrEqual = IndexOfGreaterThanOrEqual(values, 0);
var indexOfLessThan = IndexOfLessThan(values, 0);
var indexOfLessThanOrEqual = IndexOfLessThanOrEqual(values, 0);
Please consult the documentation to get the complete list of pre-defined operations.
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. Please refer to the documentation for instructions on how to do it.
Benchmarks
Please consult the documentation to obtain benchmarking results.
Product | Versions 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. |
-
net8.0
- NetFabric (>= 1.5.0)
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)
|
- Improved performance of Aggregate2D, Aggregate3D, and Aggregate4D.
- Made the operators public.
- Added interfaces IUnaryToScalarOperator, IBinaryToScalarOperator, and ITernaryToScalarOperator.
- Added IndexOfPredicate method.
- Added operations: IndexOfEquals, IndexOfGreaterThan, IndexOfGreaterThanOrEqual, IndexOfLessThan, and IndexOfLessThanOrEqual.