diff --git a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/matrix_bloc_traits.h b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/matrix_bloc_traits.h index 76ac62e7eb5..cfebb1135b9 100644 --- a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/matrix_bloc_traits.h +++ b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/matrix_bloc_traits.h @@ -194,49 +194,14 @@ class matrix_bloc_traits < sofa::type::Vec, IndexType > } }; -template -class matrix_bloc_traits < float, IndexType > +template requires std::is_scalar_v +class matrix_bloc_traits < T, IndexType > { public: - typedef float Block; - typedef Block BlockTranspose; - - typedef float Real; - enum { NL = 1 }; - enum { NC = 1 }; - static Real& v(Block& b, IndexType, IndexType) { return b; } - static const Real& v(const Block& b, IndexType, IndexType) { return b; } - static void vset(Block& b, int, int, Real val) { b = val; } - static void vadd(Block& b, int, int, Real val) { b += val; } - static void clear(Block& b) { b = 0; } - static bool empty(const Block& b) - { - return b == 0; - } - static void invert(Block& result, const Block& b) { result = 1.0f/b; } - - static void split_row_index(IndexType& index, IndexType& modulo) { bloc_index_func::split(index, modulo); } - static void split_col_index(IndexType& index, IndexType& modulo) { bloc_index_func::split(index, modulo); } - - template, bool> = true> - static void subBlock(const Block& b, IndexType row, IndexType col, TSubBlock& subBlock) - { - subBlock = v(b, row, col); - } - - static const std::string Name() { return sofa::type::TypeTrait::name(); } - static sofa::linearalgebra::BaseMatrix::ElementType getElementType() { return sofa::linearalgebra::BaseMatrix::ELEMENT_FLOAT; } - static IndexType getElementSize() { return sizeof(Real); } -}; - -template -class matrix_bloc_traits < double, IndexType > -{ -public: - typedef double Block; + typedef T Block; typedef Block BlockTranspose; - typedef double Real; + typedef T Real; enum { NL = 1 }; enum { NC = 1 }; static Real& v(Block& b, IndexType, IndexType) { return b; } @@ -248,7 +213,7 @@ class matrix_bloc_traits < double, IndexType > { return b == 0; } - static void invert(Block& result, const Block& b) { result = 1.0/b; } + static void invert(Block& result, const Block& b) { result = static_cast(1.0) / b; } template, bool> = true> static void subBlock(const Block& b, IndexType row, IndexType col, TSubBlock& subBlock) @@ -263,39 +228,4 @@ class matrix_bloc_traits < double, IndexType > static const std::string Name() { return sofa::type::TypeTrait::name(); } }; -template -class matrix_bloc_traits < int, IndexType > -{ -public: - typedef float Block; - typedef Block BlockTranspose; - - typedef float Real; - enum { NL = 1 }; - enum { NC = 1 }; - static Real& v(Block& b, int, int) { return b; } - static const Real& v(const Block& b, int, int) { return b; } - static void vset(Block& b, int, int, Real val) { b = val; } - static void vadd(Block& b, int, int, Real val) { b += val; } - static void clear(Block& b) { b = 0; } - static bool empty(const Block& b) - { - return b == 0; - } - static void invert(Block& result, const Block& b) { result = 1.0f/b; } - - template, bool> = true> - static void subBlock(const Block& b, IndexType row, IndexType col, TSubBlock& subBlock) - { - subBlock = v(b, row, col); - } - - static void split_row_index(int& index, int& modulo) { bloc_index_func::split(index, modulo); } - static void split_col_index(int& index, int& modulo) { bloc_index_func::split(index, modulo); } - - static sofa::linearalgebra::BaseMatrix::ElementType getElementType() { return sofa::linearalgebra::BaseMatrix::ELEMENT_INT; } - static const std::string Name() { return sofa::type::TypeTrait::name(); } -}; - - } // namespace sofa::linearalgebra