TensorAssign.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_ASSIGN_H
11 #define EIGEN_CXX11_TENSOR_TENSOR_ASSIGN_H
12 
13 namespace Eigen {
14 
23 namespace internal {
24 template<typename LhsXprType, typename RhsXprType>
25 struct traits<TensorAssignOp<LhsXprType, RhsXprType> >
26 {
27  typedef typename LhsXprType::Scalar Scalar;
31  typedef typename LhsXprType::Nested LhsNested;
32  typedef typename RhsXprType::Nested RhsNested;
36  static const int Layout = internal::traits<LhsXprType>::Layout;
38 
39  enum {
40  Flags = 0
41  };
42 };
43 
44 template<typename LhsXprType, typename RhsXprType>
45 struct eval<TensorAssignOp<LhsXprType, RhsXprType>, Eigen::Dense>
46 {
48 };
49 
50 template<typename LhsXprType, typename RhsXprType>
51 struct nested<TensorAssignOp<LhsXprType, RhsXprType>, 1, typename eval<TensorAssignOp<LhsXprType, RhsXprType> >::type>
52 {
54 };
55 
56 } // end namespace internal
57 
58 
59 
60 template<typename LhsXprType, typename RhsXprType>
61 class TensorAssignOp : public TensorBase<TensorAssignOp<LhsXprType, RhsXprType> >
62 {
63  public:
66  typedef typename LhsXprType::CoeffReturnType CoeffReturnType;
70 
72 
73  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorAssignOp(LhsXprType& lhs, const RhsXprType& rhs)
74  : m_lhs_xpr(lhs), m_rhs_xpr(rhs) {}
75 
80 
83  rhsExpression() const { return m_rhs_xpr; }
84 
85  protected:
88 };
89 
90 
91 template<typename LeftArgType, typename RightArgType, typename Device>
92 struct TensorEvaluator<const TensorAssignOp<LeftArgType, RightArgType>, Device>
93 {
95  typedef typename XprType::Index Index;
96  typedef typename XprType::Scalar Scalar;
102 
104  static const int NumDims = XprType::NumDims;
105 
106  enum {
117  };
118 
119  //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===//
122 
125  //===--------------------------------------------------------------------===//
126 
127  TensorEvaluator(const XprType& op, const Device& device) :
128  m_leftImpl(op.lhsExpression(), device),
129  m_rightImpl(op.rhsExpression(), device)
130  {
134  YOU_MADE_A_PROGRAMMING_MISTAKE);
135  }
136 
138  {
139  // The dimensions of the lhs and the rhs tensors should be equal to prevent
140  // overflows and ensure the result is fully initialized.
141  // TODO: use left impl instead if right impl dimensions are known at compile time.
142  return m_rightImpl.dimensions();
143  }
144 
146  eigen_assert(dimensions_match(m_leftImpl.dimensions(), m_rightImpl.dimensions()));
147  m_leftImpl.evalSubExprsIfNeeded(NULL);
148  // If the lhs provides raw access to its storage area (i.e. if m_leftImpl.data() returns a non
149  // null value), attempt to evaluate the rhs expression in place. Returns true iff in place
150  // evaluation isn't supported and the caller still needs to manually assign the values generated
151  // by the rhs to the lhs.
152  return m_rightImpl.evalSubExprsIfNeeded(m_leftImpl.data());
153  }
154 
155 #ifdef EIGEN_USE_THREADS
156  template <typename EvalSubExprsCallback>
157  EIGEN_STRONG_INLINE void evalSubExprsIfNeededAsync(
158  EvaluatorPointerType, EvalSubExprsCallback done) {
159  m_leftImpl.evalSubExprsIfNeededAsync(nullptr, [this, done](bool) {
160  m_rightImpl.evalSubExprsIfNeededAsync(
161  m_leftImpl.data(), [done](bool need_assign) { done(need_assign); });
162  });
163  }
164 #endif // EIGEN_USE_THREADS
165 
167  m_leftImpl.cleanup();
168  m_rightImpl.cleanup();
169  }
170 
172  m_leftImpl.coeffRef(i) = m_rightImpl.coeff(i);
173  }
175 
178  m_leftImpl.template writePacket<LhsStoreMode>(i, m_rightImpl.template packet<RhsLoadMode>(i));
179  }
181  {
182  return m_leftImpl.coeff(index);
183  }
184  template<int LoadMode>
186  {
187  return m_leftImpl.template packet<LoadMode>(index);
188  }
189 
191  costPerCoeff(bool vectorized) const {
192  // We assume that evalPacket or evalScalar is called to perform the
193  // assignment and account for the cost of the write here, but reduce left
194  // cost by one load because we are using m_leftImpl.coeffRef.
195  TensorOpCost left = m_leftImpl.costPerCoeff(vectorized);
196  return m_rightImpl.costPerCoeff(vectorized) +
197  TensorOpCost(
198  numext::maxi(0.0, left.bytes_loaded() - sizeof(CoeffReturnType)),
199  left.bytes_stored(), left.compute_cycles()) +
200  TensorOpCost(0, sizeof(CoeffReturnType), 0, vectorized, PacketSize);
201  }
202 
206  m_leftImpl.getResourceRequirements(),
207  m_rightImpl.getResourceRequirements());
208  }
209 
213  m_leftImpl.data() != NULL) {
214  // If destination has raw data access, we pass it as a potential
215  // destination for a block descriptor evaluation.
216  desc.template AddDestinationBuffer<Layout>(
217  /*dst_base=*/m_leftImpl.data() + desc.offset(),
218  /*dst_strides=*/internal::strides<Layout>(m_leftImpl.dimensions()));
219  }
220 
221  RightTensorBlock block = m_rightImpl.block(desc, scratch, /*root_of_expr_ast=*/true);
222  // If block was evaluated into a destination, there is no need to do assignment.
224  m_leftImpl.writeBlock(desc, block);
225  }
226  block.cleanup();
227  }
228 
229 #ifdef EIGEN_USE_SYCL
230  // binding placeholder accessors to a command group handler for SYCL
231  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const {
232  m_leftImpl.bind(cgh);
233  m_rightImpl.bind(cgh);
234  }
235 #endif
236 
237  EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return m_leftImpl.data(); }
238 
239  private:
242 };
243 
244 }
245 
246 
247 #endif // EIGEN_CXX11_TENSOR_TENSOR_ASSIGN_H
gtsam.examples.DogLegOptimizerExample.int
int
Definition: DogLegOptimizerExample.py:111
Eigen::internal::TensorBlockScratchAllocator
Definition: TensorBlock.h:525
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::RightTensorBlock
TensorEvaluator< const RightArgType, Device >::TensorBlock RightTensorBlock
Definition: TensorAssign.h:124
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::evalSubExprsIfNeeded
EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType)
Definition: TensorAssign.h:145
Eigen::TensorAssignOp::RealScalar
Eigen::NumTraits< Scalar >::Real RealScalar
Definition: TensorAssign.h:65
Eigen::TensorAssignOp::rhsExpression
const EIGEN_DEVICE_FUNC internal::remove_all< typename RhsXprType::Nested >::type & rhsExpression() const
Definition: TensorAssign.h:83
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::XprType
TensorAssignOp< LeftArgType, RightArgType > XprType
Definition: TensorAssign.h:94
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::getResourceRequirements
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE internal::TensorBlockResourceRequirements getResourceRequirements() const
Definition: TensorAssign.h:204
Eigen::internal::nested
Definition: TensorTraits.h:174
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::coeff
EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index) const
Definition: TensorAssign.h:180
Eigen::Unaligned
@ Unaligned
Definition: Constants.h:233
Eigen::internal::nested< TensorAssignOp< LhsXprType, RhsXprType >, 1, typename eval< TensorAssignOp< LhsXprType, RhsXprType > >::type >::type
TensorAssignOp< LhsXprType, RhsXprType > type
Definition: TensorAssign.h:53
eigen_assert
#define eigen_assert(x)
Definition: Macros.h:1037
Eigen::TensorEvaluator::Layout
@ Layout
Definition: TensorEvaluator.h:50
Eigen::TensorAssignOp::lhsExpression
EIGEN_DEVICE_FUNC internal::remove_all< typename LhsXprType::Nested >::type & lhsExpression() const
Definition: TensorAssign.h:79
type
Definition: pytypes.h:1525
Eigen::TensorAssignOp::Nested
Eigen::internal::nested< TensorAssignOp >::type Nested
Definition: TensorAssign.h:67
Eigen::internal::TensorMaterializedBlock
Definition: TensorBlock.h:656
Eigen::internal::TensorBlockResourceRequirements::merge
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlockResourceRequirements merge(const TensorBlockResourceRequirements &lhs, const TensorBlockResourceRequirements &rhs)
Definition: TensorBlock.h:138
Eigen::TensorEvaluator::PacketSize
static const int PacketSize
Definition: TensorEvaluator.h:36
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::TensorBlockScratch
internal::TensorBlockScratchAllocator< Device > TensorBlockScratch
Definition: TensorAssign.h:121
make_changelog.desc
desc
Definition: make_changelog.py:71
Eigen::internal::traits< TensorAssignOp< LhsXprType, RhsXprType > >::_RhsNested
remove_reference< RhsNested >::type _RhsNested
Definition: TensorAssign.h:34
Eigen::dimensions_match
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool dimensions_match(Dims1 dims1, Dims2 dims2)
Definition: TensorDimensions.h:484
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::data
EIGEN_DEVICE_FUNC EvaluatorPointerType data() const
Definition: TensorAssign.h:237
Eigen::PacketType
Definition: TensorMeta.h:50
Eigen::internal::TensorBlockDescriptor< NumDims, Index >
Eigen::internal::true_type
Definition: Meta.h:96
Eigen::TensorAssignOp::m_lhs_xpr
internal::remove_all< typename LhsXprType::Nested >::type & m_lhs_xpr
Definition: TensorAssign.h:86
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::TensorBlockDesc
internal::TensorBlockDescriptor< NumDims, Index > TensorBlockDesc
Definition: TensorAssign.h:120
Eigen::TensorAssignOp::m_rhs_xpr
const internal::remove_all< typename RhsXprType::Nested >::type & m_rhs_xpr
Definition: TensorAssign.h:87
Eigen::TensorAssignOp::TensorAssignOp
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorAssignOp(LhsXprType &lhs, const RhsXprType &rhs)
Definition: TensorAssign.h:73
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::costPerCoeff
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
Definition: TensorAssign.h:191
left
static char left
Definition: blas_interface.hh:62
Eigen::internal::traits< TensorAssignOp< LhsXprType, RhsXprType > >::_LhsNested
remove_reference< LhsNested >::type _LhsNested
Definition: TensorAssign.h:33
Eigen::TensorEvaluator::data
EIGEN_DEVICE_FUNC EvaluatorPointerType data() const
Definition: TensorEvaluator.h:181
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::evalScalar
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalScalar(Index i)
Definition: TensorAssign.h:171
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::packet
EIGEN_DEVICE_FUNC PacketReturnType packet(Index index) const
Definition: TensorAssign.h:185
Eigen::TensorAssignOp::StorageKind
Eigen::internal::traits< TensorAssignOp >::StorageKind StorageKind
Definition: TensorAssign.h:68
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::TensorEvaluator
TensorEvaluator(const XprType &op, const Device &device)
Definition: TensorAssign.h:127
EIGEN_STRONG_INLINE
#define EIGEN_STRONG_INLINE
Definition: Macros.h:917
Eigen::TensorEvaluator::PreferBlockAccess
@ PreferBlockAccess
Definition: TensorEvaluator.h:49
Eigen::TensorAssignOp::Index
Eigen::internal::traits< TensorAssignOp >::Index Index
Definition: TensorAssign.h:69
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::dimensions
const EIGEN_DEVICE_FUNC Dimensions & dimensions() const
Definition: TensorAssign.h:137
Eigen::internal::traits< TensorAssignOp< LhsXprType, RhsXprType > >::Scalar
LhsXprType::Scalar Scalar
Definition: TensorAssign.h:27
Eigen::internal::TensorMaterializedBlock::cleanup
void cleanup()
Definition: TensorBlock.h:682
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::EvaluatorPointerType
Storage::Type EvaluatorPointerType
Definition: TensorAssign.h:101
Eigen::internal::traits< TensorAssignOp< LhsXprType, RhsXprType > >::PointerType
traits< LhsXprType >::PointerType PointerType
Definition: TensorAssign.h:37
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::Storage
StorageMemory< CoeffReturnType, Device > Storage
Definition: TensorAssign.h:100
Eigen::Triplet< double >
Eigen::StorageMemory
Definition: TensorForwardDeclarations.h:37
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::m_rightImpl
TensorEvaluator< RightArgType, Device > m_rightImpl
Definition: TensorAssign.h:241
Eigen::internal::kMaterializedInOutput
@ kMaterializedInOutput
Definition: TensorBlock.h:610
Eigen::TensorBase
The tensor base class.
Definition: TensorBase.h:973
size_t
std::size_t size_t
Definition: wrap/pybind11/include/pybind11/detail/common.h:490
Eigen::TensorEvaluator::BlockAccess
@ BlockAccess
Definition: TensorEvaluator.h:48
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::Index
XprType::Index Index
Definition: TensorAssign.h:95
Eigen::internal::traits< TensorAssignOp< LhsXprType, RhsXprType > >::StorageKind
traits< LhsXprType >::StorageKind StorageKind
Definition: TensorAssign.h:28
Eigen::internal::traits
Definition: ForwardDeclarations.h:17
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::Scalar
XprType::Scalar Scalar
Definition: TensorAssign.h:96
EIGEN_STATIC_ASSERT
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:127
Eigen::TensorEvaluator::EvaluatorPointerType
Storage::Type EvaluatorPointerType
Definition: TensorEvaluator.h:39
Eigen::internal::TensorBlockResourceRequirements
Definition: TensorBlock.h:75
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::Dimensions
TensorEvaluator< RightArgType, Device >::Dimensions Dimensions
Definition: TensorAssign.h:99
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::cleanup
EIGEN_STRONG_INLINE void cleanup()
Definition: TensorAssign.h:166
Eigen::internal::traits< TensorAssignOp< LhsXprType, RhsXprType > >::Index
promote_index_type< typename traits< LhsXprType >::Index, typename traits< RhsXprType >::Index >::type Index
Definition: TensorAssign.h:30
Eigen::TensorEvaluator
A cost model used to limit the number of threads used for evaluating tensor expression.
Definition: TensorEvaluator.h:28
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::m_leftImpl
TensorEvaluator< LeftArgType, Device > m_leftImpl
Definition: TensorAssign.h:240
Eigen::internal::traits< TensorAssignOp< LhsXprType, RhsXprType > >::RhsNested
RhsXprType::Nested RhsNested
Definition: TensorAssign.h:32
Eigen::internal::eval< TensorAssignOp< LhsXprType, RhsXprType >, Eigen::Dense >::type
const typedef TensorAssignOp< LhsXprType, RhsXprType > & type
Definition: TensorAssign.h:47
internal
Definition: BandTriangularSolver.h:13
Eigen::numext::maxi
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T maxi(const T &x, const T &y)
Definition: Eigen/src/Core/MathFunctions.h:1093
Eigen::internal::traits< TensorAssignOp< LhsXprType, RhsXprType > >::LhsNested
LhsXprType::Nested LhsNested
Definition: TensorAssign.h:31
NULL
#define NULL
Definition: ccolamd.c:609
Eigen::TensorEvaluator::IsAligned
@ IsAligned
Definition: TensorEvaluator.h:46
Eigen::internal::promote_index_type
Definition: XprHelper.h:120
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::evalBlock
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalBlock(TensorBlockDesc &desc, TensorBlockScratch &scratch)
Definition: TensorAssign.h:210
Eigen::TensorEvaluator::block
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock block(TensorBlockDesc &desc, TensorBlockScratch &scratch, bool=false) const
Definition: TensorEvaluator.h:158
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::PacketReturnType
PacketType< CoeffReturnType, Device >::type PacketReturnType
Definition: TensorAssign.h:98
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::evalPacket
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalPacket(Index i)
Definition: TensorAssign.h:174
Eigen::internal::eval
Definition: XprHelper.h:332
Eigen::TensorEvaluator::PacketAccess
@ PacketAccess
Definition: TensorEvaluator.h:47
Eigen::TensorAssignOp
Definition: TensorAssign.h:61
Eigen::TensorOpCost
Definition: TensorCostModel.h:25
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Eigen::TensorEvaluator< const TensorAssignOp< LeftArgType, RightArgType >, Device >::CoeffReturnType
XprType::CoeffReturnType CoeffReturnType
Definition: TensorAssign.h:97
Eigen::TensorAssignOp::CoeffReturnType
LhsXprType::CoeffReturnType CoeffReturnType
Definition: TensorAssign.h:66
Eigen::TensorAssignOp::NumDims
static const int NumDims
Definition: TensorAssign.h:71
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::Aligned
@ Aligned
Definition: Constants.h:240
Eigen::Dense
Definition: Constants.h:507
Eigen::TensorAssignOp::Scalar
Eigen::internal::traits< TensorAssignOp >::Scalar Scalar
Definition: TensorAssign.h:64
Eigen::internal::TensorMaterializedBlock::kind
TensorBlockKind kind() const
Definition: TensorBlock.h:673


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:05:28