Fix g++-6 constexpr and c++20 constexpr build errors.

This commit is contained in:
Antonio Sánchez 2022-09-09 03:41:45 +00:00 committed by Rasmus Munk Larsen
parent ec9c7163a3
commit fb212c745d
4 changed files with 26 additions and 31 deletions

View File

@ -218,7 +218,7 @@ struct copy_using_evaluator_DefaultTraversal_CompleteUnrolling
template<typename Kernel, int Stop> template<typename Kernel, int Stop>
struct copy_using_evaluator_DefaultTraversal_CompleteUnrolling<Kernel, Stop, Stop> struct copy_using_evaluator_DefaultTraversal_CompleteUnrolling<Kernel, Stop, Stop>
{ {
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel&) { } EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel&) { }
}; };
template<typename Kernel, int Index_, int Stop> template<typename Kernel, int Index_, int Stop>
@ -287,7 +287,7 @@ struct copy_using_evaluator_innervec_CompleteUnrolling
template<typename Kernel, int Stop> template<typename Kernel, int Stop>
struct copy_using_evaluator_innervec_CompleteUnrolling<Kernel, Stop, Stop> struct copy_using_evaluator_innervec_CompleteUnrolling<Kernel, Stop, Stop>
{ {
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel&) { } EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel&) { }
}; };
template<typename Kernel, int Index_, int Stop, int SrcAlignment, int DstAlignment> template<typename Kernel, int Index_, int Stop, int SrcAlignment, int DstAlignment>
@ -327,7 +327,7 @@ struct dense_assignment_loop;
template<typename Kernel, int Unrolling> template<typename Kernel, int Unrolling>
struct dense_assignment_loop<Kernel, AllAtOnceTraversal, Unrolling> struct dense_assignment_loop<Kernel, AllAtOnceTraversal, Unrolling>
{ {
EIGEN_DEVICE_FUNC static void EIGEN_STRONG_INLINE run(Kernel& /*kernel*/) EIGEN_DEVICE_FUNC static void EIGEN_STRONG_INLINE EIGEN_CONSTEXPR run(Kernel& /*kernel*/)
{ {
EIGEN_STATIC_ASSERT(int(Kernel::DstEvaluatorType::XprType::SizeAtCompileTime) == 0, EIGEN_STATIC_ASSERT(int(Kernel::DstEvaluatorType::XprType::SizeAtCompileTime) == 0,
EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT) EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT)
@ -387,7 +387,7 @@ struct unaligned_dense_assignment_loop
{ {
// if IsAligned = true, then do nothing // if IsAligned = true, then do nothing
template <typename Kernel> template <typename Kernel>
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel&, Index, Index) {} EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel&, Index, Index) {}
}; };
template <> template <>
@ -403,7 +403,7 @@ struct unaligned_dense_assignment_loop<false>
Index end) Index end)
#else #else
template <typename Kernel> template <typename Kernel>
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel, EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel &kernel,
Index start, Index start,
Index end) Index end)
#endif #endif
@ -416,7 +416,7 @@ struct unaligned_dense_assignment_loop<false>
template<typename Kernel> template<typename Kernel>
struct dense_assignment_loop<Kernel, LinearVectorizedTraversal, NoUnrolling> struct dense_assignment_loop<Kernel, LinearVectorizedTraversal, NoUnrolling>
{ {
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel) EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel &kernel)
{ {
const Index size = kernel.size(); const Index size = kernel.size();
typedef typename Kernel::Scalar Scalar; typedef typename Kernel::Scalar Scalar;
@ -444,7 +444,7 @@ struct dense_assignment_loop<Kernel, LinearVectorizedTraversal, NoUnrolling>
template<typename Kernel> template<typename Kernel>
struct dense_assignment_loop<Kernel, LinearVectorizedTraversal, CompleteUnrolling> struct dense_assignment_loop<Kernel, LinearVectorizedTraversal, CompleteUnrolling>
{ {
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel) EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel &kernel)
{ {
typedef typename Kernel::DstEvaluatorType::XprType DstXprType; typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
typedef typename Kernel::PacketType PacketType; typedef typename Kernel::PacketType PacketType;
@ -470,7 +470,7 @@ struct dense_assignment_loop<Kernel, InnerVectorizedTraversal, NoUnrolling>
SrcAlignment = Kernel::AssignmentTraits::SrcAlignment, SrcAlignment = Kernel::AssignmentTraits::SrcAlignment,
DstAlignment = Kernel::AssignmentTraits::DstAlignment DstAlignment = Kernel::AssignmentTraits::DstAlignment
}; };
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel) EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel &kernel)
{ {
const Index innerSize = kernel.innerSize(); const Index innerSize = kernel.innerSize();
const Index outerSize = kernel.outerSize(); const Index outerSize = kernel.outerSize();
@ -512,7 +512,7 @@ struct dense_assignment_loop<Kernel, InnerVectorizedTraversal, InnerUnrolling>
template<typename Kernel> template<typename Kernel>
struct dense_assignment_loop<Kernel, LinearTraversal, NoUnrolling> struct dense_assignment_loop<Kernel, LinearTraversal, NoUnrolling>
{ {
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel) EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel &kernel)
{ {
const Index size = kernel.size(); const Index size = kernel.size();
for(Index i = 0; i < size; ++i) for(Index i = 0; i < size; ++i)
@ -523,7 +523,7 @@ struct dense_assignment_loop<Kernel, LinearTraversal, NoUnrolling>
template<typename Kernel> template<typename Kernel>
struct dense_assignment_loop<Kernel, LinearTraversal, CompleteUnrolling> struct dense_assignment_loop<Kernel, LinearTraversal, CompleteUnrolling>
{ {
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel) EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel &kernel)
{ {
typedef typename Kernel::DstEvaluatorType::XprType DstXprType; typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
copy_using_evaluator_LinearTraversal_CompleteUnrolling<Kernel, 0, DstXprType::SizeAtCompileTime>::run(kernel); copy_using_evaluator_LinearTraversal_CompleteUnrolling<Kernel, 0, DstXprType::SizeAtCompileTime>::run(kernel);
@ -537,7 +537,7 @@ struct dense_assignment_loop<Kernel, LinearTraversal, CompleteUnrolling>
template<typename Kernel> template<typename Kernel>
struct dense_assignment_loop<Kernel, SliceVectorizedTraversal, NoUnrolling> struct dense_assignment_loop<Kernel, SliceVectorizedTraversal, NoUnrolling>
{ {
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel) EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel &kernel)
{ {
typedef typename Kernel::Scalar Scalar; typedef typename Kernel::Scalar Scalar;
typedef typename Kernel::PacketType PacketType; typedef typename Kernel::PacketType PacketType;
@ -585,7 +585,7 @@ struct dense_assignment_loop<Kernel, SliceVectorizedTraversal, NoUnrolling>
template<typename Kernel> template<typename Kernel>
struct dense_assignment_loop<Kernel, SliceVectorizedTraversal, InnerUnrolling> struct dense_assignment_loop<Kernel, SliceVectorizedTraversal, InnerUnrolling>
{ {
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel) EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel &kernel)
{ {
typedef typename Kernel::DstEvaluatorType::XprType DstXprType; typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
typedef typename Kernel::PacketType PacketType; typedef typename Kernel::PacketType PacketType;
@ -767,7 +767,7 @@ void resize_if_allowed(DstXprType &dst, const SrcXprType& src, const internal::a
} }
template<typename DstXprType, typename SrcXprType, typename Functor> template<typename DstXprType, typename SrcXprType, typename Functor>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_dense_assignment_loop(DstXprType& dst, const SrcXprType& src, const Functor &func) EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void call_dense_assignment_loop(DstXprType& dst, const SrcXprType& src, const Functor &func)
{ {
typedef evaluator<DstXprType> DstEvaluatorType; typedef evaluator<DstXprType> DstEvaluatorType;
typedef evaluator<SrcXprType> SrcEvaluatorType; typedef evaluator<SrcXprType> SrcEvaluatorType;
@ -845,7 +845,7 @@ void call_assignment(const Dst& dst, const Src& src)
// Deal with "assume-aliasing" // Deal with "assume-aliasing"
template<typename Dst, typename Src, typename Func> template<typename Dst, typename Src, typename Func>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
void call_assignment(Dst& dst, const Src& src, const Func& func, std::enable_if_t< evaluator_assume_aliasing<Src>::value, void*> = 0) void call_assignment(Dst& dst, const Src& src, const Func& func, std::enable_if_t< evaluator_assume_aliasing<Src>::value, void*> = 0)
{ {
typename plain_matrix_type<Src>::type tmp(src); typename plain_matrix_type<Src>::type tmp(src);
@ -862,7 +862,7 @@ void call_assignment(Dst& dst, const Src& src, const Func& func, std::enable_if_
// by-pass "assume-aliasing" // by-pass "assume-aliasing"
// When there is no aliasing, we require that 'dst' has been properly resized // When there is no aliasing, we require that 'dst' has been properly resized
template<typename Dst, template <typename> class StorageBase, typename Src, typename Func> template<typename Dst, template <typename> class StorageBase, typename Src, typename Func>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
void call_assignment(NoAlias<Dst,StorageBase>& dst, const Src& src, const Func& func) void call_assignment(NoAlias<Dst,StorageBase>& dst, const Src& src, const Func& func)
{ {
call_assignment_no_alias(dst.expression(), src, func); call_assignment_no_alias(dst.expression(), src, func);
@ -870,7 +870,7 @@ void call_assignment(NoAlias<Dst,StorageBase>& dst, const Src& src, const Func&
template<typename Dst, typename Src, typename Func> template<typename Dst, typename Src, typename Func>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
void call_assignment_no_alias(Dst& dst, const Src& src, const Func& func) void call_assignment_no_alias(Dst& dst, const Src& src, const Func& func)
{ {
enum { enum {
@ -912,14 +912,14 @@ void call_restricted_packet_assignment_no_alias(Dst& dst, const Src& src, const
} }
template<typename Dst, typename Src> template<typename Dst, typename Src>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
void call_assignment_no_alias(Dst& dst, const Src& src) void call_assignment_no_alias(Dst& dst, const Src& src)
{ {
call_assignment_no_alias(dst, src, internal::assign_op<typename Dst::Scalar,typename Src::Scalar>()); call_assignment_no_alias(dst, src, internal::assign_op<typename Dst::Scalar,typename Src::Scalar>());
} }
template<typename Dst, typename Src, typename Func> template<typename Dst, typename Src, typename Func>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
void call_assignment_no_alias_no_transpose(Dst& dst, const Src& src, const Func& func) void call_assignment_no_alias_no_transpose(Dst& dst, const Src& src, const Func& func)
{ {
// TODO check whether this is the right place to perform these checks: // TODO check whether this is the right place to perform these checks:
@ -930,7 +930,7 @@ void call_assignment_no_alias_no_transpose(Dst& dst, const Src& src, const Func&
Assignment<Dst,Src,Func>::run(dst, src, func); Assignment<Dst,Src,Func>::run(dst, src, func);
} }
template<typename Dst, typename Src> template<typename Dst, typename Src>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
void call_assignment_no_alias_no_transpose(Dst& dst, const Src& src) void call_assignment_no_alias_no_transpose(Dst& dst, const Src& src)
{ {
call_assignment_no_alias_no_transpose(dst, src, internal::assign_op<typename Dst::Scalar,typename Src::Scalar>()); call_assignment_no_alias_no_transpose(dst, src, internal::assign_op<typename Dst::Scalar,typename Src::Scalar>());

View File

@ -200,8 +200,7 @@ struct redux_impl<Func, Evaluator, DefaultTraversal, NoUnrolling>
Scalar run(const Evaluator &eval, const Func& func, const XprType& xpr) Scalar run(const Evaluator &eval, const Func& func, const XprType& xpr)
{ {
eigen_assert(xpr.rows()>0 && xpr.cols()>0 && "you are using an empty matrix"); eigen_assert(xpr.rows()>0 && xpr.cols()>0 && "you are using an empty matrix");
Scalar res; Scalar res = eval.coeffByOuterInner(0, 0);
res = eval.coeffByOuterInner(0, 0);
for(Index i = 1; i < xpr.innerSize(); ++i) for(Index i = 1; i < xpr.innerSize(); ++i)
res = func(res, eval.coeffByOuterInner(0, i)); res = func(res, eval.coeffByOuterInner(0, i));
for(Index i = 1; i < xpr.outerSize(); ++i) for(Index i = 1; i < xpr.outerSize(); ++i)

View File

@ -5,15 +5,12 @@
using namespace Eigen; using namespace Eigen;
inline void error_if_not_constexpr() {} // not constexpr template<int Blah>
#if EIGEN_COMP_CXXVER >= 20 struct AssertConstexpr {};
consteval #define assert_constexpr(expr) \
#else do { \
constexpr (void) AssertConstexpr<(expr, 1)>(); \
#endif } while (false)
void assert_constexpr(bool b) {
if (!b) error_if_not_constexpr();
}
constexpr bool zeroSized() constexpr bool zeroSized()
{ {

View File

@ -13,7 +13,6 @@
template<typename MatrixType> void inverse_permutation_4x4() template<typename MatrixType> void inverse_permutation_4x4()
{ {
typedef typename MatrixType::Scalar Scalar;
Vector4i indices(0,1,2,3); Vector4i indices(0,1,2,3);
for(int i = 0; i < 24; ++i) for(int i = 0; i < 24; ++i)
{ {