[sage-devel] Regular expression involving numpy.float

16 views
Skip to first unread message

Pablo Angulo

unread,
Apr 28, 2010, 4:15:07 PM4/28/10
to sage-...@googlegroups.com
Hello:
Tracking a weird bug I've discovered the following:
For a symbolic variable x and a numpy.float64 y, the code 'x<y' evals
to a Symbolic expression, while 'y<x' evals to a numpy.bool.
I'm afraid I'm stacked, as it is the responsability of the method
numpy.float64.__lt__, and I can't assign it to a custom method, for example.
Any idea what can I try so that 'y<x' evals to a Symbolic Expression
too (if you agree this should be the result)?
Regards

--
To post to this group, send an email to sage-...@googlegroups.com
To unsubscribe from this group, send an email to sage-devel+...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Pablo Angulo

unread,
Apr 28, 2010, 4:42:07 PM4/28/10
to sage-...@googlegroups.com
My mind slipped: I meant "Symbolic expression involving numpy.float"

dagss

unread,
Apr 29, 2010, 8:57:56 AM4/29/10
to sage-devel
On Apr 28, 10:15 pm, Pablo Angulo <pablo.ang...@uam.es> wrote:
>   Hello:
>   Tracking a weird bug I've discovered the following:
>   For a symbolic variable x and a numpy.float64 y, the code 'x<y' evals
> to a Symbolic expression, while 'y<x' evals to a numpy.bool.
>   I'm afraid I'm stacked, as it is the responsability of the method
> numpy.float64.__lt__, and I can't assign it to a custom method, for example.
>   Any idea what can I try so that 'y<x' evals to a Symbolic Expression
> too (if you agree this should be the result)?

Sage should set the __array_priority__ attribute to something very
high in its base class(es), then let the coercion model decide how
NumPy objects should be handled (in this case, coerce to RDF or CDF).

NumPy uses the custom convention that __array_priority__ decides which
operand gets to handle the operation.

Example:

import numpy as np

class MagicOne:
__array_priority__ = 1000
def __cmp__(self, other):
print 'MagicOne has control'
return cmp(1, other)

one = MagicOne()

print one < np.float64(63.3)
print np.float64(63.3) < one

This prints

MagicOne has control
True
MagicOne has control
False

Jason Grout

unread,
Apr 29, 2010, 11:36:55 AM4/29/10
to sage-...@googlegroups.com
This is now http://trac.sagemath.org/sage_trac/ticket/8824

Thanks,

Jason
Reply all
Reply to author
Forward
0 new messages