Opened 13 months ago

Closed 9 months ago

# Small fix for is_symmetric for matrices over CDF

Reported by: Owned by: gh-mwageringel major sage-8.9 linear algebra numpy Markus Wageringel Frédéric Chapoton N/A 3b62253 (Commits) 3b62253eea29789e3323e6914942d5af678d4cc3

### 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`).

### 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
• Status changed from new to needs_review

New commits:

 ​3b62253 `fix 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.