-
-
Notifications
You must be signed in to change notification settings - Fork 78
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
Module wrapping #19
Comments
I see what you mean. In principle, However, I do not want to add anything that is not necessary, I prefer minimal, "essential" code. I wonder if the procedure that you propose is the best way to go: I guess that you want your module to call |
Hi Hermann, Is the issue that you initially raised still a problem for pint? |
We now use uncertainties as the numerical class underlying Pint's Measurements (ufloat + units). All simple things work as charm (simple arithmetic, string formatting, etc). I will soon implement string parsing (also using uncertainties functions). I am really happy about this. We are now looking for a way to have arrays and math operations. For arrays, my understanding is that the suggested way to use numpy arrays with uncertainties is to create an For math operations, in Pint we chose to use numpy functions (instead of Python's |
Thank you for this very lucid description of the situation: I understand it much better. I would like to explore that "Pint way" of integrating NumPy. Can you describe in more details how Pint "properly deals with NumPy functions" through the "addition of methods and attributes"? I haven't looked at your code, but I have looked for such a protocol in NumPy's documentation without ever finding any… |
Just for clarity, let me say that when I say support numpy functions I mean that if You can embed a numpy array in your class These magic methods are called at the beginning or end of numpy ufuncs and other numpy functions. One of the arguments that they receive is the ufunc that was called and therefore you can take appropriate action for every calculation. For example you can have dict mapping each ufunc to its derivative and after each ufunc call, calculate the new std_dev and use it in the object. This is the way we have originally choose in Pint. It has worked remarkably well and we support more numpy functions than any other units package out there. However, we have found a limitation. Any function that calls So we are looking now into subclassing. The implementation will be roughly the same but everything should work. I am trying to do it without loosing the ability to use Pint without NumPy, keeping the API simple and a single constructor. This will probably come in Pint 0.6 (we will release 0.5 before the end of this month) Finally, let me add that this comes with a cost. In Pint, some calculations are done twice. To my knowledge, there is no way to signal NumPy that my pure python code will handle the calculation. This means that if you do |
This is interesting. Thank you for the information. Would it help Pint if |
Pint transfers the task to the underlying numerical type. If the user wants |
I will have a look, then. I'm sorry but I'm not sure when, though,… The fact that NumPy always calls the ufunc complicates things for uncertainties, but as you said at least this won't incur a processing time penalty. I need to invest more thoughts in this before deciding what to do. I hope this is not too much of a problem for Pint. |
Take your time. I am really happy about how the collaboration between Pint and uncertainties is working. We find a common interest, we agree on a few things and then we implement it. We all have other things to do, so features land when we can implement them. Please keep me posted! And if you find a better way, I might ported to Pint. For 0.6, I will start working on subclassing. I will let you know how that goes. |
Leaving a reference note about handling uncertainties in arrays in a different way than currently done by |
For reference: direct implementation of uncertainties in NumPy ndarrays: astropy/astropy#3715. |
Thanks for the reference. It is roughly the direction I was proposing, right? |
@hgrecco As far as I can tell, yes, it is similar to what you were proposing, but I haven't checked the details. |
I am cross posting this here from hgrecco/pint#24
It would be nice to transform your umath module in a function plus a function call
In this way, other people using your library for their own classes (like me!) could just call wrap_module with a different wrapping function.
What do you think?
The text was updated successfully, but these errors were encountered: