question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

quantity_input could provide access to the unwrapped function

See original GitHub issue

Description

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:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mhvkcommented, Aug 1, 2021

Slightly off topic, but since uncertainties was mentioned: I’ve long meant to have a proper Measurement class in astropy.uncertainties, and got quite a bit of the way to make an array-based version of uncertainties - 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=1

If 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…

0reactions
aarchibacommented, Aug 4, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found