Does there exist an approach for calculating the determinant of matrices with low dimensions (about 4), that works well with SIMD (neon, SSE, SSE2)? I am using a hand-expansion formula, which does not work so well. I am using SSE all the way to SSE3 and neon, both under linux. The matrix elements are all floats.
Here's my 5 cents.
determinant of a 2x2 matrix:
that's an exercise for the reader, should be simple to implement
determinant of a 3x3 matrix:
use the scalar triple product. This will require smart cross()
and dot()
implementations. The recipes for these are widely available.
determinant of a 4x4 matrix:
Use one of the tricks in here. My code:
template <class T>
inline T det(matrix<T, 4, 4> const& m) noexcept
{
auto const A(make_matrix<T, 2, 2>(m(0, 0), m(0, 1), m(1, 0), m(1, 1)));
auto const B(make_matrix<T, 2, 2>(m(0, 2), m(0, 3), m(1, 2), m(1, 3)));
auto const C(make_matrix<T, 2, 2>(m(2, 0), m(2, 1), m(3, 0), m(3, 1)));
auto const D(make_matrix<T, 2, 2>(m(2, 2), m(2, 3), m(3, 2), m(3, 3)));
return det(A - B * inv(D) * C) * det(D);
}
determinant of a 5x5+ matrix:
probably use the tricks above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With