Skip to content

Commit 46e2c0f

Browse files
alexfiklinducer
authored andcommitted
feat: use constantdict instead of immutabledict
1 parent e0c554f commit 46e2c0f

4 files changed

Lines changed: 24 additions & 18 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ classifiers = [
3131
dependencies = [
3232
"arraycontext>=2021.1",
3333
"boxtree>=2023.1",
34-
"immutabledict",
34+
"constantdict>=2024.4",
3535
"loopy>=2024.1",
3636
"numpy",
3737
"pyopencl>=2022.1",

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
numpy
22
sympy
3-
immutabledict
3+
constantdict
44
pyvkfft
55

66
# used in mpi-based tests

sumpy/codegen.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import re
2929

3030
import numpy as np
31-
from immutabledict import immutabledict
31+
from constantdict import constantdict
3232

3333
import loopy as lp
3434
import pymbolic.primitives as prim
@@ -142,7 +142,7 @@ def with_types(self, arg_id_to_dtype, clbl_inf_ctx):
142142

143143
if z_dtype.numpy_dtype.kind == "c":
144144
return (self.copy(name_in_target="bessel_jv_two_complex",
145-
arg_id_to_dtype=immutabledict({
145+
arg_id_to_dtype=constantdict({
146146
-2: NumpyType(np.complex128),
147147
-1: NumpyType(np.complex128),
148148
0: NumpyType(np.int32),
@@ -151,7 +151,7 @@ def with_types(self, arg_id_to_dtype, clbl_inf_ctx):
151151
clbl_inf_ctx)
152152
else:
153153
return (self.copy(name_in_target="bessel_jv_two",
154-
arg_id_to_dtype=immutabledict({
154+
arg_id_to_dtype=constantdict({
155155
-2: NumpyType(np.float64),
156156
-1: NumpyType(np.float64),
157157
0: NumpyType(np.int32),
@@ -184,15 +184,15 @@ def with_types(self, arg_id_to_dtype, clbl_inf_ctx):
184184

185185
if z_dtype.numpy_dtype.kind == "c":
186186
return (self.copy(name_in_target="hank1_01_complex",
187-
arg_id_to_dtype=immutabledict({
187+
arg_id_to_dtype=constantdict({
188188
-2: NumpyType(np.complex128),
189189
-1: NumpyType(np.complex128),
190190
0: NumpyType(np.complex128),
191191
})),
192192
clbl_inf_ctx)
193193
else:
194194
return (self.copy(name_in_target="hank1_01",
195-
arg_id_to_dtype=immutabledict({
195+
arg_id_to_dtype=constantdict({
196196
-2: NumpyType(np.complex128),
197197
-1: NumpyType(np.complex128),
198198
0: NumpyType(np.float64),

sumpy/expansion/diff_op.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import numpy as np
3434
import sympy as sp
3535
import sympy.polys.agca.modules as sp_modules
36-
from immutabledict import immutabledict
36+
from constantdict import constantdict
3737

3838
from pytools import memoize
3939

@@ -115,7 +115,8 @@ def __mul__(self, param: Number_ish) -> LinearPDESystemOperator:
115115
deriv_ident_to_coeff = {}
116116
for k, v in eq.items():
117117
deriv_ident_to_coeff[k] = v * param
118-
eqs.append(immutabledict(deriv_ident_to_coeff))
118+
eqs.append(constantdict(deriv_ident_to_coeff))
119+
119120
return LinearPDESystemOperator(self.dim, tuple(eqs))
120121

121122
__rmul__ = __mul__
@@ -125,6 +126,7 @@ def __add__(
125126
) -> LinearPDESystemOperator:
126127
assert self.dim == other_diff_op.dim
127128
assert len(self.eqs) == len(other_diff_op.eqs)
129+
128130
eqs: list[Mapping[DerivativeIdentifier, sp.Expr]] = []
129131
for eq, other_eq in zip(self.eqs, other_diff_op.eqs, strict=True):
130132
res = dict(eq)
@@ -133,7 +135,8 @@ def __add__(
133135
res[k] += v
134136
else:
135137
res[k] = v
136-
eqs.append(immutabledict(res))
138+
eqs.append(constantdict(res))
139+
137140
return LinearPDESystemOperator(self.dim, tuple(eqs))
138141

139142
__radd__ = __add__
@@ -269,7 +272,7 @@ def intersect(
269272
DerivativeIdentifier(mi, 0): sym.sympify(coeff.as_expr().simplify()) for
270273
(mi, coeff) in zip(scalar_pde.monoms(), scalar_pde.coeffs(), strict=True)
271274
}
272-
results.append(LinearPDESystemOperator(pde.dim, (immutabledict(pde_dict),)))
275+
results.append(LinearPDESystemOperator(pde.dim, (constantdict(pde_dict),)))
273276

274277
return results
275278

@@ -347,8 +350,8 @@ def as_scalar_pde(pde: LinearPDESystemOperator, comp_idx: int) \
347350

348351
def laplacian(diff_op: LinearPDESystemOperator) -> LinearPDESystemOperator:
349352
dim = diff_op.dim
350-
empty: tuple[Mapping[DerivativeIdentifier, sp.Expr], ...] = \
351-
(immutabledict(),) * len(diff_op.eqs)
353+
empty: tuple[Mapping[DerivativeIdentifier, sp.Expr], ...] = (
354+
(constantdict(),) * len(diff_op.eqs))
352355
res = LinearPDESystemOperator(dim, empty)
353356
for j in range(dim):
354357
mi = [0]*diff_op.total_dims
@@ -366,17 +369,20 @@ def diff(
366369
for deriv_ident, v in eq.items():
367370
new_mi = add_mi(deriv_ident.mi, mi)
368371
res[DerivativeIdentifier(new_mi, deriv_ident.vec_idx)] = v
369-
eqs.append(immutabledict(res))
372+
eqs.append(constantdict(res))
373+
370374
return LinearPDESystemOperator(diff_op.dim, tuple(eqs))
371375

372376

373377
def divergence(diff_op: LinearPDESystemOperator) -> LinearPDESystemOperator:
374378
assert len(diff_op.eqs) == diff_op.dim
375-
res = LinearPDESystemOperator(diff_op.dim, (immutabledict(),))
379+
380+
res = LinearPDESystemOperator(diff_op.dim, (constantdict(),))
376381
for i in range(diff_op.dim):
377382
mi = [0]*diff_op.total_dims
378383
mi[i] = 1
379384
res += diff(diff_op[i], tuple(mi))
385+
380386
return res
381387

382388

@@ -436,6 +442,6 @@ def make_identity_diff_op(
436442
mi = tuple([0]*(ninput + 1))
437443
else:
438444
mi = tuple([0]*ninput)
439-
return LinearPDESystemOperator(ninput, tuple(immutabledict(
440-
{DerivativeIdentifier(mi, i): sp.sympify(1)})
441-
for i in range(noutput)))
445+
return LinearPDESystemOperator(ninput, tuple(
446+
constantdict({DerivativeIdentifier(mi, i): sp.sympify(1)})
447+
for i in range(noutput)))

0 commit comments

Comments
 (0)