Oven logo

Oven

numbagg0.9.2

Published

Fast N-dimensional aggregation functions with Numba

pip install numbagg

Package Downloads

Weekly DownloadsMonthly Downloads

Project URLs

Requires Python

>=3.9

Dependencies

Numbagg: Fast N-dimensional aggregation functions with Numba

GitHub Workflow CI Status PyPI Version

Fast, flexible N-dimensional array functions written with Numba and NumPy's generalized ufuncs.

Why use numbagg?

Performance

  • Outperforms pandas
    • On a single core, 2-10x faster for moving window functions, 1-2x faster for aggregation and grouping functions
    • When parallelizing with multiple cores, 4-30x faster
  • Outperforms bottleneck on multiple cores
    • On a single core, matches bottleneck
    • When parallelizing with multiple cores, 3-7x faster
  • Outperforms numpy on multiple cores
    • On a single core, matches numpy
    • When parallelizing with multiple cores, 5-15x faster
  • ...though numbagg's functions are JIT compiled, so the first run is much slower

Versatility

  • More functions (though bottleneck has some functions we don't have, and pandas' functions have many more parameters)
  • Functions work for >3 dimensions with flexible axis handling (see Axis Parameter Behavior below)
  • Written in numba — way less code, simple to inspect, simple to improve

Functions & benchmarks

Summary benchmark

Two benchmarks summarize numbagg's performance — the first with a 1D array of 10M elements without parallelization, and a second with a 2D array of 100x10K elements with parallelization1. Numbagg's relative performance is much higher where parallelization is possible. A wider range of arrays is listed in the full set of benchmarks below.

The values in the table are numbagg's performance as a multiple of other libraries for a given shaped array calculated over the final axis. (so 1.00x means numbagg is equal, higher means numbagg is faster.)

func1D
pandas
1D
bottleneck
1D
numpy
2D
pandas
2D
bottleneck
2D
numpy
bfill1.06x1.13xn/a11.11x5.04xn/a
ffill1.12x0.99xn/a11.50x4.25xn/a
group_nanall1.38xn/an/a7.77xn/an/a
group_nanany1.12xn/an/a6.21xn/an/a
group_nanargmax1.16xn/an/a6.81xn/an/a
group_nanargmin1.17xn/an/a6.48xn/an/a
group_nancount1.05xn/an/a4.94xn/an/a
group_nanfirst1.52xn/an/a11.13xn/an/a
group_nanlast1.12xn/an/a5.56xn/an/a
group_nanmax1.13xn/an/a5.13xn/an/a
group_nanmean1.14xn/an/a5.61xn/an/a
group_nanmin1.12xn/an/a5.75xn/an/a
group_nanprod1.15xn/an/a5.25xn/an/a
group_nanstd1.14xn/an/a5.41xn/an/a
group_nansum_of_squares1.33xn/an/a8.00xn/an/a
group_nansum1.18xn/an/a5.63xn/an/a
group_nanvar1.13xn/an/a4.88xn/an/a
move_corr16.42xn/an/a115.76xn/an/a
move_cov12.30xn/an/a86.56xn/an/a
move_exp_nancorr6.65xn/an/a46.98xn/an/a
move_exp_nancount1.88xn/an/a9.95xn/an/a
move_exp_nancov6.53xn/an/a43.63xn/an/a
move_exp_nanmean1.61xn/an/a10.65xn/an/a
move_exp_nanstd1.76xn/an/a12.40xn/an/a
move_exp_nansum1.09xn/an/a9.01xn/an/a
move_exp_nanvar1.77xn/an/a11.41xn/an/a
move_mean6.03x1.34xn/a26.60x6.25xn/a
move_std4.76x0.89xn/a29.09x6.24xn/a
move_sum5.16x1.13xn/a24.02x6.10xn/a
move_var5.45x1.05xn/a29.54x6.05xn/a
nanargmax22.40x0.53xn/a2.32x0.93xn/a
nanargmin22.35x0.50xn/a2.53x1.00xn/a
nancount2.01xn/a1.59x12.26xn/a3.96x
nanmax23.15x0.50x0.09x3.59x3.24x0.09x
nanmean3.00x1.01x3.82x18.98x5.04x19.33x
nanmin23.07x0.50x0.09x3.39x3.03x0.09x
nanquantile0.69xn/a0.53x4.94xn/a4.33x
nanstd1.63x1.61x3.39x12.39x10.18x22.03x
nansum2.48x0.94x3.31x20.47x4.65x17.90x
nanvar1.61x1.65x3.40x12.62x10.49x22.13x

