Skip to main content

Native

Struct Native 

Source
pub struct Native;
Expand description

The native backend: programs run as native code compiled by rustc. Scalars are Rust values, arrays are NativeArrays, and control flow is real branches and loops.

Trait Implementations§

Source§

impl Backend for Native

Source§

type Scalar<T: Element> = T

A scalar.
Source§

type Array<T: Element> = NativeArray<T>

An array.
Source§

type Leaf = HostArray

A leaf of a pytree, of any element type.
Source§

fn lit<T: Element>(v: T) -> T

A scalar constant.
Source§

fn unary<T: Element>(op: UnaryOp, x: T) -> T

A unary operation.
Source§

fn binary<T: Element>(op: BinaryOp, x: T, y: T) -> T

A binary operation.
Source§

fn compare<T: Element>(op: CompareOp, x: T, y: T) -> bool

A comparison.
Source§

fn is_finite<T: Element>(x: T) -> bool

Whether the value is finite.
Source§

fn integer_pow<T: Element>(x: T, y: i32) -> T

x^y for a static integer y.
Source§

fn select<T: Element>(c: bool, t: T, f: T) -> T

if c { t } else { f }.
Source§

fn cast<T: Element, U: Element>(x: T) -> U

Conversion to another element type.
Source§

fn bitcast<T: Element, U: Element>(x: T) -> U

Reinterpretation of the bits as another type of the same size.
Source§

fn to_real<T: Element>(op: ToReal, x: T) -> T::Real

abs, real, or imag (real and imag of complex numbers).
Source§

fn complex<C: Element>(re: C::Real, im: C::Real) -> C

A complex number from its parts (lax.complex).
Source§

fn conj<T: Element>(x: T) -> T

The complex conjugate of a complex number.
Source§

fn constant<T: Element>(x: &NativeArray<T>) -> NativeArray<T>

A constant array.
Source§

fn shape<T: Element>(x: &NativeArray<T>) -> Shape

The shape of an array.
Source§

fn to_array<T: Element>(x: T) -> NativeArray<T>

A scalar as an array of rank 0.
Source§

fn to_scalar<T: Element>(x: &NativeArray<T>) -> T

An array of rank 0 as a scalar.
Source§

fn a_unary<T: Element>(op: UnaryOp, x: &NativeArray<T>) -> NativeArray<T>

Elementwise unary operation.
Source§

fn a_binary<T: Element>( op: BinaryOp, x: &NativeArray<T>, y: &NativeArray<T>, ) -> NativeArray<T>

Elementwise binary operation on arrays of the same shape.
Source§

fn a_ternary<T: Element>( op: TernaryOp, x: &NativeArray<T>, y: &NativeArray<T>, z: &NativeArray<T>, ) -> NativeArray<T>

Elementwise ternary operation on arrays of the same shape.
Source§

fn a_compare<T: Element>( op: CompareOp, x: &NativeArray<T>, y: &NativeArray<T>, ) -> NativeArray<bool>

Elementwise comparison of arrays of the same shape.
Source§

fn a_is_finite<T: Element>(x: &NativeArray<T>) -> NativeArray<bool>

Elementwise is_finite.
Source§

fn a_integer_pow<T: Element>(x: &NativeArray<T>, y: i32) -> NativeArray<T>

Elementwise integer_pow.
Source§

fn a_cast<T: Element, U: Element>(x: &NativeArray<T>) -> NativeArray<U>

Elementwise conversion.
Source§

fn a_bitcast<T: Element, U: Element>(x: &NativeArray<T>) -> NativeArray<U>

Elementwise bit reinterpretation.
Source§

fn a_to_real<T: Element>(op: ToReal, x: &NativeArray<T>) -> NativeArray<T::Real>

Elementwise abs, real, or imag.
Source§

fn a_complex<C: Element>( re: &NativeArray<C::Real>, im: &NativeArray<C::Real>, ) -> NativeArray<C>

Elementwise complex of arrays of the same shape.
Source§

fn a_conj<T: Element>(x: &NativeArray<T>) -> NativeArray<T>

Elementwise complex conjugate.
Source§

fn a_select<T: Element>( c: &NativeArray<bool>, t: &NativeArray<T>, f: &NativeArray<T>, ) -> NativeArray<T>

