mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Add support for RowOrder reshaped
This commit is contained in:
@@ -21,7 +21,7 @@ namespace Eigen {
|
||||
* \tparam XprType the type of the expression in which we are taking a reshape
|
||||
* \tparam Rows the number of rows of the reshape we are taking at compile time (optional)
|
||||
* \tparam Cols the number of columns of the reshape we are taking at compile time (optional)
|
||||
* \tparam Order
|
||||
* \tparam Order can be ColMajor or RowMajor, default is ColMajor.
|
||||
*
|
||||
* This class represents an expression of either a fixed-size or dynamic-size reshape.
|
||||
* It is the return type of DenseBase::reshaped(NRowsType,NColsType) and
|
||||
@@ -68,9 +68,8 @@ struct traits<Reshaped<XprType, Rows, Cols, Order> > : traits<XprType>
|
||||
: Dynamic,
|
||||
OuterStrideAtCompileTime = Dynamic,
|
||||
|
||||
InOrder = Order,
|
||||
HasDirectAccess = internal::has_direct_access<XprType>::ret
|
||||
&& (Order==int(AutoOrderValue) || Order==int(XpxStorageOrder))
|
||||
&& (Order==int(XpxStorageOrder))
|
||||
&& ((evaluator<XprType>::Flags&LinearAccessBit)==LinearAccessBit),
|
||||
|
||||
MaskPacketAccessBit = (InnerSize == Dynamic || (InnerSize % packet_traits<Scalar>::size) == 0)
|
||||
@@ -324,11 +323,20 @@ struct reshaped_evaluator<ArgType, Rows, Cols, Order, /* HasDirectAccess */ fals
|
||||
|
||||
typedef std::pair<Index, Index> RowCol;
|
||||
|
||||
inline RowCol index_remap(Index rowId, Index colId) const {
|
||||
const Index nth_elem_idx = colId * m_xpr.rows() + rowId;
|
||||
const Index actual_col = nth_elem_idx / m_xpr.nestedExpression().rows();
|
||||
const Index actual_row = nth_elem_idx % m_xpr.nestedExpression().rows();
|
||||
return RowCol(actual_row, actual_col);
|
||||
inline RowCol index_remap(Index rowId, Index colId) const
|
||||
{
|
||||
if(Order==ColMajor)
|
||||
{
|
||||
const Index nth_elem_idx = colId * m_xpr.rows() + rowId;
|
||||
return RowCol(nth_elem_idx % m_xpr.nestedExpression().rows(),
|
||||
nth_elem_idx / m_xpr.nestedExpression().rows());
|
||||
}
|
||||
else
|
||||
{
|
||||
const Index nth_elem_idx = colId + rowId * m_xpr.cols();
|
||||
return RowCol(nth_elem_idx / m_xpr.nestedExpression().cols(),
|
||||
nth_elem_idx % m_xpr.nestedExpression().cols());
|
||||
}
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
|
||||
@@ -40,10 +40,12 @@ reshaped(NRowsType nRows, NColsType nCols)
|
||||
|
||||
template<typename NRowsType, typename NColsType, typename OrderType>
|
||||
EIGEN_DEVICE_FUNC
|
||||
inline Reshaped<Derived,internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value,OrderType::value>
|
||||
inline Reshaped<Derived,internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value,
|
||||
OrderType::value==AutoOrderValue?Flags&RowMajorBit:OrderType::value>
|
||||
reshaped(NRowsType nRows, NColsType nCols, OrderType)
|
||||
{
|
||||
return Reshaped<Derived,internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value,OrderType::value>(
|
||||
return Reshaped<Derived,internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value,
|
||||
OrderType::value==AutoOrderValue?Flags&RowMajorBit:OrderType::value>(
|
||||
derived(), internal::get_runtime_value(nRows), internal::get_runtime_value(nCols));
|
||||
}
|
||||
|
||||
@@ -59,10 +61,12 @@ reshaped(NRowsType nRows, NColsType nCols) const
|
||||
|
||||
template<typename NRowsType, typename NColsType, typename OrderType>
|
||||
EIGEN_DEVICE_FUNC
|
||||
inline const Reshaped<const Derived,internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value,OrderType::value>
|
||||
inline const Reshaped<const Derived,internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value,
|
||||
OrderType::value==AutoOrderValue?Flags&RowMajorBit:OrderType::value>
|
||||
reshaped(NRowsType nRows, NColsType nCols, OrderType) const
|
||||
{
|
||||
return Reshaped<const Derived,internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value,OrderType::value>(
|
||||
return Reshaped<const Derived,internal::get_fixed_value<NRowsType>::value,internal::get_fixed_value<NColsType>::value,
|
||||
OrderType::value==AutoOrderValue?Flags&RowMajorBit:OrderType::value>(
|
||||
derived(), internal::get_runtime_value(nRows), internal::get_runtime_value(nCols));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user