Skip to content

Commit

Permalink
Make all kernel/kernel_radius cached
Browse files Browse the repository at this point in the history
  • Loading branch information
Setsugennoao committed Aug 4, 2024
1 parent d3723f4 commit 66c853f
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion vskernels/kernels/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def ensure_obj(
cls, (mro := cls.mro())[mro.index(BaseScaler) - 1], scaler, cls._err_class, [], func_except
)

@inject_self.property
@inject_self.cached.property
def kernel_radius(self) -> int:
return _default_kernel_radius(__class__, self) # type: ignore

Expand Down
4 changes: 2 additions & 2 deletions vskernels/kernels/bicubic.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, b: float = 0, c: float = 1 / 2, **kwargs: Any) -> None:
self.c = c
super().__init__(**kwargs)

@inject_self
@inject_self.cached
def kernel(self, *, x: float) -> float: # type: ignore
x, b, c = abs(x), self.b, self.c

Expand All @@ -53,7 +53,7 @@ def kernel(self, *, x: float) -> float: # type: ignore

return 0.0

@inject_self.property
@inject_self.cached.property
def kernel_radius(self) -> int: # type: ignore
if (self.b, self.c) == (0, 0):
return 1
Expand Down
2 changes: 1 addition & 1 deletion vskernels/kernels/complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def __init__(self, taps: float, **kwargs: Any) -> None:
self.taps = taps
super().__init__(**kwargs)

@inject_self.property
@inject_self.cached.property
def kernel_radius(self) -> int: # type: ignore
return ceil(self.taps)

Expand Down
2 changes: 1 addition & 1 deletion vskernels/kernels/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


class CustomKernel(Kernel):
@inject_self
@inject_self.cached
def kernel(self: CustomKernelT, *, x: float) -> float:
raise NotImplementedError

Expand Down
2 changes: 1 addition & 1 deletion vskernels/kernels/placebo.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def get_params_args(
antiring=self.antiring,
) | kwargs

@inject_self.property
@inject_self.cached.property
def kernel_radius(self) -> int: # type: ignore
from .bicubic import Bicubic

Expand Down
2 changes: 1 addition & 1 deletion vskernels/kernels/spline.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _shiftPolynomial(coeffs: list[float], shift: float) -> list[float]:

return coeffs

@inject_self
@inject_self.cached
def kernel(self, x: float) -> float: # type: ignore
x, taps = abs(x), self.kernel_radius

Expand Down
24 changes: 12 additions & 12 deletions vskernels/kernels/various.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Point(CustomComplexKernel):

_static_kernel_radius = 1

@inject_self
@inject_self.cached
def kernel(self, *, x: float) -> float: # type: ignore
return 1.0

Expand All @@ -62,7 +62,7 @@ class Bilinear(CustomComplexKernel):

_static_kernel_radius = 1

@inject_self
@inject_self.cached
def kernel(self, *, x: float) -> float: # type: ignore
return max(1.0 - abs(x), 0.0)

Expand All @@ -77,7 +77,7 @@ class Lanczos(CustomComplexTapsKernel):
def __init__(self, taps: int = 3, **kwargs: Any) -> None:
super().__init__(taps, **kwargs)

@inject_self
@inject_self.cached
def kernel(self, *, x: float) -> float: # type: ignore
x, taps = abs(x), self.kernel_radius

Expand All @@ -98,7 +98,7 @@ def __init__(self, sigma: float = 0.5, taps: int = 2, **kwargs: Any) -> None:
def sigma(self) -> gauss_sigma:
return gauss_sigma(self._sigma)

@inject_self
@inject_self.cached
def kernel(self, *, x: float) -> float: # type: ignore
return 1 / (self._sigma * sqrt(2 * pi)) * exp(-x ** 2 / (2 * self._sigma ** 2))

Expand All @@ -108,7 +108,7 @@ class Box(CustomComplexKernel):

_static_kernel_radius = 1

@inject_self
@inject_self.cached
def kernel(self, *, x: float) -> float: # type: ignore
return 1.0 if x >= -0.5 and x < 0.5 else 0.0

Expand All @@ -124,7 +124,7 @@ def _win_coef(self, x: float) -> float:

return 0.42 + 0.50 * cos(w_x) + 0.08 * cos(w_x * 2)

@inject_self
@inject_self.cached
def kernel(self, *, x: float) -> float: # type: ignore
if x >= self.kernel_radius:
return 0.0
Expand All @@ -147,7 +147,7 @@ class Sinc(CustomComplexTapsKernel):
def __init__(self, taps: int = 4, **kwargs: Any) -> None:
super().__init__(taps, **kwargs)

@inject_self
@inject_self.cached
def kernel(self, *, x: float) -> float: # type: ignore
if x >= self.kernel_radius:
return 0.0
Expand All @@ -158,7 +158,7 @@ def kernel(self, *, x: float) -> float: # type: ignore
class Hann(CustomComplexTapsKernel):
"""Hann kernel."""

@inject_self
@inject_self.cached
def kernel(self, *, x: float) -> float: # type: ignore
if x >= self.kernel_radius:
return 0.0
Expand All @@ -169,7 +169,7 @@ def kernel(self, *, x: float) -> float: # type: ignore
class Hamming(CustomComplexTapsKernel):
"""Hamming kernel."""

@inject_self
@inject_self.cached
def kernel(self, *, x: float) -> float: # type: ignore
if x >= self.kernel_radius:
return 0.0
Expand All @@ -180,7 +180,7 @@ def kernel(self, *, x: float) -> float: # type: ignore
class Welch(CustomComplexTapsKernel):
"""Welch kernel."""

@inject_self
@inject_self.cached
def kernel(self, *, x: float) -> float: # type: ignore
if abs(x) >= 1.0:
return 0.0
Expand All @@ -191,7 +191,7 @@ def kernel(self, *, x: float) -> float: # type: ignore
class Cosine(CustomComplexTapsKernel):
"""Cosine kernel."""

@inject_self
@inject_self.cached
def kernel(self, *, x: float) -> float: # type: ignore
if x >= self.kernel_radius:
return 0.0
Expand All @@ -204,7 +204,7 @@ def kernel(self, *, x: float) -> float: # type: ignore
class Bohman(CustomComplexTapsKernel):
"""Bohman kernel."""

@inject_self
@inject_self.cached
def kernel(self, *, x: float) -> float: # type: ignore
if x >= self.kernel_radius:
return 0.0
Expand Down

0 comments on commit 66c853f

Please sign in to comment.