Skip to content

Move real/complex interval fields to new coercion model #24371

Closed

Description

@jdemeyer

Also fix the following:

sage: NF.<a> = QuadraticField(-2)
sage: CIF(a)
...
ValueError: can not convert complex algebraic number to real interval

We also deal with Python 3 compatibility regarding int/long and bytes/unicode.

Depends on #24423

CC: @tscrim

Component: coercion

Author: Jeroen Demeyer

Branch/Commit: 9ac1612

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/24371

Activity

  1. added this to the sage-8.2 milestone on Dec 12, 2017
  2. jdemeyer commented on Dec 13, 2017

    @jdemeyer
    ContributorAuthor
  3. sagetrac-git commented on Dec 14, 2017

    sagetrac-gitmannequin
    Mannequin

    Commit: db4611a

  4. sagetrac-git commented on Dec 14, 2017

    sagetrac-gitmannequin
    Mannequin

    Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

    375e40fMap._extra_slots(): do not pass dict
    db4611aMove real/complex interval fields to new coercion model
  5. jdemeyer commented on Dec 14, 2017

    @jdemeyer
    ContributorAuthor

    Author: Jeroen Demeyer

  6. jdemeyer commented on Dec 14, 2017

    @jdemeyer
    ContributorAuthor

    Dependencies: #24372

  7. sagetrac-git commented on Dec 14, 2017

    sagetrac-gitmannequin
    Mannequin

    Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

    549bd7dMove real/complex interval fields to new coercion model
  8. sagetrac-git commented on Dec 14, 2017

    sagetrac-gitmannequin
    Mannequin

    Changed commit from db4611a to 549bd7d

  9. sagetrac-git commented on Dec 15, 2017

    sagetrac-gitmannequin
    Mannequin

    Changed commit from 549bd7d to fe4c823

  10. sagetrac-git commented on Dec 15, 2017

    sagetrac-gitmannequin
    Mannequin

    Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

    fe4c823Move real/complex interval fields to new coercion model
  11. jdemeyer commented on Dec 15, 2017

    @jdemeyer
    Author
  12. sagetrac-git commented on Dec 15, 2017

    sagetrac-gitmannequin
    Mannequin

    Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

    2cee3a4Move real/complex interval fields to new coercion model
  13. 57 remaining items

  14. sagetrac-git commented on Feb 12, 2018

    sagetrac-gitmannequin
    Mannequin

    Branch pushed to git repo; I updated commit sha1. New commits:

    22d309cCleanup for real/complex interval fields
  15. jdemeyer commented on Feb 12, 2018

    @jdemeyer
    ContributorAuthor
    comment:47

    I ended up doing a lot of cleanup. I think I'm using element_class everywhere, but don't shoot me if I'm wrong.

    Note that currently the category stuff won't be used anyway because the elements are extension types.

  16. tscrim commented on Feb 13, 2018

    @tscrim
    Collaborator
    comment:48

    Thank you for doing the cleanup.

    For changes such as

    -        cdef ComplexIntervalFieldElement res = self._new()
    +        res = self._new()

    aren't we loosing some efficiency? I would think because they are still subclasses of ComplexIntervalFieldElement, that Cython would be able to optimize their attribute lookups by not treating them as Python objects? (Of course, we would have to explicitly cast <ComplexIntervalFieldElement> to avoid the type-checking-safety-penalty.)

    This goes through the __call__ (which in this case, bypasses the coercion framework, but normally it wouldn't):

    -        return complex_interval.ComplexIntervalFieldElement(self, 0, 1)
    +        return self(0, 1)

    I think we are better making a direct call to self.element_class(self, 0, 1) since this is not user input.

  17. jdemeyer commented on Feb 13, 2018

    @jdemeyer
    ContributorAuthor
    comment:49

    Replying to @tscrim:

    Thank you for doing the cleanup.

    For changes such as

    -        cdef ComplexIntervalFieldElement res = self._new()
    +        res = self._new()

    aren't we loosing some efficiency?

    No, Cython has type inference. Since _new is declared as returning a ComplexIntervalFieldElement, the declaration cdef ComplexIntervalFieldElement res is just redundant.

    This goes through the __call__ (which in this case, bypasses the coercion framework, but normally it wouldn't):

    -        return complex_interval.ComplexIntervalFieldElement(self, 0, 1)
    +        return self(0, 1)

    I think we are better making a direct call to self.element_class(self, 0, 1) since this is not user input.

    I don't see the problem with using __call__ here but I can make that change.

  18. sagetrac-git commented on Feb 13, 2018

    sagetrac-gitmannequin
    Mannequin

    Changed commit from 22d309c to 9ac1612

  19. sagetrac-git commented on Feb 13, 2018

    sagetrac-gitmannequin
    Mannequin

    Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

    9ac1612Cleanup for real/complex interval fields
  20. jdemeyer commented on Feb 13, 2018

    @jdemeyer
    ContributorAuthor
    comment:51

    Replying to @tscrim:

    Cython would be able to optimize their attribute lookups by not treating them as Python objects?

    Actually, the relevant attributes are cdef attributes, so they cannot even be accessed from Python! So the fact that the code works proves that Cython must be doing type inference.

    I changed some self(...) calls to self.element_class(self, ...)

  21. tscrim commented on Feb 13, 2018

    @tscrim
    Collaborator
    comment:52

    Replying to @jdemeyer:

    Replying to @tscrim:

    Cython would be able to optimize their attribute lookups by not treating them as Python objects?

    Actually, the relevant attributes are cdef attributes, so they cannot even be accessed from Python! So the fact that the code works proves that Cython must be doing type inference.

    That is what is happening, e.g.:

      __pyx_t_1 = ((PyObject *)__pyx_f_4sage_5rings_16complex_interval_27ComplexIntervalFieldE
    lement__new(__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 325, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_v_a00 = ((struct __pyx_obj_4sage_5rings_16complex_interval_ComplexIntervalFieldEle
    ment *)__pyx_t_1);
      __pyx_t_1 = 0;

    I didn't realize that Cython was that smart. :)

    I changed some self(...) calls to self.element_class(self, ...)

    Thank you. LGTM. (If I wanted to be really picky, I would say self.element_class(self, 1) should instead use the cached self.one(), but zeta(1) is almost certainly never called.)

  22. jdemeyer commented on Feb 13, 2018

    @jdemeyer
    ContributorAuthor
    comment:53

    Thanks!

  23. vbraun commented on Feb 15, 2018

    @vbraun
    Member
  24. added a commit that references this issue on Sep 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions