[][src]Trait nshare::ToNdarray2

pub trait ToNdarray2 {
    type Out;
    fn to_ndarray2(self) -> Self::Out;
}

Converts 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

type Out

Loading content...

Required methods

fn to_ndarray2(self) -> Self::Out

Loading content...

Implementations on Foreign Types

impl<A> ToNdarray2 for ImageBuffer<Luma<A>, Vec<A>> where
    A: Primitive + 'static, 
[src]

use image::GrayImage;
use nshare::ToNdarray2;
use ndarray::s;

let zeros = GrayImage::new(2, 4);
let mut nd = zeros.to_ndarray2();
nd.fill(255);
// ndarray uses (row, col), so the dims get flipped.
assert_eq!(nd.dim(), (4, 2));

type Out = Array2<A>

impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> ToNdarray2 for Matrix<N, R, C, SliceStorage<'a, N, R, C, RStride, CStride>>[src]

use nshare::ToNdarray2;
use nalgebra::Matrix4;

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.row(1).to_ndarray2();
assert!(arr.iter().eq(&[0.5, 0.6, 0.7, 0.8]));
assert_eq!(arr.dim(), (1, 4));

type Out = ArrayView2<'a, N>

impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> ToNdarray2 for Matrix<N, R, C, SliceStorageMut<'a, N, R, C, RStride, CStride>>[src]

use nshare::ToNdarray2;
use nalgebra::Matrix4;

let mut 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.row_mut(1).to_ndarray2().fill(0.0);
assert!(m.row(1).iter().eq(&[0.0; 4]));

type Out = ArrayViewMut2<'a, N>

impl<'a, N: Scalar> ToNdarray2 for Matrix<N, Dynamic, Dynamic, VecStorage<N, Dynamic, Dynamic>> where
    DefaultAllocator: Allocator<N, Dynamic, Dynamic, Buffer = VecStorage<N, Dynamic, Dynamic>>, 
[src]

use nshare::ToNdarray2;
use nalgebra::{Matrix, dimension::{U4, Dynamic}};
use ndarray::s;

let m = Matrix::<f32, Dynamic, Dynamic, _>::from_vec(4, 4, vec![
    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.to_ndarray2();
assert!(arr.slice(s![0, ..]).iter().eq(&[0.1, 0.2, 0.3, 0.4]));
assert!(arr.slice(s![.., 0]).iter().eq(&[0.1, 0.5, 1.1, 1.5]));

type Out = Array2<N>

Loading content...

Implementors

Loading content...