Skip to content

Commit 6aef851

Browse files
committed
fix: circular imports
1 parent c94b1fe commit 6aef851

3 files changed

Lines changed: 65 additions & 55 deletions

File tree

src/finchlite/__init__.py

Lines changed: 58 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,6 @@
1-
from .algebra import (
2-
FTyped,
3-
Tensor,
4-
TensorFType,
5-
bool,
6-
bool_,
7-
complex64,
8-
complex128,
9-
complex_,
10-
ffuncs,
11-
finfo,
12-
fisinstance,
13-
float16,
14-
float32,
15-
float64,
16-
float_,
17-
ftype,
18-
iinfo,
19-
int8,
20-
int16,
21-
int32,
22-
int64,
23-
int_,
24-
intp,
25-
isdtype,
26-
none_,
27-
str_,
28-
uint8,
29-
uint16,
30-
uint32,
31-
uint64,
32-
)
33-
from .autoschedule.tensor_stats import (
34-
DC,
35-
BlockedStats,
36-
DCStats,
37-
DenseStats,
38-
TensorDef,
39-
UniformStats,
40-
)
41-
from .codegen import (
42-
NumpyBuffer,
43-
NumpyBufferFType,
44-
)
45-
from .compile import (
46-
AssemblyContext,
47-
BufferizedNDArray,
48-
Extent,
49-
ExtentFType,
50-
dimension,
51-
)
52-
from .finch_fused import jit
1+
# isort: split
2+
# interface must be imported first so EagerTensor is defined before the
3+
# autoschedule→compile chain runs (compile.BufferizedNDArray inherits from it).
534
from .interface import (
545
EagerTensor,
556
LazyTensor,
@@ -161,6 +112,61 @@
161112
var,
162113
vecdot,
163114
)
115+
116+
# isort: split
117+
118+
from .algebra import (
119+
FTyped,
120+
Tensor,
121+
TensorFType,
122+
bool,
123+
bool_,
124+
complex64,
125+
complex128,
126+
complex_,
127+
ffuncs,
128+
finfo,
129+
fisinstance,
130+
float16,
131+
float32,
132+
float64,
133+
float_,
134+
ftype,
135+
iinfo,
136+
int8,
137+
int16,
138+
int32,
139+
int64,
140+
int_,
141+
intp,
142+
isdtype,
143+
none_,
144+
str_,
145+
uint8,
146+
uint16,
147+
uint32,
148+
uint64,
149+
)
150+
from .autoschedule.tensor_stats import (
151+
DC,
152+
BlockedStats,
153+
DCStats,
154+
DenseStats,
155+
TensorDef,
156+
UniformStats,
157+
)
158+
from .codegen import (
159+
NumpyBuffer,
160+
NumpyBufferFType,
161+
)
162+
from .compile import (
163+
AssemblyContext,
164+
BufferizedNDArray,
165+
Extent,
166+
ExtentFType,
167+
dimension,
168+
)
169+
from .finch_fused import jit
164170
from .tensor import (
165171
DenseLevel,
166172
DenseLevelFType,

src/finchlite/compile/bufferized_ndarray.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from ..algebra import FType, ImmutableStructFType, Tensor, TupleFType, ffuncs, ftype
99
from ..codegen import NumpyBuffer, NumpyBufferFType
1010
from ..codegen.numba_codegen import to_numpy_type
11+
from ..interface.eager import EagerTensor
1112
from . import looplets as lplt
1213
from .lower import AssemblyContext, FinchTensorFType
1314

@@ -16,7 +17,7 @@ def _get_default_strides(size: tuple[int, ...]) -> tuple[int, ...]:
1617
return tuple(np.cumprod((1,) + size[::-1]).astype(int))[-2::-1]
1718

1819

19-
class BufferizedNDArray(Tensor):
20+
class BufferizedNDArray(EagerTensor):
2021
def __init__(
2122
self,
2223
val: NumpyBuffer,

src/finchlite/interface/eager.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
from typing import Any
77

88
from ..algebra import FinchOperator
9-
from . import lazy
10-
from .fuse import compute
119
from .overrides import OverrideTensor
1210

1311

@@ -231,6 +229,10 @@ def __ne__(self, other):
231229
return not_equal(self, other)
232230

233231

232+
from . import lazy # noqa: E402
233+
from .fuse import compute # noqa: E402
234+
235+
234236
def full(
235237
shape: int | tuple[int, ...],
236238
fill_value: bool | complex,
@@ -418,6 +420,7 @@ def matmul(x1, x2, /):
418420
"""
419421
if isinstance(x1, lazy.LazyTensor) or isinstance(x2, lazy.LazyTensor):
420422
return lazy.matmul(x1, x2)
423+
421424
c = lazy.matmul(x1, x2)
422425
return compute(c)
423426

0 commit comments

Comments
 (0)