diff --git a/RELEASES.md b/RELEASES.md index 071d12464..b5e351e92 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,4 +1,4 @@ -Version 0.13.1 (2020-04) +Version 0.13.1 (2020-04-21) =========================== New features @@ -14,7 +14,10 @@ New features https://github.com/rust-ndarray/ndarray/pull/728 - `Dimension::Larger` now requires `RemoveAxis` by [@TheLortex] https://github.com/rust-ndarray/ndarray/pull/792 - +- New methods for collecting Zip into an array by [@bluss] + https://github.com/rust-ndarray/ndarray/pull/797 +- New `Array::maybe_uninit` and `.assume_init()` by [@bluss] + https://github.com/rust-ndarray/ndarray/pull/803 Enhancements ------------ @@ -25,6 +28,8 @@ Enhancements https://github.com/rust-ndarray/ndarray/pull/754 - Implement `fold` for `IndicesIter` by [@jturner314] https://github.com/rust-ndarray/ndarray/pull/733 +- New Quick Start readme by [@lifuyang] + https://github.com/rust-ndarray/ndarray/pull/785 API changes ----------- @@ -39,6 +44,9 @@ Other changes - Improve blas version documentation by [@jturner314] - Doc improvements by [@mockersf] https://github.com/rust-ndarray/ndarray/pull/751 - Doc and lint related improvements by [@viniciusd] https://github.com/rust-ndarray/ndarray/pull/750 +- Minor fixes related to best practices for unsafe code by [@bluss] + https://github.com/rust-ndarray/ndarray/pull/799 + https://github.com/rust-ndarray/ndarray/pull/802 - Release management by [@bluss] @@ -944,3 +952,4 @@ Earlier releases [@TheLortex]: https://github.com/TheLortex [@mockersf]: https://github.com/mockersf [@viniciusd]: https://github.com/viniciusd +[@lifuyang]: https://github.com/liufuyang diff --git a/src/impl_constructors.rs b/src/impl_constructors.rs index 964003dd8..8d1471e78 100644 --- a/src/impl_constructors.rs +++ b/src/impl_constructors.rs @@ -474,41 +474,20 @@ where /// /// ### Safety /// - /// Accessing uninitalized values is undefined behaviour. You must - /// overwrite *all* the elements in the array after it is created; for - /// example using the methods `.fill()` or `.assign()`. + /// Accessing uninitalized values is undefined behaviour. You must overwrite *all* the elements + /// in the array after it is created; for example using + /// [`raw_view_mut`](ArrayBase::raw_view_mut) or other low-level element access. /// /// The contents of the array is indeterminate before initialization and it /// is an error to perform operations that use the previous values. For /// example it would not be legal to use `a += 1.;` on such an array. /// /// This constructor is limited to elements where `A: Copy` (no destructors) - /// to avoid users shooting themselves too hard in the foot; it is not - /// a problem to drop an array created with this method even before elements - /// are initialized. (Note that constructors `from_shape_vec` and - /// `from_shape_vec_unchecked` allow the user yet more control). - /// - /// ### Examples - /// - /// ``` - /// use ndarray::{s, Array2}; - /// - /// // Example Task: Let's create a column shifted copy of a in b - /// - /// fn shift_by_two(a: &Array2) -> Array2 { - /// let mut b = unsafe { Array2::uninitialized(a.dim()) }; - /// - /// // two first columns in b are two last in a - /// // rest of columns in b are the initial columns in a - /// b.slice_mut(s![.., ..2]).assign(&a.slice(s![.., -2..])); - /// b.slice_mut(s![.., 2..]).assign(&a.slice(s![.., ..-2])); - /// - /// // `b` is safe to use with all operations at this point - /// b - /// } - /// - /// # shift_by_two(&Array2::zeros((8, 8))); - /// ``` + /// to avoid users shooting themselves too hard in the foot. + /// + /// (Also note that the constructors `from_shape_vec` and + /// `from_shape_vec_unchecked` allow the user yet more control, in the sense + /// that Arrays can be created from arbitrary vectors.) pub unsafe fn uninitialized(shape: Sh) -> Self where A: Copy, @@ -554,7 +533,7 @@ where /// use ndarray::Zip; /// use ndarray::Axis; /// - /// // Example Task: Let's create a transposed copy of the input + /// // Example Task: Let's create a column shifted copy of the input /// /// fn shift_by_two(a: &Array2) -> Array2 { /// // create an uninitialized array @@ -574,6 +553,8 @@ where /// /// use ndarray::{IntoNdProducer, AssignElem}; /// + /// // This function clones elements from the first input to the second; + /// // the two producers must have the same shape /// fn assign_to<'a, P1, P2, A>(from: P1, to: P2) /// where P1: IntoNdProducer, /// P2: IntoNdProducer,