pub struct Array<B: Backend, T: Element>(/* private fields */);Expand description
An array of element type T on backend B, with a shape known at run
time (and fixed within a traced program).
On Native it holds shared elements, so clone is cheap; on Trace it
is a traced value.
Implementations§
Source§impl<B: Backend, T: Element> Array<B, T>
impl<B: Backend, T: Element> Array<B, T>
Sourcepub fn i(&self, index: impl IntoIndices<B>) -> Array<B, T>
pub fn i(&self, index: impl IntoIndices<B>) -> Array<B, T>
The elements at index, like x[index] in JAX.
Run-time indices out of bounds are clamped (as in JAX); a static integer out of bounds panics.
Sourcepub fn get(&self, index: impl IntoIndices<B>) -> Scalar<B, T>
pub fn get(&self, index: impl IntoIndices<B>) -> Scalar<B, T>
The element at index, which must select a single element.
§Panics
Panics if the index selects more than one element.
Sourcepub fn at(&self, index: impl IntoIndices<B>) -> At<'_, B, T>
pub fn at(&self, index: impl IntoIndices<B>) -> At<'_, B, T>
Updates of the elements at index, like x.at[index] in JAX. The
updates return new arrays; out-of-bounds updates are dropped.
Sourcepub fn into_at(self, index: impl IntoIndices<B>) -> At<'static, B, T>
pub fn into_at(self, index: impl IntoIndices<B>) -> At<'static, B, T>
Array::at taking the array: an update of one element then writes
in place when the array’s elements are not shared, instead of
copying them (Native; the result is the same).
§Examples
use ruxla_core::{Native, jnp};
let grid = jnp::zeros::<Native, f32>([3, 3]).into_at((1i64, 2i64)).set(1.0f32);
assert_eq!(grid.get((1i64, 2i64)).value(), 1.0);Sourcepub fn at_mut(&mut self, index: impl IntoIndices<B>) -> AtMut<'_, B, T>
pub fn at_mut(&mut self, index: impl IntoIndices<B>) -> AtMut<'_, B, T>
Updates of the elements at index that replace this array (like
x = x.at[index].set(v) in JAX). Natively, an update of one element
writes in place when the elements are not shared, without moving
the array; traced, it records the same scatter as Array::at.
§Examples
use ruxla_core::{Native, jnp};
let mut grid = jnp::zeros::<Native, f32>([3, 3]);
grid.at_mut((1i64, 2i64)).set(1.0f32);
grid.at_mut((1i64, 2i64)).add(0.5f32);
assert_eq!(grid.get((1i64, 2i64)).value(), 1.5);Source§impl<B: Backend, T: ComplexFloat> Array<B, T>
impl<B: Backend, T: ComplexFloat> Array<B, T>
Source§impl<B: Backend, T: Numeric> Array<B, T>
impl<B: Backend, T: Numeric> Array<B, T>
Source§impl<B: Backend, T: Float> Array<B, T>
impl<B: Backend, T: Float> Array<B, T>
Sourcepub fn round_even(&self) -> Self
pub fn round_even(&self) -> Self
Round to the nearest integer, halfway cases to even.
Source§impl<B: Backend, T: Element> Array<B, T>
impl<B: Backend, T: Element> Array<B, T>
Sourcepub fn from_vec(data: Vec<T>, shape: impl Into<Shape>) -> Self
pub fn from_vec(data: Vec<T>, shape: impl Into<Shape>) -> Self
A constant array from its elements in row-major order.
§Panics
Panics if the number of elements does not match the shape.
Sourcepub fn from_slice(data: &[T], shape: impl Into<Shape>) -> Self
pub fn from_slice(data: &[T], shape: impl Into<Shape>) -> Self
A constant array from a copy of its elements in row-major order
(like Array::from_vec, without a Vec).
§Examples
use ruxla_core::{Array, I32, Native};
let table = Array::<Native, i32>::from_slice(&[1, 0, 3, 2], [4]);
assert_eq!(table.get(I32::new(2)).value(), 3);§Panics
Panics if the number of elements does not match the shape.
Sourcepub fn constant(x: &NativeArray<T>) -> Self
pub fn constant(x: &NativeArray<T>) -> Self
A constant array.
Sourcepub fn transpose(&self, perm: &[usize]) -> Self
pub fn transpose(&self, perm: &[usize]) -> Self
Permutes the dimensions: dimension i of the result is dimension
perm[i] of self.
Sourcepub fn broadcast_to(&self, shape: impl Into<Shape>) -> Self
pub fn broadcast_to(&self, shape: impl Into<Shape>) -> Self
Sourcepub fn reduce_sum(&self, axes: &[usize]) -> Self
pub fn reduce_sum(&self, axes: &[usize]) -> Self
Sums over axes (lax.reduce_sum; integers wrap around).
Sourcepub fn reduce_max(&self, axes: &[usize]) -> Self
pub fn reduce_max(&self, axes: &[usize]) -> Self
The maximum over axes, propagating NaN (lax.reduce_max).
Sourcepub fn reduce_min(&self, axes: &[usize]) -> Self
pub fn reduce_min(&self, axes: &[usize]) -> Self
The minimum over axes, propagating NaN (lax.reduce_min).
Trait Implementations§
Source§impl<B: Backend, T: Element> ArrayLike<B, T> for Array<B, T>
impl<B: Backend, T: Element> ArrayLike<B, T> for Array<B, T>
Source§fn into_array(self) -> Array<B, T>
fn into_array(self) -> Array<B, T>
Source§fn with_array<R>(self, f: impl FnOnce(&Array<B, T>) -> R) -> R
fn with_array<R>(self, f: impl FnOnce(&Array<B, T>) -> R) -> R
f with the array, without copying a borrowed array.Source§impl<B: Backend, T: Element> ArrayLike<B, T> for &Array<B, T>
impl<B: Backend, T: Element> ArrayLike<B, T> for &Array<B, T>
Source§fn into_array(self) -> Array<B, T>
fn into_array(self) -> Array<B, T>
Source§fn with_array<R>(self, f: impl FnOnce(&Array<B, T>) -> R) -> R
fn with_array<R>(self, f: impl FnOnce(&Array<B, T>) -> R) -> R
f with the array, without copying a borrowed array.