JuliaAstroSim/PhysicalParticles.jl

`uconvert(PVector, units)` not typestable

Closed this issue ยท 3 comments

I have a problem regarding unit conversion which seems to change the datatype.

For example:

source_units = getuVel(uGadget2);
target_units = getuVel(uAstro);
v = PVector(3.f0, 3.f0, 4.f0, source_units);
println(typeof(uconvert(target_units, v.x)))
     Quantity{Float64, ๐‹ ๐“^-1, Unitful.FreeUnits{(Gyr^-1, kpc), ๐‹ ๐“^-1, nothing}}

but I'd like it to stay a Float32.

See JuliaAstroSim/AstroIO.jl#10 (comment)

type instability comes from UnitfulAstro:

julia> using Unitful, UnitfulAstro

julia> a = 1.0f0u"kpc/Gyr"
โ”Œ Warning: Symbol Gyr was found in multiple registered unit modules.
โ”‚ We will use the one from UnitfulAstro.
โ”” @ Unitful E:\.julia\packages\Unitful\9janP\src\user.jl:589
1.0f0 kpc Gyr^-1

julia> b = uconvert(u"km/s", a)
0.9777922216807892 km s^-1

julia> typeof(b)
Quantity{Float64, ๐‹  ๐“ ^-1, Unitful.FreeUnits{(km, s^-1), ๐‹  ๐“ ^-1, nothing}

type instability comes from UnitfulAstro

Yes, you're right

It requires changes upstream to Unitful.
See PainterQubits/Unitful.jl#190.

For now I'll just cast each component separately