1 /*! 2 * \file include/TFEL/Math/Tensor/TensorTransposeExpr.hxx 3 * \brief 4 * 5 * \author Thomas Helfer 6 * \date 07 avr 2008 7 * \copyright Copyright (C) 2006-2018 CEA/DEN, EDF R&D. All rights 8 * reserved. 9 * This project is publicly released under either the GNU GPL Licence 10 * or the CECILL-A licence. A copy of thoses licences are delivered 11 * with the sources of TFEL. CEA or EDF may also distribute this 12 * project under specific licensing conditions. 13 */ 14 15 #ifndef LIB_TFEL_MATH_TENSORTRANSPOSEEXPR_HXX 16 #define LIB_TFEL_MATH_TENSORTRANSPOSEEXPR_HXX 17 18 #include<cmath> 19 #include<cstddef> 20 21 #include"TFEL/Config/TFELConfig.hxx" 22 23 #include"TFEL/Metaprogramming/StaticAssert.hxx" 24 #include"TFEL/Metaprogramming/Implements.hxx" 25 #include"TFEL/Math/Forward/TensorConcept.hxx" 26 #include"TFEL/Math/General/ResultType.hxx" debug_exit_read(void * opaque,hwaddr addr,unsigned size)27#include"TFEL/Math/General/EmptyRunTimeProperties.hxx" 28 #include"TFEL/Math/ExpressionTemplates/Expr.hxx" 29 30 namespace tfel{ 31 32 namespace math { 33 34 template<typename A> 35 struct TFEL_VISIBILITY_LOCAL TensorTransposeExprBase 36 : public ExprBase 37 { 38 typedef EmptyRunTimeProperties RunTimeProperties; 39 typedef typename TensorTraits<typename std::decay<A>::type>::IndexType IndexType; 40 typedef typename TensorTraits<typename std::decay<A>::type>::NumType NumType; 41 42 TFEL_MATH_INLINE RunTimeProperties 43 getRunTimeProperties() const 44 { 45 return EmptyRunTimeProperties(); 46 } 47 48 protected: 49 50 typedef NumType value_type; 51 typedef NumType* pointer; 52 typedef const NumType* const_pointer; 53 typedef NumType& reference; 54 typedef const NumType& const_reference; 55 typedef IndexType size_type; 56 typedef ptrdiff_t difference_type; 57 58 TFEL_MATH_INLINE TensorTransposeExprBase(A l) 59 : a(l) 60 {} 61 62 ArgumentStorage<A> a; 63 64 private: 65 TFEL_STATIC_ASSERT((tfel::meta::Implements<typename std::decay<A>::type,TensorConcept>::cond)); 66 67 }; 68 69 template<typename A> 70 struct TFEL_VISIBILITY_LOCAL TensorTransposeExpr1D 71 : public TensorTransposeExprBase<A> 72 { 73 74 TFEL_MATH_INLINE TensorTransposeExpr1D(A l) 75 : TensorTransposeExprBase<A>(std::forward<A>(l)) 76 {} 77 78 TFEL_MATH_INLINE typename TensorTransposeExprBase<A>::NumType 79 operator()(const typename TensorTransposeExprBase<A>::IndexType i) const 80 { 81 return this->a(i); 82 } // end of operator() 83 84 private: 85 86 TFEL_STATIC_ASSERT((tfel::math::TensorTraits<typename std::decay<A>::type>::dime==1u)); 87 }; 88 89 template<typename A> 90 struct TFEL_VISIBILITY_LOCAL TensorTransposeExpr2D 91 : public TensorTransposeExprBase<A> 92 { 93 94 TFEL_MATH_INLINE TensorTransposeExpr2D(A l) 95 : TensorTransposeExprBase<A>(std::forward<A>(l)) 96 {} 97 98 TFEL_MATH_INLINE typename TensorTransposeExprBase<A>::NumType 99 operator()(const typename TensorTransposeExprBase<A>::IndexType i) const 100 { 101 constexpr const typename TensorTransposeExprBase<A>::NumType zero{0}; 102 switch(i){ 103 case 0: 104 return this->a(0); 105 break; 106 case 1: 107 return this->a(1); 108 break; 109 case 2: 110 return this->a(2); 111 break; 112 case 3: 113 return this->a(4); 114 break; 115 case 4: 116 return this->a(3); 117 break; 118 default: 119 break; 120 } 121 return zero; 122 } // end of operator() 123 124 private: 125 126 TFEL_STATIC_ASSERT((tfel::math::TensorTraits<typename std::decay<A>::type>::dime==2u)); 127 }; 128 129 template<typename A> 130 struct TFEL_VISIBILITY_LOCAL TensorTransposeExpr3D 131 : public TensorTransposeExprBase<A> 132 { 133 134 TFEL_MATH_INLINE TensorTransposeExpr3D(A l) 135 : TensorTransposeExprBase<A>(std::forward<A>(l)) 136 {} 137 138 TFEL_MATH_INLINE typename TensorTransposeExprBase<A>::NumType 139 operator()(const typename TensorTransposeExprBase<A>::IndexType i) const 140 { 141 constexpr const typename TensorTransposeExprBase<A>::NumType zero{0}; 142 switch(i){ 143 case 0: 144 return this->a(0); 145 break; 146 case 1: 147 return this->a(1); 148 break; 149 case 2: 150 return this->a(2); 151 break; 152 case 3: 153 return this->a(4); 154 break; 155 case 4: 156 return this->a(3); 157 break; 158 case 5: 159 return this->a(6); 160 break; 161 case 6: 162 return this->a(5); 163 break; 164 case 7: 165 return this->a(8); 166 break; 167 case 8: 168 return this->a(7); 169 break; 170 default: 171 break; 172 } 173 return zero; 174 } // end of operator() 175 176 private: 177 178 TFEL_STATIC_ASSERT((tfel::math::TensorTraits<typename std::decay<A>::type>::dime==3u)); 179 }; 180 181 } // end of namespace math 182 183 } // end of namespace tfel 184 185 #endif /* LIB_TFEL_MATH_TENSORTRANSPOSEEXPR_HXX */ 186