X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fcml%2Fmatrix%2Fmatop_macros.h;fp=src%2Fcml%2Fmatrix%2Fmatop_macros.h;h=f13b67877158f066b0e0975d2b860e9a4f4e18a4;hp=0000000000000000000000000000000000000000;hb=6b0a0d0efafe34d48ab344fca3b479553bd4e62c;hpb=85783316365181491a3e3c0c63659972477cebba diff --git a/src/cml/matrix/matop_macros.h b/src/cml/matrix/matop_macros.h new file mode 100644 index 0000000..f13b678 --- /dev/null +++ b/src/cml/matrix/matop_macros.h @@ -0,0 +1,236 @@ +/* -*- C++ -*- ------------------------------------------------------------ + +Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/ + +The Configurable Math Library (CML) is distributed under the terms of the +Boost Software License, v1.0 (see cml/LICENSE for details). + + *-----------------------------------------------------------------------*/ +/** @file + * @brief Defines the various combinations of matrix expressions. + * + * Create unary and binary operators with macros. The available combinations + * are: + * + * Unary expressions: + * + * op Matrix -> Matrix + * op MatXpr -> Matrix + * + * Binary expressions: + * + * Matrix op Matrix -> Matrix + * MatXpr op Matrix -> MatXpr + * Matrix op MatXpr -> MatXpr + * MatXpr op MatXpr -> MatXpr + * + * Matrix op Scalar -> Matrix + * Scalar op Matrix -> Matrix + * MatXpr op Scalar -> MatXpr + * Scalar op MatXpr -> MatXpr + * + * All of the generator functions compress the expression tree by hoisting + * subexpressions into the containing expression. This has the effect of + * forcing only the root node of the expression tree to be a MatrixXpr. + * Every other node is a Unary or BinaryMatrixOp. + */ +#ifndef matop_macros_h +#define matop_macros_h + +/** Declare a unary operator taking a matrix operand. */ +#define CML_MAT_UNIOP(_op_, _OpT_) \ +template \ +inline et::MatrixXpr< \ + et::UnaryMatrixOp< matrix, _OpT_ > \ +> \ + \ +_op_ (const matrix& arg) \ +{ \ + typedef et::UnaryMatrixOp< \ + matrix, _OpT_ \ + > ExprT; \ + return et::MatrixXpr(ExprT(arg)); \ +} + +/** Declare a unary operator taking a et::MatrixXpr operand. */ +#define CML_MATXPR_UNIOP(_op_, _OpT_) \ +template \ +inline et::MatrixXpr< \ + et::UnaryMatrixOp > \ +> \ + \ +_op_ (MATXPR_ARG_TYPE arg) \ +{ \ + typedef et::UnaryMatrixOp< \ + XprT, _OpT_ \ + > ExprT; \ + return et::MatrixXpr(ExprT(arg.expression())); \ +} + +/** Declare an operator taking two matrix operands. */ +#define CML_MAT_MAT_BINOP(_op_, _OpT_) \ +template \ +inline et::MatrixXpr< \ + et::BinaryMatrixOp< \ + matrix, matrix, _OpT_ > \ +> \ + \ +_op_ ( \ + const matrix& left, \ + const matrix& right) \ +{ \ + typedef et::BinaryMatrixOp< \ + matrix, matrix, _OpT_ \ + > ExprT; \ + return et::MatrixXpr(ExprT(left,right)); \ +} + +/** Declare an operator taking a matrix and a et::MatrixXpr. */ +#define CML_MAT_MATXPR_BINOP(_op_, _OpT_) \ +template \ +inline et::MatrixXpr< \ + et::BinaryMatrixOp< \ + matrix, XprT, _OpT_ \ + > \ +> \ + \ +_op_ ( \ + const matrix& left, \ + MATXPR_ARG_TYPE right) \ +{ \ + typedef et::BinaryMatrixOp< \ + matrix, XprT, \ + _OpT_ \ + > ExprT; \ + return et::MatrixXpr(ExprT(left,right.expression())); \ +} + +/** Declare an operator taking a et::MatrixXpr and a matrix. */ +#define CML_MATXPR_MAT_BINOP(_op_, _OpT_) \ +template \ +inline et::MatrixXpr< \ + et::BinaryMatrixOp< \ + XprT, matrix, _OpT_ \ + > \ +> \ + \ +_op_ ( \ + MATXPR_ARG_TYPE left, \ + const matrix& right) \ +{ \ + typedef et::BinaryMatrixOp< \ + XprT, matrix, \ + _OpT_ \ + > ExprT; \ + return et::MatrixXpr(ExprT(left.expression(),right)); \ +} + +/** Declare an operator taking two et::MatrixXpr operands. */ +#define CML_MATXPR_MATXPR_BINOP(_op_, _OpT_) \ +template \ +inline et::MatrixXpr< \ + et::BinaryMatrixOp< \ + XprT1, XprT2, \ + _OpT_ < \ + typename XprT1::value_type, \ + typename XprT2::value_type \ + > \ + > \ +> \ + \ +_op_ ( \ + MATXPR_ARG_TYPE_N(1) left, \ + MATXPR_ARG_TYPE_N(2) right) \ +{ \ + typedef et::BinaryMatrixOp< \ + XprT1, XprT2, \ + _OpT_ < \ + typename XprT1::value_type, \ + typename XprT2::value_type> \ + > ExprT; \ + return et::MatrixXpr( \ + ExprT(left.expression(),right.expression())); \ +} + + +/** Declare an operator taking a matrix and a scalar. */ +#define CML_MAT_SCALAR_BINOP(_op_, _OpT_) \ +template\ +inline et::MatrixXpr< \ + et::BinaryMatrixOp< \ + matrix, ScalarT, _OpT_ \ + > \ +> \ + \ +_op_ ( \ + const matrix& left, \ + SCALAR_ARG_TYPE right) \ +{ \ + typedef et::BinaryMatrixOp< \ + matrix, ScalarT, _OpT_ \ + > ExprT; \ + return et::MatrixXpr(ExprT(left,right)); \ +} + +/** Declare an operator taking a scalar and a matrix. */ +#define CML_SCALAR_MAT_BINOP(_op_, _OpT_) \ +template\ +inline et::MatrixXpr< \ + et::BinaryMatrixOp< \ + ScalarT, matrix, _OpT_ \ + > \ +> \ + \ +_op_ ( \ + SCALAR_ARG_TYPE left, \ + const matrix& right) \ +{ \ + typedef et::BinaryMatrixOp< \ + ScalarT, matrix, _OpT_ \ + > ExprT; \ + return et::MatrixXpr(ExprT(left,right)); \ +} + +/** Declare an operator taking a et::MatrixXpr and a scalar. */ +#define CML_MATXPR_SCALAR_BINOP(_op_, _OpT_) \ +template \ +inline et::MatrixXpr< \ + et::BinaryMatrixOp< \ + XprT, ScalarT, _OpT_ \ + > \ +> \ + \ +_op_ ( \ + MATXPR_ARG_TYPE left, \ + SCALAR_ARG_TYPE right) \ +{ \ + typedef et::BinaryMatrixOp< \ + XprT, ScalarT, _OpT_ \ + > ExprT; \ + return et::MatrixXpr(ExprT(left.expression(),right)); \ +} + +/** Declare an operator taking a scalar and a et::MatrixXpr. */ +#define CML_SCALAR_MATXPR_BINOP(_op_, _OpT_) \ +template \ +inline et::MatrixXpr< \ + et::BinaryMatrixOp< \ + ScalarT, XprT, _OpT_ \ + > \ +> \ + \ +_op_ ( \ + SCALAR_ARG_TYPE left, \ + MATXPR_ARG_TYPE right) \ +{ \ + typedef et::BinaryMatrixOp< \ + ScalarT, XprT, _OpT_ \ + > ExprT; \ + return et::MatrixXpr(ExprT(left,right.expression())); \ +} + +#endif + +// ------------------------------------------------------------------------- +// vim:ft=cpp