On 19/12/2017 07:58, Jeroen Demeyer wrote:
On 2017-12-18 18:31, Simon King wrote:
One way to answer the question whether a coercion from A to B exists is
by implementing the method B._coerce_map_from_.

Right, I was asking the question because I need to implement such a method for RIF and CIF.

If that method returns "True" then the coercion system knows that
it is right to choose _real_mpfi_() for coercion.

1. Check for a coercion map.

2. If coercion is possible, check for a NamedConvertMap. If so, use that
instead.

No. If there is a coercion map, then (by definition) coercion is possible,
and the coercion map is cached. So, do not use something else instead.

I think it should be the other way around: if a _real_mpfi_() method exists, it should always be picked as conversion map. The existence of that method means that somebody explicitly implemented a specific conversion to RIF. So any other map that the coercion framework can come up with cannot be as good as this NamedConvertMap using _real_mpfi_().

+1

In #24285, I did implement a _arb_ and _acb_ methods on number field elements. In order for the coercion model to use it, I had to fight with coercions declared in the constructor (self._populate_coercion_lists_) versus has_coerce_map_from. Depending on what you choose, different coercions are chosen. Namely, there was a predefined coercion RLF -> RBF in the constructor. As a consequence, any object with a coercion to RLF would go through this map. It is the case for number fields.

And you can see that I left a comment in real_mpfi.pyx (line 1223)

         elif hasattr(x, '_real_mpfi_'):
            # TODO: this is a stupid useless copy!
            # this case should be handled by coercion

If you start making it better, please doctest which coercion map is used to avoid regressions

    sage: K = QuadraticField(-2, embedding=AA(-2).sqrt())
    sage: CBF.coerce_map_from(K)
    Conversion via _acb_ method map:
     ...

Vincent

--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to