GNU Octave  8.1.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-2023 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 
42 
43 // unary complex matrix ops.
44 
45 DEFNDUNOP_OP (not, complex_matrix, complex_array, !)
46 DEFNDUNOP_OP (uplus, complex_matrix, complex_array, /* no-op */)
47 DEFNDUNOP_OP (uminus, complex_matrix, complex_array, -)
48 
49 DEFUNOP (transpose, complex_matrix)
50 {
51  const octave_complex_matrix& v
52  = dynamic_cast<const octave_complex_matrix&> (a);
53 
54  if (v.ndims () > 2)
55  error ("transpose not defined for N-D objects");
56 
58 }
59 
60 DEFUNOP (hermitian, complex_matrix)
61 {
62  const octave_complex_matrix& v
63  = dynamic_cast<const octave_complex_matrix&> (a);
64 
65  if (v.ndims () > 2)
66  error ("complex-conjugate transpose not defined for N-D objects");
67 
69 }
70 
71 DEFNCUNOP_METHOD (incr, complex_matrix, increment)
72 DEFNCUNOP_METHOD (decr, complex_matrix, decrement)
73 DEFNCUNOP_METHOD (changesign, complex_matrix, changesign)
74 
75 // complex matrix by complex matrix ops.
76 
77 DEFNDBINOP_OP (add, complex_matrix, complex_matrix, complex_array,
78  complex_array, +)
79 DEFNDBINOP_OP (sub, complex_matrix, complex_matrix, complex_array,
80  complex_array, -)
81 
82 DEFBINOP_OP (mul, complex_matrix, complex_matrix, *)
83 
84 DEFBINOP (div, complex_matrix, complex_matrix)
85 {
86  const octave_complex_matrix& v1
87  = dynamic_cast<const octave_complex_matrix&> (a1);
89  = dynamic_cast<const octave_complex_matrix&> (a2);
90  MatrixType typ = v2.matrix_type ();
91 
93  v2.complex_matrix_value (), typ);
94 
95  v2.matrix_type (typ);
96  return ret;
97 }
98 
99 DEFBINOPX (pow, complex_matrix, complex_matrix)
100 {
101  error ("can't do A ^ B for A and B both matrices");
102 }
103 
104 DEFBINOP (ldiv, complex_matrix, complex_matrix)
105 {
106  const octave_complex_matrix& v1
107  = dynamic_cast<const octave_complex_matrix&> (a1);
109  = dynamic_cast<const octave_complex_matrix&> (a2);
110  MatrixType typ = v1.matrix_type ();
111 
113  v2.complex_matrix_value (), typ);
114 
115  v1.matrix_type (typ);
116  return ret;
117 }
118 
119 DEFBINOP (trans_mul, complex_matrix, complex_matrix)
120 {
121  const octave_complex_matrix& v1
122  = dynamic_cast<const octave_complex_matrix&> (a1);
124  = dynamic_cast<const octave_complex_matrix&> (a2);
128 }
129 
130 DEFBINOP (mul_trans, complex_matrix, complex_matrix)
131 {
132  const octave_complex_matrix& v1
133  = dynamic_cast<const octave_complex_matrix&> (a1);
135  = dynamic_cast<const octave_complex_matrix&> (a2);
139 }
140 
141 DEFBINOP (herm_mul, complex_matrix, complex_matrix)
142 {
143  const octave_complex_matrix& v1
144  = dynamic_cast<const octave_complex_matrix&> (a1);
146  = dynamic_cast<const octave_complex_matrix&> (a2);
150 }
151 
152 DEFBINOP (mul_herm, complex_matrix, complex_matrix)
153 {
154  const octave_complex_matrix& v1
155  = dynamic_cast<const octave_complex_matrix&> (a1);
157  = dynamic_cast<const octave_complex_matrix&> (a2);
161 }
162 
163 DEFBINOP (trans_ldiv, complex_matrix, complex_matrix)
164 {
165  const octave_complex_matrix& v1
166  = dynamic_cast<const octave_complex_matrix&> (a1);
168  = dynamic_cast<const octave_complex_matrix&> (a2);
169  MatrixType typ = v1.matrix_type ();
170 
173 
174  v1.matrix_type (typ);
175  return ret;
176 }
177 
178 DEFBINOP (herm_ldiv, complex_matrix, complex_matrix)
179 {
180  const octave_complex_matrix& v1
181  = dynamic_cast<const octave_complex_matrix&> (a1);
183  = dynamic_cast<const octave_complex_matrix&> (a2);
184  MatrixType typ = v1.matrix_type ();
185 
187  v2.complex_matrix_value (), typ,
189 
190  v1.matrix_type (typ);
191  return ret;
192 }
193 
194 DEFNDCMPLXCMPOP_FN (lt, complex_matrix, complex_matrix, complex_array,
195  complex_array, mx_el_lt)
196 DEFNDCMPLXCMPOP_FN (le, complex_matrix, complex_matrix, complex_array,
197  complex_array, mx_el_le)
198 DEFNDCMPLXCMPOP_FN (eq, complex_matrix, complex_matrix, complex_array,
199  complex_array, mx_el_eq)
200 DEFNDCMPLXCMPOP_FN (ge, complex_matrix, complex_matrix, complex_array,
201  complex_array, mx_el_ge)
202 DEFNDCMPLXCMPOP_FN (gt, complex_matrix, complex_matrix, complex_array,
203  complex_array, mx_el_gt)
204 DEFNDCMPLXCMPOP_FN (ne, complex_matrix, complex_matrix, complex_array,
205  complex_array, mx_el_ne)
206 
207 DEFNDBINOP_FN (el_mul, complex_matrix, complex_matrix, complex_array,
208  complex_array, product)
209 DEFNDBINOP_FN (el_div, complex_matrix, complex_matrix, complex_array,
210  complex_array, quotient)
211 DEFNDBINOP_FN (el_pow, complex_matrix, complex_matrix, complex_array,
212  complex_array, elem_xpow)
213 
214 DEFBINOP (el_ldiv, complex_matrix, complex_matrix)
215 {
216  const octave_complex_matrix& v1
217  = dynamic_cast<const octave_complex_matrix&> (a1);
219  = dynamic_cast<const octave_complex_matrix&> (a2);
220 
222  v1.complex_array_value ()));
223 }
224 
225 DEFNDBINOP_FN (el_and, complex_matrix, complex_matrix, complex_array,
226  complex_array, mx_el_and)
227 DEFNDBINOP_FN (el_or, complex_matrix, complex_matrix, complex_array,
228  complex_array, mx_el_or)
229 
230 DEFNDCATOP_FN (cm_cm, complex_matrix, complex_matrix, complex_array,
231  complex_array, concat)
232 
233 DEFNDASSIGNOP_FN (assign, complex_matrix, complex_matrix, complex_array, assign)
234 
235 DEFNULLASSIGNOP_FN (null_assign, complex_matrix, delete_elements)
236 
237 DEFNDASSIGNOP_OP (assign_add, complex_matrix, complex_matrix, complex_array, +=)
238 DEFNDASSIGNOP_OP (assign_sub, complex_matrix, complex_matrix, complex_array, -=)
239 DEFNDASSIGNOP_FNOP (assign_el_mul, complex_matrix, complex_matrix,
240  complex_array, product_eq)
241 DEFNDASSIGNOP_FNOP (assign_el_div, complex_matrix, complex_matrix,
242  complex_array, quotient_eq)
243 
244 void
246 {
252 
253  INSTALL_NCUNOP_TI (ti, op_incr, octave_complex_matrix, incr);
254  INSTALL_NCUNOP_TI (ti, op_decr, octave_complex_matrix, decr);
256 
258  add);
260  sub);
262  mul);
264  div);
266  pow);
268  ldiv);
271  trans_mul);
274  mul_trans);
276  herm_mul);
278  mul_herm);
279  INSTALL_BINOP_TI (ti, op_trans_ldiv, octave_complex_matrix,
281  trans_ldiv);
282  INSTALL_BINOP_TI (ti, op_herm_ldiv, octave_complex_matrix,
284  herm_ldiv);
285 
293  el_mul);
295  el_div);
297  el_pow);
299  el_ldiv);
301  el_and);
303  el_or);
304 
306 
309  assign);
310 
312  null_assign);
314  null_assign);
316  null_assign);
317 
320  assign_add);
323  assign_sub);
324  INSTALL_ASSIGNOP_TI (ti, op_el_mul_eq, octave_complex_matrix,
326  assign_el_mul);
327  INSTALL_ASSIGNOP_TI (ti, op_el_div_eq, octave_complex_matrix,
329  assign_el_div);
330 }
331 
OCTAVE_END_NAMESPACE(octave)
ComplexColumnVector quotient(const ComplexColumnVector &x, const ComplexColumnVector &y)
Definition: CColVector.h:156
ComplexColumnVector product_eq(ComplexColumnVector &x, const ComplexColumnVector &y)
Definition: CColVector.h:156
ComplexColumnVector product(const ComplexColumnVector &x, const ComplexColumnVector &y)
Definition: CColVector.h:156
ComplexColumnVector quotient_eq(ComplexColumnVector &x, const ComplexColumnVector &y)
Definition: CColVector.h:156
ComplexMatrix xgemm(const ComplexMatrix &a, const ComplexMatrix &b, blas_trans_type transa, blas_trans_type transb)
Definition: CMatrix.cc:3346
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:7511
ComplexMatrix mul_herm(const ComplexMatrix &m, const SparseComplexMatrix &a)
Definition: CSparse.cc:7517
ComplexMatrix trans_mul(const SparseComplexMatrix &m, const ComplexMatrix &a)
Definition: CSparse.cc:7541
ComplexMatrix herm_mul(const SparseComplexMatrix &m, const ComplexMatrix &a)
Definition: CSparse.cc:7547
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:172
ComplexMatrix hermitian(void) const
Definition: CMatrix.h:170
MatrixType matrix_type(void) const
Definition: ov-base-mat.h:136
int ndims(void) const
Definition: ov-base-mat.h:121
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:214
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error(const char *fmt,...)
Definition: error.cc:979
@ blas_no_trans
Definition: mx-defs.h:81
@ blas_conj_trans
Definition: mx-defs.h:83
@ blas_trans
Definition: mx-defs.h:82
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:245
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:349
#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:1881
octave_value op_el_ldiv(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1886
octave_value op_uplus(const octave_value &a)
Definition: ov.h:1839
octave_value op_add(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1868
octave_value op_gt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1880
octave_value op_uminus(const octave_value &a)
Definition: ov.h:1840
octave_value op_el_div(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1884
octave_value op_mul_herm(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1902
octave_value op_transpose(const octave_value &a)
Definition: ov.h:1842
octave_value op_el_or(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1888
octave_value op_sub(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1869
octave_value op_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1870
octave_value op_hermitian(const octave_value &a)
Definition: ov.h:1843
octave_value op_le(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1877
octave_value op_el_and(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1887
octave_value op_herm_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1901
octave_value op_eq(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1878
octave_value op_el_pow(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1885
octave_value op_not(const octave_value &a)
Definition: ov.h:1838
octave_value op_ldiv(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1874
octave_value op_pow(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1873
octave_value op_ge(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1879
octave_value op_el_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1883
octave_value op_div(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1871
octave_value op_trans_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1899
octave_value op_mul_trans(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1900
octave_value op_lt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1876
Matrix xdiv(const Matrix &a, const SparseMatrix &b, MatrixType &typ)
Definition: sparse-xdiv.cc:137
Matrix xleftdiv(const SparseMatrix &a, const Matrix &b, MatrixType &typ)
Definition: sparse-xdiv.cc:468
octave_value elem_xpow(double a, const SparseMatrix &b)
Definition: sparse-xpow.cc:347
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:391