Tutorials

These tutorials are ordered by user workflow. Standard scientific computing comes first; extension authoring and execution-model internals are advanced paths. The repository is extensible internally, but ordinary use stays conventional: construct a value, enter a session, call an operation, and keep the result.

Start here

Tutorial Use it when
Ordinary CPU scientific computing You want matmul, solve, and singular values in one bounded backend session.
TypedTensor for numeric computation without autodiff You know the scalar type in Rust and want ndarray-like CPU tensor computation without AD.
CUDA and explicit device movement You want to upload inputs, run supported operations on CUDA, and download values explicitly. Hardware-executed CUDA tutorial validation lives in the GPU CI lane; CPU CI only compile-checks that artifact.
Using tenferro with ndarray/faer data Your application already owns arrays and needs an explicit borrowed-view round trip.
Calling faer or BLAS/LAPACK directly One specialized routine is outside the standard operation families; borrow compact host storage, call the external library, and continue with tenferro.
Eager autodiff, PyTorch style You want immediate execution, scalar losses, backward(), accumulated gradients, or the functional eager AD entry point.
Traced autodiff, JAX style You want to build a graph, compile/run it, and use grad or jvp on the traced graph.

Advanced topics

Tutorial Use it when
Einsum: subscripts to gradients You contract more than two tensors and want planned contraction order plus AD.
XLA backend: einsum to StableHLO You want to lower a fixed-shape N-ary einsum path through the experimental XLA executor.
Dynamic shapes: truncated SVD Output ranks depend on runtime values such as singular-value thresholds.
Tropical extension You want a complete extension crate for non-standard arithmetic, runtime registration, and AD rules.
Sparse tensor extension You want a fixed-pattern sparse COO extension with sparse-sparse contraction and value AD.
KdV PINN sample You want a full traced-graph PINN training loop with PDE residuals and scalar loss gradients.

The custom operations guide explains the extension architecture only when you need to add a new operation family.

Running the tutorial code

From the repository root:

cargo test -p tenferro-tutorial-code --release

The CI workflow runs this package through the existing workspace test workflow. The CPU tutorial binaries remain hardware-independent. The CUDA tutorial is compiled and archived on the non-GPU CUDA lane and executed with deterministic value assertions on the trusted GPU lane; see Devices and GPU for the exact transfer contract.

The tropical and sparse extension tutorials are tested as standalone crates:

cargo test --manifest-path ext/tropical/Cargo.toml --release --features autodiff
cargo test --manifest-path ext/sparse/Cargo.toml --release --features autodiff
cargo test --manifest-path ext/tenferro-cpu-tblis/Cargo.toml --release

The KdV PINN sample is compile-checked separately:

cargo check --manifest-path samples/kdv-pinn/Cargo.toml --release --all-targets