ndarray::s! [] [src]

macro_rules! s {
    (@as_expr $e:expr) => { ... };
    (@parse [$($stack:tt)*] $r:expr;$s:expr) => { ... };
    (@parse [$($stack:tt)*] $r:expr) => { ... };
    (@parse [$($stack:tt)*] $r:expr;$s:expr, $($t:tt)*) => { ... };
    (@parse [$($stack:tt)*] $r:expr, $($t:tt)*) => { ... };
    (@step $r:expr, $s:expr) => { ... };
    ($($t:tt)*) => { ... };
}

Slice argument constructor.

s![] takes a list of ranges, separated by comma, with optional strides that are separated from the range by a semicolon. It is converted into a slice argument with type &[Si; N].

Each range uses signed indices, where a negative value is counted from the end of the axis. Strides are also signed and may be negative, but must not be zero.

For example, if an array has two axes, the slice argument is passed as type &[Si; 2].

For example s![a..b;c, d..e] is equivalent to &[Si(a, Some(b), c), Si(d, Some(e), 1)].

#[macro_use]
extern crate ndarray;

use ndarray::{
    ArrayView,
    Ix,
    OwnedArray,
};

fn laplacian(v: &ArrayView<f32, (Ix, Ix)>) -> OwnedArray<f32, (Ix, Ix)> {
    -4. * &v.slice(s![1..-1, 1..-1])
    + v.slice(s![ ..-2, 1..-1])
    + v.slice(s![1..-1,  ..-2])
    + v.slice(s![1..-1, 2..  ])
    + v.slice(s![2..  , 1..-1])
}