Struct InnerLoopKernelKey
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
Packedulong
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
Op
The raw op ordinal (interpret through Family).
public int Op { get; }
Property Value
Packed
public ulong Packed { get; init; }
Property Value
Type0
First dtype (lhs / input / shift value).
public NPTypeCode Type0 { get; }
Property Value
Type1
Second dtype (rhs / output / shift result).
public NPTypeCode Type1 { get; }
Property Value
Type2
Third dtype (binary result; Empty otherwise).
public NPTypeCode Type2 { get; }
Property Value
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
opBinaryOplhsNPTypeCoderhsNPTypeCoderesultNPTypeCode
Returns
Clip(ClipMode?, bool, NPTypeCode)
Key of np.clip's iterator-route kernel npy_clip_{mode}{general|const}{dtype}. The body differs per
bound mode and per NumPy loop (const vs general), so both are part of the identity; the dtype is the loop
dtype every operand carries.
public static InnerLoopKernelKey Clip(DirectILKernelGenerator.ClipMode? mode, bool constSelect, NPTypeCode dtype)
Parameters
modeDirectILKernelGenerator.ClipMode?The clip mode, or
nullfor the no-bound identity copy (NumPy's positive).constSelectboolTrue for NumPy's const fast path (float32/float64, two bounds).
dtypeNPTypeCodeThe loop dtype.
Returns
- InnerLoopKernelKey
The packed key.
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
opComparisonOplhsNPTypeCoderhsNPTypeCode
Returns
PowerStrideZero(NPTypeCode, NPTypeCode, NPTypeCode)
Key of np.power's zero-exponent-step float kernel npy_powz_{lhs}{rhs}{result}
(EmitPowerStrideZeroBody(ILGenerator, NPTypeCode, NPTypeCode, NPTypeCode)): the operands keep their stored dtypes and
are converted to result inside the body.
public static InnerLoopKernelKey PowerStrideZero(NPTypeCode lhs, NPTypeCode rhs, NPTypeCode result)
Parameters
lhsNPTypeCodeThe base's stored dtype.
rhsNPTypeCodeThe exponent's stored dtype.
resultNPTypeCodeThe loop dtype (float32 or float64).
Returns
- InnerLoopKernelKey
The packed key.
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
isLeftShiftboolvalueLoopTypeNPTypeCoderesultNPTypeCode
Returns
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
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
opUnaryOpinputNPTypeCodeoutputNPTypeCode