Skip to content

Speed up coordinate_vector function #40591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: develop
Choose a base branch
from

Conversation

user202729
Copy link
Contributor

Build up on #40497, coordinate_vector can use the same optimization.

the v = v.list() is an unfortunate artifact of another suboptimality, namely we have the following

    cpdef _coerce_map_from_(self, M):
        """
        Return a coercion map from `M` to ``self``, or None.

        The implementation of this method in module classes should
        observe the following guidelines:

        1. We want to relate two different *ambient* modules if and
           only if they have the same rank (which is the same as
           degree) and if there is a coercion of the base rings.

        2. Two modules embedded in other modules that have a coercion
           may inherit a coercion if they are in fact sub-modules of
           one another.

        3. Since different embeddings of one abstract module are
           related by non-identical coerce maps (in 2.), we must not
           have coercion from a sub-module to the corresponding
           abstract module, for otherwise non-commuting coercion
           triangles emerge.

        4. Quotient modules must not coerce unless their modulus `W`
           is the same. There must not be forgetful maps.

        5. Coerce maps for quotient modules are already registered on
           construction.

        TESTS:

        Make sure :issue:`3638` is fixed::

            sage: vector(ZZ,[1,2,11]) == vector(Zmod(8),[1,2,3])                        # needs sage.modules
            True

        AUTHORS:

        - Simon King (2010-12)

        - Peter Bruin (June 2014)
        """
        try:
            if (isinstance(M, Module)
                    and self.base_ring().has_coerce_map_from(M.base_ring())
                    and M.change_ring(self.base_ring()).is_submodule(self)):
                return M.hom([self._element_constructor_(x, check=False) for x in M.gens()], self)
        except (TypeError, NotImplementedError, AttributeError, ArithmeticError):
            pass
        return None

this map is called even to convert a from a submodule of ℤ^2 to ℤ^2.

the problem is ModuleMorphism needs to (1) call coordinate_vector, then (2) multiply it by the basis matrix. and (1) leads to an infinite loop.

Requires #40371

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

#40371

Copy link

Documentation preview for this PR (built with commit a3ab0d3; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants