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

Offset matrix multiplication via `generic_matmatmul!`

Open mcabbott opened this issue 3 years ago • 1 comments
trafficstars

This is meant to work with https://github.com/JuliaLang/julia/pull/43552, although I think mul! might work without that.

Alternative to #146. Since this does not overload *, I think it should not encounter the endless method ambiguities that tends to cause, against Adjoint matrices and other types. In fact I think other packages could overload generic_matmul! too in the same way, and each unwrap nicely, so long as they all only dispatch on the output C, which is created by similar.

This seems to cause one extra allocation and hence is slower than without offsets. I'm not so sure why, I thought MulAddMul(α,β) (whose type depends on the values of α,β) was the culprit, but in fact get similar times after avoiding that:

julia> for N in [3, 10, 100, 1000]
           @show N
           A, B, x = rand(N,N), rand(N,N), rand(N)
           @btime $A * $B
           A, B, x = OffsetArray(A,5,5), OffsetArray(B,5,5), OffsetArray(x,5)
           @btime $A * $B
       end
N = 3
  min 31.407 ns, mean 33.633 ns (1 allocation, 128 bytes)
  min 52.950 ns, mean 56.294 ns (2 allocations, 144 bytes)
N = 10
  min 180.901 ns, mean 200.923 ns (1 allocation, 896 bytes)
  min 209.057 ns, mean 225.422 ns (2 allocations, 912 bytes)
N = 100
  min 9.625 μs, mean 15.880 μs (2 allocations, 78.17 KiB)
  min 9.583 μs, mean 15.396 μs (3 allocations, 78.19 KiB)
N = 1000
  min 7.685 ms, mean 8.350 ms (2 allocations, 7.63 MiB)
  min 7.756 ms, mean 8.336 ms (3 allocations, 7.63 MiB)

Discussed briefly in this long discourse thread.

mcabbott avatar Dec 26 '21 15:12 mcabbott

Codecov Report

Merging #270 (816b928) into master (54ade62) will decrease coverage by 7.58%. The diff coverage is 3.57%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #270      +/-   ##
==========================================
- Coverage   96.52%   88.93%   -7.59%     
==========================================
  Files           5        6       +1     
  Lines         460      488      +28     
==========================================
- Hits          444      434      -10     
- Misses         16       54      +38     
Impacted Files Coverage Δ
src/OffsetArrays.jl 95.54% <0.00%> (-2.87%) :arrow_down:
src/linearalgebra.jl 3.70% <3.70%> (ø)
src/axes.jl 97.46% <0.00%> (-2.54%) :arrow_down:
src/utils.jl 96.00% <0.00%> (-2.00%) :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 54ade62...816b928. Read the comment docs.

codecov[bot] avatar Dec 28 '21 04:12 codecov[bot]