Skip to content

File syn_matrix.h

FileList > src > syntropic > util > syn_matrix.h

Go to the source code of this file

Fixed-point Q16.16 matrix operations — zero heap allocation. More...

  • #include "../common/syn_defs.h"
  • #include "syn_qmath.h"
  • #include <stdbool.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_Matrix
Fixed-point matrix descriptor (non-owning view).

Public Functions

Type Name
void syn_matrix_add (const SYN_Matrix * a, const SYN_Matrix * b, SYN_Matrix * out)
Element-wise addition: out = A + B.
void syn_matrix_copy (SYN_Matrix * dst, const SYN_Matrix * src)
Copy matrix contents.
q16_t syn_matrix_det (const SYN_Matrix * m)
Determinant of a square matrix.
SYN_Status syn_matrix_eigen_sym2 (const SYN_Matrix * A, q16_t evals, SYN_Matrix * E)
Compute eigenvalues and eigenvectors of a symmetric 2×2 matrix A.
SYN_Status syn_matrix_eigen_sym3 (const SYN_Matrix * A, q16_t evals, SYN_Matrix * E)
Compute eigenvalues and eigenvectors of a symmetric 3×3 matrix A via Jacobi rotations.
SYN_Status syn_matrix_get_block (const SYN_Matrix * src, uint8_t r0, uint8_t c0, SYN_Matrix * dst)
Extract a submatrix block from src into dst.
void syn_matrix_identity (SYN_Matrix * m)
Set matrix to identity.
SYN_Status syn_matrix_inv (const SYN_Matrix * m, SYN_Matrix * out)
Matrix inverse: out = M⁻¹.
SYN_Status syn_matrix_inv_3x3 (const SYN_Matrix * src, SYN_Matrix * dst)
Invert a 3×3 matrix in-place or out-of-place via Cramer's rule.
SYN_Status syn_matrix_inv_lu (const SYN_Matrix * src, SYN_Matrix * dst)
Invert an arbitrary N×N matrix via LU decomposition (convenience wrapper).
SYN_Status syn_matrix_inv_lu_work (const SYN_Matrix * src, SYN_Matrix * dst, q16_t * lu_work, uint8_t * p_work, q16_t * col_work)
Invert an arbitrary N×N matrix via LU decomposition using caller-supplied workspace.
SYN_Status syn_matrix_least_squares (const SYN_Matrix * A, const SYN_Matrix * b, SYN_Matrix * x)
Solve overdetermined system A · x ≈ b via Normal Equations (Least Squares).
SYN_Status syn_matrix_least_squares_work (const SYN_Matrix * A, const SYN_Matrix * b, SYN_Matrix * x, q16_t * ata_work, q16_t * atb_work, q16_t * at_work, q16_t * solver_lu, q16_t * solver_y)
Solve overdetermined system A · x ≈ b via Least Squares using caller-supplied workspace.
void syn_matrix_mul (const SYN_Matrix * a, const SYN_Matrix * b, SYN_Matrix * out)
Matrix multiply: out = A × B.
void syn_matrix_mul_vec (const SYN_Matrix * m, const q16_t * v_in, q16_t * v_out, uint8_t n_in)
Matrix–vector multiply: out = M × v.
SYN_Status syn_matrix_outer_product (const q16_t * u, uint8_t rows, const q16_t * v, uint8_t cols, SYN_Matrix * out)
Vector outer product: out = u · vᵀ (rows(u) × cols(v)).
SYN_Status syn_matrix_qr (const SYN_Matrix * A, SYN_Matrix * Q, SYN_Matrix * R)
QR Decomposition: A = Q · R via Modified Gram-Schmidt process.
void syn_matrix_rotate_2d (SYN_Matrix * out, q16_t angle)
Set 3×3 matrix to a 2D rotation.
void syn_matrix_rotate_x (SYN_Matrix * out, q16_t angle)
Set 4×4 matrix to a rotation around the X axis.
void syn_matrix_rotate_y (SYN_Matrix * out, q16_t angle)
Set 4×4 matrix to a rotation around the Y axis.
void syn_matrix_rotate_z (SYN_Matrix * out, q16_t angle)
Set 4×4 matrix to a rotation around the Z axis.
void syn_matrix_scale (const SYN_Matrix * a, q16_t scalar, SYN_Matrix * out)
Scalar multiply: out = A × scalar.
void syn_matrix_scale_2d (SYN_Matrix * out, q16_t sx, q16_t sy)
Set 3×3 matrix to a 2D scale.
SYN_Status syn_matrix_set_block (SYN_Matrix * dst, uint8_t r0, uint8_t c0, const SYN_Matrix * src)
Embed a submatrix block src into dst at position (r0, c0).
SYN_Status syn_matrix_solve_cholesky (const SYN_Matrix * A, const SYN_Matrix * b, SYN_Matrix * x)
Solve symmetric positive-definite system A · x = b via Cholesky (convenience wrapper).
SYN_Status syn_matrix_solve_cholesky_work (const SYN_Matrix * A, const SYN_Matrix * b, SYN_Matrix * x, q16_t * L_work, q16_t * y_work)
Solve system A · x = b via Cholesky decomposition using caller-supplied workspace buffer.
SYN_Status syn_matrix_solve_lu (const SYN_Matrix * A, const SYN_Matrix * b, SYN_Matrix * x)
Solve system A · x = b via LU decomposition (convenience wrapper).
SYN_Status syn_matrix_solve_lu_work (const SYN_Matrix * A, const SYN_Matrix * b, SYN_Matrix * x, q16_t * lu_work, uint8_t * p_work, q16_t * y_work)
Solve system A · x = b via LU decomposition using caller-supplied workspace buffer.
void syn_matrix_sub (const SYN_Matrix * a, const SYN_Matrix * b, SYN_Matrix * out)
Element-wise subtraction: out = A − B.
q16_t syn_matrix_trace (const SYN_Matrix * m)
Trace (sum of diagonal elements).
void syn_matrix_translate_2d (SYN_Matrix * out, q16_t tx, q16_t ty)
Set 3×3 matrix to a 2D translation.
void syn_matrix_translate_3d (SYN_Matrix * out, q16_t tx, q16_t ty, q16_t tz)
Set 4×4 matrix to a 3D translation.
void syn_matrix_transpose (const SYN_Matrix * a, SYN_Matrix * out)
Transpose: out = Aᵀ.
void syn_matrix_zero (SYN_Matrix * m)
Set all elements to zero.
void syn_vec3_cross (const q16_t * a, const q16_t * b, q16_t * out)
Cross product of two 3-element Q16 vectors.
q16_t syn_vec_dot (const q16_t * a, const q16_t * b, uint8_t n)
Dot product of two n-element Q16 vectors.
q16_t syn_vec_norm (const q16_t * v, uint8_t n)
Magnitude (Euclidean norm) of an n-element Q16 vector.
SYN_Status syn_vec_normalize (const q16_t * v, q16_t * out, uint8_t n)
Normalize a vector to unit length.

