8000 quantity_input could provide access to the unwrapped function · Issue #11987 · astropy/astropy · GitHub 8000
[go: up one dir, main page]

Skip to content
quantity_input could provide access to the unwrapped function #11987
@aarchiba

Description

@aarchiba

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0