api: Fix handling of staggering in injection/interpolation#2936
api: Fix handling of staggering in injection/interpolation#2936mloubout wants to merge 3 commits into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2936 +/- ##
==========================================
+ Coverage 83.33% 83.38% +0.05%
==========================================
Files 248 248
Lines 51799 51895 +96
Branches 4467 4480 +13
==========================================
+ Hits 43165 43275 +110
+ Misses 7882 7866 -16
- Partials 752 754 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
e3f0971 to
bc601dc
Compare
|
|
||
| def _field_shifts(self, field): | ||
| """ | ||
| Per-grid-Dimension half-cell shift induced by ``field``'s staggering |
There was a problem hiding this comment.
ultra-nitpick, fixable in a separate PR -- single `, not two, for homogeneity
There was a problem hiding this comment.
We seem to be wildly inconsistent on this
| try: | ||
| staggered = field.staggered | ||
| except AttributeError: | ||
| return None |
There was a problem hiding this comment.
when can u end up in the AttributeError? add a comment?
| try: | ||
| staggered = field.staggered | ||
| except AttributeError: | ||
| return None |
| except AttributeError: | ||
| return None | ||
| if not staggered or all(s == 0 for s in staggered): | ||
| return None |
| for _, g in groupby(pairs, lambda f: f[0].staggered): | ||
| g = list(g) | ||
| g_fields = [f for f, _ in g] | ||
| g_exprs = [e for _, e in g] |
There was a problem hiding this comment.
I think you can do
g_fields, g_exprs = zip(*g)
instead of these two lines
| def _grid_map(self): | ||
| return {} | ||
|
|
||
| @property |
|
|
||
| @property | ||
| def origin(self): | ||
| return DimensionTuple(*[0]*len(self.dimensions), |
There was a problem hiding this comment.
ultra-nitpick: self.ndim == len(self.dimensions)
| def _pos_symbols(self): | ||
| return [Symbol(name=f'pos{d}', dtype=np.int32) | ||
| for d in self.grid.dimensions] | ||
| @memoized_meth |
There was a problem hiding this comment.
the fact that this had to be turned into a memoized_meth makes me think that it should better be placed in the interpolator classes instead.
Accepting shifts here doesn't make much sense imho.
There was a problem hiding this comment.
I think I probably agree with this
| @cached_property | ||
| def _position_map(self): | ||
| @memoized_meth | ||
| def _position_map(self, shifts=None): |
There was a problem hiding this comment.
same story, imho this method doesn't belong here anymore
| "assert np.isclose(norm(rec), 31.23, atol=0, rtol=1e-3)\n", | ||
| "assert np.isclose(norm(rec2), 3.5482, atol=0, rtol=1e-3)\n", | ||
| "assert np.isclose(norm(rec3), 4.7007, atol=0, rtol=1e-3)" | ||
| "assert np.isclose(norm(rec), 29.538, atol=0, rtol=1e-3)\n", |
There was a problem hiding this comment.
that's quite the change
|
|
||
| @property | ||
| def origin(self): | ||
| return DimensionTuple(*[0]*len(self.dimensions), |
There was a problem hiding this comment.
Ultra nitpick: DimensionTuple(*[0 for _ in self.dimensions]) would be more readable in this context
| def _pos_symbols(self): | ||
| return [Symbol(name=f'pos{d}', dtype=np.int32) | ||
| for d in self.grid.dimensions] | ||
| @memoized_meth |
There was a problem hiding this comment.
I think I probably agree with this
|
|
||
| # Position map and temporaries for it | ||
| pmap = self._position_map | ||
| pmap = self._position_map() |
There was a problem hiding this comment.
Does this never need to know about the shifts then?
There was a problem hiding this comment.
How come this file has been so heavily reworked?
No description provided.