Skip to content
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

norm of vector with uncertainties #121

Open
karlwessel opened this issue Feb 25, 2020 · 4 comments
Open

norm of vector with uncertainties #121

karlwessel opened this issue Feb 25, 2020 · 4 comments

Comments

@karlwessel
Copy link

Calculating the norm of a numpy array with uncertainties using numpy.linalg.norm throws an error which can be reproduced with the following MWE:

from uncertainties import unumpy
import numpy
a = unumpy.uarray([1, 1], [1, 1])
numpy.linalg.norm(unumpy.nominal_values(a)) # works fine
numpy.linalg.norm(a)

This throws the following exception:

AttributeError: 'AffineScalarFunc' object has no attribute 'sqrt'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<__array_function__ internals>", line 6, in norm
  File "lib/python3.6/site-packages/numpy/linalg/linalg.py", line 2483, in norm
    ret = sqrt(sqnorm)
TypeError: loop of ufunc does not support argument 0 of type AffineScalarFunc which has no callable sqrt method

This is with uncertainties version 3.1.2 and numpy version 1.17.4.

@lebigot
Copy link
Collaborator

lebigot commented Feb 25, 2020

Thanks for reporting this. Either we should have a unumpy.linalg.norm function or, better, some mechanism that makes the original numpy.linalg.norm work.

@karlwessel
Copy link
Author

karlwessel commented Feb 25, 2020

I added a pull request (#122) that fixes the problem. However, since it adds sqrt as a member function to AffineScalarFunc it might introduce some unexpected side effects.

@lebigot
Copy link
Collaborator

lebigot commented Feb 25, 2020

Thanks. I am quite confident that this should work fine. I'll have to review the pull request when I am close to my personal computer but so far things look good.

1 similar comment
@lebigot
Copy link
Collaborator

lebigot commented Feb 25, 2020

Thanks. I am quite confident that this should work fine. I'll have to review the pull request when I am close to my personal computer but so far things look good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants