Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -194,49 +194,14 @@ class matrix_bloc_traits < sofa::type::Vec<N, T>, IndexType >
}
};

template <typename IndexType>
class matrix_bloc_traits < float, IndexType >
template <class T, typename IndexType> requires std::is_scalar_v<T>
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<NL, IndexType>::split(index, modulo); }
static void split_col_index(IndexType& index, IndexType& modulo) { bloc_index_func<NC, IndexType>::split(index, modulo); }

template<class TSubBlock, std::enable_if_t<std::is_scalar_v<TSubBlock>, 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<Real>::name(); }
static sofa::linearalgebra::BaseMatrix::ElementType getElementType() { return sofa::linearalgebra::BaseMatrix::ELEMENT_FLOAT; }
static IndexType getElementSize() { return sizeof(Real); }
};

template <typename IndexType>
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; }
Expand All @@ -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<Real>(1.0) / b; }

template<class TSubBlock, std::enable_if_t<std::is_scalar_v<TSubBlock>, bool> = true>
static void subBlock(const Block& b, IndexType row, IndexType col, TSubBlock& subBlock)
Expand All @@ -263,39 +228,4 @@ class matrix_bloc_traits < double, IndexType >
static const std::string Name() { return sofa::type::TypeTrait<Real>::name(); }
};

template <typename IndexType>
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<class TSubBlock, std::enable_if_t<std::is_scalar_v<TSubBlock>, 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<NL, IndexType>::split(index, modulo); }
static void split_col_index(int& index, int& modulo) { bloc_index_func<NC, IndexType>::split(index, modulo); }

static sofa::linearalgebra::BaseMatrix::ElementType getElementType() { return sofa::linearalgebra::BaseMatrix::ELEMENT_INT; }
static const std::string Name() { return sofa::type::TypeTrait<Real>::name(); }
};


} // namespace sofa::linearalgebra
Loading