1 // This file is part of Eigen, a lightweight C++ template library 2 // for linear algebra. 3 // 4 // Mehdi Goli Codeplay Software Ltd. 5 // Ralph Potter Codeplay Software Ltd. 6 // Luke Iwanski Codeplay Software Ltd. 7 // Contact: <eigen@codeplay.com> 8 // 9 // This Source Code Form is subject to the terms of the Mozilla 10 // Public License v. 2.0. If a copy of the MPL was not distributed 11 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 12 13 /***************************************************************** 14 * TensorSyclLeafCount.h 15 * 16 * \brief: 17 * The leaf count used the pre-order expression tree traverse in order to name 18 * count the number of leaf nodes in the expression 19 * 20 *****************************************************************/ 21 22 #ifndef UNSUPPORTED_EIGEN_CXX11_SRC_TENSOR_TENSORSYCL_LEAF_COUNT_HPP 23 #define UNSUPPORTED_EIGEN_CXX11_SRC_TENSOR_TENSORSYCL_LEAF_COUNT_HPP 24 25 namespace Eigen { 26 namespace TensorSycl { 27 namespace internal { 28 /// \brief LeafCount used to counting terminal nodes. The total number of 29 /// leaf nodes is used by MakePlaceHolderExprHelper to find the order 30 /// of the leaf node in a expression tree at compile time. 31 template <typename Expr> 32 struct LeafCount; 33 34 template<typename... Args> struct CategoryCount; 35 36 template<> struct CategoryCount<> 37 { 38 static const size_t Count =0; 39 }; 40 41 template<typename Arg, typename... Args> 42 struct CategoryCount<Arg,Args...>{ 43 static const size_t Count = LeafCount<Arg>::Count + CategoryCount<Args...>::Count; 44 }; 45 46 /// specialisation of the \ref LeafCount struct when the node type is const TensorMap 47 template <typename PlainObjectType, int Options_, template <class> class MakePointer_> 48 struct LeafCount<const TensorMap<PlainObjectType, Options_, MakePointer_> > { 49 static const size_t Count =1; 50 }; 51 52 /// specialisation of the \ref LeafCount struct when the node type is TensorMap 53 template <typename PlainObjectType, int Options_, template <class> class MakePointer_> 54 struct LeafCount<TensorMap<PlainObjectType, Options_, MakePointer_> > :LeafCount<const TensorMap<PlainObjectType, Options_, MakePointer_> >{}; 55 56 // const TensorCwiseUnaryOp, const TensorCwiseNullaryOp, const TensorCwiseBinaryOp, const TensorCwiseTernaryOp, and Const TensorBroadcastingOp 57 template <template <class, class...> class CategoryExpr, typename OP, typename... RHSExpr> 58 struct LeafCount<const CategoryExpr<OP, RHSExpr...> >: CategoryCount<RHSExpr...> {}; 59 // TensorCwiseUnaryOp, TensorCwiseNullaryOp, TensorCwiseBinaryOp, TensorCwiseTernaryOp, and TensorBroadcastingOp 60 template <template <class, class...> class CategoryExpr, typename OP, typename... RHSExpr> 61 struct LeafCount<CategoryExpr<OP, RHSExpr...> > :LeafCount<const CategoryExpr<OP, RHSExpr...> >{}; 62 63 /// specialisation of the \ref LeafCount struct when the node type is const TensorSelectOp is an exception 64 template <typename IfExpr, typename ThenExpr, typename ElseExpr> 65 struct LeafCount<const TensorSelectOp<IfExpr, ThenExpr, ElseExpr> > : CategoryCount<IfExpr, ThenExpr, ElseExpr> {}; 66 /// specialisation of the \ref LeafCount struct when the node type is TensorSelectOp 67 template <typename IfExpr, typename ThenExpr, typename ElseExpr> 68 struct LeafCount<TensorSelectOp<IfExpr, ThenExpr, ElseExpr> >: LeafCount<const TensorSelectOp<IfExpr, ThenExpr, ElseExpr> > {}; 69 70 71 /// specialisation of the \ref LeafCount struct when the node type is const TensorAssignOp 72 template <typename LHSExpr, typename RHSExpr> 73 struct LeafCount<const TensorAssignOp<LHSExpr, RHSExpr> >: CategoryCount<LHSExpr,RHSExpr> {}; 74 75 /// specialisation of the \ref LeafCount struct when the node type is 76 /// TensorAssignOp is an exception. It is not the same as Unary 77 template <typename LHSExpr, typename RHSExpr> 78 struct LeafCount<TensorAssignOp<LHSExpr, RHSExpr> > :LeafCount<const TensorAssignOp<LHSExpr, RHSExpr> >{}; 79 80 /// specialisation of the \ref LeafCount struct when the node type is const TensorForcedEvalOp 81 template <typename Expr> 82 struct LeafCount<const TensorForcedEvalOp<Expr> > { 83 static const size_t Count =1; 84 }; 85 86 /// specialisation of the \ref LeafCount struct when the node type is TensorForcedEvalOp 87 template <typename Expr> 88 struct LeafCount<TensorForcedEvalOp<Expr> >: LeafCount<const TensorForcedEvalOp<Expr> > {}; 89 90 /// specialisation of the \ref LeafCount struct when the node type is const TensorEvalToOp 91 template <typename Expr> 92 struct LeafCount<const TensorEvalToOp<Expr> > { 93 static const size_t Count = 1 + CategoryCount<Expr>::Count; 94 }; 95 96 /// specialisation of the \ref LeafCount struct when the node type is const TensorReductionOp 97 template <typename OP, typename Dim, typename Expr> 98 struct LeafCount<const TensorReductionOp<OP, Dim, Expr> > { 99 static const size_t Count =1; 100 }; 101 102 /// specialisation of the \ref LeafCount struct when the node type is TensorReductionOp 103 template <typename OP, typename Dim, typename Expr> 104 struct LeafCount<TensorReductionOp<OP, Dim, Expr> >: LeafCount<const TensorReductionOp<OP, Dim, Expr> >{}; 105 106 /// specialisation of the \ref LeafCount struct when the node type is TensorEvalToOp 107 template <typename Expr> 108 struct LeafCount<TensorEvalToOp<Expr> >: LeafCount<const TensorEvalToOp<Expr> >{}; 109 110 } /// namespace TensorSycl 111 } /// namespace internal 112 } /// namespace Eigen 113 114 #endif // UNSUPPORTED_EIGEN_CXX11_SRC_TENSOR_TENSORSYCL_LEAF_COUNT_HPP 115