Class ILKernelGenerator
Generates per-chunk IL kernels for NDIter-driven execution.
Kernels emitted here are called as the inner loop of an NDIter iteration — once per chunk, with dataptrs/strides/count provided by the iterator. The kernel does no axis or stride walking of its own.
Add new kernel families in ILKernelGenerator.<Op>.cs
partial files. See DirectILKernelGenerator for the
legacy whole-array kernels currently being migrated to this model.
public static class ILKernelGenerator
- Inheritance
-
ILKernelGenerator
- Inherited Members
Methods
GetCumSumInnerLoop(NPTypeCode, NPTypeCode)
Returns the NDIter-driven cumulative-sum inner loop for
inType → accType. The returned
delegate matches NDInnerLoopFunc; drive it with an
iterator whose scan axis has been removed (see
DefaultEngine.AccumulateAxis), passing a pointer to a
ILKernelGenerator.ScanAxisAux as the kernel's auxdata.
public static NDInnerLoopFunc GetCumSumInnerLoop(NPTypeCode inType, NPTypeCode accType)
Parameters
inTypeNPTypeCodeaccTypeNPTypeCode
Returns
GetReduceInnerLoop(ReduceKernelKey)
Returns the cached per-chunk reduction kernel for the given (op, input, accumulator) triple, or null when no NDIter-driven kernel exists yet (caller falls back to the DirectILKernelGenerator path). The returned delegate matches NDInnerLoopFunc; hand it to an iterator built by NewReduce(NDArray, NDArray, int, NDIterGlobalFlags).
public static NDInnerLoopFunc GetReduceInnerLoop(ILKernelGenerator.ReduceKernelKey key)
Parameters
Returns
MeanDivideByCount(NDArray, long)
Divide every element of output by count in
place — the post-pass that turns an accumulated axis Sum into a Mean. For Complex
this is NumPy's complex division by count+0j (np.mean's true_divide(sum, n)
runs the CDOUBLE_divide loop, Smith's algorithm: ((re + im0)(1/n), (im - re0)(1/n)),
see ComplexDivideByCountLikeNumPy(Complex, long)), so an
infinite or NaN part poisons the other one and the rounding is NumPy's; it used to divide each
component by the count. Any output layout is honored.
public static void MeanDivideByCount(NDArray output, long count)
Parameters
outputNDArrayThe accumulated sums, divided in place.
countlongThe reduced-axis length (0 leaves the output untouched, as before).
Remarks
A writeable dense-block output (C- or F-contiguous) is divided through typed pointers — a
Vector<T> loop for float64/float32, a scalar loop for complex/decimal — with the
IDENTICAL arithmetic of the boxed loop (x / (double)count, x / (float)count,
NumPy's complex division, decimal): IEEE division is correctly rounded per lane, so the vector
and scalar forms are bit-identical. The boxed GetAtIndex/SetAtIndex loop it
replaces cost ~4 ns per output (np.mean(axis=0) of 3×1M spent ~4 of its 6.7 ms here). A
strided or read-only output keeps the boxed loop.
Exceptions
- NotSupportedException
The output dtype is not Complex/Double/Single/Decimal (the only mean accumulators).
SeedReduceIdentity(NDArray, ReductionOp)
Pre-fill output with the reduction identity for
op before driving a REDUCE iterator. Required because
the per-chunk kernels fold into the existing output slot(s). Any output
layout (contiguous fresh alloc or user-supplied view) is honored.
public static void SeedReduceIdentity(NDArray output, ReductionOp op)
Parameters
outputNDArrayThe reduction output to seed; its dtype selects the identity.
opReductionOpThe reduction whose identity is written (Sum/Prod/Min/Max, Any/All for bool).
Remarks
A writeable output whose elements occupy one dense memory block (C- or F-contiguous —
every fresh reduction result, and most user out= arrays) takes the fast path: the
identity is written to logical element 0 through SetAtIndex(object, long)
— so its exact unboxing conversion and read-only check are unchanged — and that element's
bytes are then replicated across the block with a vectorized fill. The per-element boxed
SetAtIndex loop it replaces cost ~2 ns per output (a 3×1M axis-0 sum spent ~2 ms
seeding 1M slots). A strided or read-only output keeps that loop (which raises the same
read-only error at its first write).
Exceptions
- NotSupportedException
ophas no identity for the output dtype (Complex supports Sum/Prod/Min/Max only; see GetIdentity(ReductionOp, NPTypeCode)).- InvalidCastException
The boxed identity does not unbox to the output's element type (a caller pairing the op with a foreign dtype).