Trait ToNalgebra

Source
pub trait ToNalgebra {
    type Out;

    // Required method
    fn into_nalgebra(self) -> Self::Out;
}
Expand description

Converts a 1 or 2 dimensional type to a nalgebra type.

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

Required Associated Types§

Required Methods§

Source

fn into_nalgebra(self) -> Self::Out

Implementations on Foreign Types§

Source§

impl<'a, T> ToNalgebra for ArrayView1<'a, T>
where T: Scalar,

use nshare::ToNalgebra;

let arr = ndarray::arr1(&[0.1, 0.2, 0.3, 0.4]);
let m = arr.view().into_nalgebra();
assert!(m.iter().eq(&[0.1, 0.2, 0.3, 0.4]));
assert_eq!(m.shape(), (4, 1));
Source§

type Out = Matrix<T, Dyn, Const<1>, ViewStorage<'a, T, Dyn, Const<1>, Const<1>, Dyn>>

Source§

fn into_nalgebra(self) -> Self::Out

Source§

impl<'a, T> ToNalgebra for ArrayView2<'a, T>
where T: Scalar,

use nshare::ToNalgebra;

let arr = ndarray::arr2(&[
    [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 m = arr.view().into_nalgebra();
assert!(m.row(1).iter().eq(&[0.5, 0.6, 0.7, 0.8]));
assert_eq!(m.shape(), (4, 4));
assert!(arr
    .t()
    .into_nalgebra()
    .column(1)
    .iter()
    .eq(&[0.5, 0.6, 0.7, 0.8]));
Source§

type Out = Matrix<T, Dyn, Dyn, ViewStorage<'a, T, Dyn, Dyn, Dyn, Dyn>>

Source§

fn into_nalgebra(self) -> Self::Out

Source§

impl<'a, T> ToNalgebra for ArrayViewMut1<'a, T>
where T: Scalar,

use nshare::ToNalgebra;

let mut arr = ndarray::arr1(&[0.1, 0.2, 0.3, 0.4]);
let m = arr.view_mut().into_nalgebra();
assert!(m.iter().eq(&[0.1, 0.2, 0.3, 0.4]));
assert_eq!(m.shape(), (4, 1));
Source§

type Out = Matrix<T, Dyn, Const<1>, ViewStorageMut<'a, T, Dyn, Const<1>, Const<1>, Dyn>>

Source§

fn into_nalgebra(self) -> Self::Out

Source§

impl<'a, T> ToNalgebra for ArrayViewMut2<'a, T>
where T: Scalar,

use nshare::ToNalgebra;

let mut arr = ndarray::arr2(&[
    [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 m = arr.view_mut().into_nalgebra();
assert!(m.row(1).iter().eq(&[0.5, 0.6, 0.7, 0.8]));
assert_eq!(m.shape(), (4, 4));
assert!(arr
    .view_mut()
    .reversed_axes()
    .into_nalgebra()
    .column(1)
    .iter()
    .eq(&[0.5, 0.6, 0.7, 0.8]));
Source§

type Out = Matrix<T, Dyn, Dyn, ViewStorageMut<'a, T, Dyn, Dyn, Dyn, Dyn>>

Source§

fn into_nalgebra(self) -> Self::Out

Source§

impl<T> ToNalgebra for Array1<T>
where T: Scalar,

use nshare::ToNalgebra;

let arr = ndarray::arr1(&[0.1, 0.2, 0.3, 0.4]);
let m = arr.into_nalgebra();
assert!(m.iter().eq(&[0.1, 0.2, 0.3, 0.4]));
assert_eq!(m.shape(), (4, 1));
Source§

type Out = Matrix<T, Dyn, Const<1>, VecStorage<T, Dyn, Const<1>>>

Source§

fn into_nalgebra(self) -> Self::Out

Source§

impl<T> ToNalgebra for Array2<T>
where T: Scalar,

use nshare::ToNalgebra;

let mut arr = ndarray::arr2(&[
    [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 m = arr.clone().into_nalgebra();
assert!(m.row(1).iter().eq(&[0.5, 0.6, 0.7, 0.8]));
assert_eq!(m.shape(), (4, 4));
assert!(arr
    .reversed_axes()
    .into_nalgebra()
    .column(1)
    .iter()
    .eq(&[0.5, 0.6, 0.7, 0.8]));
Source§

type Out = Matrix<T, Dyn, Dyn, VecStorage<T, Dyn, Dyn>>

Source§

fn into_nalgebra(self) -> Self::Out

Implementors§