Macros

Type Name
define SYN_MAT2_DECL (name) [**SYN\_MAT\_DECL**](syn__matrix_8h.md#define-syn_mat_decl)(name, 2, 2)
Shorthand for 2×2.
define SYN_MAT3_DECL (name) [**SYN\_MAT\_DECL**](syn__matrix_8h.md#define-syn_mat_decl)(name, 3, 3)
Shorthand for 3×3.
define SYN_MAT4_DECL (name) [**SYN\_MAT\_DECL**](syn__matrix_8h.md#define-syn_mat_decl)(name, 4, 4)
Shorthand for 4×4.
define SYN_MAT_AT (m, r, c) ((m)-&gt;data[(r) \* (m)-&gt;cols + (c)])
Element access (row, col) — evaluates to an lvalue.
define SYN_MAT_DECL (name, R, C) /* multi line expression */
Declare a matrix with automatic (stack) storage.
define SYN_MAT_INIT (name, storage, R, C) [**SYN\_Matrix**](structSYN__Matrix.md) name = {(storage), (R), (C)}
Initialize a matrix view over existing storage.
define SYN_MAT_STATIC (name, R, C) /* multi line expression */
Declare a matrix with static storage (zero-initialized).
define SYN_SOLVER_MAX_N 8
Maximum matrix dimension N for general linear solvers (LU, Cholesky, LS)

Detailed Description

Supports compile-time-arbitrary matrix dimensions. Callers supply all storage via stack or static arrays. The compiler constant-folds dimension parameters and unrolls loops when sizes are compile-time constants.

** **

// Declare three 3×3 matrices on the stack
SYN_MAT_DECL(A, 3, 3);
SYN_MAT_DECL(B, 3, 3);
SYN_MAT_DECL(C, 3, 3);

syn_matrix_identity(&A);
syn_matrix_rotate_2d(&B, Q16_PI_2);  // 90° rotation
syn_matrix_mul(&A, &B, &C);          // C = A × B

// Non-square multiply: 2×3 × 3×4 = 2×4
SYN_MAT_DECL(M, 2, 3);
SYN_MAT_DECL(N, 3, 4);
SYN_MAT_DECL(P, 2, 4);
syn_matrix_mul(&M, &N, &P);

// Element access
SYN_MAT_AT(&A, 1, 2) = Q16_FROM_INT(42);

Public Functions Documentation

function syn_matrix_add

Element-wise addition: out = A + B.

void syn_matrix_add (
    const SYN_Matrix * a,
    const SYN_Matrix * b,
    SYN_Matrix * out
) 

Parameters:

  • a First operand.
  • b Second operand (same dimensions as a).
  • out Result (same dimensions as a).

function syn_matrix_copy

Copy matrix contents.

void syn_matrix_copy (
    SYN_Matrix * dst,
    const SYN_Matrix * src
) 

Parameters:

  • dst Destination (must match src dimensions).
  • src Source matrix.

function syn_matrix_det

Determinant of a square matrix.

q16_t syn_matrix_det (
    const SYN_Matrix * m
) 

Supports 2×2, 3×3, and 4×4. Uses cofactor expansion for 2×2/3×3 and LU decomposition for 4×4.

Parameters:

  • m Square matrix.

Returns:

Determinant in Q16.


function syn_matrix_eigen_sym2

Compute eigenvalues and eigenvectors of a symmetric 2×2 matrix A.

SYN_Status syn_matrix_eigen_sym2 (
    const SYN_Matrix * A,
    q16_t evals,
    SYN_Matrix * E
) 

Parameters:

  • A Symmetric 2×2 matrix.
  • evals Output array of 2 eigenvalues (sorted descending).
  • E Output 2×2 matrix whose columns are the normalized eigenvectors.

Returns:

SYN_OK on success, SYN_INVALID_PARAM on invalid inputs.


function syn_matrix_eigen_sym3

Compute eigenvalues and eigenvectors of a symmetric 3×3 matrix A via Jacobi rotations.

SYN_Status syn_matrix_eigen_sym3 (
    const SYN_Matrix * A,
    q16_t evals,
    SYN_Matrix * E
) 

Parameters:

  • A Symmetric 3×3 matrix.
  • evals Output array of 3 eigenvalues (sorted descending).
  • E Output 3×3 matrix whose columns are the normalized eigenvectors.

Returns:

SYN_OK on success, SYN_INVALID_PARAM on invalid inputs.


function syn_matrix_get_block

Extract a submatrix block from src into dst.

SYN_Status syn_matrix_get_block (
    const SYN_Matrix * src,
    uint8_t r0,
    uint8_t c0,
    SYN_Matrix * dst
) 

Parameters:

  • src Source matrix (M×N).
  • r0 Starting row index in src.
  • c0 Starting column index in src.
  • dst Destination matrix (R×C). Must fit within src bounds from (r0, c0).

Returns:

SYN_OK on success, SYN_INVALID_PARAM on out-of-bounds.


function syn_matrix_identity

Set matrix to identity.

void syn_matrix_identity (
    SYN_Matrix * m
) 

Parameters:

  • m Square matrix.

function syn_matrix_inv

Matrix inverse: out = M⁻¹.

SYN_Status syn_matrix_inv (
    const SYN_Matrix * m,
    SYN_Matrix * out
) 

Supports 2×2, 3×3, and 4×4 square matrices. Returns SYN_ERROR if the matrix is singular (determinant ≈ 0).

Parameters:

  • m Input square matrix.
  • out Output inverse (same dimensions). Must not alias m.

Returns:

SYN_OK on success, SYN_ERROR if singular.


function syn_matrix_inv_3x3

Invert a 3×3 matrix in-place or out-of-place via Cramer's rule.

SYN_Status syn_matrix_inv_3x3 (
    const SYN_Matrix * src,
    SYN_Matrix * dst
) 

Parameters:

  • src Input 3×3 matrix.
  • dst Output 3×3 inverse matrix. May alias src.

Returns:

SYN_OK on success, SYN_ERROR if matrix is singular (det == 0).


function syn_matrix_inv_lu

Invert an arbitrary N×N matrix via LU decomposition (convenience wrapper).

SYN_Status syn_matrix_inv_lu (
    const SYN_Matrix * src,
    SYN_Matrix * dst
) 

Parameters:

  • src Input square matrix (N×N).
  • dst Output inverse matrix (N×N).

Returns:

SYN_OK on success, SYN_ERROR if src is singular or dimensions invalid.


function syn_matrix_inv_lu_work

Invert an arbitrary N×N matrix via LU decomposition using caller-supplied workspace.

SYN_Status syn_matrix_inv_lu_work (
    const SYN_Matrix * src,
    SYN_Matrix * dst,
    q16_t * lu_work,
    uint8_t * p_work,
    q16_t * col_work
) 

Parameters:

  • src Input square matrix (N×N).
  • dst Output inverse matrix (N×N). Must not alias src.
  • lu_work Caller-supplied N×N buffer (N*N elements).
  • p_work Caller-supplied N pivot buffer (N elements).
  • col_work Caller-supplied N vector buffer (N elements).

Returns:

SYN_OK on success, SYN_ERROR if src is singular or dimensions invalid.


function syn_matrix_least_squares

Solve overdetermined system A · x ≈ b via Normal Equations (Least Squares).

SYN_Status syn_matrix_least_squares (
    const SYN_Matrix * A,
    const SYN_Matrix * b,
    SYN_Matrix * x
) 

Parameters:

  • A Overdetermined system matrix (M×N, M ≥ N).
  • b Right-hand side measurement vector (M×1).
  • x Output solution parameter vector (N×1).

Returns:

SYN_OK on success, SYN_ERROR if AᵀA is singular.


function syn_matrix_least_squares_work

Solve overdetermined system A · x ≈ b via Least Squares using caller-supplied workspace.

SYN_Status syn_matrix_least_squares_work (
    const SYN_Matrix * A,
    const SYN_Matrix * b,
    SYN_Matrix * x,
    q16_t * ata_work,
    q16_t * atb_work,
    q16_t * at_work,
    q16_t * solver_lu,
    q16_t * solver_y
) 

Parameters:

  • A Overdetermined system matrix (M×N, M ≥ N).
  • b Right-hand side measurement vector (M×1).
  • x Output solution parameter vector (N×1).
  • ata_work Caller-supplied N×N matrix buffer (N*N elements).
  • atb_work Caller-supplied N vector buffer (N elements).
  • at_work Caller-supplied N×M transpose matrix buffer (N*M elements).
  • solver_lu Caller-supplied N×N solver matrix buffer (N*N elements).
  • solver_y Caller-supplied N solver vector buffer (N elements).

Returns:

SYN_OK on success, SYN_ERROR if AᵀA is singular.


function syn_matrix_mul

Matrix multiply: out = A × B.

void syn_matrix_mul (
    const SYN_Matrix * a,
    const SYN_Matrix * b,
    SYN_Matrix * out
) 

Requires: A.cols == B.rows, out is A.rows × B.cols. Uses int64_t accumulator for full Q16 precision.

Parameters:

  • a Left operand (R₁ × C₁).
  • b Right operand (C₁ × C₂).
  • out Result (R₁ × C₂). Must not alias a or b.

function syn_matrix_mul_vec

Matrix–vector multiply: out = M × v.

void syn_matrix_mul_vec (
    const SYN_Matrix * m,
    const q16_t * v_in,
    q16_t * v_out,
    uint8_t n_in
) 

Parameters:

  • m Square or rectangular matrix (R × C).
  • v_in Input vector (C elements).
  • v_out Output vector (R elements). Must not alias v_in.
  • n_in Length of input vector (must equal m->cols).

function syn_matrix_outer_product

Vector outer product: out = u · vᵀ (rows(u) × cols(v)).

SYN_Status syn_matrix_outer_product (
    const q16_t * u,
    uint8_t rows,
    const q16_t * v,
    uint8_t cols,
    SYN_Matrix * out
) 

Parameters:

  • u Column vector elements (R elements).
  • rows Number of rows (R).
  • v Row vector elements (C elements).
  • cols Number of columns (C).
  • out Output matrix (R×C).

Returns:

SYN_OK on success, SYN_INVALID_PARAM if NULL or invalid dimensions.


function syn_matrix_qr

QR Decomposition: A = Q · R via Modified Gram-Schmidt process.

SYN_Status syn_matrix_qr (
    const SYN_Matrix * A,
    SYN_Matrix * Q,
    SYN_Matrix * R
) 

Decomposes an M×N matrix A (M ≥ N) into orthogonal M×N matrix Q (QᵀQ = I) and upper-triangular N×N matrix R.

Parameters:

  • A Input matrix (M×N, M ≥ N).
  • Q Output orthogonal matrix (M×N).
  • R Output upper-triangular matrix (N×N).

Returns:

SYN_OK on success, SYN_ERROR if A is linearly dependent / singular.


function syn_matrix_rotate_2d

Set 3×3 matrix to a 2D rotation.

void syn_matrix_rotate_2d (
    SYN_Matrix * out,
    q16_t angle
) 

Parameters:

  • out Output 3×3 matrix.
  • angle Rotation angle in Q16 radians (counter-clockwise).

function syn_matrix_rotate_x

Set 4×4 matrix to a rotation around the X axis.

void syn_matrix_rotate_x (
    SYN_Matrix * out,
    q16_t angle
) 

Parameters:

  • out Output 4×4 matrix.
  • angle Rotation angle in Q16 radians.

function syn_matrix_rotate_y

Set 4×4 matrix to a rotation around the Y axis.

void syn_matrix_rotate_y (
    SYN_Matrix * out,
    q16_t angle
) 

Parameters:

  • out Output 4×4 matrix.
  • angle Rotation angle in Q16 radians.

function syn_matrix_rotate_z

Set 4×4 matrix to a rotation around the Z axis.

void syn_matrix_rotate_z (
    SYN_Matrix * out,
    q16_t angle
) 

Parameters:

  • out Output 4×4 matrix.
  • angle Rotation angle in Q16 radians.

function syn_matrix_scale

Scalar multiply: out = A × scalar.

void syn_matrix_scale (
    const SYN_Matrix * a,
    q16_t scalar,
    SYN_Matrix * out
) 

Parameters:

  • a Input matrix.
  • scalar Q16 scalar multiplier.
  • out Result (same dimensions as a).

function syn_matrix_scale_2d

Set 3×3 matrix to a 2D scale.

void syn_matrix_scale_2d (
    SYN_Matrix * out,
    q16_t sx,
    q16_t sy
) 

Parameters:

  • out Output 3×3 matrix.
  • sx X scale factor in Q16.
  • sy Y scale factor in Q16.

function syn_matrix_set_block

Embed a submatrix block src into dst at position (r0, c0).

SYN_Status syn_matrix_set_block (
    SYN_Matrix * dst,
    uint8_t r0,
    uint8_t c0,
    const SYN_Matrix * src
) 

Parameters:

  • dst Destination matrix (M×N).
  • r0 Starting row index in dst.
  • c0 Starting column index in dst.
  • src Source submatrix block (R×C).

Returns:

SYN_OK on success, SYN_INVALID_PARAM on out-of-bounds.


function syn_matrix_solve_cholesky

Solve symmetric positive-definite system A · x = b via Cholesky (convenience wrapper).

SYN_Status syn_matrix_solve_cholesky (
    const SYN_Matrix * A,
    const SYN_Matrix * b,
    SYN_Matrix * x
) 

Parameters:

  • A Symmetric positive-definite system matrix (N×N).
  • b Right-hand side vector (N×1).
  • x Output solution vector (N×1). May alias b.

Returns:

SYN_OK on success, SYN_ERROR if A is not positive-definite.


function syn_matrix_solve_cholesky_work

Solve system A · x = b via Cholesky decomposition using caller-supplied workspace buffer.

SYN_Status syn_matrix_solve_cholesky_work (
    const SYN_Matrix * A,
    const SYN_Matrix * b,
    SYN_Matrix * x,
    q16_t * L_work,
    q16_t * y_work
) 

Parameters:

  • A Symmetric positive-definite system matrix (N×N).
  • b Right-hand side vector (N×1).
  • x Output solution vector (N×1).
  • L_work Caller-supplied N×N lower triangular buffer (N*N elements).
  • y_work Caller-supplied N vector buffer (N elements).

Returns:

SYN_OK on success, SYN_ERROR if A is not positive-definite.


function syn_matrix_solve_lu

Solve system A · x = b via LU decomposition (convenience wrapper).

SYN_Status syn_matrix_solve_lu (
    const SYN_Matrix * A,
    const SYN_Matrix * b,
    SYN_Matrix * x
) 

Parameters:

  • A Square system matrix (N×N).
  • b Right-hand side vector (N×1).
  • x Output solution vector (N×1). May alias b.

Returns:

SYN_OK on success, SYN_ERROR if A is singular or dimensions invalid.


function syn_matrix_solve_lu_work

Solve system A · x = b via LU decomposition using caller-supplied workspace buffer.

SYN_Status syn_matrix_solve_lu_work (
    const SYN_Matrix * A,
    const SYN_Matrix * b,
    SYN_Matrix * x,
    q16_t * lu_work,
    uint8_t * p_work,
    q16_t * y_work
) 

Zero stack allocation inside solver.

Parameters:

  • A Square system matrix (N×N).
  • b Right-hand side vector (N×1).
  • x Output solution vector (N×1).
  • lu_work Caller-supplied N×N buffer (N*N elements).
  • p_work Caller-supplied N pivot buffer (N elements).
  • y_work Caller-supplied N vector buffer (N elements).

Returns:

SYN_OK on success, SYN_ERROR if A is singular or dimensions invalid.


function syn_matrix_sub

Element-wise subtraction: out = A − B.

void syn_matrix_sub (
    const SYN_Matrix * a,
    const SYN_Matrix * b,
    SYN_Matrix * out
) 

Parameters:

  • a Minuend.
  • b Subtrahend (same dimensions as a).
  • out Result (same dimensions as a).

function syn_matrix_trace

Trace (sum of diagonal elements).

q16_t syn_matrix_trace (
    const SYN_Matrix * m
) 

Parameters:

  • m Square matrix.

Returns:

Trace in Q16.


function syn_matrix_translate_2d

Set 3×3 matrix to a 2D translation.

void syn_matrix_translate_2d (
    SYN_Matrix * out,
    q16_t tx,
    q16_t ty
) 

Parameters:

  • out Output 3×3 matrix.
  • tx X translation in Q16.
  • ty Y translation in Q16.

function syn_matrix_translate_3d

Set 4×4 matrix to a 3D translation.

void syn_matrix_translate_3d (
    SYN_Matrix * out,
    q16_t tx,
    q16_t ty,
    q16_t tz
) 

Parameters:

  • out Output 4×4 matrix.
  • tx X translation in Q16.
  • ty Y translation in Q16.
  • tz Z translation in Q16.

function syn_matrix_transpose

Transpose: out = Aᵀ.

void syn_matrix_transpose (
    const SYN_Matrix * a,
    SYN_Matrix * out
) 

Parameters:

  • a Input (R × C).
  • out Output (C × R). Must not alias a.

function syn_matrix_zero

Set all elements to zero.

void syn_matrix_zero (
    SYN_Matrix * m
) 

Parameters:

  • m Matrix to clear.

function syn_vec3_cross

Cross product of two 3-element Q16 vectors.

void syn_vec3_cross (
    const q16_t * a,
    const q16_t * b,
    q16_t * out
) 

Parameters:

  • a First vector (3 elements).
  • b Second vector (3 elements).
  • out Output vector (3 elements). Must not alias a or b.

function syn_vec_dot

Dot product of two n-element Q16 vectors.

q16_t syn_vec_dot (
    const q16_t * a,
    const q16_t * b,
    uint8_t n
) 

Parameters:

  • a First vector.
  • b Second vector.
  • n Number of elements.

Returns:

Dot product in Q16.


function syn_vec_norm

Magnitude (Euclidean norm) of an n-element Q16 vector.

q16_t syn_vec_norm (
    const q16_t * v,
    uint8_t n
) 

Parameters:

  • v Vector.
  • n Number of elements.

Returns:

|v| in Q16.


function syn_vec_normalize

Normalize a vector to unit length.

SYN_Status syn_vec_normalize (
    const q16_t * v,
    q16_t * out,
    uint8_t n
) 

Parameters:

  • v Input vector (n elements).
  • out Output unit vector (n elements). May alias v.
  • n Number of elements.

Returns:

SYN_OK on success, SYN_ERROR if zero-length vector.


Macro Definition Documentation

define SYN_MAT2_DECL

Shorthand for 2×2.

#define SYN_MAT2_DECL (
    name
) `SYN_MAT_DECL (name, 2, 2)`


define SYN_MAT3_DECL

Shorthand for 3×3.

#define SYN_MAT3_DECL (
    name
) `SYN_MAT_DECL (name, 3, 3)`


define SYN_MAT4_DECL

Shorthand for 4×4.

#define SYN_MAT4_DECL (
    name
) `SYN_MAT_DECL (name, 4, 4)`


define SYN_MAT_AT

Element access (row, col) — evaluates to an lvalue.

#define SYN_MAT_AT (
    m,
    r,
    c
) `((m)->data[(r) * (m)->cols + (c)])`


define SYN_MAT_DECL

Declare a matrix with automatic (stack) storage.

#define SYN_MAT_DECL (
    name,
    R,
    C
) `q16_t name##_store[(R) * (C)]; \ SYN_Matrix name = {name##_store, (R), (C)}`


define SYN_MAT_INIT

Initialize a matrix view over existing storage.

#define SYN_MAT_INIT (
    name,
    storage,
    R,
    C
) `SYN_Matrix name = {(storage), (R), (C)}`


define SYN_MAT_STATIC

Declare a matrix with static storage (zero-initialized).

#define SYN_MAT_STATIC (
    name,
    R,
    C
) `/* multi line expression */`


define SYN_SOLVER_MAX_N

Maximum matrix dimension N for general linear solvers (LU, Cholesky, LS)

#define SYN_SOLVER_MAX_N `8`



The documentation for this class was generated from the following file src/syntropic/util/syn_matrix.h