pub struct Array { /* private fields */ }Expand description
A lazily evaluated n-dimensional array.
Cloning is cheap: clones share the computation and its result. Operations record a
graph node and return immediately; values are computed on Array::eval,
crate::eval, or when read back.
Implementations§
Source§impl Array
impl Array
Sourcepub fn from_slice<T: Element>(data: &[T], shape: &[usize]) -> Result<Self>
pub fn from_slice<T: Element>(data: &[T], shape: &[usize]) -> Result<Self>
An array holding data with the given shape.
Fails with Error::SizeMismatch if data.len() is not the shape’s element count.
Sourcepub fn full<T: Element>(shape: &[usize], value: T) -> Result<Self>
pub fn full<T: Element>(shape: &[usize], value: T) -> Result<Self>
An array of the given shape with every element set to value.
Sourcepub fn from_primitive(
primitive: Primitive,
inputs: Vec<Array>,
) -> Result<Vec<Array>>
pub fn from_primitive( primitive: Primitive, inputs: Vec<Array>, ) -> Result<Vec<Array>>
Records primitive applied to inputs, with the same validation as the operations,
and returns one array per output. Inputs that already failed short-circuit with their
error.
Sourcepub fn placeholder(dtype: DType, shape: &[usize]) -> Result<Array>
pub fn placeholder(dtype: DType, shape: &[usize]) -> Result<Array>
A placeholder with this dtype and shape, standing for an input while a function is traced (as in MLX): operations can be recorded on it, but evaluating anything that depends on it fails. Placeholders are tracers.
Sourcepub fn inputs(&self) -> Vec<Array>
pub fn inputs(&self) -> Vec<Array>
The arrays this one is computed from, until it has been evaluated. Empty for host data and evaluated arrays.
Sourcepub fn siblings(&self) -> Vec<Array>
pub fn siblings(&self) -> Vec<Array>
Every output of the operation that produces this array, in order (this array is
the one at Array::output_index).
Sourcepub fn output_index(&self) -> usize
pub fn output_index(&self) -> usize
Which output of its operation this array is.
Sourcepub fn id(&self) -> usize
pub fn id(&self) -> usize
Identifies the operation that produces this array (shared by its siblings) for as long as the array is alive.
Sourcepub fn is_tracer(&self) -> bool
pub fn is_tracer(&self) -> bool
Whether the array depends on a transform’s tracer or a placeholder, that is, it is
being traced by grad, vjp, jvp, vmap or compile.
Sourcepub fn is_evaluated(&self) -> bool
pub fn is_evaluated(&self) -> bool
Whether the array has been evaluated (successfully or not).
Sourcepub fn primitive(&self) -> Option<Primitive>
pub fn primitive(&self) -> Option<Primitive>
The operation that produces this array, until it has been evaluated.
None for host data and evaluated arrays.
Trait Implementations§
Source§impl<S: ScalarOperand> Add<S> for &Array
impl<S: ScalarOperand> Add<S> for &Array
Source§impl<S: ScalarOperand> Add<S> for Array
impl<S: ScalarOperand> Add<S> for Array
Source§impl<S: ScalarOperand> Div<S> for &Array
impl<S: ScalarOperand> Div<S> for &Array
Source§impl<S: ScalarOperand> Div<S> for Array
impl<S: ScalarOperand> Div<S> for Array
Source§impl From<&Array> for ScalarOrArray
impl From<&Array> for ScalarOrArray
Source§impl From<Array> for ScalarOrArray
impl From<Array> for ScalarOrArray
Source§impl<S: ScalarOperand> Mul<S> for &Array
impl<S: ScalarOperand> Mul<S> for &Array
Source§impl<S: ScalarOperand> Mul<S> for Array
impl<S: ScalarOperand> Mul<S> for Array
Source§impl<S: ScalarOperand> Sub<S> for &Array
impl<S: ScalarOperand> Sub<S> for &Array
Auto Trait Implementations§
impl !RefUnwindSafe for Array
impl !UnwindSafe for Array
impl Freeze for Array
impl Send for Array
impl Sync for Array
impl Unpin for Array
impl UnsafeUnpin for Array
Blanket Implementations§
impl<T> AutoreleaseSafe for Twhere
T: ?Sized,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more