GNU Octave  4.4.1
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-2018 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include "errwarn.h"
28 #include "ovl.h"
29 #include "ov.h"
30 #include "ov-cx-mat.h"
31 #include "ov-flt-cx-mat.h"
32 #include "ov-typeinfo.h"
33 #include "ov-null-mat.h"
34 #include "ops.h"
35 #include "xdiv.h"
36 #include "xpow.h"
37 
38 // unary complex matrix ops.
39 
40 DEFNDUNOP_OP (not, complex_matrix, complex_array, !)
41 DEFNDUNOP_OP (uplus, complex_matrix, complex_array, /* no-op */)
42 DEFNDUNOP_OP (uminus, complex_matrix, complex_array, -)
43 
44 DEFUNOP (transpose, complex_matrix)
45 {
46  const octave_complex_matrix& v
47  = dynamic_cast<const octave_complex_matrix&> (a);
48 
49  if (v.ndims () > 2)
50  error ("transpose not defined for N-D objects");
51 
53 }
54 
55 DEFUNOP (hermitian, complex_matrix)
56 {
57  const octave_complex_matrix& v
58  = dynamic_cast<const octave_complex_matrix&> (a);
59 
60  if (v.ndims () > 2)
61  error ("complex-conjugate transpose not defined for N-D objects");
62 
64 }
65 
66 DEFNCUNOP_METHOD (incr, complex_matrix, increment)
67 DEFNCUNOP_METHOD (decr, complex_matrix, decrement)
68 DEFNCUNOP_METHOD (changesign, complex_matrix, changesign)
69 
70 // complex matrix by complex matrix ops.
71 
72 DEFNDBINOP_OP (add, complex_matrix, complex_matrix, complex_array,
73  complex_array, +)
74 DEFNDBINOP_OP (sub, complex_matrix, complex_matrix, complex_array,
75  complex_array, -)
76 
77 DEFBINOP_OP (mul, complex_matrix, complex_matrix, *)
78 
79 DEFBINOP (div, complex_matrix, complex_matrix)
80 {
81  const octave_complex_matrix& v1
82  = dynamic_cast<const octave_complex_matrix&> (a1);
84  = dynamic_cast<const octave_complex_matrix&> (a2);
85  MatrixType typ = v2.matrix_type ();
86 
88  v2.complex_matrix_value (), typ);
89 
90  v2.matrix_type (typ);
91  return ret;
92 }
93 
94 DEFBINOPX (pow, complex_matrix, complex_matrix)
95 {
96  error ("can't do A ^ B for A and B both matrices");
97 }
98 
99 DEFBINOP (ldiv, complex_matrix, complex_matrix)
100 {
101  const octave_complex_matrix& v1
102  = dynamic_cast<const octave_complex_matrix&> (a1);
104  = dynamic_cast<const octave_complex_matrix&> (a2);
105  MatrixType typ = v1.matrix_type ();
106 
108  v2.complex_matrix_value (), typ);
109 
110  v1.matrix_type (typ);
111  return ret;
112 }
113 
114 DEFBINOP (trans_mul, complex_matrix, complex_matrix)
115 {
116  const octave_complex_matrix& v1
117  = dynamic_cast<const octave_complex_matrix&> (a1);
119  = dynamic_cast<const octave_complex_matrix&> (a2);
123 }
124 
125 DEFBINOP (mul_trans, complex_matrix, complex_matrix)
126 {
127  const octave_complex_matrix& v1
128  = dynamic_cast<const octave_complex_matrix&> (a1);
130  = dynamic_cast<const octave_complex_matrix&> (a2);
134 }
135 
136 DEFBINOP (herm_mul, complex_matrix, complex_matrix)
137 {
138  const octave_complex_matrix& v1
139  = dynamic_cast<const octave_complex_matrix&> (a1);
141  = dynamic_cast<const octave_complex_matrix&> (a2);
145 }
146 
147 DEFBINOP (mul_herm, complex_matrix, complex_matrix)
148 {
149  const octave_complex_matrix& v1
150  = dynamic_cast<const octave_complex_matrix&> (a1);
152  = dynamic_cast<const octave_complex_matrix&> (a2);
156 }
157 
158 DEFBINOP (trans_ldiv, complex_matrix, complex_matrix)
159 {
160  const octave_complex_matrix& v1
161  = dynamic_cast<const octave_complex_matrix&> (a1);
163  = dynamic_cast<const octave_complex_matrix&> (a2);
164  MatrixType typ = v1.matrix_type ();
165 
168 
169  v1.matrix_type (typ);
170  return ret;
171 }
172 
173 DEFBINOP (herm_ldiv, complex_matrix, complex_matrix)
174 {
175  const octave_complex_matrix& v1
176  = dynamic_cast<const octave_complex_matrix&> (a1);
178  = dynamic_cast<const octave_complex_matrix&> (a2);
179  MatrixType typ = v1.matrix_type ();
180 
182  v2.complex_matrix_value (), typ,
184 
185  v1.matrix_type (typ);
186  return ret;
187 }
188 
189 DEFNDCMPLXCMPOP_FN (lt, complex_matrix, complex_matrix, complex_array,
190  complex_array, mx_el_lt)
191 DEFNDCMPLXCMPOP_FN (le, complex_matrix, complex_matrix, complex_array,
192  complex_array, mx_el_le)
193 DEFNDCMPLXCMPOP_FN (eq, complex_matrix, complex_matrix, complex_array,
194  complex_array, mx_el_eq)
195 DEFNDCMPLXCMPOP_FN (ge, complex_matrix, complex_matrix, complex_array,
196  complex_array, mx_el_ge)
197 DEFNDCMPLXCMPOP_FN (gt, complex_matrix, complex_matrix, complex_array,
198  complex_array, mx_el_gt)
199 DEFNDCMPLXCMPOP_FN (ne, complex_matrix, complex_matrix, complex_array,
200  complex_array, mx_el_ne)
201 
202 DEFNDBINOP_FN (el_mul, complex_matrix, complex_matrix, complex_array,
203  complex_array, product)
204 DEFNDBINOP_FN (el_div, complex_matrix, complex_matrix, complex_array,
205  complex_array, quotient)
206 DEFNDBINOP_FN (el_pow, complex_matrix, complex_matrix, complex_array,
207  complex_array, elem_xpow)
208 
209 DEFBINOP (el_ldiv, complex_matrix, complex_matrix)
210 {
211  const octave_complex_matrix& v1
212  = dynamic_cast<const octave_complex_matrix&> (a1);
214  = dynamic_cast<const octave_complex_matrix&> (a2);
215 
217  v1.complex_array_value ()));
218 }
219 
220 DEFNDBINOP_FN (el_and, complex_matrix, complex_matrix, complex_array,
221  complex_array, mx_el_and)
222 DEFNDBINOP_FN (el_or, complex_matrix, complex_matrix, complex_array,
223  complex_array, mx_el_or)
224 
225 DEFNDCATOP_FN (cm_cm, complex_matrix, complex_matrix, complex_array,
226  complex_array, concat)
227 
228 DEFNDASSIGNOP_FN (assign, complex_matrix, complex_matrix, complex_array, assign)
229 
230 DEFNULLASSIGNOP_FN (null_assign, complex_matrix, delete_elements)
231 
232 DEFNDASSIGNOP_OP (assign_add, complex_matrix, complex_matrix, complex_array, +=)
233 DEFNDASSIGNOP_OP (assign_sub, complex_matrix, complex_matrix, complex_array, -=)
234 DEFNDASSIGNOP_FNOP (assign_el_mul, complex_matrix, complex_matrix,
235  complex_array, product_eq)
236 DEFNDASSIGNOP_FNOP (assign_el_div, complex_matrix, complex_matrix,
237  complex_array, quotient_eq)
238 
239 void
240 install_cm_cm_ops (octave::type_info& ti)
241 {
247 
248  INSTALL_NCUNOP_TI (ti, op_incr, octave_complex_matrix, incr);
249  INSTALL_NCUNOP_TI (ti, op_decr, octave_complex_matrix, decr);
251 
253  add);
255  sub);
257  mul);
259  div);
261  pow);
263  ldiv);
266  trans_mul);
269  mul_trans);
271  herm_mul);
273  mul_herm);
274  INSTALL_BINOP_TI (ti, op_trans_ldiv, octave_complex_matrix,
276  trans_ldiv);
277  INSTALL_BINOP_TI (ti, op_herm_ldiv, octave_complex_matrix,
279  herm_ldiv);
280 
288  el_mul);
290  el_div);
292  el_pow);
294  el_ldiv);
296  el_and);
298  el_or);
299 
301 
304  assign);
305 
307  null_assign);
309  null_assign);
311  null_assign);
312 
315  assign_add);
318  assign_sub);
319  INSTALL_ASSIGNOP_TI (ti, op_el_mul_eq, octave_complex_matrix,
321  assign_el_mul);
322  INSTALL_ASSIGNOP_TI (ti, op_el_div_eq, octave_complex_matrix,
324  assign_el_div);
325 }
ComplexColumnVector quotient_eq(ComplexColumnVector &x, const ComplexColumnVector &y)
Definition: CColVector.h:150
ComplexColumnVector product(const ComplexColumnVector &x, const ComplexColumnVector &y)
Definition: CColVector.h:150
#define INSTALL_ASSIGNOP_TI(ti, op, t1, t2, f)
Definition: ops.h:62
octave_value op_mul_trans(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1635
octave_value op_uplus(const octave_value &a)
Definition: ov.h:1574
void install_cm_cm_ops(octave::type_info &ti)
Definition: op-cm-cm.cc:240
#define DEFBINOP(name, t1, t2)
Definition: ops.h:264
#define DEFUNOP(name, t)
Definition: ops.h:213
octave_value op_el_pow(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1620
#define DEFBINOPX(name, t1, t2)
Definition: ops.h:259
#define INSTALL_BINOP_TI(ti, op, t1, t2, f)
Definition: ops.h:53
octave_value op_eq(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1613
#define DEFNDASSIGNOP_FNOP(name, t1, t2, f, fnop)
Definition: ops.h:175
ComplexNDArray complex_array_value(bool=false) const
Definition: ov-cx-mat.h:127
#define DEFNULLASSIGNOP_FN(name, t, f)
Definition: ops.h:134
octave_value op_el_ldiv(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1621
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:386
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: CNDArray.cc:653
boolMatrix mx_el_le(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:89
void error(const char *fmt,...)
Definition: error.cc:578
octave_value op_pow(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1608
#define INSTALL_NCUNOP_TI(ti, op, t, f)
Definition: ops.h:49
#define DEFNDBINOP_FN(name, t1, t2, e1, e2, f)
Definition: ops.h:335
ComplexMatrix transpose(void) const
Definition: CMatrix.h:168
ComplexMatrix mul_trans(const ComplexMatrix &m, const SparseComplexMatrix &a)
Definition: CSparse.cc:7544
#define DEFBINOP_OP(name, t1, t2, op)
Definition: ops.h:269
const octave_base_value & a2
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:400
#define INSTALL_UNOP_TI(ti, op, t, f)
Definition: ops.h:45
ComplexMatrix complex_matrix_value(bool=false) const
Definition: ov-ch-mat.h:128
octave_value op_div(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1606
octave_value op_el_or(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1623
ComplexColumnVector quotient(const ComplexColumnVector &x, const ComplexColumnVector &y)
Definition: CColVector.h:150
boolMatrix mx_el_ge(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:89
octave_value op_not(const octave_value &a)
Definition: ov.h:1573
ComplexMatrix herm_mul(const SparseComplexMatrix &m, const ComplexMatrix &a)
Definition: CSparse.cc:7580
boolMatrix mx_el_gt(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:89
#define INSTALL_CATOP_TI(ti, t1, t2, f)
Definition: ops.h:58
octave_value op_trans_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1634
octave_value op_transpose(const octave_value &a)
Definition: ov.h:1577
ComplexNDArray complex_array_value(bool=false) const
Definition: ov-ch-mat.h:134
octave_value elem_xpow(double a, const SparseMatrix &b)
Definition: sparse-xpow.cc:247
octave_value op_el_and(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1622
octave_int< T > pow(const octave_int< T > &a, const octave_int< T > &b)
ComplexMatrix mul_herm(const ComplexMatrix &m, const SparseComplexMatrix &a)
Definition: CSparse.cc:7550
octave_value op_mul_herm(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1637
Matrix xleftdiv(const SparseMatrix &a, const Matrix &b, MatrixType &typ)
Definition: sparse-xdiv.cc:464
boolMatrix mx_el_ne(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:89
octave_value op_le(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1612
octave_value op_lt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1611
octave_value op_el_div(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1619
ComplexMatrix xgemm(const ComplexMatrix &a, const ComplexMatrix &b, blas_trans_type transa, blas_trans_type transb)
Definition: CMatrix.cc:3515
ComplexMatrix complex_matrix_value(bool=false) const
Definition: ov-cx-mat.cc:210
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
int ndims(void) const
Definition: ov-base-mat.h:109
const octave_char_matrix & v2
boolMatrix mx_el_or(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:86
#define DEFNDASSIGNOP_FN(name, t1, t2, e, f)
Definition: ops.h:146
Matrix xdiv(const Matrix &a, const SparseMatrix &b, MatrixType &typ)
Definition: sparse-xdiv.cc:133
octave_value op_ne(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1616
ComplexMatrix trans_mul(const SparseComplexMatrix &m, const ComplexMatrix &a)
Definition: CSparse.cc:7574
boolMatrix mx_el_and(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:86
MatrixType matrix_type(void) const
Definition: ov-base-mat.h:124
#define DEFNDASSIGNOP_OP(name, t1, t2, f, op)
Definition: ops.h:160
octave_value op_add(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1603
octave_value op_ldiv(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1609
#define DEFNDCMPLXCMPOP_FN(name, t1, t2, e1, e2, f)
Definition: ops.h:346
octave_value op_sub(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1604
boolMatrix mx_el_lt(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:89
octave_value op_el_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1618
octave_value op_herm_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1636
#define DEFNDUNOP_OP(name, t, e, op)
Definition: ops.h:225
octave_value op_hermitian(const octave_value &a)
Definition: ov.h:1578
octave_value op_ge(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1614
#define DEFNDBINOP_OP(name, t1, t2, e1, e2, op)
Definition: ops.h:310
#define DEFNDCATOP_FN(name, t1, t2, e1, e2, f)
Definition: ops.h:382
boolMatrix mx_el_eq(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:89
octave_value op_uminus(const octave_value &a)
Definition: ov.h:1575
octave_value op_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1605
ComplexColumnVector product_eq(ComplexColumnVector &x, const ComplexColumnVector &y)
Definition: CColVector.h:150
octave_value op_gt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1615
#define DEFNCUNOP_METHOD(name, t, method)
Definition: ops.h:251
ComplexMatrix hermitian(void) const
Definition: CMatrix.h:166