No. Using Array{T2}
is completely fine. The issue is the literal. If you look at the code_warntype
julia> @code_warntype test(A(1., 2., 3., 4.), [0.0; 1.0; 0.0])
Variables:
a::A{Float64}
w::Array{Float64,1}
Ω::Any
Body:
begin
NewvarNode(:(Ω::Any))
unless (Base.not_int)(((Base.arraylen)(w::Array{Float64,1})::Int64 === 3)::Bool)::Bool goto 5
#= line 4 =#
(Main.throw)(Main.ArgumentError)::Union{}
5:
#= line 7 =#
$(Expr(:static_parameter, 1))
SSAValue(0) = (Core.tuple)(0, (Base.neg_float)((Base.arrayref)(true, w::Array{Float64,1}, 1)::Float64)::Float64, (Base.neg_float)((Base.arrayref)(true, w::Array{Float64,1}, 2)::Float64)::Float64, (Base.neg_float)((Base.arrayref)(true, w::Array{Float64,1}, 3)::Float64)::Float64, (Base.arrayref)(true, w::Array{Float64,1}, 1)::Float64, 0, (Base.arrayref)(true, w::Array{Float64,1}, 3)::Float64, (Base.neg_float)((Base.arrayref)(true, w::Array{Float64,1}, 2)::Float64)::Float64, (Base.arrayref)(true, w::Array{Float64,1}, 2)::Float64, (Base.neg_float)((Base.arrayref)(true, w::Array{Float64,1}, 3)::Float64)::Float64, 0, (Base.arrayref)(true, w::Array{Float64,1}, 1)::Float64, (Base.arrayref)(true, w::Array{Float64,1}, 3)::Float64, (Base.arrayref)(true, w::Array{Float64,1}, 2)::Float64, (Base.neg_float)((Base.arrayref)(true, w::Array{Float64,1}, 1)::Float64)::Float64, 0)::Tuple{Int64,Float64,Float64,Float64,Float64,Int64,Float64,Float64,Float64,Float64,Int64,Float64,Float64,Float64,Float64,Int64}
SSAValue(1) = (Core._apply)(Base.promote_typeof, SSAValue(0))::Any
Ω::Any = (Array{Float64,N} where N)((Base.typed_hvcat)(SSAValue(1), (4, 4, 4, 4), (Core.getfield)(SSAValue(0), 1)::Int64, (Core.getfield)(SSAValue(0), 2)::Float64, (Core.getfield)(SSAValue(0), 3)::Float64, (Core.getfield)(SSAValue(0), 4)::Float64, (Core.getfield)(SSAValue(0), 5)::Float64, (Core.getfield)(SSAValue(0), 6)::Int64, (Core.getfield)(SSAValue(0), 7)::Float64, (Core.getfield)(SSAValue(0), 8)::Float64, (Core.getfield)(SSAValue(0), 9)::Float64, (Core.getfield)(SSAValue(0), 10)::Float64, (Core.getfield)(SSAValue(0), 11)::Int64, (Core.getfield)(SSAValue(0), 12)::Float64, (Core.getfield)(SSAValue(0), 13)::Float64, (Core.getfield)(SSAValue(0), 14)::Float64, (Core.getfield)(SSAValue(0), 15)::Float64, (Core.getfield)(SSAValue(0), 16)::Int64)::Any)::Any
#= line 13 =#
return ((Ω::Any / 2)::Any * $(Expr(:invoke, MethodInstance for vcat(::Float64, ::Float64, ::Float64, ::Vararg{Float64,N} where N), :(Main.vcat), :((Core.getfield)(a, :a)::Float64), :((Core.getfield)(a, :b)::Float64), :((Core.getfield)(a, :c)::Float64), :((Core.getfield)(a, :d)::Float64)))::Array{Float64,1})::Any
end::Any
You’ll notice that Any
appears BEFORE you calling the array constructor. It’s hitting the tuple size limit here when computing the eltype for the literal.