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

Meshgrid implementation #1477

Draft
wants to merge 33 commits into
base: master
Choose a base branch
from
Draft

Meshgrid implementation #1477

wants to merge 33 commits into from

Conversation

akern40
Copy link
Collaborator

@akern40 akern40 commented Feb 1, 2025

Closes #1355, but depends first on #1440. Could have its dependence on #1440 removed if needed faster.

The reference type, `RefBase<A, D, R>`, is parameterized by its element
type, a dimensionality type, and its "referent" type. This last type
is only a `PhantomData` marker, and acts to differentiate references
that are "safe" from those that are "raw", i.e., references that come
from an array whose storage is `Data` vs an array whose stoarge is
`RawData`. The `DerefMut` implementation contains a check of uniqueness,
guaranteeing that an `&mut RefBase` is safe to mutate.

This comes with one breaking change and one important internal library
note. The breaking change is that `ArrayBase` no longer implements `Copy`
for views. This is because a `RefBase` does not know where it is pointing,
and therefore cannot implement `Copy`; this, in turn, prohibits
`ArrayBase` from implementing `Copy`. Users will now have to explicitly
invoke `Clone` in the same way that they do for non-view arrays.

The important library note has to do with the `.try_ensure_unique` check
that occurs in the `DerefMut` implementation. The library's methods are
allowed to *temporarily* break the invariant that an array's `ptr`
is contained within `data`. The issue comes when trying to then alter
`ptr`, `shape`, or `dim` while that invariant is broken. Code was
using `self.ptr = ...` (where `self` is `ArrayBase`), which triggers
`DerefMut`, which calls `try_ensure_unique`, which panics on the
pointer inbounds check. As a result, code that is altering `RefBase`
fields while the array's invariants are broken must be sure to write
`self.aref.ptr = ...` instead.
…ow to write functionality with the new types
I think I accidentally moved this over to ArrayRef, but we're not sure it should still require DataOwned
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.

Implementation of numpy's meshgrid function for ndarray
1 participant