Full benchmarks

funcshapesizendimpandasbottlenecknumpynumbaggpandas_ratiobottleneck_rationumpy_rationumbagg_ratio
bfill(1000,)100010ms0msn/a0ms0.38x0.01xn/a1.00x
(10000000,)10000000115ms16msn/a14ms1.06x1.13xn/a1.00x
(100, 100000)10000000237ms17msn/a3ms11.11x5.04xn/a1.00x
(10, 10, 10, 10, 1000)100000005n/a18msn/a3msn/a6.13xn/a1.00x
(100, 1000, 1000)1000000003n/a199msn/a31msn/a6.44xn/a1.00x
ffill(1000,)100010ms0msn/a0ms0.37x0.01xn/a1.00x
(10000000,)10000000115ms14msn/a14ms1.12x0.99xn/a1.00x
(100, 100000)10000000237ms14msn/a3ms11.50x4.25xn/a1.00x
(10, 10, 10, 10, 1000)100000005n/a14msn/a3msn/a4.64xn/a1.00x
(100, 1000, 1000)1000000003n/a176msn/a31msn/a5.72xn/a1.00x
group_nanall(1000,)100010msn/an/a0ms0.72xn/an/a1.00x
(10000000,)10000000148msn/an/a35ms1.38xn/an/a1.00x
(100, 100000)10000000218msn/an/a2ms7.77xn/an/a1.00x
(10, 10, 10, 10, 1000)100000005n/an/an/a1msn/an/an/a1.00x
group_nanany(1000,)100010msn/an/a0ms0.70xn/an/a1.00x
(10000000,)10000000149msn/an/a44ms1.12xn/an/a1.00x
(100, 100000)10000000218msn/an/a3ms6.21xn/an/a1.00x
(10, 10, 10, 10, 1000)100000005n/an/an/a2msn/an/an/a1.00x
group_nanargmax(1000,)100010msn/an/a0ms1.07xn/an/a1.00x
(10000000,)10000000149msn/an/a42ms1.16xn/an/a1.00x
(100, 100000)10000000217msn/an/a3ms6.81xn/an/a1.00x
(10, 10, 10, 10, 1000)100000005n/an/an/a2msn/an/an/a1.00x
group_nanargmin(1000,)100010msn/an/a0ms1.06xn/an/a1.00x
(10000000,)10000000149msn/an/a42ms1.17xn/an/a1.00x
(100, 100000)10000000217msn/an/a3ms6.48xn/an/a1.00x
(10, 10, 10, 10, 1000)100000005n/an/an/a2msn/an/an/a1.00x
group_nancount(1000,)100010msn/an/a0ms0.66xn/an/a1.00x
(10000000,)10000000144msn/an/a42ms1.05xn/an/a1.00x
(100, 100000)10000000213msn/an/a3ms4.94xn/an/a1.00x
(10, 10, 10, 10, 1000)100000005n/an/an/a1msn/an/an/a1.00x
group_nanfirst(1000,)100010msn/an/a0ms0.73xn/an/a1.00x
(10000000,)10000000152msn/an/a34ms1.52xn/an/a1.00x
(100, 100000)10000000216msn/an/a1ms11.13xn/an/a1.00x
(10, 10, 10, 10, 1000)100000005n/an/an/a1msn/an/an/a1.00x
group_nanlast(1000,)100010msn/an/a0ms0.72xn/an/a1.00x
(10000000,)10000000147msn/an/a42ms1.12xn/an/a1.00x
(100, 100000)10000000214msn/an/a2ms5.56xn/an/a1.00x
(10, 10, 10, 10, 1000)100000005n/an/an/a1msn/an/an/a1.00x
group_nanmax(1000,)100010msn/an/a0ms0.71xn/an/a1.00x
(10000000,)10000000148msn/an/a43ms1.13xn/an/a1.00x
(100, 100000)10000000214msn/an/a3ms5.13xn/an/a1.00x
(10, 10, 10, 10, 1000)100000005n/an/an/a2msn/an/an/a1.00x
group_nanmean(1000,)100010msn/an/a0ms0.72xn/an/a1.00x
(10000000,)10000000150msn/an/a44ms1.14xn/an/a1.00x
(100, 100000)10000000216msn/an/a3ms5.61xn/an/a1.00x
(10, 10, 10, 10, 1000)100000005n/an/an/a2msn/an/an/a1.00x
group_nanmin(1000,)100010msn/an/a0ms0.73xn/an/a1.00x
(10000000,)10000000148msn/an/a43ms1.12xn/an/a1.00x
(100, 100000)10000000214msn/an/a2ms5.75xn/an/a1.00x
(10, 10, 10, 10, 1000)100000005n/an/an/a2msn/an/an/a1.00x
group_nanprod(1000,)100010msn/an/a0ms0.70xn/an/a1.00x
(10000000,)10000000148msn/an/a42ms1.15xn/an/a1.00x
(100, 100000)10000000214msn/an/a3ms5.25xn/an/a1.00x
(10, 10, 10, 10, 1000)100000005n/an/an/a1msn/an/an/a1.00x
group_nanstd(1000,)100010msn/an/a0ms0.71xn/an/a1.00x
(10000000,)10000000151msn/an/a45ms1.14xn/an/a1.00x
(100, 100000)10000000217msn/an/a3ms5.41xn/an/a1.00x
(10, 10, 10, 10, 1000)100000005n/an/an/a2msn/an/an/a1.00x
group_nansum(1000,)100010msn/an/a0ms0.74xn/an/a1.00x
(10000000,)10000000151msn/an/a43ms1.18xn/an/a1.00x
(100, 100000)10000000216msn/an/a3ms5.63xn/an/a1.00x
(10, 10, 10, 10, 1000)100000005n/an/an/a2msn/an/an/a1.00x
group_nanvar(1000,)100010msn/an/a0ms0.70xn/an/a1.00x
(10000000,)10000000151msn/an/a45ms1.13xn/an/a1.00x
(100, 100000)10000000216msn/an/a3ms4.88xn/an/a1.00x
(10, 10, 10, 10, 1000)100000005n/an/an/a2msn/an/an/a1.00x
group_nansum_of_squares(1000,)100010msn/an/a0ms0.88xn/an/a1.00x
(10000000,)10000000157msn/an/a43ms1.33xn/an/a1.00x
(100, 100000)10000000222msn/an/a3ms8.00xn/an/a1.00x
(10, 10, 10, 10, 1000)100000005n/an/an/a1msn/an/an/a1.00x
move_corr(1000,)100010msn/an/a0ms2.68xn/an/a1.00x
(10000000,)100000001710msn/an/a43ms16.42xn/an/a1.00x
(100, 100000)100000002683msn/an/a6ms115.76xn/an/a1.00x
(10, 10, 10, 10, 1000)100000005n/an/an/a5msn/an/an/a1.00x
(100, 1000, 1000)1000000003n/an/an/a49msn/an/an/a1.00x
move_cov(1000,)100010msn/an/a0ms2.43xn/an/a1.00x
(10000000,)100000001490msn/an/a40ms12.30xn/an/a1.00x
(100, 100000)100000002460msn/an/a5ms86.56xn/an/a1.00x
(10, 10, 10, 10, 1000)100000005n/an/an/a4msn/an/an/a1.00x
(100, 1000, 1000)1000000003n/an/an/a44msn/an/an/a1.00x
move_mean(1000,)100010ms0msn/a0ms0.46x0.01xn/a1.00x
(10000000,)10000000192ms21msn/a15ms6.03x1.34xn/a1.00x
(100, 100000)10000000288ms21msn/a3ms26.60x6.25xn/a1.00x
(10, 10, 10, 10, 1000)100000005n/a20msn/a3msn/a6.66xn/a1.00x
(100, 1000, 1000)1000000003n/a228msn/a32msn/a7.12xn/a1.00x
move_std(1000,)100010ms0msn/a0ms0.53x0.02xn/a1.00x
(10000000,)100000001141ms26msn/a30ms4.76x0.89xn/a1.00x
(100, 100000)100000002123ms26msn/a4ms29.09x6.24xn/a1.00x
(10, 10, 10, 10, 1000)100000005n/a26msn/a4msn/a7.37xn/a1.00x
(100, 1000, 1000)1000000003n/a291msn/a37msn/a7.82xn/a1.00x
move_sum(1000,)100010ms0msn/a0ms0.46x0.01xn/a1.00x
(10000000,)10000000195ms21msn/a18ms5.16x1.13xn/a1.00x
(100, 100000)10000000283ms21msn/a3ms24.02x6.10xn/a1.00x
(10, 10, 10, 10, 1000)100000005n/a21msn/a3msn/a6.79xn/a1.00x
(100, 1000, 1000)1000000003n/a227msn/a31msn/a7.29xn/a1.00x
move_var(1000,)100010ms0msn/a0ms0.50x0.02xn/a1.00x
(10000000,)100000001131ms25msn/a24ms5.45x1.05xn/a1.00x
(100, 100000)100000002122ms25msn/a4ms29.54x6.05xn/a1.00x
(10, 10, 10, 10, 1000)100000005n/a25msn/a4msn/a7.12xn/a1.00x
(100, 1000, 1000)1000000003n/a275msn/a36msn/a7.69xn/a1.00x
move_exp_nancorr(1000,)100010msn/an/a0ms2.33xn/an/a1.00x
(10000000,)100000001344msn/an/a52ms6.65xn/an/a1.00x
(100, 100000)100000002338msn/an/a7ms46.98xn/an/a1.00x
(10, 10, 10, 10, 1000)100000005n/an/an/a6msn/an/an/a1.00x
(100, 1000, 1000)1000000003n/an/an/a55msn/an/an/a1.00x
move_exp_nancount(1000,)100010msn/an/a0ms0.57xn/an/a1.00x
(10000000,)10000000151msn/an/a27ms1.88xn/an/a1.00x
(100, 100000)10000000247msn/an/a5ms9.95xn/an/a1.00x
(10, 10, 10, 10, 1000)100000005n/an/an/a4msn/an/an/a1.00x
(100, 1000, 1000)1000000003n/an/an/a40msn/an/an/a1.00x
move_exp_nancov(1000,)100010msn/an/a0ms2.19xn/an/a1.00x
(10000000,)100000001215msn/an/a33ms6.53xn/an/a1.00x
(100, 100000)100000002234msn/an/a5ms43.63xn/an/a1.00x
(10, 10, 10, 10, 1000)100000005n/an/an/a5msn/an/an/a1.00x
(100, 1000, 1000)1000000003n/an/an/a43msn/an/an/a1.00x
move_exp_nanmean(1000,)100010msn/an/a0ms0.39xn/an/a1.00x
(10000000,)10000000147msn/an/a30ms1.61xn/an/a1.00x
(100, 100000)10000000252msn/an/a5ms10.65xn/an/a1.00x
(10, 10, 10, 10, 1000)100000005n/an/an/a4msn/an/an/a1.00x
(100, 1000, 1000)1000000003n/an/an/a43msn/an/an/a1.00x
move_exp_nanstd(1000,)100010msn/an/a0ms0.68xn/an/a1.00x
(10000000,)10000000164msn/an/a36ms1.76xn/an/a1.00x
(100, 100000)10000000274msn/an/a6ms12.40xn/an/a1.00x
(10, 10, 10, 10, 1000)100000005n/an/an/a5msn/an/an/a1.00x
(100, 1000, 1000)1000000003n/an/an/a44msn/an/an/a1.00x
move_exp_nansum(1000,)100010msn/an/a0ms0.38xn/an/a1.00x
(10000000,)10000000136msn/an/a33ms1.09xn/an/a1.00x
(100, 100000)10000000243msn/an/a5ms9.01xn/an/a1.00x
(10, 10, 10, 10, 1000)100000005n/an/an/a4msn/an/an/a1.00x
(100, 1000, 1000)1000000003n/an/an/a42msn/an/an/a1.00x
move_exp_nanvar(1000,)100010msn/an/a0ms0.40xn/an/a1.00x
(10000000,)10000000156msn/an/a32ms1.77xn/an/a1.00x
(100, 100000)10000000264msn/an/a6ms11.41xn/an/a1.00x
(10, 10, 10, 10, 1000)100000005n/an/an/a4msn/an/an/a1.00x
(100, 1000, 1000)1000000003n/an/an/a46msn/an/an/a1.00x
nanargmax2(1000,)100010ms0msn/a0ms17.65x0.17xn/a1.00x
(10000000,)10000000124ms5msn/a10ms2.40x0.53xn/a1.00x
(100, 100000)10000000225ms10msn/a11ms2.32x0.93xn/a1.00x
(10, 10, 10, 10, 1000)100000005n/a11msn/a11msn/a1.00xn/a1.00x
(100, 1000, 1000)1000000003n/a107msn/a108msn/a0.99xn/a1.00x
nanargmin2(1000,)100010ms0msn/a0ms17.72x0.17xn/a1.00x
(10000000,)10000000125ms5msn/a11ms2.35x0.50xn/a1.00x
(100, 100000)10000000225ms10msn/a10ms2.53x1.00xn/a1.00x
(10, 10, 10, 10, 1000)100000005n/a11msn/a11msn/a1.00xn/a1.00x
(100, 1000, 1000)1000000003n/a108msn/a108msn/a1.00xn/a1.00x
nancount(1000,)100010msn/a0ms0ms0.77xn/a0.02x1.00x
(10000000,)1000000013msn/a3ms2ms2.01xn/a1.59x1.00x
(100, 100000)1000000028msn/a3ms1ms12.26xn/a3.96x1.00x
(10, 10, 10, 10, 1000)100000005n/an/a3ms1msn/an/a3.97x1.00x
(100, 1000, 1000)1000000003n/an/a33ms7msn/an/a5.07x1.00x
nanmax2(1000,)100010ms0ms0ms0ms11.07x0.17x0.55x1.00x
(10000000,)10000000132ms5ms1ms10ms3.15x0.50x0.09x1.00x
(100, 100000)10000000236ms33ms1ms10ms3.59x3.24x0.09x1.00x
(10, 10, 10, 10, 1000)100000005n/a32ms1ms10msn/a3.24x0.10x1.00x
(100, 1000, 1000)1000000003n/a320ms11ms98msn/a3.26x0.11x1.00x
nanmean(1000,)100010ms0ms0ms0ms0.39x0.00x0.05x1.00x
(10000000,)10000000117ms6ms21ms6ms3.00x1.01x3.82x1.00x
(100, 100000)10000000221ms5ms21ms1ms18.98x5.04x19.33x1.00x
(10, 10, 10, 10, 1000)100000005n/a5ms21ms1msn/a6.10x23.77x1.00x
(100, 1000, 1000)1000000003n/a54ms258ms8msn/a7.00x33.59x1.00x
nanmin2(1000,)100010ms0ms0ms0ms10.86x0.17x0.55x1.00x
(10000000,)10000000133ms5ms1ms11ms3.07x0.50x0.09x1.00x
(100, 100000)10000000236ms32ms1ms11ms3.39x3.03x0.09x1.00x
(10, 10, 10, 10, 1000)100000005n/a32ms1ms10msn/a3.12x0.10x1.00x
(100, 1000, 1000)1000000003n/a320ms11ms102msn/a3.12x0.11x1.00x
nanquantile(1000,)100010msn/a0ms0ms0.56xn/a0.21x1.00x
(10000000,)100000001114msn/a87ms164ms0.69xn/a0.53x1.00x
(100, 100000)100000002131msn/a115ms27ms4.94xn/a4.33x1.00x
(10, 10, 10, 10, 1000)100000005n/an/a315ms19msn/an/a16.51x1.00x
(100, 1000, 1000)1000000003n/an/a3118ms165msn/an/a18.88x1.00x
nanstd(1000,)100010ms0ms0ms0ms0.31x0.02x0.14x1.00x
(10000000,)10000000121ms20ms43ms13ms1.63x1.61x3.39x1.00x
(100, 100000)10000000224ms20ms43ms2ms12.39x10.18x22.03x1.00x
(10, 10, 10, 10, 1000)100000005n/a20ms46ms1msn/a14.17x32.66x1.00x
(100, 1000, 1000)1000000003n/a202ms513ms13msn/a16.08x40.78x1.00x
nansum(1000,)100010ms0ms0ms0ms0.46x0.01x0.03x1.00x
(10000000,)10000000114ms5ms19ms6ms2.48x0.94x3.31x1.00x
(100, 100000)10000000222ms5ms19ms1ms20.47x4.65x17.90x1.00x
(10, 10, 10, 10, 1000)100000005n/a5ms20ms1msn/a6.21x22.95x1.00x
(100, 1000, 1000)1000000003n/a53ms226ms8msn/a6.98x29.90x1.00x
nanvar(1000,)100010ms0ms0ms0ms0.32x0.02x0.13x1.00x
(10000000,)10000000121ms21ms44ms13ms1.61x1.65x3.40x1.00x
(100, 100000)10000000225ms21ms43ms2ms12.62x10.49x22.13x1.00x
(10, 10, 10, 10, 1000)100000005n/a20ms46ms1msn/a14.02x32.28x1.00x
(100, 1000, 1000)1000000003n/a202ms503ms13msn/a15.68x38.98x1.00x