select_n(c, f, t): c is a scalar or has the shape of the cases.
Source§

fn a_clamp<T: Element>( lo: &NativeArray<T>, x: &NativeArray<T>, hi: &NativeArray<T>, ) -> NativeArray<T>

clamp(lo, x, hi): bounds are scalars or have the shape of x.
Source§

fn broadcast_in_dim<T: Element>( x: &NativeArray<T>, shape: &[usize], dims: &[usize], ) -> NativeArray<T>

broadcast_in_dim.
Source§

fn reshape<T: Element>(x: &NativeArray<T>, shape: &[usize]) -> NativeArray<T>

reshape.
Source§

fn transpose<T: Element>(x: &NativeArray<T>, perm: &[usize]) -> NativeArray<T>

transpose.
Source§

fn slice<T: Element>( x: &NativeArray<T>, start: &[usize], limit: &[usize], strides: &[usize], ) -> NativeArray<T>

slice.
Source§

fn dynamic_slice<T: Element, I: Element>( x: &NativeArray<T>, starts: &[I], sizes: &[usize], ) -> NativeArray<T>

dynamic_slice (start indices are clamped).
Source§

fn dynamic_update_slice<T: Element, I: Element>( x: &NativeArray<T>, update: &NativeArray<T>, starts: &[I], ) -> NativeArray<T>

dynamic_update_slice (start indices are clamped).
Source§

fn concatenate<T: Element>(xs: &[NativeArray<T>], dim: usize) -> NativeArray<T>

concatenate.
Source§

fn pad<T: Element>( x: &NativeArray<T>, value: T, config: &[(i64, i64, usize)], ) -> NativeArray<T>

pad.
Source§

fn rev<T: Element>(x: &NativeArray<T>, dims: &[usize]) -> NativeArray<T>

rev.
Source§

fn iota<T: Element>(shape: &[usize], dim: usize) -> NativeArray<T>

iota.
Source§

fn reduce<T: Element>( op: ReduceOp, x: &NativeArray<T>, axes: &[usize], ) -> NativeArray<T>

A reduction over axes.
Source§

fn arg_min_max<T: Element, I: Element>( x: &NativeArray<T>, axis: usize, max: bool, ) -> NativeArray<I>

argmax or argmin.
Source§

fn sort( operands: &[HostArray], dimension: usize, is_stable: bool, num_keys: usize, ) -> Vec<HostArray>

sort of operands of the same shape (of any element types) along dimension, lexicographically by the first num_keys of them.
Source§

fn cumulative<T: Element>( op: CumulativeOp, x: &NativeArray<T>, axis: usize, reverse: bool, ) -> NativeArray<T>

A cumulative reduction along axis (cumsum and the like), from the end with reverse.
Source§

fn top_k<T: Element>( x: &NativeArray<T>, k: usize, axis: usize, ) -> (NativeArray<T>, NativeArray<i32>)

top_k along axis: the k largest elements in descending order, and their indices.
Source§

fn cholesky<T: LinalgScalar>(x: &NativeArray<T>) -> NativeArray<T>

cholesky of a batch of matrices (see lax::linalg::cholesky).
Source§

fn triangular_solve<T: LinalgScalar>( a: &NativeArray<T>, b: &NativeArray<T>, options: TriangularSolveOptions, ) -> NativeArray<T>

triangular_solve of batches of matrices.
Source§

fn lu<T: LinalgScalar>( x: &NativeArray<T>, ) -> (NativeArray<T>, NativeArray<i32>, NativeArray<i32>)

lu of a batch of matrices: the factors, the pivots, and the permutation.
Source§

fn lu_pivots_to_permutation( pivots: &NativeArray<i32>, size: usize, ) -> NativeArray<i32>

lu_pivots_to_permutation.
Source§

fn qr<T: LinalgScalar>( x: &NativeArray<T>, full_matrices: bool, ) -> (NativeArray<T>, NativeArray<T>)

qr of a batch of matrices: q and r.
Source§

fn qr_pivoting<T: LinalgScalar>( x: &NativeArray<T>, full_matrices: bool, ) -> (NativeArray<T>, NativeArray<T>, NativeArray<i32>)

qr with column pivoting of a batch of matrices: q, r, and the permutation.
Source§

