From be20207d108a9d74d62bfe3e7d8680a17483551e Mon Sep 17 00:00:00 2001 From: Arthur Date: Mon, 8 Aug 2022 19:29:56 +0000 Subject: [PATCH] Fix vectorized Jacobi Rotation --- Eigen/src/Jacobi/Jacobi.h | 23 +++++++++++++---------- test/jacobi.cpp | 5 +++++ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Eigen/src/Jacobi/Jacobi.h b/Eigen/src/Jacobi/Jacobi.h index 852a38533..5d9698990 100644 --- a/Eigen/src/Jacobi/Jacobi.h +++ b/Eigen/src/Jacobi/Jacobi.h @@ -344,15 +344,18 @@ struct apply_rotation_in_the_plane_selector::size, - OtherPacketSize = packet_traits::size - }; typedef typename packet_traits::type Packet; typedef typename packet_traits::type OtherPacket; + enum { + RequiredAlignment = plain_enum_max(unpacket_traits::alignment, + unpacket_traits::alignment), + PacketSize = packet_traits::size, + OtherPacketSize = packet_traits::size + }; + /*** dynamic-size vectorized paths ***/ - if(SizeAtCompileTime == Dynamic && ((incrx==1 && incry==1) || PacketSize == 1)) + if(size >= 2 * PacketSize && SizeAtCompileTime == Dynamic && ((incrx == 1 && incry == 1) || PacketSize == 1)) { // both vectors are sequentially stored in memory => vectorization enum { Peeling = 2 }; @@ -423,11 +426,11 @@ struct apply_rotation_in_the_plane_selector0) // FIXME should be compared to the required alignment + else if(SizeAtCompileTime != Dynamic && MinAlignment >= RequiredAlignment) { const OtherPacket pc = pset1(c); const OtherPacket ps = pset1(s); - conj_helper::IsComplex,false> pcj; + conj_helper::IsComplex,false> pcj; conj_helper pm; Scalar* EIGEN_RESTRICT px = x; Scalar* EIGEN_RESTRICT py = y; @@ -452,11 +455,11 @@ struct apply_rotation_in_the_plane_selector EIGEN_DEVICE_FUNC -void /*EIGEN_DONT_INLINE*/ apply_rotation_in_the_plane(DenseBase& xpr_x, DenseBase& xpr_y, const JacobiRotation& j) +void inline apply_rotation_in_the_plane(DenseBase& xpr_x, DenseBase& xpr_y, const JacobiRotation& j) { typedef typename VectorX::Scalar Scalar; - const bool Vectorizable = (int(VectorX::Flags) & int(VectorY::Flags) & PacketAccessBit) - && (int(packet_traits::size) == int(packet_traits::size)); + constexpr bool Vectorizable = (int(evaluator::Flags) & int(evaluator::Flags) & PacketAccessBit) && + (int(packet_traits::size) == int(packet_traits::size)); eigen_assert(xpr_x.size() == xpr_y.size()); Index size = xpr_x.size(); diff --git a/test/jacobi.cpp b/test/jacobi.cpp index 5604797f5..273b94df8 100644 --- a/test/jacobi.cpp +++ b/test/jacobi.cpp @@ -65,6 +65,11 @@ EIGEN_DECLARE_TEST(jacobi) CALL_SUBTEST_3(( jacobi() )); CALL_SUBTEST_3(( jacobi >() )); + CALL_SUBTEST_1(( jacobi, float>() )); + CALL_SUBTEST_2(( jacobi, double>() )); + CALL_SUBTEST_3(( jacobi, 4, 4, RowMajor>, float>() )); + CALL_SUBTEST_3(( jacobi, 4, 4, RowMajor>, std::complex >() )); + int r = internal::random(2, internal::random(1,EIGEN_TEST_MAX_SIZE)/2), c = internal::random(2, internal::random(1,EIGEN_TEST_MAX_SIZE)/2); CALL_SUBTEST_4(( jacobi(MatrixXf(r,c)) ));