Numpy support #253
Replies: 4 comments 16 replies
-
OK. It is not obvious to me that
Why is that? I'm not saying I object, I just don't see what that is "should". Does "arrays of ufloats rather than an ndarray of ufloats" mean "list of ufloats", or do you really mean arrays (https://docs.python.org/3/library/array.html)? I could certainly be missing some use cases, but I think an important case to consider (and what I know I would probably "normally have" in my own work, and sort of how
(where the shape, size, and dtype of That could make The idea of using lists or arrays (but not ndarray) of ufloats seems pretty different from that. What am I missing? |
Beta Was this translation helpful? Give feedback.
-
We're all aware that this code works:
This didn't require any dependency of This code currently breaks
But if we do
It works. Again we get Note that defining This would be very nice to get the ability to work with numpy arrays of The only thing that is missing is the ability to conveniently construct arrays of |
Beta Was this translation helpful? Give feedback.
-
I would really appreciate seeing some test cases to get us on the same page about what the supported API should look like. I wonder if some of the confusion in this discussion is coming from differing assumptions about what API we’re aiming for. I’ll try to write some tests this week to share or would look at what others can write in the mean time. |
Beta Was this translation helpful? Give feedback.
-
Ok, I got what I consider to be a pretty easy implementation working on my branch: jagerber48#2 Here's the In Here's some tests that show we satisfy 1-7. I'd say in my opinion these tests pretty satisfactorily satisfy all of 1-7 except 7b which needs an asterisk.
Output:
On 7b I had to make a "bespoke" hack to |
Beta Was this translation helpful? Give feedback.
-
The goal is to have a scalar class, AffineScalarFunc/ufloat, and an array class, UArray. The UArray class should be used to store arrays of ufloats rather than an ndarray of ufloats as is currently the case.
__array_ufunc__
and__array_function__
can be used to overide numpy functions, and can return ufloats or UArray, (or bool or whatever the result should be)__array_ufunc__
https://numpy.org/doc/stable/reference/arrays.classes.html#numpy.class.__array_ufunc__
This lets uncertainties control how numpy ufuncs operate. I think
__array_function__
takes precedence so it'll only be used for scalar ops once thats implemented.UArray
This would be an array that holds the nominal values and linearcombinations. Might be easier to use an ndarray of ufloats to start with than to store the floats in an ndarray seperate to the linearcombinations.
__array_function__
https://numpy.org/doc/stable/reference/arrays.classes.html#numpy.class.__array_function__
This lets uncertainties control how most numpy functions operate, eg
np.mean(UArray)
. I'm not sure whether it gets used innp.mean(arr_of_ufloats)
The difficult part here is that for every numpy function we implement, we'll need to write a function that can deal with any shape of input arrays and kwargs. I think we've only got 1D function wrappers at present. I think a reasonable goal is to get the functions currently in unumpy working for 1D inputs, and be at a point where a user can submit a PR implementing or improving a function they need.Beta Was this translation helpful? Give feedback.
All reactions