Index of /code/matrix/

NameLast modified
Makefile 12-Nov-2011 17:49
matrix.hpp 12-Nov-2011 18:19
matrix_fwd.hpp 12-Nov-2011 17:43
matrix_test.cpp 12-Nov-2011 18:24


What is it?
One day I was bored, so I wrote a matrix class based on the C++ std::vector container. This is the result of my labors.
Can I use it?
Sure, but there's no warranty expressed or implied.
How can I use it?
See the reference.
Should I use it?

Probably not. Here are some other matrix libraries that are actually supported by their authors:

These libraries are rather heavy-duty, though; I still like my implementation for its (relative) simplicity.

Why is it called eloi::matrix?

I go by the nickname elo[i] on #C++ on EFnet. It's a matrix class. You do the math.

Why did you privately inherit from std::vector?

It's what Herb Sutter calls the "Is Implemented In Terms Of" idiom. Here, a 2D array is implemented in terms of a 1D array:

012 345 678

This is what C++ does under the hood for fixed-size multidimensional arrays (T array[R][C]). This approach also requires less memory than a vector of vectors or a vector of pointers, each of which adds a fixed cost per row. And it's a smidge faster than those, too.

A smidge faster, eh?

Per the results from this program, with minor optimizations enabled, on an Intel Core i7-2720QM running 64-bit Ubuntu Linux:

type row column rand
init fetch init fetch
T[R*C] 0.301.4711.6513.8225.38
T[R][C] 0.271.4111.7413.8225.47
T *[R] 0.351.3912.2014.8526.75
new T[R*C] 0.291.3912.3014.2625.42
new T[R][C] 0.271.3712.2414.1926.19
new T *[R] 0.341.4012.8515.4427.55
vector<T> 0.281.3712.1914.1426.19
vector<vector<T>> 0.351.3813.9016.2527.83
vector<T *> 0.331.3912.6515.3427.55