Transformation composition (Known as Matrix Multiplication) operation.
More...
#include <transformations.hpp>
|
static constexpr type | promote (type inner, type outer) |
| Promotes two operand types to a common type for composition operations.
|
|
static constexpr Shape | transform (Shape const &first, Shape const &second) |
| Computes transformed output shape for composition.
|
|
|
static constexpr auto | promotions |
| Type promotion rules table.
|
|
Transformation composition (Known as Matrix Multiplication) operation.
Implements tensor composition with:
- Automatic type promotion
- Shape broadcasting for batch dimensions
- Support for vectors, matrices, and higher-rank tensors
◆ forward()
void tannic::transformation::Composition::forward |
( |
Tensor const & |
outer, |
|
|
Tensor const & |
inner, |
|
|
Tensor & |
result |
|
) |
| const |
◆ promote()
static constexpr type tannic::transformation::Composition::promote |
( |
type |
inner, |
|
|
type |
outer |
|
) |
| |
|
inlinestaticconstexpr |
Promotes two operand types to a common type for composition operations.
- Parameters
-
inner | Type of the inner (right) operand |
outer | Type of the outer (left) operand |
- Returns
- Promoted type according to the composition rules
- Exceptions
-
assertion | error if the type combination is unsupported |
This promotion system:
- Uses a precomputed promotion table for all valid type combinations
- Ensures safe arithmetic by:
- Promoting integers to avoid overflow (e.g., int8 → int32)
- Promoting mixed integer/float to float
- Preserving higher precision when types differ
- Explicitly rejects invalid combinations via assertion
Example promotions:
promote(float32, float64) → float64
◆ transform()
static constexpr Shape tannic::transformation::Composition::transform |
( |
Shape const & |
first, |
|
|
Shape const & |
second |
|
) |
| |
|
inlinestaticconstexpr |
Computes transformed output shape for composition.
- Parameters
-
first | First operand shape |
second | Second operand shape |
- Returns
- Broadcasted output shape
- Exceptions
-
assertion | error if shapes are incompatible |
Handles multiple cases:
- Vector-vector: (n) × (n) → scalar (empty shape)
- Matrix-vector: (m,n) × (n) → (m)
- Vector-matrix: (n) × (n,k) → (k)
- Matrix-matrix: (m,n) × (n,k) → (m,k)
- Batched operations: (...,m,n) × (...,n,k) → (...,m,k)
◆ promotions
constexpr auto tannic::transformation::Composition::promotions |
|
staticconstexpr |
Type promotion rules table.
Defines promotion rules for all type combinations:
- Integer operations promote to avoid overflow
- Mixed integer/float promotes to float
- Operations preserve highest precision
◆ scale
double tannic::transformation::Composition::scale = 1.0 |
The documentation for this struct was generated from the following file: