]>
Dogcows Code - chaz/yoink/blob - cml/matrix/matop_macros.h
1 /* -*- C++ -*- ------------------------------------------------------------
3 Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
5 The Configurable Math Library (CML) is distributed under the terms of the
6 Boost Software License, v1.0 (see cml/LICENSE for details).
8 *-----------------------------------------------------------------------*/
10 * @brief Defines the various combinations of matrix expressions.
12 * Create unary and binary operators with macros. The available combinations
22 * Matrix op Matrix -> Matrix
23 * MatXpr op Matrix -> MatXpr
24 * Matrix op MatXpr -> MatXpr
25 * MatXpr op MatXpr -> MatXpr
27 * Matrix op Scalar -> Matrix
28 * Scalar op Matrix -> Matrix
29 * MatXpr op Scalar -> MatXpr
30 * Scalar op MatXpr -> MatXpr
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.
37 #ifndef matop_macros_h
38 #define matop_macros_h
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> > \
47 _op_ (const matrix<E,AT,BO,L>& arg) \
49 typedef et::UnaryMatrixOp< \
50 matrix<E,AT,BO,L>, _OpT_ <E> \
52 return et::MatrixXpr<ExprT>(ExprT(arg)); \
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> > \
62 _op_ (MATXPR_ARG_TYPE arg) \
64 typedef et::UnaryMatrixOp< \
65 XprT, _OpT_<typename XprT::value_type> \
67 return et::MatrixXpr<ExprT>(ExprT(arg.expression())); \
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< \
76 matrix<E1,AT1,BO,L2>, matrix<E2,AT2,BO,L2>, _OpT_<E1,E2> > \
80 const matrix<E1,AT1,BO,L1>& left, \
81 const matrix<E2,AT2,BO,L2>& right) \
83 typedef et::BinaryMatrixOp< \
84 matrix<E1,AT1,BO,L1>, matrix<E2,AT2,BO,L2>, _OpT_<E1,E2> \
86 return et::MatrixXpr<ExprT>(ExprT(left,right)); \
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< \
94 matrix<E,AT,BO,L>, XprT, _OpT_ <E, typename XprT::value_type> \
99 const matrix<E,AT,BO,L>& left, \
100 MATXPR_ARG_TYPE right) \
102 typedef et::BinaryMatrixOp< \
103 matrix<E,AT,BO,L>, XprT, \
104 _OpT_ <E, typename XprT::value_type> \
106 return et::MatrixXpr<ExprT>(ExprT(left,right.expression())); \
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> \
119 MATXPR_ARG_TYPE left, \
120 const matrix<E,AT,BO,L>& right) \
122 typedef et::BinaryMatrixOp< \
123 XprT, matrix<E,AT,BO,L>, \
124 _OpT_ <typename XprT::value_type, E> \
126 return et::MatrixXpr<ExprT>(ExprT(left.expression(),right)); \
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< \
136 typename XprT1::value_type, \
137 typename XprT2::value_type \
143 MATXPR_ARG_TYPE_N(1) left, \
144 MATXPR_ARG_TYPE_N(2) right) \
146 typedef et::BinaryMatrixOp< \
149 typename XprT1::value_type, \
150 typename XprT2::value_type> \
152 return et::MatrixXpr<ExprT>( \
153 ExprT(left.expression(),right.expression())); \
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> \
167 const matrix<E,AT,BO,L>& left, \
168 SCALAR_ARG_TYPE right) \
170 typedef et::BinaryMatrixOp< \
171 matrix<E,AT,BO,L>, ScalarT, _OpT_ <E,ScalarT > \
173 return et::MatrixXpr<ExprT>(ExprT(left,right)); \
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> \
186 SCALAR_ARG_TYPE left, \
187 const matrix<E,AT,BO,L>& right) \
189 typedef et::BinaryMatrixOp< \
190 ScalarT, matrix<E,AT,BO,L>, _OpT_<ScalarT,E> \
192 return et::MatrixXpr<ExprT>(ExprT(left,right)); \
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> \
205 MATXPR_ARG_TYPE left, \
206 SCALAR_ARG_TYPE right) \
208 typedef et::BinaryMatrixOp< \
209 XprT, ScalarT, _OpT_ <typename XprT::value_type,ScalarT> \
211 return et::MatrixXpr<ExprT>(ExprT(left.expression(),right)); \
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> \
224 SCALAR_ARG_TYPE left, \
225 MATXPR_ARG_TYPE right) \
227 typedef et::BinaryMatrixOp< \
228 ScalarT, XprT, _OpT_ <ScalarT, typename XprT::value_type> \
230 return et::MatrixXpr<ExprT>(ExprT(left,right.expression())); \
235 // -------------------------------------------------------------------------
This page took 0.04686 seconds and 4 git commands to generate.