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

Extend unary operations to apply to bounds #147

Closed
davidhassell opened this issue Nov 6, 2020 · 1 comment · Fixed by #149
Closed

Extend unary operations to apply to bounds #147

davidhassell opened this issue Nov 6, 2020 · 1 comment · Fixed by #149
Assignees
Labels
enhancement New feature or request

Comments

@davidhassell
Copy link
Collaborator

davidhassell commented Nov 6, 2020

Currently, unary operation do not apply to bounds, but equivalent binary operations do:

>>> f = cf.example_field(0)
>>> a = f.dimension_coordinate('X')
>>> a.bounds.array
array([[  0.,  45.],
       [ 45.,  90.],
       [ 90., 135.],
       [135., 180.],
       [180., 225.],
       [225., 270.],
       [270., 315.],
       [315., 360.]])
b = -1 * a
>>> b.bounds.array
array([[  -0.,  -45.],
       [ -45.,  -90.],
       [ -90., -135.],
       [-135., -180.],
       [-180., -225.],
       [-225., -270.],
       [-270., -315.],
       [-315., -360.]])
>>> c = -a
>>> c.bounds.array 
array([[  0.,  45.],
       [ 45.,  90.],
       [ 90., 135.],
       [135., 180.],
       [180., 225.],
       [225., 270.],
       [270., 315.],
       [315., 360.]])

This is inconsistent. I propose making the arithmetic (as opposed to bitwise) unary operators also apply to bounds, when present, i.e. __abs__, __neg__, and __pos__ only.

@davidhassell
Copy link
Collaborator Author

I think the change is correct, but the motivation was wrong. The motivation should have been to ensure that x - y is always the same as -y + x. The changes of this issue will make this so, regardless of the chosen treatment of bounds (see #146 for details).

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

Successfully merging a pull request may close this issue.

1 participant