Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

backslash operator on RDF matrices

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)
   1401 
   1402 

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

/usr/local/sage-5.6/local/lib/python2.7/site-packages/sage/matrix/matrix_double_dense.so 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?)