Skip to content

Improve some types in traversal#113

Open
alexfikl wants to merge 7 commits intoinducer:mainfrom
alexfikl:type-traversal
Open

Improve some types in traversal#113
alexfikl wants to merge 7 commits intoinducer:mainfrom
alexfikl:type-traversal

Conversation

@alexfikl
Copy link
Contributor

@alexfikl alexfikl commented Mar 1, 2026

This fixes some actual errors (e.g. from_sep_smaller_by_level is an ObjectArray1D) and adds some more types.

from arraycontext import Array, ArrayContext, PyOpenCLArrayContext
from pyopencl.tools import ScalarArg, VectorArg as _VectorArg, dtype_to_c_struct
from pyopencl.tools import (
ScalarArg as ScalarArg, # noqa: PLC0414
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this so that pyright doesn't complain that ScalarArg isn't exported from here.

Comment on lines 1620 to +1624
# separated bigger boxes ("List 4")
from_sep_bigger_starts: Array
from_sep_bigger_lists: Array
from_sep_close_bigger_starts: Array
from_sep_close_bigger_lists: Array
from_sep_close_bigger_starts: Array | None
from_sep_close_bigger_lists: Array | None
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think any of these other arrays can be None, but probably needs a closer look.

Comment on lines +1763 to +1765
# FIXME: not clear this is the right default?
if particle_id_dtype is None:
particle_id_dtype = np.dtype(np.int32)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be used below unconditionally in some VectorArg. That can't be None, so this sets it to some value.

My understanding is that this can only be None for a bare TreeOfBoxes (which doesn't have the particle_id_dtype), so not sure if this is a reasonable default? Does this even work in that case?

@alexfikl
Copy link
Contributor Author

alexfikl commented Mar 1, 2026

Hm.. The dataclass_array_container seems to fail for obj_array.ObjectArray1D. I'll have to take a closer look :(

@alexfikl alexfikl marked this pull request as ready for review March 2, 2026 08:43
Comment on lines -174 to -175
if isinstance(field_type, GenericAlias | _BaseGenericAlias | _SpecialForm):
# NOTE: anything except a Union is not an array
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue was mainly here, because ObjectArray1D[Array] is actually a _BaseGenericAlias, so this would incorrectly return False.

It now just checks for special forms, but we can't use too much of the arraycontext implementation because some of the boxtree classes have tuple[Array, ...] and Literal, which aren't supported by all_type_leaves_satisfy_predicate.

@alexfikl alexfikl force-pushed the type-traversal branch 2 times, most recently from d97d417 to e474a34 Compare March 2, 2026 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant