Closed Jacob-Stevens-Haas closed 5 months ago
CI bug related to https://bugs.python.org/issue42233, testing on 3.8/3.9 but it'll be an easy fix either way.
Heads up, I made AxesArray
raise errors for broken axis labels (e.g. labeling a third axis in a 2D array). So numpy functions that change the axes of its inputs raise errors on AxesArray inputs. Previously, they just assigned the same axes as their inputs. I am fixing them one by one. So far I've finished reshape
and transpose
, did einsum
but need to add tests , and need to do linalg.solve
and tensordot
.
Attention: 7 lines
in your changes are missing coverage. Please review.
Comparison is base (
8341efb
) 93.92% compared to head (bc3fbd2
) 94.40%. Report is 2 commits behind head on master.
Files | Patch % | Lines |
---|---|---|
pysindy/utils/axes.py | 98.28% | 7 Missing :warning: |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Issues to add to pysindy repo, discovered during this PR but not for this PR:
in_ndim
and axes
in _AxisMapping
- args should be required.stencil = t[n_stencil]
) or provide a better way to do this in developer docs.pysindy.version
module) ... it's a bit out of hand. One page per module or package, and package only with list of links to modulesnumpy.ndarray.view(AxesArray)
. Should it fail? Should it accept a second parameter if that's possible?)np.foo((AxesArray, np.ndarray)) or just return ndarray. See
__array_function__`. Changing this now breaks pysindy. This may affect the next issue:__array_finalize__
. Currently that method has ugly conditionals, and it might be cleaner to remove them (but doing so now breaks pysindy).Alright @znicolaou, @akaptano, this is ready for your review, if desired! After this I'd suggest we release 2.0.0. One of the main points of this PR was to removes some defaults for AxesArray
, so that I'm comfortable fixing issues without breaking backwards compatability.
This PR dramatically changes the AxesArray
class to support slicing. This is the most common pysindy operation on arrays. Now that slicing works, AxesArray
is stricter about creating arrays/array views. The strictness caused some functions in pysindy to fail; the PR patches FiniteDifference
and PDELibrary
as well as introduces implementations of common numpy operations on AxesArray (e.g. numpy.linalg.solve).
I'm going to leave this open for at least two weeks. I'd especially appreciate if you could take a look at the changes to the package outside of axes.py, which are many fewer and easier to review. Admittedly, some of these changes only make sense in debugging, when you can see that slices of the spatiotemporal grid carry the correct axis definition.
Fixes #220
It's long made sense to expose the
AxesArray
interface and document it. However, when it was created, it wasn't stable enough even for every use case inside pysindy. Indexing can remove, add, and even move around the axes in an array, which meant that properties such asax_time
andn_spatial
were unreliable when an array was indexed.FiniteDifference._accumulate()
is an example of great code that worked whichAxesArray
s, but in whichAxesArray
gave no extra understanding in debugging because the axis labels were incorrect.This PR makes basic indexing, integer advanced indexing, and boolean array indexing work. It does so by adding a a private attribute that contains both forwards and backwards maps of the axes, and modifying
__getitem__
to detect which axes are added, removed, combined, relocated, etc. The PR also expands the ufunc tests dramatically. Item 1 below is probably all that's needed to accept the PR.transpose
,roll
, andreshape
work for axesarrays.__array_finalize__
. Not sure I need all those conditionals.