Skip to content

Add note about memory layout in .to_owned() docs #442

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

Merged
merged 1 commit into from
May 4, 2018
Merged
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
31 changes: 30 additions & 1 deletion src/impl_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,36 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
}
}

/// Return an uniquely owned copy of the array
/// Return an uniquely owned copy of the array.
///
/// If the input array is contiguous and its strides are positive, then the
/// output array will have the same memory layout. Otherwise, the layout of
/// the output array is unspecified. If you need a particular layout, you
/// can allocate a new array with the desired memory layout and
/// [`.assign()`](#method.assign) the data. Alternatively, you can collect
/// an iterator, like this for a result in standard layout:
///
/// ```
/// # use ndarray::prelude::*;
/// # let arr = Array::from_shape_vec((2, 2).f(), vec![1, 2, 3, 4]).unwrap();
/// # let owned = {
/// Array::from_shape_vec(arr.raw_dim(), arr.iter().cloned().collect()).unwrap()
/// # };
/// # assert!(owned.is_standard_layout());
/// # assert_eq!(arr, owned);
/// ```
///
/// or this for a result in column-major (Fortran) layout:
///
/// ```
/// # use ndarray::prelude::*;
/// # let arr = Array::from_shape_vec((2, 2), vec![1, 2, 3, 4]).unwrap();
/// # let owned = {
/// Array::from_shape_vec(arr.raw_dim().f(), arr.t().iter().cloned().collect()).unwrap()
/// # };
/// # assert!(owned.t().is_standard_layout());
/// # assert_eq!(arr, owned);
/// ```
pub fn to_owned(&self) -> Array<A, D>
where A: Clone
{
Expand Down