Ask Your Question

backslash operator on RDF matrices

asked 2013-02-08 21:53:18 +0200

Greg Marks gravatar image

I've discovered that the backslash operator produces a weird type error when used on matrices with Real Double Field entries:

| Sage Version 5.6, Release Date: 2013-01-21                         |
| Type "notebook()" for the browser-based notebook interface.        |
| Type "help()" for help.                                            |
sage: A = matrix(QQ, 3, [1,2,4,2,3,1,0,1,2])
sage: B = matrix(QQ, 3, 2, [1,7,5,2,1,3])
sage: A\B
[  -1    1]
[13/5 -3/5]
[-4/5  9/5]
sage: A = matrix(RDF, 3, [1,2,4,2,3,1,0,1,2])
sage: B = matrix(RDF, 3, 2, [1,7,5,2,1,3])
sage: A\B
TypeError                                 Traceback (most recent call last)

/home/gtmarks/<ipython console> in <module>()

/usr/local/sage-5.6/local/lib/python2.7/site-packages/sage/misc/preparser.pyc in __mul__(self, right)
   1398             (0.0, 0.5, 1.0, 1.5, 2.0)
   1399         """
-> 1400         return self.left._backslash_(right)

/usr/local/sage-5.6/local/lib/python2.7/site-packages/sage/matrix/ in sage.matrix.matrix2.Matrix._backslash_ (sage/matrix/matrix2.c:3658)()

/usr/local/sage-5.6/local/lib/python2.7/site-packages/sage/matrix/ in sage.matrix.matrix_double_dense.Matrix_double_dense.solve_right (sage/matrix/matrix_double_dense.c:11636)()

TypeError: vector of constants over Real Double Field incompatible with matrix over Real Double Field

I don't understand the final "imcompatibility" message: both the vector and the matrix are RDF type, so how could they be incompatible? This is a small version of a problem I encountered in the context of an attempt to demonstrate to a linear algebra class the computation time of solving systems of linear equations via LU factorization versus via matrix inversion by naive methods; to make the case for LU, I have to avoid various optimized algorithms built into SAGE. (Perhaps I should be using a call to LAPACK or something for this demonstration?)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-02-08 23:58:36 +0200

ppurka gravatar image

If you compare the documentation of the methods A.solve_right? when A is a matrix over QQ and when A is a matrix over RDF, you will find that the former allows B to be a matrix, but the latter does not. Only vectors are supported/implemented for RDF fields. As such it is not a bug, but I think this should raise a NotImplementedError when a matrix B is is used over RDF A.

edit flag offensive delete link more


I agree - open a ticket and be sure to cc rbeezer on it, who would be very interested in at least raising the error, if not even implementing it.

kcrisman gravatar imagekcrisman ( 2013-02-09 08:54:36 +0200 )edit

It's [#14087](

ppurka gravatar imageppurka ( 2013-02-09 10:00:15 +0200 )edit

patch posted there...

Jason Grout gravatar imageJason Grout ( 2013-02-12 11:09:01 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-02-08 21:53:18 +0200

Seen: 714 times

Last updated: Feb 08 '13