Opened 13 months ago

Closed 9 months ago

#27831 closed defect (fixed)

Small fix for is_symmetric for matrices over CDF

Reported by: gh-mwageringel Owned by:
Priority: major Milestone: sage-8.9
Component: linear algebra Keywords: numpy
Cc: Merged in:
Authors: Markus Wageringel Reviewers: Frédéric Chapoton
Report Upstream: N/A Work issues:
Branch: 3b62253 (Commits) Commit: 3b62253eea29789e3323e6914942d5af678d4cc3
Dependencies: Stopgaps:

Description

Calling is_symmetric on a matrix defined over CDF fails:

sage: a = matrix(CDF, [(21, 0.6 + 18.5*i), (0.6 - 18.5*i, 21)])
sage: a.is_symmetric()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-6d0498c2f774> in <module>()
----> 1 a.is_symmetric()

/Applications/SageMath/local/lib/python2.7/site-packages/sage/matrix/matrix_double_dense.pyx in sage.matrix.matrix_double_dense.Matrix_double_dense.is_symmetric (build/cythonized/sage/matrix/matrix_double_dense.c:15478)()
   2400         for i from 0 < i < self._nrows:
   2401             for j from 0 <= j < i:
-> 2402                 if math.fabs(self.get_unsafe(i,j) - self.get_unsafe(j,i)) > tol:
   2403                     b = False
   2404                     break

/Applications/SageMath/local/lib/python2.7/site-packages/sage/rings/complex_double.pyx in sage.rings.complex_double.ComplexDoubleElement.__float__ (build/cythonized/sage/rings/complex_double.c:10102)()
    968         """
    969         if self._complex.imag:
--> 970             raise TypeError(f"unable to convert {self} to float; use abs() or real_part() as desired")
    971         return self._complex.real
    972

TypeError: unable to convert -37.0*I to float; use abs() or real_part() as desired

The implementation calls math.fabs which unsuitable for complex numbers and should be replaced by abs (which is used in similar functions like is_hermitian).

Change History (4)

comment:1 Changed 13 months ago by gh-mwageringel

  • Authors set to Markus Wageringel
  • Branch set to u/gh-mwageringel/matrix_cdf_symmetric
  • Commit set to 3b62253eea29789e3323e6914942d5af678d4cc3
  • Keywords numpy added
  • Status changed from new to needs_review

New commits:

3b62253fix is_symmetric for matrices over CDF

comment:2 Changed 11 months ago by embray

  • Milestone changed from sage-8.8 to sage-8.9

Moving tickets from the Sage 8.8 milestone that have been actively worked on in the last six months to the next release milestone (optimistically).

comment:3 Changed 9 months ago by chapoton

  • Reviewers set to Frédéric Chapoton
  • Status changed from needs_review to positive_review

ok

comment:4 Changed 9 months ago by vbraun

  • Branch changed from u/gh-mwageringel/matrix_cdf_symmetric to 3b62253eea29789e3323e6914942d5af678d4cc3
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.