![]() |
Eigen-unsupported
3.3.3
|
00001 // This file is part of Eigen, a lightweight C++ template library 00002 // for linear algebra. 00003 // 00004 // Mehdi Goli Codeplay Software Ltd. 00005 // Ralph Potter Codeplay Software Ltd. 00006 // Luke Iwanski Codeplay Software Ltd. 00007 // Contact: <eigen@codeplay.com> 00008 // 00009 // This Source Code Form is subject to the terms of the Mozilla 00010 // Public License v. 2.0. If a copy of the MPL was not distributed 00011 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 00012 00013 /***************************************************************** 00014 * TensorSyclextractFunctors.h 00015 * 00016 * \brief: 00017 * Used to extract all the functors allocated to each node of the expression 00018 *tree. 00019 * 00020 *****************************************************************/ 00021 00022 #ifndef UNSUPPORTED_EIGEN_CXX11_SRC_TENSOR_TENSORSYCL_EXTRACT_FUNCTORS_HPP 00023 #define UNSUPPORTED_EIGEN_CXX11_SRC_TENSOR_TENSORSYCL_EXTRACT_FUNCTORS_HPP 00024 00025 namespace Eigen { 00026 namespace TensorSycl { 00027 namespace internal { 00035 // This struct is used for leafNode (TensorMap) and nodes behaving like leafNode (TensorForcedEval). 00036 template <typename Evaluator> struct FunctorExtractor{ 00037 typedef typename Evaluator::Dimensions Dimensions; 00038 const Dimensions m_dimensions; 00039 const Dimensions& dimensions() const { return m_dimensions; } 00040 FunctorExtractor(const Evaluator& expr) 00041 : m_dimensions(expr.dimensions()) {} 00042 00043 }; 00044 00047 template <template <class, class> class UnaryCategory, typename OP, typename RHSExpr, typename Dev> 00048 struct FunctorExtractor<TensorEvaluator<const UnaryCategory<OP, RHSExpr>, Dev> > { 00049 FunctorExtractor<TensorEvaluator<RHSExpr, Dev> > rhsExpr; 00050 OP func; 00051 FunctorExtractor(const TensorEvaluator<const UnaryCategory<OP, RHSExpr>, Dev>& expr) 00052 : rhsExpr(expr.impl()), func(expr.functor()) {} 00053 }; 00056 template <template <class, class> class UnaryCategory, typename OP, typename RHSExpr, typename Dev> 00057 struct FunctorExtractor<TensorEvaluator<UnaryCategory<OP, RHSExpr>, Dev> > 00058 : FunctorExtractor<TensorEvaluator<const UnaryCategory<OP, RHSExpr>, Dev> >{}; 00059 00062 template <template<class, class, class> class BinaryCategory, typename OP, typename LHSExpr, typename RHSExpr, typename Dev> 00063 struct FunctorExtractor<TensorEvaluator<const BinaryCategory<OP, LHSExpr, RHSExpr>, Dev> > { 00064 FunctorExtractor<TensorEvaluator<LHSExpr, Dev> > lhsExpr; 00065 FunctorExtractor<TensorEvaluator<RHSExpr, Dev> > rhsExpr; 00066 OP func; 00067 FunctorExtractor(const TensorEvaluator<const BinaryCategory<OP, LHSExpr, RHSExpr>, Dev>& expr) 00068 : lhsExpr(expr.left_impl()),rhsExpr(expr.right_impl()),func(expr.functor()) {} 00069 }; 00070 00073 template <template <class, class, class> class BinaryCategory, typename OP, typename LHSExpr, typename RHSExpr, typename Dev> 00074 struct FunctorExtractor<TensorEvaluator<BinaryCategory<OP, LHSExpr, RHSExpr>, Dev> > 00075 : FunctorExtractor<TensorEvaluator<const BinaryCategory<OP, LHSExpr, RHSExpr>, Dev> >{}; 00076 00079 template <template <class, class, class, class> class TernaryCategory, typename OP, typename Arg1Expr, typename Arg2Expr, typename Arg3Expr,typename Dev> 00080 struct FunctorExtractor<TensorEvaluator<const TernaryCategory<OP, Arg1Expr, Arg2Expr, Arg3Expr>, Dev> > { 00081 FunctorExtractor<TensorEvaluator<Arg1Expr, Dev> > arg1Expr; 00082 FunctorExtractor<TensorEvaluator<Arg2Expr, Dev> > arg2Expr; 00083 FunctorExtractor<TensorEvaluator<Arg3Expr, Dev> > arg3Expr; 00084 OP func; 00085 FunctorExtractor(const TensorEvaluator<const TernaryCategory<OP, Arg1Expr, Arg2Expr, Arg3Expr>, Dev>& expr) 00086 : arg1Expr(expr.arg1Impl()), arg2Expr(expr.arg2Impl()), arg3Expr(expr.arg3Impl()), func(expr.functor()) {} 00087 }; 00088 00091 template <template <class, class, class, class> class TernaryCategory, typename OP, typename Arg1Expr, typename Arg2Expr, typename Arg3Expr, typename Dev> 00092 struct FunctorExtractor<TensorEvaluator< TernaryCategory<OP, Arg1Expr, Arg2Expr, Arg3Expr>, Dev> > 00093 :FunctorExtractor<TensorEvaluator<const TernaryCategory<OP, Arg1Expr, Arg2Expr, Arg3Expr>, Dev> >{}; 00094 00097 template <typename IfExpr, typename ThenExpr, typename ElseExpr, typename Dev> 00098 struct FunctorExtractor< TensorEvaluator<const TensorSelectOp<IfExpr, ThenExpr, ElseExpr>, Dev> > { 00099 FunctorExtractor<TensorEvaluator<IfExpr, Dev> > ifExpr; 00100 FunctorExtractor<TensorEvaluator<ThenExpr, Dev> > thenExpr; 00101 FunctorExtractor<TensorEvaluator<ElseExpr, Dev> > elseExpr; 00102 FunctorExtractor(const TensorEvaluator<const TensorSelectOp<IfExpr, ThenExpr, ElseExpr>, Dev>& expr) 00103 : ifExpr(expr.cond_impl()), thenExpr(expr.then_impl()), elseExpr(expr.else_impl()) {} 00104 }; 00105 00108 template <typename IfExpr, typename ThenExpr, typename ElseExpr, typename Dev> 00109 struct FunctorExtractor<TensorEvaluator<TensorSelectOp<IfExpr, ThenExpr, ElseExpr>, Dev> > 00110 :FunctorExtractor< TensorEvaluator<const TensorSelectOp<IfExpr, ThenExpr, ElseExpr>, Dev> > {}; 00111 00114 template <typename LHSExpr, typename RHSExpr, typename Dev> 00115 struct FunctorExtractor<TensorEvaluator<const TensorAssignOp<LHSExpr, RHSExpr>, Dev> > { 00116 FunctorExtractor<TensorEvaluator<LHSExpr, Dev> > lhsExpr; 00117 FunctorExtractor<TensorEvaluator<RHSExpr, Dev> > rhsExpr; 00118 FunctorExtractor(const TensorEvaluator<const TensorAssignOp<LHSExpr, RHSExpr>, Dev>& expr) 00119 : lhsExpr(expr.left_impl()), rhsExpr(expr.right_impl()) {} 00120 }; 00121 00124 template <typename LHSExpr, typename RHSExpr, typename Dev> 00125 struct FunctorExtractor<TensorEvaluator<TensorAssignOp<LHSExpr, RHSExpr>, Dev> > 00126 :FunctorExtractor<TensorEvaluator<const TensorAssignOp<LHSExpr, RHSExpr>, Dev> >{}; 00127 00128 00131 template <typename RHSExpr, typename Dev> 00132 struct FunctorExtractor<TensorEvaluator<const TensorEvalToOp<RHSExpr>, Dev> > { 00133 FunctorExtractor<TensorEvaluator<RHSExpr, Dev> > rhsExpr; 00134 FunctorExtractor(const TensorEvaluator<const TensorEvalToOp<RHSExpr>, Dev>& expr) 00135 : rhsExpr(expr.impl()) {} 00136 }; 00137 00140 template <typename RHSExpr, typename Dev> 00141 struct FunctorExtractor<TensorEvaluator<TensorEvalToOp<RHSExpr>, Dev> > 00142 : FunctorExtractor<TensorEvaluator<const TensorEvalToOp<RHSExpr>, Dev> > {}; 00143 00144 template<typename Dim, size_t NumOutputDim> struct DimConstr { 00145 template<typename InDim> 00146 static inline Dim getDim(InDim dims ) {return dims;} 00147 }; 00148 00149 template<typename Dim> struct DimConstr<Dim, 0> { 00150 template<typename InDim> 00151 static inline Dim getDim(InDim dims ) {return Dim(dims.TotalSize());} 00152 }; 00153 00154 template<typename Op, typename Dims, typename ArgType, template <class> class MakePointer_, typename Device> 00155 struct FunctorExtractor<TensorEvaluator<const TensorReductionOp<Op, Dims, ArgType, MakePointer_>, Device>>{ 00156 typedef TensorEvaluator<const TensorReductionOp<Op, Dims, ArgType, MakePointer_>, Device> Evaluator; 00157 typedef typename Eigen::internal::conditional<Evaluator::NumOutputDims==0, DSizes<typename Evaluator::Index, 1>, typename Evaluator::Dimensions >::type Dimensions; 00158 const Dimensions m_dimensions; 00159 const Dimensions& dimensions() const { return m_dimensions; } 00160 FunctorExtractor(const TensorEvaluator<const TensorReductionOp<Op, Dims, ArgType, MakePointer_>, Device>& expr) 00161 : m_dimensions(DimConstr<Dimensions, Evaluator::NumOutputDims>::getDim(expr.dimensions())) {} 00162 }; 00163 00164 00165 template<typename Op, typename Dims, typename ArgType, template <class> class MakePointer_, typename Device> 00166 struct FunctorExtractor<TensorEvaluator<TensorReductionOp<Op, Dims, ArgType, MakePointer_>, Device>> 00167 : FunctorExtractor<TensorEvaluator<const TensorReductionOp<Op, Dims, ArgType, MakePointer_>, Device>>{}; 00169 template <typename Evaluator> 00170 auto inline extractFunctors(const Evaluator& evaluator)-> FunctorExtractor<Evaluator> { 00171 return FunctorExtractor<Evaluator>(evaluator); 00172 } 00173 } // namespace internal 00174 } // namespace TensorSycl 00175 } // namespace Eigen 00176 00177 #endif // UNSUPPORTED_EIGEN_CXX11_SRC_TENSOR_TENSORSYCL_EXTRACT_FUNCTORS_HPP