#8824: Make it so that numpy datatypes are integrated into the coercion model
------------------------+---------------------------------------------------
Reporter: jason | Owner: robertwb
Type: defect | Status: new
Priority: major | Milestone: sage-4.4.1
Component: coercion | Keywords:
Author: | Upstream: N/A
Reviewer: | Merged:
Work_issues: |
------------------------+---------------------------------------------------
From sage-devel: http://groups.google.com/group/sage-
devel/browse_frm/thread/221f569eaba874de
> 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
}}}
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/8824>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.