Skip to content

Add umath funcs: maximum & minimum #241

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions quantities/dimensionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ def _d_check_uniform(q1, q2, out=None):
p_dict[np.less_equal] = _d_check_uniform
p_dict[np.greater] = _d_check_uniform
p_dict[np.greater_equal] = _d_check_uniform
p_dict[np.maximum] = _d_check_uniform
p_dict[np.minimum] = _d_check_uniform

def _d_arctan2(q1, q2, out=None):
try:
Expand Down
10 changes: 10 additions & 0 deletions quantities/tests/test_umath.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,13 @@ def test_greater_equal(self):
arr2 = (1.0, 2.0) * pq.m
self.assertTrue(np.all(np.greater_equal(arr2, arr1)))
self.assertFalse(np.all(np.greater_equal(arr2*0.99, arr1)))

def test_maximum(self):
arr1 = (998, 999) * pq.m
arr2 = (1e3, 5e2) * pq.m
self.assertQuantityEqual(np.maximum(arr1, arr2) - [1000, 999]*pq.m, [0, 0]*pq.m)
Copy link
Contributor

@zm711 zm711 Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity why do the subtraction and then compare to 0 rather than compare directly to the values? Is there a benefit to doing this in readability or reliability? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a habit of mine, no particular reason.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Just wanted to make sure I wasn't missing a trick. Thanks!


def test_minimum(self):
arr1 = (998, 999) * pq.m
arr2 = (1e3, 5e2) * pq.m
self.assertQuantityEqual(np.minimum(arr1, arr2) - [998, 500]*pq.m, [0, 0]*pq.m)
Loading