[Numpy-discussion] np.any and np.all short-circuiting

Charles R Harris charlesr.harris@gmail....
Thu Sep 24 17:07:18 CDT 2009


On Thu, Sep 24, 2009 at 3:43 PM, Citi, Luca <lciti@essex.ac.uk> wrote:

> Hello
> I noticed that python's "any" can be faster than numpy's "any" (and the
> similarly for "all").
> Then I wondered why.
> I realized that numpy implements "any" as logical_or.reduce (and "all" as
> logical_and.reduce).
> This means that numpy cannot take advantage of short-circuiting.
> Looking at the timings confirmed my suspects.
> I think python fetches one element at the time from the array and as soon
> as any of them is true it returns true.
> Instead, numpy goes on until the end of the array even if the very first
> element is already true.
> Looking at the code I think I found a way to fix it.
> I don't see a reason why it should not work. It seems to work. But you
> never know.
> I wanted to run the test suite.
> I am unable to run the test on the svn version, neither from
> .../build/lib... nor form a different folder using sys.path.insert(0,
> '.../build/lib...').
> In the first case I get "NameError: name 'numeric' is not defined"
> while in the second case zero tests are successfully performed :-)
> What is the correct way of running the tests (without installing the
> development version in the system)?
> Is there some expert of the inner numpy core able to tell whether the
> approach is correct and won't break something?
> I opened a ticket for this:
> http://projects.scipy.org/numpy/ticket/1237
> Best,
> Luca
>
>
Did you delete your build directory first?

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090924/0bafac27/attachment.html 


More information about the NumPy-Discussion mailing list