Hi Andy,
I don't know if you should do this, but you certainly can do it :-)
julia> type Thing{N}
a::Vector{Float64}
function Thing()
new(zeros(Float64, N))
end
end
julia> Thing{1}()
Thing{1}([0.0])
julia> Thing{5}()
Thing{5}([0.0,0.0,0.0,0.0,0.0])
I guess the relevant section in the manual is the one on parametric types
<http://julia.readthedocs.org/en/latest/manual/types/#man-parametric-types>,
which states that N in type Foo{N} ... end can be any type or an *integer*.
This is used for example by Array{T,N}, where N is the "dimension" of the
array.
Best,
Alex.
On Tuesday, 28 October 2014 16:47:56 UTC+1, Andrew Gibb wrote:
>
> Is there a way to create a parameterised type where the parameter
> describes the number of items, ie
> type Thing{N<:Integer}
> for i = 1:N
> a_i::Float64
> end
> end
>
> I realise one could achieve this simple example with an array, but I'm
> trying to create a type which holds scale space. My current thinking is
> this would consist of a parameterisable number of images each with a
> parameterisable number of layers. And each image in the sequence has the
> two spatial dimensions (not the number of layers) reduced by a factor of
> two.
>
> I guess you cold do some tricks with array packing, but I guess I'm
> looking for something more elegant. Is there any way to use the type
> parameter to indicate a number of elements in this way?
>
> Andy
>