Skip to content

floor, ceil, round called with (::Type{T}, ::SArray) allocates #992

@jaemolihm

Description

@jaemolihm
using BenchmarkTools, StaticArrays
x = SVector(0., 1.)
@btime round.(Int, $x) # 11.817 ns (1 allocation: 16 bytes)
@btime floor.(Int, $x) # 11.723 ns (1 allocation: 16 bytes)
@btime ceil.(Int, $x) # 11.754 ns (1 allocation: 16 bytes)

There seems to be no type instability.

julia> @code_warntype round.(Int, x)
MethodInstance for (::var"##dotfunction#439#69")(::Type{Int64}, ::SVector{2, Float64})
  from (::var"##dotfunction#439#69")(x1, x2) in Main
Arguments
  #self#::Core.Const(var"##dotfunction#439#69"())
  x1::Core.Const(Int64)
  x2::SVector{2, Float64}
Body::SVector{2, Int64}
1%1 = Base.broadcasted(Main.round, x1, x2)::Base.Broadcast.Broadcasted{StaticArrays.StaticArrayStyle{1}, Nothing, typeof(round), Tuple{Base.RefValue{Type{Int64}}, SVector{2, Float64}}}
│   %2 = Base.materialize(%1)::SVector{2, Int64}
└──      return %2
julia> versioninfo()
Julia Version 1.7.0
Commit 3bf9d17731 (2021-11-30 12:12 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E5-2630 v3 @ 2.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, haswell)
Environment:
  JULIA = /home/jmlim/appl/julia-1.7.0/bin/julia

(@v1.7) pkg> status StaticArrays
      Status `~/.julia/environments/v1.7/Project.toml`
  [90137ffa] StaticArrays v1.3.4

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