C++ matrix classes
Similar to RVec, we want a C++ matrix class to replace C-style matrices.
General requirements are
- member access operator ( can be (x,y) or [x][y])
- enables efficient algebra operations
- implicit conversions between const and non-const matrices
- constraint matrix implementation
- implicit conversion from constraint to non-constraint matrices
For a feasible transition period from the C-style matrices,
- implicit conversion operator to matrix type
- member access with bracket notation [x][y]
Previous discussion about C++ style vectors/matrices led to RVec implementation at #1017
view on MultiDimArray
Access the view and a const view on a MultiDimArray.
Matrices with contiguous, aliged memory as C-style "matrix" replacement
Matrix elements are accessed efficiently with bracket notation m(x,y)
or, for compability reasons, with m[x][y] (though deprecated)
Matrices manage their own memory, but provide an implicit conversion to
views and const views on their data which should be used instead of a
Arithmetic operations will follow in a later patch.
#5 Updated by Mark Abraham 8 months ago
From src/gromacs/math/vec.h, we probably want ways to access most of the following functionality:
matrix (3x3) operations: ! indicates that dest should not be the same as a, b or src the _ur0 varieties work on matrices that have only zeros in the upper right part, such as box matrices, these varieties could produce less rounding errors, not due to the operations themselves, but because the compiler can easier recombine the operations void copy_mat(matrix a,matrix b) b = a void clear_mat(matrix a) a = 0 void mmul(matrix a,matrix b,matrix dest) ! dest = a . b void mmul_ur0(matrix a,matrix b,matrix dest) dest = a . b void transpose(matrix src,matrix dest) ! dest = src* void tmmul(matrix a,matrix b,matrix dest) ! dest = a* . b void mtmul(matrix a,matrix b,matrix dest) ! dest = a . b* real det(matrix a) = det(a) void m_add(matrix a,matrix b,matrix dest) dest = a + b void m_sub(matrix a,matrix b,matrix dest) dest = a - b void msmul(matrix m1,real r1,matrix dest) dest = r1 * m1 void mvmul(matrix a,rvec src,rvec dest) ! dest = a . src void mvmul_ur0(matrix a,rvec src,rvec dest) dest = a . src void tmvmul_ur0(matrix a,rvec src,rvec dest) dest = a* . src real trace(matrix m) = trace(m)
There's probably some useful operations (or implementation details) to copy from BasicVector in vectypes.h