345621

Axis parameter behavior

The axis parameter in numbagg has three different behaviors depending on the function type:

Aggregation functions

Includes: nanmean, nansum, nanstd, nanvar, nanmin, nanmax, nancount, nanargmin, nanargmax, nanquantile, allnan, anynan

  • Specify dimensions to reduce/aggregate over
  • Support multiple axes, e.g. axis=(0, 1)
  • Remove the specified dimensions from output shape
# Example with 3D array
arr = np.random.rand(4, 3, 5)
result = nb.nanmean(arr, axis=(0, 2))  # Reduces over dimensions 0 and 2
# result.shape is (3,)

Moving window functions

Includes: move_mean, move_sum, move_std, move_var, move_corr, move_cov, and exponential variants like move_exp_nanmean

  • Specify the dimension along which the window moves
  • Single axis only
  • Preserve input shape
# Moving average along axis 1
arr = np.random.rand(4, 3, 5)
result = nb.move_mean(arr, window=2, axis=1)
# result.shape is (4, 3, 5) - same as input

Grouped functions

Includes: group_nanmean, group_nansum, group_nanstd, group_nanvar, group_nanmin, group_nanmax, and others

  • Specify dimension along which groups are defined
  • Single axis only
  • Group consecutive identical labels along the axis
# Group operations along axis 0
arr = np.random.rand(4, 3, 5)
labels = np.array([0, 0, 1, 1])  # Groups for axis 0
result = nb.group_nanmean(arr, labels, axis=0)
# result.shape is (2, 3, 5) - 2 groups along axis 0

