Repository navigation
hotkernels 0.3.0
hotkernels 0.3.0
Highlights
Eleven more NumPy calls are served, chosen from the calls a program in use makes rather than from a list of benchmarks. Eight kernels are new, and three calls on short arrays now skip NumPy's own call path. The new kernels are written for Linux x86-64; on Apple Silicon they run as compiled C until their ARM64 assembly exists, so every figure in these notes is from x86-64, measured from Python on an Intel Core i5-14600KF.
- Boolean masks.
np.cumsum(mask)is 9.7x faster than NumPy at 4,096 elements and 9.1x at a million.np.sum(mask)andmask.sum()are 12.5x faster at a million and 14x to 33x at 16.m.any(axis=1)on a matrix of 22 columns is 16x faster at 4,096 elements and 43x at a million. np.where(mask, a, b)onfloat64orint64arrays of one shape, and on afloat64array beside a single number, as innp.where(mask, a, np.nan): 5.9x faster at a million elements with half the mask True, 2.5x for the form with a number and a mask that is mostly True, and 4.6x at 16.- Running maxima, and maxima of runs.
np.maximum.accumulateonint64is 11.5x faster at 4,096 elements and 5.2x at a million;np.fmax.accumulateonfloat646.8x and 5.1x.np.fmax.reduceaton runs of 16 elements is 12x faster at 4,096 and at a million. np.bincountonint16andint64: 4.5x and 1.9x faster at a million elements on codes from 0 to 63.- More arrays reach kernels that already existed.
x[mask],np.compressandnp.extracttakeint64(10x at a million elements with half selected), andx[mask]andx[mask] = vtake arrays of any number of dimensions when the mask has the array's shape (10x and 18x at a million). - Short arrays.
np.median(x)on up to 128float64elements is 44x faster at 16 elements.np.cliponint64andnp.roundonfloat64, on up to 4,096 elements, are 15x and 7.5x faster at 16. Above those sizes the calls go to NumPy as before, at NumPy's speed. - What goes to NumPy on purpose. For a few inputs NumPy's own answer depends on which of its builds is running: the sign of a zero maximum when the data holds zeros of both signs, and which NaN comes back when everything is NaN.
np.fmax.accumulateandnp.fmax.reduceatleave those inputs to NumPy, so the result is NumPy's on every machine.
No wrong result was fixed in this release.
What is installed. 31 kernels for 21 NumPy operations. install() installs the 29 that return NumPy's result bit for bit; install(inexact=True) adds np.cumsum on float32 and float64. The three short-array calls are loops inside the package, listed in report() beside the kernels.
Checked against NumPy itself. On Linux x86-64, 166,029 NumPy calls give the same result, exceptions and warnings with hotkernels as without, and NumPy's own test suite gives the same outcome for each of its 48,659 tests. On Apple Silicon the same calls were checked on every pull request of this release.
Where it runs. Unchanged: macOS on Apple Silicon and Linux on x86-64 (glibc, x86-64-v3), Python 3.11 to 3.14, NumPy 2.3 or a later NumPy 2.
Measured from Python with uv run delivery time, one line per machine:
- Intel Core i5-14600KF, NumPy 2.5.5, Python 3.13.15, pinned to one performance core (load average 0.8), at revision
52c1abc:delivery/results/intel-r-core-tm-i5-14600kf.md. - Apple M1 Pro: not measured for this release.
delivery/results/apple-m1-pro.mdis the run recorded for 0.2.0, at revision1aae15a, and holds none of the calls that are new here.
New kernels
np.sum(mask)andmask.sum()on a boolean array are served by the kernel that sumsuint8: about 12x faster than NumPy at a million elements and 15x to 30x on small arrays, measured on x86-64. (#145)x[mask],np.compress(mask, x)andnp.extract(mask, x)onint64are served by the kernel that selectsfloat64: about 10x faster than NumPy at a million elements with half the mask True, measured on x86-64. (#146)x[mask]andx[mask] = vare served by their kernels for arrays of more than one dimension, when the mask has the shape ofx:x[mask] = 0.0on a two-dimensionalfloat64array is about 10x faster than NumPy at 4,096 elements, measured on x86-64. (#147)np.cumsum(mask)andmask.cumsum()on a boolean array are served by a kernel: about 9.7x faster than NumPy at 4,096 elements and 9x at a million, measured on x86-64. (#148)np.where(mask, a, b)onfloat64andint64arrays of one shape, and on afloat64array beside a single number such asnp.nanor0, is served by a kernel: measured on x86-64, about 6x faster than NumPy at a million elements with half the mask True, and 2.5x fornp.where(mask, a, np.nan)with most of it True. On ARM64 the same calls run a plain C loop for now. (#149)np.maximum.accumulateonint64, andnp.fmax.accumulateonint64andfloat64, are served by kernels for one-dimensional arrays: measured on x86-64, about 5.3x and 5x faster than NumPy at a million elements and 2.6x and 2.8x at 16.np.maximum.accumulateon floats, which carries NaN forward, stays with NumPy, and so does afloat64array holding a signalling NaN, a negative zero, or NaNs of different bit patterns. On ARM64 the same calls run a plain C loop for now. (#150)np.fmax.reduceat(x, starts)on a one-dimensionalfloat64array withint64starts is served by a kernel: on runs of 16 elements with 5% NaN it is about 12x faster than NumPy at a million elements, measured on x86-64. The gain is on short runs; on runs of a thousand elements or more in large arrays it can be slower than NumPy.np.fmax.accumulateonfloat64is faster too (about 5x at a million elements, was 3.3x), and neither call now leaves the floating-point invalid flag set. (#151)m.any(axis=1)andnp.any(m, axis=1)on a two-dimensional boolean array in C order are served by a kernel: on rows of 22 columns about 42x faster than NumPy at a million elements and 5x on a single row, measured on x86-64.m.any(), other axes and calls without,keepdimsorwherestay with NumPy. (#152)np.bincountonint16andint64arrays is served by kernels: on codes from 0 to 63, about 4.5x faster than NumPy forint16and 1.9x forint64at a million elements, measured on x86-64. An array holding a negative element still goes to NumPy, which raises as before. (#153)
Faster
np.clip(x, lo, hi)andx.clip(lo, hi)on anint64array of up to 4,096 elements, with bounds that are Python ints ornp.int64, skip NumPy's call path: about 15x faster than NumPy at 16 elements and 3.6x at 4,096, measured on x86-64. Longer arrays go to NumPy as before. (#154)np.round(x, decimals),np.aroundandx.round(decimals)on afloat64array of up to 4,096 elements, withdecimalsa Python int from 0 to 15, skip NumPy's call path and give NumPy's result bit for bit:np.round(x, 2)is about 7.5x faster than NumPy at 16 elements and 2.2x at 4,096, measured on x86-64. Longer arrays, and calls where NumPy would warn, go to NumPy as before. (#155)np.median(x)on afloat64array of up to 128 elements, with no other argument, skips NumPy's Python implementation and gives its result bit for bit: about 44x faster than NumPy at 16 elements, measured on x86-64. Longer arrays, arrays holding a NaN, and calls withaxisor any other argument go to NumPy as before. (#156)