GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
op-cm-cm.cc
Go to the documentation of this file.
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 "errwarn.h"
31 #include "ovl.h"
32 #include "ov.h"
33 #include "ov-cx-mat.h"
34 #include "ov-flt-cx-mat.h"
35 #include "ov-typeinfo.h"
36 #include "ov-null-mat.h"
37 #include "ops.h"
38 #include "xdiv.h"
39 #include "xpow.h"
40 
41 // unary complex matrix ops.
42 
43 DEFNDUNOP_OP (not, complex_matrix, complex_array, !)
44 DEFNDUNOP_OP (uplus, complex_matrix, complex_array, /* no-op */)
45 DEFNDUNOP_OP (uminus, complex_matrix, complex_array, -)
46 
47 DEFUNOP (transpose, complex_matrix)
48 {
49  const octave_complex_matrix& v
50  = dynamic_cast<const octave_complex_matrix&> (a);
51 
52  if (v.ndims () > 2)
53  error ("transpose not defined for N-D objects");
54 
56 }
57 
58 DEFUNOP (hermitian, complex_matrix)
59 {
60  const octave_complex_matrix& v
61  = dynamic_cast<const octave_complex_matrix&> (a);
62 
63  if (v.ndims () > 2)
64  error ("complex-conjugate transpose not defined for N-D objects");
65 
67 }
68 
69 DEFNCUNOP_METHOD (incr, complex_matrix, increment)
70 DEFNCUNOP_METHOD (decr, complex_matrix, decrement)
71 DEFNCUNOP_METHOD (changesign, complex_matrix, changesign)
72 
73 // complex matrix by complex matrix ops.
74 
75 DEFNDBINOP_OP (add, complex_matrix, complex_matrix, complex_array,
76  complex_array, +)
77 DEFNDBINOP_OP (sub, complex_matrix, complex_matrix, complex_array,
78  complex_array, -)
79 
80 DEFBINOP_OP (mul, complex_matrix, complex_matrix, *)
81 
82 DEFBINOP (div, complex_matrix, complex_matrix)
83 {
84  const octave_complex_matrix& v1
85  = dynamic_cast<const octave_complex_matrix&> (a1);
87  = dynamic_cast<const octave_complex_matrix&> (a2);
88  MatrixType typ = v2.matrix_type ();
89 
91  v2.complex_matrix_value (), typ);
92 
93  v2.matrix_type (typ);
94  return ret;
95 }
96 
97 DEFBINOPX (pow, complex_matrix, complex_matrix)
98 {
99  error ("can't do A ^ B for A and B both matrices");
100 }
101 
102 DEFBINOP (ldiv, complex_matrix, complex_matrix)
103 {
104  const octave_complex_matrix& v1
105  = dynamic_cast<const octave_complex_matrix&> (a1);
107  = dynamic_cast<const octave_complex_matrix&> (a2);
108  MatrixType typ = v1.matrix_type ();
109 
111  v2.complex_matrix_value (), typ);
112 
113  v1.matrix_type (typ);
114  return ret;
115 }
116 
117 DEFBINOP (trans_mul, complex_matrix, complex_matrix)
118 {
119  const octave_complex_matrix& v1
120  = dynamic_cast<const octave_complex_matrix&> (a1);
122  = dynamic_cast<const octave_complex_matrix&> (a2);
126 }
127 
128 DEFBINOP (mul_trans, complex_matrix, complex_matrix)
129 {
130  const octave_complex_matrix& v1
131  = dynamic_cast<const octave_complex_matrix&> (a1);
133  = dynamic_cast<const octave_complex_matrix&> (a2);
137 }
138 
139 DEFBINOP (herm_mul, complex_matrix, complex_matrix)
140 {
141  const octave_complex_matrix& v1
142  = dynamic_cast<const octave_complex_matrix&> (a1);
144  = dynamic_cast<const octave_complex_matrix&> (a2);
148 }
149 
150 DEFBINOP (mul_herm, complex_matrix, complex_matrix)
151 {
152  const octave_complex_matrix& v1
153  = dynamic_cast<const octave_complex_matrix&> (a1);
155  = dynamic_cast<const octave_complex_matrix&> (a2);
159 }
160 
161 DEFBINOP (trans_ldiv, complex_matrix, complex_matrix)
162 {
163  const octave_complex_matrix& v1
164  = dynamic_cast<const octave_complex_matrix&> (a1);
166  = dynamic_cast<const octave_complex_matrix&> (a2);
167  MatrixType typ = v1.matrix_type ();
168 
171 
172  v1.matrix_type (typ);
173  return ret;
174 }
175 
176 DEFBINOP (herm_ldiv, complex_matrix, complex_matrix)
177 {
178  const octave_complex_matrix& v1
179  = dynamic_cast<const octave_complex_matrix&> (a1);
181  = dynamic_cast<const octave_complex_matrix&> (a2);
182  MatrixType typ = v1.matrix_type ();
183 
185  v2.complex_matrix_value (), typ,
187 
188  v1.matrix_type (typ);
189  return ret;
190 }
191 
192 DEFNDCMPLXCMPOP_FN (lt, complex_matrix, complex_matrix, complex_array,
193  complex_array, mx_el_lt)
194 DEFNDCMPLXCMPOP_FN (le, complex_matrix, complex_matrix, complex_array,
195  complex_array, mx_el_le)
196 DEFNDCMPLXCMPOP_FN (eq, complex_matrix, complex_matrix, complex_array,
197  complex_array, mx_el_eq)
198 DEFNDCMPLXCMPOP_FN (ge, complex_matrix, complex_matrix, complex_array,
199  complex_array, mx_el_ge)
200 DEFNDCMPLXCMPOP_FN (gt, complex_matrix, complex_matrix, complex_array,
201  complex_array, mx_el_gt)
202 DEFNDCMPLXCMPOP_FN (ne, complex_matrix, complex_matrix, complex_array,
203  complex_array, mx_el_ne)
204 
205 DEFNDBINOP_FN (el_mul, complex_matrix, complex_matrix, complex_array,
206  complex_array, product)
207 DEFNDBINOP_FN (el_div, complex_matrix, complex_matrix, complex_array,
208  complex_array, quotient)
209 DEFNDBINOP_FN (el_pow, complex_matrix, complex_matrix, complex_array,
210  complex_array, elem_xpow)
211 
212 DEFBINOP (el_ldiv, complex_matrix, complex_matrix)
213 {
214  const octave_complex_matrix& v1
215  = dynamic_cast<const octave_complex_matrix&> (a1);
217  = dynamic_cast<const octave_complex_matrix&> (a2);
218 
220  v1.complex_array_value ()));
221 }
222 
223 DEFNDBINOP_FN (el_and, complex_matrix, complex_matrix, complex_array,
224  complex_array, mx_el_and)
225 DEFNDBINOP_FN (el_or, complex_matrix, complex_matrix, complex_array,
226  complex_array, mx_el_or)
227 
228 DEFNDCATOP_FN (cm_cm, complex_matrix, complex_matrix, complex_array,
229  complex_array, concat)
230 
231 DEFNDASSIGNOP_FN (assign, complex_matrix, complex_matrix, complex_array, assign)
232 
233 DEFNULLASSIGNOP_FN (null_assign, complex_matrix, delete_elements)
234 
235 DEFNDASSIGNOP_OP (assign_add, complex_matrix, complex_matrix, complex_array, +=)
236 DEFNDASSIGNOP_OP (assign_sub, complex_matrix, complex_matrix, complex_array, -=)
237 DEFNDASSIGNOP_FNOP (assign_el_mul, complex_matrix, complex_matrix,
238  complex_array, product_eq)
239 DEFNDASSIGNOP_FNOP (assign_el_div, complex_matrix, complex_matrix,
240  complex_array, quotient_eq)
241 
242 void
243 install_cm_cm_ops (octave::type_info& ti)
244 {
250 
251  INSTALL_NCUNOP_TI (ti, op_incr, octave_complex_matrix, incr);
252  INSTALL_NCUNOP_TI (ti, op_decr, octave_complex_matrix, decr);
254 
256  add);
258  sub);
260  mul);
262  div);
264  pow);
266  ldiv);
269  trans_mul);
272  mul_trans);
274  herm_mul);
276  mul_herm);
277  INSTALL_BINOP_TI (ti, op_trans_ldiv, octave_complex_matrix,
279  trans_ldiv);
280  INSTALL_BINOP_TI (ti, op_herm_ldiv, octave_complex_matrix,
282  herm_ldiv);
283 
291  el_mul);
293  el_div);
295  el_pow);
297  el_ldiv);
299  el_and);
301  el_or);
302 
304 
307  assign);
308 
310  null_assign);
312  null_assign);
314  null_assign);
315 
318  assign_add);
321  assign_sub);
322  INSTALL_ASSIGNOP_TI (ti, op_el_mul_eq, octave_complex_matrix,
324  assign_el_mul);
325  INSTALL_ASSIGNOP_TI (ti, op_el_div_eq, octave_complex_matrix,
327  assign_el_div);
328 }
ComplexColumnVector quotient(const ComplexColumnVector &x, const ComplexColumnVector &y)
Definition: CColVector.h:152
ComplexColumnVector product_eq(ComplexColumnVector &x, const ComplexColumnVector &y)
Definition: CColVector.h:152
ComplexColumnVector product(const ComplexColumnVector &x, const ComplexColumnVector &y)
Definition: CColVector.h:152
ComplexColumnVector quotient_eq(ComplexColumnVector &x, const ComplexColumnVector &y)
Definition: CColVector.h:152
ComplexMatrix xgemm(const ComplexMatrix &a, const ComplexMatrix &b, blas_trans_type transa, blas_trans_type transb)
Definition: CMatrix.cc:3322
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: CNDArray.cc:418
ComplexMatrix mul_trans(const ComplexMatrix &m, const SparseComplexMatrix &a)
Definition: CSparse.cc:7543
ComplexMatrix mul_herm(const ComplexMatrix &m, const SparseComplexMatrix &a)
Definition: CSparse.cc:7549
ComplexMatrix trans_mul(const SparseComplexMatrix &m, const ComplexMatrix &a)
Definition: CSparse.cc:7573
ComplexMatrix herm_mul(const SparseComplexMatrix &m, const ComplexMatrix &a)
Definition: CSparse.cc:7579
boolMatrix mx_el_le(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:91
boolMatrix mx_el_ne(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:91
boolMatrix mx_el_or(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:88
boolMatrix mx_el_and(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:88
boolMatrix mx_el_gt(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:91
boolMatrix mx_el_eq(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:91
boolMatrix mx_el_lt(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:91
boolMatrix mx_el_ge(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:91
ComplexMatrix transpose(void) const
Definition: CMatrix.h:171
ComplexMatrix hermitian(void) const
Definition: CMatrix.h:169
MatrixType matrix_type(void) const
Definition: ov-base-mat.h:131
int ndims(void) const
Definition: ov-base-mat.h:116
ComplexMatrix complex_matrix_value(bool=false) const
Definition: ov-ch-mat.h:130
ComplexNDArray complex_array_value(bool=false) const
Definition: ov-ch-mat.h:136
ComplexNDArray complex_array_value(bool=false) const
Definition: ov-cx-mat.h:129
ComplexMatrix complex_matrix_value(bool=false) const
Definition: ov-cx-mat.cc:213
void error(const char *fmt,...)
Definition: error.cc:968
@ blas_no_trans
Definition: mx-defs.h:110
@ blas_conj_trans
Definition: mx-defs.h:112
@ blas_trans
Definition: mx-defs.h:111
octave_int< T > pow(const octave_int< T > &a, const octave_int< T > &b)
void install_cm_cm_ops(octave::type_info &ti)
Definition: op-cm-cm.cc:243
const octave_base_value & a2
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
const octave_char_matrix & v2
#define DEFNDASSIGNOP_FN(name, t1, t2, e, f)
Definition: ops.h:112
#define DEFNDBINOP_OP(name, t1, t2, e1, e2, op)
Definition: ops.h:276
#define INSTALL_NCUNOP_TI(ti, op, t, f)
Definition: ops.h:51
#define DEFNULLASSIGNOP_FN(name, t, f)
Definition: ops.h:100
#define DEFNDBINOP_FN(name, t1, t2, e1, e2, f)
Definition: ops.h:301
#define DEFNDCMPLXCMPOP_FN(name, t1, t2, e1, e2, f)
Definition: ops.h:312
#define DEFBINOPX(name, t1, t2)
Definition: ops.h:225
#define DEFNDASSIGNOP_FNOP(name, t1, t2, f, fnop)
Definition: ops.h:141
#define DEFBINOP(name, t1, t2)
Definition: ops.h:230
#define DEFNDUNOP_OP(name, t, e, op)
Definition: ops.h:191
#define DEFBINOP_OP(name, t1, t2, op)
Definition: ops.h:235
#define DEFNCUNOP_METHOD(name, t, method)
Definition: ops.h:217
#define INSTALL_BINOP_TI(ti, op, t1, t2, f)
Definition: ops.h:55
#define DEFNDCATOP_FN(name, t1, t2, e1, e2, f)
Definition: ops.h:348
#define DEFUNOP(name, t)
Definition: ops.h:179
#define INSTALL_CATOP_TI(ti, t1, t2, f)
Definition: ops.h:60
#define INSTALL_UNOP_TI(ti, op, t, f)
Definition: ops.h:47
#define DEFNDASSIGNOP_OP(name, t1, t2, f, op)
Definition: ops.h:126
#define INSTALL_ASSIGNOP_TI(ti, op, t1, t2, f)
Definition: ops.h:64
octave_value op_ne(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1579
octave_value op_el_ldiv(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1584
octave_value op_uplus(const octave_value &a)
Definition: ov.h:1537
octave_value op_add(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1566
octave_value op_gt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1578
octave_value op_uminus(const octave_value &a)
Definition: ov.h:1538
octave_value op_el_div(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1582
octave_value op_mul_herm(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1600
octave_value op_transpose(const octave_value &a)
Definition: ov.h:1540
octave_value op_el_or(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1586
octave_value op_sub(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1567
octave_value op_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1568
octave_value op_hermitian(const octave_value &a)
Definition: ov.h:1541
octave_value op_le(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1575
octave_value op_el_and(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1585
octave_value op_herm_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1599
octave_value op_eq(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1576
octave_value op_el_pow(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1583
octave_value op_not(const octave_value &a)
Definition: ov.h:1536
octave_value op_ldiv(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1572
octave_value op_pow(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1571
octave_value op_ge(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1577
octave_value op_el_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1581
octave_value op_div(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1569
octave_value op_trans_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1597
octave_value op_mul_trans(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1598
octave_value op_lt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1574
Matrix xdiv(const Matrix &a, const SparseMatrix &b, MatrixType &typ)
Definition: sparse-xdiv.cc:135
Matrix xleftdiv(const SparseMatrix &a, const Matrix &b, MatrixType &typ)
Definition: sparse-xdiv.cc:466
octave_value elem_xpow(double a, const SparseMatrix &b)
Definition: sparse-xpow.cc:249
static void transpose(octave_idx_type N, const octave_idx_type *ridx, const octave_idx_type *cidx, octave_idx_type *ridx2, octave_idx_type *cidx2)
Definition: symrcm.cc:389