Aggregation functions are compatible with NumPy's axis parameter behavior, while moving window and grouped functions provide functionality not available in NumPy.

Matrix functions

Includes: nancorrmatrix, nancovmatrix (static), and move_corrmatrix, move_covmatrix, move_exp_nancorrmatrix, move_exp_nancovmatrix (moving)

Matrix functions use different dimension conventions:

  • Static matrix functions (nancorrmatrix, nancovmatrix): expect (..., vars, obs)(..., vars, vars)
  • Moving matrix functions (move_corrmatrix, move_covmatrix, move_exp_nancorrmatrix, move_exp_nancovmatrix): expect (..., obs, vars)(..., obs, vars, vars)

The different conventions follow a simple principle: dimensions should only be added or removed at the end of the array shape. Static functions both remove (the obs dimension) and add (a second vars dimension), so they need obs at the end. Moving functions only add (a second vars dimension), so they can keep the natural time-series ordering with obs before vars.

Example implementation

Numbagg makes it easy to write, in pure Python/NumPy, flexible aggregation functions accelerated by Numba. All the hard work is done by Numba's JIT compiler and NumPy's gufunc machinery (as wrapped by Numba).

For example, here is how we wrote nansum:

import numpy as np
from numbagg.decorators import ndreduce


@ndreduce.wrap()
def nansum(a):
    asum = 0.0
    for ai in a.flat:
        if not np.isnan(ai):
            asum += ai
    return asum

