Skip to content

Commit

Permalink
Merge branch 'main' into production-pilot-merge-main
Browse files Browse the repository at this point in the history
  • Loading branch information
MTCam committed Feb 3, 2025
2 parents 1cdd41a + 029026c commit 044f191
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Python 3 POCL:
script: |
export PYOPENCL_TEST=portable:cpu
export EXTRA_INSTALL="jax[cpu]"
export JAX_PLATFORMS=cpu
curl -L -O https://gitlab.tiker.net/inducer/ci-support/raw/main/build-and-test-py-project.sh
. ./build-and-test-py-project.sh
tags:
Expand Down
2 changes: 1 addition & 1 deletion arraycontext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def _deprecated_acf():


def __getattr__(name):
replacement_and_obj = _depr_name_to_replacement_and_obj.get(name, None)
replacement_and_obj = _depr_name_to_replacement_and_obj.get(name)
if replacement_and_obj is not None:
replacement, obj, year = replacement_and_obj
from warnings import warn
Expand Down
25 changes: 12 additions & 13 deletions arraycontext/container/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,19 +373,18 @@ def wrap(cls: Any) -> Any:
cls_has_array_context_attr: bool | None = _cls_has_array_context_attr
bcast_actx_array_type: bool | None = _bcast_actx_array_type

if cls_has_array_context_attr is None:
if hasattr(cls, "array_context"):
raise TypeError(
f"{cls} has an 'array_context' attribute, but it does not "
"set '_cls_has_array_context_attr' to *True* when calling "
"with_container_arithmetic. This is being interpreted "
"as '.array_context' being permitted to fail "
"with an exception, which is no longer allowed. "
f"If {cls.__name__}.array_context will not fail, pass "
"'_cls_has_array_context_attr=True'. "
"If you do not want container arithmetic to make "
"use of the array context, set "
"'_cls_has_array_context_attr=False'.")
if cls_has_array_context_attr is None and hasattr(cls, "array_context"):
raise TypeError(
f"{cls} has an 'array_context' attribute, but it does not "
"set '_cls_has_array_context_attr' to *True* when calling "
"with_container_arithmetic. This is being interpreted "
"as '.array_context' being permitted to fail "
"with an exception, which is no longer allowed. "
f"If {cls.__name__}.array_context will not fail, pass "
"'_cls_has_array_context_attr=True'. "
"If you do not want container arithmetic to make "
"use of the array context, set "
"'_cls_has_array_context_attr=False'.")

if bcast_actx_array_type is None:
if cls_has_array_context_attr:
Expand Down
7 changes: 2 additions & 5 deletions arraycontext/container/traversal.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,7 @@ def rec(lines: list[str], ary_: ArrayOrContainerT, level: int) -> None:
else:
for key, subary in iterable:
key = f"{key} ({type(subary).__name__})"
if level == 0:
indent = ""
else:
indent = f" | {' ' * 4 * (level - 1)}"
indent = "" if level == 0 else f" | {' ' * 4 * (level - 1)}"

lines.append(f"{indent} +-- {key}")
rec(lines, subary, level + 1)
Expand Down Expand Up @@ -833,7 +830,7 @@ def _unflatten(template_subary: ArrayOrContainer) -> ArrayOrContainer:

# {{{ check strides

if strict and hasattr(template_subary_c, "strides"):
if strict and hasattr(template_subary_c, "strides"): # noqa: SIM102
# Checking strides for 0 sized arrays is ill-defined
# since they cannot be indexed
if (
Expand Down
12 changes: 5 additions & 7 deletions arraycontext/impl/pytato/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,9 @@ def _to_frozen(key: tuple[Any, ...], ary) -> TaggableCLArray:

from pytools import common_prefix
name_hint = common_prefix([nh.prefix for nh in name_hint_tags])
if name_hint:
# All name_hint_tags shared at least some common prefix.
function_name = f"frozen_{name_hint}"
else:
function_name = "frozen_result"

# All name_hint_tags shared at least some common prefix.
function_name = f"frozen_{name_hint}" if name_hint else "frozen_result"

self._dag_transform_cache[normalized_expr] = (
transformed_dag, function_name)
Expand Down Expand Up @@ -668,7 +666,7 @@ def preprocess_arg(name, arg):
f"array type: got '{type(arg).__name__}', but expected one "
f"of {self.array_types}")

if name is not None:
if name is not None: # noqa: SIM102
# Tagging Placeholders with naming-related tags is pointless:
# They already have names. It's also counterproductive, as
# multiple placeholders with the same name that are not
Expand Down Expand Up @@ -897,7 +895,7 @@ def preprocess_arg(name, arg):
f"array type: got '{type(arg).__name__}', but expected one "
f"of {self.array_types}")

if name is not None:
if name is not None: # noqa: SIM102
# Tagging Placeholders with naming-related tags is pointless:
# They already have names. It's also counterproductive, as
# multiple placeholders with the same name that are not
Expand Down
27 changes: 13 additions & 14 deletions doc/make_numpy_coverage_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,19 @@ def write_searching_sorting_and_counting(outf, contexts):
parser.add_argument("filename", nargs="?", type=pathlib.Path, default=None)
args = parser.parse_args()

import sys
if args.filename is not None:
outf = open(args.filename, "w")
else:
outf = sys.stdout
def write(outf):
outf.write(HEADER)
write_array_creation_routines(outf, ctxs)
write_array_manipulation_routines(outf, ctxs)
write_linear_algebra(outf, ctxs)
write_logic_functions(outf, ctxs)
write_mathematical_functions(outf, ctxs)

ctxs = initialize_contexts()

outf.write(HEADER)
write_array_creation_routines(outf, ctxs)
write_array_manipulation_routines(outf, ctxs)
write_linear_algebra(outf, ctxs)
write_logic_functions(outf, ctxs)
write_mathematical_functions(outf, ctxs)

if args.filename is not None:
outf.close()
if args.filename:
with open(args.filename, "w") as outf:
write(outf)
else:
import sys
write(sys.stdout)
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ extend-select = [
"RUF", # ruff
"UP", # pyupgrade
"W", # pycodestyle
"SIM",
]
extend-ignore = [
"C90", # McCabe complexity
Expand Down
5 changes: 1 addition & 4 deletions test/test_arraycontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,7 @@ def randn(shape, dtype):
rng = np.random.default_rng()
dtype = np.dtype(dtype)

if shape == 0:
ashape = 1
else:
ashape = shape
ashape = 1 if shape == 0 else shape

if dtype.kind == "c":
dtype = np.dtype(f"<f{dtype.itemsize // 2}")
Expand Down

0 comments on commit 044f191

Please sign in to comment.