diff options
author | Antonio Sanchez <cantonios@google.com> | 2021-01-06 13:14:20 -0800 |
---|---|---|
committer | Antonio Sanchez <cantonios@google.com> | 2021-01-06 13:14:20 -0800 |
commit | 52d1dd979af688fbf67c34860527b3a4295b7936 (patch) | |
tree | 07ac335c1d7905313424fba531b3495cbe50bdf0 /Eigen/src/Core/Ref.h | |
parent | 166fcdecdb9178fe7f3eea38f67fb3f5848a4ae2 (diff) |
Fix Ref initialization.
Since `eigen_assert` is a macro, the statements can become noops (e.g.
when compiling for GPU), so they may not execute the contained logic -- which
in this case is the entire `Ref` construction. We need to separate the assert
from statements which have consequences.
Fixes #2113
Diffstat (limited to 'Eigen/src/Core/Ref.h')
-rw-r--r-- | Eigen/src/Core/Ref.h | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Eigen/src/Core/Ref.h b/Eigen/src/Core/Ref.h index 00aa45d34..9fca42873 100644 --- a/Eigen/src/Core/Ref.h +++ b/Eigen/src/Core/Ref.h @@ -94,7 +94,7 @@ protected: typedef Stride<StrideType::OuterStrideAtCompileTime,StrideType::InnerStrideAtCompileTime> StrideBase; // Resolves inner stride if default 0. - static Index resolveInnerStride(Index inner) { + static EIGEN_DEVICE_FUNC Index resolveInnerStride(Index inner) { if (inner == 0) { return 1; } @@ -102,7 +102,7 @@ protected: } // Resolves outer stride if default 0. - static Index resolveOuterStride(Index inner, Index outer, Index rows, Index cols, bool isVectorAtCompileTime, bool isRowMajor) { + static EIGEN_DEVICE_FUNC Index resolveOuterStride(Index inner, Index outer, Index rows, Index cols, bool isVectorAtCompileTime, bool isRowMajor) { if (outer == 0) { if (isVectorAtCompileTime) { outer = inner * rows * cols; @@ -311,7 +311,9 @@ template<typename PlainObjectType, int Options, typename StrideType> class Ref { EIGEN_STATIC_ASSERT(bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH); // Construction must pass since we will not create temprary storage in the non-const case. - eigen_assert(Base::construct(expr.derived())); + const bool success = Base::construct(expr.derived()); + EIGEN_UNUSED_VARIABLE(success) + eigen_assert(success); } template<typename Derived> EIGEN_DEVICE_FUNC inline Ref(const DenseBase<Derived>& expr, @@ -326,7 +328,9 @@ template<typename PlainObjectType, int Options, typename StrideType> class Ref EIGEN_STATIC_ASSERT(bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH); EIGEN_STATIC_ASSERT(!Derived::IsPlainObjectBase,THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY); // Construction must pass since we will not create temporary storage in the non-const case. - eigen_assert(Base::construct(expr.const_cast_derived())); + const bool success = Base::construct(expr.const_cast_derived()); + EIGEN_UNUSED_VARIABLE(success) + eigen_assert(success); } EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Ref) |