]> Dogcows Code - chaz/yoink/blob - src/cml/matrix/matop_macros.h
testing new non-autotools build system
[chaz/yoink] / src / cml / matrix / matop_macros.h
1 /* -*- C++ -*- ------------------------------------------------------------
2
3 Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
4
5 The Configurable Math Library (CML) is distributed under the terms of the
6 Boost Software License, v1.0 (see cml/LICENSE for details).
7
8 *-----------------------------------------------------------------------*/
9 /** @file
10 * @brief Defines the various combinations of matrix expressions.
11 *
12 * Create unary and binary operators with macros. The available combinations
13 * are:
14 *
15 * Unary expressions:
16 *
17 * op Matrix -> Matrix
18 * op MatXpr -> Matrix
19 *
20 * Binary expressions:
21 *
22 * Matrix op Matrix -> Matrix
23 * MatXpr op Matrix -> MatXpr
24 * Matrix op MatXpr -> MatXpr
25 * MatXpr op MatXpr -> MatXpr
26 *
27 * Matrix op Scalar -> Matrix
28 * Scalar op Matrix -> Matrix
29 * MatXpr op Scalar -> MatXpr
30 * Scalar op MatXpr -> MatXpr
31 *
32 * All of the generator functions compress the expression tree by hoisting
33 * subexpressions into the containing expression. This has the effect of
34 * forcing only the root node of the expression tree to be a MatrixXpr.
35 * Every other node is a Unary or BinaryMatrixOp.
36 */
37 #ifndef matop_macros_h
38 #define matop_macros_h
39
40 /** Declare a unary operator taking a matrix operand. */
41 #define CML_MAT_UNIOP(_op_, _OpT_) \
42 template<typename E, class AT, typename BO, typename L> \
43 inline et::MatrixXpr< \
44 et::UnaryMatrixOp< matrix<E,AT,BO,L>, _OpT_ <E> > \
45 > \
46 \
47 _op_ (const matrix<E,AT,BO,L>& arg) \
48 { \
49 typedef et::UnaryMatrixOp< \
50 matrix<E,AT,BO,L>, _OpT_ <E> \
51 > ExprT; \
52 return et::MatrixXpr<ExprT>(ExprT(arg)); \
53 }
54
55 /** Declare a unary operator taking a et::MatrixXpr operand. */
56 #define CML_MATXPR_UNIOP(_op_, _OpT_) \
57 template<class XprT> \
58 inline et::MatrixXpr< \
59 et::UnaryMatrixOp<XprT, _OpT_<typename XprT::value_type> > \
60 > \
61 \
62 _op_ (MATXPR_ARG_TYPE arg) \
63 { \
64 typedef et::UnaryMatrixOp< \
65 XprT, _OpT_<typename XprT::value_type> \
66 > ExprT; \
67 return et::MatrixXpr<ExprT>(ExprT(arg.expression())); \
68 }
69
70 /** Declare an operator taking two matrix operands. */
71 #define CML_MAT_MAT_BINOP(_op_, _OpT_) \
72 template<typename E1, class AT1, typename L1, \
73 typename E2, class AT2, typename L2, typename BO> \
74 inline et::MatrixXpr< \
75 et::BinaryMatrixOp< \
76 matrix<E1,AT1,BO,L2>, matrix<E2,AT2,BO,L2>, _OpT_<E1,E2> > \
77 > \
78 \
79 _op_ ( \
80 const matrix<E1,AT1,BO,L1>& left, \
81 const matrix<E2,AT2,BO,L2>& right) \
82 { \
83 typedef et::BinaryMatrixOp< \
84 matrix<E1,AT1,BO,L1>, matrix<E2,AT2,BO,L2>, _OpT_<E1,E2> \
85 > ExprT; \
86 return et::MatrixXpr<ExprT>(ExprT(left,right)); \
87 }
88
89 /** Declare an operator taking a matrix and a et::MatrixXpr. */
90 #define CML_MAT_MATXPR_BINOP(_op_, _OpT_) \
91 template<typename E, class AT, typename BO, typename L, class XprT> \
92 inline et::MatrixXpr< \
93 et::BinaryMatrixOp< \
94 matrix<E,AT,BO,L>, XprT, _OpT_ <E, typename XprT::value_type> \
95 > \
96 > \
97 \
98 _op_ ( \
99 const matrix<E,AT,BO,L>& left, \
100 MATXPR_ARG_TYPE right) \
101 { \
102 typedef et::BinaryMatrixOp< \
103 matrix<E,AT,BO,L>, XprT, \
104 _OpT_ <E, typename XprT::value_type> \
105 > ExprT; \
106 return et::MatrixXpr<ExprT>(ExprT(left,right.expression())); \
107 }
108
109 /** Declare an operator taking a et::MatrixXpr and a matrix. */
110 #define CML_MATXPR_MAT_BINOP(_op_, _OpT_) \
111 template<class XprT, typename E, class AT, typename BO, typename L> \
112 inline et::MatrixXpr< \
113 et::BinaryMatrixOp< \
114 XprT, matrix<E,AT,BO,L>, _OpT_ <typename XprT::value_type, E> \
115 > \
116 > \
117 \
118 _op_ ( \
119 MATXPR_ARG_TYPE left, \
120 const matrix<E,AT,BO,L>& right) \
121 { \
122 typedef et::BinaryMatrixOp< \
123 XprT, matrix<E,AT,BO,L>, \
124 _OpT_ <typename XprT::value_type, E> \
125 > ExprT; \
126 return et::MatrixXpr<ExprT>(ExprT(left.expression(),right)); \
127 }
128
129 /** Declare an operator taking two et::MatrixXpr operands. */
130 #define CML_MATXPR_MATXPR_BINOP(_op_, _OpT_) \
131 template<class XprT1, class XprT2> \
132 inline et::MatrixXpr< \
133 et::BinaryMatrixOp< \
134 XprT1, XprT2, \
135 _OpT_ < \
136 typename XprT1::value_type, \
137 typename XprT2::value_type \
138 > \
139 > \
140 > \
141 \
142 _op_ ( \
143 MATXPR_ARG_TYPE_N(1) left, \
144 MATXPR_ARG_TYPE_N(2) right) \
145 { \
146 typedef et::BinaryMatrixOp< \
147 XprT1, XprT2, \
148 _OpT_ < \
149 typename XprT1::value_type, \
150 typename XprT2::value_type> \
151 > ExprT; \
152 return et::MatrixXpr<ExprT>( \
153 ExprT(left.expression(),right.expression())); \
154 }
155
156
157 /** Declare an operator taking a matrix and a scalar. */
158 #define CML_MAT_SCALAR_BINOP(_op_, _OpT_) \
159 template<typename E, class AT, typename BO, typename L, typename ScalarT>\
160 inline et::MatrixXpr< \
161 et::BinaryMatrixOp< \
162 matrix<E,AT,BO,L>, ScalarT, _OpT_ <E,ScalarT> \
163 > \
164 > \
165 \
166 _op_ ( \
167 const matrix<E,AT,BO,L>& left, \
168 SCALAR_ARG_TYPE right) \
169 { \
170 typedef et::BinaryMatrixOp< \
171 matrix<E,AT,BO,L>, ScalarT, _OpT_ <E,ScalarT > \
172 > ExprT; \
173 return et::MatrixXpr<ExprT>(ExprT(left,right)); \
174 }
175
176 /** Declare an operator taking a scalar and a matrix. */
177 #define CML_SCALAR_MAT_BINOP(_op_, _OpT_) \
178 template<typename ScalarT, typename E, class AT, typename BO, typename L>\
179 inline et::MatrixXpr< \
180 et::BinaryMatrixOp< \
181 ScalarT, matrix<E,AT,BO,L>, _OpT_ <ScalarT,E> \
182 > \
183 > \
184 \
185 _op_ ( \
186 SCALAR_ARG_TYPE left, \
187 const matrix<E,AT,BO,L>& right) \
188 { \
189 typedef et::BinaryMatrixOp< \
190 ScalarT, matrix<E,AT,BO,L>, _OpT_<ScalarT,E> \
191 > ExprT; \
192 return et::MatrixXpr<ExprT>(ExprT(left,right)); \
193 }
194
195 /** Declare an operator taking a et::MatrixXpr and a scalar. */
196 #define CML_MATXPR_SCALAR_BINOP(_op_, _OpT_) \
197 template<class XprT, typename ScalarT> \
198 inline et::MatrixXpr< \
199 et::BinaryMatrixOp< \
200 XprT, ScalarT, _OpT_ <typename XprT::value_type, ScalarT> \
201 > \
202 > \
203 \
204 _op_ ( \
205 MATXPR_ARG_TYPE left, \
206 SCALAR_ARG_TYPE right) \
207 { \
208 typedef et::BinaryMatrixOp< \
209 XprT, ScalarT, _OpT_ <typename XprT::value_type,ScalarT> \
210 > ExprT; \
211 return et::MatrixXpr<ExprT>(ExprT(left.expression(),right)); \
212 }
213
214 /** Declare an operator taking a scalar and a et::MatrixXpr. */
215 #define CML_SCALAR_MATXPR_BINOP(_op_, _OpT_) \
216 template<typename ScalarT, class XprT> \
217 inline et::MatrixXpr< \
218 et::BinaryMatrixOp< \
219 ScalarT, XprT, _OpT_ <ScalarT, typename XprT::value_type> \
220 > \
221 > \
222 \
223 _op_ ( \
224 SCALAR_ARG_TYPE left, \
225 MATXPR_ARG_TYPE right) \
226 { \
227 typedef et::BinaryMatrixOp< \
228 ScalarT, XprT, _OpT_ <ScalarT, typename XprT::value_type> \
229 > ExprT; \
230 return et::MatrixXpr<ExprT>(ExprT(left,right.expression())); \
231 }
232
233 #endif
234
235 // -------------------------------------------------------------------------
236 // vim:ft=cpp
This page took 0.041283 seconds and 4 git commands to generate.