pub trait RefNdarray2 {
    type Out;
    fn ref_ndarray2(self) -> Self::Out;
}
Expand description

Borrows a 2d type to a ndarray 2d array type.

Coordinates are in (row, col).

This uses an associated type to avoid ambiguity for the compiler. By calling this, the compiler always knows the returned type.

Associated Types

Required methods

Implementations on Foreign Types

use image::{GrayImage, Luma};
use nshare::RefNdarray2;
use ndarray::s;

let mut vals = GrayImage::new(2, 4);
vals[(1, 0)] = Luma([255]);
let nd = vals.ref_ndarray2();
// ndarray uses (row, col), so the dims get flipped.
assert_eq!(nd.dim(), (4, 2));
// The first row should sum to 255.
assert_eq!(nd.slice(s![0, ..]).sum(), 255);
use nshare::RefNdarray2;
use nalgebra::Matrix4;
use ndarray::s;

let m = Matrix4::new(
    0.1, 0.2, 0.3, 0.4,
    0.5, 0.6, 0.7, 0.8,
    1.1, 1.2, 1.3, 1.4,
    1.5, 1.6, 1.7, 1.8,
);
let arr = m.ref_ndarray2();
assert!(arr.slice(s![1, ..]).iter().eq(&[0.5, 0.6, 0.7, 0.8]));
assert_eq!(arr.dim(), (4, 4));

Implementors