[Numpy-discussion] The NumPy Mandelbrot code 16x slower than Fortran
Wed Jan 25 20:56:31 CST 2012
On Tue, Jan 24, 2012 at 4:33 PM, Mark Wiebe <firstname.lastname@example.org> wrote:
> 2012/1/21 Ondřej Čertík <email@example.com>
>> 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]
> 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 : timeit z[mask] *= z[mask]
> 10 loops, best of 3: 29.1 ms per loop
> In : 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.
More information about the NumPy-Discussion