Linalg Prims
This file keeps the historical linalg-prims.md name, but the current workspace no longer has a separate tenferro-linalg-prims crate. The backend-facing tensor linalg contracts are owned by tenferro-linalg::backend::LinalgBackend and implemented by backend crates such as tenferro-cpu and tenferro-gpu.
Why This Crate Exists
The redesign separates two concerns that were previously coupled:
- public/composite tensor linalg APIs
- backend-facing structured kernel contracts
tenferro-linalg owns both the public linalg API and the linalg extension runtime, while LinalgBackend defines the narrower backend kernel surface. Core scalar, analytic, structural, and contraction vocabulary lives in tenferro-internal-ops::StdTensorOp, with primitive metadata supplied by tenferro-core-ops, and is executed through tenferro-runtime::ExecOp and tenferro-tensor::TensorBackend. This prevents generic tensor backends and operation-family crates from inheriting linalg-specific requirements.
What Belongs Here
Only operations that naturally map to structured backend kernels belong in the LinalgBackend contract.
Current kernel basis:
solvesolve_triangularqrthin_svdlu_factorcholeskyeigen_symeig
Associated structured result types also live here:
QrTensorResultSvdTensorResultLuTensorResultEigenTensorResultEigTensorResult
What Does Not Belong Here
Composite public APIs stay in tenferro-linalg.
Examples:
matrix_powercondtensorinvtensorsolvemulti_dotvecdotvander
These are public linalg operations, but they are not backend kernel contracts. They should lower through tensor structural ops, core StdTensorOp families, operation-family runtimes, and the smaller kernel basis above.
Relation to tenferro-linalg
tenferro-linalg is expected to:
- validate public API contracts
- normalize shape/axis options
- lower composites to core tensor ops or
LinalgBackendkernels - expose structured public results
tenferro-linalg should not directly branch on backend types or contain backend-specific execution kernels.
Relation to Core Tensor Ops
The linalg backend contract is peer to the core tensor backend contract, not a parent/child abstraction.
StdTensorOp/ExecOpcover scalar, analytic, structural, reduction, and contraction execution vocabularyLinalgBackendcovers structured factorization and solve kernels
High-level linalg code may depend on both families:
- core tensor ops for composites
LinalgBackendfor factorization kernels
Current Status
LinalgBackend exists and is wired into backend implementations as the canonical backend-facing linalg contract. Some concrete backends still use local helper modules internally, but those helpers sit behind LinalgBackend instead of acting as competing public abstractions.
The scalar side is intentionally split:
LinalgScalardescribes the general scalar behavior shared by linalg codeKernelLinalgScalarmarks the dtypes that backend kernel contracts currently supportLapackEigScalarisolates the narrower CPU eig buffer conversion helpers
That separation keeps public/high-level linalg APIs backend-generic without leaking CPU-specific scalar trait names.