You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using LinearAlgebra
using BlockDiagonals
blocksizes = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]
btimes = []
mtimes = []
for nblocks in blocksizes
b =BlockDiagonal([rand(1, 1) for _ in1:nblocks])
m =rand(nblocks, nblocks)
t =@benchmark$b[$nblocks, $nblocks]
push!(btimes, mean(t).time)
t =@benchmark$m[$nblocks, $nblocks]
push!(mtimes, mean(t).time)
endplot(blocksizes, btimes; label="BlockDiagonal", xlabel="matrix size", ylabel="time (ns)", title="execution time for getindex()")
plot!(blocksizes, mtimes; label="Matrix")
This scaling is a problem when BlockDiagonals hit fallback implementations for matrices which often use getindex. Example in the wild #116.
The reason for this is the implementation of getindex which iterates over the blocks to find the right location - the sizes of blocks are not known in advance.
One way to improve this relationship would be to store the cumulative block sizes in both dimensions, and then do a bisection search, which would bring the relationship to O(LogN)
The text was updated successfully, but these errors were encountered:
BlockArrays does something like this, where the array axis stores the block sizes. I wonder if it makes sense for BlockDiagonal to subtype an AbstractBlockArray?
This scaling is a problem when
BlockDiagonal
s hit fallback implementations for matrices which often usegetindex
. Example in the wild #116.The reason for this is the implementation of
getindex
which iterates over the blocks to find the right location - the sizes of blocks are not known in advance.One way to improve this relationship would be to store the cumulative block sizes in both dimensions, and then do a bisection search, which would bring the relationship to
O(LogN)
The text was updated successfully, but these errors were encountered: