-
Notifications
You must be signed in to change notification settings - Fork 30
Open
Description
Here's something I was trying to do recently, to avoid materializing a huge array just to sum it:
V = rand(500);
V3 = reshape(V, 1,1,:);
@time sum(V .* V' .* V3) # 0.57 seconds, 953.675 MiB
@time sum(BroadcastArray(*, V, V', V3)) # 0.36 seconds
@time sum(BroadcastArray(*, V, V', V3), dims=(1,2,3))[1] # 0.014 seconds
Might it be worth making sum()
simply call the dims=...
version here?
Before I saw this package I was messing around with broadcasting to do this by hand, and could get in the ballpark of 0.014s here, but no better. Doing that seems likely to be more fragile.
Metadata
Metadata
Assignees
Labels
No labels