Open serge-sans-paille opened 4 years ago
steps to reproduce:
g++ specialconvolve.cpp `python-config --cflags --ldflags --libs` -I./.npb/include -std=c++14 -O2 -shared -o xtensor_specialconvolve.so
python -m timeit -s 'import numpy as np ; r = np.arange(100*10000, dtype=np.uint32).reshape(1000,1000); from xtensor_specialconvolve import specialconvolve' 'specialconvolve(r)'
ok, i spent a bit of time debugging this, and it's actually not a very deep issue.
The problem is that we're currently not defaulting to a static row_major
layout in the python arrays which makes things slow (because we don't do enough dynamic layout checking!).
I think if you change your code to ingest a pytensor<uint32_t, 2, xt::layout_type::row_major>
the speed should be roughly 1.5x faster than numpy (that's what I am seeing locally, with a pure C++ version of this benchmark) (~6.5ms for numpy, ~4ms for C++).
We should dispatch to the right assignment loops for dynamic layouts, too, though.
When benchmarking the following snippets, I have very surprising results:
vs.
I get