determinant calculation with SIMD

2019-05-08 03:34发布

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.

标签: sse simd neon
1条回答
迷人小祖宗
2楼-- · 2019-05-08 04:32

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.

查看更多
登录 后发表回答