Repository navigation
Releases
hotkernels 0.4.0
hotkernels 0.4.0
Highlights
More of the calls real programs make are served. The calls were chosen from what scikit-learn, pandas, training loops and published benchmarks spend their time in. There are 18 new kernels, and seven changes make calls faster that were already served or were left to NumPy. The package now has 49 kernels where 0.3.1 had 31. Every figure below is from Python on an Apple M1 Pro, against plain NumPy, unless it names the Intel Core i5-14600KF.
-
Sorting and selecting.
np.argsort(x, kind="stable")onfloat64,int64anduint64is 13x faster at a million elements, and 28x on keys with few distinct values.np.medianonfloat64is 7.8x faster at a million elements and 53x at 16.np.unique(x)onint64labels close together, such as class labels, is 17x faster.
-
Reductions and searches over matrices.
a.cumsum(axis=0),a.cumprod(axis=0),np.maximum.accumulate(a, axis=0)andnp.fmax.accumulate(a, axis=0)on a C-orderedfloat64matrix are 20x to 25x faster at a million elements.m.any(axis=0)on a boolean matrix is 43x faster with 31 columns.np.nonzero(m)andnp.where(m)on a boolean matrix are 27x faster at a million elements with few True, andnp.argwhere(m)20x.np.argmax(m, axis=1)andnp.argmin(m, axis=1)are about 3.5x faster on rows of tenfloat64.
-
Sums.
np.sum(x)andx.sum()onfloat32andfloat64keep NumPy's result bit for bit. They are 23x faster at 16 elements, and 3.0x (float32) and 1.8x (float64) at a million. -
In place.
np.clip(g, lo, hi, out=g), the gradient-clipping idiom, used to go to NumPy and is now served: 16x faster at 16 elements and 2.5x at a million onfloat64.w -= bandw += bon largefloat64arrays right after a matrix product has readware about 5x faster on Apple Silicon. Elsewhere they run at NumPy's speed.
-
Searches.
np.searchsortedonint64is 2.2x faster with as many needles as elements, and about 2x with one needle at any length.np.searchsortedonfloat64withfloat32needles is 8x faster.
-
bottleneck. When bottleneck is installed, its
nanmean,nanstd,nanminandnanmaxalongaxis=0of afloat64matrix, which pandas and empyrical call, are served with bottleneck's results bit for bit. They are about 4x to 7x faster than bottleneck. -
Small arrays. Elementwise operations on up to 16,384 elements, such as
a + b,a > 0,np.exp(a)andx += y, skip most of NumPy's call path. At 16 elementsa + bis about 2x faster,a > 0about 3x andnp.exp(a)1.6x, with the same results and warnings. -
Linux x86-64. Several calls got faster on the Intel Core i5-14600KF, with the figures measured on it in their pull requests:
x[mask]on one-byte and two-byte types: 56x at a million elements onuint8.x[mask] = vonfloat32andint32: 31x onfloat32.np.isinonint32: 20x at a million elements.- A single
np.roundon afloat64scalar: 16x to 18x. np.uniqueonint64labels: about 39x at a million elements.
On Apple Silicon, the kernels for
x[mask]on one- and two-byte types, forx[mask] = vonfloat32andint32, and fornp.isinonint32are the same kernels compiled from C.np.uniquehas ARM64 assembly of its own. The scalarnp.roundis a loop inside hotkernels on both architectures.
One wrong result fixed. with hotkernels.enabled(inexact=True): inside an install() left the inexact np.cumsum kernels on after the block. Until the next install() or uninstall(), np.cumsum on float32 and float64 gave results within the inexact kernels' tolerance instead of NumPy's bit for bit. On leaving the block, hotkernels is now as the block found it.
One figure went down.
- What changed.
np.clip(x, lo, hi)on a million elements is 8.0x faster than NumPy onfloat32and 3.2x onfloat64, where 0.3.1 measured 11x and 4.7x. - What did not. The kernel is the same, NumPy's time at a million elements is the same, and the figures at 4,096 elements are unchanged. At 16 elements
np.cliponfloat32is 10x faster where it was 11x, in a run on a newer Python. - Where it starts. The difference starts with the in-place add and subtract loops of this release. It looks like how memory for the result is reused, not the kernel, and is being looked into in #345.
What is installed.
- The count. 49 kernels for 23 NumPy operations and four functions of bottleneck.
install()installs the 47 that return NumPy's or bottleneck's result bit for bit, andinstall(inexact=True)addsnp.cumsumonfloat32andfloat64. - ARM64. 37 of the 49 are hand-written assembly, and the rest are compiled C.
- x86-64. 42 are assembly.
Checked against NumPy itself. On Apple Silicon, 403,023 calls to NumPy and bottleneck give the same result, exceptions and warnings with hotkernels as without. release.yml runs NumPy's own test suite against every wheel.
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.
Not in the package. The repository also has a prototype lazy layer, which fuses whole NumPy expressions into one pass. It is not part of this release; its README describes it.
Measured from Python with uv run delivery time, one line per machine:
- Apple M1 Pro. NumPy 2.5.5, Python 3.13.12, load average 1.13, at revision
3da180b, whose package and kernels are those of this release:delivery/results/apple-m1-pro.md. Thew -= bfigure is from the gradient-step study of #210, and the bottleneck andargmax(axis=1)figures are from their pull requests on the same machine. - Intel Core i5-14600KF. Not re-measured for this release. The x86-64 figures above are from the pull requests that added each kernel.
delivery/results/intel-r-core-tm-i5-14600kf.mdis still the run recorded for 0.3.0.
New kernels
np.clip(x, lo, hi, out=x)andx.clip(lo, hi, out=x)onfloat32andfloat64, the usual way to clip gradients in place, are served by the clip kernels instead of NumPy: about 4x faster than NumPy on a 100 × 100float64array and 2.7x at a million elements, measured on an Apple M1 Pro. (#197)np.argmax(m, axis=1)andnp.argmin(m, axis=1)(andm.argmax(axis=1)) on a C-ordered two-dimensionalfloat32orfloat64array are served: about 3.5x faster than NumPy on 300,000 rows of tenfloat64and about 15x on rows of two or three, on an Apple M1 Pro.report()now counts such a call once, however many rows NumPy splits it into. (#201)np.unique(x)onint64labels, a few distinct values close together such as the class labels scikit-learn checks on every call, is served by a kernel: about 18x faster than NumPy at a million elements on an Apple M1 Pro (ARM64). Calls with counts, an inverse or indices, withsorted=False, or on widely spread values go to NumPy as before. (#206)- When bottleneck is installed, its
nanmean,nanstd,nanminandnanmaxon two-dimensionalfloat64arrays along an axis whose other axis is contiguous (axis=0of a C-ordered array or of a rolling-window view), which pandas and empyrical call in place of NumPy's, are served by kernels with bottleneck's results bit for bit: about 4x to 7x faster than bottleneck at 252 × 4,789 on an Apple M1 Pro. hotkernels never imports bottleneck, andinstall(bottleneck=False)leaves it alone. (#211) np.argsort(x, kind="stable")on one-dimensionalfloat64,int64anduint64arrays is served by a kernel, as arekind="mergesort"andstable=True: about 13x faster than NumPy at a millionfloat64elements and 15x to 28x on integers, measured on an Apple M1 Pro. The result is NumPy's, ties, NaNs and zeros of both signs included. The default kind,np.argsort(x), is unchanged. (#215)np.searchsortedon a sortedint64array is served by a kernel, on either side, forint64needles: an array of them, onenp.int64or a Python int. On x86-64 (Intel Core i5-14600KF) a call with one needle is about 2.1x faster than NumPy at any length, and one with 4,096 needles against 4,096 elements about 3.3x. Needles of another type, such asint32or a float, go to NumPy as before. (#245)m.any(axis=0)andnp.any(m, axis=0)on a two-dimensional boolean array in C order are served by a kernel. On x86-64 (Intel Core i5-14600KF) a mask of 30 rows by 31 columns is about 9x faster than NumPy, and a matrix of 31 columns about 18x at 4,096 elements and 37x at a million. Calls withkeepdims,outorwherego to NumPy as before. (#248)np.sum(x)andx.sum()on a one-dimensionalfloat32array are served by a kernel on Apple Silicon, with NumPy's result bit for bit: from Python on an Apple M1 Pro, about 20x faster than NumPy at 16 elements, 10x at 4,096 and 3x at a million. It is installed by default; other arguments, other shapes, and sums that overflow or meet a NaN or an infinity stay with NumPy. (#250)np.sum(x)andx.sum()on a one-dimensionalfloat64array are served by a kernel on Apple Silicon, with NumPy's result bit for bit: from Python on an Apple M1 Pro, about 20x faster than NumPy at 16 elements, 6x ...
hotkernels 0.3.1
hotkernels 0.3.1
Highlights
On Apple Silicon, the eight kernels that 0.3.0 added for Linux x86-64 now have ARM64 assembly of their own. In 0.3.0 those calls ran on a Mac as compiled C; one of them, np.fmax.reduceat, was slower than NumPy there beyond a few thousand elements. Nothing changes on x86-64. Every figure below is from Python on an Apple M1 Pro, against plain NumPy.
- Boolean masks.
np.cumsum(mask)is 12x faster than NumPy at 4,096 elements and 19x at a million.m.any(axis=1)on a matrix of 22 columns is 11x faster at 4,096 elements and 24x at a million, and rows of every other width were given paths of their own: a matrix of one column, which was slower than NumPy, is now 1.4x faster. - Running maxima.
np.maximum.accumulateonint64is 18x faster at 4,096 elements and 14x at a million.np.fmax.accumulateonfloat64is 19x and 13x, where 0.3.0 had it at 1.2x. np.fmax.reduceaton runs of 16 elements is 3.6x faster at 4,096 elements and 3.1x at a million, where 0.3.0 was 0.8x and 0.7x of NumPy. On long runs it is still slower than NumPy on Apple Silicon: 0.6x to 0.8x for runs of 256 elements or more in arrays of 262,144 elements and up, and level with it at 4,096 elements. The package reads the array once for signalling NaNs before the kernel reads it, and NumPy reads it once.np.bincountonint16is 9.4x faster at a million elements and onint644.3x, on codes from 0 to 63.np.where(mask, a, b)onfloat64orint64is 3.3x faster at 4,096 elements and 1.6x at a million with half the mask True.- One more case that stays behind NumPy on Apple Silicon:
m.any(axis=1)on rows of about 1,000 columns that each hold a True runs at about 0.6x of NumPy, which stops at the first True of a row while the package first reads every byte.
No wrong result was fixed in this release.
What is installed. Unchanged: 31 kernels for 21 NumPy operations, 29 of them by install() and two more by install(inexact=True). On Apple Silicon 30 of the 31 are now assembly and one, x.astype(np.float32) on uint8, is compiled C because the judge found no assembly faster; on x86-64 all 31 are assembly, as before.
Checked against NumPy itself. On Apple Silicon, 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 47,234 tests. The specifications of np.fmax.accumulate and np.fmax.reduceat were narrowed to the inputs the package sends to their kernels (it already left the others to NumPy), and the x86-64 kernels pass the judge under them: 20,368 and 20,313 cases on Linux x86-64.
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:
- Apple M1 Pro, NumPy 2.5.5, Python 3.12.7, with no CI job running (load average 2.2), at revision
ede46d1, whose package and kernels are those of this release:delivery/results/apple-m1-pro.md. The figures for long runs ofnp.fmax.reduceatand for other row widths ofm.any(axis=1)are fromtimeiton the same machine. - Intel Core i5-14600KF: not measured for this release. No x86-64 kernel changed, and the package's changes are in code compiled only for ARM64, so
delivery/results/intel-r-core-tm-i5-14600kf.mdis the run recorded for 0.3.0, at revision52c1abc.
Faster
np.maximum.accumulateandnp.fmax.accumulateonint64are served by assembly on Apple Silicon as well: about 14x faster than NumPy at a million elements on an Apple M1 Pro. (#163)np.cumsumon a boolean array is served by assembly on Apple Silicon as well: about 19x faster than NumPy at a million elements on an Apple M1 Pro. (#164)m.any(axis=1)andnp.any(m, axis=1)on a two-dimensional boolean array are served by assembly on Apple Silicon as well: on rows of 22 columns about 24x faster than NumPy at a million elements on an Apple M1 Pro, where the kernel alone is 8.7x faster than the compiled C loop that served the call before. (#165)np.bincounton int16 and int64 arrays is served by assembly on Apple Silicon as well: on int16 codes from 0 to 63 about 9x faster than NumPy at a million elements on an Apple M1 Pro, and on int64 about 4x, where the kernels alone are 2.95x and 1.54x faster than the compiled C loops that served the calls before. (#168)np.where(c, a, b)on float64 and int64 arrays is served by assembly on Apple Silicon as well: about 1.7x faster than NumPy at a million elements on an Apple M1 Pro, where the kernel alone is 1.36x faster than the compiled C loop that served the call before. (#170)m.any(axis=1)on Apple Silicon is faster for rows of other widths than 4, 22 and 64 as well: rows of 8 columns, for example, about 3.7x faster than before at a million elements on an Apple M1 Pro, and a matrix of one column now faster than NumPy. (#171)np.fmax.reduceatonfloat64is served by assembly on Apple Silicon: on runs of 16 elements it is about 2.4x faster than NumPy at a million elements on an Apple M1 Pro, where it was 0.7x, slower than NumPy. On runs of 256 elements or more it is still slower than NumPy there, about half its speed. (#179)np.fmax.accumulateonfloat64is served by assembly on Apple Silicon as well: about 7x faster than NumPy at 4,096 elements and at a million on an Apple M1 Pro, where it was 1.2x. (#180)- On Apple Silicon,
np.fmax.accumulateonfloat64andnp.fmax.reduceatread the array more cheaply before the kernel: on an Apple M1 Pronp.fmax.accumulateis about 18x faster than NumPy at 4,096 elements (was 7.5x) andnp.fmax.reduceaton runs of 16 about 3x at a million (was 2.3x).np.bincounton 16int16elements also gets faster, 4.5x where it was 3.2x. (#181)
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)
hotkernels 0.2.0
hotkernels 0.2.0
Highlights
hotkernels now runs on Linux x86-64 as well as on Apple Silicon, installs with pip on any platform, and serves np.searchsorted, np.interp and np.digitize. It now requires NumPy 2.3 or later, for a reason that matters to anyone on 0.1.0 with an older NumPy; see the last point.
- Linux x86-64. All 23 kernels were written a second time, for AVX2, and are checked against NumPy as the Apple Silicon ones are.
install()works on any processor with the x86-64-v3 instruction sets (Intel since 2013, AMD since 2015), and wheels are published for glibc Linux on CPython 3.11 to 3.14. From Python at a million elements on an Intel Core i5-14600KF:np.sumonuint8is 41.6x faster than NumPy,x[mask] = 0.017.7x,x[mask]onfloat3215.7x,np.cumsumonfloat3213.0x (withinstall(inexact=True)),np.histogram8.15x andnp.argmax1.84x. NumPy has vector loops of its own fornp.clipandx.astype(np.float32)on this platform, so those are level with it at a million elements (1.02x to 1.04x) and ahead only on small arrays (7.67x fornp.clipat 16 elements). No call a kernel takes is slower than NumPy at any size timed. np.searchsorted,np.interpandnp.digitizeonfloat64. For a million values looked up in a million sorted elements,np.searchsortedis 8.57x faster than NumPy on an Apple M1 Pro andnp.interp22.4x; against 1,000 sorted elementsnp.searchsortedis 26.6x andnp.digitize26.7x. On the Intel Core i5-14600KF the same four are 4.20x, 5.30x, 4.92x and 4.78x.- The function forms of the mask calls.
np.compress,np.extract,np.putmask,np.copyto(x, v, where=mask)andnp.where(mask)reach the kernels thatx[mask],x[mask] = vandnp.nonzeroalready used. At a million elements with half the mask selected, on the M1 Pro:np.compress6.11x,np.putmask18.0x,np.copyto20.3x,np.where(mask)3.46x. On the Intel Core i5-14600KF: 2.00x, 15.6x, 18.5x and 1.57x. - Small arrays.
np.clipwith Python numbers as bounds is 9.76x to 11.1x faster than NumPy at 16 elements on the M1 Pro, where 0.1.0 gained nothing, andx.argmax()3.11x. pip install hotkernelsworks everywhere. A source distribution is published. Where the kernels do not run it builds without a compiler andinstall()does nothing;print(hotkernels.report())says why.python -m hotkernels script.pyruns an unmodified script with hotkernels installed.- NumPy 2.3 or later is required, and 0.1.0 on NumPy 2.0 to 2.2 changes two results. Those NumPy releases answer
np.clip(the sign of a zero) andnp.count_nonzero(a Pythonint, notnp.intp) differently from later ones, and with hotkernels 0.1.0 installed those calls give the later answer. From this releaseinstall()does nothing on NumPy 2.0 to 2.2. If you stay on 0.1.0, use it with NumPy 2.3 or later.
What is installed. 23 kernels for 15 NumPy operations. install() installs the 21 that return NumPy's result bit for bit; install(inexact=True) adds np.cumsum on float32 and float64.
Checked against NumPy itself. On each platform, 96,734 NumPy calls give the same result, exceptions and warnings with hotkernels as without. On Linux x86-64, NumPy's own test suite gives the same outcome for each of its 48,659 tests.
Where it runs. 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. On an older x86-64 processor, on any other platform and on free-threaded Python, install() does nothing and report() says why.
Measured from Python with uv run delivery time, one line per machine:
- Apple M1 Pro, NumPy 2.5.5, Python 3.12.7, on a machine in use (load average about 2), at revision
1aae15a:delivery/results/apple-m1-pro.md. - Intel Core i5-14600KF, NumPy 2.5.5, Python 3.13.15, pinned to one performance core (load average about 1), at revision
5ad3a94:delivery/results/intel-r-core-tm-i5-14600kf.md.
The same statements on an Apple M4 Max are in delivery/results/apple-m4-max.md.
New kernels
np.searchsorted(a, v)andnp.interp(x, xp, fp)onfloat64are served by kernels: about 8.6x and 22x faster than NumPy for a million values looked up in a million sorted elements, on an Apple M1 Pro.np.searchsortedis taken without asorter, andnp.interpwithoutleft,rightorperiod. (#42)np.searchsorted(a, v, side='right')onfloat64is served by a kernel, and with itnp.digitize(x, bins)with its default arguments: about 27x faster than NumPy for a million values placed among 1,000 sorted elements or bin edges, on an Apple M1 Pro.np.digitizeis taken when its bins increase. (#49)np.compress(mask, x)andnp.extract(mask, x)onfloat32andfloat64,np.putmask(x, mask, v)andnp.copyto(x, v, where=mask)onfloat64with a Python number as the value, andnp.where(mask)with only a boolean mask are served by the same kernels asx[mask],x[mask] = vandnp.nonzero. At a million elements with half the mask selected, on an Apple M1 Pro,np.compressis about 6x faster than NumPy,np.putmaskandnp.copytoabout 18x to 20x, andnp.where(mask)about 3.4x. (#61)
Faster
np.clipandx.cliponfloat32andfloat64are much faster on small arrays when the bounds are Python numbers (or NumPy scalars of the array's own type) and there is noout: about 10x faster than NumPy at 16 elements on an Apple M1 Pro, where they used to gain nothing.x.argmax()andx.argmin()on arrays shorter than 128 elements are served by the kernels too: about 3x faster at 16 elements. (#64)
Compatibility
pip install hotkernelsnow works on any platform: a source distribution is published, which builds without a compiler where the kernels do not run and leavesinstall()doing nothing, and builds the kernels on an Apple Silicon Mac whose Python has no wheel.python -m hotkernels script.pyruns an unmodified script with hotkernels installed. (#31)- hotkernels now requires NumPy 2.3 or later. NumPy 2.0 to 2.2 answer
np.clip(the sign of a zero) andnp.count_nonzero(a Pythonintinstead ofnp.intp) differently from later releases, and with hotkernels installed those calls gave the later answer; on those releasesinstall()now does nothing andreport()says why. (#60) - hotkernels now runs on Linux x86-64, with a second set of kernels written for AVX2:
install()works on any processor with the x86-64-v3 instruction sets (Intel since 2013, AMD since 2015), and wheels are published for glibc Linux. On an Intel Core i5-14600KF at a million elements,np.sumonuint8is about 42x faster than NumPy,x[mask]onfloat32about 16x,np.cumsumonfloat32about 13x andnp.argmaxabout 1.8x;np.clipandx.astype(np.float32)are level with NumPy there, which already has vector loops for them. (#82)
hotkernels 0.1.0
hotkernels 0.1.0
Highlights
The first release of hotkernels. One line, hotkernels.install(), points NumPy at hand-written kernels for the calls where NumPy is slowest, and existing NumPy code runs faster with no other change. A call no kernel handles goes to NumPy exactly as before, and costs under a nanosecond more.
- 18 kernels for 13 NumPy operations are installed by default:
np.argmaxandnp.argmin,np.clip,x[mask]andx[mask] = v,np.nonzero,np.cumsumonint64,x.astype(np.float32)fromuint8,np.sumonuint8,np.count_nonzero,np.histogram,np.bincountandnp.isin.install(inexact=True)addsnp.cumsumonfloat32andfloat64, which are within a declared tolerance of NumPy rather than bit-identical. - From Python, at a million elements:
x[mask]onfloat32is 31.0x faster,x[mask] = 0.020.6x,np.sumonuint815.6x,np.cumsumonint6413.7x,np.histogram9.41x andnp.argmax8.90x. An unmodified example program,examples/workload.py, goes from 45.2 ms to 8.4 ms with the same results bit for bit. - Checked against NumPy itself. 70,031 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 47,234 tests.
print(hotkernels.report())shows what is installed and how often each kernel ran, so you can see whether your code reaches them.
Where it runs. macOS on Apple Silicon, Python 3.11 to 3.14, NumPy 2. Wheels are published for that platform only; there is no source distribution yet, so pip install hotkernels finds nothing elsewhere. On free-threaded Python install() does nothing and report() says why.
Measured on an Apple M1 Pro with NumPy 2.5.5 and Python 3.12.7, on a machine in use (load average about 3). Every statement at three sizes is in delivery/results/apple-m1-pro.md.
Other changes
hotkernels.__version__gives the installed release, andprint(hotkernels.report())names it on its first line. (#28)