File Exchange

image thumbnail

Sparse block diagonal concatenation

version 1.1.0.0 (2.93 KB) by Rody Oldenhuis
Sparse version of BLKDIAG()

2 Downloads

Updated 10 Jun 2018

GitHub view license on GitHub

SPBLKDIAG Block diagonal concatenation of matrix input arguments, with sparse output.

Y = SPBLKDIAG(A,B,...) produces SPARSE(BLKDIAG(A, B, ..)) efficiently, where A, B, ... are matrices of class double (real or complex).

Basically, this is a thin wrapper around MATLAB's own BLKDIAG, since it already supports sparse output. However:

- BLKDIAG does not mention sparse support in its documentation; nor the fact that it is supported, nor how to access the functionality.

- BLKDIAG's name is inconsistent with the function names for any of MATLAB's other sparse functions (SPEYE, SPDIAGS, etc.)

Therefore, until The MathWorks fixes this, this function provides a better documented and more intuitively named alternative to BLKDIAG.

Comments and Ratings (5)

@Yutao Chen I'm sorry you feel this way. What blkdiag() does is call blkdiagmex() whenever it receives sparse input. This is (presumably) a C-MEX function that is as fast as it will get without sacrificing generality. What my function does is cast only the smallest matrix to sparse(), and then call blkdiag() which immediately calls blkdiagmex() because it sees a sparse matrix...I don't see how that can be done any faster. If you can give an example of inputs that make this function slow, I can perhaps analyze the problem and improve things a bit.

Yutao Chen

I'd like to see a function that can concatnate sparse matrix into a block diagonal matrix EFFICIENTLY!
A Simply wrapper of the sparse and blkdiag functions is not efficient.
I think a good implementation requires spdiag, with some careful coding.

Please, people, 1 or 2 star ratings tell me nothing. Please leave a message, however brief, so that I can improve/update/remove my code.

Updates

1.1.0.0

fixed typos in the description.

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux