Bug in BenchmarkTools?

Is this a bug, or am I missing something?

julia> using StaticArrays

julia> m = rand(SMatrix{3,3,Float64});

julia> f(m::SMatrix{N,N,T}) where {N,T} = SMatrix{N,N,T,N*N}(m[c] for c in CartesianIndices(m))
f (generic function with 1 method)

julia> f(m) # fine
3×3 SMatrix{3, 3, Float64, 9} with indices SOneTo(3)×SOneTo(3):
 0.256642   0.842059  0.421776
 0.408755   0.266084  0.887893
 0.0570036  0.402704  0.260989

julia> @btime f($m)
ERROR: MethodError: objects of type SVector{2, Float64} are not callable
Use square brackets [] for indexing an Array.

Works for me!

julia> using BenchmarkTools

julia> using StaticArrays

julia> m = rand(SMatrix{3,3,Float64});

julia> f(m::SMatrix{N,N,T}) where {N,T} = SMatrix{N,N,T,N*N}(m[c] for c in CartesianIndices(m))
f (generic function with 1 method)

julia> f(m) # fine
3×3 SMatrix{3, 3, Float64, 9} with indices SOneTo(3)×SOneTo(3):
 0.31864   0.478805  0.430077
 0.31005   0.541521  0.241841
 0.284379  0.569089  0.00424923

julia> @btime f($m)
  3.821 ns (0 allocations: 0 bytes)
3×3 SMatrix{3, 3, Float64, 9} with indices SOneTo(3)×SOneTo(3):
 0.31864   0.478805  0.430077
 0.31005   0.541521  0.241841
 0.284379  0.569089  0.00424923

julia> versioninfo()
Julia Version 1.8.5
Commit 17cfb8e65ea (2023-01-08 06:45 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 4 × Intel(R) Core(TM) i5-4258U CPU @ 2.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, haswell)
  Threads: 1 on 4 virtual cores
2 Likes

Yeah, tested here again in fresh sessions and it works now. It was probably a world-age problem.

1 Like