AMReX-Codes / pyamrex

GPU-Enabled, Zero-Copy AMReX Python Bindings including AI/ML
http://pyamrex.readthedocs.io
Other
32 stars 15 forks source link

Iterator: Python (Non-Typed) Implementation #261

Closed ax3l closed 4 months ago

ax3l commented 4 months ago

Currently, we implement the iterator member functions __next__ and __iter__ in C++. This results in strong typing. https://github.com/AMReX-Codes/pyamrex/blob/24.02/src/Base/Iterator.H

In downstream codes, we often derive the particle container and (particle) iterator classes. This results in calls to iterate to demote them from their own type to the base type.

As a work-around, we have to overwrite in derived classes:

to keep the derived classes in downstream workflows.

We might be able to generalize the return type in the pybind11 bindings for iteration or implement the __next__/__iter__ methods directly from Python as a dynamic attribute. That way, we should be able to skip the overwrites in derived classes.