op-dms-template.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2008-2012 Jaroslav Hajek
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include "ops.h"
00028 #include "gripes.h"
00029 #include "xpow.h"
00030 #include SINCLUDE
00031 #include MINCLUDE
00032 
00033 // matrix by diag matrix ops.
00034 
00035 #ifndef SCALARV
00036 #define SCALARV SCALAR
00037 #endif
00038 
00039 #ifndef MATRIXV
00040 #define MATRIXV MATRIX
00041 #endif
00042 
00043 DEFNDBINOP_OP (sdmmul, SCALAR, MATRIX, SCALARV, MATRIXV, *)
00044 DEFNDBINOP_OP (dmsmul, MATRIX, SCALAR, MATRIXV, SCALARV, *)
00045 
00046 #define OCTAVE_MATRIX CONCAT2(octave_, MATRIX)
00047 #define OCTAVE_SCALAR CONCAT2(octave_, SCALAR)
00048 #define MATRIX_VALUE CONCAT2(MATRIXV, _value)
00049 #define SCALAR_VALUE CONCAT2(SCALARV, _value)
00050 
00051 template <class T>
00052 static T
00053 gripe_if_zero (T x)
00054 {
00055   if (x == T ())
00056     gripe_divide_by_zero ();
00057   return x;
00058 }
00059 
00060 DEFBINOP (dmsdiv, MATRIX, SCALAR)
00061 {
00062   CAST_BINOP_ARGS (const OCTAVE_MATRIX&, const OCTAVE_SCALAR&);
00063 
00064   return v1.MATRIX_VALUE () / gripe_if_zero (v2.SCALAR_VALUE ());
00065 }
00066 
00067 DEFBINOP (sdmldiv, SCALAR, MATRIX)
00068 {
00069   CAST_BINOP_ARGS (const OCTAVE_SCALAR&, const OCTAVE_MATRIX&);
00070 
00071   return v2.MATRIX_VALUE () / gripe_if_zero (v1.SCALAR_VALUE ());
00072 }
00073 
00074 DEFBINOP (dmspow, MATRIX, SCALAR)
00075 {
00076   CAST_BINOP_ARGS (const OCTAVE_MATRIX&, const OCTAVE_SCALAR&);
00077 
00078   return xpow (v1.MATRIX_VALUE (), v2.SCALAR_VALUE ());
00079 }
00080 
00081 #define SHORT_NAME CONCAT3(MSHORT, _, SSHORT)
00082 #define INST_NAME CONCAT3(install_, SHORT_NAME, _ops)
00083 
00084 void
00085 INST_NAME (void)
00086 {
00087   INSTALL_BINOP (op_mul, OCTAVE_MATRIX, OCTAVE_SCALAR, dmsmul);
00088   INSTALL_BINOP (op_div, OCTAVE_MATRIX, OCTAVE_SCALAR, dmsdiv);
00089   INSTALL_BINOP (op_mul, OCTAVE_SCALAR, OCTAVE_MATRIX, sdmmul);
00090   INSTALL_BINOP (op_ldiv, OCTAVE_SCALAR, OCTAVE_MATRIX, sdmldiv);
00091   INSTALL_BINOP (op_pow, OCTAVE_MATRIX, OCTAVE_SCALAR, dmspow);
00092 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines