Remove alignment restriction on RawArrayView/Mut by jturner314 · Pull Request #738 · rust-ndarray/ndarray · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions src/impl_raw_views.rs
21 changes: 11 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1106,10 +1106,12 @@ pub type Ixs = isize;
// `dim`, and `strides` must be exclusively borrowed and not aliased by
// multiple indices.
//
// 2. `ptr` must be non-null and aligned, and it must be safe to [`.offset()`]
// `ptr` by zero.
// 2. If the type of `data` implements `Data`, then `ptr` must be aligned.
//
// 3. It must be safe to [`.offset()`] the pointer repeatedly along all axes
// 3. `ptr` must be non-null, and it must be safe to [`.offset()`] `ptr` by
// zero.
//
// 4. It must be safe to [`.offset()`] the pointer repeatedly along all axes
// and calculate the `count`s for the `.offset()` calls without overflow,
// even if the array is empty or the elements are zero-sized.
//
Expand Down Expand Up @@ -1177,13 +1179,13 @@ pub type Ixs = isize;
// `.offset()` at all, even by zero bytes, but the implementation of
// `Vec<A>` does this, so we can too. See rust-lang/rust#54857 for details.)
//
// 4. The product of non-zero axis lengths must not exceed `isize::MAX`. (This
// 5. The product of non-zero axis lengths must not exceed `isize::MAX`. (This
// also implies that the length of any individual axis must not exceed
// `isize::MAX`, and an array can contain at most `isize::MAX` elements.)
// This constraint makes various calculations easier because they don't have
// to worry about overflow and axis lengths can be freely cast to `isize`.
//
// Constraints 2–4 are carefully designed such that if they're upheld for the
// Constraints 2–5 are carefully designed such that if they're upheld for the
// array, they're also upheld for any subset of axes of the array as well as
// slices/subviews/reshapes of the array. This is important for iterators that
// produce subviews (and other similar cases) to be safe without extra (easy to
Expand All @@ -1209,8 +1211,8 @@ where
/// Data buffer / ownership information. (If owned, contains the data
/// buffer; if borrowed, contains the lifetime and mutability.)
data: S,
/// A non-null and aligned pointer into the buffer held by `data`; may
/// point anywhere in its range.
/// A non-null pointer into the buffer held by `data`; may point anywhere
/// in its range. If `S: Data`, this pointer must be aligned.
ptr: std::ptr::NonNull<S::Elem>,
/// The lengths of the axes.
dim: D,
Expand Down Expand Up @@ -1331,7 +1333,7 @@ pub type ArrayViewMut<'a, A, D> = ArrayBase<ViewRepr<&'a mut A>, D>;
/// conversion into an [`ArrayView`]. The relationship between `RawArrayView`
/// and [`ArrayView`] is somewhat analogous to the relationship between `*const
/// T` and `&T`, but `RawArrayView` has additional requirements that `*const T`
/// does not, such as alignment and non-nullness.
/// does not, such as non-nullness.
///
/// [`ArrayView`]: type.ArrayView.html
///
Expand All @@ -1356,8 +1358,7 @@ pub type RawArrayView<A, D> = ArrayBase<RawViewRepr<*const A>, D>;
/// unsafe conversion into an [`ArrayViewMut`]. The relationship between
/// `RawArrayViewMut` and [`ArrayViewMut`] is somewhat analogous to the
/// relationship between `*mut T` and `&mut T`, but `RawArrayViewMut` has
/// additional requirements that `*mut T` does not, such as alignment and
/// non-nullness.
/// additional requirements that `*mut T` does not, such as non-nullness.
///
/// [`ArrayViewMut`]: type.ArrayViewMut.html
///
Expand Down
43 changes: 20 additions & 23 deletions tests/raw_views.rs