Kronecker.jl icon indicating copy to clipboard operation
Kronecker.jl copied to clipboard

Sum of kroneckers

Open MichielStock opened this issue 4 years ago • 3 comments
trafficstars

Lazily working with sums of Kronecker products: A ⊗ B + C ⊗ D, in response to #76

MichielStock avatar Jan 03 '21 11:01 MichielStock

conceptually this works, but I am observing very low performance when nesting with another kronecker product, reproduced in the following example:

julia> A=kronecker(ones(100,100),ones(100,100))
julia> C=ones(2,2)

julia> @time kronecker(A+A,C)*ones(20000);
  3.457423 seconds (18 allocations: 469.594 KiB)
julia> @time (kronecker(A,C)+kronecker(A,C))*ones(20000);
  0.015021 seconds (27 allocations: 627.781 KiB)
julia> @time kronecker(2*A,C)*ones(20000);
  0.006633 seconds (13 allocations: 313.859 KiB)

vsaase avatar Jan 04 '21 17:01 vsaase

Yes, it cannot access the fast multiplication this way. I have added a naive decomposition for this, so your examples is now:

julia> @time kronecker(A+A,C)*ones(20000);
  0.011665 seconds (41.67 k allocations: 2.837 MiB)

julia> @time (kronecker(A,C)+kronecker(A,C))*ones(20000);
  0.008346 seconds (41.67 k allocations: 2.837 MiB)

julia> @time kronecker(2*A,C)*ones(20000);
  0.004133 seconds (20.84 k allocations: 1.495 MiB)

Though I made a small example in the test, which throws an error. Definitely something fishy still!

MichielStock avatar Jan 18 '21 20:01 MichielStock

Codecov Report

Merging #77 (50152bc) into master (0b6bbcc) will decrease coverage by 0.55%. The diff coverage is 96.15%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #77      +/-   ##
==========================================
- Coverage   90.76%   90.20%   -0.56%     
==========================================
  Files          11       12       +1     
  Lines         617      643      +26     
==========================================
+ Hits          560      580      +20     
- Misses         57       63       +6     
Impacted Files Coverage Δ
src/Kronecker.jl 100.00% <ø> (ø)
src/sums.jl 96.15% <96.15%> (ø)
src/vectrick.jl 90.47% <0.00%> (-3.97%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 8608af6...50152bc. Read the comment docs.

codecov-io avatar Jan 24 '21 14:01 codecov-io