Skip to content

Improve some types in traversal#113

Merged
inducer merged 7 commits intoinducer:mainfrom
alexfikl:type-traversal
Mar 10, 2026
Merged

Improve some types in traversal#113
inducer merged 7 commits intoinducer:mainfrom
alexfikl:type-traversal

Conversation

@alexfikl
Copy link
Copy Markdown
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.

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
Copy Markdown
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?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I don't think it's OK to default this at all. I've removed the defaulting logic, plus the sketchy getattr in the caller. We'll see what breaks.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Apparently, nothing. All the better!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@inducer Forgot to push this? I'm still seeing it in the merged version in main.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Very weird. That force-push apparently went nowhere? Not sure. #114 has my changes.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

And thanks for noticing!

@alexfikl
Copy link
Copy Markdown
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
Copy Markdown
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
@inducer
Copy link
Copy Markdown
Owner

inducer commented Mar 10, 2026

LGTM, thanks!

@inducer inducer merged commit 51739f7 into inducer:main Mar 10, 2026
15 of 16 checks passed
@alexfikl alexfikl deleted the type-traversal branch March 10, 2026 17:26
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.

2 participants