Skip to content

Commit

Permalink
feat: port deprecated __new__ calls
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfikl committed Nov 20, 2024
1 parent 5392644 commit 6946383
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 27 deletions.
2 changes: 1 addition & 1 deletion pytential/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _norm_inf_op(discr, num_components):
else:
max_arg = sym.abs(sym.var("arg"))

return bind(discr, sym.NodeMax(max_arg))
return bind(discr, sym.node_max(max_arg))


def norm(discr, x, p=2):
Expand Down
5 changes: 3 additions & 2 deletions pytential/qbx/refinement.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,9 @@ def check_expansion_disks_undisturbed_by_sources(self,
center_danger_zone_radii = flatten(
bind(
stage1_density_discr,
sym.interp(None, sym.GRANULARITY_CENTER,
sym.expansion_radii(stage1_density_discr.ambient_dim))
sym.interpolate(
sym.expansion_radii(stage1_density_discr.ambient_dim),
from_dd=None, to_dd=sym.GRANULARITY_CENTER)
)(self.array_context),
self.array_context)

Expand Down
9 changes: 4 additions & 5 deletions pytential/symbolic/mappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ def map_num_reference_derivative(self, expr):
return expr

from_dd = to_dd.copy(discr_stage=self.from_discr_stage)
return prim.interp(from_dd, to_dd, self.rec(self.tagger(expr)))
return prim.interpolate(self.rec(self.tagger(expr)), from_dd, to_dd)

def map_int_g(self, expr):
if expr.target.discr_stage is None:
Expand All @@ -658,13 +658,12 @@ def map_int_g(self, expr):
from_dd = expr.source.to_stage1()
to_dd = from_dd.to_quad_stage2()
densities = tuple(
prim.interp(from_dd, to_dd, self.rec(density)) for
density in expr.densities)
prim.interpolate(self.rec(density), from_dd, to_dd)
for density in expr.densities)

from_dd = from_dd.copy(discr_stage=self.from_discr_stage)
kernel_arguments = {
name: prim.interp(from_dd, to_dd,
self.rec(self.tagger(arg_expr)))
name: prim.interpolate(self.rec(self.tagger(arg_expr)), from_dd, to_dd)
for name, arg_expr in expr.kernel_arguments.items()}

