-
Notifications
You must be signed in to change notification settings - Fork 30
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
New-style Fields #187
New-style Fields #187
Conversation
a2f2490
to
3f631bb
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #187 +/- ##
==========================================
+ Coverage 81.90% 82.05% +0.15%
==========================================
Files 101 101
Lines 7433 7552 +119
==========================================
+ Hits 6088 6197 +109
- Misses 1345 1355 +10 ☔ View full report in Codecov by Sentry. |
@syhaffert Would you mind taking a first quick review pass on this? No rush whatsoever: I'm still working out some kinks on how to test this. But the general structure is there and this is quite an involved transition. All tests pass locally on both new-style and old-style grids. |
c6d4e59
to
d03f6ef
Compare
d03f6ef
to
ff7c3f1
Compare
I am currently reading up on the new way of sub-classing and interoperability with numpy. When I am done with that I might have more comments. But from what I can see now, I think this implementation is looking pretty good. It's pretty logical. There are now a couple places where you explicitly cast to an array (np.asarray) is that to make it work with non array type objects? |
Those are actually all cases where it should've been a numpy array in the first place and not a Field. It's just that a Field can end up in there and you wouldn't notice normally if there is no explicit check for that, like is the case currently. |
0ac3041
to
bc83c85
Compare
I added unit tests for basic arithmetic and pickling, that is performed for both old- and new-style fields. While this is not a complete end-to-end test, this unit test checks most things that are used in the rest of the codebase. There are several improvements that can be made still. A major example is the use of Field for after Another potential improvements is explicit use of @syhaffert Ready for final review. |
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.
Looks good to me. I think its ready for merging.
These specific functions internally do an instance check, and therefore are not compatible with just a NewStyleField.
This tests basic arithmetic and pickling behaviour.
bc83c85
to
46627de
Compare
This PR starts the transition to a new implementation of Fields that is more amenable to backend changes later on. We will refer to the current style of Fields as OldStyleField and the new implementation as NewStyleField. The OldStyleFields are based on subclassing numpy arrays. At the time HCIPy was written, subclassing was the only way to associate a Grid with a Field. Subclassing has several disadvantages, most notably that we fully rely on Numpy to "remember" that the array is in fact a Field. This has been a problem early-on, with the
np.angle()
function, which would not properly call__array_finalize__()
.Recent NEPs have made it more and more possible to avoid subclassing, and instead create a completely new class that behaves just like a numpy array. This approach has been successfully used by Dask, CuPy and others, and is now fully mature. The NewStyleField class uses this implementation, with a
Field.data
attribute that contains the values and aField.grid
attribute that contains the grid as before.Since this is a huge transition, that will affect everyone if done improperly, this will be done with feature flags, which will be turned off for now. This allows everyone to test their code, on an opt-in basis, until we deem that the feature is mature enough to enable by default. Even later, the old-style fields and the corresponding feature flag will be removed.
Open questions: