Expand description
The primitives of ruxla: shape inference, evaluation (with
ruxla-kernels), lowering to StableHLO, batching rules (vmap, following
JAX’s rules; see batching), and differentiation rules (jvp and
transpose, ported from JAX’s).
The set follows jax.lax. Elementwise primitives are entries of tables
keyed by the operations of ruxla-kernels (unary_prim,
binary_prim, compare_prim).
Re-exports§
pub use random::THREEFRY2X32;
Modules§
- ad
- Helpers for differentiation rules, shared by the primitives and the
drivers in
ruxla-transforms. - batching
- Helpers for batching rules (
vmap), shared by the primitives and thevmapdriver inruxla-transforms.
Statics§
- ABS
|x|.- ADD
x + y.- AND
- Logical or bitwise and.
- ARGMAX
- The index of the largest element along an axis (
Params::ArgMinMax). - ARGMIN
- The index of the smallest element along an axis.
- ATAN2
atan2(x, y).- BESSEL_
I0E exp(-|x|) I0(x).- BESSEL_
I1E exp(-|x|) I1(x).- BITCAST_
CONVERT_ TYPE - Reinterpret the bits as another type of the same size.
- BROADCAST_
IN_ DIM - Broadcasts to a larger shape (
Params::BroadcastInDim). - CBRT
- Cube root.
- CEIL
- Round up.
- CHECKPOINT
- Calls a function whose intermediate values reverse mode recomputes
instead of storing (
Params::Checkpoint,jax.checkpoint). - CHOLESKY
- The Cholesky factor
L(A = L L^T) of each symmetric positive definite matrix, read from its lower triangle; the strictly upper triangle of the result is that of the input, and matrices that are not positive definite give NaNs (as JAX’scholesky_pon CPU and GPU). - CHOLESKY_
UPDATE - The rank-1 update of each upper triangular Cholesky factor
r(a = r^T r) by the vectorw: the factor ofa + w w^T, as JAX’scholesky_update_p(real matrices; Givens rotations, as JAX computes it on CPU). Not differentiable, as in JAX. - CLAMP
- Clamp to bounds.
- COMPLEX
- Complex numbers from their real and imaginary parts.
- CONCATENATE
- Joins arrays along a dimension.
- COND
- Calls the branch chosen by an
i32index, passing the other operands (Params::Cond). An index out of range calls the last branch, asstablehlo.casedoes. - CONJ
- The complex conjugate.
- CONVERT_
ELEMENT_ TYPE - Convert to another element type (
Params::Convert). - CONV_
GENERAL_ DILATED - A convolution with strides, padding, input and kernel dilation, and
feature and batch groups (
Params::ConvGeneralDilated), as XLA’sConv. - COS
- Cosine.
- CUMLOGSUMEXP
- The cumulative
logsumexpalong an axis (floats only). - CUMMAX
- The cumulative maximum along an axis, propagating NaN.
- CUMMIN
- The cumulative minimum along an axis, propagating NaN.
- CUMPROD
- The cumulative product along an axis.
- CUMSUM
- The cumulative sum along an axis (
Params::Cumulative). - CUSTOM_
JVP_ CALL - Calls a function with a JVP rule written by the user
(
Params::CustomJvp). - CUSTOM_
LIN - The tangents of the outputs of a
custom_vjp_call(Params::CustomLin): linear in the tangents of the arguments, and defined only by its transpose, the backward function. It cannot be evaluated: forward-mode differentiation of acustom_vjpfunction is not supported, as in JAX. - CUSTOM_
VJP_ CALL - Calls a function with a VJP rule written by the user
(
Params::CustomVjp). - DIGAMMA
- The digamma function.
- DIV
x / y.- DOT_
GENERAL - Sums of products over contracting dimensions (
Params::DotGeneral). - DYNAMIC_
SLICE - A slice at run-time start indices (one integer scalar per dimension), clamped to stay in bounds.
- DYNAMIC_
UPDATE_ SLICE - Writes an update at run-time start indices, clamped to stay in bounds.
- EIG
- The eigendecomposition of each general matrix (
Params::Eig): the complex eigenvalues ([..., n]), and the left and right eigenvectors ([..., n, n], one per column) that are requested, of the complex type of the input, as JAX’seig_p, which it computes with LAPACK’sgeev(seeruxla_kernels::linalg::eigfor the conventions). - EIGH
- The eigendecomposition of each symmetric matrix, read from the triangle
given by
lower(Params::Eigh): the eigenvectorsv(columns) and the eigenvalueswin ascending order, as JAX’seigh_p(which returnsvfirst). Withsubset_by_index, the eigenvalues of that range of indices and their eigenvectors (computed from the whole decomposition; JAX supports it on TPU only). - EQ
x == y.- ERF
- The error function.
- ERFC
- The complementary error function.
- ERF_INV
- The inverse error function.
- EXP
e^x.- EXPM1
e^x - 1.- EXTERN_
CALL - Calls the public
mainof a StableHLO module written by another program, such as a JAX model exported withjax.export(Params::Extern). XLA links the module with the caller and compiles them together; the interpreter and the native backend cannot run it. - FFT
- Fourier transforms of the trailing axes (
Params::Fft). - FLOOR
- Round down.
- GATHER
- Slices at run-time start indices (
Params::Gather). - GE
x >= y.- GT
x > y.- HESSENBERG
- The reduction of each square matrix to upper Hessenberg form, as JAX’s
hessenberg_p(LAPACK’sgehrd): the matrix withhon and above the subdiagonal and the Householder reflectors below it, and then - 1factorstau. Not differentiable, as in JAX. - HOST_
CALLBACK - Calls a Rust function on host arrays (
Params::HostCallback): the interpreter calls it directly, XLA through the FFI handlerruxla_host_callbackofruxla-pjrt(on CUDA, around copies to the host), which finds it by its id. The function must be pure (it may run any number of times). Not differentiable; batched by a loop over the examples (scan, aspure_callbackwithvmap_method="sequential"). Programs with host callbacks cannot be serialized, embedded in JAX, or compiled to Rust. - HOUSEHOLDER_
PRODUCT - The first
ncolumns of the product of the Householder reflectors below the diagonal ofa([..., m, n],m >= n) with the factorstaus([..., k],k <= n), as JAX’shouseholder_product_p(LAPACK’sorgqr). Not differentiable, as in JAX. - IGAMMA
- The regularized lower incomplete gamma function.
- IGAMMAC
- The regularized upper incomplete gamma function.
- IGAMMA_
GRAD_ A - The derivative of
igammawith respect to its first operand. - IMAG
- The imaginary part of complex numbers.
- INTEGER_
POW x^yfor a static integery(Params::IntegerPow).- IOTA
- The indices along a dimension.
- IS_
FINITE - Whether each element is finite.
- JIT
- Calls a function compiled as a unit (
Params::Jit). - LE
x <= y.- LGAMMA
- The logarithm of the absolute value of the gamma function.
- LOG
- Natural logarithm.
- LOG1P
log(1 + x).- LOGISTIC
- The logistic sigmoid.
- LT
x < y.- LU
- The LU factorization with partial pivoting of each matrix: the factors
(
Lbelow the diagonal with an implicit unit diagonal,Uon and above it), the pivots (i32[..., min(m, n)], 0-based row swaps), and the permutation (i32[..., m]), as JAX’slu_p. - LU_
PIVOTS_ TO_ PERMUTATION - Converts the pivots of
lu(i32[..., k]) to permutations (i32[..., permutation_size]): starting from the identity, swaps elementiwith elementpivots[i]for eachiin order (Params::LuPivotsToPermutation). - MAX
- Maximum.
- MIN
- Minimum.
- MUL
x * y.- NE
x != y.- NEG
-x.- NOT
- Logical or bitwise not.
- OR
- Logical or bitwise or.
- ORMQR
- The product of
cwithQ(orQ^H) of the Householder reflectors ofaand the factorstaus, from the left or the right (Params::Ormqr), without formingQ, as JAX’sormqr_p(LAPACK’sormqr). Not differentiable, as in JAX. - PAD
- Pads with a scalar value; negative padding removes elements.
- POLYGAMMA
- The polygamma function.
- POW
x^y.- QR
- The QR decomposition of each matrix (
Params::Qr):qwith orthonormal columns and an upper triangularr, with the signs of LAPACK’s Householder reflectors (as JAX’sqr_p, which it computes withgeqrfandorgqr). Withpivoting, the decomposition of the columns permuted by LAPACK’sgeqp3(x[..., p] = q r) and the permutationp(i32[..., n]) as a third output. - RANDOM_
GAMMA_ GRAD - The derivative of a sample of
Gamma(a, 1)with respect toa. - REAL
- The real part of complex numbers.
- REDUCE_
MAX - The maximum over axes, propagating NaN (logical or for booleans).
- REDUCE_
MIN - The minimum over axes, propagating NaN (logical and for booleans).
- REDUCE_
SUM - Sums over axes (
Params::Reduce). - REDUCE_
WINDOW_ MAX - The maximum over windows, propagating NaN.
- REDUCE_
WINDOW_ MIN - The minimum over windows, propagating NaN.
- REDUCE_
WINDOW_ SUM - Sums over windows (
Params::ReduceWindow). - REGULARIZED_
INCOMPLETE_ BETA - The regularized incomplete beta function
I_x(a, b)of(a, b, x). - REM
- Remainder.
- RESHAPE
- Changes the shape, keeping the elements in row-major order.
- REV
- Reverses dimensions.
- ROUND
- Round to an integer (
Params::Round). - RSQRT
1 / sqrt(x).- SCAN
- A loop over the leading dimension of the scanned inputs (
Params::Scan). - SCATTER
- Writes updates at run-time start indices (
Params::Scatter). With repeated indices, which update wins is unspecified. - SCATTER_
ADD - Adds updates at run-time start indices.
- SCATTER_
MAX - Takes the maximum with updates at run-time start indices.
- SCATTER_
MIN - Takes the minimum with updates at run-time start indices.
- SCATTER_
MUL - Multiplies by updates at run-time start indices.
- SCHUR
- The Schur decomposition
x = z t z^Hof each square matrix (Params::Schur):t(quasi-triangular with standardized 2 x 2 blocks for real matrices, triangular for complex ones) and, if requested, the Schur vectorsz, as JAX’sschur_p(LAPACK’sgees, without sorting). Not differentiable, as in JAX. - SELECT_
AND_ GATHER_ ADD - For each window of the operand (the second input), the element of the
tangents (the first input) at the selected element: the JVP of max
(
ge) or min (le) pooling (Params::SelectAndGatherAdd). - SELECT_
AND_ SCATTER_ ADD - For each window of the operand (the second input), adds the source
element (the first input) at the selected element: the gradient of
max (
ge) or min (le) pooling (Params::SelectAndScatterAdd). - SELECT_
N - Select elements from cases.
- SHIFT_
LEFT x << y.- SHIFT_
RIGHT_ ARITHMETIC x >> y, filling with the sign bit.- SHIFT_
RIGHT_ LOGICAL x >> y, filling with zeros.- SIGN
- The sign.
- SIN
- Sine.
- SLICE
- A static slice, with strides.
- SORT
- Sorts operands of the same shape along a dimension, lexicographically by
the first
num_keysof them (Params::Sort). Floats are ordered as-inf < ... < 0 < ... < inf < NaN, with-0.0equal to0.0and all NaNs equal, as in JAX. - SQRT
- Square root.
- SQUARE
x * x.- SUB
x - y.- SVD
- The singular value decomposition of each matrix (
Params::Svd): the singular valuessin descending order, and withcompute_uv,uandvt(a = u diag(s) vt), as JAX’ssvd_p. Withsubset_by_index(not withfull_matrices), the singular values of that range of indices and their vectors (computed from the whole decomposition; JAX supports it on TPU only). - SYMMETRIC_
PRODUCT alpha a a^T + beta cfor each reala([..., m, n]) andc([..., m, m]) (Params::SymmetricProduct), as JAX’ssymmetric_product_p: the whole matrix, as JAX computes it on CPU (on GPU, where JAX calls cuBLAS’ssyrk, only the lower triangle is guaranteed, as in JAX). Not differentiable, as in JAX.- TAN
- Tangent.
- TANH
- Hyperbolic tangent.
- THREEFR
Y2X32 - The threefry2x32 hash of the counters
(x1, x2)with the key(k1, k2), elementwise; operands of rank 0 are broadcast to the shape of the others, as in JAX. - TOP_K
- The
klargest elements along an axis in descending order, and their indices asi32(Params::TopK). Floats are ordered by XLA’s total order-NaN < -inf < ... < -0.0 < 0.0 < ... < inf < NaN; equal elements keep their order. - TRANSPOSE
- Permutes the dimensions.
- TRIANGULAR_
SOLVE - Solves
op(a) x = borx op(a) = bfor a triangulara(Params::TriangularSolve); only the triangle ofagiven byloweris read (without the diagonal forunit_diagonal). - TRIDIAGONAL
- The reduction of each Hermitian (symmetric) matrix, read from its lower
(or upper) triangle (
Params::Tridiagonal), to real tridiagonal form by a unitary similarity, as JAX’stridiagonal_p(LAPACK’ssytrdandhetrd): the matrix with the tridiagonal form and the Householder reflectors in that triangle (the other one untouched), the real diagonald, the real off-diagonale, and then - 1factorstaus. Not differentiable, as in JAX. - TRIDIAGONAL_
SOLVE - The solution
xofA x = bfor each tridiagonal matrixA, given by its diagonalsdl(dl[..., i] = A[i, i - 1],dl[..., 0]ignored),d, anddu(du[..., i] = A[i, i + 1], the last one ignored), each[..., m], andb([..., m, n]), as JAX’stridiagonal_solve_p(Params::TridiagonalSolve): Gaussian elimination with partial pivoting, where singular systems give NaNs, or withperturb_singular, tiny pivots perturbed so that numerically singular systems give finite solutions. Differentiable in all inputs, linear inb. - WHILE
- Repeats the body while the predicate holds (
Params::While). - XOR
- Logical or bitwise exclusive or.
- ZETA
- The Hurwitz zeta function.
Functions§
- all
- Returns every primitive.
- binary_
prim - Returns the primitive of a
BinaryOp. - by_name
- Returns the primitive with the given name.
- compare_
prim - Returns the primitive of a
CompareOp. - ternary_
prim - Returns the primitive of a
TernaryOp. - unary_
prim - Returns the primitive of a
UnaryOp(roundandround_evenmap to theroundprimitive with a method).