Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommendations for a small c-based vector and matrix library [closed]

Tags:

c

math

vector

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?

like image 636
Hans Sjunnesson Avatar asked Oct 13 '08 20:10

Hans Sjunnesson


People also ask

Is there a matrix library in C?

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.

Who discovered linear algebra?

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.


2 Answers

Meschach is a c-only vector/matrix library, significantly smaller than e.g. LAPACK (according to the FAQ, at least :)

like image 190
gnud Avatar answered Sep 23 '22 07:09

gnud


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...

like image 26
Greg Rogers Avatar answered Sep 22 '22 07:09

Greg Rogers