Skip to content

Commit

Permalink
Merge pull request hgrecco#1251 from arjavtrivedi/feature/np-linalg-norm
Browse files Browse the repository at this point in the history
Add np.linalg.norm implementation
  • Loading branch information
hgrecco committed Sep 18, 2023
2 parents cf8cced + cc56b12 commit 247512b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Pint Changelog
(PR #1803)
- Optimize matplotlib unit conversion for Quantity arrays
(PR #1819)

- Add numpy.linalg.norm implementation.
(PR #1251)

0.22 (2023-05-25)
-----------------
Expand Down
10 changes: 9 additions & 1 deletion pint/facets/numpy/numpy_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,15 @@ def implementation(a, *args, **kwargs):
implement_func("function", func_str, input_units=None, output_unit=None)

# Handle functions with output unit defined by operation
for func_str in ("std", "nanstd", "sum", "nansum", "cumsum", "nancumsum"):
for func_str in (
"std",
"nanstd",
"sum",
"nansum",
"cumsum",
"nancumsum",
"linalg.norm",
):
implement_func("function", func_str, input_units=None, output_unit="sum")
for func_str in ("diff", "ediff1d"):
implement_func("function", func_str, input_units=None, output_unit="delta")
Expand Down
6 changes: 6 additions & 0 deletions pint/testsuite/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,12 @@ def test_intersect1d(self):
[1, 3] * self.ureg.m,
)

@helpers.requires_array_function_protocol()
def test_linalg_norm(self):
q = np.array([[3, 5, 8], [4, 12, 15]]) * self.ureg.m
expected = [5, 13, 17] * self.ureg.m
helpers.assert_quantity_equal(np.linalg.norm(q, axis=0), expected)


@pytest.mark.skip
class TestBitTwiddlingUfuncs(TestUFuncs):
Expand Down

0 comments on commit 247512b

Please sign in to comment.