On Thu, May 20, 2010 at 12:10 AM, Dag Sverre Seljebotn < [email protected]> wrote:
> Yes, the NumPy functions are a bit strange regarding references, but the > ones you use don't take any Python objects so you're safe. It all looks > good to me. > > What's performance hit do you get from the extra check, is it noticeable? > > The hit is really minimal for me. In [5]: timeit test.quadruple(x, out) 1000000 loops, best of 3: 811 ns per loop In [6]: timeit test.quadruple2(x, out) 1000000 loops, best of 3: 798 ns per loop Where quadruple2 had the "if out is None" check and empty array creation commented out. Of course, having to create the array did cause a slowdown. In [7]: timeit test.quadruple(x) 1000000 loops, best of 3: 1.3 us per loop But even then it wasn't much. Perhaps it will scale differently. > out = PyArray_EMPTY(1, <npy_intp *>(&x.shape[0]), > > NPY_DOUBLE, 0) > It's a bit more readable to simply pass "x.shape" without &..[0] and the > cast, you should be able to do that. > > Aha. Thanks again for all your help. There is no way I would have done this so quickly, easily otherwise.
_______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
