Skip to content

Commit

Permalink
Remove rmatmul implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinpfoertner committed Nov 8, 2022
1 parent 7b26800 commit 33d972c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 60 deletions.
52 changes: 0 additions & 52 deletions src/probnum/linops/_kronecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ def __init__(self, A: LinearOperatorLike, B: LinearOperatorLike):
self.A.shape[1] * self.B.shape[1],
),
matmul=lambda x: _kronecker_matmul(self.A, self.B, x),
rmatmul=lambda x: _kronecker_rmatmul(self.A, self.B, x),
todense=lambda: np.kron(
self.A.todense(cache=False), self.B.todense(cache=False)
),
Expand Down Expand Up @@ -260,28 +259,6 @@ def _kronecker_matmul(
return y


def _kronecker_rmatmul(
A: _linear_operator.LinearOperator,
B: _linear_operator.LinearOperator,
x: np.ndarray,
) -> np.ndarray:
# Reshape into stack of matrices
y = x

if not y.flags.c_contiguous:
y = y.copy(order="C")

y = y.reshape(y.shape[:-1] + (A.shape[0], B.shape[0]))

# ((A.T) @ X) @ (B.T).T
y = (A.T @ y) @ B

# Revert to stack of vectorized matrices
y = y.reshape(y.shape[:-2] + (-1,))

return y


class SymmetricKronecker(_linear_operator.LambdaLinearOperator):
"""Symmetric Kronecker product of two linear operators.
Expand Down Expand Up @@ -337,7 +314,6 @@ def __init__(

dtype = self.A.dtype
matmul = lambda x: _kronecker_matmul(self.A, self.A, x)
rmatmul = lambda x: _kronecker_rmatmul(self.A, self.A, x)
todense = self._todense_identical_factors
# (A (x)_s A)^T = A^T (x)_s A^T
transpose = lambda: SymmetricKronecker(A=self.A.T)
Expand All @@ -357,7 +333,6 @@ def __init__(

dtype = np.result_type(self.A.dtype, self.B.dtype, 0.5)
matmul = self._matmul_different_factors
rmatmul = self._rmatmul_different_factors
todense = self._todense_different_factors
# (A (x)_s B)^T = A^T (x)_s B^T
transpose = lambda: SymmetricKronecker(A=self.A.T, B=self.B.T)
Expand All @@ -371,7 +346,6 @@ def __init__(
dtype=dtype,
shape=2 * (self._n**2,),
matmul=matmul,
rmatmul=rmatmul,
todense=todense,
transpose=transpose,
inverse=inverse,
Expand Down Expand Up @@ -441,29 +415,6 @@ def _matmul_different_factors(self, x: np.ndarray) -> np.ndarray:

return y

def _rmatmul_different_factors(self, x: np.ndarray) -> np.ndarray:
# Reshape into stack of matrices
y = x

if not y.flags.c_contiguous:
y = y.copy(order="C")

y = y.reshape(y.shape[:-1] + (self._n, self._n))

# (A.T) @ X @ (B.T).T
y1 = (self.A.T @ y) @ self.B

# (B.T) @ X @ (A.T).T
y2 = (self.B.T @ y) @ self.A

# 1/2 ((A^T)X(B^T)^T + (B^T)X(A^T)^T)
y = 0.5 * (y1 + y2)

# Revert to stack of vectorized matrices
y = y.reshape(y.shape[:-2] + (-1,))

return y

def _todense_identical_factors(self) -> np.ndarray:
"""Dense representation of the symmetric Kronecker product."""
# 1/2 (A (x) B + B (x) A)
Expand Down Expand Up @@ -533,9 +484,6 @@ def __init__(self, num_blocks: int, B: LinearOperatorLike):
matmul=lambda x: _kronecker_matmul(
self.A, self.B, x
), # TODO: can be implemented more efficiently
rmatmul=lambda x: _kronecker_rmatmul(
self.A, self.B, x
), # TODO: can be implemented more efficiently
todense=lambda: np.kron(
self.A.todense(cache=False), self.B.todense(cache=False)
),
Expand Down
8 changes: 0 additions & 8 deletions src/probnum/linops/_scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ def __init__(
matmul = lambda x: x.astype(
np.result_type(self.dtype, x.dtype), copy=False
)
rmatmul = lambda x: x.astype(
np.result_type(self.dtype, x.dtype), copy=False
)

apply = lambda x, axis: x.astype(
np.result_type(self.dtype, x.dtype), copy=False
Expand All @@ -97,7 +94,6 @@ def __init__(
)
else:
matmul = lambda x: self._scalar * x
rmatmul = lambda x: self._scalar * x

apply = lambda x, axis: self._scalar * x

Expand Down Expand Up @@ -129,7 +125,6 @@ def __init__(
dtype = self._factors.dtype

matmul = lambda x: self._factors[:, np.newaxis] * x
rmatmul = lambda x: self._factors * x

apply = lambda x, axis: (
self._factors.reshape((-1,) + (x.ndim - (axis + 1)) * (1,)) * x
Expand All @@ -154,7 +149,6 @@ def __init__(
shape,
dtype,
matmul=matmul,
rmatmul=rmatmul,
apply=apply,
todense=todense,
transpose=lambda: self,
Expand Down Expand Up @@ -334,7 +328,6 @@ class Zero(_linear_operator.LambdaLinearOperator):
def __init__(self, shape, dtype=np.float64):

matmul = lambda x: np.zeros(x.shape, np.result_type(x, self.dtype))
rmatmul = lambda x: np.zeros(x.shape, np.result_type(x, self.dtype))
apply = lambda x, axis: np.zeros(x.shape, np.result_type(x, self.dtype))
todense = lambda: np.zeros(shape=shape, dtype=dtype)
rank = lambda: np.intp(0)
Expand All @@ -347,7 +340,6 @@ def __init__(self, shape, dtype=np.float64):
shape,
dtype=dtype,
matmul=matmul,
rmatmul=rmatmul,
apply=apply,
todense=todense,
transpose=lambda: self,
Expand Down

0 comments on commit 33d972c

Please sign in to comment.