fn eigh<T: LinalgScalar>( x: &NativeArray<T>, lower: bool, sort_eigenvalues: bool, subset_by_index: Option<(usize, usize)>, algorithm: Option<EighImplementation>, ) -> (NativeArray<T>, NativeArray<T::Real>)

eigh of a batch of symmetric matrices: the eigenvectors and the eigenvalues (of the range subset_by_index of indices, if given).
Source§

fn schur<T: LinalgScalar>( x: &NativeArray<T>, compute_schur_vectors: bool, ) -> (NativeArray<T>, Option<NativeArray<T>>)

schur of a batch of square matrices: t and, with compute_schur_vectors, z.
Source§

fn hessenberg<T: LinalgScalar>( x: &NativeArray<T>, ) -> (NativeArray<T>, NativeArray<T>)

hessenberg of a batch of square matrices: the reduced matrices and the factors of the reflectors.
Source§

fn householder_product<T: LinalgScalar>( a: &NativeArray<T>, taus: &NativeArray<T>, ) -> NativeArray<T>

householder_product of reflectors and their factors.
Source§

fn ormqr<T: LinalgScalar>( a: &NativeArray<T>, taus: &NativeArray<T>, c: &NativeArray<T>, left: bool, transpose: bool, ) -> NativeArray<T>

ormqr: c times Q (or Q^H) of the reflectors.
Source§

fn cholesky_update<T: LinalgFloat>( r: &NativeArray<T>, w: &NativeArray<T>, ) -> NativeArray<T>

cholesky_update: the rank-1 update by w of the upper triangular Cholesky factors r.
Source§

fn symmetric_product<T: LinalgFloat>( a: &NativeArray<T>, c: &NativeArray<T>, alpha: f64, beta: f64, ) -> NativeArray<T>

symmetric_product: alpha a a^T + beta c.
Source§

fn tridiagonal<T: LinalgScalar>( x: &NativeArray<T>, lower: bool, ) -> (NativeArray<T>, NativeArray<T::Real>, NativeArray<T::Real>, NativeArray<T>)

tridiagonal of a batch of Hermitian matrices: the reduced matrices, the real diagonals and off-diagonals, and the factors of the reflectors.
Source§

fn tridiagonal_solve<T: LinalgScalar>( dl: &NativeArray<T>, d: &NativeArray<T>, du: &NativeArray<T>, b: &NativeArray<T>, perturb_singular: bool, ) -> NativeArray<T>

tridiagonal_solve: the solution of the tridiagonal systems of the diagonals dl, d, and du ([..., m]) with the right-hand sides b ([..., m, n]).
Source§

fn eig<T: LinalgScalar>( x: &NativeArray<T>, left: bool, right: bool, enable_eigvec_derivs: bool, ) -> (NativeArray<<T as LinalgScalar>::Complex>, Option<NativeArray<<T as LinalgScalar>::Complex>>, Option<NativeArray<<T as LinalgScalar>::Complex>>)

eig of a batch of general matrices: the complex eigenvalues, and the left and right eigenvectors that are requested.
Source§

fn svd<T: LinalgScalar>( x: &NativeArray<T>, full_matrices: bool, compute_uv: bool, subset_by_index: Option<(usize, usize)>, algorithm: Option<SvdAlgorithm>, ) -> (NativeArray<T::Real>, Option<(NativeArray<T>, NativeArray<T>)>)

svd of a batch of matrices: the singular values, and u and vt with compute_uv (of the range subset_by_index of indices, if given).
Source§

fn fft<T: Element, U: Element>( x: &NativeArray<T>, fft_type: FftType, fft_lengths: &[usize], ) -> NativeArray<U>

fft of the trailing axes, from T to U (complex to complex, real to complex, or complex to real).
Source§

fn dot_general<T: Element, U: Element>( l: &NativeArray<T>, r: &NativeArray<T>, dims: &DotDims, precision: Precision, ) -> NativeArray<U>

dot_general, computing in U (the operand type unless a preferred type is given).
Source§

