quantity_input could provide access to the unwrapped function
See original GitHub issueDescription
It is very handy to use the quantity_input
decorator to ensure the inputs to a function are Quantities with appropriate units. But this checking makes it impossible to use the function with the python package uncertainties
or other automatic-differentiation tools that rely on passing things that behave enough like numbers to pass through simple mathematics. In an ideal world one would be able to attach units to such exotic objects, but in practical terms the easiest thing to do is to pass these objects through the raw un-decorated version of the function - if the decorator provided that.
Additional context
I suggest usage that looks like:
@quantity_input
def f(x: u.m):
return x**2
f(1*u.m)
f.raw(ufloat(1, 0.1))
This should be implementable, if desired, just by storing the function to be wrapped in an attribute of the wrapper object.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
How do I unwrap a printed returned optional in a function ...
There are many ways to unwrap a value. You can try these ways. 1. The first way: guard let value = purchase(item: "Chips")...
Read more >Unwrapped Arguments for Functions - Pitches - Swift Forums
The language feature I'm proposing is that an optional value can be passed into a non-optional parameter position in a function or closure...
Read more >What is the difference between unwrap() function ... - MathWorks
I use two different ways to perform phase unwrapping: by using unwrap() Matlab function. by using the principal value of phase according to ......
Read more >Beginning Swift Programming Part 8 — Type Casting, Safely ...
You can convert almost anything to a String type, it won't always make sense ... Private access should be reserved for things that...
Read more >UNWRAP Function - SAS Help Center
The UNWRAP function takes the phase of a signal that is represented by a vector of angles and unwraps the phase when the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Slightly off topic, but since
uncertainties
was mentioned: I’ve long meant to have a properMeasurement
class inastropy.uncertainties
, and got quite a bit of the way to make an array-based version ofuncertainties
- see #3715 for an initial implementation and discussion about pitfalls as well as the current version at https://github.com/astropy/astropy/compare/main...mhvk:uncertainty?expand=1If I remember correctly, yhe main problem is tracking covariances for operations involving non-trivial broadcasts. I may get back to that once
Masked
is really fully functional…We had some discussion that the documentation for
quantity_input
wasn’t as friendly and discoverable as we wished, so a PR that fleshed it out and mentioned the availability of__wrapped__
would be nice. My schedule is a little full just now, though.