Function rerun::external::ndarray::prelude::aview1

source ·
pub const fn aview1<A>(xs: &[A]) -> ArrayBase<ViewRepr<&A>, Dim<[usize; 1]>>
Expand description

Create a one-dimensional array view with elements borrowing xs.

Panics if the length of the slice overflows isize. (This can only occur if A is zero-sized, because slices cannot contain more than isize::MAX number of bytes.)

use ndarray::{aview1, ArrayView1};

let data = [1.0; 1024];

// Create a 2D array view from borrowed data
let a2d = aview1(&data).into_shape_with_order((32, 32)).unwrap();

assert_eq!(a2d.sum(), 1024.0);

// Create a const 1D array view
const C: ArrayView1<'static, f64> = aview1(&[1., 2., 3.]);

assert_eq!(C.sum(), 6.);