1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-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 "ovl.h"
31 #include "ov.h"
32 #include "ov-cx-mat.h"
33 #include "ov-flt-cx-mat.h"
34 #include "ov-complex.h"
35 #include "ov-typeinfo.h"
36 #include "ops.h"
37 #include "xdiv.h"
38 #include "xpow.h"
39 
40 // complex matrix by complex scalar ops.
41 
42 DEFNDBINOP_OP (add, complex_matrix, complex, complex_array, complex, +)
43 DEFNDBINOP_OP (sub, complex_matrix, complex, complex_array, complex, -)
44 DEFNDBINOP_OP (mul, complex_matrix, complex, complex_array, complex, *)
45 
DEFBINOP(div,complex_matrix,complex)46 DEFBINOP (div, complex_matrix, complex)
47 {
48   const octave_complex_matrix& v1
49     = dynamic_cast<const octave_complex_matrix&> (a1);
50   const octave_complex& v2 = dynamic_cast<const octave_complex&> (a2);
51 
52   return octave_value (v1.complex_array_value () / v2.complex_value ());
53 }
54 
DEFBINOP_FN(pow,complex_matrix,complex,xpow)55 DEFBINOP_FN (pow, complex_matrix, complex, xpow)
56 
57 DEFBINOP (ldiv, complex_matrix, complex)
58 {
59   const octave_complex_matrix& v1
60     = dynamic_cast<const octave_complex_matrix&> (a1);
61   const octave_complex& v2 = dynamic_cast<const octave_complex&> (a2);
62 
63   ComplexMatrix m1 = v1.complex_matrix_value ();
64   ComplexMatrix m2 = v2.complex_matrix_value ();
65   MatrixType typ = v1.matrix_type ();
66 
67   ComplexMatrix ret = xleftdiv (m1, m2, typ);
68   v1.matrix_type (typ);
69   return ret;
70 }
71 
DEFNDCMPLXCMPOP_FN(lt,complex_matrix,complex,complex_array,complex,mx_el_lt)72 DEFNDCMPLXCMPOP_FN (lt, complex_matrix, complex, complex_array, complex,
73                     mx_el_lt)
74 DEFNDCMPLXCMPOP_FN (le, complex_matrix, complex, complex_array, complex,
75                     mx_el_le)
76 DEFNDCMPLXCMPOP_FN (eq, complex_matrix, complex, complex_array, complex,
77                     mx_el_eq)
78 DEFNDCMPLXCMPOP_FN (ge, complex_matrix, complex, complex_array, complex,
79                     mx_el_ge)
80 DEFNDCMPLXCMPOP_FN (gt, complex_matrix, complex, complex_array, complex,
81                     mx_el_gt)
82 DEFNDCMPLXCMPOP_FN (ne, complex_matrix, complex, complex_array, complex,
83                     mx_el_ne)
84 
85 DEFNDBINOP_OP (el_mul, complex_matrix, complex, complex_array, complex, *)
86 
87 DEFBINOP (el_div, complex_matrix, complex)
88 {
89   const octave_complex_matrix& v1
90     = dynamic_cast<const octave_complex_matrix&> (a1);
91   const octave_complex& v2 = dynamic_cast<const octave_complex&> (a2);
92 
93   return octave_value (v1.complex_array_value () / v2.complex_value ());
94 }
95 
DEFNDBINOP_FN(el_pow,complex_matrix,complex,complex_array,complex,elem_xpow)96 DEFNDBINOP_FN (el_pow, complex_matrix, complex, complex_array, complex,
97                elem_xpow)
98 
99 DEFBINOP (el_ldiv, complex_matrix, complex)
100 {
101   const octave_complex_matrix& v1
102     = dynamic_cast<const octave_complex_matrix&> (a1);
103   const octave_complex& v2 = dynamic_cast<const octave_complex&> (a2);
104 
105   return x_el_div (v2.complex_value (), v1.complex_array_value ());
106 }
107 
DEFNDBINOP_FN(el_and,complex_matrix,complex,complex_array,complex,mx_el_and)108 DEFNDBINOP_FN (el_and, complex_matrix, complex, complex_array, complex,
109                mx_el_and)
110 DEFNDBINOP_FN (el_or,  complex_matrix, complex, complex_array, complex,
111                mx_el_or)
112 
113 DEFNDCATOP_FN (cm_cs, complex_matrix, complex, complex_array, complex_array,
114                concat)
115 
116 DEFNDASSIGNOP_FN (assign, complex_matrix, complex, complex, assign)
117 DEFNDASSIGNOP_FN (sgl_assign, float_complex_matrix, complex, float_complex,
118                   assign)
119 
120 DEFNDASSIGNOP_OP (assign_add, complex_matrix, complex_scalar, complex, +=)
121 DEFNDASSIGNOP_OP (assign_sub, complex_matrix, complex_scalar, complex, -=)
122 DEFNDASSIGNOP_OP (assign_mul, complex_matrix, complex_scalar, complex, *=)
123 DEFNDASSIGNOP_OP (assign_div, complex_matrix, complex_scalar, complex, /=)
124 
125 void
126 install_cm_cs_ops (octave::type_info& ti)
127 {
128   INSTALL_BINOP_TI (ti, op_add, octave_complex_matrix, octave_complex, add);
129   INSTALL_BINOP_TI (ti, op_sub, octave_complex_matrix, octave_complex, sub);
130   INSTALL_BINOP_TI (ti, op_mul, octave_complex_matrix, octave_complex, mul);
131   INSTALL_BINOP_TI (ti, op_div, octave_complex_matrix, octave_complex, div);
132   INSTALL_BINOP_TI (ti, op_pow, octave_complex_matrix, octave_complex, pow);
133   INSTALL_BINOP_TI (ti, op_ldiv, octave_complex_matrix, octave_complex, ldiv);
134   INSTALL_BINOP_TI (ti, op_lt, octave_complex_matrix, octave_complex, lt);
135   INSTALL_BINOP_TI (ti, op_le, octave_complex_matrix, octave_complex, le);
136   INSTALL_BINOP_TI (ti, op_eq, octave_complex_matrix, octave_complex, eq);
137   INSTALL_BINOP_TI (ti, op_ge, octave_complex_matrix, octave_complex, ge);
138   INSTALL_BINOP_TI (ti, op_gt, octave_complex_matrix, octave_complex, gt);
139   INSTALL_BINOP_TI (ti, op_ne, octave_complex_matrix, octave_complex, ne);
140   INSTALL_BINOP_TI (ti, op_el_mul, octave_complex_matrix, octave_complex, el_mul);
141   INSTALL_BINOP_TI (ti, op_el_div, octave_complex_matrix, octave_complex, el_div);
142   INSTALL_BINOP_TI (ti, op_el_pow, octave_complex_matrix, octave_complex, el_pow);
143   INSTALL_BINOP_TI (ti, op_el_ldiv, octave_complex_matrix, octave_complex,
144                     el_ldiv);
145   INSTALL_BINOP_TI (ti, op_el_and, octave_complex_matrix, octave_complex, el_and);
146   INSTALL_BINOP_TI (ti, op_el_or, octave_complex_matrix, octave_complex, el_or);
147 
148   INSTALL_CATOP_TI (ti, octave_complex_matrix, octave_complex, cm_cs);
149 
150   INSTALL_ASSIGNOP_TI (ti, op_asn_eq, octave_complex_matrix, octave_complex,
151                        assign);
152   INSTALL_ASSIGNOP_TI (ti, op_asn_eq, octave_float_complex_matrix, octave_complex,
153                        sgl_assign);
154 
155   INSTALL_ASSIGNOP_TI (ti, op_add_eq, octave_complex_matrix,
156                        octave_complex_scalar,
157                        assign_add);
158   INSTALL_ASSIGNOP_TI (ti, op_sub_eq, octave_complex_matrix,
159                        octave_complex_scalar,
160                        assign_sub);
161   INSTALL_ASSIGNOP_TI (ti, op_mul_eq, octave_complex_matrix,
162                        octave_complex_scalar,
163                        assign_mul);
164   INSTALL_ASSIGNOP_TI (ti, op_div_eq, octave_complex_matrix,
165                        octave_complex_scalar,
166                        assign_div);
167 }
168