NumSharp.Interop.System.Numerics.Tensors 0.80.0

dotnet add package NumSharp.Interop.System.Numerics.Tensors --version 0.80.0
                    
NuGet\Install-Package NumSharp.Interop.System.Numerics.Tensors -Version 0.80.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="NumSharp.Interop.System.Numerics.Tensors" Version="0.80.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NumSharp.Interop.System.Numerics.Tensors" Version="0.80.0" />
                    
Directory.Packages.props
<PackageReference Include="NumSharp.Interop.System.Numerics.Tensors" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NumSharp.Interop.System.Numerics.Tensors --version 0.80.0
                    
#r "nuget: NumSharp.Interop.System.Numerics.Tensors, 0.80.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.
#:package NumSharp.Interop.System.Numerics.Tensors@0.80.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NumSharp.Interop.System.Numerics.Tensors&version=0.80.0
                    
Install as a Cake Addin
#tool nuget:?package=NumSharp.Interop.System.Numerics.Tensors&version=0.80.0
                    
Install as a Cake Tool

NumSharp.Interop.System.Numerics.Tensors

Zero-copy interop between NumSharp's NDArray and the BCL's System.Numerics.Tensors types — Tensor<T>, TensorSpan<T> and ReadOnlyTensorSpan<T>.

It is a conversion library: it moves data (or rather, descriptions of the same memory) across the boundary. It is not an engine backend — System.Numerics.Tensors does not compute NumSharp operations, so there is no TensorEngine seam, no [ModuleInitializer], and no native dependency. Referencing the package changes nothing until you call a verb.

Do not route NumSharp's own operations through TensorPrimitives — NumSharp's kernels are bit-exact with NumPy (and often faster than TensorPrimitives). This bridge is a data bridge.

Verbs

As… shares memory (zero-copy); To… copies.

Verb Direction Semantics
nd.AsTensorSpan<T>() → TensorSpanHandle<T> NDArray → Tensors zero-copy TensorSpan<T> / ReadOnlyTensorSpan<T> over the NDArray's buffer, any non-negative-stride layout
nd.ToTensor<T>() → Tensor<T> NDArray → Tensors independent dense copy (any source layout, logical order)
tensor.ToNDArray() → NDArray Tensors → NDArray owning copy (the safe default)
tensor.AsNDArray() → NDArray Tensors → NDArray zero-copy view over the pinned tensor backing store, booked with NumSharp's memory accounting while pinned (a forgotten view is collected like a forgotten NumSharp array)
span.ToNDArray() Tensors → NDArray copy (a ref struct span cannot be leased)
nd.ToStringTensor() → Tensor<string> NDArray → Tensors copy of a text array (U, S decoded as UTF-8, StringDType; an NA as null)
tensor.ToNDArray() of Tensor<string> / a string span Tensors → NDArray copy into StringDType(na_object=None), a null as the NA

Dtypes — all 15 cross as themselves

System.Numerics.Tensors containers are unconstrained generics over an unmanaged T. So every NumSharp dtype crosses zero-copy as its own CLR type — bool, the eight integers, char, System.Half (directly, no Float16 wrapper), float, double, System.Decimal and System.Numerics.Complex. Nothing is refused and nothing is converted.

Text — always a copy

NumSharp's text arrays (U, S, StringDType) are not an unmanaged element type, and a Tensor<string> holds managed strings, so no text can be shared in either direction: text crosses as a copy, nd.ToStringTensor() one way and tensor.ToNDArray() the other. AsTensorSpan<T>() / ToTensor<T>() refuse a text array with a message naming its class and ToStringTensor().

Layout — strided views share, negative strides copy

A TensorSpan<T> carries explicit lengths + strides, so a sliced, transposed, strided or broadcast NDArray view shares zero-copy (a broadcast view through ReadOnlySpan only — writing overlapping stride-0 lanes would corrupt data). The one refusal is a negative-stride view (a reversed slice a[::-1]): System.Numerics.Tensors forbids negative strides — materialize it first (np.ascontiguousarray(nd), nd.copy()) or use ToTensor.

Edge shapes

  • 0-d scalar → [1]. The BCL has no rank 0, so both AsTensorSpan and ToTensor give a 0-d array the shape [1], keeping its value; importing that tensor back gives (1,).
  • Empty arrays keep their shape. A (3,0,4) array exports as a rank-3 span with every stride 0 (the form the BCL accepts for a zero-size span), which the BCL can flatten, fill and reduce. The BCL's own rank-0 values (Tensor<T>.Empty, ReadOnlyTensorSpan<T>.Empty) hold no element and import as (0,).
  • Sliced tensors import their own elements. A tensor that starts past element 0 of its backing array (t.Slice(…), a range indexer, Tensor.Create(array, start, …)) is copied or viewed from its own start. (Tensor<T>.GetPinnedHandle() points at the backing array's element 0, so the bridge reads the start from the tensor's span instead.)
  • Released buffers are refused. AsTensorSpan and ToTensor throw ObjectDisposedException for an array whose buffer has been released, whatever its layout.

Example

