Skip to content
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
9 changes: 9 additions & 0 deletions pint/facets/numpy/numpy_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,15 @@ def _trapz(y, x=None, dx=1.0, **kwargs):
return y.units._REGISTRY.Quantity(ret, units)


@implements("correlate", "function")
def _correlate(a, v, mode="valid", **kwargs):
a = _base_unit_if_needed(a)
v = _base_unit_if_needed(v)
units = a.units * v.units
ret = np.correlate(a._magnitude, v._magnitude, mode=mode, **kwargs)
return a.units._REGISTRY.Quantity(ret, units)


def implement_mul_func(func):
# If NumPy is not available, do not attempt implement that which does not exist
if np is None:
Expand Down
8 changes: 8 additions & 0 deletions pint/testsuite/test_numpy_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@ def test_trapz_no_autoconvert(self):
with pytest.raises(OffsetUnitCalculusError):
np.trapz(t, x=z)

def test_correlate(self):
a = self.Q_(np.array([1, 2, 3]), "m")
v = self.Q_(np.array([0, 1, 0.5]), "s")
res = np.correlate(a, v, "full")
ref = np.array([0.5, 2.0, 3.5, 3.0, 0.0])
assert np.array_equal(res.magnitude, ref)
assert res.units == "meter * second"

def test_dot(self):
with ExitStack() as stack:
stack.callback(
Expand Down