GNU Octave  9.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-2024 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 {
52 
53  if (v.ndims () > 2)
54  error ("transpose not defined for N-D objects");
55 
56  return octave_value (v.complex_matrix_value ().transpose ());
57 }
58 
59 DEFUNOP (hermitian, complex_matrix)
60 {
62 
63  if (v.ndims () > 2)
64  error ("complex-conjugate transpose not defined for N-D objects");
65 
66  return octave_value (v.complex_matrix_value ().hermitian ());
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 {
86  MatrixType typ = v2.matrix_type ();
87 
88  ComplexMatrix ret = xdiv (v1.complex_matrix_value (),
89  v2.complex_matrix_value (), typ);
90 
91  v2.matrix_type (typ);
92  return ret;
93 }
94 
95 DEFBINOPX (pow, complex_matrix, complex_matrix)
96 {
97  error ("can't do A ^ B for A and B both matrices");
98 }
99 
100 DEFBINOP (ldiv, complex_matrix, complex_matrix)
101 {
104  MatrixType typ = v1.matrix_type ();
105 
106  ComplexMatrix ret = xleftdiv (v1.complex_matrix_value (),
107  v2.complex_matrix_value (), typ);
108 
109  v1.matrix_type (typ);
110  return ret;
111 }
112 
113 DEFBINOP (trans_mul, complex_matrix, complex_matrix)
114 {
117  return octave_value(xgemm (v1.complex_matrix_value (),
120 }
121 
122 DEFBINOP (mul_trans, complex_matrix, complex_matrix)
123 {
126  return octave_value(xgemm (v1.complex_matrix_value (),
129 }
130 
131 DEFBINOP (herm_mul, complex_matrix, complex_matrix)
132 {
135  return octave_value(xgemm (v1.complex_matrix_value (),
138 }
139 
140 DEFBINOP (mul_herm, complex_matrix, complex_matrix)
141 {
144  return octave_value(xgemm (v1.complex_matrix_value (),
147 }
148 
149 DEFBINOP (trans_ldiv, complex_matrix, complex_matrix)
150 {
153  MatrixType typ = v1.matrix_type ();
154 
155  ComplexMatrix ret = xleftdiv (v1.complex_matrix_value (),
157 
158  v1.matrix_type (typ);
159  return ret;
160 }
161 
162 DEFBINOP (herm_ldiv, complex_matrix, complex_matrix)
163 {
166  MatrixType typ = v1.matrix_type ();
167 
168  ComplexMatrix ret = xleftdiv (v1.complex_matrix_value (),
169  v2.complex_matrix_value (), typ,
171 
172  v1.matrix_type (typ);
173  return ret;
174 }
175 
176 DEFNDCMPLXCMPOP_FN (lt, complex_matrix, complex_matrix, complex_array,
177  complex_array, mx_el_lt)
178 DEFNDCMPLXCMPOP_FN (le, complex_matrix, complex_matrix, complex_array,
179  complex_array, mx_el_le)
180 DEFNDCMPLXCMPOP_FN (eq, complex_matrix, complex_matrix, complex_array,
181  complex_array, mx_el_eq)
182 DEFNDCMPLXCMPOP_FN (ge, complex_matrix, complex_matrix, complex_array,
183  complex_array, mx_el_ge)
184 DEFNDCMPLXCMPOP_FN (gt, complex_matrix, complex_matrix, complex_array,
185  complex_array, mx_el_gt)
186 DEFNDCMPLXCMPOP_FN (ne, complex_matrix, complex_matrix, complex_array,
187  complex_array, mx_el_ne)
188 
189 DEFNDBINOP_FN (el_mul, complex_matrix, complex_matrix, complex_array,
190  complex_array, product)
191 DEFNDBINOP_FN (el_div, complex_matrix, complex_matrix, complex_array,
192  complex_array, quotient)
193 DEFNDBINOP_FN (el_pow, complex_matrix, complex_matrix, complex_array,
194  complex_array, elem_xpow)
195 
196 DEFBINOP (el_ldiv, complex_matrix, complex_matrix)
197 {
200 
202  v1.complex_array_value ()));
203 }
204 
205 DEFNDBINOP_FN (el_and, complex_matrix, complex_matrix, complex_array,
206  complex_array, mx_el_and)
207 DEFNDBINOP_FN (el_or, complex_matrix, complex_matrix, complex_array,
208  complex_array, mx_el_or)
209 
210 DEFNDCATOP_FN (cm_cm, complex_matrix, complex_matrix, complex_array,
211  complex_array, concat)
212 
213 DEFNDASSIGNOP_FN (assign, complex_matrix, complex_matrix, complex_array, assign)
214 
215 DEFNULLASSIGNOP_FN (null_assign, complex_matrix, delete_elements)
216 
217 DEFNDASSIGNOP_OP (assign_add, complex_matrix, complex_matrix, complex_array, +=)
218 DEFNDASSIGNOP_OP (assign_sub, complex_matrix, complex_matrix, complex_array, -=)
219 DEFNDASSIGNOP_FNOP (assign_el_mul, complex_matrix, complex_matrix,
220  complex_array, product_eq)
221 DEFNDASSIGNOP_FNOP (assign_el_div, complex_matrix, complex_matrix,
222  complex_array, quotient_eq)
223 
224 void
226 {
232 
233  INSTALL_NCUNOP_TI (ti, op_incr, octave_complex_matrix, incr);
234  INSTALL_NCUNOP_TI (ti, op_decr, octave_complex_matrix, decr);
236 
238  add);
240  sub);
242  mul);
244  div);
246  pow);
248  ldiv);
251  trans_mul);
254  mul_trans);
256  herm_mul);
258  mul_herm);
259  INSTALL_BINOP_TI (ti, op_trans_ldiv, octave_complex_matrix,
261  trans_ldiv);
262  INSTALL_BINOP_TI (ti, op_herm_ldiv, octave_complex_matrix,
264  herm_ldiv);
265 
273  el_mul);
275  el_div);
277  el_pow);
279  el_ldiv);
281  el_and);
283  el_or);
284 
286 
289  assign);
290 
292  null_assign);
294  null_assign);
296  null_assign);
297 
300  assign_add);
303  assign_sub);
304  INSTALL_ASSIGNOP_TI (ti, op_el_mul_eq, octave_complex_matrix,
306  assign_el_mul);
307  INSTALL_ASSIGNOP_TI (ti, op_el_div_eq, octave_complex_matrix,
309  assign_el_div);
310 }
311 
312 OCTAVE_END_NAMESPACE(octave)
ComplexColumnVector quotient(const ComplexColumnVector &x, const ComplexColumnVector &y)
Definition: CColVector.h:158
ComplexColumnVector product_eq(ComplexColumnVector &x, const ComplexColumnVector &y)
Definition: CColVector.h:158
ComplexColumnVector product(const ComplexColumnVector &x, const ComplexColumnVector &y)
Definition: CColVector.h:158
ComplexColumnVector quotient_eq(ComplexColumnVector &x, const ComplexColumnVector &y)
Definition: CColVector.h:158
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:7516
ComplexMatrix mul_herm(const ComplexMatrix &m, const SparseComplexMatrix &a)
Definition: CSparse.cc:7522
ComplexMatrix trans_mul(const SparseComplexMatrix &m, const ComplexMatrix &a)
Definition: CSparse.cc:7546
ComplexMatrix herm_mul(const SparseComplexMatrix &m, const ComplexMatrix &a)
Definition: CSparse.cc:7552
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
MatrixType matrix_type() const
Definition: ov-base-mat.h:139
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
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void() error(const char *fmt,...)
Definition: error.cc:988
@ 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:225
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:127
#define DEFNDBINOP_OP(name, t1, t2, e1, e2, op)
Definition: ops.h:291
#define INSTALL_NCUNOP_TI(ti, op, t, f)
Definition: ops.h:66
#define DEFNULLASSIGNOP_FN(name, t, f)
Definition: ops.h:115
#define DEFNDBINOP_FN(name, t1, t2, e1, e2, f)
Definition: ops.h:316
#define DEFNDCMPLXCMPOP_FN(name, t1, t2, e1, e2, f)
Definition: ops.h:327
#define DEFBINOPX(name, t1, t2)
Definition: ops.h:240
#define DEFNDASSIGNOP_FNOP(name, t1, t2, f, fnop)
Definition: ops.h:156
#define DEFBINOP(name, t1, t2)
Definition: ops.h:245
#define DEFNDUNOP_OP(name, t, e, op)
Definition: ops.h:206
#define DEFBINOP_OP(name, t1, t2, op)
Definition: ops.h:250
#define OCTAVE_CAST_BASE_VALUE(T, T_VAL, BASE_VAL)
Definition: ops.h:52
#define DEFNCUNOP_METHOD(name, t, method)
Definition: ops.h:232
#define INSTALL_BINOP_TI(ti, op, t1, t2, f)
Definition: ops.h:70
#define DEFNDCATOP_FN(name, t1, t2, e1, e2, f)
Definition: ops.h:364
#define DEFUNOP(name, t)
Definition: ops.h:194
#define INSTALL_CATOP_TI(ti, t1, t2, f)
Definition: ops.h:75
#define INSTALL_UNOP_TI(ti, op, t, f)
Definition: ops.h:62
#define DEFNDASSIGNOP_OP(name, t1, t2, f, op)
Definition: ops.h:141
#define INSTALL_ASSIGNOP_TI(ti, op, t1, t2, f)
Definition: ops.h:79
octave_value op_ne(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1676
octave_value op_el_ldiv(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1681
octave_value op_uplus(const octave_value &a)
Definition: ov.h:1634
octave_value op_add(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1663
octave_value op_gt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1675
octave_value op_uminus(const octave_value &a)
Definition: ov.h:1635
octave_value op_el_div(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1679
octave_value op_mul_herm(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1697
octave_value op_transpose(const octave_value &a)
Definition: ov.h:1637
octave_value op_el_or(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1683
octave_value op_sub(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1664
octave_value op_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1665
octave_value op_hermitian(const octave_value &a)
Definition: ov.h:1638
octave_value op_le(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1672
octave_value op_el_and(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1682
octave_value op_herm_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1696
octave_value op_eq(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1673
octave_value op_el_pow(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1680
octave_value op_not(const octave_value &a)
Definition: ov.h:1633
octave_value op_ldiv(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1669
octave_value op_pow(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1668
octave_value op_ge(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1674
octave_value op_el_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1678
octave_value op_div(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1666
octave_value op_trans_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1694
octave_value op_mul_trans(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1695
octave_value op_lt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1671
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:469
octave_value elem_xpow(double a, const SparseMatrix &b)
Definition: sparse-xpow.cc:347