I have a problem where I want to collect an Array of vectors as I perform an iteration. Something like this:
function foo(x::Vector{Float64}, size::Int8)
tmat = SMatrix{4,4}{Float64}(eye(4))
tmatrices = Array{SMatrix{4,4}{Float64}}(size)
for j=1:size
tmatrices[j] = bar(x[j])
tmat *= tmatrices[j]
end
return tmat, tmatrices;
end
function bar(x)
return eye(4)
end
where SMatrix is a Static Arrays type. When I run this using @code_warntype, Julia complains that tmat is of an abstract type:
tmat::Any = SSAValue(4) # line 5:
tmatrices::Array{StaticArrays.SArray{Tuple{4,4},Float64,2,L} where L,1} = $(Expr(:foreigncall, :(:jl_alloc_array_1d), Array{StaticArrays.SArray{Tuple{4,4},Float64,2,L} where L,1}, svec(Any, Int64), Array{StaticArrays.SArray{Tuple{4,4},Float64,2,L} where L,1}, 0, 5, 0)) # line 6:
SSAValue(6) = (Base.select_value)((Base.sle_int)(1, size::Int64)::Bool, size::Int64, (Base.sub_int)(1, 1)::Int64)::Int64
#temp#@_5::Int64 = 1
35:
unless (Base.not_int)((#temp#@_5::Int64 === (Base.add_int)(SSAValue(6), 1)::Int64)::Bool)::Bool goto 48
SSAValue(7) = #temp#@_5::Int64
SSAValue(8) = (Base.add_int)(#temp#@_5::Int64, 1)::Int64
j::Int64 = SSAValue(7)
#temp#@_5::Int64 = SSAValue(8) # line 7:
SSAValue(2) = $(Expr(:invoke, MethodInstance for eye(::Type{Float64}, ::Int64, ::Int64), :(Base.eye), Float64, 4, 4))
$(Expr(:invoke, MethodInstance for setindex!(::Array{StaticArrays.SArray{Tuple{4,4},Float64,2,L} where L,1}, ::Array{Float64,2}, ::Int64), :(Main.setindex!), :(tmatrices), SSAValue(2), :(j))) # line 8:
tmat::Any = (tmat::Any * (Base.arrayref)(tmatrices::Array{StaticArrays.SArray{Tuple{4,4},Float64,2,L} where L,1}, j::Int64)::StaticArrays.SArray{Tuple{4,4},Float64,2,L} where L)::Any
46:
goto 35
48: # line 10:
return (Core.tuple)(tmat::Any, tmatrices::Array{StaticArrays.SArray{Tuple{4,4},Float64,2,L} where L,1})::Tuple{Any,Array{StaticArrays.SArray{Tuple{4,4},Float64,2,L} where L,1}}
end::Tuple{Any,Array{StaticArrays.SArray{Tuple{4,4},Float64,2,L} where L,1}}
Why?