Skip to content

Commit

Permalink
Trac #28935: infinite recursion in exponential of sparse matrices
Browse files Browse the repository at this point in the history
{{{
sage: matrix([[0]], sparse=True).exp()
...
RecursionError: maximum recursion depth exceeded while calling a Python
object
}}}

as reported at [https://ask.sagemath.org/question/49190/exponential-
function-does-not-work-for-diagonal-matrices].

URL: https://trac.sagemath.org/28935
Reported by: gh-mwageringel
Ticket author(s): Markus Wageringel
Reviewer(s): Frédéric Chapoton
  • Loading branch information
Release Manager committed Jan 5, 2020
2 parents b731e8b + 1ec3605 commit ba2f949
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/sage/matrix/matrix2.pyx
Expand Up @@ -13417,7 +13417,20 @@ cdef class Matrix(Matrix1):
sage: a.change_ring(RDF).exp() # rel tol 1e-14
[42748127.31532951 7368259.244159399]
[234538976.1381042 40426191.45156228]

TESTS:

Check that sparse matrices are handled correctly (:trac:`28935`)::

sage: matrix.diagonal([0], sparse=True).exp()
[1]
sage: matrix.zero(CBF, 2, sparse=True).exp()
[1.000000000000000 0]
[ 0 1.000000000000000]
"""
if self.is_sparse():
# exp is only implemented for dense matrices (:trac:`28935`)
return self.dense_matrix().exp().sparse_matrix()
from sage.symbolic.ring import SR
return self.change_ring(SR).exp()

Expand Down

0 comments on commit ba2f949

Please sign in to comment.