William Stein wrote:
> On Fri, Apr 11, 2008 at 10:43 AM, Ryan Hinton <[EMAIL PROTECTED]> wrote:
>>  Sorry, I meant to.  One problem is that the Sage pre-parsing results
>>  in different behavior than I am seeing, so pasting code into a Sage
>>  session will not exhibit the problem I am seeing.
> 
> Include
> 
> sage: preparse(False)
> 
> at the top of the example to turn off the Sage preparser.
> Alternatively, you can do Integer=int; RealNumber=float
> to turn off just bits of it.
> 
> It looks like below the issue is that you want to use
> the Python builtin round instead of Sage's round.
> That Sage uses it's round instead the builtin one
> by default has nothing to do with the preparse.  It's
> just because we import our own round in
> 
>   from sage.all import *
> 
> We do that because the semantics of Python's builtin
> round aren't optimal for Sage.
> 


Ryan,

If you use Sage's round command:

from sage.all import round

or

from sage.misc.functional import round

then the example seems to work just fine:

sage: vector([round(frac*length) for frac in fracs_list])
(5, 3, 2)


If I wanted to be sure that I had an integer vector, I could specify the 
parent explicitly, just like with matrices:

sage: vector(ZZ,[round(frac*length) for frac in fracs_list])
(5, 3, 2)


That said, William, is there a reason why this doesn't work?  This is 
what is necessitating the two type conversions above.

sage: Integer(float(2))
---------------------------------------------------------------------------
<type 'exceptions.TypeError'>             Traceback (most recent call last)

/home/grout/<ipython console> in <module>()

/home/grout/integer.pyx in sage.rings.integer.Integer.__init__()

<type 'exceptions.TypeError'>: unable to coerce element to an integer


sage: Integer(RDF(2))
---------------------------------------------------------------------------
<type 'exceptions.TypeError'>             Traceback (most recent call last)

/home/grout/<ipython console> in <module>()

/home/grout/integer.pyx in sage.rings.integer.Integer.__init__()

<type 'exceptions.TypeError'>: unable to coerce element to an integer


I guess I would think it was a design decision to not convert floating 
points to ints automatically.  However, the following does work:

sage: Integer(RR(2))
2


This seems inconsistent.

Jason


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to