13 #ifndef EIGEN_COREEVALUATORS_H
14 #define EIGEN_COREEVALUATORS_H
22 template<
typename StorageKind>
83 template<typename T, typename Shape = typename evaluator_traits<T>::Shape >
85 static const bool value =
false;
108 template<
typename ExpressionType>
126 template<
typename Derived>
135 IsRowMajor = PlainObjectType::IsRowMajor,
136 IsVectorAtCompileTime = PlainObjectType::IsVectorAtCompileTime,
137 RowsAtCompileTime = PlainObjectType::RowsAtCompileTime,
138 ColsAtCompileTime = PlainObjectType::ColsAtCompileTime,
147 m_outerStride(IsVectorAtCompileTime ? 0
148 :
int(IsRowMajor) ? ColsAtCompileTime
155 : m_data(m.data()), m_outerStride(IsVectorAtCompileTime ? 0 : m.outerStride())
164 return m_data[
row * m_outerStride.value() +
col];
166 return m_data[
row +
col * m_outerStride.value()];
172 return m_data[index];
179 return const_cast<Scalar*
>(m_data)[
row * m_outerStride.value() +
col];
181 return const_cast<Scalar*
>(m_data)[
row +
col * m_outerStride.value()];
187 return const_cast<Scalar*
>(m_data)[index];
190 template<
int LoadMode,
typename PacketType>
195 return ploadt<PacketType, LoadMode>(m_data +
row * m_outerStride.value() +
col);
197 return ploadt<PacketType, LoadMode>(m_data +
row +
col * m_outerStride.value());
200 template<
int LoadMode,
typename PacketType>
204 return ploadt<PacketType, LoadMode>(m_data + index);
207 template<
int StoreMode,
typename PacketType>
212 return pstoret<Scalar, PacketType, StoreMode>
213 (
const_cast<Scalar*
>(m_data) +
row * m_outerStride.value() +
col,
x);
215 return pstoret<Scalar, PacketType, StoreMode>
216 (
const_cast<Scalar*
>(m_data) +
row +
col * m_outerStride.value(),
x);
219 template<
int StoreMode,
typename PacketType>
223 return pstoret<Scalar, PacketType, StoreMode>(
const_cast<Scalar*
>(m_data) + index,
x);
231 :
int(IsRowMajor) ? ColsAtCompileTime
235 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
237 :
evaluator<PlainObjectBase<Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> > >
248 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
250 :
evaluator<PlainObjectBase<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> > >
263 template<
typename ArgType>
283 return m_argImpl.coeff(
col,
row);
289 return m_argImpl.coeff(index);
295 return m_argImpl.coeffRef(
col,
row);
301 return m_argImpl.coeffRef(index);
304 template<
int LoadMode,
typename PacketType>
308 return m_argImpl.template packet<LoadMode,PacketType>(
col,
row);
311 template<
int LoadMode,
typename PacketType>
315 return m_argImpl.template packet<LoadMode,PacketType>(index);
318 template<
int StoreMode,
typename PacketType>
322 m_argImpl.template writePacket<StoreMode,PacketType>(
col,
row,
x);
325 template<
int StoreMode,
typename PacketType>
329 m_argImpl.template writePacket<StoreMode,PacketType>(index,
x);
340 template<
typename Scalar,
typename NullaryOp,
346 template <
typename IndexType>
348 template <
typename IndexType>
351 template <
typename T,
typename IndexType> EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE T
packetOp(
const NullaryOp& op, IndexType i, IndexType j)
const {
return op.template packetOp<T>(i,j); }
352 template <
typename T,
typename IndexType> EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE T
packetOp(
const NullaryOp& op, IndexType i)
const {
return op.template packetOp<T>(i); }
355 template<
typename Scalar,
typename NullaryOp>
358 template <
typename IndexType>
360 template <
typename T,
typename IndexType> EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE T
packetOp(
const NullaryOp& op, IndexType=0, IndexType=0)
const {
return op.template packetOp<T>(); }
363 template<
typename Scalar,
typename NullaryOp>
366 template <
typename IndexType>
368 template <
typename T,
typename IndexType> EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE T
packetOp(
const NullaryOp& op, IndexType i, IndexType j=0)
const {
return op.template packetOp<T>(i,j); }
374 template<
typename Scalar,
typename NullaryOp>
377 template <
typename IndexType>
384 return op.template packetOp<T>(i+j);
387 template <
typename IndexType>
389 template <
typename T,
typename IndexType>
393 template<
typename Scalar,
typename NullaryOp>
396 #if 0 && EIGEN_COMP_MSVC>0
414 template<
typename T>
struct nullary_wrapper_workaround_msvc {
415 nullary_wrapper_workaround_msvc(
const T&);
419 template<
typename Scalar,
typename NullaryOp>
420 struct nullary_wrapper<
Scalar,NullaryOp,true,true,true>
422 template <
typename IndexType>
424 return nullary_wrapper<
Scalar,NullaryOp,
425 has_nullary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
426 has_unary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
427 has_binary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value>().
operator()(op,i,j);
429 template <
typename IndexType>
431 return nullary_wrapper<
Scalar,NullaryOp,
432 has_nullary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
433 has_unary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
434 has_binary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value>().
operator()(op,i);
437 template <
typename T,
typename IndexType>
439 return nullary_wrapper<
Scalar,NullaryOp,
440 has_nullary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
441 has_unary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
442 has_binary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value>().
template packetOp<T>(op,i,j);
444 template <
typename T,
typename IndexType>
446 return nullary_wrapper<
Scalar,NullaryOp,
447 has_nullary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
448 has_unary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
449 has_binary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value>().
template packetOp<T>(op,i);
452 #endif // MSVC workaround
454 template<
typename NullaryOp,
typename PlainObjectType>
473 : m_functor(
n.functor()), m_wrapper()
480 template <
typename IndexType>
484 return m_wrapper(m_functor,
row,
col);
487 template <
typename IndexType>
491 return m_wrapper(m_functor,index);
494 template<
int LoadMode,
typename PacketType,
typename IndexType>
498 return m_wrapper.template packetOp<PacketType>(m_functor,
row,
col);
501 template<
int LoadMode,
typename PacketType,
typename IndexType>
505 return m_wrapper.template packetOp<PacketType>(m_functor, index);
515 template<
typename UnaryOp,
typename ArgType>
531 : m_functor(op.functor()),
532 m_argImpl(op.nestedExpression())
543 return m_functor(m_argImpl.coeff(
row,
col));
549 return m_functor(m_argImpl.coeff(index));
552 template<
int LoadMode,
typename PacketType>
556 return m_functor.packetOp(m_argImpl.template packet<LoadMode, PacketType>(
row,
col));
559 template<
int LoadMode,
typename PacketType>
563 return m_functor.packetOp(m_argImpl.template packet<LoadMode, PacketType>(index));
574 template<
typename TernaryOp,
typename Arg1,
typename Arg2,
typename Arg3>
584 template<
typename TernaryOp,
typename Arg1,
typename Arg2,
typename Arg3>
598 Flags0 = (
int(Arg1Flags) |
int(Arg2Flags) |
int(Arg3Flags)) & (
600 | (
int(Arg1Flags) &
int(Arg2Flags) &
int(Arg3Flags) &
613 : m_functor(xpr.functor()),
614 m_arg1Impl(xpr.arg1()),
615 m_arg2Impl(xpr.arg2()),
616 m_arg3Impl(xpr.arg3())
627 return m_functor(m_arg1Impl.coeff(
row,
col), m_arg2Impl.coeff(
row,
col), m_arg3Impl.coeff(
row,
col));
633 return m_functor(m_arg1Impl.coeff(index), m_arg2Impl.coeff(index), m_arg3Impl.coeff(index));
636 template<
int LoadMode,
typename PacketType>
640 return m_functor.packetOp(m_arg1Impl.template packet<LoadMode,PacketType>(
row,
col),
641 m_arg2Impl.template packet<LoadMode,PacketType>(
row,
col),
642 m_arg3Impl.template packet<LoadMode,PacketType>(
row,
col));
645 template<
int LoadMode,
typename PacketType>
649 return m_functor.packetOp(m_arg1Impl.template packet<LoadMode,PacketType>(index),
650 m_arg2Impl.template packet<LoadMode,PacketType>(index),
651 m_arg3Impl.template packet<LoadMode,PacketType>(index));
664 template<
typename BinaryOp,
typename Lhs,
typename Rhs>
674 template<
typename BinaryOp,
typename Lhs,
typename Rhs>
687 Flags0 = (
int(LhsFlags) |
int(RhsFlags)) & (
689 | (
int(LhsFlags) &
int(RhsFlags) &
700 : m_functor(xpr.functor()),
701 m_lhsImpl(xpr.lhs()),
713 return m_functor(m_lhsImpl.coeff(
row,
col), m_rhsImpl.coeff(
row,
col));
719 return m_functor(m_lhsImpl.coeff(index), m_rhsImpl.coeff(index));
722 template<
int LoadMode,
typename PacketType>
726 return m_functor.packetOp(m_lhsImpl.template packet<LoadMode,PacketType>(
row,
col),
727 m_rhsImpl.template packet<LoadMode,PacketType>(
row,
col));
730 template<
int LoadMode,
typename PacketType>
734 return m_functor.packetOp(m_lhsImpl.template packet<LoadMode,PacketType>(index),
735 m_rhsImpl.template packet<LoadMode,PacketType>(index));
746 template<
typename UnaryOp,
typename ArgType>
761 : m_unaryOp(op.functor()),
762 m_argImpl(op.nestedExpression())
774 return m_unaryOp(m_argImpl.coeff(
row,
col));
780 return m_unaryOp(m_argImpl.coeff(index));
786 return m_unaryOp(m_argImpl.coeffRef(
row,
col));
792 return m_unaryOp(m_argImpl.coeffRef(index));
804 template<
typename Derived,
typename PlainObjectType>
807 template<
typename Derived,
typename PlainObjectType>
827 PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1);
855 template<
int LoadMode,
typename PacketType>
860 return internal::ploadt<PacketType, LoadMode>(ptr);
863 template<
int LoadMode,
typename PacketType>
870 template<
int StoreMode,
typename PacketType>
875 return internal::pstoret<Scalar, PacketType, StoreMode>(ptr,
x);
878 template<
int StoreMode,
typename PacketType>
895 template<
typename PlainObjectType,
int MapOptions,
typename Str
ideType>
897 :
public mapbase_evaluator<Map<PlainObjectType, MapOptions, StrideType>, PlainObjectType>
905 InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0
906 ?
int(PlainObjectType::InnerStrideAtCompileTime)
907 :
int(StrideType::InnerStrideAtCompileTime),
908 OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0
909 ?
int(PlainObjectType::OuterStrideAtCompileTime)
910 :
int(StrideType::OuterStrideAtCompileTime),
911 HasNoInnerStride = InnerStrideAtCompileTime == 1,
912 HasNoOuterStride = StrideType::OuterStrideAtCompileTime == 0,
913 HasNoStride = HasNoInnerStride && HasNoOuterStride,
914 IsDynamicSize = PlainObjectType::SizeAtCompileTime==
Dynamic,
917 LinearAccessMask = bool(HasNoStride) || bool(PlainObjectType::IsVectorAtCompileTime) ? ~
int(0) : ~
int(
LinearAccessBit),
918 Flags =
int(
evaluator<PlainObjectType>::Flags) & (LinearAccessMask&PacketAccessMask),
930 template<
typename PlainObjectType,
int RefOptions,
typename Str
ideType>
932 :
public mapbase_evaluator<Ref<PlainObjectType, RefOptions, StrideType>, PlainObjectType>
948 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel,
951 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel>
969 IsRowMajor = (MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1) ? 1
970 : (MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1) ? 0
972 HasSameStorageOrderAsArgType = (IsRowMajor == ArgTypeIsRowMajor),
973 InnerSize = IsRowMajor ?
int(ColsAtCompileTime) :
int(RowsAtCompileTime),
974 InnerStrideAtCompileTime = HasSameStorageOrderAsArgType
977 OuterStrideAtCompileTime = HasSameStorageOrderAsArgType
980 MaskPacketAccessBit = (InnerStrideAtCompileTime == 1 || HasSameStorageOrderAsArgType) ?
PacketAccessBit : 0,
986 MaskPacketAccessBit),
987 Flags = Flags0 | FlagsLinearAccessBit | FlagsRowMajorBit,
990 Alignment0 = (InnerPanel && (OuterStrideAtCompileTime!=
Dynamic)
991 && (OuterStrideAtCompileTime!=0)
992 && (((OuterStrideAtCompileTime *
int(sizeof(
Scalar))) %
int(PacketAlignment)) == 0)) ?
int(PacketAlignment) : 0,
1003 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel>
1014 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel>
1016 :
evaluator_base<Block<ArgType, BlockRows, BlockCols, InnerPanel> >
1021 : m_argImpl(
block.nestedExpression()),
1022 m_startRow(
block.startRow()),
1023 m_startCol(
block.startCol()),
1031 RowsAtCompileTime = XprType::RowsAtCompileTime,
1038 return m_argImpl.coeff(m_startRow.value() +
row, m_startCol.value() +
col);
1044 if (ForwardLinearAccess)
1045 return m_argImpl.coeff(m_linear_offset.value() + index);
1047 return coeff(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0);
1053 return m_argImpl.coeffRef(m_startRow.value() +
row, m_startCol.value() +
col);
1059 if (ForwardLinearAccess)
1060 return m_argImpl.coeffRef(m_linear_offset.value() + index);
1062 return coeffRef(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0);
1065 template<
int LoadMode,
typename PacketType>
1069 return m_argImpl.template packet<LoadMode,PacketType>(m_startRow.value() +
row, m_startCol.value() +
col);
1072 template<
int LoadMode,
typename PacketType>
1076 if (ForwardLinearAccess)
1077 return m_argImpl.template packet<LoadMode,PacketType>(m_linear_offset.value() + index);
1079 return packet<LoadMode,PacketType>(RowsAtCompileTime == 1 ? 0 : index,
1080 RowsAtCompileTime == 1 ? index : 0);
1083 template<
int StoreMode,
typename PacketType>
1087 return m_argImpl.template writePacket<StoreMode,PacketType>(m_startRow.value() +
row, m_startCol.value() +
col,
x);
1090 template<
int StoreMode,
typename PacketType>
1094 if (ForwardLinearAccess)
1095 return m_argImpl.template writePacket<StoreMode,PacketType>(m_linear_offset.value() + index,
x);
1097 return writePacket<StoreMode,PacketType>(RowsAtCompileTime == 1 ? 0 : index,
1098 RowsAtCompileTime == 1 ? index : 0,
1112 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel>
1115 typename Block<ArgType, BlockRows, BlockCols, InnerPanel>::PlainObject>
1133 template<
typename ConditionMatrixType,
typename ThenMatrixType,
typename ElseMatrixType>
1135 :
evaluator_base<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >
1149 : m_conditionImpl(select.conditionMatrix()),
1150 m_thenImpl(select.thenMatrix()),
1151 m_elseImpl(select.elseMatrix())
1161 if (m_conditionImpl.coeff(
row,
col))
1162 return m_thenImpl.coeff(
row,
col);
1164 return m_elseImpl.coeff(
row,
col);
1170 if (m_conditionImpl.coeff(index))
1171 return m_thenImpl.coeff(index);
1173 return m_elseImpl.coeff(index);
1185 template<
typename ArgType,
int RowFactor,
int ColFactor>
1206 : m_arg(replicate.nestedExpression()),
1208 m_rows(replicate.nestedExpression().rows()),
1209 m_cols(replicate.nestedExpression().cols())
1217 : RowFactor==1 ?
row
1218 :
row % m_rows.value();
1220 : ColFactor==1 ?
col
1221 :
col % m_cols.value();
1223 return m_argImpl.coeff(actual_row, actual_col);
1231 ? (ColFactor==1 ? index : index%m_cols.value())
1232 : (RowFactor==1 ? index : index%m_rows.value());
1234 return m_argImpl.coeff(actual_index);
1237 template<
int LoadMode,
typename PacketType>
1242 : RowFactor==1 ?
row
1243 :
row % m_rows.value();
1245 : ColFactor==1 ?
col
1246 :
col % m_cols.value();
1248 return m_argImpl.template packet<LoadMode,PacketType>(actual_row, actual_col);
1251 template<
int LoadMode,
typename PacketType>
1256 ? (ColFactor==1 ? index : index%m_cols.value())
1257 : (RowFactor==1 ? index : index%m_rows.value());
1259 return m_argImpl.template packet<LoadMode,PacketType>(actual_index);
1272 template<
typename ArgType,
typename MemberOp,
int Direction>
1274 :
evaluator_base<PartialReduxExpr<ArgType, MemberOp, Direction> >
1282 TraversalSize = Direction==
int(
Vertical) ?
int(ArgType::RowsAtCompileTime) :
int(ArgType::ColsAtCompileTime)
1295 : m_arg(xpr.nestedExpression()), m_functor(xpr.functor())
1307 return m_functor(m_arg.col(j));
1309 return m_functor(m_arg.row(i));
1316 return m_functor(m_arg.col(index));
1318 return m_functor(m_arg.row(index));
1332 template<
typename XprType>
1351 return m_argImpl.coeff(
row,
col);
1357 return m_argImpl.coeff(index);
1363 return m_argImpl.coeffRef(
row,
col);
1369 return m_argImpl.coeffRef(index);
1372 template<
int LoadMode,
typename PacketType>
1376 return m_argImpl.template packet<LoadMode,PacketType>(
row,
col);
1379 template<
int LoadMode,
typename PacketType>
1383 return m_argImpl.template packet<LoadMode,PacketType>(index);
1386 template<
int StoreMode,
typename PacketType>
1390 m_argImpl.template writePacket<StoreMode>(
row,
col,
x);
1393 template<
int StoreMode,
typename PacketType>
1397 m_argImpl.template writePacket<StoreMode>(index,
x);
1404 template<
typename TArgType>
1415 template<
typename TArgType>
1432 template<
typename ArgType,
int Direction>
1441 IsRowMajor = XprType::IsRowMajor,
1442 IsColMajor = !IsRowMajor,
1446 || ((Direction ==
Vertical) && IsColMajor)
1447 || ((Direction ==
Horizontal) && IsRowMajor),
1455 || ((ReverseRow && XprType::ColsAtCompileTime==1) || (ReverseCol && XprType::RowsAtCompileTime==1))
1464 : m_argImpl(reverse.nestedExpression()),
1465 m_rows(ReverseRow ? reverse.nestedExpression().rows() : 1),
1466 m_cols(ReverseCol ? reverse.nestedExpression().cols() : 1)
1472 return m_argImpl.coeff(ReverseRow ? m_rows.value() -
row - 1 :
row,
1473 ReverseCol ? m_cols.value() -
col - 1 :
col);
1479 return m_argImpl.coeff(m_rows.value() * m_cols.value() - index - 1);
1485 return m_argImpl.coeffRef(ReverseRow ? m_rows.value() -
row - 1 :
row,
1486 ReverseCol ? m_cols.value() -
col - 1 :
col);
1492 return m_argImpl.coeffRef(m_rows.value() * m_cols.value() - index - 1);
1495 template<
int LoadMode,
typename PacketType>
1501 OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1,
1502 OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1
1506 ReverseRow ? m_rows.value() -
row - OffsetRow :
row,
1507 ReverseCol ? m_cols.value() -
col - OffsetCol :
col));
1510 template<
int LoadMode,
typename PacketType>
1515 return preverse(m_argImpl.template packet<LoadMode,PacketType>(m_rows.value() * m_cols.value() - index - PacketSize));
1518 template<
int LoadMode,
typename PacketType>
1525 OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1,
1526 OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1
1529 m_argImpl.template writePacket<LoadMode>(
1530 ReverseRow ? m_rows.value() -
row - OffsetRow :
row,
1531 ReverseCol ? m_cols.value() -
col - OffsetCol :
col,
1535 template<
int LoadMode,
typename PacketType>
1540 m_argImpl.template writePacket<LoadMode>
1541 (m_rows.value() * m_cols.value() - index - PacketSize,
preverse(
x));
1556 template<
typename ArgType,
int DiagIndex>
1571 : m_argImpl(diagonal.nestedExpression()),
1572 m_index(diagonal.index())
1581 return m_argImpl.coeff(
row + rowOffset(),
row + colOffset());
1587 return m_argImpl.coeff(index + rowOffset(), index + colOffset());
1593 return m_argImpl.coeffRef(
row + rowOffset(),
row + colOffset());
1599 return m_argImpl.coeffRef(index + rowOffset(), index + colOffset());
1622 template<
typename ArgType>
1627 template<
typename ArgType>
1647 return m_arg.rows();
1652 return m_arg.cols();
1659 template<
typename ArgType>
1661 :
public evaluator<typename ArgType::PlainObject>
1668 : m_result(xpr.
arg())
1670 ::new (
static_cast<Base*
>(
this))
Base(m_result);
1677 ::new (
static_cast<Base*
>(
this))
Base(m_result);
1688 #endif // EIGEN_COREEVALUATORS_H