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

Improve .assume_init() and use Array::maybe_uninit instead of Array::uninitialized #876

Merged
merged 5 commits into from
Dec 30, 2020

Conversation

bluss
Copy link
Member

@bluss bluss commented Dec 29, 2020

Improve .assume_init() so that we can see that it is on sound ground (and not transmuting wildly).

Then the remaining internal uses of Array::uninitialized are removed and replaced with Array::maybe_uninit.

Fixes part of #796
Prerequisite of #804

This pull request demonstrates two different ways of working with maybe_uninit. In concatenate and stack,
we can see how we're using the more "Rust-level" approach of using regular array traversal and interacting with
elements of type MaybeUninit<A> (by just assigning to them, but still).

In the implementation of dot and the benchmark, we instead use raw array views - RawArrayViewMut,
cast the raw view from element type MaybeUninit<A> to A, and handle the resulting raw view and
raw pointers carefully. We have some power in the ndarray abstractions because we can use Zip
to traverse raw views just like regular arrays.

Fix up the way we implement .assume_init() - use a mapping of the data
storage type instead of transmute. The end result is similar anyway but
easier to verify that it is correct. See docs for Arc::from_raw for its
requirements - which we should now adhere to.
/// ## Safety
///
/// Caller must ensure the two types have the same representation.
unsafe fn data_subst(self) -> Self::Output;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the data storage types are never publically available so the user of ndarray can never reach this method and call it.

@bluss bluss changed the title Improve .assume_init() and transfer implementation to using Array::maybe_uninit Improve .assume_init() and use Array::maybe_uninit instead of Array::uninitialized Dec 30, 2020
@bluss bluss merged commit d5b61ba into master Dec 30, 2020
@bluss bluss deleted the uninit branch December 30, 2020 10:00
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.

1 participant