On Tue, Jan 24, 2012 at 4:33 PM, Mark Wiebe <mwwiebe@gmail.com> wrote:
2012/1/21 Ondřej Čertík <ondrej.certik@gmail.com>
<snip>
Let me know if you figure out something. I think the "mask" thing is quite slow, but the problem is that it needs to be there, to catch overflows (and it is there in Fortran as well, see the "where" statement, which does the same thing). Maybe there is some other way to write the same thing in NumPy?
In the current master, you can replace
z[mask] *= z[mask] z[mask] += c[mask] with np.multiply(z, z, out=z, where=mask) np.add(z, c, out=z, where=mask)
I am getting: Traceback (most recent call last): File "b.py", line 19, in <module> np.multiply(z, z, out=z, where=mask) TypeError: 'where' is an invalid keyword to ufunc 'multiply' I assume it is a new feature in numpy?
The performance of this alternate syntax is still not great, but it is significantly faster than what it replaces. For a particular choice of mask, I get
In [40]: timeit z[mask] *= z[mask]
10 loops, best of 3: 29.1 ms per loop
In [41]: timeit np.multiply(z, z, out=z, where=mask)
100 loops, best of 3: 4.2 ms per loop
That looks like 7x faster to me. If it works for you, can you run the mandelbrot example with and without your patch? That way we'll know the actual speedup. Ondrej