1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2008-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING.  If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 #  include "config.h"
28 #endif
29 
30 #include "ops.h"
31 #include "xpow.h"
32 #include SINCLUDE
33 #include MINCLUDE
34 
35 // matrix by diag matrix ops.
36 
37 #if ! defined (SCALARV)
38 #  define SCALARV SCALAR
39 #endif
40 
41 #if ! defined (MATRIXV)
42 #  define MATRIXV MATRIX
43 #endif
44 
45 DEFNDBINOP_OP (sdmmul, SCALAR, MATRIX, SCALARV, MATRIXV, *)
46 DEFNDBINOP_OP (dmsmul, MATRIX, SCALAR, MATRIXV, SCALARV, *)
47 
48 #define OCTAVE_MATRIX CONCAT2(octave_, MATRIX)
49 #define OCTAVE_SCALAR CONCAT2(octave_, SCALAR)
50 #define MATRIX_VALUE CONCAT2(MATRIXV, _value)
51 #define SCALAR_VALUE CONCAT2(SCALARV, _value)
52 
DEFBINOP(dmsdiv,MATRIX,SCALAR)53 DEFBINOP (dmsdiv, MATRIX, SCALAR)
54 {
55   const OCTAVE_MATRIX& v1 = dynamic_cast<const OCTAVE_MATRIX&> (a1);
56   const OCTAVE_SCALAR& v2 = dynamic_cast<const OCTAVE_SCALAR&> (a2);
57 
58   return v1.MATRIX_VALUE () / v2.SCALAR_VALUE ();
59 }
60 
DEFBINOP(sdmldiv,SCALAR,MATRIX)61 DEFBINOP (sdmldiv, SCALAR, MATRIX)
62 {
63   const OCTAVE_SCALAR& v1 = dynamic_cast<const OCTAVE_SCALAR&> (a1);
64   const OCTAVE_MATRIX& v2 = dynamic_cast<const OCTAVE_MATRIX&> (a2);
65 
66   return v2.MATRIX_VALUE () / v1.SCALAR_VALUE ();
67 }
68 
DEFBINOP(dmspow,MATRIX,SCALAR)69 DEFBINOP (dmspow, MATRIX, SCALAR)
70 {
71   const OCTAVE_MATRIX& v1 = dynamic_cast<const OCTAVE_MATRIX&> (a1);
72   const OCTAVE_SCALAR& v2 = dynamic_cast<const OCTAVE_SCALAR&> (a2);
73 
74   return xpow (v1.MATRIX_VALUE (), v2.SCALAR_VALUE ());
75 }
76 
77 #define SHORT_NAME CONCAT3(MSHORT, _, SSHORT)
78 #define INST_NAME CONCAT3(install_, SHORT_NAME, _ops)
79 
80 void
INST_NAME(octave::type_info & ti)81 INST_NAME (octave::type_info& ti)
82 {
83   INSTALL_BINOP_TI (ti, op_mul, OCTAVE_MATRIX, OCTAVE_SCALAR, dmsmul);
84   INSTALL_BINOP_TI (ti, op_div, OCTAVE_MATRIX, OCTAVE_SCALAR, dmsdiv);
85   INSTALL_BINOP_TI (ti, op_mul, OCTAVE_SCALAR, OCTAVE_MATRIX, sdmmul);
86   INSTALL_BINOP_TI (ti, op_ldiv, OCTAVE_SCALAR, OCTAVE_MATRIX, sdmldiv);
87   INSTALL_BINOP_TI (ti, op_pow, OCTAVE_MATRIX, OCTAVE_SCALAR, dmspow);
88 }
89