mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Apply clang-format
This commit is contained in:
@@ -16,21 +16,20 @@
|
||||
namespace Eigen {
|
||||
|
||||
/** \class TensorAssign
|
||||
* \ingroup CXX11_Tensor_Module
|
||||
*
|
||||
* \brief The tensor assignment class.
|
||||
*
|
||||
* This class is represents the assignment of the values resulting from the evaluation of
|
||||
* the rhs expression to the memory locations denoted by the lhs expression.
|
||||
*/
|
||||
* \ingroup CXX11_Tensor_Module
|
||||
*
|
||||
* \brief The tensor assignment class.
|
||||
*
|
||||
* This class is represents the assignment of the values resulting from the evaluation of
|
||||
* the rhs expression to the memory locations denoted by the lhs expression.
|
||||
*/
|
||||
namespace internal {
|
||||
template<typename LhsXprType, typename RhsXprType>
|
||||
struct traits<TensorAssignOp<LhsXprType, RhsXprType> >
|
||||
{
|
||||
template <typename LhsXprType, typename RhsXprType>
|
||||
struct traits<TensorAssignOp<LhsXprType, RhsXprType> > {
|
||||
typedef typename LhsXprType::Scalar Scalar;
|
||||
typedef typename traits<LhsXprType>::StorageKind StorageKind;
|
||||
typedef typename promote_index_type<typename traits<LhsXprType>::Index,
|
||||
typename traits<RhsXprType>::Index>::type Index;
|
||||
typedef
|
||||
typename promote_index_type<typename traits<LhsXprType>::Index, typename traits<RhsXprType>::Index>::type Index;
|
||||
typedef typename LhsXprType::Nested LhsNested;
|
||||
typedef typename RhsXprType::Nested RhsNested;
|
||||
typedef std::remove_reference_t<LhsNested> LhsNested_;
|
||||
@@ -39,31 +38,24 @@ struct traits<TensorAssignOp<LhsXprType, RhsXprType> >
|
||||
static constexpr int Layout = internal::traits<LhsXprType>::Layout;
|
||||
typedef typename traits<LhsXprType>::PointerType PointerType;
|
||||
|
||||
enum {
|
||||
Flags = 0
|
||||
};
|
||||
enum { Flags = 0 };
|
||||
};
|
||||
|
||||
template<typename LhsXprType, typename RhsXprType>
|
||||
struct eval<TensorAssignOp<LhsXprType, RhsXprType>, Eigen::Dense>
|
||||
{
|
||||
template <typename LhsXprType, typename RhsXprType>
|
||||
struct eval<TensorAssignOp<LhsXprType, RhsXprType>, Eigen::Dense> {
|
||||
typedef const TensorAssignOp<LhsXprType, RhsXprType>& type;
|
||||
};
|
||||
|
||||
template<typename LhsXprType, typename RhsXprType>
|
||||
struct nested<TensorAssignOp<LhsXprType, RhsXprType>, 1, typename eval<TensorAssignOp<LhsXprType, RhsXprType> >::type>
|
||||
{
|
||||
template <typename LhsXprType, typename RhsXprType>
|
||||
struct nested<TensorAssignOp<LhsXprType, RhsXprType>, 1, typename eval<TensorAssignOp<LhsXprType, RhsXprType> >::type> {
|
||||
typedef TensorAssignOp<LhsXprType, RhsXprType> type;
|
||||
};
|
||||
|
||||
} // end namespace internal
|
||||
|
||||
|
||||
|
||||
template<typename LhsXprType, typename RhsXprType>
|
||||
class TensorAssignOp : public TensorBase<TensorAssignOp<LhsXprType, RhsXprType> >
|
||||
{
|
||||
public:
|
||||
template <typename LhsXprType, typename RhsXprType>
|
||||
class TensorAssignOp : public TensorBase<TensorAssignOp<LhsXprType, RhsXprType> > {
|
||||
public:
|
||||
typedef typename Eigen::internal::traits<TensorAssignOp>::Scalar Scalar;
|
||||
typedef typename Eigen::NumTraits<Scalar>::Real RealScalar;
|
||||
typedef typename LhsXprType::CoeffReturnType CoeffReturnType;
|
||||
@@ -76,24 +68,22 @@ class TensorAssignOp : public TensorBase<TensorAssignOp<LhsXprType, RhsXprType>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorAssignOp(LhsXprType& lhs, const RhsXprType& rhs)
|
||||
: m_lhs_xpr(lhs), m_rhs_xpr(rhs) {}
|
||||
|
||||
/** \returns the nested expressions */
|
||||
EIGEN_DEVICE_FUNC
|
||||
internal::remove_all_t<typename LhsXprType::Nested>&
|
||||
lhsExpression() const { return *((internal::remove_all_t<typename LhsXprType::Nested>*)&m_lhs_xpr); }
|
||||
/** \returns the nested expressions */
|
||||
EIGEN_DEVICE_FUNC internal::remove_all_t<typename LhsXprType::Nested>& lhsExpression() const {
|
||||
return *((internal::remove_all_t<typename LhsXprType::Nested>*)&m_lhs_xpr);
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
const internal::remove_all_t<typename RhsXprType::Nested>&
|
||||
rhsExpression() const { return m_rhs_xpr; }
|
||||
EIGEN_DEVICE_FUNC const internal::remove_all_t<typename RhsXprType::Nested>& rhsExpression() const {
|
||||
return m_rhs_xpr;
|
||||
}
|
||||
|
||||
protected:
|
||||
internal::remove_all_t<typename LhsXprType::Nested>& m_lhs_xpr;
|
||||
const internal::remove_all_t<typename RhsXprType::Nested>& m_rhs_xpr;
|
||||
protected:
|
||||
internal::remove_all_t<typename LhsXprType::Nested>& m_lhs_xpr;
|
||||
const internal::remove_all_t<typename RhsXprType::Nested>& m_rhs_xpr;
|
||||
};
|
||||
|
||||
|
||||
template<typename LeftArgType, typename RightArgType, typename Device>
|
||||
struct TensorEvaluator<const TensorAssignOp<LeftArgType, RightArgType>, Device>
|
||||
{
|
||||
template <typename LeftArgType, typename RightArgType, typename Device>
|
||||
struct TensorEvaluator<const TensorAssignOp<LeftArgType, RightArgType>, Device> {
|
||||
typedef TensorAssignOp<LeftArgType, RightArgType> XprType;
|
||||
typedef typename XprType::Index Index;
|
||||
typedef typename XprType::Scalar Scalar;
|
||||
@@ -108,37 +98,32 @@ struct TensorEvaluator<const TensorAssignOp<LeftArgType, RightArgType>, Device>
|
||||
static constexpr int Layout = TensorEvaluator<LeftArgType, Device>::Layout;
|
||||
|
||||
enum {
|
||||
IsAligned = int(TensorEvaluator<LeftArgType, Device>::IsAligned) &
|
||||
int(TensorEvaluator<RightArgType, Device>::IsAligned),
|
||||
PacketAccess = int(TensorEvaluator<LeftArgType, Device>::PacketAccess) &
|
||||
int(TensorEvaluator<RightArgType, Device>::PacketAccess),
|
||||
BlockAccess = int(TensorEvaluator<LeftArgType, Device>::BlockAccess) &
|
||||
int(TensorEvaluator<RightArgType, Device>::BlockAccess),
|
||||
IsAligned =
|
||||
int(TensorEvaluator<LeftArgType, Device>::IsAligned) & int(TensorEvaluator<RightArgType, Device>::IsAligned),
|
||||
PacketAccess = int(TensorEvaluator<LeftArgType, Device>::PacketAccess) &
|
||||
int(TensorEvaluator<RightArgType, Device>::PacketAccess),
|
||||
BlockAccess = int(TensorEvaluator<LeftArgType, Device>::BlockAccess) &
|
||||
int(TensorEvaluator<RightArgType, Device>::BlockAccess),
|
||||
PreferBlockAccess = int(TensorEvaluator<LeftArgType, Device>::PreferBlockAccess) |
|
||||
int(TensorEvaluator<RightArgType, Device>::PreferBlockAccess),
|
||||
RawAccess = TensorEvaluator<LeftArgType, Device>::RawAccess
|
||||
RawAccess = TensorEvaluator<LeftArgType, Device>::RawAccess
|
||||
};
|
||||
|
||||
//===- Tensor block evaluation strategy (see TensorBlock.h) -------------===//
|
||||
typedef internal::TensorBlockDescriptor<NumDims, Index> TensorBlockDesc;
|
||||
typedef internal::TensorBlockScratchAllocator<Device> TensorBlockScratch;
|
||||
|
||||
typedef typename TensorEvaluator<const RightArgType, Device>::TensorBlock
|
||||
RightTensorBlock;
|
||||
typedef typename TensorEvaluator<const RightArgType, Device>::TensorBlock RightTensorBlock;
|
||||
//===--------------------------------------------------------------------===//
|
||||
|
||||
TensorEvaluator(const XprType& op, const Device& device) :
|
||||
m_leftImpl(op.lhsExpression(), device),
|
||||
m_rightImpl(op.rhsExpression(), device)
|
||||
{
|
||||
EIGEN_STATIC_ASSERT(
|
||||
(static_cast<int>(TensorEvaluator<LeftArgType, Device>::Layout) ==
|
||||
static_cast<int>(TensorEvaluator<RightArgType, Device>::Layout)),
|
||||
YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
TensorEvaluator(const XprType& op, const Device& device)
|
||||
: m_leftImpl(op.lhsExpression(), device), m_rightImpl(op.rhsExpression(), device) {
|
||||
EIGEN_STATIC_ASSERT((static_cast<int>(TensorEvaluator<LeftArgType, Device>::Layout) ==
|
||||
static_cast<int>(TensorEvaluator<RightArgType, Device>::Layout)),
|
||||
YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC const Dimensions& dimensions() const
|
||||
{
|
||||
EIGEN_DEVICE_FUNC const Dimensions& dimensions() const {
|
||||
// The dimensions of the lhs and the rhs tensors should be equal to prevent
|
||||
// overflows and ensure the result is fully initialized.
|
||||
// TODO: use left impl instead if right impl dimensions are known at compile time.
|
||||
@@ -157,11 +142,9 @@ struct TensorEvaluator<const TensorAssignOp<LeftArgType, RightArgType>, Device>
|
||||
|
||||
#ifdef EIGEN_USE_THREADS
|
||||
template <typename EvalSubExprsCallback>
|
||||
EIGEN_STRONG_INLINE void evalSubExprsIfNeededAsync(
|
||||
EvaluatorPointerType, EvalSubExprsCallback done) {
|
||||
EIGEN_STRONG_INLINE void evalSubExprsIfNeededAsync(EvaluatorPointerType, EvalSubExprsCallback done) {
|
||||
m_leftImpl.evalSubExprsIfNeededAsync(nullptr, [this, done](bool) {
|
||||
m_rightImpl.evalSubExprsIfNeededAsync(
|
||||
m_leftImpl.data(), [done](bool need_assign) { done(need_assign); });
|
||||
m_rightImpl.evalSubExprsIfNeededAsync(m_leftImpl.data(), [done](bool need_assign) { done(need_assign); });
|
||||
});
|
||||
}
|
||||
#endif // EIGEN_USE_THREADS
|
||||
@@ -175,45 +158,34 @@ struct TensorEvaluator<const TensorAssignOp<LeftArgType, RightArgType>, Device>
|
||||
m_leftImpl.coeffRef(i) = m_rightImpl.coeff(i);
|
||||
}
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalPacket(Index i) const {
|
||||
|
||||
const int LhsStoreMode = TensorEvaluator<LeftArgType, Device>::IsAligned ? Aligned : Unaligned;
|
||||
const int RhsLoadMode = TensorEvaluator<RightArgType, Device>::IsAligned ? Aligned : Unaligned;
|
||||
m_leftImpl.template writePacket<LhsStoreMode>(i, m_rightImpl.template packet<RhsLoadMode>(i));
|
||||
}
|
||||
EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index) const
|
||||
{
|
||||
return m_leftImpl.coeff(index);
|
||||
}
|
||||
template<int LoadMode>
|
||||
EIGEN_DEVICE_FUNC PacketReturnType packet(Index index) const
|
||||
{
|
||||
EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index) const { return m_leftImpl.coeff(index); }
|
||||
template <int LoadMode>
|
||||
EIGEN_DEVICE_FUNC PacketReturnType packet(Index index) const {
|
||||
return m_leftImpl.template packet<LoadMode>(index);
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost
|
||||
costPerCoeff(bool vectorized) const {
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const {
|
||||
// We assume that evalPacket or evalScalar is called to perform the
|
||||
// assignment and account for the cost of the write here, but reduce left
|
||||
// cost by one load because we are using m_leftImpl.coeffRef.
|
||||
TensorOpCost left = m_leftImpl.costPerCoeff(vectorized);
|
||||
return m_rightImpl.costPerCoeff(vectorized) +
|
||||
TensorOpCost(
|
||||
numext::maxi(0.0, left.bytes_loaded() - sizeof(CoeffReturnType)),
|
||||
left.bytes_stored(), left.compute_cycles()) +
|
||||
TensorOpCost(numext::maxi(0.0, left.bytes_loaded() - sizeof(CoeffReturnType)), left.bytes_stored(),
|
||||
left.compute_cycles()) +
|
||||
TensorOpCost(0, sizeof(CoeffReturnType), 0, vectorized, PacketSize);
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
internal::TensorBlockResourceRequirements getResourceRequirements() const {
|
||||
return internal::TensorBlockResourceRequirements::merge(
|
||||
m_leftImpl.getResourceRequirements(),
|
||||
m_rightImpl.getResourceRequirements());
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE internal::TensorBlockResourceRequirements getResourceRequirements() const {
|
||||
return internal::TensorBlockResourceRequirements::merge(m_leftImpl.getResourceRequirements(),
|
||||
m_rightImpl.getResourceRequirements());
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalBlock(
|
||||
TensorBlockDesc& desc, TensorBlockScratch& scratch) {
|
||||
if (TensorEvaluator<LeftArgType, Device>::RawAccess &&
|
||||
m_leftImpl.data() != NULL) {
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalBlock(TensorBlockDesc& desc, TensorBlockScratch& scratch) {
|
||||
if (TensorEvaluator<LeftArgType, Device>::RawAccess && m_leftImpl.data() != NULL) {
|
||||
// If destination has raw data access, we pass it as a potential
|
||||
// destination for a block descriptor evaluation.
|
||||
desc.template AddDestinationBuffer<Layout>(
|
||||
@@ -236,7 +208,6 @@ struct TensorEvaluator<const TensorAssignOp<LeftArgType, RightArgType>, Device>
|
||||
TensorEvaluator<RightArgType, Device> m_rightImpl;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Eigen
|
||||
|
||||
|
||||
#endif // EIGEN_CXX11_TENSOR_TENSOR_ASSIGN_H
|
||||
#endif // EIGEN_CXX11_TENSOR_TENSOR_ASSIGN_H
|
||||
|
||||
Reference in New Issue
Block a user