using System.Numerics.Tensors;
using NumSharp;
using NumSharp.Interop.Tensors;

var nd = np.arange(6).reshape(2, 3).astype(NPTypeCode.Single);

// Zero-copy: mutate the NDArray through a TensorSpan.
using (var h = nd.AsTensorSpan<float>())
{
    TensorSpan<float> span = h.Span;          // shares nd's buffer
    for (nint i = 0; i < span.Lengths[0]; i++)
        for (nint j = 0; j < span.Lengths[1]; j++)
            span[new[] { i, j }] += 10f;       // writes straight into nd
}

// Read a tensor produced elsewhere back as an NDArray, no copy.
var output = Tensor.Create(new[] { 0.1f, 0.7f, 0.2f }, new nint[] { 3 });
using NDArray probs = output.AsNDArray();
long best = np.argmax(probs);                  // 1 (the flat argmax is a long)

Frameworks

Builds assemblies for net8.0 and net10.0; net9.0 and net11.0 consumers are served by the net8.0 / net10.0 assets via NuGet nearest-TFM selection. Depends only on the managed System.Numerics.Tensors package.

Experimental

Tensor<T>/TensorSpan<T> are [Experimental("SYSLIB5001")] in the BCL; this package re-marks its own surface [Experimental("NUMSHARP_TENSORS")] so you acknowledge that churn once. Suppress with <NoWarn>NUMSHARP_TENSORS</NoWarn> or #pragma warning disable NUMSHARP_TENSORS.


What's new in 0.80.0

We are at 95.2% NumPy API coverage, and everything except datetime, complex64 and other exotic dtypes matches NumPy byte for byte. This release brings NumPy's text dtypes with numpy.strings and numpy.char, numpy.ma, numpy.polynomial, np.emath and 48 new np.* functions. Integration rather than competition goes on, this time inside .NET: an NDArray now runs through ONNX Runtime models, serves as an ML.NET IDataView and shares its memory with System.Numerics.Tensors.

🧭 Overview

  • NumPy 2.x API coverage around 95.2%, everything except datetime, complex64 and other exotic dtypes is fully supported, with byte-to-byte equality and compatibility to NumPy.
    • Text - NumPy's fixed-width bytes_ (S) and str_ (U) dtypes and NEP 55's variable-width StringDType, with every computation NumPy runs on text, all 46 numpy.strings functions and numpy.char with chararray.
    • np.polynomial.* - the whole numpy.polynomial package, all 193 functions and the six series classes for all six bases, bit-exact.
    • np.* - +48 functions, the ten most used on GitHub: np.hypot, np.histogram, np.logspace, np.gradient, np.vectorize, np.hanning, np.geomspace, np.apply_along_axis, np.trapezoid and np.histogram2d.
    • np.random.* - every NumPy bit generator, the whole Generator distribution surface, and a legacy RandomState that is NumPy's own sampler code line for line, all byte-identical streams.
    • np.ma.* - the masked-array module; np.emath.* - the automatic-domain math module; np.matrix - numpy.matrix as the new NDMatrix type.
  • DType is NumPy's two-level dtype model - NDArray.dtype returns a numpy.dtype-shaped descriptor, with np.dtypes, byte order and datetime64 / timedelta64 descriptors, and NumPy's scalar classes (np.integer, np.floating, np.number, ...) with np.typing.
  • Reductions on NumPy's own schedules - max, min, ptp, nanmax, nanmin, argmax, the flat sum / mean and the fused np.evaluate reductions match NumPy bit for bit, down to the sign of a ±0 tie and a NaN's payload; mean, var, std and their NaN-aware forms are NumPy's own statements; and most of them run faster.
  • NumPy's structure for the engine - every computing np.* function is a TensorEngine member named after its NumPy source file, numpy.linalg and numpy.fft are replaceable sub-engines, and the default engine is settable.
  • The 2026-11-02 parity QA - 53 of its 55 findings fixed on the owner's decisions (one kept as a documented divergence, one deferred), and NumPy's own dot functions behind np.dot / np.vdot / np.vecdot.
  • 86 NumPy-parity, memory-safety and tooling fixes, 40 measured speedups and 44 breaking changes, across the release's 1,670 commits.
  • 3 new NuGet packages - NumSharp.Interop.System.Numerics.Tensors, NumSharp.Interop.OnnxRuntime and NumSharp.Interop.MLNet.
  • 1,119,305 NumPy 2.4.2 oracle test cases (0.70.0: 119,517) and 20,506 test methods (0.70.0: 14,416).

📦 New NuGet Packages

  • NumSharp.Interop.System.Numerics.Tensors - zero-copy interop between NDArray and the BCL's Tensor<T> / TensorSpan<T> (System.Numerics.Tensors), all 15 dtypes.
  • NumSharp.Interop.OnnxRuntime - run ONNX Runtime models on NDArrays, fed from the arrays' own memory, with the outputs read back as NDArrays.
  • NumSharp.Interop.MLNet - an NDArray as an ML.NET IDataView, and a transformer's output column back as an NDArray.

Full NumSharp 0.80.0 release notes

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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.80.0 85 11/8/2026