Return type of blockdiag?

I was studying the type stability of my code (I’m still very bad at it) and I bumped into this weird behavior with SparseArrays.blockdiag():

julia> using SparseArrays
julia> A = [sprand(100, 100, .1) for i = 1: 15]; @code_warntype blockdiag(A...);


But if I make a 16-element array (or bigger)

julia> A = [sprand(100, 100, .1) for i = 1: 16]; @code_warntype blockdiag(A...);

Body::SparseMatrixCSC{_1,_2} where _2 where _1

I’m omitting the complete output of @code_warntype, but you can easily get it on your computer.

The size of the sparse matrices doesn’t seem to affect the behavior.

What is going on here?

Seems like your hitting a heuristic cutoff in the compiler. AFAIU, these cutoffs are sometimes necessary to avoid long (or even endless) compilation times.

Hopefully someone more qualified will answer your question in more detail.

1 Like