This may or may not be relevant.
abstract UnsignedVector
type VectorOfUnsigned{T<:Unsigned} <: UnsignedVector
vec::Vector{T}
end
Base.eltype{T<:Unsigned}(x::VectorOfUnsigned{T}) = T
Base.show{T<:Unsigned}(io::IO, x::VectorOfUnsigned{T}) = show(io, x.vec)
Base.length{T<:Unsigned}(x::VectorOfUnsigned{T}) = length(x.vec)
Base.getindex{T<:UnsignedVector}(x::T, i::Int) = getindex(x.vec, i)
length_plus_one{T<:UnsignedVector}(x::T) = length(x) + 1
u8s = VectorOfUnsigned([ 0x01, 0x02, 0x03, 0x04 ] )
u16s = VectorOfUnsigned([ 0x0001, 0x0002, 0x0003 ] )
println([eltype(u8s), eltype(u16s)])
println([length_plus_one(u8s), length_plus_one(u16s)])
getindex(u8s,2), getindex(u16s,2)
On Tuesday, March 1, 2016 at 11:40:10 PM UTC-5, Scott Jones wrote:
>
> I've been running into the same issue myself recently, thanks for all the
> exploration here of the different ways of attacking the problem.
> In my case, I need the type of a vector to change, i.e. from UInt8,
> UInt16,... up to UInt64, depending on the data, so unlike your case, I
> can't use reshape.
> This is an internal structure, so I'm not sure if it should be exposed in
> the type parameters, and for performance, I need the type (a form of Dict)
> to be concrete.
> Do you think going very low-level and just defining it always as a
> Vector{UInt8}, and using a pointer (reinterpreted to the correct type) and
> unsafe_load() would
> perform well and handle the problem?
>
> On Tuesday, March 1, 2016 at 5:42:31 PM UTC+1, Kristoffer Carlsson wrote:
>>
>> Just an update. Having an extra "linear dependent" parameter turned out
>> to be a bit of a pain, for example when you want to make containers of the
>> type because if you don't parametrize on all parameters you no longer have
>> a concrete type. Just using a Vector and calling reshape when needed turned
>> out to be smoother.
>
>