On Thu, Jul 28, 2011 at 9:58 AM, Hans Meine <me...@informatik.uni-hamburg.de > wrote:
> Hi again! > > Am Donnerstag, 21. Juli 2011, 16:56:21 schrieb Hans Meine: > > import numpy > > > > class Test(numpy.ndarray): > > pass > > > > a1 = numpy.ndarray((1,)) > > a2 = Test((1,)) > > > > assert type(a1.min()) == type(a2.min()), \ > > "%s != %s" % (type(a1.min()), type(a2.min())) > > # --------------------------------------------------- > > > > This code fails with 1.6.0, while it worked in 1.3.0. > > I just tried with 1.5.1 (Ubuntu natty), and it works, too. > > Thus, this behavor-incompatible change happened between 1.5.1 and 1.6.0. > I dug a little bit into the relevant 1.5.x vs 1.6.x code, in the places I would most suspect a change, but couldn't find anything obvious. Here's the ndarray.min method: https://github.com/numpy/numpy/blob/maintenance%2F1.5.x/numpy/core/src/multiarray/methods.c#L267 https://github.com/numpy/numpy/blob/maintenance%2F1.6.x/numpy/core/src/multiarray/methods.c#L257 it calls PyArray_Min, which is here: https://github.com/numpy/numpy/blob/maintenance%2F1.5.x/numpy/core/src/multiarray/calculation.c#L208 https://github.com/numpy/numpy/blob/maintenance%2F1.6.x/numpy/core/src/multiarray/calculation.c#L208 this calls numpy.minimum.reduce, which ends up here: https://github.com/numpy/numpy/blob/maintenance%2F1.5.x/numpy/core/src/umath/ufunc_object.c#L3194 https://github.com/numpy/numpy/blob/maintenance%2F1.6.x/numpy/core/src/umath/ufunc_object.c#L3851 This function calls PyArray_Return(ret), which is how things get converted into the NumPy scalars: https://github.com/numpy/numpy/blob/maintenance%2F1.5.x/numpy/core/src/umath/ufunc_object.c#L3365 https://github.com/numpy/numpy/blob/maintenance%2F1.6.x/numpy/core/src/umath/ufunc_object.c#L4019 Here's the code for PyArray_Return, which was unchanged: https://github.com/numpy/numpy/blob/maintenance%2F1.5.x/numpy/core/src/multiarray/scalarapi.c#L729 https://github.com/numpy/numpy/blob/maintenance%2F1.6.x/numpy/core/src/multiarray/scalarapi.c#L793 Something more subtle is going on. I don't have the time to dig into this more at the moment, but hopefully these pointers into the code can help anyone out there who has the time to investigate further. We definitely need to add some tests for the desired behavior here. Cheers, -Mark > > > I tend to think that this is a bug (after all, a1.min() does not return > > ndarray, but an array scalar), but maybe there is also a good reason for > > this (for us, unexpected) behavor change and a nice solution? > > Unfortunately, I did not receive any answers so far. > > Have a nice day, > Hans > _______________________________________________ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion >
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion