Trait ArrayBroadcast

Source
pub trait ArrayBroadcast<T: ArrayElement>
where Self: Sized + Clone,
{ // Required methods fn broadcast( &self, other: &Array<T>, ) -> Result<Array<Tuple2<T, T>>, ArrayError>; fn broadcast_to(&self, shape: Vec<usize>) -> Result<Array<T>, ArrayError>; fn broadcast_arrays( arrays: Vec<Array<T>>, ) -> Result<Vec<Array<T>>, ArrayError>; }
Expand description

ArrayTrait - Array Broadcast functions

Required Methods§

Source

fn broadcast(&self, other: &Array<T>) -> Result<Array<Tuple2<T, T>>, ArrayError>

Broadcast an array to a new shape

§Arguments
  • other - other array for broadcasting
§Examples
use arr_rs::prelude::*;

let expected = Array::new(vec![
    (1, 4), (1, 5), (1, 6),
    (2, 4), (2, 5), (2, 6),
    (3, 4), (3, 5), (3, 6)
].into_iter().map(Tuple2::from_tuple).collect(), vec![3, 3]).unwrap();

let arr_1 = array!(i32, [[1], [2], [3]]).unwrap();
let arr_2 = array!(i32, [[4, 5, 6]]).unwrap();

let broadcast = arr_1.broadcast(&arr_2).unwrap();
assert_eq!(expected, broadcast);
§Errors

may returns ArrayError

Source

fn broadcast_to(&self, shape: Vec<usize>) -> Result<Array<T>, ArrayError>

Broadcast an array to a new shape

§Arguments
  • other - other array for broadcasting
§Examples
use arr_rs::prelude::*;

let expected = Array::new(vec![1, 1, 1, 2, 2, 2, 3, 3, 3], vec![3, 3]).unwrap();
let arr_1 = array!(i32, [[1], [2], [3]]).unwrap();

let broadcast = arr_1.broadcast_to(vec![3, 3]).unwrap();
assert_eq!(expected, broadcast);
§Errors

may returns ArrayError

Source

fn broadcast_arrays(arrays: Vec<Array<T>>) -> Result<Vec<Array<T>>, ArrayError>

Broadcast a list of arrays to a common shape

§Arguments
  • arrays - list of arrays for broadcasting
§Examples
use arr_rs::prelude::*;

let expected = vec![
    Array::new(vec![1, 1, 1, 2, 2, 2, 3, 3, 3], vec![3, 3]).unwrap(),
    Array::new(vec![4, 5, 6, 4, 5, 6, 4, 5, 6], vec![3, 3]).unwrap(),
];
let arr_1 = array!(i32, [[1], [2], [3]]).unwrap();
let arr_2 = array!(i32, [4, 5, 6]).unwrap();

let broadcast = Array::broadcast_arrays(vec![arr_1 ,arr_2]).unwrap();
assert_eq!(expected, broadcast);
§Errors

may returns ArrayError

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T: ArrayElement> ArrayBroadcast<T> for Result<Array<T>, ArrayError>

Source§

fn broadcast(&self, other: &Array<T>) -> Result<Array<Tuple2<T, T>>, ArrayError>

Source§

fn broadcast_to(&self, shape: Vec<usize>) -> Self

Source§

fn broadcast_arrays(arrays: Vec<Array<T>>) -> Result<Vec<Array<T>>, ArrayError>

Implementors§