# empty matrix

Hello all,

I am currently implementing a numerical algorithm and I need to do a lot of matrix manipulations. I often use submatrices via B[m:,:]. The problem is that this operation occasionally yield 0xn matrices. Unfortunately those are handled like 0x0 matrices so I can't multiply them by vectors:

sage: identity_matrix(RDF, 4)[3:,:] * vector(RDF, 4)
(0.0)
sage: identity_matrix(RDF, 4)[4:,:] * vector(RDF, 4)
TypeError: unsupported operand parent(s) for '*':
'Full MatrixSpace of 0 by 0 dense matrices over Real Double Field'
and 'Vector space of dimension 4 over Real Double Field'


I think that the latter operation should be supported and yielding a vector of length 0. Can I force this kind of behaviour (maybe using numpy instead)?

edit retag close merge delete

Sort by » oldest newest most voted

This is indeed a bug. I've posted a fix here: trac #14049, which needs review. The problem was a faulty optimization, and it's a one-line fix. You could try applying it to your version of Sage, if you wanted. Thanks for reporting this!

more

As you note, using mat[m:,:] can give the wrong size matrix. This is perhaps a bug.

sage: identity_matrix(RDF, 4)[4:,:].nrows()
0
sage: identity_matrix(RDF, 4)[4:,:].ncols()
0


If you use the submatrix method instead, you will get matrices of the correct size:

sage: identity_matrix(RDF, 4).submatrix(4,0,0,4).nrows()
0
sage: identity_matrix(RDF, 4).submatrix(4,0,0,4).ncols()
4
sage: identity_matrix(RDF, 4).submatrix(4,0,0,4) * vector([1,2,3,4])
()

more

## Stats

Seen: 388 times

Last updated: Feb 01 '13