Skip to content

Allocations when using mul! + transpose #770

Closed
JuliaLang/julia
#37892
@rvignolo

Description

@rvignolo

Hi!

I have been looking at this and cannot figure out if this is an issue or is expected behaviour:

julia> using LinearAlgebra
julia> using BenchmarkTools

julia> @btime mul!(cache, mat, transpose(mat)) setup=(N=3; mat=rand(N,N); cache=zeros(N,N))
  59.471 ns (1 allocation: 16 bytes)
3×3 Array{Float64,2}:
 2.2594   1.68041  1.98825
 1.68041  1.56487  1.46579
 1.98825  1.46579  1.75028

julia> @btime mul!(cache, mat, transpose(mat)) setup=(N=4; mat=rand(N,N); cache=zeros(N,N))
  282.589 ns (0 allocations: 0 bytes)
4×4 Array{Float64,2}:
 1.21238   0.646434  0.315025  0.831406
 0.646434  0.829583  0.355537  0.450968
 0.315025  0.355537  0.241286  0.398706
 0.831406  0.450968  0.398706  1.09966

For N = 3 there are allocations and for N = 4 there are not. For N = 2 there are also the same amount of allocations as for N = 3. For all the other cases I tested, there are not allocations.

julia> versioninfo()
Julia Version 1.5.0
Commit 96786e22cc (2020-08-01 23:44 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.7.0)
  CPU: Intel(R) Core(TM) i7-4558U CPU @ 2.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, haswell)
Environment:
  JULIA_EDITOR = "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code"
  JULIA_NUM_THREADS =

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions