| Name | Last 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 |
std::vector container.
This is the result of my labors.
Probably not. Here are some other matrix libraries that are actually supported by their authors:
Tensor class.
These libraries are rather heavy-duty, though; I still like my implementation for its (relative) simplicity.
eloi::matrix?I go by the nickname elo[i] on #C++ on EFnet. It's a matrix class. You do the math.
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:
| 0 | 1 | 2 |
| 3 | 4 | 5 |
| 6 | 7 | 8 |
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
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.
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.30 | 1.47 | 11.65 | 13.82 | 25.38 |
| T[R][C] | 0.27 | 1.41 | 11.74 | 13.82 | 25.47 |
| T *[R] | 0.35 | 1.39 | 12.20 | 14.85 | 26.75 |
| new T[R*C] | 0.29 | 1.39 | 12.30 | 14.26 | 25.42 |
| new T[R][C] | 0.27 | 1.37 | 12.24 | 14.19 | 26.19 |
| new T *[R] | 0.34 | 1.40 | 12.85 | 15.44 | 27.55 |
| vector<T> | 0.28 | 1.37 | 12.19 | 14.14 | 26.19 |
| vector<vector<T>> | 0.35 | 1.38 | 13.90 | 16.25 | 27.83 |
| vector<T *> | 0.33 | 1.39 | 12.65 | 15.34 | 27.55 |