Skip to content
Snippets Groups Projects
Commit 475b73d7 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Few clean-up in TinyMatrix

Now det for arbitrary dimension is only available to floating point
types.
parent 9937b14f
No related branches found
No related tags found
No related merge requests found
......@@ -99,6 +99,21 @@ public:
return os;
}
KOKKOS_INLINE_FUNCTION
bool operator==(const TinyMatrix& A) const
{
for (size_t i=0; i<N*N; ++i) {
if (m_values[i] != A.m_values[i]) return false;
}
return true;
}
KOKKOS_INLINE_FUNCTION
bool operator!=(const TinyMatrix& A) const
{
return not this->operator==(A);
}
KOKKOS_INLINE_FUNCTION
TinyMatrix operator+(const TinyMatrix& A) const
{
......@@ -174,7 +189,7 @@ public:
}
KOKKOS_INLINE_FUNCTION
const TinyMatrix& operator=(const TinyMatrix& A)
TinyMatrix& operator=(const TinyMatrix& A)
{
for (size_t i=0; i<N*N; ++i) {
m_values[i] = A.m_values[i];
......@@ -194,10 +209,7 @@ public:
}
KOKKOS_INLINE_FUNCTION
TinyMatrix()
{
;
}
TinyMatrix()=default;
KOKKOS_INLINE_FUNCTION
TinyMatrix(const ZeroType& z)
......@@ -231,10 +243,7 @@ public:
TinyMatrix(TinyMatrix&& A) = default;
KOKKOS_INLINE_FUNCTION
~TinyMatrix()
{
;
}
~TinyMatrix()=default;
};
template <size_t N, typename T>
......@@ -256,17 +265,18 @@ KOKKOS_INLINE_FUNCTION
T det(const TinyMatrix<N,T>& A)
{
static_assert(std::is_arithmetic<T>::value, "determinent is not defined for non arithmetic types");
static_assert(std::is_floating_point<T>::value, "determinent for arbitrary dimension N is defined for floating point types only");
TinyMatrix<N,T> M = A;
TinyVector<N, int> index;
for (int i=0; i<N; ++i) index[i]=i;
TinyVector<N, size_t> index;
for (size_t i=0; i<N; ++i) index[i]=i;
T determinent = 1;
for (int i=0; i<N; ++i) {
for (int j=i; j<N; ++j) {
int l = j;
const int J = index[j];
for (int k=j+1; k<N; ++k) {
for (size_t i=0; i<N; ++i) {
for (size_t j=i; j<N; ++j) {
size_t l = j;
const size_t J = index[j];
for (size_t k=j+1; k<N; ++k) {
if (std::abs(M(index[k],i)) > std::abs(M(J,i))) {
l=k;
}
......@@ -276,19 +286,19 @@ T det(const TinyMatrix<N,T>& A)
determinent *= -1;
}
}
const int I = index[i];
const size_t I = index[i];
if (M(I,i)==0) return 0;
double inv_Mii = 1./M(I,i);
for (int k=i+1; k<N; ++k) {
const int K = index[k];
const T inv_Mii = 1./M(I,i);
for (size_t k=i+1; k<N; ++k) {
const size_t K = index[k];
const T factor = M(K,i)*inv_Mii;
for (int l=i+1; l<N; ++l) {
for (size_t l=i+1; l<N; ++l) {
M(K,l) -= factor*M(I,l);
}
}
}
for (int i=0; i<N; ++i) {
for (size_t i=0; i<N; ++i) {
determinent *= M(index[i],i);
}
return determinent;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment