@@ -474,41 +474,20 @@ where
474
474
///
475
475
/// ### Safety
476
476
///
477
- /// Accessing uninitalized values is undefined behaviour. You must
478
- /// overwrite *all* the elements in the array after it is created; for
479
- /// example using the methods `.fill()` or `.assign()` .
477
+ /// Accessing uninitalized values is undefined behaviour. You must overwrite *all* the elements
478
+ /// in the array after it is created; for example using
479
+ /// [`raw_view_mut`](ArrayBase::raw_view_mut) or other low-level element access .
480
480
///
481
481
/// The contents of the array is indeterminate before initialization and it
482
482
/// is an error to perform operations that use the previous values. For
483
483
/// example it would not be legal to use `a += 1.;` on such an array.
484
484
///
485
485
/// This constructor is limited to elements where `A: Copy` (no destructors)
486
- /// to avoid users shooting themselves too hard in the foot; it is not
487
- /// a problem to drop an array created with this method even before elements
488
- /// are initialized. (Note that constructors `from_shape_vec` and
489
- /// `from_shape_vec_unchecked` allow the user yet more control).
490
- ///
491
- /// ### Examples
492
- ///
493
- /// ```
494
- /// use ndarray::{s, Array2};
495
- ///
496
- /// // Example Task: Let's create a column shifted copy of a in b
497
- ///
498
- /// fn shift_by_two(a: &Array2<f32>) -> Array2<f32> {
499
- /// let mut b = unsafe { Array2::uninitialized(a.dim()) };
500
- ///
501
- /// // two first columns in b are two last in a
502
- /// // rest of columns in b are the initial columns in a
503
- /// b.slice_mut(s![.., ..2]).assign(&a.slice(s![.., -2..]));
504
- /// b.slice_mut(s![.., 2..]).assign(&a.slice(s![.., ..-2]));
505
- ///
506
- /// // `b` is safe to use with all operations at this point
507
- /// b
508
- /// }
509
- ///
510
- /// # shift_by_two(&Array2::zeros((8, 8)));
511
- /// ```
486
+ /// to avoid users shooting themselves too hard in the foot.
487
+ ///
488
+ /// (Also note that the constructors `from_shape_vec` and
489
+ /// `from_shape_vec_unchecked` allow the user yet more control, in the sense
490
+ /// that Arrays can be created from arbitrary vectors.)
512
491
pub unsafe fn uninitialized < Sh > ( shape : Sh ) -> Self
513
492
where
514
493
A : Copy ,
@@ -554,7 +533,7 @@ where
554
533
/// use ndarray::Zip;
555
534
/// use ndarray::Axis;
556
535
///
557
- /// // Example Task: Let's create a transposed copy of the input
536
+ /// // Example Task: Let's create a column shifted copy of the input
558
537
///
559
538
/// fn shift_by_two(a: &Array2<f32>) -> Array2<f32> {
560
539
/// // create an uninitialized array
@@ -574,6 +553,8 @@ where
574
553
///
575
554
/// use ndarray::{IntoNdProducer, AssignElem};
576
555
///
556
+ /// // This function clones elements from the first input to the second;
557
+ /// // the two producers must have the same shape
577
558
/// fn assign_to<'a, P1, P2, A>(from: P1, to: P2)
578
559
/// where P1: IntoNdProducer<Item = &'a A>,
579
560
/// P2: IntoNdProducer<Dim = P1::Dim>,
0 commit comments