r/cprogramming • • 8d ago

I built a zero dependencies complex linear algebra library from scratch on C99.

It has zero dependencies and is built entirely from C99 <complex.h> library. Anybody can use my library to write programs utilizing complex vector spaces be it Electrical Engineering, Signal Processing, Quantum Mechanics or even more.

I utilized single pointer flattened arrays for contiguous memory and cache efficiency.

I have included standalone example for every single function I have in my header file under the Examples/ folder.

I also built two pure C applications:

  1. Mesh Analysis on Bilateral Alternating Current Circuits to find mesh currents and power.
  2. von Neumann Quantum Entropy Calculator to measure entropy and uncertainty in qubit systems of pure and mixed probabilities.

Check out my https://github.com/CodeLeverEuler/c-complex-linalg

I'm a freshman and this is my first systems/math library in C. Would love feedback on my API design, memory contracts, or numerical stability edge cases!

Thank you
EDIT:
Some are suspicious that this is AI generated. I didn't know that was an issue. I thought I wouldn't make my repository public until it's done.
I can't share the image from my local file here. But if anyone is having second thoughts, I have timestamps on my private Git repository and local files

20 Upvotes

15 comments sorted by

View all comments

2

u/Quirky-Ad-292 4d ago

Neat work! I’ve Done plenty of implementations of my own linear algebra frameworks. One thing to always be smart about is naming conventions. `matrix_solver` is to ambigous of when you have more than one method! Say you use choleksy instead, or an iterative method? Prefixing or postfixing is best practises (lapack, blas and ”numerical recipies” all do it).

Also, only support complex doubles may be a flaw if you want to do real numerics. They Are fairly large. Say you have a 1000x1000 double complex vs a 1000x1000 float. The ram usage Will differ, and if you do naive Matrix multiplication all of a sudden u have substanial memory usage.

Another thing but this is highly controversial, maybe pack structs, because having to keep track of seperate variables of size is a dread in my optionen, but then one should be careful with ownership because the struct and the pointer might be different owners. Its a tradeoff going this route, but I do enjoy the idea of having a packed struct (note the name here, aligning the memory!).

But cool work!

1

u/Nonyabuizness 4d ago

Thanks a lot for looking through my programs

I deliberately made it complex as my primary intention was to make it a suitable pack for signal and wave mechanics.

Regarding the struct...I actually was in a dilemma about struct or pointer variables ...but I decided against struct because I wanted to trust the user and allow them to modify the variables the way they want to use.

Regarding matrix_solver, thank you for pointing that out. I will change it as soon as I can

1

u/Quirky-Ad-292 3d ago

One can do some neat macro magic do introduce multiple function definitions by loading a file multiple times with some predefined functions. Say multiplication between complexes or floats! Using the same Idea for macros one could also post of prefix the typename! Then it’s only one implementation to focus on! This is only a problem in certain eigenvalue / diagonalization scenarios!