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

Unit type computations #164

Open
ChrisRackauckas opened this issue Sep 30, 2018 · 3 comments
Open

Unit type computations #164

ChrisRackauckas opened this issue Sep 30, 2018 · 3 comments

Comments

@ChrisRackauckas
Copy link
Contributor

It would be nice to be able to compute on the type directly:

using Unitful
uType = typeof(1u"kg")
tType = typeof(1u"s")
uType/tType

This would allow the computation of where types as well:

using Unitful
uBottomEltype = Unitful.Quantity{Float64,D,U} where U where D
tType = typeof(1u"s")
uBottomEltype/tType

Currently, handling recursive arrays is incompatible with Unitful due to the inability to do this calculation.

@ajkeller34
Copy link
Collaborator

In principle I agree that such a calculation should be possible at compile time. However, it feels like a pun to define division on types, and may also count as type piracy. Jeff has signaled that overloading Base.show(::IO, ::Type{<:Quantity}) is somehow not great for reasons I'm not clear on (see e.g. Keno/SIUnits.jl#113 (comment)), so I imagine Base. /(::Type{<:Quantity}, ::Type{<:Quantity}) would be objectionable as well. Can you provide more information on what you're trying to do with recursive arrays?

@ChrisRackauckas
Copy link
Contributor Author

I am trying to compute the element type of an array of arrays, and the element type may be a non-concrete Quantity if the array has multiple different unit types.

However, it feels like a pun to define division on types, and may also count as type piracy.

No, it's not type-piracy because it would have dispatches on Quantity types only. Overloading Base.show is different and to do it is complicated and that's what's mentioned there, not anything to do with overloading other functions with Type{<:Quantity}.

I think there are better precidents to looks at. You can take an eltype of an array type. You can get the real part of a type too. For example:

julia> A = Array{Complex{Float64}}
Array{Complex{Float64},N} where N

julia> eltype(A)
Complex{Float64}

julia> real(eltype(A))
Float64

Being able to then similarly do calculations on units would allow one to build arrays before computing all of the values.

@ajkeller34
Copy link
Collaborator

Yes, those are better examples. I'll try it out.

ajkeller34 added a commit that referenced this issue Oct 1, 2018
ajkeller34 added a commit that referenced this issue Oct 1, 2018
ajkeller34 added a commit that referenced this issue Oct 1, 2018
ajkeller34 added a commit that referenced this issue Oct 17, 2018
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