Skip to content
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

Fixing issues related to dtype=object arrays in interpolation routines #1655

Conversation

leftaroundabout
Copy link
Contributor

This is a cleaned-up version of parts of #1649. See that PR for discussion.

In old versions of NumPy, ODL relied on its capability to represent ragged arrays automatically as arrays of arrays (i.e., of objects). This was in particular used for meshgrids, which are a kind of discretization supported by the interpolation classes in odl.discr.

Current NumPy does not automatically convert to dtype=object anymore, and for good reasons: it is error-prone (shapes become ambiguous, whether to consider the nested array or just its outer structure) and performance / memory locality suffers. In #1633, this was addressed by explicitly generating an object-array specifically for the meshgrid-specifying inputs, but further testing (#1648) revealed that this was not sufficient: the dtype=object property would percolate into the interpolation calculations, and there cause new failures due to required implicit conversion (as well as performance degradation).

This PR goes into the details of the interpolation routines and ensures linear arrays are stored with primitive dtype. It fixes the discretization tests in NumPy-1.19, though there are still some implicit conversions that the even stricter numpy-1.26 does not accept, as well as different tests that currently fail for unrelated reasons.

…e stored as arrays.

Without this, NumPy implicitly generates arrays but makes them ragged (dtype=object),
which is bad for performance and disabled in newer versions.
In older NumPy, this would silently create an array-of-object, but that
has a wrong shape too.
…ject.

This would previously happen because meshgrids are passed in as ragged arrays,
and NumPy does not convert the rows to float dtype as should happen.
…riate.

One of the tests samples from an integral grid at non-integral points.
This failed after the explicit conversion introduced in c90044a.
Falling back to `float` fixes the test case, though perhaps it would
be better to select a dedicated meshing dtype.
When this happens it is likely that the used did something like starting
from an integer mesh, but in that case linear interpolation does not seem
very appropriate.
@pep8speaks
Copy link

Checking new PR...

Line 629:20: E225 missing whitespace around operator
Line 629:19: E128 continuation line under-indented for visual indent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants