35 std::array<real, N>
data{};
39 static constexpr idx size() noexcept {
return N; }
42 for (
idx i = 0; i < N; ++i)
47 for (
idx i = 0; i < N; ++i)
52 for (
idx i = 0; i < N; ++i)
59 for (
idx i = 0; i < N; ++i)
60 s +=
data[i] * o.data[i];
80 std::array<real, M * N>
data{};
84 return data[i * N + j];
87 static constexpr idx rows() noexcept {
return M; }
88 static constexpr idx cols() noexcept {
return N; }
95 static_assert(M == N,
"identity() requires a square matrix");
97 for (
idx i = 0; i < M; ++i)
104 for (
idx i = 0; i < M; ++i)
105 for (
idx j = 0; j < N; ++j)
106 t(j, i) = (*this)(i, j);
115 for (
idx i = 0; i < M; ++i)
116 for (
idx k = 0; k < N; ++k)
117 for (
idx j = 0; j < K; ++j)
118 C(i, j) += (*this)(i, k) * B(k, j);
125 for (
idx i = 0; i < M; ++i)
126 for (
idx j = 0; j < N; ++j)
127 y[i] += (*
this)(i, j) * x[j];
132 for (
idx k = 0; k < M * N; ++k)
137 for (
idx k = 0; k < M * N; ++k)
163 real r = std::sqrt(a * a + b * b);
164 return {a / r, b / r};
constexpr SmallVec< N > operator*(real s, SmallVec< N > v) noexcept
constexpr SmallVec< N > operator+(SmallVec< N > a, const SmallVec< N > &b) noexcept
Givens plane rotation: G = [c, s; -s, c].
constexpr void apply(real &x, real &y) const noexcept
Apply G from the left: [x; y] <- G * [x; y].
constexpr void apply_t(real &x, real &y) const noexcept
Apply G^T (inverse rotation): [x; y] <- G^T * [x; y].
constexpr SmallMatrix< 2, 2 > as_matrix() const noexcept
Return the 2x2 rotation matrix.
static constexpr GivensRotation from(real a, real b) noexcept
Constexpr fixed-size row-major matrix (stack-allocated).
static constexpr SmallMatrix identity() noexcept
static constexpr idx cols() noexcept
constexpr SmallMatrix & operator+=(const SmallMatrix &o) noexcept
constexpr SmallMatrix< N, M > transposed() const noexcept
static constexpr SmallMatrix zeros() noexcept
constexpr real & operator()(idx i, idx j) noexcept
constexpr SmallVec< M > operator*(const SmallVec< N > &x) const noexcept
Matrix-vector product: (MxN) * (N) -> (M).
constexpr void fill(real v) noexcept
static constexpr idx rows() noexcept
constexpr SmallMatrix & operator*=(real s) noexcept
std::array< real, M *N > data
constexpr const real & operator()(idx i, idx j) const noexcept
constexpr SmallMatrix< M, K > operator*(const SmallMatrix< N, K > &B) const noexcept
Matrix multiplication: (M x N) * (N x K) -> (M x K).
Constexpr fixed-size dense vector (stack-allocated).
static constexpr idx size() noexcept
constexpr real norm_sq() const noexcept
Sum of squares (avoid sqrt to stay constexpr in C++17).
constexpr SmallVec & operator+=(const SmallVec &o) noexcept
constexpr real dot(const SmallVec &o) const noexcept
constexpr SmallVec & operator-=(const SmallVec &o) noexcept
constexpr const real & operator[](idx i) const noexcept
constexpr real & operator[](idx i) noexcept
std::array< real, N > data
constexpr SmallVec & operator*=(real s) noexcept