ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 12 Feb 2013 04:09:01 -0600backslash operator on RDF matriceshttp://ask.sagemath.org/question/9787/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?)Fri, 08 Feb 2013 14:53:18 -0600http://ask.sagemath.org/question/9787/backslash-operator-on-rdf-matrices/Answer by ppurka for <p>I've discovered that the backslash operator produces a weird type error when used on matrices with Real Double Field entries:</p>
<pre><code>----------------------------------------------------------------------
| 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
</code></pre>
<p>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?)</p>
http://ask.sagemath.org/question/9787/backslash-operator-on-rdf-matrices/?answer=14530#post-id-14530If 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`.Fri, 08 Feb 2013 16:58:36 -0600http://ask.sagemath.org/question/9787/backslash-operator-on-rdf-matrices/?answer=14530#post-id-14530Comment by ppurka for <p>If you compare the documentation of the methods <code>A.solve_right?</code> when <code>A</code> is a matrix over <code>QQ</code> and when <code>A</code> is a matrix over <code>RDF</code>, you will find that the former allows <code>B</code> 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 <code>NotImplementedError</code> when a matrix <code>B</code> is is used over RDF <code>A</code>.</p>
http://ask.sagemath.org/question/9787/backslash-operator-on-rdf-matrices/?comment=18264#post-id-18264It's [#14087](http://trac.sagemath.org/sage_trac/ticket/14087).Sat, 09 Feb 2013 03:00:15 -0600http://ask.sagemath.org/question/9787/backslash-operator-on-rdf-matrices/?comment=18264#post-id-18264Comment by Jason Grout for <p>If you compare the documentation of the methods <code>A.solve_right?</code> when <code>A</code> is a matrix over <code>QQ</code> and when <code>A</code> is a matrix over <code>RDF</code>, you will find that the former allows <code>B</code> 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 <code>NotImplementedError</code> when a matrix <code>B</code> is is used over RDF <code>A</code>.</p>
http://ask.sagemath.org/question/9787/backslash-operator-on-rdf-matrices/?comment=18246#post-id-18246patch posted there...Tue, 12 Feb 2013 04:09:01 -0600http://ask.sagemath.org/question/9787/backslash-operator-on-rdf-matrices/?comment=18246#post-id-18246Comment by kcrisman for <p>If you compare the documentation of the methods <code>A.solve_right?</code> when <code>A</code> is a matrix over <code>QQ</code> and when <code>A</code> is a matrix over <code>RDF</code>, you will find that the former allows <code>B</code> 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 <code>NotImplementedError</code> when a matrix <code>B</code> is is used over RDF <code>A</code>.</p>
http://ask.sagemath.org/question/9787/backslash-operator-on-rdf-matrices/?comment=18267#post-id-18267I 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.Sat, 09 Feb 2013 01:54:36 -0600http://ask.sagemath.org/question/9787/backslash-operator-on-rdf-matrices/?comment=18267#post-id-18267