1 /*!
2  * \file   include/TFEL/Math/Matrix/tmatrixResultType.hxx
3  * \brief  this file implements partial specialisations of the ResultType and GenerateMatrix traits class for tmatrix.
4  * \author Thomas Helfer
5  * \date   12 Jul 2006
6  * \copyright Copyright (C) 2006-2018 CEA/DEN, EDF R&D. All rights
7  * reserved.
8  * This project is publicly released under either the GNU GPL Licence
9  * or the CECILL-A licence. A copy of thoses licences are delivered
10  * with the sources of TFEL. CEA or EDF may also distribute this
11  * project under specific licensing conditions.
12  */
13 
14 #ifndef LIB_TFEL_TINY_MATRIX_RESULT_TYPE_HXX
15 #define LIB_TFEL_TINY_MATRIX_RESULT_TYPE_HXX
16 
17 #include"TFEL/Math/tvector.hxx"
18 #include"TFEL/Math/tmatrix.hxx"
19 #include"TFEL/Math/Matrix/TVectorTMatrixExpr.hxx"
20 #include"TFEL/Math/Matrix/TMatrixTVectorExpr.hxx"
21 
22 namespace tfel{
23 
24   namespace math{
25 
26     /*
27      * Partial specialisation for negation.
28      */
29     template<unsigned short N,unsigned short M,typename T>
30     class UnaryResultType<tmatrix<N,M,T>,OpNeg>
31     {
32       typedef typename UnaryResultType<T,OpNeg>::type ResBase_;
33     public:
34       typedef typename std::conditional<tfel::typetraits::IsInvalid<ResBase_>::cond,
35 				      tfel::meta::InvalidType,
36 				      tmatrix<N,M,ResBase_> >::type type;
37     };
38 
39     /*!
40      * \brief Partial specialisation for tmatrix and
41      * scalars operations
42      * \see   ResultType_
43      */
44     template<unsigned short N,unsigned short M, typename T, typename Scal>
45     class ResultType_<MatrixTag,ScalarTag,tmatrix<N,M,T>,Scal,OpMult>
46     {
47       typedef typename ResultType<T,Scal,OpMult>::type ResBase_;
48     public:
49       typedef typename std::conditional<tfel::typetraits::IsInvalid<ResBase_>::cond,
50 				      tfel::meta::InvalidType,
51 				      tmatrix<N,M,ResBase_> >::type type;
52     };
53 
54     /*!
55      * \brief Partial specialisation for tmatrix and
56      * scalars operations
57      * \see   ResultType_
58      */
59     template<unsigned short N,unsigned short M, typename T, typename Scal>
60     class ResultType_<MatrixTag,ScalarTag,tmatrix<N,M,T>,Scal,OpDiv>
61     {
62       typedef typename ResultType<T,Scal,OpDiv>::type ResBase_;
63     public:
64       typedef typename std::conditional<tfel::typetraits::IsInvalid<ResBase_>::cond,
65 				      tfel::meta::InvalidType,
66 				      tmatrix<N,M,ResBase_> >::type type;
67     };
68 
69     /*!
70      * \brief Partial specialisation for tmatrix and
71      * scalars operations
72      * \see   ResultType_
73      */
74     template<typename Scal,unsigned short N,unsigned short M, typename T>
75     class ResultType_<ScalarTag,MatrixTag,Scal,tmatrix<N,M,T>,OpMult>
76     {
77       typedef typename ResultType<Scal,T,OpMult>::type ResBase_;
78     public:
79       typedef typename std::conditional<tfel::typetraits::IsInvalid<ResBase_>::cond,
80 				      tfel::meta::InvalidType,
81 				      tmatrix<N,M,ResBase_> >::type type;
82     };
83 
84     /*!
85      * \brief Partial specialisation for tmatrix
86      * \see   ResultType
87      */
88     template<unsigned short N,unsigned short M, typename T, typename T2>
89     class ResultType<tmatrix<N,M,T>,tmatrix<N,M,T2>,OpPlus>
90     {
91       typedef typename ResultType<T,T2,OpPlus>::type ResBase_;
92     public:
93       typedef typename std::conditional<tfel::typetraits::IsInvalid<ResBase_>::cond,
94 				      tfel::meta::InvalidType,
95 				      tmatrix<N,M,ResBase_> >::type type;
96     };
97 
98     /*!
99      * \brief Partial specialisation for tmatrix
100      * \see   ResultType
101      */
102     template<unsigned short N,unsigned short M, typename T, typename T2>
103     class ResultType<tmatrix<N,M,T>,tmatrix<N,M,T2>,OpMinus>
104     {
105       typedef typename ResultType<T,T2,OpMinus>::type ResBase_;
106     public:
107       typedef typename std::conditional<tfel::typetraits::IsInvalid<ResBase_>::cond,
108 				      tfel::meta::InvalidType,
109 				      tmatrix<N,M,ResBase_> >::type type;
110     };
111 
112     template<unsigned short N,unsigned short M, typename T, typename T2>
113     class ResultType<tmatrix<N,M,T>,tvector<M,T2>,OpMult>
114     {
115       typedef typename ResultType<T,T2,OpMult>::type ResBase_;
116     public:
117       typedef typename std::conditional<tfel::typetraits::IsInvalid<ResBase_>::cond,
118 				      tfel::meta::InvalidType,
119 				      tvector<N,ResBase_> >::type type;
120     }; // end of ComputeBinaryResult.
121 
122     template<unsigned short N,unsigned short M, typename T, typename T2>
123     class ResultType<tvector<N,T>,tmatrix<N,M,T2>,OpMult>
124     {
125       typedef typename ResultType<T,T2,OpMult>::type ResBase_;
126     public:
127       typedef typename std::conditional<tfel::typetraits::IsInvalid<ResBase_>::cond,
128 				      tfel::meta::InvalidType,
129 				      tvector<M,ResBase_> >::type type;
130     }; // end of ComputeBinaryResult.
131 
132     template<unsigned short N,unsigned short M,
133 	     typename T, typename T2,
134 	     typename A, typename B>
135     class MatrixVectorHandle<tmatrix<N,M,T>,tvector<M,T2>,A,B>
136     {
137       struct DummyHandle
138       {};
139     public:
140       typedef Expr<typename ResultType<tmatrix<N,M,T>,tvector<M,T2>,OpMult>::type,
141 		   TMatrixTVectorExpr<N,M,A,B> > type;
142     };
143 
144     template<unsigned short N,unsigned short M,
145 	     typename T, typename T2,
146 	     typename A, typename B>
147     class MatrixVectorHandle<tvector<N,T>,tmatrix<N,M,T2>,A,B>
148     {
149       struct DummyHandle
150       {};
151     public:
152       typedef Expr<typename ResultType<tvector<N,T>,tmatrix<N,M,T2>,OpMult>::type,
153 		   TVectorTMatrixExpr<N,M,A,B> > type;
154     };
155 
156   } // end of namespace math
157 
158 } // end of namespace tfel
159 
160 
161 #endif /* LIB_TFEL_TINY_MATRIX_RESULT_TYPE_HXX */
162 
163