Skip to main content

IntoArray

Trait IntoArray 

Source
pub trait IntoArray<T: Element> {
    // Required method
    fn into_array(self) -> Array<T>;

    // Provided method
    fn scalar_value(&self) -> Option<T> { ... }
}
Expand description

Converts an array-like value into an array, like NumPy asarray.

use rustnum::{IntoArray, array};
assert_eq!(3.into_array().item(),3);
assert_eq!([1,2].into_array(),array![1,2]);
let v=vec![1,2]; assert_eq!(v.as_slice().into_array(),array![1,2]);
assert_eq!(v.into_array(),array![1,2]);
let a=array![1,2]; assert_eq!((&a).into_array(),a.clone().into_array());

Required Methods§

Source

fn into_array(self) -> Array<T>

Converts to an array, like np.asarray.

use rustnum::IntoArray;
assert_eq!(7.into_array().item(),7);

Provided Methods§

Source

fn scalar_value(&self) -> Option<T>

Exposes a scalar without allocation, like NumPy scalar broadcasting.

use rustnum::IntoArray;
assert_eq!(3.scalar_value(),Some(3));

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T: Element, const N: usize> IntoArray<T> for [T; N]

Source§

fn into_array(self) -> Array<T>

Source§

impl<T: Element> IntoArray<T> for &[T]

Source§

fn into_array(self) -> Array<T>

Source§

impl<T: Element> IntoArray<T> for Vec<T>

Source§

fn into_array(self) -> Array<T>

Implementors§

Source§

impl<T: Element> IntoArray<T> for &Array<T>

Source§

impl<T: Element> IntoArray<T> for Array<T>

Source§

impl<T: Element> IntoArray<T> for T