Skip to content
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

Override linop instead of _evaluate_linop #818

Merged
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
12 changes: 5 additions & 7 deletions src/probnum/randprocs/covfuncs/_arithmetic_fallbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import numpy as np

from probnum import linops, utils
from probnum.typing import NotImplementedType, ScalarLike
from probnum.typing import ArrayLike, NotImplementedType, ScalarLike

from ._covariance_function import BinaryOperandType, CovarianceFunction

Expand Down Expand Up @@ -55,8 +55,8 @@ def __init__(self, covfunc: CovarianceFunction, scalar: ScalarLike):
def _evaluate(self, x0: np.ndarray, x1: Optional[np.ndarray] = None) -> np.ndarray:
return self._scalar * self._covfunc(x0, x1)

def _evaluate_linop(
self, x0: np.ndarray, x1: Optional[np.ndarray]
def linop(
self, x0: ArrayLike, x1: Optional[ArrayLike] = None
) -> linops.LinearOperator:
return self._scalar * self._covfunc.linop(x0, x1)

Expand All @@ -82,7 +82,6 @@ class SumCovarianceFunction(CovarianceFunction):
"""

def __init__(self, *summands: CovarianceFunction):

if not all(
(summand.input_shape == summands[0].input_shape)
and (summand.output_shape_0 == summands[0].output_shape_0)
Expand All @@ -104,8 +103,8 @@ def _evaluate(self, x0: np.ndarray, x1: Optional[np.ndarray]) -> np.ndarray:
operator.add, (summand(x0, x1) for summand in self._summands)
)

def _evaluate_linop(
self, x0: np.ndarray, x1: Optional[np.ndarray]
def linop(
self, x0: ArrayLike, x1: Optional[ArrayLike] = None
) -> linops.LinearOperator:
return functools.reduce(
operator.add, (summand.linop(x0, x1) for summand in self._summands)
Expand Down Expand Up @@ -151,7 +150,6 @@ class ProductCovarianceFunction(CovarianceFunction):
"""

def __init__(self, *factors: CovarianceFunction):

if not all(
(factor.input_shape == factors[0].input_shape)
and (factor.output_shape_0 == factors[0].output_shape_0)
Expand Down