mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-12 03:39:01 +08:00
bug #1736: fix compilation issue with A(all,{1,2}).col(j) by implementing true compile-time "if" for block_evaluator<>::coeff(i)/coeffRef(i)
This commit is contained in:
parent
031f17117d
commit
747c6a51ca
@ -1118,11 +1118,8 @@ struct unary_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel>, IndexBa
|
|||||||
|
|
||||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||||
CoeffReturnType coeff(Index index) const
|
CoeffReturnType coeff(Index index) const
|
||||||
{
|
{
|
||||||
if (ForwardLinearAccess)
|
return linear_coeff_impl(index, bool_constant<ForwardLinearAccess>());
|
||||||
return m_argImpl.coeff(m_linear_offset.value() + index);
|
|
||||||
else
|
|
||||||
return coeff(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||||
@ -1133,11 +1130,8 @@ struct unary_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel>, IndexBa
|
|||||||
|
|
||||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||||
Scalar& coeffRef(Index index)
|
Scalar& coeffRef(Index index)
|
||||||
{
|
{
|
||||||
if (ForwardLinearAccess)
|
return linear_coeffRef_impl(index, bool_constant<ForwardLinearAccess>());
|
||||||
return m_argImpl.coeffRef(m_linear_offset.value() + index);
|
|
||||||
else
|
|
||||||
return coeffRef(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<int LoadMode, typename PacketType>
|
template<int LoadMode, typename PacketType>
|
||||||
@ -1178,6 +1172,28 @@ struct unary_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel>, IndexBa
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||||
|
CoeffReturnType linear_coeff_impl(Index index, internal::true_type /* ForwardLinearAccess */) const
|
||||||
|
{
|
||||||
|
return m_argImpl.coeff(m_linear_offset.value() + index);
|
||||||
|
}
|
||||||
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||||
|
CoeffReturnType linear_coeff_impl(Index index, internal::false_type /* not ForwardLinearAccess */) const
|
||||||
|
{
|
||||||
|
return coeff(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||||
|
Scalar& linear_coeffRef_impl(Index index, internal::true_type /* ForwardLinearAccess */)
|
||||||
|
{
|
||||||
|
return m_argImpl.coeffRef(m_linear_offset.value() + index);
|
||||||
|
}
|
||||||
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||||
|
Scalar& linear_coeffRef_impl(Index index, internal::false_type /* not ForwardLinearAccess */)
|
||||||
|
{
|
||||||
|
return coeffRef(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0);
|
||||||
|
}
|
||||||
|
|
||||||
evaluator<ArgType> m_argImpl;
|
evaluator<ArgType> m_argImpl;
|
||||||
const variable_if_dynamic<Index, (ArgType::RowsAtCompileTime == 1 && BlockRows==1) ? 0 : Dynamic> m_startRow;
|
const variable_if_dynamic<Index, (ArgType::RowsAtCompileTime == 1 && BlockRows==1) ? 0 : Dynamic> m_startRow;
|
||||||
const variable_if_dynamic<Index, (ArgType::ColsAtCompileTime == 1 && BlockCols==1) ? 0 : Dynamic> m_startCol;
|
const variable_if_dynamic<Index, (ArgType::ColsAtCompileTime == 1 && BlockCols==1) ? 0 : Dynamic> m_startCol;
|
||||||
|
@ -63,6 +63,15 @@ typedef std::size_t UIntPtr;
|
|||||||
struct true_type { enum { value = 1 }; };
|
struct true_type { enum { value = 1 }; };
|
||||||
struct false_type { enum { value = 0 }; };
|
struct false_type { enum { value = 0 }; };
|
||||||
|
|
||||||
|
template<bool Condition>
|
||||||
|
struct bool_constant;
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct bool_constant<true> : true_type {};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct bool_constant<false> : false_type {};
|
||||||
|
|
||||||
template<bool Condition, typename Then, typename Else>
|
template<bool Condition, typename Then, typename Else>
|
||||||
struct conditional { typedef Then type; };
|
struct conditional { typedef Then type; };
|
||||||
|
|
||||||
|
@ -419,6 +419,12 @@ void check_indexed_view()
|
|||||||
VERIFY_IS_EQUAL( A3(ind,ind).eval(), MatrixXi::Constant(5,5,A3(1,1)) );
|
VERIFY_IS_EQUAL( A3(ind,ind).eval(), MatrixXi::Constant(5,5,A3(1,1)) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Regression for bug 1736
|
||||||
|
{
|
||||||
|
VERIFY_IS_APPROX(A(all, eii).col(0).eval(), A.col(eii(0)));
|
||||||
|
A(all, eii).col(0) = A.col(eii(0));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EIGEN_DECLARE_TEST(indexed_view)
|
EIGEN_DECLARE_TEST(indexed_view)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user