-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: avoid particle_index type cast #4996
base: main
Are you sure you want to change the base?
Conversation
Converting to draft because this needs some more thorough testing: namely, does this introduce any bugs in cython operations that are expecting float arrays? Only tried it out with a projection and it works (because the int field gets converted to float before the projection), but need to check other functionality. |
59b5d85
to
9b5c823
Compare
9b5c823
to
641e590
Compare
Assuming tests pass again, I think this is ready for review. For reference, the following IO child classes override
The one other IO frontend that overrides |
oh, I suppose I should update the docs to mention this behavior, but I'll wait for review before doing that in case the functionality changes. |
As I said somewhere else I'm currently unable to compile yt so I cannot review this properly at the moment. I hope someone else can step in. |
if finfos[f].units != finfos[f].output_units: | ||
self.field_data[f].convert_to_units(finfos[f].output_units) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note to reviewers: this change is necessary because unit conversions on unyt arrays of int dtype always cast the result to float64. e.g., unyt.unyt_array([1, 2], "1", dtype='int').to("1")
yields an array of type float64
. So only converting if the units differ allow the int fields to persist through the data read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems good to me as a first pass.
I want to note one other possible place we may want to update things. I think it might be too much work, but could be simplified with a broader particle type accessing refactor. (i.e., making it easier to figure out what type to make new fields, etc.)
I can see use cases for making the smoothing and deposition operations utilize integers. Specifically, if one wanted to deposit the nearest particle's index, that would be a use case we could support. But, it's not necessary for this.
I would also like to suggest that we avoid (for now) allowing 32bit floats and ints, which you've also avoided here.
One thing that came to mind, in addition -- using fused types we can make it somewhat easier to address issues in the cython code, but we could also utilize JIT's for fun in the distant future. |
I agree! and I think this PR opens up the possibility of doing just that.
agreed! I'll add a comment to the new |
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
This is a possible fix for #4995 which would affect all the particle frontends that don't override
_read_particle_selection
.