Skip to content

Mat (C) — Print Helpers & Convenience Wrapper

Overview

tiny_mat.h serves two purposes in the post-refactoring TinyMath:

  1. Print helpers — debug-print matrices to serial console
  2. Convenience header — includes all submodules for backward compatibility

Header: #include "tiny_mat.h"


Architecture

Since the refactoring that split the original monolithic tiny_mat.c (1920 lines) into dedicated submodules, tiny_mat.h is now a thin wrapper:

tiny_mat.h
├── #include "tiny_linalg.h"    → element-wise ops
├── #include "tiny_cfloat.h"    → complex arithmetic
├── #include "tiny_decomp.h"    → matrix decomposition
├── #include "tiny_eigen.h"     → eigenvalue computation
├── #include "tiny_modal.h"     → modal analysis
└── #include "tiny_iterative.h" → Krylov methods & RSVD
    (plus print_matrix declarations)

Backward Compatibility

Existing code that uses #include "tiny_mat.h" continues to work without changes — all functions are re-exported through the submodule includes.


void print_matrix(const char *name, const float *mat, int rows, int cols);

Prints a contiguous matrix (no padding, row-major).

Param Description
name Label printed before the matrix
mat Row-major matrix data
rows Number of rows
cols Number of columns

Output:

A =
  1.000000   2.000000   3.000000
  4.000000   5.000000   6.000000

void print_matrix_padded(const char *name, const float *mat,
                          int rows, int cols, int step);

Prints a matrix with row padding. step = logical columns + padding.

Param Description
name Label printed before the matrix
mat Row-major matrix data
rows Number of rows
cols Number of logical columns to display
step Total elements per row (including padding)

Platform Support

Both functions use printf() from <stdio.h> — no platform-specific dispatch.


Usage

#include "tiny_mat.h"

// Print a 2×3 matrix
float A[6] = {1, 2, 3, 4, 5, 6};
print_matrix("A", A, 2, 3);

// Print the same matrix with padding info
print_matrix_padded("A (padded)", A, 2, 3, 3);  // step = cols (no padding)

// All submodule functions are also available:
tiny_cfloat_t z = tiny_cf(1.0f, 2.0f);

For detailed function documentation, see the dedicated submodule pages:

Module Page
Vector operations VECTOR API
Basic linear algebra LINALG API
Complex numbers CFLOAT API
Matrix decomposition DECOMP API
Eigenvalue & modal EIGEN API
Iterative methods ITERATIVE API