Expand description
Algebra traits for the tenferro workspace.
This crate provides the minimal algebra foundation:
Scalar: Minimum requirements for tensor element types (equivalent toScalarBasefrom strided-traits).Conjugate: Complex conjugation (identity for real types).HasAlgebra: Maps a scalar typeTto its default algebraAlg. Enables automatic inference:Tensor<f64>→Standard<f64>,Tensor<MaxPlus<f64>>→MaxPlusAlgebra<f64>(in external crate). This is UX sugar — the core model isAlg::Scalar-centric.Algebra: Associates an algebra marker with its scalar type (Alg::Scalar).Semiring: ExtendsAlgebrawith zero, one, add, mul for algebra-generic operations.Standard<T>: Typed standard arithmetic algebra (add =+, mul =*).
§Extensibility
External crates define new algebras by implementing HasAlgebra for their
scalar types and then implementing the primitive family traits they need
(for example TensorSemiringCore<MyAlgebra> for CpuBackend) under the
orphan rule. For example, tenferro-ext-tropical defines MaxPlus<T>.
§Examples
use tenferro_algebra::{HasAlgebra, Scalar, Standard};
// f64 maps to Standard<f64> algebra automatically
fn check_algebra<T: HasAlgebra<Algebra = Standard<T>>>() {}
check_algebra::<f64>();
check_algebra::<f32>();
// Scalar is automatically implemented for numeric types
fn needs_scalar<T: Scalar>() {}
needs_scalar::<f64>();
needs_scalar::<f32>();Structs§
- Standard
- Typed standard arithmetic algebra (add =
+, mul =*).
Traits§
- Algebra
- Associates an algebra marker with its scalar type.
- Conjugate
- Complex conjugation for tensor element types.
- HasAlgebra
- Maps a scalar type
Tto its default algebraAlg. - Scalar
- Scalar element type for tensors.
- Semiring
- Semiring trait for algebra-generic operations.