Keno / SIUnits.jl

Efficient unit-checked computation
Other
70 stars 26 forks source link

Support `linspace` #79

Open ssfrr opened 8 years ago

ssfrr commented 8 years ago

I recently tried getting a SIQuantity range using linspace, but it's not supported:

julia> using SIUnits
julia> using SIUnits.ShortUnits
julia> linspace(0s, 10s, 100)
ERROR: MethodError: `linspace` has no method matching linspace(::SIUnits.SIQuantity{Int64,0,0,1,0,0,0,0,0,0}, ::SIUnits.SIQuantity{Int64,0,0,1,0,0,0,0,0,0}, ::Int64)
Closest candidates are:
  linspace{T<:AbstractFloat}(::T<:AbstractFloat, ::T<:AbstractFloat, ::Real)
  linspace(::Real, ::Real, ::Real)
  linspace{T<:ColorTypes.Color{T,N}}(::T<:ColorTypes.Color{T,N}, ::T<:ColorTypes.Color{T,N}, ::Any)

I started looking into an implementation but it looks like you already went through this with Range, and decided to re-implement all the Range stuff with SIRange, so I figured I'd get some early feedback. Do you think that's the best way forward with LinSpace as well? I assume there must be use cases for non-Real SIUnit values or else you would have just made SIQuantity{T<:Real, ...} <: Real instead of the more general Number, right?

I have a feeling that this is an application where the Trait / abstract interface stuff will provide a cleaner solution, so another option might just be to wait until that settles down.

ChrisRackauckas commented 8 years ago

Ran into this issue (see the linked issue). Is linspace support planned?

timholy commented 8 years ago

Relevant: https://github.com/JuliaLang/julia/pull/17408

Unitful avoids defining linspace because of similar difficulties. I really do suspect we need a LinSpaces package.