determinant calculation with SIMD

这一生的挚爱 提交于 2019-12-07 09:23:33

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/29991373/determinant-calculation-with-simd

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!