.max(0) on reshaped array returns inconsistent results.

I'm seeing some strange behavior from .max() on a reshaped array in the current master, and wanted to raise it here to make sure it's not something uniquely broken in my setup.
This code fails for me, though changing the context (adding a counter to the loop, or running under "python -i") sometimes prevents it from failing. This code doesn't fail under 1.6.2.
--------------- import numpy as np
b = np.array([0, 1, 2, 3, 4, 5], np.int64) a = b.reshape(3, 2)
while True: np.testing.assert_array_equal(np.atleast_1d(np.array(a.max(0), np.float)), np.atleast_1d(np.array(a.max(0), np.float))) ---------------
I spent several hours with valgrind trying to track down what was causing this, but had no luck. Perhaps someone with more knowledge of the numpy ufunc internals can track it down faster than me.
I went ahead and filed a bug for it: http://projects.scipy.org/numpy/ticket/2144

On Fri, May 25, 2012 at 12:46 PM, Thouis (Ray) Jones thouis@gmail.com wrote:
I'm seeing some strange behavior from .max() on a reshaped array in the current master, and wanted to raise it here to make sure it's not something uniquely broken in my setup.
This code fails for me, though changing the context (adding a counter to the loop, or running under "python -i") sometimes prevents it from failing. This code doesn't fail under 1.6.2.
import numpy as np
b = np.array([0, 1, 2, 3, 4, 5], np.int64) a = b.reshape(3, 2)
while True: np.testing.assert_array_equal(np.atleast_1d(np.array(a.max(0), np.float)), np.atleast_1d(np.array(a.max(0), np.float)))
I spent several hours with valgrind trying to track down what was causing this, but had no luck. Perhaps someone with more knowledge of the numpy ufunc internals can track it down faster than me.
What do you get, if not the expected value? And are the calls to atleast_1d, np.array, etc., necessary to trigger the problem, or will just plain a.max(0) do it?
-- Nathaniel

On Fri, May 25, 2012 at 1:52 PM, Nathaniel Smith njs@pobox.com wrote:
On Fri, May 25, 2012 at 12:46 PM, Thouis (Ray) Jones thouis@gmail.com wrote:
I'm seeing some strange behavior from .max() on a reshaped array in the current master, and wanted to raise it here to make sure it's not something uniquely broken in my setup.
This code fails for me, though changing the context (adding a counter to the loop, or running under "python -i") sometimes prevents it from failing. This code doesn't fail under 1.6.2.
import numpy as np
b = np.array([0, 1, 2, 3, 4, 5], np.int64) a = b.reshape(3, 2)
while True: np.testing.assert_array_equal(np.atleast_1d(np.array(a.max(0), np.float)), np.atleast_1d(np.array(a.max(0), np.float)))
I spent several hours with valgrind trying to track down what was causing this, but had no luck. Perhaps someone with more knowledge of the numpy ufunc internals can track it down faster than me.
What do you get, if not the expected value? And are the calls to atleast_1d, np.array, etc., necessary to trigger the problem, or will just plain a.max(0) do it?
AssertionError: Arrays are not equal (mismatch 100.0%) x: array([ 4., 5.]) y: array([ 4.31441533e+09, 4.31441402e+09])
I don't seem to be able to reproduce with just a.max(0) or np.array(a.max(0), np.float), but since it seems to be very unstable to other changes in the code, I'll keep trying to find out if I can make those simpler versions crash.
Ray Jones

On Fri, May 25, 2012 at 2:07 PM, Thouis Jones thouis.jones@curie.fr wrote:
I don't seem to be able to reproduce with just a.max(0) or np.array(a.max(0), np.float), but since it seems to be very unstable to other changes in the code, I'll keep trying to find out if I can make those simpler versions crash.
By the way, the strange phrasing comes from these lines in histogramdd(): smin = atleast_1d(array(sample.min(0), float)) smax = atleast_1d(array(sample.max(0), float))
Which is where I encountered the bug in the numpy tests.
Ray Jones

I've bisected it down to this commit: https://github.com/numpy/numpy/commit/aed9925a9d5fe9a407d0ca2c65cb577116c4d0...
This exercises it consistently for me: while True; do python -m nose.core ../numpy.bisect/numpy/lib/tests/test_function_base.py:TestHistogramdd --pdb --pdb-failures; done
It happens at HEAD in Nathan's separate-maskna branch, as well.
Ray Jones

On May 25, 2012 5:30 PM, "Thouis (Ray) Jones" thouis@gmail.com wrote:
It happens at HEAD in Nathan's separate-maskna branch, as well.
Sorry, Nathaniel's branch. My fingers went into autopilot.
Ray

25.05.2012 13:46, Thouis (Ray) Jones kirjoitti:
I'm seeing some strange behavior from .max() on a reshaped array in the current master, and wanted to raise it here to make sure it's not something uniquely broken in my setup.
This code fails for me, though changing the context (adding a counter to the loop, or running under "python -i") sometimes prevents it from failing. This code doesn't fail under 1.6.2.
Try using "git bisect" to find the the first failing commit:
1. git bisect start master v1.6.2
2. Rebuild, and run test
3. Pick one of the following according to the result:
git bisect good # test OK git bisect bad # test fails with this error git bisect skip # doesn't build, or some other error
4. Goto 2, until Git tells you what's the first bad commit.
Abort with "git bisect reset".
If you are on unix, the following rig can help automate this: https://github.com/pv/scipy-build-makefile
participants (4)
-
Nathaniel Smith
-
Pauli Virtanen
-
Thouis (Ray) Jones
-
Thouis Jones