Meaning, calling invertMatrix(mat, mat) with mat = type::Mat<2,2> and type::Mat<3,3> is wrong.
dest(0,0)= from(1,1)/det;
dest(0,1)= -from(0,1)/det;
dest(1,0)= -from(1,0)/det;
dest(1,1)= from(0,0)/det;
first line of code will modify mat(0,0) and then last line will use this value for mat(1,1)
Meaning, calling invertMatrix(mat, mat) with mat = type::Mat<2,2> and type::Mat<3,3> is wrong.
Because :
(illustration with 2x2):
https://github.com/alxbilger/sofa/blob/a1395f7adce413f1ce1966e9e4055c2ad0334545/Sofa/framework/Type/src/sofa/type/Mat.h#L1198
first line of code will modify mat(0,0) and then last line will use this value for mat(1,1)