This is a bug but I am not sure on which side. The convert function is
wrong because it does not create the type that is passed. But maybe Julia
should not create the immutable type when seeing this.
Could you please file a bug on the ImmutableArrays.jl project page? I will
file one on the Julia bug tracker.
Cheers
Tobi
Am Freitag, 15. August 2014 11:02:01 UTC+2 schrieb Jan Kybic:
>
> Dear all,
>
> I am seeing an unexpected behaviour when combining ImmutableArrays and
> struct like types (I forgot what the proper name is). In particular, the
> following code:
>
> using ImmutableArrays
>
> immutable Mytype
> pos::Vector2{Float32}
> end
>
> println(Mytype([4.; 5.]))
>
>
> incorrectly prints "Mytype(Float32[0.0,2.25])" instead of the expected
> "Mytype(Float32[4.0,5.0])". This is on the latest Ubuntu,
> Julia 0.3.0-prerelease+3628 (2014-06-11 15:07 UTC).
>
> Both "Mytype([4f0; 5f0])" and "convert(Vector2{Float32},[4.;5.])" work as
> expected but changing "immutable" to "type" does not change the error.
>
> So is there a bug in ImmutableArrays, in Julia, or am I doing something
> wrong? If I am doing something wrong, I would at least expect a warning -
> this error cost me quite some time to find out.
>
> Maybe I do not understand how ImmutableArrays is supposed to work, since
>
> typeof(convert(Vector2{Float32},[4.;5.]).e1)
>
> gives Float64, not Float32 as expected. So is ImmutableArrays actually an
> efficient way of storing fixed-size vectors? Or do I have to stick to
> Float64 even if I do not need the accuracy?
>
>
> Thank you for your help. Yours,
>
>
> Jan
>
>