Opened 2 years ago

Closed 2 years ago

#29700 closed defect (fixed)

ValueError raised when computing numerical approx of a matrix on QQbar

Reported by: slabbe Owned by:
Priority: major Milestone: sage-9.2
Component: linear algebra Keywords:
Cc: Merged in:
Authors: Sébastien Labbé Reviewers: Frédéric Chapoton
Report Upstream: N/A Work issues:
Branch: 034d71a (Commits, GitHub, GitLab) Commit: 034d71ace4312b495de3ba434566f75bbe621b46
Dependencies: Stopgaps:

Status badges


sage: M = matrix(3,[1,1,1,1,0,0,0,1,0])
sage: A,B = M.diagonalization(QQbar)
sage: A.n()


ValueError                                Traceback (most recent call last)
<ipython-input-122-26e33bb2b8a5> in <module>()
----> 1 A.n()

/home/slabbe/GitBox/sage/local/lib/python3.7/site-packages/sage/structure/element.pyx in sage.structure.element.Element.n (build/cythonized/sage/structure/element.c:8037)()
    857             0.666666666666667
    858         """
--> 859         return self.numerical_approx(prec, digits, algorithm)
    861     def _mpmath_(self, prec=53, rounding=None):

/home/slabbe/GitBox/sage/local/lib/python3.7/site-packages/sage/matrix/matrix2.pyx in sage.matrix.matrix2.Matrix.numerical_approx (build/cythonized/sage/matrix/matrix2.c:90568)()
  13686         try:
> 13687             return self.change_ring(sage.rings.real_mpfr.RealField(prec))
  13688         except TypeError:
  13689             # try to return a complex result


/home/slabbe/GitBox/sage/local/lib/python3.7/site-packages/sage/rings/ in _element_constructor_(self, x)
   1067                 return x.real()
   1068             else:
-> 1069                 raise ValueError("Cannot coerce algebraic number with non-zero imaginary part to algebraic real")
   1070         elif hasattr(x, '_algebraic_'):
   1071             return x._algebraic_(AA)

ValueError: Cannot coerce algebraic number with non-zero imaginary part to algebraic real

Maybe we should do

-  13688         except TypeError:
+  13688         except (TypeError,ValueError):

in the file sage/matrix/matrix2.pyx ?

Change History (3)

comment:1 Changed 2 years ago by slabbe

  • Authors set to Sébastien Labbé
  • Branch set to u/slabbe/29700
  • Commit set to 034d71ace4312b495de3ba434566f75bbe621b46
  • Status changed from new to needs_review

New commits:

034d71a29700:catching also ValueError

comment:2 Changed 2 years ago by chapoton

  • Milestone changed from sage-9.1 to sage-9.2
  • Reviewers set to Frédéric Chapoton
  • Status changed from needs_review to positive_review


comment:3 Changed 2 years ago by vbraun

  • Branch changed from u/slabbe/29700 to 034d71ace4312b495de3ba434566f75bbe621b46
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.