-
Notifications
You must be signed in to change notification settings - Fork 112
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
Base overrides #9
Comments
I'm certainly interested in updating Unitful and addressing these issues. Of course, I would be delighted to have this package be used broadly. To be honest about my bandwidth, I am doing an experimental physics postdoc, with all that entails. That being said, the initial reason I wrote Unitful in the first place was because I figured that Keno Fischer would be busy or more interested in working on higher profile projects like Gallium or Cxx for the foreseeable future. I wanted units functionality for my measurement and CAD code, and it didn't seem like SIUnits would be updated anytime soon. That was just my reading of the tea leaves, and I could be wrong. Do you have some timeline in mind for when you would want Unitful to be stable and fully functional? Here are some replies to your concerns:
Anyway, I hope this is helpful to you regardless of which package you choose to use. |
Thanks for your reply. Would be worth bringing @Keno into this, if he has a few CPU cycles to spare on this discussion. IMO there's little point in there being two packages with similar design, so it would be great to come to some kind of consensus. |
BTW, at this point the thought of modifying base to make this work better is a non-starter, since 0.5 just went into feature freeze. It would have to be after 0.6 development starts, and that won't hit widespread usage for months. So realistically I think the better option is to go with what's in base and see how much of your desired functionality one can get. |
Alright, I'll see what breaks if I don't redefine anything in base. Probably you know already, but virtually all of what I override is for ranges. The package should still provide much functionality regardless. Perhaps we could have some kind of switch to turn on range support for eager users. It seems like several of the tests I wrote are failing on 0.5 master. I'll investigate what has changed. |
Seems like it should be possible to get pretty far: julia> using SIUnits.ShortUnits
julia> r = 1m:1m:10m
1 m:1 m:10 m
julia> for i in r
@show i
end
i = 1 m
i = 2 m
i = 3 m
i = 4 m
i = 5 m
i = 6 m
i = 7 m
i = 8 m
i = 9 m
i = 10 m If I remember correctly, in the discussion we had in base the problem was with |
Yes, SIUnits achieves ranges with units by implementing an SIRange type. My package instead enabled the native range types to work with some small tweaks in base. To me, this approach initially seemed preferable, but in any case it is now a moot point with the feature freeze. I'm happy to go the other route if it makes the majority of users satisfied. My priority will be to fix bugs in Unitful now, particularly regarding array math. I'll work on some new range types after that. |
I see. I hadn't looked at how it works. To be clear, things that are effectively bugfixes should still be allowed. Changing signatures (e.g., changing |
Looks like you don't need to do anything special: # Let's create a "meter" type and try to build a StepRange
immutable m{T<:Real}
coef::T
end
Base.promote_rule{S,T}(::Type{m{S}}, ::Type{m{T}}) = m{promote_type(S,T)}
Base.zero{M<:m}(::Type{M}) = M(0)
Base.zero(x::m) = zero(typeof(x))
Base.isless(x::m, y::m) = isless(x.coef, y.coef)
Base.:+(x::m, y::m) = m(x.coef+y.coef)
Base.:-(x::m, y::m) = m(x.coef-y.coef)
Base.rem(x::m, y::m) = m(rem(x.coef, y.coef))
r1 = StepRange(m(1), m(1), m(10))
r2 = StepRange(m(2.5), m(7.5), m(100.0)) Results: julia> include("/tmp/units.jl")
m{Float64}(2.5):m{Float64}(7.5):m{Float64}(100.0)
julia> for x in r1
@show x
end
x = m{Int64}(1)
x = m{Int64}(2)
x = m{Int64}(3)
x = m{Int64}(4)
x = m{Int64}(5)
x = m{Int64}(6)
x = m{Int64}(7)
x = m{Int64}(8)
x = m{Int64}(9)
x = m{Int64}(10)
julia> for x in r2
@show x
end
x = m{Float64}(2.5)
x = m{Float64}(10.0)
x = m{Float64}(17.5)
x = m{Float64}(25.0)
x = m{Float64}(32.5)
x = m{Float64}(40.0)
x = m{Float64}(47.5)
x = m{Float64}(55.0)
x = m{Float64}(62.5)
x = m{Float64}(70.0)
x = m{Float64}(77.5)
x = m{Float64}(85.0)
x = m{Float64}(92.5)
x = m{Float64}(100.0) |
Though it might be worth arguing to change the type declaration of |
I'm sorry but I'm sensing a bit of a mixed message. Which approach would you prefer, new range types or getting existing ones to work? I feel like I will have an uphill battle proposing changes to 0.5 at this point, especially since I haven't made a significant contribution to Julia before. Without my base redefinitions, it looks like all my Suppose we came up with a small list of changes that did not even change type declarations or signatures of methods, but tweaked the way things work. These changes would give the same results as now for numbers without units. Now, if these changes employ a single new function that is not exported out of base, does that count as a "new feature" or a "bug fix"? I could do a lot if given a function that strips a number with units into the number and the unit. For numbers without units, the unit is multiplicative identity. If something like the following were in base, and used by only a small subset of the functions in base (specifically some in range.jl):
Then I could write something like the following in Unitful:
and the range magic could follow. I hope I don't sound like a broken record but I just want to get the facts on the table. I guess my philosophy with this package is that eventually, there should be little distinction between numbers with units and numbers without. Julia is for "technical computing" after all. The more special treatment we give numbers with units, the less likely they are to work generically with other packages. Rewriting ranges seems like special treatment, but I respect the rules, and if the feature freeze prevents the changes I need then I guess that's the alternative, in my view. |
It is a mixed message because, from the standpoint of units, I've just realized I'm not terribly happy with most of the Range types in Base. (I just posted here: JuliaLang/julia#17408 (comment)). I would say the best approach is we should probably ignore the range types in base and start a unit-friendly I'm being a broken record too, but I think we should avoid the unit-stripping and just use the mathematics. I guess I'm of the opinion that I wonder how much in Base we assume that |
Turns out StepRanges don't work entirely because of the We are definitely in agreement about the definition of I'm on board if you and others want |
I guess what I meant to say is that getting a |
I agree that the base ranges are messed up when one speaks in terms of units, and we seem to be in agreement about the meaning of I guess here's the plan I'd recommend:
To me it seems this plan will eliminate all override warnings when loading the package, and give you the functionality you need. |
Oh, and now that I think about it, we don't even have to get the |
All tests pass again except for the range ones that I've commented out. Also, no overriding base --> no more warnings. Let me know when you find some bugs in this thing, I'd love more tests. |
Ooh! Very exciting! I will start giving it a whirl. |
I propose I do the following prior to publishing and tagging this package:
After these three changes are implemented, I expect the package's implementation to stabilize and I would be more comfortable with broader adoption. |
Sounds exciting! I'm going to be a real pest here...but, can you clarify where you see it being important to have unitful numbers be subtypes of To me the main point is this: unitful numbers correspond to physical reality. That's very different from the artificial world in which computers work, and it's important not to let the computer world infringe unnecessarily on the actual meaning of quantities. I'm very happy to have these be a subtype of See: |
I should add that I'm happy to help with this transition. But if we simply can't see eye to eye on these matters, I certainly don't wish you to feel like you have to "break" your package just to please me---you wrote the code, and if it doesn't work for you then it's just wasted effort. |
First off, thank you for the offer of help. I value your feedback and you are being very generous with your time given your work on so many different projects and other responsibilities. I’ll try implementing just one I don’t think we are that different in our viewpoint—I do understand your argument (despite appearances...) and maybe it is best to keep formal rigor. My motivation for considering doing it my way was entirely practical. Let’s consider |
I agree that such methods are likely to be problematic---when julia gets traits, it should be better because we might be able to say |
@timholy, are you able to review the branch "rewrite"? I've implemented a lot of changes and added some documentation. I haven't pushed this to master because I am hoping you can look it over and see what you think before forcing major changes on users. All existing tests pass. Hopefully we can work together to get something we're both happy with published and tagged. I dropped the use of Note that you now need to call edit: you can now do things like |
I've just updated the "rewrite" branch again. I've adopted the strategy @dhoegh takes in EngUnits.jl to define default units, which solves the dirty package issue I was having. I've adopted his string macro for units now, e.g. Shortly after 0.5 is released I hope to publish and tag this, if only so that I am compelled to settle down with the breaking changes so that I start using this in my own projects in earnest. I will continue to tweak things in the mean time. |
@ajkeller34 I am glad my idea could be used. When I get time I will take it for a spin. |
@timholy Just a heads up that some Julia change has killed all of my array tests using 0.5.0-rc3 for the code in my JuliaLang/julia@5d2ac0d I gave it a few hours of debugging but maybe it is better to debug once rc4 or final comes out. Strangely, array math will work or not work depending on if Initial failure:
Peculiar success:
Note that I didn't even have to use volts when I called |
Sorry I've not had the time to check in on this. I just checked this on master, and it seems like you've figured it out? |
Thank you, I figured it out. I think it was from an overuse of generated functions that somehow resulted in different behavior between rc2 and rc3. I am using generated functions to do pre-computation for unit conversion, as well as to avoid type instabilities where I didn't see how to do so otherwise ( The most recent code is now on the master branch of this package, and the documentation has been updated. I still welcome any feedback you have! I'm starting to try and use this package in earnest, so there's no better time than now to raise lingering concerns you have with it. |
If I don't review it by the end of this week, ping me again. Got a few other items in the queue first, though. |
@ajkeller34 As requested, here are my two cents on whether unitful quantities should subtype
Whether to do it, then, should be entirely a pragmatic decision. I see two things to consider:
My opinion is that I ran
My suspicion is that |
Great job on this package, by the way. I have been monitoring its progress excitedly. |
To butt in here - I feel that I know I can do Also numbers of the same type are usually closed under multiplication. Lots of code uses |
Also, I'm glad we're all agreeing that I'm looking forward to using Unitful.jl. I had to implement some limited subset of ideas in Chrono.jl but really wished that stuff already existed. I think traits would be pretty kick-ass in this package. For the moment, I'd think some dimensions-based traits would be a good idea (like |
Not to beat a dead horse, but I don't think the meaning of I'm not sure if you saw, but you can already dispatch on You bring up a good point regarding angles. Currently my package defines an angle dimension and Regarding Thanks to you both for your feedback. When I get a moment, maybe I'll try making a branch where quantities are not |
I think this line of thinking is the bit that worried me. Surely having
No, sorry, I guess you are right - I haven't used it much at all yet. From following the above, I thought maybe it would be difficult to dispatch on both dimensions and number type simultaneously, but I'm probably wrong. Also, I wasn't sure if it would be easy (or desirable) for users to implement their own types with dimensions. And then you might consider that a vector is a
That sounds like a good idea. It would be great if, e.g.,
I'm thinking more-and-more that |
I've now taken a gander over the docs, tests, and a bit at the code itself. I haven't used it other than just playing around, and if it's like any other code in the universe then some issues will doubtlessly pop up, but on first glance I didn't see anything that worried me. I'll Overall, I have to say: I'm basically blown away. This seems to be the units package of my dreams. |
Many thanks to @timholy for the kind words, and especially for the time spent looking over the code! I'm inclined to leave things as is for now with regards to I'll stick to the plan of registering the package shortly after 0.5.0 is out. |
I'm rewriting Images.jl, which currently (sort of) supports encoding of information like the spacing between pixels with unit-ful quantitites (currently via SIUnits). In the rewrite (which will require julia 0.5), I'm struggling with whether to remain with SIUnits or switch to Unitful. The switch faces a number of issues:
promote_op
infrastructure has been dramatically simplified with (yay!) finally the ability to rely on inference for many operationsI guess I'm posting this largely to try to gauge your enthusiasm for updating Unitful and addressing these issues. Given the number of other packages I maintain/work on I probably don't have the bandwidth to make major changes to this package (nor to SIUnits), so I am trying to read the tea leaves to figure out what will become the future well-supported units package in Julia.
The text was updated successfully, but these errors were encountered: