r/cprogramming • • 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:

  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

14 comments sorted by

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.

4

u/Nonyabuizness 4d ago

Sure sure! I'll definitely check it out 😁

6

u/CoderStudios 4d ago

I don’t trust projects that don’t have a verifiable git commit history to be authored by humans.

1

u/Nonyabuizness 4d ago edited 4d ago

I didn't know this was an issue.
I don't make my repositories public unless i feel its presentable online.

If you want proof...I am not allowed to share images here but my header file was created on 27th October and I have commit history on my private repository

4

u/CoderStudios 4d ago

It’s the worst issue online right know, every second post sometimes is

hey “I” built x, y, z which seems really cool and advanced but probably doesn’t have a good reason for existing

But as long as yours it’s actually made by a human I applaud you for that 😊

1

u/Nonyabuizness 4d ago

Thanks for the insight. I really didn't know commit histories were that important!

1

u/Key_River7180 4d ago

Why are you not allowed?

I present my OSS very half finished so yeah...

2

u/Nonyabuizness 4d ago

No I meant I am not allowed to share my commit history screenshot in the comments here.

1

u/Key_River7180 4d ago

Oh then share an imgur link

1

u/Nonyabuizness 4d ago

Imgur doesn't work in my country
https://imgbox.com/g/8W2OmGVLfg

I won't lie. I didn't know commit histories mattered so much so I was sloppy with it. Only gave one-liners like changes made. But you can see I worked on this library for nearly a month.

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/Nonyabuizness 22h 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/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

1

u/Nonyabuizness 3d ago

I didnt use a Matrix type because I wanted user to be able to pass raw stack and static data. I took more of leave everything to the user approach.

Regarding the return 0, I wanted to make sure my library never causes the segfault. But after you explained....maybe I could have used return NaN