[Numpy-discussion] np.any and np.all short-circuiting
Charles R Harris
Thu Sep 24 17:07:18 CDT 2009
On Thu, Sep 24, 2009 at 3:43 PM, Citi, Luca <email@example.com> wrote:
> 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
> 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,
> 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:
Did you delete your build directory first?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion