numerics
Loading...
Searching...
No Matches
small_matrix.hpp File Reference

Constexpr fixed-size stack-allocated matrix and Givens rotation. More...

#include "core/types.hpp"
#include <array>
#include <cmath>
#include <algorithm>

Go to the source code of this file.

Classes

struct  num::SmallVec< N >
 Constexpr fixed-size dense vector (stack-allocated). More...
 
struct  num::SmallMatrix< M, N >
 Constexpr fixed-size row-major matrix (stack-allocated). More...
 
struct  num::GivensRotation
 Givens plane rotation: G = [c, s; -s, c]. More...
 

Namespaces

namespace  num
 

Functions

template<idx N>
constexpr SmallVec< N > num::operator+ (SmallVec< N > a, const SmallVec< N > &b) noexcept
 
template<idx N>
constexpr SmallVec< N > num::operator* (real s, SmallVec< N > v) noexcept
 

Detailed Description

Constexpr fixed-size stack-allocated matrix and Givens rotation.

These types complement the heap-allocated Matrix / Vector for small inner kernels where heap traffic is undesirable:

SmallVec<N> – constexpr dense vector backed by std::array<real,N> SmallMatrix<M,N> – constexpr row-major matrix backed by std::array<real,M*N> GivensRotation – constexpr (c,s) pair; apply() / apply_t() are branchless

Because these are literal types every operation can be evaluated at compile time (C++17: arithmetic only; C++20+: also sqrt/hypot via constexpr <cmath>). At runtime the compiler places them entirely in registers for small M, N.

Typical uses:

  • GMRES: Hessenberg column updates via GivensRotation::from + apply
  • Jacobi SVD / eig: 2x2 eigensystem kernel as SmallMatrix<2,2>
  • Register-tile accumulation: SmallMatrix<4,4> replaces 16 named doubles
  • Unit tests: known-answer matmuls computed at compile time

Definition in file small_matrix.hpp.