r/cprogramming • u/Nonyabuizness • 4d 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:
- Mesh Analysis on Bilateral Alternating Current Circuits to find mesh currents and power.
- 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
6
u/alkavan 4d ago edited 4d ago
I encourage checking out my math and linear algebra library Vecmat — and maybe even consider implementing as a feature or feature module. You get a lot of heavy lifting for free, for example SIMD acceleration for all architectures, modularity, runtime dispatch, unified FP32/FP64 ABI, and other cool stuff. It was built to support exactly stuff like this. But even if not you're welcome to "steal" some ideas that are the result of years experience with math and physics libraries.
It's also "zero-dependency" except system math, and includes a portable testing and benchmarking framework that's easy to integrate into other projects.
6
u/CoderStudios 4d ago
I don’t trust projects that don’t have a verifiable git commit history to be authored by humans.
2
u/Quirky-Ad-292 23h 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/redoo715 3d ago
why did you chose to not create a proper matrix type? all the burden will lay on the user to follow the size of each matrix by creating size_t variables. The user has also to find a way to make difference between a matrix and a simple vector.
A second remark, is that some of your function return 0 in case if invalid input ( a == NULL || columns ==0 || rows ==0), and 0 can also be a valid return result of the same functions. This will cause some trouble to the user