return replace(
Expand Down
6 changes: 3 additions & 3 deletions pytential/symbolic/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ def map_num_reference_derivative(self, expr):

actx = self.array_context
dofdesc = expr.dofdesc
op = sym.NumReferenceDerivative(
ref_axes=expr.ref_axes,
operand=sym.var("u"),
op = sym.num_reference_derivative(
sym.var("u"),
expr.ref_axes,
dofdesc=dofdesc)

discr = self.places.get_discretization(dofdesc.geometry, dofdesc.discr_stage)
Expand Down
31 changes: 17 additions & 14 deletions pytential/symbolic/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
.. autofunction:: for_each_expression
.. autoclass:: ExpressionT
.. class:: P
See :class:`pytools.P`
Expand Down Expand Up @@ -262,7 +264,7 @@
:undoc-members:
:members: mapper_method
.. autofunction:: interp
.. autofunction:: interpolate
Geometric Calculus (based on Geometric/Clifford Algebra)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -342,7 +344,7 @@
"ElementwiseMax", "integral", "Ones", "ones_vec", "area", "mean",
"IterativeInverse",

"Interpolation", "interp",
"Interpolation", "interpolate",

"Derivative",

Expand Down Expand Up @@ -676,7 +678,7 @@ def reference_jacobian(func, output_dim, dim, dofdesc=None):
for i in range(output_dim):
func_component = func[i]
for j in range(dim):
jac[i, j] = NumReferenceDerivative(((j, 1),), func_component, dofdesc)
jac[i, j] = num_reference_derivative(func_component, j, dofdesc)

return jac

Expand Down Expand Up @@ -804,11 +806,9 @@ def second_fundamental_form(ambient_dim, dim=None, dofdesc=None):

# https://en.wikipedia.org/w/index.php?title=Second_fundamental_form&oldid=821047433#Classical_notation

from functools import partial
d = partial(NumReferenceDerivative, dofdesc=dofdesc)
ruu = d(((0, 2),), r)
ruv = d(((0, 1), (1, 1)), r)
rvv = d(((1, 2),), r)
ruu = num_reference_derivative(r, ((0, 2),), dofdesc)
ruv = num_reference_derivative(r, ((0, 1), (1, 1)), dofdesc)
rvv = num_reference_derivative(r, ((1, 2),), dofdesc)

nrml = normal(ambient_dim, dim, dofdesc).as_vector()

Expand Down Expand Up @@ -852,9 +852,9 @@ def _element_size(ambient_dim, dim=None, dofdesc=None):
if dim is None:
dim = ambient_dim - 1

return ElementwiseSum(
area_element(ambient_dim=ambient_dim, dim=dim)
* QWeight())**(1/dim)
return elementwise_sum(
area_element(ambient_dim=ambient_dim, dim=dim) * QWeight(),
dofdesc)**(1/dim)


def _small_mat_inverse(mat):
Expand Down Expand Up @@ -1082,7 +1082,7 @@ def _quad_resolution(ambient_dim, dim=None, granularity=None, dofdesc=None):
to_dd = from_dd.copy(granularity=granularity)

stretch = _mapping_max_stretch_factor(ambient_dim, dim=dim, dofdesc=from_dd)
return interp(from_dd, to_dd, stretch)
return interpolate(stretch, from_dd, to_dd)


def _source_danger_zone_radii(ambient_dim, dim=None,
Expand Down Expand Up @@ -1136,7 +1136,7 @@ def interleaved_expansion_centers(ambient_dim, dim=None, dofdesc=None):

source = as_dofdesc(dofdesc)
target = source.copy(granularity=GRANULARITY_CENTER)
return interp(source, target, centers)
return interpolate(centers, source, target)


def h_max(ambient_dim, dim=None, dofdesc=None):
Expand Down Expand Up @@ -1196,6 +1196,9 @@ def __new__(cls,
from_dd = as_dofdesc(from_dd)
to_dd = as_dofdesc(to_dd)

if from_dd == to_dd:
return operand # type: ignore[return-value]

if isinstance(operand, np.ndarray | MultiVector):
warn(f"Passing {type(operand)} directly to {cls.__name__!r} "
"is deprecated and will result in an error from 2025. Use "
Expand Down Expand Up @@ -1317,7 +1320,7 @@ def integral(ambient_dim, dim, operand, dofdesc=None):
"""A volume integral of *operand*."""

dofdesc = as_dofdesc(dofdesc)
return NodeSum(
return node_sum(
area_element(ambient_dim, dim, dofdesc)
* QWeight(dofdesc)
* operand)
Expand Down
11 changes: 9 additions & 2 deletions test/test_symbolic.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def test_interpolation(actx_factory, name, source_discr_stage, target_granularit
places = GeometryCollection(qbx, auto_where=where)

sigma_sym = sym.var("sigma")
op_sym = sym.sin(sym.interp(from_dd, to_dd, sigma_sym))
op_sym = sym.sin(sym.interpolate(sigma_sym, from_dd, to_dd))
bound_op = bind(places, op_sym, auto_where=where)

def discr_and_nodes(stage):
Expand Down Expand Up @@ -327,6 +327,9 @@ def randrange_like(xi, offset):

n = discr.ndofs
for func, expected in [
(sym.node_sum, n * (n + 1) // 2),
(sym.node_max, n),
(sym.node_min, 1),
(sym.NodeSum, n * (n + 1) // 2),
(sym.NodeMax, n),
(sym.NodeMin, 1),
Expand All @@ -341,8 +344,12 @@ def randrange_like(xi, offset):

from meshmode.dof_array import flat_norm
for func, np_func in [
(sym.elementwise_sum, np.sum),
(sym.elementwise_max, np.max),
(sym.elementwise_min, np.min),
(sym.ElementwiseSum, np.sum),
(sym.ElementwiseMax, np.max)
(sym.ElementwiseMax, np.max),
(sym.ElementwiseMin, np.min),
]:
expected = DOFArray(actx, data=tuple(
actx.from_numpy(np.tile(np_func(xi, axis=1, keepdims=True), xi.shape[1]))
Expand Down

0 comments on commit 6946383

Please sign in to comment.