Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uconvert(PVector, units) not typestable #27

Closed
elehcim opened this issue Nov 29, 2021 · 3 comments
Closed

uconvert(PVector, units) not typestable #27

elehcim opened this issue Nov 29, 2021 · 3 comments

Comments

@elehcim
Copy link
Contributor

elehcim commented Nov 29, 2021

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)

@elehcim elehcim changed the title typestable uconvert(PVector, units) uconvert(PVector, units) not typestable Nov 29, 2021
@islent
Copy link
Member

islent commented Nov 29, 2021

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}

@elehcim
Copy link
Contributor Author

elehcim commented Nov 29, 2021

type instability comes from UnitfulAstro

Yes, you're right

@elehcim
Copy link
Contributor Author

elehcim commented Dec 6, 2021

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

For now I'll just cast each component separately

@elehcim elehcim closed this as completed Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants