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 "errwarn.h"
31 #include "ovl.h"
32 #include "ov.h"
33 #include "ov-flt-re-mat.h"
34 #include "ov-flt-re-diag.h"
35 #include "ov-re-diag.h"
36 #include "ov-typeinfo.h"
37 #include "ops.h"
38 #include "xdiv.h"
39 #include "xpow.h"
40 
41 // matrix unary ops.
42 
43 DEFUNOP_OP (uplus, float_diag_matrix, /* no-op */)
44 DEFUNOP_OP (uminus, float_diag_matrix, -)
45 
DEFUNOP(transpose,float_diag_matrix)46 DEFUNOP (transpose, float_diag_matrix)
47 {
48   const octave_float_diag_matrix& v
49     = dynamic_cast<const octave_float_diag_matrix&> (a);
50   return octave_value (v.float_diag_matrix_value ().transpose ());
51 }
52 
53 // matrix by matrix ops.
54 
55 DEFBINOP_OP (add, float_diag_matrix, float_diag_matrix, +)
56 DEFBINOP_OP (sub, float_diag_matrix, float_diag_matrix, -)
57 DEFBINOP_OP (mul, float_diag_matrix, float_diag_matrix, *)
58 
DEFBINOP(div,float_diag_matrix,float_diag_matrix)59 DEFBINOP (div, float_diag_matrix, float_diag_matrix)
60 {
61   const octave_float_diag_matrix& v1
62     = dynamic_cast<const octave_float_diag_matrix&> (a1);
63   const octave_float_diag_matrix& v2
64     = dynamic_cast<const octave_float_diag_matrix&> (a2);
65 
66   return xdiv (v1.float_diag_matrix_value (),
67                v2.float_diag_matrix_value ());
68 }
69 
DEFBINOP(ldiv,float_diag_matrix,float_diag_matrix)70 DEFBINOP (ldiv, float_diag_matrix, float_diag_matrix)
71 {
72   const octave_float_diag_matrix& v1
73     = dynamic_cast<const octave_float_diag_matrix&> (a1);
74   const octave_float_diag_matrix& v2
75     = dynamic_cast<const octave_float_diag_matrix&> (a2);
76 
77   return xleftdiv (v1.float_diag_matrix_value (),
78                    v2.float_diag_matrix_value ());
79 }
80 
CONVDECL(float_diag_matrix_to_float_matrix)81 CONVDECL (float_diag_matrix_to_float_matrix)
82 {
83   const octave_float_diag_matrix& v
84     = dynamic_cast<const octave_float_diag_matrix&> (a);
85 
86   return new octave_float_matrix (v.float_matrix_value ());
87 }
88 
89 void
install_fdm_fdm_ops(octave::type_info & ti)90 install_fdm_fdm_ops (octave::type_info& ti)
91 {
92   INSTALL_UNOP_TI (ti, op_uplus, octave_float_diag_matrix, uplus);
93   INSTALL_UNOP_TI (ti, op_uminus, octave_float_diag_matrix, uminus);
94   INSTALL_UNOP_TI (ti, op_transpose, octave_float_diag_matrix, transpose);
95   INSTALL_UNOP_TI (ti, op_hermitian, octave_float_diag_matrix, transpose);
96 
97   INSTALL_BINOP_TI (ti, op_add, octave_float_diag_matrix,
98                     octave_float_diag_matrix,
99                     add);
100   INSTALL_BINOP_TI (ti, op_sub, octave_float_diag_matrix,
101                     octave_float_diag_matrix,
102                     sub);
103   INSTALL_BINOP_TI (ti, op_mul, octave_float_diag_matrix,
104                     octave_float_diag_matrix,
105                     mul);
106   INSTALL_BINOP_TI (ti, op_div, octave_float_diag_matrix,
107                     octave_float_diag_matrix,
108                     div);
109   INSTALL_BINOP_TI (ti, op_ldiv, octave_float_diag_matrix,
110                     octave_float_diag_matrix,
111                     ldiv);
112 
113   INSTALL_ASSIGNCONV_TI (ti, octave_float_diag_matrix, octave_float_matrix,
114                          octave_float_matrix);
115   INSTALL_WIDENOP_TI (ti, octave_float_diag_matrix, octave_float_matrix,
116                       float_diag_matrix_to_float_matrix);
117 }
118