# import numpy # numpy.add.at(target, idx, vals) import fastfunc fastfunc.add.at(target, idx, vals) # If you really only need _add_, you can use # numpy.bincount(idx, weights=vals, minlength=target.shape)
to get a speed-up by a factor of 40.
This is achieved by moving the operations to C++ using pybind11.
fastfunc is available from the Python Package Index, so simply do
pip install -U fastfunc
to install or upgrade.
To run the fastfunc unit tests, check out this repository and type
fastfunc is published under the MIT license.