Skip to main content

ArraySequence

Trait ArraySequence 

Source
pub trait ArraySequence: ArraySequenceImpl { }
Expand description

A sequence of arrays passed to multi-array operations such as stack and concatenate.

Arrays in the sequence may have different element types or dimensions, both runtime and compile-time. The sub traits ArraySequenceElementType and ArraySequenceDimension are used to constrain operations to sequences where all arrays share the same element type and dimension.

This is a sealed trait - it cannot be implemented outside this crate. It is implemented for the following collection types, covering both homogeneous and heterogeneous cases:

TypeNotes
[Array<S>; N]Fixed-length array; all elements share the same storage type.
Vec<Array<S>>Dynamic-length list; all elements share the same storage type.
&[Array<S>]Borrowed slice; all elements share the same storage type.
(Array<S0>, Array<S1>, ...)Tuple of up to 10 arrays; each element may have a different storage type.

§Examples

Stack with a fixed-length array (homogeneous):

use jix::Array;
use ndarray::array;

let a = Array::compact_ndarray(&array![1i32, 2, 3])?;
let b = Array::compact_ndarray(&array![4i32, 5, 6])?;
let stacked = jix::ops::stack([a, b], 0);
assert_eq!(stacked.shape(), &[2, 3]);

Stack a tuple of arrays with different storage types (heterogeneous):

use jix::Array;
use ndarray::array;

let a = Array::compact_ndarray(&array![1i32, 2, 3])?;
let b = Array::compact_ndarray(&array![4i32, 5, 6])?;
// Lazy view has a different storage type from the original Compact arrays,
// but a tuple still implements ArraySequence.
let c = a.map(|x| x + 8);
let stacked = jix::ops::stack((b, c), 0);
assert_eq!(stacked.shape(), &[2, 3]);

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<T: ArraySequenceImpl> ArraySequence for T