## Task #2834

### C++ matrix classes

**Description**

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])
- copy-able
- movable
- 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

**Subtasks**

### Associated revisions

3x3 matrices

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

copy.

Arithmetic operations will follow in a later patch.

refs #2834

Change-Id: Ia96037384d2e1d774559fbcac97f420c58106625

### History

#### #1 Updated by Gerrit Code Review Bot 3 months ago

Gerrit received a related patchset '16' for Issue #2834.

Uploader: Christian Blau (cblau@gwdg.de)

Change-Id: gromacs~master~Ida9dd28d27e2b17bac05a17eb1110a900a7701bd

Gerrit URL: https://gerrit.gromacs.org/6309

#### #2 Updated by Gerrit Code Review Bot 3 months ago

Gerrit received a related patchset '7' for Issue #2834.

Uploader: Christian Blau (cblau@gwdg.de)

Change-Id: gromacs~master~I4d3eab9073e23afb752cc0f15d09acd9824b6e93

Gerrit URL: https://gerrit.gromacs.org/6312

#### #3 Updated by Gerrit Code Review Bot 3 months ago

Gerrit received a related patchset '3' for Issue #2834.

Uploader: Christian Blau (cblau@gwdg.de)

Change-Id: gromacs~master~Ia96037384d2e1d774559fbcac97f420c58106625

Gerrit URL: https://gerrit.gromacs.org/8981

#### #4 Updated by Roland Schulz 3 months ago

We can add [] bracket notation to mdspan.

#### #5 Updated by Mark Abraham 3 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

#### #6 Updated by Gerrit Code Review Bot 3 months ago

Gerrit received a related patchset '1' for Issue #2834.

Uploader: Christian Blau (cblau@gwdg.de)

Change-Id: gromacs~master~If2c1d8f05bba95318f3fe725599e91392cd1869a

Gerrit URL: https://gerrit.gromacs.org/9018

#### #7 Updated by Gerrit Code Review Bot 3 months ago

Gerrit received a related patchset '3' for Issue #2834.

Uploader: Christian Blau (cblau@gwdg.de)

Change-Id: gromacs~master~Ia82983ac9e3bc8edebc53a1c9f3335101ad4c704

Gerrit URL: https://gerrit.gromacs.org/9016

view on MultiDimArray

Access the view and a const view on a MultiDimArray.

refs #2834

Change-Id: Ia82983ac9e3bc8edebc53a1c9f3335101ad4c704