From a312136aa3240fdc83deaedd0a5738711bebdede Mon Sep 17 00:00:00 2001 From: Aman Goel Date: Fri, 3 Sep 2021 01:31:04 +0530 Subject: [PATCH] feat: base class for interpolators --- src/hist/interp.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/hist/interp.py diff --git a/src/hist/interp.py b/src/hist/interp.py new file mode 100644 index 00000000..d4aa6454 --- /dev/null +++ b/src/hist/interp.py @@ -0,0 +1,22 @@ +from __future__ import annotations + +import dataclasses +from typing import Any + +import numpy as np + +from hist import Hist + + +@dataclasses.dataclass +class Interp: + x: np.typing.ArrayLike + _hist: Hist + + def __call__(self, x: np.typing.ArrayLike, _hist: Hist) -> Any: + raise NotImplementedError() + + +class Linear(Interp): + def __call__(self, x: np.typing.ArrayLike, _hist: Hist) -> Any: + return np.interp(x, _hist.axes[0].centers, _hist.values()) # type: ignore