Thanks for the reference, I'll give it a try!
Op vrijdag 5 augustus 2016 15:36:03 UTC+2 schreef Erik Schnetter: > > Pieterjan > > Depending on your needs, <https://github.com/eschnett/FlexibleArrays.jl> > might also be a solution. It supports arrays where the size is known at > compile time. > > -erik > > On Fri, Aug 5, 2016 at 6:20 AM, Pieterjan Robbe <[email protected] > <javascript:>> wrote: > >> Accord to >> http://docs.julialang.org/en/release-0.4/manual/performance-tips/#avoid-fields-with-abstract-containers, >> >> this is the way to go for types with a container field: >> >> type MyVector{T<:AbstractFloat,V<:AbstractVector} >> v::V >> >> MyVector(v::AbstractVector{T}) = new(v) >> end >> MyVector(v::AbstractVector) = MyVector{eltype(v),typeof(v)}(v) >> >> This is indeed type-stable: >> >> @code_warntype MyVector(0:0.1:1) >> >> However, If I also want to parametrize my type in the vector length L like >> >> type MySecondVector{L,T<:AbstractFloat,V<:AbstractVector} >> v::V >> >> MySecondVector(v::AbstractVector{T}) = new(v) >> end >> MySecondVector(v::AbstractVector) = >> MySecondVector{length(v),eltype(v),typeof(v)}(v) >> >> This is no longer type-stable: >> >> @code_warntype MySecondVector(0:0.1:1) >> >> Can I enforce the length as a parameter so that this is known to the >> compiler or should I look into FixedSizeArrays instead? >> > > > > -- > Erik Schnetter <[email protected] <javascript:>> > http://www.perimeterinstitute.ca/personal/eschnetter/ >