Implementation details

Numbagg includes somewhat awkward workarounds for features missing from NumPy/Numba:

  • It implements its own cache for functions wrapped by Numba's guvectorize, because that decorator is rather slow.
  • It does its own handling of array transposes to handle the axis argument in reduction functions.
  • It rewrites plain functions into gufuncs, to allow writing a traditional function while retaining the multidimensional advantages of gufuncs.

Already some of the ideas here have flowed upstream to numba (for example, an axis parameter), and we hope that others will follow.

License

3-clause BSD. Includes portions of Bottleneck, which is distributed under a Simplified BSD license.

Footnotes

  1. Matrix functions (correlation/covariance matrices) use different array shapes in the summary benchmark: their largest 2D shape appears in the 1D column and their largest 3D shape appears in the 2D column to demonstrate parallelization across multiple independent matrices. 2

  2. This function is not currently parallelized, so exhibits worse performance on parallelizable arrays. 2 3 4 5 6 7 8 9

  3. Benchmarks were run on a Mac M3 Max laptop in September 2024 on numbagg's HEAD, pandas 2.2.2, bottleneck 1.4.0 numpy 2.0.1, with python numbagg/test/run_benchmarks.py -- --benchmark-max-time=10. They run in CI, though GHA's low CPU count means we don't see the full benefits of parallelization.

  4. While we separate the setup and the running of the functions, pandas still needs to do some work to create its result dataframe, and numbagg does some checks in python which bottleneck does in C or doesn't do. So use benchmarks on larger arrays for our summary so we can focus on the computational speed, which doesn't asymptote away. Any contributions to improve the benchmarks are welcome.

  5. In some instances, a library won't have the exact function — for example, pandas doesn't have an equivalent move_exp_nancount function, so we use its sum function on an array of 1s. Similarly for group_nansum_of_squares, we use two separate operations.

  6. anynan & allnan are also functions in numbagg, but not listed here as they require a different benchmark setup.