Skip to content

Commit 22dfda6

Browse files
committed
Enable ruff.isort
1 parent cd0f809 commit 22dfda6

Some content is hidden

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

59 files changed

+357
-149
lines changed

experiments/traversal-benchmark.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import sys
44

55
from pymbolic import parse
6-
from pymbolic.primitives import Variable
76
from pymbolic.mapper import CachedIdentityMapper
87
from pymbolic.mapper.optimize import optimize_mapper
8+
from pymbolic.primitives import Variable
99

1010

1111
code = ("(-1)*((cse_577[_pt_data_48[((iface_ensm15*1075540 + iel_ensm15*10 + idof_ensm15) % 4302160) // 10, 0],"

pymbolic/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import annotations
2+
3+
14
__copyright__ = "Copyright (C) 2009-2013 Andreas Kloeckner"
25

36
__license__ = """

pymbolic/algorithm.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import annotations
2+
3+
14
__copyright__ = "Copyright (C) 2009-2013 Andreas Kloeckner"
25

36
__license__ = """
@@ -223,7 +226,7 @@ def sym_fft(x, sign=1):
223226
wrappers at opportune points.
224227
"""
225228

226-
from pymbolic.mapper import IdentityMapper, CSECachingMapperMixin
229+
from pymbolic.mapper import CSECachingMapperMixin, IdentityMapper
227230

228231
class NearZeroKiller(CSECachingMapperMixin, IdentityMapper):
229232
map_common_subexpression_uncached = \

pymbolic/compiler.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import annotations
2+
3+
14
__copyright__ = "Copyright (C) 2009-2013 Andreas Kloeckner"
25

36
__license__ = """
@@ -21,10 +24,9 @@
2124
"""
2225

2326
import math
27+
2428
import pymbolic
25-
from pymbolic.mapper.stringifier import (
26-
StringifyMapper, PREC_NONE,
27-
PREC_SUM, PREC_POWER)
29+
from pymbolic.mapper.stringifier import PREC_NONE, PREC_POWER, PREC_SUM, StringifyMapper
2830

2931

3032
class CompileMapper(StringifyMapper):

pymbolic/cse.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import annotations
2+
3+
14
__copyright__ = "Copyright (C) 2009-2013 Andreas Kloeckner"
25

36
__license__ = """
@@ -23,6 +26,7 @@
2326
import pymbolic.primitives as prim
2427
from pymbolic.mapper import IdentityMapper, WalkMapper
2528

29+
2630
COMMUTATIVE_CLASSES = (prim.Sum, prim.Product)
2731

2832

pymbolic/functions.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import annotations
2+
3+
14
__copyright__ = "Copyright (C) 2009-2013 Andreas Kloeckner"
25

36
__license__ = """

pymbolic/geometric_algebra/__init__.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import annotations
2+
3+
14
__copyright__ = "Copyright (C) 2009-2013 Andreas Kloeckner"
25

36
__license__ = """
@@ -20,9 +23,10 @@
2023
THE SOFTWARE.
2124
"""
2225

23-
from pytools import memoize, memoize_method
2426
import numpy as np
2527

28+
from pytools import memoize, memoize_method
29+
2630

2731
__doc__ = """
2832
See `Wikipedia <https://en.wikipedia.org/wiki/Geometric_algebra>`__ for an idea
@@ -536,6 +540,7 @@ def __init__(self, data, space=None):
536540
# {{{ normalize data to bitmaps, if needed
537541

538542
from pytools import single_valued
543+
539544
from pymbolic.primitives import is_zero
540545
if data and single_valued(isinstance(k, tuple) for k in data.keys()):
541546
# data is in non-normalized non-bits tuple form

pymbolic/geometric_algebra/mapper.py

+19-17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import annotations
2+
3+
14
__copyright__ = "Copyright (C) 2014 Andreas Kloeckner"
25

36
__license__ = """
@@ -23,27 +26,26 @@
2326
# This is experimental, undocumented, and could go away any second.
2427
# Consider yourself warned.
2528

26-
from typing import ClassVar, Dict
29+
from typing import ClassVar
2730

28-
from pymbolic.geometric_algebra import MultiVector
2931
import pymbolic.geometric_algebra.primitives as prim
32+
from pymbolic.geometric_algebra import MultiVector
3033
from pymbolic.mapper import (
31-
CombineMapper as CombineMapperBase,
32-
Collector as CollectorBase,
33-
IdentityMapper as IdentityMapperBase,
34-
WalkMapper as WalkMapperBase,
35-
CachedMapper,
36-
)
34+
CachedMapper,
35+
Collector as CollectorBase,
36+
CombineMapper as CombineMapperBase,
37+
IdentityMapper as IdentityMapperBase,
38+
WalkMapper as WalkMapperBase,
39+
)
3740
from pymbolic.mapper.constant_folder import (
38-
ConstantFoldingMapper as ConstantFoldingMapperBase)
39-
from pymbolic.mapper.graphviz import (
40-
GraphvizMapper as GraphvizMapperBase)
41+
ConstantFoldingMapper as ConstantFoldingMapperBase,
42+
)
43+
from pymbolic.mapper.evaluator import EvaluationMapper as EvaluationMapperBase
44+
from pymbolic.mapper.graphviz import GraphvizMapper as GraphvizMapperBase
4145
from pymbolic.mapper.stringifier import (
42-
StringifyMapper as StringifyMapperBase,
43-
PREC_NONE
44-
)
45-
from pymbolic.mapper.evaluator import (
46-
EvaluationMapper as EvaluationMapperBase)
46+
PREC_NONE,
47+
StringifyMapper as StringifyMapperBase,
48+
)
4749

4850

4951
class IdentityMapper(IdentityMapperBase):
@@ -105,7 +107,7 @@ def map_derivative_source(self, expr):
105107

106108

107109
class StringifyMapper(StringifyMapperBase):
108-
AXES: ClassVar[Dict[int, str]] = {0: "x", 1: "y", 2: "z"}
110+
AXES: ClassVar[dict[int, str]] = {0: "x", 1: "y", 2: "z"}
109111

110112
def map_nabla(self, expr, enclosing_prec):
111113
return f"∇[{expr.nabla_id}]"

pymbolic/geometric_algebra/primitives.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import annotations
2+
3+
14
__copyright__ = "Copyright (C) 2014 Andreas Kloeckner"
25

36
__license__ = """
@@ -23,7 +26,7 @@
2326
# This is experimental, undocumented, and could go away any second.
2427
# Consider yourself warned.
2528

26-
from typing import ClassVar, Hashable, List
29+
from typing import ClassVar, Hashable
2730

2831
from pymbolic.primitives import Expression, Variable, expr_dataclass
2932
from pymbolic.typing import ExpressionT
@@ -66,7 +69,7 @@ class Derivative:
6669
.. automethod:: dnabla
6770
.. automethod:: resolve
6871
"""
69-
_next_id: ClassVar[List[int]] = [0]
72+
_next_id: ClassVar[list[int]] = [0]
7073

7174
def __init__(self):
7275
self.my_id = f"id{self._next_id[0]}"
@@ -77,8 +80,9 @@ def nabla(self):
7780
return Nabla(self.my_id)
7881

7982
def dnabla(self, ambient_dim):
80-
from pymbolic.geometric_algebra import MultiVector
8183
from pytools.obj_array import make_obj_array
84+
85+
from pymbolic.geometric_algebra import MultiVector
8286
return MultiVector(make_obj_array(
8387
[NablaComponent(axis, self.my_id)
8488
for axis in range(ambient_dim)]))

pymbolic/imperative/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Imperative program representation"""
2+
from __future__ import annotations
3+
24

35
__copyright__ = "Copyright (C) 2015 Matt Wala, Andreas Kloeckner"
46

pymbolic/imperative/analysis.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Fusion and other user-facing code transforms"""
2+
from __future__ import annotations
3+
24

35
__copyright__ = "Copyright (C) 2015 Matt Wala, Andreas Kloeckner"
46

pymbolic/imperative/instruction.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Instruction types"""
2+
from __future__ import annotations
3+
24

35
__copyright__ = "Copyright (C) 2015 Matt Wala, Andreas Kloeckner"
46

@@ -29,5 +31,9 @@
2931
"to pymbolic.imperative.statement", DeprecationWarning, stacklevel=1)
3032

