Skip to content

cmatrix

A small C matrix library. Purpose: get comfortable with manual memory management, 2D allocation patterns, and ownership/lifetime bugs — in isolation, before seatorch adds backprop math on top.

Status: not started. Begins after Beej's Guide is finished. Time-box: 1–2 weeks. This is a warm-up, not a destination — if it's taking longer, you're gold-plating it. Ship it and move to seatorch.


Goal

A Matrix struct with create/free/multiply/transpose/print, with zero memory leaks (verified with valgrind) and correct behavior on misuse (NULL input, mismatched dims).

Milestones

# Milestone What it proves
1 Matrix* mat_create(int rows, int cols) + mat_free() malloc/free discipline, struct design
2 mat_set / mat_get with bounds checking pointer arithmetic, 2D indexing into flat memory
3 mat_multiply(A, B) — naive triple loop row-major layout, return-by-pointer vs return-by-value tradeoffs
4 mat_transpose(A) in-place vs new-allocation tradeoffs
5 mat_print nothing fancy — just useful for debugging the rest
6 Run under valgrind --leak-check=full, fix every leak this is the actual point of the project
7 Misuse tests: NULL matrix, mismatched multiply dims, 0×0 matrix defensive C, not just happy-path code

Ship checklist

  • Header + implementation, single small repo (this doesn't need its own GitHub repo necessarily — can live as a folder, your call)
  • Valgrind clean
  • No writeup needed — this isn't a portfolio piece, it's a rehearsal

Decision log

  • Fill in as you go: flat array vs array-of-pointers for 2D storage, why.

Explicitly not in scope

SIMD, cache optimization, anything performance-related. That's seatorch's stage 2, deliberately deferred so this project stays about correctness and memory discipline only.