One more puzzle:
julia> function cross3!(
result::AbstractVector{T1},
theta::AbstractVector{T2},
v::Tuple{T3, T3, T3},
) where {T1, T2, T3}
@assert (length(theta) == 3) && (length(v) == 3) "Inputs must be 3-vectors"
result[1] = -theta[3] * v[2] + theta[2] * v[3]
result[2] = theta[3] * v[1] - theta[1] * v[3]
result[3] = -theta[2] * v[1] + theta[1] * v[2]
return result
end
cross3! (generic function with 1 method)
julia>
julia> @time cross3!(rand(3), rand(3), (1.0, 0.0, 0.0))
0.000003 seconds (2 allocations: 160 bytes)
3-element Vector{Float64}:
0.00000e+00
9.03374e-01
-2.03397e-01
julia> @code_warntype cross3!(rand(3), rand(3), (1.0, 0.0, 0.0))
MethodInstance for cross3!(::Vector{Float64}, ::Vector{Float64}, ::Tuple{Float64, Float64, Float64})
from cross3!(result::AbstractVector{T1}, theta::AbstractVector{T2}, v::Tuple{T3, T3, T3}) where {T1, T2, T3} @ Main REPL[3]:1
Static Parameters
T1 = Float64
T2 = Float64
T3 = Float64
Arguments
#self#::Core.Const(cross3!)
result::Vector{Float64}
theta::Vector{Float64}
v::Tuple{Float64, Float64, Float64}
Body::Vector{Float64}
1 ─ %1 = Main.length(theta)::Int64
│ %2 = (%1 == 3)::Bool
└── goto #4 if not %2
2 ─ %4 = Main.length(v)::Core.Const(3)
│ %5 = (%4 == 3)::Core.Const(true)
└── goto #4 if not %5
3 ─ goto #5
4 ┄ %8 = Base.AssertionError("Inputs must be 3-vectors")::Core.Const(AssertionError("Inputs must be 3-vectors"))
└── Base.throw(%8)
5 ┄ %10 = Base.getindex(theta, 3)::Float64
│ %11 = -%10::Float64
│ %12 = Base.getindex(v, 2)::Float64
│ %13 = (%11 * %12)::Float64
│ %14 = Base.getindex(theta, 2)::Float64
│ %15 = Base.getindex(v, 3)::Float64
│ %16 = (%14 * %15)::Float64
│ %17 = (%13 + %16)::Float64
│ Base.setindex!(result, %17, 1)
│ %19 = Base.getindex(theta, 3)::Float64
│ %20 = Base.getindex(v, 1)::Float64
│ %21 = (%19 * %20)::Float64
│ %22 = Base.getindex(theta, 1)::Float64
│ %23 = Base.getindex(v, 3)::Float64
│ %24 = (%22 * %23)::Float64
│ %25 = (%21 - %24)::Float64
│ Base.setindex!(result, %25, 2)
│ %27 = Base.getindex(theta, 2)::Float64
│ %28 = -%27::Float64
│ %29 = Base.getindex(v, 1)::Float64
│ %30 = (%28 * %29)::Float64
│ %31 = Base.getindex(theta, 1)::Float64
│ %32 = Base.getindex(v, 2)::Float64
│ %33 = (%31 * %32)::Float64
│ %34 = (%30 + %33)::Float64
│ Base.setindex!(result, %34, 3)
└── return result
```
Can you see any place where 80 bytes will need to be allocated?