Table of Contents

Struct InnerLoopKernelKey

Namespace
NumSharp.Backends.Kernels
Assembly
NumSharp.dll

Compact identity of a production inner-loop kernel (the Tier-3B kernels the ufunc routes drive through NDIterRef.ExecuteElementWise*): the ufunc family, its op and up to three dtypes packed into one 64-bit value.

public readonly record struct InnerLoopKernelKey : IEquatable<InnerLoopKernelKey>
Implements
Inherited Members

Remarks

The routes used to identify their kernel with an interpolated string — $"npy_binop_{op}{lhs}{rhs}_{res}" — rebuilt on EVERY call: four enum formats and a string allocation, measured 45 ns + 96 B of garbage per call against ~10 ns for a dictionary probe on a prebuilt key. On a small array that string was a larger share of the call than the iterator's own construction. This key is the allocation-free replacement; ToCacheKey() reproduces the exact string each route used to build, so the string-keyed cache and the generated DynamicMethod names are unchanged — the struct cache is purely a front cache over them.

Constructors

InnerLoopKernelKey(ulong)

Compact identity of a production inner-loop kernel (the Tier-3B kernels the ufunc routes drive through NDIterRef.ExecuteElementWise*): the ufunc family, its op and up to three dtypes packed into one 64-bit value.

public InnerLoopKernelKey(ulong Packed)

Parameters

Packed ulong

Remarks

The routes used to identify their kernel with an interpolated string — $"npy_binop_{op}{lhs}{rhs}_{res}" — rebuilt on EVERY call: four enum formats and a string allocation, measured 45 ns + 96 B of garbage per call against ~10 ns for a dictionary probe on a prebuilt key. On a small array that string was a larger share of the call than the iterator's own construction. This key is the allocation-free replacement; ToCacheKey() reproduces the exact string each route used to build, so the string-keyed cache and the generated DynamicMethod names are unchanged — the struct cache is purely a front cache over them.

Properties

Family

The family this key was built for.

public InnerLoopKernelKey.KernelFamily Family { get; }

Property Value

InnerLoopKernelKey.KernelFamily

Op

The raw op ordinal (interpret through Family).

public int Op { get; }

Property Value

int

Packed

public ulong Packed { get; init; }

Property Value

ulong

Type0

First dtype (lhs / input / shift value).

public NPTypeCode Type0 { get; }

Property Value

NPTypeCode

Type1

Second dtype (rhs / output / shift result).

public NPTypeCode Type1 { get; }

Property Value

NPTypeCode

Type2

Third dtype (binary result; Empty otherwise).

public NPTypeCode Type2 { get; }

Property Value

NPTypeCode

Methods

Binary(BinaryOp, NPTypeCode, NPTypeCode, NPTypeCode)

Key of the binary-arithmetic kernel npy_binop_{op}{lhs}{rhs}_{result}.

public static InnerLoopKernelKey Binary(BinaryOp op, NPTypeCode lhs, NPTypeCode rhs, NPTypeCode result)

Parameters

op BinaryOp
lhs NPTypeCode
rhs NPTypeCode
result NPTypeCode

Returns

InnerLoopKernelKey

Comparison(ComparisonOp, NPTypeCode, NPTypeCode)

Key of the comparison kernel npy_cmp_{op}{lhs}{rhs} (bool output).

public static InnerLoopKernelKey Comparison(ComparisonOp op, NPTypeCode lhs, NPTypeCode rhs)

Parameters

op ComparisonOp
lhs NPTypeCode
rhs NPTypeCode

Returns

InnerLoopKernelKey

Shift(bool, NPTypeCode, NPTypeCode)

Key of the shift kernel npy_shift_{L|R}{value}{result}.

public static InnerLoopKernelKey Shift(bool isLeftShift, NPTypeCode valueLoopType, NPTypeCode result)

Parameters

isLeftShift bool
valueLoopType NPTypeCode
result NPTypeCode

Returns

InnerLoopKernelKey

ToCacheKey()

The string key this kernel is registered under in the string-keyed inner-loop cache — byte-identical to the interpolated key the route built before the packed key existed. Only evaluated on a cache miss.

public string ToCacheKey()

Returns

string

ToString()

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string

The fully qualified type name.

Unary(UnaryOp, NPTypeCode, NPTypeCode)

Key of the unary kernel npy_unop_{op}{input}{output}.

public static InnerLoopKernelKey Unary(UnaryOp op, NPTypeCode input, NPTypeCode output)

Parameters

op UnaryOp
input NPTypeCode
output NPTypeCode

Returns

InnerLoopKernelKey