Ask Your Question
0

empty matrix

asked 2013-02-01 02:43:52 -0500

Mathmon gravatar image

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 flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2013-02-01 04:08:02 -0500

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])
()
edit flag offensive delete link more
2

answered 2013-02-01 13:45:08 -0500

Jason Grout gravatar image

updated 2013-02-01 13:52:47 -0500

DSM gravatar image

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!

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2013-02-01 02:43:52 -0500

Seen: 474 times

Last updated: Feb 01 '13