Re: [Numpy-discussion] Changes in PyArray_FromAny between 1.5.x and 1.6.x
On Tue, Jun 5, 2012 at 8:34 AM, Nathaniel Smith wrote: > I don't think that would work, because looking more closely, I don't > think they're actually doing anything like what > __array_interface__/PEP3118 are designed for. They just have some > custom class ("sage.rings.real_mpfr.RealLiteral", I guess an arbitrary > precision floating point of some sort?), and they want instances that > are passed to np.array() to be automatically coerced to another type > (float64) by default. But there's no buffer sharing or anything like > that going on at all. Mike, does that sound right? Yes, there's no buffer sharing going on at all. > This automagic coercion seems... in very dubious taste to me. (Why > does creating an array object imply that you want to throw away > precision? The __array_interface__ attribute is a property which depends on the precision of the ring. If it floats have enough precision, you just get floats; otherwise you get objects. > You can already throw away precision explicitly by doing > np.array(f, dtype=float).) But if this automatic coercion feature is > useful, then wouldn't it be better to have a different interface > instead of kluging it into __array_interface__, like we should check > for an attribute called __numpy_preferred_dtype__ or something? It isn't just the array() calls which end up getting problems. For example, in 1.5.x sage: f = 10; type(f) sage: numpy.arange(f) array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) #int64 while in 1.6.x sage: numpy.arange(f) array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=object) We also see problems with calls like sage: scipy.stats.uniform(0,15).ppf([0.5,0.7]) array([ 7.5, 10.5]) which work in 1.5.x, but fail with a traceback "TypeError: array cannot be safely cast to required type" in 1.6.x. --Mike ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Changes in PyArray_FromAny between 1.5.x and 1.6.x
On Mon, Jun 4, 2012 at 9:30 PM, Travis Oliphant wrote: > Can you raise an issue on the Github issue tracker for NumPy? These issues > will be looked at more closely. This kind of change should not have made it > in to the release. Thanks Travis! I've made this https://github.com/numpy/numpy/issues/291 --Mike ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Changes in PyArray_FromAny between 1.5.x and 1.6.x
On Mon, May 28, 2012 at 3:15 AM, Mike Hansen wrote: > In trying to upgrade NumPy within Sage, we notices some differences in > behavior between 1.5 and 1.6. In particular, in 1.5, we have > > sage: f = 0.5 > sage: f.__array_interface__ > {'typestr': '=f8'} > sage: numpy.array(f) > array(0.5) > sage: numpy.array(float(f)) > array(0.5) > > In 1.6, we get the following, > > sage: f = 0.5 > sage: f.__array_interface__ > {'typestr': '=f8'} > sage: numpy.array(f) > array(0.500, dtype=object) > > This seems to be do to the changes in PyArray_FromAny introduced in > https://github.com/mwhansen/numpy/commit/2635398db3f26529ce2aaea4028a8118844f3c48 > . In particular, _array_find_type used to be used to query our > __array_interface__ attribute, and it no longer seems to work. Is > there a way to get the old behavior with the current code? Any ideas? Thanks, --Mike ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] Changes in PyArray_FromAny between 1.5.x and 1.6.x
Hello, In trying to upgrade NumPy within Sage, we notices some differences in behavior between 1.5 and 1.6. In particular, in 1.5, we have sage: f = 0.5 sage: f.__array_interface__ {'typestr': '=f8'} sage: numpy.array(f) array(0.5) sage: numpy.array(float(f)) array(0.5) In 1.6, we get the following, sage: f = 0.5 sage: f.__array_interface__ {'typestr': '=f8'} sage: numpy.array(f) array(0.500, dtype=object) This seems to be do to the changes in PyArray_FromAny introduced in https://github.com/mwhansen/numpy/commit/2635398db3f26529ce2aaea4028a8118844f3c48 . In particular, _array_find_type used to be used to query our __array_interface__ attribute, and it no longer seems to work. Is there a way to get the old behavior with the current code? --Mike ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion