Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Trac #33107: cholesky() for trivial matrices.
Browse files Browse the repository at this point in the history
Somehow the trivial matrix was overlooked (probably by myself) in the
generic cholesky() method for matrices. Here we add a special-case and
a doctest for it; the trivial matrix itself satisfies the definition
of its Cholesky factor.
  • Loading branch information
orlitzky committed Jan 30, 2022
1 parent 439907f commit a1bc2c9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/sage/matrix/matrix2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -12620,6 +12620,13 @@ cdef class Matrix(Matrix1):
sage: A.cholesky()
[ 1.0 0.0]
[-1.0*I 1.0]

Try the trivial case (:trac:`33107`)::

sage: all( matrix(R,[]).cholesky() == matrix(R,[])
....: for R in (RR,CC,RDF,CDF,ZZ,QQ,AA,QQbar) )
True

"""
cdef Matrix C # output matrix
C = self.fetch('cholesky')
Expand All @@ -12631,6 +12638,12 @@ cdef class Matrix(Matrix1):
if not self.is_hermitian():
raise ValueError("matrix is not Hermitian")

if n == 0:
# The trivial matrix has a trivial cholesky decomposition.
# We special-case this after is_hermitian() to ensure that
# the matrix is square.
return self

# Use classical=True to ensure that we don't get a permuted L.
cdef Matrix L # block_ldlt() results
cdef list d # block_ldlt() results
Expand Down

0 comments on commit a1bc2c9

Please sign in to comment.