9 template <
typename T,
int N>
10 MUDA_INLINE MUDA_GENERIC Eigen::Matrix<T, N, N> operator()(
const Eigen::Matrix<T, N, N>& input)
12 Eigen::Matrix<T, N, N> result;
14 constexpr auto eps = std::numeric_limits<T>::epsilon();
15 constexpr int dim = N;
17 for(
int i = 0; i < dim; i++)
19 for(
int j = 0; j < 2 * dim; j++)
23 mat[i][j] = input(i, j);
27 mat[i][j] = j - dim == i ? 1 : 0;
32 for(
int i = 0; i < dim; i++)
34 if(abs(mat[i][i]) < eps)
37 for(j = i + 1; j < dim; j++)
39 if(abs(mat[j][i]) > eps)
44 for(
int r = i; r < 2 * dim; r++)
46 mat[i][r] += mat[j][r];
50 for(
int r = i; r < 2 * dim; r++)
55 for(
int j = i + 1; j < dim; j++)
57 T e = -1 * (mat[j][i] / mat[i][i]);
58 for(
int r = i; r < 2 * dim; r++)
60 mat[j][r] += e * mat[i][r];
65 for(
int i = dim - 1; i >= 0; i--)
67 for(
int j = i - 1; j >= 0; j--)
69 T e = -1 * (mat[j][i] / mat[i][i]);
70 for(
int r = i; r < 2 * dim; r++)
72 mat[j][r] += e * mat[i][r];
78 for(
int i = 0; i < dim; i++)
80 for(
int r = dim; r < 2 * dim; r++)
82 result(i, r - dim) = mat[i][r];