I'm in need of a lightweight library for 2d & 3d vectors and 3x3 & 4x4 matrices. In basic C. Just so I don't reinvent the wheel suboptimally.
Any suggestions?
This article develops a matrix algebra library in the C language. The library includes both basic and advanced functions that are defined in this regard. The library is properly coded to be fast and efficient by employing appropriate mathematical algorithms.
Finding the eigenvectors and eigenvalues for a linear transformation is often done using matrix algebra, first developed in the mid-19th century by the English mathematician Arthur Cayley. His work formed the foundation for modern linear algebra.
Meschach is a c-only vector/matrix library, significantly smaller than e.g. LAPACK (according to the FAQ, at least :)
Many people are telling you to use various BLAS libraries, but this is probably going to be very slow for you since you are working on small matrices. Most of them are optimized to chunk the matrix into fixed sizes (around 50ish elements - depends on cache sizes) and operate on the chunks with an optimized algorithm, then operate on the leftovers with a trivial algorithm. On small matrices this makes it even slower than just calling the trivial algorithm.
FWIW, when I needed to do this in fortran (2x2 and 4x4 square matrix mults) I just hardcoded fully unrolled versions and it worked well enough (about 20x the speed of builtin MATMUL on gfortran, but part of this was probably due to the fact that MATMUL is not in place and my version was). I could never find a good library to do this for me.
In C++ it would be fine since you would be able to use BLITZ but alas...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With