4 ms·
> auto *my_matrix = new MathArray<double, 10, 10>(); In Fortran, one can choose the matrix size at runtime, though. But otherwise, great. Now if you just add
by sampo 9y ago
> auto *my_matrix = new MathArray<double, 10, 10>();
In Fortran, one can choose the matrix size at runtime, though.
But otherwise, great. Now if you just add slicing so that if we, say
allocate(name_of_array(-1:5, 1:3))
and then say fill in the matrix by
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
then
name_or_array(0:4:2,2:3)
should return
9 11 13
16 18 20
and then we're talking. (Slicing should of course also work in higher dimensions than 2.)
- gravypod 9y agoIf you want to do make an implementation that supports runtime-specified matrix sizes you change your implementation from... auto *my_matrix = new MathArray<double, 10, 10>(); Into auto *my_matrix = new MathArray<double>(10, 10); Most programs don't need dynamically sized arrays (rows and columns) and as such it makes sense to also provide a template Row and Column width. By doing this you can likely implement matrix multiplication and addition as a constexpr (with some effort) and thus get.... 1. Compile time matrix evaluation 2. Vectorized multiplication/addition of matrices 3. Pipline-efficient code