Skip to content

Commit 6eff871

Browse files
authored
Merge pull request cornellius-gp#85 from cornellius-gp/absolute_imports
Use absolute imports
2 parents 5496242 + 7858888 commit 6eff871

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+397
-355
lines changed

linear_operator/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
2-
from . import beta_features, operators, settings, utils
3-
from .functions import (
2+
from linear_operator import beta_features, operators, settings, utils
3+
from linear_operator.functions import (
44
add_diagonal,
55
add_jitter,
66
diagonalization,
@@ -13,7 +13,7 @@
1313
solve,
1414
sqrt_inv_matmul,
1515
)
16-
from .operators import LinearOperator, to_dense, to_linear_operator
16+
from linear_operator.operators import LinearOperator, to_dense, to_linear_operator
1717

1818
# Read version number as written by setuptools_scm
1919
try:

linear_operator/beta_features.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import warnings
44

5-
from .settings import _feature_flag
5+
from linear_operator.settings import _feature_flag
66

77

88
class _moved_beta_feature(object):

linear_operator/functions/__init__.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import torch
88

9-
from ._dsmm import DSMM
9+
from linear_operator.functions._dsmm import DSMM
1010

1111
LinearOperatorType = Any # Want this to be "LinearOperator" but runtime type checker can't handle
1212

@@ -23,7 +23,7 @@ def add_diagonal(input: Anysor, diag: torch.Tensor) -> LinearOperatorType:
2323
:return: :math:`\mathbf A + \text{diag}(\mathbf d)`, where :math:`\mathbf A` is the linear operator
2424
and :math:`\mathbf d` is the diagonal component
2525
"""
26-
from ..operators import to_linear_operator
26+
from linear_operator.operators import to_linear_operator
2727

2828
return to_linear_operator(input).add_diagonal(diag)
2929

@@ -61,7 +61,7 @@ def diagonalization(
6161
based on size if not specified.
6262
:return: eigenvalues and eigenvectors representing the diagonalization.
6363
"""
64-
from ..operators import to_linear_operator
64+
from linear_operator.operators import to_linear_operator
6565

6666
return to_linear_operator(input).diagonalization(method=method)
6767

@@ -105,7 +105,7 @@ def inv_quad(input: Anysor, inv_quad_rhs: torch.Tensor, reduce_inv_quad: bool =
105105
:returns: The inverse quadratic term.
106106
If `reduce_inv_quad=True`, the inverse quadratic term is of shape (...). Otherwise, it is (... x M).
107107
"""
108-
from ..operators import to_linear_operator
108+
from linear_operator.operators import to_linear_operator
109109

110110
return to_linear_operator(input).inv_quad(inv_quad_rhs, reduce_inv_quad=reduce_inv_quad)
111111

@@ -127,7 +127,7 @@ def inv_quad_logdet(
127127
:returns: The inverse quadratic term (or None), and the logdet term (or None).
128128
If `reduce_inv_quad=True`, the inverse quadratic term is of shape (...). Otherwise, it is (... x M).
129129
"""
130-
from ..operators import to_linear_operator
130+
from linear_operator.operators import to_linear_operator
131131

132132
return to_linear_operator(input).inv_quad_logdet(inv_quad_rhs, logdet, reduce_inv_quad=reduce_inv_quad)
133133

@@ -156,7 +156,7 @@ def pivoted_cholesky(
156156
.. _Harbrecht et al., 2012:
157157
https://www.sciencedirect.com/science/article/pii/S0168927411001814
158158
"""
159-
from ..operators import to_linear_operator
159+
from linear_operator.operators import to_linear_operator
160160

161161
return to_linear_operator(input).pivoted_cholesky(rank=rank, error_tol=error_tol, return_pivots=return_pivots)
162162

@@ -173,7 +173,7 @@ def root_decomposition(input: Anysor, method: Optional[str] = None) -> LinearOpe
173173
"cholesky", "lanczos", "symeig", "pivoted_cholesky", or "svd".
174174
:return: A tensor :math:`\mathbf R` such that :math:`\mathbf R \mathbf R^\top \approx \mathbf A`.
175175
"""
176-
from ..operators import to_linear_operator
176+
from linear_operator.operators import to_linear_operator
177177

178178
return to_linear_operator(input).root_decomposition(method=method)
179179

@@ -199,7 +199,7 @@ def root_inv_decomposition(
199199
:param method: Root decomposition method to use (symeig, diagonalization, lanczos, or cholesky).
200200
:return: A tensor :math:`\mathbf R` such that :math:`\mathbf R \mathbf R^\top \approx \mathbf A^{-1}`.
201201
"""
202-
from ..operators import to_linear_operator
202+
from linear_operator.operators import to_linear_operator
203203

204204
return to_linear_operator(input).root_inv_decomposition(
205205
initial_vectors=initial_vectors, test_vectors=test_vectors, method=method
@@ -235,7 +235,7 @@ def solve(input: Anysor, rhs: torch.Tensor, lhs: Optional[torch.Tensor] = None)
235235
:param lhs: :math:`\mathbf L` - the left hand side
236236
:return: :math:`\mathbf A^{-1} \mathbf R` or :math:`\mathbf L \mathbf A^{-1} \mathbf R`.
237237
"""
238-
from ..operators import to_linear_operator
238+
from linear_operator.operators import to_linear_operator
239239

240240
return to_linear_operator(input).solve(right_tensor=rhs, left_tensor=lhs)
241241

@@ -268,7 +268,7 @@ def sqrt_inv_matmul(
268268
:param lhs: :math:`\mathbf L` - the left hand side
269269
:return: :math:`\mathbf A^{-1/2} \mathbf R` or :math:`\mathbf L \mathbf A^{-1/2} \mathbf R`.
270270
"""
271-
from ..operators import to_linear_operator
271+
from linear_operator.operators import to_linear_operator
272272

273273
return to_linear_operator(input).sqrt_inv_matmul(rhs=rhs, lhs=lhs)
274274

linear_operator/functions/_diagonalization.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import torch
44
from torch.autograd import Function
55

6-
from .. import settings
7-
from ..utils import lanczos
6+
from linear_operator import settings
7+
from linear_operator.utils import lanczos
88

99

1010
class Diagonalization(Function):

linear_operator/functions/_dsmm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from torch.autograd import Function
44

5-
from ..utils.sparse import bdsmm
5+
from linear_operator.utils.sparse import bdsmm
66

77

88
class DSMM(Function):

linear_operator/functions/_inv_quad.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import torch
44
from torch.autograd import Function
55

6-
from .. import settings
6+
from linear_operator import settings
77

88

99
def _solve(linear_op, rhs):

linear_operator/functions/_inv_quad_logdet.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import torch
66
from torch.autograd import Function
77

8-
from .. import settings
9-
from ..utils.lanczos import lanczos_tridiag_to_diag
10-
from ..utils.stochastic_lq import StochasticLQ
8+
from linear_operator import settings
9+
from linear_operator.utils.lanczos import lanczos_tridiag_to_diag
10+
from linear_operator.utils.stochastic_lq import StochasticLQ
1111

1212

1313
class InvQuadLogdet(Function):

linear_operator/functions/_matmul.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from torch.autograd import Function
44

5-
from .. import settings
5+
from linear_operator import settings
66

77

88
class Matmul(Function):

linear_operator/functions/_pivoted_cholesky.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import torch
44
from torch.autograd import Function
55

6-
from .. import settings
7-
from ..utils.cholesky import psd_safe_cholesky
8-
from ..utils.permutation import apply_permutation, inverse_permutation
6+
from linear_operator import settings
7+
from linear_operator.utils.cholesky import psd_safe_cholesky
8+
from linear_operator.utils.permutation import apply_permutation, inverse_permutation
99

1010

1111
class PivotedCholesky(Function):

linear_operator/functions/_root_decomposition.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import torch
44
from torch.autograd import Function
55

6-
from .. import settings
7-
from ..utils import lanczos
6+
from linear_operator import settings
7+
from linear_operator.utils import lanczos
88

99

1010
class RootDecomposition(Function):
@@ -29,7 +29,7 @@ def forward(
2929
:return: :attr:`R`, such that :math:`R R^T \approx A`, and :attr:`R_inv`, such that
3030
:math:`R_{inv} R_{inv}^T \approx A^{-1}` (will only be populated if self.inverse = True)
3131
"""
32-
from ..operators import to_linear_operator
32+
from linear_operator.operators import to_linear_operator
3333

3434
ctx.representation_tree = representation_tree
3535
ctx.device = device

linear_operator/functions/_solve.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import torch
44
from torch.autograd import Function
55

6-
from .. import settings
6+
from linear_operator import settings
77

88

99
def _solve(linear_op, rhs):
10-
from ..operators import CholLinearOperator, TriangularLinearOperator
10+
from linear_operator.operators import CholLinearOperator, TriangularLinearOperator
1111

1212
if isinstance(linear_op, (CholLinearOperator, TriangularLinearOperator)):
1313
# May want to do this for some KroneckerProductLinearOperators and possibly

linear_operator/functions/_sqrt_inv_matmul.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import torch
44
from torch.autograd import Function
55

6-
from .. import settings, utils
6+
from linear_operator import settings, utils
77

88

99
class SqrtInvMatmul(Function):

linear_operator/operators/__init__.py

+36-31
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,45 @@
11
#!/usr/bin/env python3
22

3-
from ._linear_operator import LinearOperator, to_dense
4-
from .added_diag_linear_operator import AddedDiagLinearOperator
5-
from .batch_repeat_linear_operator import BatchRepeatLinearOperator
6-
from .block_diag_linear_operator import BlockDiagLinearOperator
7-
from .block_interleaved_linear_operator import BlockInterleavedLinearOperator
8-
from .block_linear_operator import BlockLinearOperator
9-
from .cat_linear_operator import cat, CatLinearOperator
10-
from .chol_linear_operator import CholLinearOperator
11-
from .constant_mul_linear_operator import ConstantMulLinearOperator
12-
from .dense_linear_operator import DenseLinearOperator, to_linear_operator
13-
from .diag_linear_operator import ConstantDiagLinearOperator, DiagLinearOperator
14-
from .identity_linear_operator import IdentityLinearOperator
15-
from .interpolated_linear_operator import InterpolatedLinearOperator
16-
from .keops_linear_operator import KeOpsLinearOperator
17-
from .kernel_linear_operator import KernelLinearOperator
18-
from .kronecker_product_added_diag_linear_operator import KroneckerProductAddedDiagLinearOperator
19-
from .kronecker_product_linear_operator import (
3+
from linear_operator.operators._linear_operator import LinearOperator, to_dense
4+
from linear_operator.operators.added_diag_linear_operator import AddedDiagLinearOperator
5+
from linear_operator.operators.batch_repeat_linear_operator import BatchRepeatLinearOperator
6+
from linear_operator.operators.block_diag_linear_operator import BlockDiagLinearOperator
7+
from linear_operator.operators.block_interleaved_linear_operator import BlockInterleavedLinearOperator
8+
from linear_operator.operators.block_linear_operator import BlockLinearOperator
9+
from linear_operator.operators.cat_linear_operator import cat, CatLinearOperator
10+
from linear_operator.operators.chol_linear_operator import CholLinearOperator
11+
from linear_operator.operators.constant_mul_linear_operator import ConstantMulLinearOperator
12+
from linear_operator.operators.dense_linear_operator import DenseLinearOperator, to_linear_operator
13+
from linear_operator.operators.diag_linear_operator import ConstantDiagLinearOperator, DiagLinearOperator
14+
from linear_operator.operators.identity_linear_operator import IdentityLinearOperator
15+
from linear_operator.operators.interpolated_linear_operator import InterpolatedLinearOperator
16+
from linear_operator.operators.keops_linear_operator import KeOpsLinearOperator
17+
from linear_operator.operators.kernel_linear_operator import KernelLinearOperator
18+
from linear_operator.operators.kronecker_product_added_diag_linear_operator import (
19+
KroneckerProductAddedDiagLinearOperator,
20+
)
21+
from linear_operator.operators.kronecker_product_linear_operator import (
2022
KroneckerProductDiagLinearOperator,
2123
KroneckerProductLinearOperator,
2224
KroneckerProductTriangularLinearOperator,
2325
)
24-
from .low_rank_root_added_diag_linear_operator import LowRankRootAddedDiagLinearOperator
25-
from .low_rank_root_linear_operator import LowRankRootLinearOperator
26-
from .masked_linear_operator import MaskedLinearOperator
27-
from .matmul_linear_operator import MatmulLinearOperator
28-
from .mul_linear_operator import MulLinearOperator
29-
from .permutation_linear_operator import PermutationLinearOperator, TransposePermutationLinearOperator
30-
from .psd_sum_linear_operator import PsdSumLinearOperator
31-
from .root_linear_operator import RootLinearOperator
32-
from .sum_batch_linear_operator import SumBatchLinearOperator
33-
from .sum_kronecker_linear_operator import SumKroneckerLinearOperator
34-
from .sum_linear_operator import SumLinearOperator
35-
from .toeplitz_linear_operator import ToeplitzLinearOperator
36-
from .triangular_linear_operator import TriangularLinearOperator
37-
from .zero_linear_operator import ZeroLinearOperator
26+
from linear_operator.operators.low_rank_root_added_diag_linear_operator import LowRankRootAddedDiagLinearOperator
27+
from linear_operator.operators.low_rank_root_linear_operator import LowRankRootLinearOperator
28+
from linear_operator.operators.masked_linear_operator import MaskedLinearOperator
29+
from linear_operator.operators.matmul_linear_operator import MatmulLinearOperator
30+
from linear_operator.operators.mul_linear_operator import MulLinearOperator
31+
from linear_operator.operators.permutation_linear_operator import (
32+
PermutationLinearOperator,
33+
TransposePermutationLinearOperator,
34+
)
35+
from linear_operator.operators.psd_sum_linear_operator import PsdSumLinearOperator
36+
from linear_operator.operators.root_linear_operator import RootLinearOperator
37+
from linear_operator.operators.sum_batch_linear_operator import SumBatchLinearOperator
38+
from linear_operator.operators.sum_kronecker_linear_operator import SumKroneckerLinearOperator
39+
from linear_operator.operators.sum_linear_operator import SumLinearOperator
40+
from linear_operator.operators.toeplitz_linear_operator import ToeplitzLinearOperator
41+
from linear_operator.operators.triangular_linear_operator import TriangularLinearOperator
42+
from linear_operator.operators.zero_linear_operator import ZeroLinearOperator
3843

3944
__all__ = [
4045
"to_dense",

0 commit comments

Comments
 (0)