3133
from pymbolic.imperative.statement import ( # noqa: F401
32-
Instruction, ConditionalInstruction, Assignment, ConditionalAssignment,
33-
Nop)
34+
Assignment,
35+
ConditionalAssignment,
36+
ConditionalInstruction,
37+
Instruction,
38+
Nop,
39+
)

pymbolic/imperative/statement.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Instruction types"""
2+
from __future__ import annotations
3+
24

35
__copyright__ = "Copyright (C) 2015 Matt Wala, Andreas Kloeckner"
46

@@ -23,7 +25,9 @@
2325
"""
2426

2527
from sys import intern
28+
2629
from pytools import RecordWithoutPickling
30+
2731
from pymbolic.typing import not_none
2832

2933

@@ -136,7 +140,7 @@ def __init__(self, lhs, rhs, **kwargs):
136140
**kwargs)
137141

138142
def get_written_variables(self):
139-
from pymbolic.primitives import Variable, Subscript
143+
from pymbolic.primitives import Subscript, Variable
140144
if isinstance(self.lhs, Variable):
141145
return frozenset([self.lhs.name])
142146
elif isinstance(self.lhs, Subscript):

pymbolic/imperative/transform.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Imperative program representation: transformations"""
2+
from __future__ import annotations
3+
24

35
__copyright__ = "Copyright (C) 2015 Matt Wala, Andreas Kloeckner"
46

@@ -85,8 +87,7 @@ def should_disambiguate_name(name): # pylint:disable=function-redefined
8587
unclash = vng(clash)
8688
subst_b[clash] = var(unclash)
8789

88-
from pymbolic.mapper.substitutor import (
89-
make_subst_func, SubstitutionMapper)
90+
from pymbolic.mapper.substitutor import SubstitutionMapper, make_subst_func
9091
subst_map = SubstitutionMapper(make_subst_func(subst_b))
9192

9293
statements_b = [

pymbolic/imperative/utils.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import annotations
2+
3+
14
__copyright__ = """
25
Copyright (C) 2013 Andreas Kloeckner
36
Copyright (C) 2014 Matt Wala
@@ -24,6 +27,8 @@
2427
"""
2528

2629
import logging
30+
31+
2732
logger = logging.getLogger(__name__)
2833

2934

pymbolic/interop/ast.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import annotations
2+
3+
14
__copyright__ = """
25
Copyright (C) 2015 Andreas Kloeckner
36
Copyright (C) 2022 Kaushik Kulkarni
@@ -24,11 +27,12 @@
2427
"""
2528

2629
import ast
27-
from typing import Any, ClassVar, Dict, List, Tuple, Type
30+
from typing import Any, ClassVar
2831

2932
import pymbolic.primitives as p
30-
from pymbolic.typing import ExpressionT, ScalarT
3133
from pymbolic.mapper import CachedMapper
34+
from pymbolic.typing import ExpressionT, ScalarT
35+
3236

3337
__doc__ = r'''
3438
@@ -113,7 +117,7 @@ def _neg(x):
113117

114118
class ASTToPymbolic(ASTMapper):
115119

116-
bin_op_map: ClassVar[Dict[Type[ast.operator], Any]] = {
120+
bin_op_map: ClassVar[dict[type[ast.operator], Any]] = {
117121
ast.Add: _add,
118122
ast.Sub: _sub,
119123
ast.Mult: _mult,
@@ -139,7 +143,7 @@ def map_BinOp(self, expr): # noqa
139143

140144
return op_constructor(self.rec(expr.left), self.rec(expr.right))
141145

142-
unary_op_map: ClassVar[Dict[Type[ast.unaryop], Any]] = {
146+
unary_op_map: ClassVar[dict[type[ast.unaryop], Any]] = {
143147
ast.Invert: _neg,
144148
ast.Not: p.LogicalNot,
145149
# ast.UAdd:
@@ -160,7 +164,7 @@ def map_IfExp(self, expr): # noqa
160164
# (expr test, expr body, expr orelse)
161165
return p.If(self.rec(expr.test), self.rec(expr.body), self.rec(expr.orelse))
162166

163-
comparison_op_map: ClassVar[Dict[Type[ast.cmpop], str]] = {
167+
comparison_op_map: ClassVar[dict[type[ast.cmpop], str]] = {
164168
ast.Eq: "==",
165169
ast.NotEq: "!=",
166170
ast.Lt: "<",
@@ -264,7 +268,7 @@ def map_variable(self, expr) -> ast.expr:
264268
return ast.Name(id=expr.name)
265269

266270
def _map_multi_children_op(self,
267-
children: Tuple[ExpressionT, ...],
271+
children: tuple[ExpressionT, ...],
268272
op_type: ast.operator) -> ast.expr:
269273
rec_children = [self.rec(child) for child in children]
270274
result = rec_children[-1]
@@ -366,10 +370,10 @@ def map_logical_and(self, expr) -> ast.expr:
366370
return ast.BoolOp(ast.And(), [self.rec(child)
367371
for child in expr.children])
368372

369-
def map_list(self, expr: List[Any]) -> ast.expr:
373+
def map_list(self, expr: list[Any]) -> ast.expr:
370374
return ast.List([self.rec(el) for el in expr])
371375

372-
def map_tuple(self, expr: Tuple[Any, ...]) -> ast.expr:
376+
def map_tuple(self, expr: tuple[Any, ...]) -> ast.expr:
373377
return ast.Tuple([self.rec(el) for el in expr])
374378

375379
def map_if(self, expr: p.If) -> ast.expr:
@@ -465,6 +469,7 @@ def foo(*, E, S):
465469
return S // 32 + E % 32
466470
"""
467471
import sys
472+
468473
from pymbolic.mapper.dependency import CachedDependencyMapper
469474

470475
if sys.version_info < (3, 9):

pymbolic/interop/common.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import annotations
2+
3+
14
__copyright__ = "Copyright (C) 2009-2013 Andreas Kloeckner"
25

36
__license__ = """
@@ -20,9 +23,10 @@
2023
THE SOFTWARE.
2124
"""
2225

26+
from functools import partial
27+
2328
import pymbolic.primitives as prim
2429
from pymbolic.mapper.evaluator import EvaluationMapper
25-
from functools import partial
2630

2731

2832
class SympyLikeMapperBase:

0 commit comments

Comments
 (0)