omeinsum/algebra/
mod.rs

1//! Algebraic structures for tensor operations.
2//!
3//! This module defines the [`Semiring`] trait and implementations for:
4//! - [`Standard<T>`]: Standard arithmetic `(+, ×)` (always available)
5//! - `MaxPlus<T>`: Tropical max-plus `(max, +)` (requires `tropical` feature)
6//! - `MinPlus<T>`: Tropical min-plus `(min, +)` (requires `tropical` feature)
7//! - `MaxMul<T>`: Tropical max-mul `(max, ×)` (requires `tropical` feature)
8
9mod semiring;
10mod standard;
11
12#[cfg(feature = "tropical")]
13mod tropical;
14
15pub use semiring::{Algebra, Semiring};
16pub use standard::Standard;
17
18#[cfg(feature = "tropical")]
19pub use tropical::{MaxMul, MaxPlus, MinPlus};
20
21// Re-export complex types for convenience
22pub use num_complex::{Complex32, Complex64};
23
24/// Marker trait for scalar types that can be used in tensors.
25pub trait Scalar:
26    Copy
27    + Clone
28    + Send
29    + Sync
30    + Default
31    + std::fmt::Debug
32    + 'static
33    + bytemuck::Pod
34    + std::ops::AddAssign
35{
36}
37
38impl Scalar for f32 {}
39impl Scalar for f64 {}
40impl Scalar for i32 {}
41impl Scalar for i64 {}
42impl Scalar for u32 {}
43impl Scalar for u64 {}
44impl Scalar for Complex32 {}
45impl Scalar for Complex64 {}