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 // This file should not include config.h.  It is only included in other
27 // C++ source files that should have included config.h before including
28 // this file.
29 
30 // FIXME: it might be nice to only include the declarations of the
31 // operators that are actually needed instead of including all of them.
32 #include "mx-ops.h"
33 
34 #include "ops.h"
35 #include "xdiv.h"
36 #include LINCLUDE
37 #include RINCLUDE
38 #if defined (DEFINENULLASSIGNCONV)
39 #  include "ov-null-mat.h"
40 #endif
41 
42 // matrix by diag matrix ops.
43 
44 DEFBINOP_OP (add, LMATRIX, RMATRIX, +)
45 DEFBINOP_OP (sub, LMATRIX, RMATRIX, -)
46 DEFBINOP_OP (mul, LMATRIX, RMATRIX, *)
47 
48 #if ! defined (LDMATRIX)
49 #  define LDMATRIX LMATRIX
50 #endif
51 
52 #if ! defined (RDMATRIX)
53 #  define RDMATRIX RMATRIX
54 #endif
55 
56 #define OCTAVE_LMATRIX CONCAT2(octave_, LMATRIX)
57 #define OCTAVE_LDMATRIX CONCAT2(octave_, LDMATRIX)
58 #define OCTAVE_RMATRIX CONCAT2(octave_, RMATRIX)
59 #define LMATRIX_VALUE CONCAT2(LMATRIX, _value)
60 #define RMATRIX_VALUE CONCAT2(RMATRIX, _value)
61 #define LDMATRIX_VALUE CONCAT2(LDMATRIX, _value)
62 #define RDMATRIX_VALUE CONCAT2(RDMATRIX, _value)
63 
64 #if defined (DEFINEDIV)
DEFBINOP(div,LMATRIX,RMATRIX)65 DEFBINOP (div, LMATRIX, RMATRIX)
66 {
67   const OCTAVE_LMATRIX& v1 = dynamic_cast<const OCTAVE_LMATRIX&> (a1);
68   const OCTAVE_RMATRIX& v2 = dynamic_cast<const OCTAVE_RMATRIX&> (a2);
69 
70   return xdiv (v1.LDMATRIX_VALUE (), v2.RMATRIX_VALUE ());
71 }
72 #endif
73 
74 #if defined (DEFINELDIV)
DEFBINOP(ldiv,LMATRIX,RMATRIX)75 DEFBINOP (ldiv, LMATRIX, RMATRIX)
76 {
77   const OCTAVE_LMATRIX& v1 = dynamic_cast<const OCTAVE_LMATRIX&> (a1);
78   const OCTAVE_RMATRIX& v2 = dynamic_cast<const OCTAVE_RMATRIX&> (a2);
79 
80   return xleftdiv (v1.LMATRIX_VALUE (), v2.RDMATRIX_VALUE ());
81 }
82 #endif
83 
84 #define SHORT_NAME CONCAT3(LSHORT, _, RSHORT)
85 #define INST_NAME CONCAT3(install_, SHORT_NAME, _ops)
86 
87 void
INST_NAME(octave::type_info & ti)88 INST_NAME (octave::type_info& ti)
89 {
90   INSTALL_BINOP_TI (ti, op_add, OCTAVE_LMATRIX, OCTAVE_RMATRIX, add);
91   INSTALL_BINOP_TI (ti, op_sub, OCTAVE_LMATRIX, OCTAVE_RMATRIX, sub);
92   INSTALL_BINOP_TI (ti, op_mul, OCTAVE_LMATRIX, OCTAVE_RMATRIX, mul);
93 #if defined (DEFINEDIV)
94   INSTALL_BINOP_TI (ti, op_div, OCTAVE_LMATRIX, OCTAVE_RMATRIX, div);
95 #endif
96 #if defined (DEFINELDIV)
97   INSTALL_BINOP_TI (ti, op_ldiv, OCTAVE_LMATRIX, OCTAVE_RMATRIX, ldiv);
98 #endif
99 #if defined (DEFINENULLASSIGNCONV)
100   INSTALL_ASSIGNCONV_TI (ti, OCTAVE_LMATRIX, octave_null_matrix, OCTAVE_LDMATRIX);
101   INSTALL_ASSIGNCONV_TI (ti, OCTAVE_LMATRIX, octave_null_str, OCTAVE_LDMATRIX);
102   INSTALL_ASSIGNCONV_TI (ti, OCTAVE_LMATRIX, octave_null_sq_str, OCTAVE_LDMATRIX);
103 #endif
104 }
105