fn conv_general_dilated<T: Element, U: Element>( lhs: &NativeArray<T>, rhs: &NativeArray<T>, window: &ConvWindow<'_>, dims: &ConvDims, groups: (usize, usize), precision: Precision, ) -> NativeArray<U>

conv_general_dilated with (feature_group_count, batch_group_count) groups, computing in U (the operand type unless a preferred type is given).
Source§

fn reduce_window<T: Element>( op: ReduceOp, x: &NativeArray<T>, window: &Window<'_>, ) -> NativeArray<T>

reduce_window_sum, reduce_window_max, or reduce_window_min.
Source§

fn select_and_scatter_add<T: Element>( source: &NativeArray<T>, operand: &NativeArray<T>, select_prim: SelectPrim, window: &Window<'_>, ) -> NativeArray<T>

select_and_scatter_add (the window’s dilations must be 1).
Source§

fn select_and_gather_add<T: Element>( tangents: &NativeArray<T>, operand: &NativeArray<T>, select_prim: SelectPrim, window: &Window<'_>, ) -> NativeArray<T>

select_and_gather_add.
Source§

fn gather<T: Element, I: Element>( x: &NativeArray<T>, indices: &NativeArray<I>, dims: &GatherDims, sizes: &[usize], mode: GatherScatterMode, sorted_unique: bool, ) -> NativeArray<T>

gather.
Source§

fn scatter<T: Element, I: Element>( combine: Option<BinaryOp>, x: &NativeArray<T>, indices: &NativeArray<I>, updates: &NativeArray<T>, dims: &ScatterDims, mode: GatherScatterMode, sorted_unique: bool, ) -> NativeArray<T>

A scatter: replaces (combine is None) or combines updates.
Source§

fn cond<S: Tree<Self>, R: Tree<Self>>( index: I32<Native>, branches: &[&dyn Fn(S) -> R], operand: S, ) -> R

Calls branches[index] on operand; an index out of range calls the last branch, as stablehlo.case does.
Source§

fn while_loop<C: Tree<Self>>( cond: &dyn Fn(&C) -> Bool<Native>, body: &dyn Fn(C) -> C, init: C, ) -> C

Repeats body while cond holds.
Source§

fn scan<C: Tree<Self>, X: Tree<Self>, Y: Tree<Self>>( f: &dyn Fn(C, X) -> (C, Y), init: C, xs: X, length: usize, reverse: bool, ) -> (C, Y)

A loop over the leading dimension of the arrays of xs.
Source§

fn fori_loop<C: Tree<Self>>( lo: I32<Native>, hi: I32<Native>, body: &dyn Fn(I32<Native>, C) -> C, init: C, ) -> C

for i in lo..hi { state = body(i, state) }.
Source§

fn scalar_leaf<T: Element>(x: T) -> HostArray

A scalar as a pytree leaf.
Source§

fn leaf_scalar<T: Element>(l: HostArray) -> T

A pytree leaf as a scalar.
Source§

fn array_leaf<T: Element>(x: &NativeArray<T>) -> HostArray

An array as a pytree leaf.
Source§

fn leaf_array<T: Element>(l: HostArray) -> NativeArray<T>

A pytree leaf as an array.
Source§

fn leaf_aval(l: &HostArray) -> AVal

The abstract value of a leaf.
Source§

fn host_callback( callback: &HostCallback, args: &[HostArray], outputs: &[AVal], ) -> Vec<HostArray>

host_callback: callback on the leaves args, whose results have the types outputs.
Source§

fn custom_jvp<I: Tree<Self>, O: Tree<Self>>( f: &dyn Fn(I) -> O, jvp: &dyn Fn(I, I) -> (O, O), primals: I, ) -> O

f(primals), differentiated with the rule jvp (see lax::custom_jvp).
Source§

fn custom_vjp<I: Tree<Self>, O: Tree<Self>, R: Tree<Self>>( f: &dyn Fn(I) -> O, fwd: &dyn Fn(I) -> (O, R), bwd: &dyn Fn(R, O) -> I, primals: I, ) -> O

f(primals), differentiated in reverse mode with the rules fwd and bwd (see lax::custom_vjp).
Source§

fn checkpoint<I: Tree<Self>, O: Tree<Self>>(f: &dyn Fn(I) -> O, input: I) -> O

f(input), whose intermediate values reverse mode recomputes (see lax::checkpoint).
Source§

impl Clone for Native

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Native

Source§

impl Debug for Native

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Native

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Native

Source§

impl Hash for Native

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Native

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Native

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.