diff --git a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/BaseMatrix.cpp b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/BaseMatrix.cpp index be01bdfc369..4abbdfac1d0 100644 --- a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/BaseMatrix.cpp +++ b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/BaseMatrix.cpp @@ -29,7 +29,7 @@ namespace sofa::linearalgebra { -BaseMatrix::BaseMatrix() {} +BaseMatrix::BaseMatrix() = default; BaseMatrix::~BaseMatrix() {} @@ -64,11 +64,20 @@ struct BaseMatrixLinearOpMV_BlockDiagonal const Index colSize = mat->colSize(); BlockData buffer; - if (!add) - opVresize(result, (transpose ? colSize : rowSize)); + if constexpr (!add) + { + if constexpr (transpose) + { + opVresize(result, colSize); + } + else + { + opVresize(result, rowSize); + } + } for (std::pair rowRange = mat->bRowsRange(); - rowRange.first != rowRange.second; - ++rowRange.first) + rowRange.first != rowRange.second; + ++rowRange.first) { std::pair colRange = rowRange.first.range(); if (colRange.first != colRange.second) // diagonal block exists @@ -77,7 +86,7 @@ struct BaseMatrixLinearOpMV_BlockDiagonal const BlockData& bdata = *(const BlockData*)block.elements(buffer.ptr()); const Index i = block.getRow() * NL; const Index j = block.getCol() * NC; - if (!transpose) + if constexpr (!transpose) { type::VecNoInit vj; for (int bj = 0; bj < NC; ++bj) @@ -162,8 +171,17 @@ struct BaseMatrixLinearOpMV_BlockDiagonal { const Index rowSize = mat->rowSize(); const Index colSize = mat->colSize(); - if (!add) - opVresize(result, (transpose ? colSize : rowSize)); + if constexpr (!add) + { + if constexpr (transpose) + { + opVresize(result, colSize); + } + else + { + opVresize(result, rowSize); + } + } const Index size = (rowSize < colSize) ? rowSize : colSize; for (Index i=0; i vtmpj; type::Vec vtmpi; - if (!add) + if constexpr (!add) + { opVresize(result, (transpose ? colSize : rowSize)); + } for (std::pair rowRange = mat->bRowsRange(); - rowRange.first != rowRange.second; - ++rowRange.first) + rowRange.first != rowRange.second; + ++rowRange.first) { const Index i = rowRange.first.row() * NL; - if (!transpose) + if constexpr (!transpose) { for (int bi = 0; bi < NL; ++bi) vtmpi[bi] = (Real)0; @@ -212,7 +232,7 @@ struct BaseMatrixLinearOpMV_BlockSparse BlockConstAccessor block = colRange.first.bloc(); const BlockData& bdata = *(const BlockData*)block.elements(buffer.ptr()); const Index j = block.getCol() * NC; - if (!transpose) + if constexpr (!transpose) { for (int bj = 0; bj < NC; ++bj) vtmpj[bj] = (Real)opVget(v, j+bj); @@ -231,14 +251,11 @@ struct BaseMatrixLinearOpMV_BlockSparse opVadd(result, j+bj, vtmpj[bj]); } } - if (!transpose) + if constexpr (!transpose) { for (int bi = 0; bi < NL; ++bi) opVadd(result, i+bi, vtmpi[bi]); } - else - { - } } } }; @@ -253,9 +270,18 @@ class BaseMatrixLinearOpMV { const Index rowSize = mat->rowSize(); const Index colSize = mat->colSize(); - if (!add) - opVresize(result, (transpose ? colSize : rowSize)); - if (!transpose) + if constexpr (!add) + { + if constexpr (transpose) + { + opVresize(result, colSize); + } + else + { + opVresize(result, rowSize); + } + } + if constexpr (!transpose) { for (Index i=0; irowSize(); const Index colSize = mat->colSize(); - if (!add) - opVresize(result, (transpose ? colSize : rowSize)); + if constexpr (!add) + { + if constexpr (transpose) + { + opVresize(result, colSize); + } + else + { + opVresize(result, rowSize); + } + } const Index size = (rowSize < colSize) ? rowSize : colSize; for (Index i=0; irowSize(); const Index colSize = mat->colSize(); - if (!add) - opVresize(result, (transpose ? colSize : rowSize)); + if constexpr (!add) + { + if (transpose) + { + opVresize(result, colSize); + } + else + { + opVresize(result, rowSize); + } + } const Index size = (rowSize < colSize) ? rowSize : colSize; for (Index i=0; iadd(i,j,bdata * fact); } @@ -626,7 +670,7 @@ class BaseMatrixLinearOpAM { const Index rowSize = m1->rowSize(); const Index colSize = m2->colSize(); - if (!transpose) + if constexpr (!transpose) { for (Index j=0; j