Trait ArraySplit

Source
pub trait ArraySplit<T: ArrayElement>
where Self: Sized + Clone,
{ // Required methods fn array_split( &self, parts: usize, axis: Option<usize>, ) -> Result<Vec<Array<T>>, ArrayError>; fn split( &self, parts: usize, axis: Option<usize>, ) -> Result<Vec<Array<T>>, ArrayError>; fn split_axis(&self, axis: usize) -> Result<Vec<Array<T>>, ArrayError>; fn hsplit(&self, parts: usize) -> Result<Vec<Array<T>>, ArrayError>; fn vsplit(&self, parts: usize) -> Result<Vec<Array<T>>, ArrayError>; fn dsplit(&self, parts: usize) -> Result<Vec<Array<T>>, ArrayError>; }
Expand description

ArrayTrait - Array Split functions

Required Methods§

Source

fn array_split( &self, parts: usize, axis: Option<usize>, ) -> Result<Vec<Array<T>>, ArrayError>

Split an array into multiple sub-arrays

§Arguments
  • parts - indices defining how to split the array
  • axis - the axis along which to split. optional, defaults to 0
§Examples
use arr_rs::prelude::*;

let arr = array_arange!(i32, 0, 7);
let split = arr.array_split(3, None).unwrap();
assert_eq!(vec![array_flat!(i32, 0, 1, 2).unwrap(), array_flat!(i32, 3, 4, 5).unwrap(), array_flat!(i32, 6, 7).unwrap()], split);

let arr = array_arange!(i32, 0, 8);
let split = arr.array_split(4, None).unwrap();
assert_eq!(vec![array_flat!(i32, 0, 1, 2).unwrap(), array_flat!(i32, 3, 4).unwrap(), array_flat!(i32, 5, 6).unwrap(), array_flat!(i32, 7, 8).unwrap()], split);
§Errors

may returns ArrayError

Source

fn split( &self, parts: usize, axis: Option<usize>, ) -> Result<Vec<Array<T>>, ArrayError>

Split an array into multiple sub-arrays of equal size

§Arguments
  • parts - indices defining how to split the array
  • axis - the axis along which to split. optional, defaults to 0
§Examples
use arr_rs::prelude::*;

let arr = array_arange!(i32, 0, 8);
let split = arr.split(3, None).unwrap();
assert_eq!(vec![array_flat!(i32, 0, 1, 2).unwrap(), array_flat!(i32, 3, 4, 5).unwrap(), array_flat!(i32, 6, 7, 8).unwrap()], split);

let arr = array_arange!(i32, 0, 7);
let split = arr.split(4, None).unwrap();
assert_eq!(vec![array_flat!(i32, 0, 1).unwrap(), array_flat!(i32, 2, 3).unwrap(), array_flat!(i32, 4, 5).unwrap(), array_flat!(i32, 6, 7).unwrap()], split);
§Errors

may returns ArrayError

Source

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

Split an array into multiple sub-arrays of equal size by axis

§Arguments
  • axis - the axis along which to split
§Examples
use arr_rs::prelude::*;

let arr = array_arange!(i32, 0, 3).reshape(&[2, 2]);
let split = arr.split_axis(0).unwrap();
assert_eq!(vec![array!(i32, [[0, 1]]).unwrap(), array!(i32, [[2, 3]]).unwrap()], split);

let arr = array_arange!(i32, 0, 7).reshape(&[2, 2, 2]);
let split = arr.split_axis(1).unwrap();
assert_eq!(vec![array!(i32, [[[0, 1]], [[4, 5]]]).unwrap(), array!(i32, [[[2, 3]], [[6, 7]]]).unwrap()], split);
§Errors

may returns ArrayError

Source

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

Split an array into multiple sub-arrays horizontally (column-wise)

§Arguments
  • parts - indices defining how to split the array
§Examples
use arr_rs::prelude::*;

let arr = array_arange!(i32, 0, 7).reshape(&[2, 2, 2]).unwrap();
let split = arr.hsplit(2).unwrap();
assert_eq!(vec![array!(i32, [[[0, 1]], [[4, 5]]]).unwrap(), array!(i32, [[[2, 3]], [[6, 7]]]).unwrap()], split);
§Errors

may returns ArrayError

Source

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

Split an array into multiple sub-arrays vertically (row-wise)

§Arguments
  • parts - indices defining how to split the array
§Examples
use arr_rs::prelude::*;

let arr = array_arange!(i32, 0, 7).reshape(&[2, 2, 2]).unwrap();
let split = arr.vsplit(2).unwrap();
assert_eq!(vec![array!(i32, [[[0, 1], [2, 3]]]).unwrap(), array!(i32, [[[4, 5], [6, 7]]]).unwrap()], split);
§Errors

may returns ArrayError

Source

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

Split an array into multiple sub-arrays along the 3rd axis (depth)

§Arguments
  • parts - indices defining how to split the array
§Examples
use arr_rs::prelude::*;

let arr = array_arange!(i32, 0, 7).reshape(&[2, 2, 2]).unwrap();
let split = arr.dsplit(2).unwrap();
assert_eq!(vec![array!(i32, [[[0], [2]], [[4], [6]]]).unwrap(), array!(i32, [[[1], [3]], [[5], [7]]]).unwrap()], split);
§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> ArraySplit<T> for Result<Array<T>, ArrayError>

Source§

fn array_split( &self, parts: usize, axis: Option<usize>, ) -> Result<Vec<Array<T>>, ArrayError>

Source§

fn split( &self, parts: usize, axis: Option<usize>, ) -> Result<Vec<Array<T>>, ArrayError>

Source§

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

Source§

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

Source§

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

Source§

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

Implementors§