Tannic
A C++ Tensor Library
Loading...
Searching...
No Matches
tannic::transformation::Composition Struct Reference

Transformation composition (Known as Matrix Multiplication) operation. More...

#include <transformations.hpp>

Public Member Functions

void forward (Tensor const &outer, Tensor const &inner, Tensor &result) const
 

Static Public Member Functions

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.
 

Public Attributes

double scale = 1.0
 

Static Public Attributes

static constexpr auto promotions
 Type promotion rules table.
 

Detailed Description

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

Member Function Documentation

◆ 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
innerType of the inner (right) operand
outerType of the outer (left) operand
Returns
Promoted type according to the composition rules
Exceptions
assertionerror if the type combination is unsupported

This promotion system:

  1. Uses a precomputed promotion table for all valid type combinations
  2. 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
  3. Explicitly rejects invalid combinations via assertion

Example promotions:

promote(int8, int32) → int32 // Integer widening
promote(int32, float32) → float32 // Mixed to float
promote(float32, float64) → float64 // Precision preservation
static constexpr type promote(type inner, type outer)
Promotes two operand types to a common type for composition operations.
Definition: transformations.hpp:216

◆ transform()

static constexpr Shape tannic::transformation::Composition::transform ( Shape const &  first,
Shape const &  second 
)
inlinestaticconstexpr

Computes transformed output shape for composition.

Parameters
firstFirst operand shape
secondSecond operand shape
Returns
Broadcasted output shape
Exceptions
assertionerror if shapes are incompatible

Handles multiple cases:

  1. Vector-vector: (n) × (n) → scalar (empty shape)
  2. Matrix-vector: (m,n) × (n) → (m)
  3. Vector-matrix: (n) × (n,k) → (k)
  4. Matrix-matrix: (m,n) × (n,k) → (m,k)
  5. Batched operations: (...,m,n) × (...,n,k) → (...,m,k)

Member Data Documentation

◆ 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: