Skip to content

Commit

Permalink
Trac #15824: Remove deprecated code from matrix/
Browse files Browse the repository at this point in the history
Removes deprecated code from #3794, #5460, #6094, #6115, #7852, #11603,
#12840, #13012 and #13643.

URL: http://trac.sagemath.org/15824
Reported by: aapitzsch
Ticket author(s): André Apitzsch
Reviewer(s): Ralf Stephan
  • Loading branch information
Release Manager authored and vbraun committed Mar 22, 2014
2 parents 2092418 + 28d349b commit 25255ca
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 532 deletions.
214 changes: 0 additions & 214 deletions src/sage/matrix/matrix2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4664,10 +4664,6 @@ cdef class Matrix(matrix1.Matrix):
break
return f

# Deprecated Aug 2008 Trac #3794
# Removed July 2011
# def eigenspaces(self, var='a', even_if_inexact=None):

def _eigenspace_format(self, format):
r"""
Helper method to control output format for eigenspaces.
Expand Down Expand Up @@ -10086,216 +10082,6 @@ cdef class Matrix(matrix1.Matrix):
else:
return subspace

def cholesky_decomposition(self):
r"""
Return the Cholesky decomposition of ``self``.

.. WARNING::

``cholesky_decomposition()`` is deprecated,
please use :meth:`cholesky` instead.

The computed decomposition is cached and returned on
subsequent calls. Methods such as :meth:`solve_left` may also
take advantage of the cached decomposition depending on the
exact implementation.

INPUT:

The input matrix must be:

- real, symmetric, and positive definite; or

- complex, Hermitian, and positive definite.

If not, a ``ValueError`` exception will be raised.

OUTPUT:

An immutable lower triangular matrix `L` such that `L L^t` equals ``self``.

ALGORITHM:

Calls the method ``_cholesky_decomposition_``, which by
default uses a standard recursion.

.. warning::

This implementation uses a standard recursion that is not known to
be numerically stable.

.. warning::

It is potentially expensive to ensure that the input is
positive definite. Therefore this is not checked and it
is possible that the output matrix is *not* a valid
Cholesky decomposition of ``self``. An example of this is
given in the tests below.

EXAMPLES:

Here is an example over the real double field; internally, this uses SciPy::

sage: r = matrix(RDF, 5, 5, [ 0,0,0,0,1, 1,1,1,1,1, 16,8,4,2,1, 81,27,9,3,1, 256,64,16,4,1 ])
sage: m = r * r.transpose(); m
[ 1.0 1.0 1.0 1.0 1.0]
[ 1.0 5.0 31.0 121.0 341.0]
[ 1.0 31.0 341.0 1555.0 4681.0]
[ 1.0 121.0 1555.0 7381.0 22621.0]
[ 1.0 341.0 4681.0 22621.0 69905.0]
sage: L = m.cholesky_decomposition(); L
doctest:...: DeprecationWarning:
cholesky_decomposition() is deprecated; please use cholesky() instead.
See http://trac.sagemath.org/13045 for details.
[ 1.0 0.0 0.0 0.0 0.0]
[ 1.0 2.0 0.0 0.0 0.0]
[ 1.0 15.0 10.7238052948 0.0 0.0]
[ 1.0 60.0 60.9858144589 7.79297342371 0.0]
[ 1.0 170.0 198.623524155 39.3665667796 1.72309958068]
sage: L.parent()
Full MatrixSpace of 5 by 5 dense matrices over Real Double Field
sage: L*L.transpose()
[ 1.0 1.0 1.0 1.0 1.0]
[ 1.0 5.0 31.0 121.0 341.0]
[ 1.0 31.0 341.0 1555.0 4681.0]
[ 1.0 121.0 1555.0 7381.0 22621.0]
[ 1.0 341.0 4681.0 22621.0 69905.0]
sage: ( L*L.transpose() - m ).norm(1) < 2^-30
True

The result is immutable::

sage: L[0,0] = 0
Traceback (most recent call last):
...
ValueError: matrix is immutable; please change a copy instead (i.e., use copy(M) to change a copy of M).

Here is an example over a higher precision real field::

sage: r = matrix(RealField(100), 5, 5, [ 0,0,0,0,1, 1,1,1,1,1, 16,8,4,2,1, 81,27,9,3,1, 256,64,16,4,1 ])
sage: m = r * r.transpose()
sage: L = m.cholesky_decomposition()
sage: L.parent()
Full MatrixSpace of 5 by 5 dense matrices over Real Field with 100 bits of precision
sage: ( L*L.transpose() - m ).norm(1) < 2^-50
True

Here is a Hermitian example::

sage: r = matrix(CDF, 2, 2, [ 1, -2*I, 2*I, 6 ]); r
[ 1.0 -2.0*I]
[ 2.0*I 6.0]
sage: r.eigenvalues()
[0.298437881284, 6.70156211872]
sage: ( r - r.conjugate().transpose() ).norm(1) < 1e-30
True
sage: L = r.cholesky_decomposition(); L
[ 1.0 0.0]
[ 2.0*I 1.41421356237]
sage: ( r - L*L.conjugate().transpose() ).norm(1) < 1e-30
True
sage: L.parent()
Full MatrixSpace of 2 by 2 dense matrices over Complex Double Field

TESTS:

The following examples are not positive definite::

sage: m = -identity_matrix(3).change_ring(RDF)
sage: m.cholesky_decomposition()
Traceback (most recent call last):
...
ValueError: The input matrix was not symmetric and positive definite

sage: m = -identity_matrix(2).change_ring(RealField(100))
sage: m.cholesky_decomposition()
Traceback (most recent call last):
...
ValueError: The input matrix was not symmetric and positive definite

Here is a large example over a higher precision complex field::

sage: r = MatrixSpace(ComplexField(100), 6, 6).random_element()
sage: m = r * r.conjugate().transpose()
sage: m.change_ring(CDF) # for display purposes
[ 4.03491289478 1.65865229397 + 1.20395241554*I -0.275377464753 - 0.392579363912*I 0.646019176609 - 1.80427378747*I 1.15898675468 + 2.35202344518*I -1.07920143474 + 1.37815737417*I]
[ 1.65865229397 - 1.20395241554*I 5.19463366777 0.192784646673 + 0.217539084881*I -1.24630239913 - 1.00510523556*I 1.65179716714 + 1.27031304403*I 1.17275462994 + 0.565615358757*I]
[-0.275377464753 + 0.392579363912*I 0.192784646673 - 0.217539084881*I 2.04647180997 -0.550558880479 + 0.379933796418*I 1.00862850855 + 0.945317139306*I -0.740344951784 - 0.46578741292*I]
[ 0.646019176609 + 1.80427378747*I -1.24630239913 + 1.00510523556*I -0.550558880479 - 0.379933796418*I 4.07227967662 -2.81600845862 - 0.56060176804*I -2.28695708255 - 0.360066613053*I]
[ 1.15898675468 - 2.35202344518*I 1.65179716714 - 1.27031304403*I 1.00862850855 - 0.945317139306*I -2.81600845862 + 0.56060176804*I 5.26892394669 0.964830717551 + 0.111780339251*I]
[ -1.07920143474 - 1.37815737417*I 1.17275462994 - 0.565615358757*I -0.740344951784 + 0.46578741292*I -2.28695708255 + 0.360066613053*I 0.964830717551 - 0.111780339251*I 3.49912480167]
sage: eigs = m.change_ring(CDF).eigenvalues() # again for display purposes
sage: all(abs(imag(e)) < 1.3e-15 for e in eigs)
True
sage: [real(e) for e in eigs]
[12.1121838768, 5.17714373118, 0.183583821657, 0.798520682956, 2.03399202232, 3.81092266261]

sage: ( m - m.conjugate().transpose() ).norm(1) < 1e-50
True
sage: L = m.cholesky_decomposition(); L.change_ring(CDF)
[ 2.00870926089 0.0 0.0 0.0 0.0 0.0]
[ 0.825730396261 - 0.599366189511*I 2.03802923221 0.0 0.0 0.0 0.0]
[ -0.137091748475 + 0.195438618996*I 0.20761467212 - 0.145606613292*I 1.38750721467 0.0 0.0 0.0]
[ 0.321609099528 + 0.898225453828*I -0.477666770113 + 0.0346666053769*I -0.416429223553 - 0.094835914364*I 1.65839194165 0.0 0.0]
[ 0.576980839012 - 1.17091282993*I 0.232362216253 - 0.318581071175*I 0.880672963687 - 0.692440838276*I -0.920603548686 + 0.566479149373*I 0.992988116915 0.0]
[ -0.537261143636 - 0.686091014267*I 0.591339766401 + 0.158450627525*I -0.561877938537 + 0.106470627954*I -0.871217053358 + 0.176042897482*I 0.0516893015902 + 0.656402869037*I 0.902427551681]
sage: ( m - L*L.conjugate().transpose() ).norm(1) < 1e-20
True
sage: L.parent()
Full MatrixSpace of 6 by 6 dense matrices over Complex Field with 100 bits of precision
sage: L[0,0] = 0
Traceback (most recent call last):
...
ValueError: matrix is immutable; please change a copy instead (i.e., use copy(M) to change a copy of M).

Here is an example that returns an incorrect answer, because the input is *not* positive definite::

sage: r = matrix(CDF, 2, 2, [ 1, -2*I, 2*I, 0 ]); r
[ 1.0 -2.0*I]
[ 2.0*I 0.0]
sage: r.eigenvalues()
[2.56155281281, -1.56155281281]
sage: ( r - r.conjugate().transpose() ).norm(1) < 1e-30
True
sage: L = r.cholesky_decomposition(); L
[ 1.0 0.0]
[2.0*I 2.0*I]
sage: L*L.conjugate().transpose()
[ 1.0 -2.0*I]
[ 2.0*I 8.0]

This test verifies that the caching of the two variants
of the Cholesky decomposition have been cleanly separated.
It can be safely removed as part of removing this method
at the end of the deprecation period.
(From :trac:`13045`.) ::

sage: r = matrix(CDF, 2, 2, [ 0, -2*I, 2*I, 0 ]); r
[ 0.0 -2.0*I]
[ 2.0*I 0.0]
sage: r.cholesky_decomposition()
[ 0.0 0.0]
[NaN + NaN*I NaN + NaN*I]
sage: r.cholesky()
Traceback (most recent call last):
...
ValueError: matrix is not positive definite
sage: r[0,0] = 0 # clears cache
sage: r.cholesky()
Traceback (most recent call last):
...
ValueError: matrix is not positive definite
sage: r.cholesky_decomposition()
[ 0.0 0.0]
[NaN + NaN*I NaN + NaN*I]
"""
from sage.misc.superseded import deprecation
deprecation(13045, "cholesky_decomposition() is deprecated; please use cholesky() instead.")
assert self._nrows == self._ncols, "Can only Cholesky decompose square matrices"
if self._nrows == 0:
return self.__copy__()
return self._cholesky_decomposition_()

def _cholesky_decomposition_(self):
r"""
Return the Cholesky decomposition of ``self``; see ``cholesky_decomposition``.
Expand Down
Loading

0 comments on commit 25255ca

Please sign in to comment.