SIMD 行列式计算 [英] determinant calculation with SIMD
问题描述
是否存在一种计算低维(约 4)矩阵行列式的方法,该方法适用于 SIMD(霓虹灯、SSE、SSE2)?我正在使用手动膨胀公式,但效果不佳.我在 linux 下一直使用 SSE 到 SSE3 和霓虹灯.矩阵元素都是浮点数.
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.
推荐答案
这是我的 5 美分.
2x2 矩阵的行列式:
determinant of a 2x2 matrix:
这是给读者的练习,应该很容易实现
that's an exercise for the reader, should be simple to implement
3x3 矩阵的行列式:
determinant of a 3x3 matrix:
使用标量三重积.这将需要智能的 cross()
和 dot()
实现.这些食谱随处可见.
use the scalar triple product. This will require smart cross()
and dot()
implementations. The recipes for these are widely available.
4x4 矩阵的行列式:
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);
}
5x5+ 矩阵的行列式:
determinant of a 5x5+ matrix:
可能使用上面的技巧.
这篇关于SIMD 行列式计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!