First time here? Check out the FAQ!

Ask Your Question
0

empty matrix

asked 12 years ago

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)?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
2

answered 12 years ago

Jason Grout gravatar image

updated 12 years ago

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!

Preview: (hide)
link
1

answered 12 years ago

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])
()
Preview: (hide)
link

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: 12 years ago

Seen: 1,446 times

Last updated: Feb 01 '13