Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 1 addition & 121 deletions .basedpyright/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -1005,47 +1005,7 @@
"code": "reportAny",
"range": {
"startColumn": 15,
"endColumn": 71,
"lineCount": 1
}
},
{
"code": "reportUnknownArgumentType",
"range": {
"startColumn": 40,
"endColumn": 64,
"lineCount": 1
}
},
{
"code": "reportUnknownLambdaType",
"range": {
"startColumn": 47,
"endColumn": 48,
"lineCount": 1
}
},
{
"code": "reportUnknownLambdaType",
"range": {
"startColumn": 50,
"endColumn": 51,
"lineCount": 1
}
},
{
"code": "reportUnknownArgumentType",
"range": {
"startColumn": 59,
"endColumn": 60,
"lineCount": 1
}
},
{
"code": "reportUnknownArgumentType",
"range": {
"startColumn": 62,
"endColumn": 63,
"endColumn": 52,
"lineCount": 1
}
}
Expand Down Expand Up @@ -2989,22 +2949,6 @@
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
"startColumn": 53,
"endColumn": 59,
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
"startColumn": 68,
"endColumn": 74,
"lineCount": 1
}
},
{
"code": "reportMissingParameterType",
"range": {
Expand All @@ -3013,22 +2957,6 @@
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
"startColumn": 53,
"endColumn": 59,
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
"startColumn": 68,
"endColumn": 74,
"lineCount": 1
}
},
{
"code": "reportReturnType",
"range": {
Expand Down Expand Up @@ -9153,22 +9081,6 @@
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
"startColumn": 23,
"endColumn": 29,
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
"startColumn": 38,
"endColumn": 44,
"lineCount": 1
}
},
{
"code": "reportMissingParameterType",
"range": {
Expand All @@ -9177,22 +9089,6 @@
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
"startColumn": 23,
"endColumn": 29,
"lineCount": 1
}
},
{
"code": "reportAny",
"range": {
"startColumn": 38,
"endColumn": 44,
"lineCount": 1
}
},
{
"code": "reportUnknownParameterType",
"range": {
Expand Down Expand Up @@ -11191,22 +11087,6 @@
"lineCount": 1
}
},
{
"code": "reportUnknownLambdaType",
"range": {
"startColumn": 48,
"endColumn": 49,
"lineCount": 1
}
},
{
"code": "reportUnknownLambdaType",
"range": {
"startColumn": 51,
"endColumn": 65,
"lineCount": 1
}
},
{
"code": "reportUnusedExpression",
"range": {
Expand Down
2 changes: 1 addition & 1 deletion arraycontext/container/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ def {fname}(arg2, arg1):
code = gen.get().rstrip()+"\n"

result_dict = {"_MODULE_SOURCE_CODE": code, "cls": cls}
exec(compile(code, f"<container arithmetic for {cls.__name__}>", "exec"), # ruff:ignore[exec-builtin]
exec(compile(code, f"<container arithmetic for {cls.__name__}>", "exec"),
result_dict)

return cls
Expand Down
2 changes: 1 addition & 1 deletion arraycontext/container/dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def _deserialize_init_arrays_code_{lower_cls_name}(
""")

exec_dict = {"cls": cls, "_MODULE_SOURCE_CODE": serialize_code}
exec(compile(serialize_code, f"<container serialization for {cls.__name__}>", # ruff:ignore[exec-builtin]
exec(compile(serialize_code, f"<container serialization for {cls.__name__}>",
"exec"), exec_dict)

return cls
Expand Down
2 changes: 1 addition & 1 deletion arraycontext/container/traversal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ def treat_as_scalar(x: ArrayOrContainerOrScalar) -> bool:
raise TypeError(
"both arguments must have the same type if they are both "
"non-object-array array containers.")
return multimap_array_container(lambda x, y: outer(x, y), a, b)
return multimap_array_container(outer, a, b)

# }}}

Expand Down
14 changes: 5 additions & 9 deletions arraycontext/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,15 +495,11 @@ def _get_csr_matmul_prg(self, out_ndim: int) -> loopy.TranslationUnit:
out_shape_comp_names = ("nrows", *out_extra_shape_comp_names)

domains: list[str] = []
domains.append(
"{ [" + ",".join(out_inames) + "] : "
+ " and ".join(
f"0 <= {iname} < {shape_comp_name}"
for iname, shape_comp_name in zip(
out_inames, out_shape_comp_names, strict=True))
+ " }")
domains.append(
"{ [iel] : iel_lbound <= iel < iel_ubound }")
domains.extend(("{ [" + ",".join(out_inames) + "] : " + " and ".join(
f"0 <= {iname} < {shape_comp_name}"
for iname, shape_comp_name
in zip(out_inames, out_shape_comp_names, strict=True))
+ " }", "{ [iel] : iel_lbound <= iel < iel_ubound }"))

temporary_variables: Mapping[str, lp.TemporaryVariable] = {
"iel_lbound": lp.TemporaryVariable(
Expand Down
4 changes: 2 additions & 2 deletions arraycontext/impl/numpy/fake_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ def vdot(self, a, b):

def any(self, a, /):
return rec_map_reduce_array_container(partial(reduce, np.logical_or),
lambda subary: np.any(subary), a)
np.any, a)

def all(self, a, /):
return rec_map_reduce_array_container(partial(reduce, np.logical_and),
lambda subary: np.all(subary), a)
np.all, a)

@override
def array_equal(self,
Expand Down
2 changes: 1 addition & 1 deletion arraycontext/impl/pyopencl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def __init__(self,
super().__init__()
self.context = queue.context
self.queue = queue
self.allocator = allocator if allocator else None
self.allocator = allocator or None
if wait_event_queue_length is None:
wait_event_queue_length = 10

Expand Down
6 changes: 3 additions & 3 deletions arraycontext/impl/pyopencl/fake_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def sum(self,
dtype: DTypeLike | None = None,
) -> ArrayOrScalar:
if isinstance(axis, int):
axis = axis,
axis = (axis,)

def _rec_sum(ary):
if axis not in [None, tuple(range(ary.ndim))]:
Expand Down Expand Up @@ -400,7 +400,7 @@ def max(self,
queue = self._array_context.queue

if isinstance(axis, int):
axis = axis,
axis = (axis,)

def _rec_max(ary):
if axis not in [None, tuple(range(ary.ndim))]:
Expand Down Expand Up @@ -438,7 +438,7 @@ def min(self,
queue = self._array_context.queue

if isinstance(axis, int):
axis = axis,
axis = (axis,)

def _rec_min(ary):
if axis not in [None, tuple(range(ary.ndim))]:
Expand Down
2 changes: 1 addition & 1 deletion arraycontext/impl/pytato/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def id_collector(keys, ary):
def _to_input_for_compiled(
ary: AllowedArrayTc,
actx: _BasePytatoArrayContext) -> AllowedArrayTc:
"""
r"""
Preprocess *ary* before turning it into a :class:`pytato.array.Placeholder`
in :meth:`LazilyCompilingFunctionCaller.__call__`.

Expand Down
4 changes: 2 additions & 2 deletions arraycontext/impl/pytato/fake_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ def stack(self, arrays, axis=0):
def all(self, a, /):
return rec_map_reduce_array_container(
partial(reduce, pt.logical_and),
lambda subary: pt.all(subary), a)
pt.all, a)

def any(self, a, /):
return rec_map_reduce_array_container(
partial(reduce, pt.logical_or),
lambda subary: pt.any(subary), a)
pt.any, a)

@override
def array_equal(self,
Expand Down
2 changes: 1 addition & 1 deletion arraycontext/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def inner(metafunc: pytest.Metafunc) -> None:
arg_value_tuples = sorted([
tuple(arg_dict[name] for name in arg_names)
for arg_dict in arg_values_with_actx
], key=lambda x: str(x))
], key=str)

metafunc.parametrize(arg_names, arg_value_tuples, ids=ids)

Expand Down
37 changes: 19 additions & 18 deletions test/test_arraycontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"""

import logging
import math
from dataclasses import dataclass
from functools import partial
from typing import TYPE_CHECKING, cast
Expand Down Expand Up @@ -891,7 +892,7 @@ def _check_allclose(f, arg1, arg2, atol=5.0e-14):
partial(_check_allclose, lambda x: 3 * x),
ary, 2 * ary + ary)
rec_multimap_array_container(
partial(_check_allclose, lambda x: actx.np.sin(x)),
partial(_check_allclose, actx.np.sin),
ary, actx.np.sin(ary))

with pytest.raises(TypeError):
Expand Down Expand Up @@ -1186,11 +1187,11 @@ def test_actx_compile(actx_factory: ArrayContextFactory):

vel = actx.from_numpy(Velocity2D(v_x, v_y, actx))

scaled_speed = compiled_rhs(np.float64(3.14), vel)
scaled_speed = compiled_rhs(np.float64(math.pi), vel)

result = actx.to_numpy(scaled_speed)
np.testing.assert_allclose(result.u, -3.14*v_y)
np.testing.assert_allclose(result.v, 3.14*v_x)
np.testing.assert_allclose(result.u, -math.pi*v_y)
np.testing.assert_allclose(result.v, math.pi*v_x)


def test_actx_compile_python_scalar(actx_factory: ArrayContextFactory):
Expand All @@ -1204,11 +1205,11 @@ def test_actx_compile_python_scalar(actx_factory: ArrayContextFactory):

vel = actx.from_numpy(Velocity2D(v_x, v_y, actx))

scaled_speed = compiled_rhs(3.14, vel)
scaled_speed = compiled_rhs(math.pi, vel)

result = actx.to_numpy(scaled_speed)
np.testing.assert_allclose(result.u, -3.14*v_y)
np.testing.assert_allclose(result.v, 3.14*v_x)
np.testing.assert_allclose(result.u, -math.pi*v_y)
np.testing.assert_allclose(result.v, math.pi*v_x)


def test_actx_compile_kwargs(actx_factory: ArrayContextFactory):
Expand All @@ -1222,11 +1223,11 @@ def test_actx_compile_kwargs(actx_factory: ArrayContextFactory):

vel = actx.from_numpy(Velocity2D(v_x, v_y, actx))

scaled_speed = compiled_rhs(3.14, vel=vel)
scaled_speed = compiled_rhs(math.pi, vel=vel)

result = actx.to_numpy(scaled_speed)
np.testing.assert_allclose(result.u, -3.14*v_y)
np.testing.assert_allclose(result.v, 3.14*v_x)
np.testing.assert_allclose(result.u, -math.pi*v_y)
np.testing.assert_allclose(result.v, math.pi*v_x)


def test_actx_compile_with_tuple_output_keys(actx_factory: ArrayContextFactory):
Expand All @@ -1247,11 +1248,11 @@ def my_rhs(scale, vel):

vel = actx.from_numpy(Velocity2D(v_x, v_y, actx))

scaled_speed = compiled_rhs(3.14, vel=vel)
scaled_speed = compiled_rhs(math.pi, vel=vel)

result = actx.to_numpy(scaled_speed)[0, 0]
np.testing.assert_allclose(result.u, -3.14*v_y)
np.testing.assert_allclose(result.v, 3.14*v_x)
np.testing.assert_allclose(result.u, -math.pi*v_y)
np.testing.assert_allclose(result.v, math.pi*v_x)


def test_actx_compile_with_outlined_function(actx_factory: ArrayContextFactory):
Expand Down Expand Up @@ -1286,14 +1287,14 @@ def multi_scale_and_orthogonalize(
vel1 = Velocity2D(v1_x_actx, v1_y_actx, actx)
vel2 = Velocity2D(v2_x_actx, v2_y_actx, actx)

scaled_speed1, scaled_speed2 = compiled_rhs(np.float64(3.14), vel1, vel2)
scaled_speed1, scaled_speed2 = compiled_rhs(np.float64(math.pi), vel1, vel2)

result1 = actx.to_numpy(scaled_speed1)
result2 = actx.to_numpy(scaled_speed2)
np.testing.assert_allclose(result1.u, -3.14*v1_y)
np.testing.assert_allclose(result1.v, 3.14*v1_x)
np.testing.assert_allclose(result2.u, -3.14*v2_y)
np.testing.assert_allclose(result2.v, 3.14*v2_x)
np.testing.assert_allclose(result1.u, -math.pi*v1_y)
np.testing.assert_allclose(result1.v, math.pi*v1_x)
np.testing.assert_allclose(result2.u, -math.pi*v2_y)
np.testing.assert_allclose(result2.v, math.pi*v2_x)

# }}}

Expand Down
Loading