
Emil Dotchevski wrote:
For determinants, I wanted to have at least the 2x2 3x3 and 4x4 versions done efficiently because those are used in 2D and 3D graphics. The formula is certainly not efficient, but (perhaps a bit naively?) I relied on compiler optimizations: the generated functions pull all scalars in local variables, which should untie the optimizer to figure out which series of multiplication/addition operations are identical and can be computed only once.
FWIW, I read somewhere (can try to dig up reference if desired) that 4x4 (and 5x5) determinants are most efficiently calculated via dynamic programming, so you might consider explicitly implementing that rather than relying on the compiler. Also, signed volumes of small matrices might be useful, and I believe they can be implemented more efficiently than simply taking the determinant of a matrix adjoined with 1's.
I'm not sure why we're talking about 3D arrays, those can't possibly represent vectors or matrices.
I just have to take issue with the strong "can't" here ;) It is certainly imaginable that a 3D array could represent a linear operator from 2D arrays to 1D arrays, or from 1D arrays to 2D arrays. Using multidimensional arrays as your vectors might be more convenient than flattening them for a given application. - Jeff