On 8/11/10 8:29 AM, Tobias Katz wrote:
Hi,
did I kill my sage or is numpy.round broken in 4.5.2?
I get the same error as you in my build of 4.4.1:
sage: version()
'Sage Version 4.4.1, Release Date: 2010-05-02'
sage: import numpy
sage: import numpy; numpy.round(1.2)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/Users/grout/sage-4.4.1/<ipython console> in <module>()
/Users/grout/sage-4.4.1/local/lib/python2.6/site-packages/numpy/core/fromnumeric.pyc
in round_(a, decimals, out)
2031 except AttributeError:
2032 return _wrapit(a, 'round', decimals, out)
-> 2033 return round(decimals, out)
2034
2035
TypeError: round() takes no arguments (2 given)
sage: import numpy; numpy.round(float(1.2))
1.0
The problem is that Sage floats have their own round function which does
not take any arguments. Here is the numpy code:
try:
round = a.round
except AttributeError:
return _wrapit(a, 'round', decimals, out)
return round(decimals, out)
So effectively, numpy is trying to do:
sage: a=1.2; a.round(decimals,out)
which doesn't work because the syntax is
sage: a=1.2; a.round()
I'm not sure what we should do here. This is a problem when two
different systems use duck typing with different meanings "quack".
Maybe that's why when we do a similar thing in Sage, we should always
name our private method _sage_methodname (effectively creating our own
namespace for our private functions).
Any ideas of what we should do? Clearly, we could support the decimals
argument; even the __builtins__.round supports that. However, it
doesn't make sense for us to support the "out" parameter:
out : ndarray, optional
Alternative output array in which to place the result. It must have
the same shape as the expected output, but the type of the output
values will be cast if necessary.
Ideas, anyone?
Jason
--
To post to this group, send an email to [email protected]
To unsubscribe from this group, send an email to
[email protected]
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org