Mercurial > octave-nkf
annotate src/OPERATORS/op-cm-cm.cc @ 7800:5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 07 May 2008 16:33:15 +0200 |
parents | 82be108cc558 |
children | 283989f2da9b |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 2000, 2002, 2003, 2004, 2005, 2006, |
4 2007 John W. Eaton | |
2928 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2928 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2928 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include "gripes.h" | |
4055 | 29 #include "oct-obj.h" |
2928 | 30 #include "ov.h" |
31 #include "ov-cx-mat.h" | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
32 #include "ov-flt-cx-mat.h" |
2928 | 33 #include "ov-typeinfo.h" |
34 #include "ops.h" | |
35 #include "xdiv.h" | |
36 #include "xpow.h" | |
37 | |
3203 | 38 // unary complex matrix ops. |
39 | |
4550 | 40 DEFNDUNOP_OP (not, complex_matrix, complex_array, !) |
4965 | 41 DEFNDUNOP_OP (uplus, complex_matrix, complex_array, /* no-op */) |
4550 | 42 DEFNDUNOP_OP (uminus, complex_matrix, complex_array, -) |
3203 | 43 |
44 DEFUNOP (transpose, complex_matrix) | |
45 { | |
46 CAST_UNOP_ARG (const octave_complex_matrix&); | |
47 | |
4673 | 48 if (v.ndims () > 2) |
49 { | |
50 error ("transpose not defined for N-d objects"); | |
51 return octave_value (); | |
52 } | |
53 else | |
54 return octave_value (v.complex_matrix_value().transpose ()); | |
3203 | 55 } |
56 | |
57 DEFUNOP (hermitian, complex_matrix) | |
58 { | |
59 CAST_UNOP_ARG (const octave_complex_matrix&); | |
60 | |
4673 | 61 if (v.ndims () > 2) |
62 { | |
63 error ("complex-conjugate transpose not defined for N-d objects"); | |
64 return octave_value (); | |
65 } | |
66 else | |
67 return octave_value (v.complex_matrix_value().hermitian ()); | |
3203 | 68 } |
69 | |
70 DEFNCUNOP_METHOD (incr, complex_matrix, increment) | |
71 DEFNCUNOP_METHOD (decr, complex_matrix, decrement) | |
72 | |
2928 | 73 // complex matrix by complex matrix ops. |
74 | |
4550 | 75 DEFNDBINOP_OP (add, complex_matrix, complex_matrix, complex_array, complex_array, +) |
76 DEFNDBINOP_OP (sub, complex_matrix, complex_matrix, complex_array, complex_array, -) | |
4543 | 77 |
2928 | 78 DEFBINOP_OP (mul, complex_matrix, complex_matrix, *) |
5785 | 79 |
80 DEFBINOP (div, complex_matrix, complex_matrix) | |
81 { | |
82 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&); | |
83 MatrixType typ = v2.matrix_type (); | |
84 | |
85 ComplexMatrix ret = xdiv (v1.complex_matrix_value (), | |
86 v2.complex_matrix_value (), typ); | |
87 | |
88 v2.matrix_type (typ); | |
89 return ret; | |
90 } | |
2928 | 91 |
92 DEFBINOPX (pow, complex_matrix, complex_matrix) | |
93 { | |
94 error ("can't do A ^ B for A and B both matrices"); | |
95 return octave_value (); | |
96 } | |
97 | |
5785 | 98 DEFBINOP (ldiv, complex_matrix, complex_matrix) |
99 { | |
100 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&); | |
101 MatrixType typ = v1.matrix_type (); | |
102 | |
103 ComplexMatrix ret = xleftdiv (v1.complex_matrix_value (), | |
104 v2.complex_matrix_value (), typ); | |
105 | |
106 v1.matrix_type (typ); | |
107 return ret; | |
108 } | |
2928 | 109 |
7800
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
110 DEFBINOP (trans_mul, complex_matrix, complex_matrix) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
111 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
112 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
113 return octave_value(xgemm (true, false, v1.complex_matrix_value (), |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
114 false, false, v2.complex_matrix_value ())); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
115 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
116 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
117 DEFBINOP (mul_trans, complex_matrix, complex_matrix) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
118 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
119 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
120 return octave_value(xgemm (false, false, v1.complex_matrix_value (), |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
121 true, false, v2.complex_matrix_value ())); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
122 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
123 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
124 DEFBINOP (herm_mul, complex_matrix, complex_matrix) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
125 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
126 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
127 return octave_value(xgemm (true, true, v1.complex_matrix_value (), |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
128 false, false, v2.complex_matrix_value ())); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
129 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
130 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
131 DEFBINOP (mul_herm, complex_matrix, complex_matrix) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
132 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
133 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
134 return octave_value(xgemm (false, false, v1.complex_matrix_value (), |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
135 true, true, v2.complex_matrix_value ())); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
136 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
137 |
4550 | 138 DEFNDBINOP_FN (lt, complex_matrix, complex_matrix, complex_array, complex_array, mx_el_lt) |
139 DEFNDBINOP_FN (le, complex_matrix, complex_matrix, complex_array, complex_array, mx_el_le) | |
140 DEFNDBINOP_FN (eq, complex_matrix, complex_matrix, complex_array, complex_array, mx_el_eq) | |
141 DEFNDBINOP_FN (ge, complex_matrix, complex_matrix, complex_array, complex_array, mx_el_ge) | |
142 DEFNDBINOP_FN (gt, complex_matrix, complex_matrix, complex_array, complex_array, mx_el_gt) | |
143 DEFNDBINOP_FN (ne, complex_matrix, complex_matrix, complex_array, complex_array, mx_el_ne) | |
2928 | 144 |
4550 | 145 DEFNDBINOP_FN (el_mul, complex_matrix, complex_matrix, complex_array, complex_array, product) |
146 DEFNDBINOP_FN (el_div, complex_matrix, complex_matrix, complex_array, complex_array, quotient) | |
147 DEFNDBINOP_FN (el_pow, complex_matrix, complex_matrix, complex_array, complex_array, elem_xpow) | |
2928 | 148 |
149 DEFBINOP (el_ldiv, complex_matrix, complex_matrix) | |
150 { | |
151 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&); | |
152 | |
4550 | 153 return octave_value (quotient (v2.complex_array_value (), v1.complex_array_value ())); |
2928 | 154 } |
155 | |
4550 | 156 DEFNDBINOP_FN (el_and, complex_matrix, complex_matrix, complex_array, complex_array, mx_el_and) |
157 DEFNDBINOP_FN (el_or, complex_matrix, complex_matrix, complex_array, complex_array, mx_el_or) | |
2928 | 158 |
4915 | 159 DEFNDCATOP_FN (cm_cm, complex_matrix, complex_matrix, complex_array, complex_array, concat) |
160 | |
4686 | 161 DEFNDASSIGNOP_FN (assign, complex_matrix, complex_matrix, complex_array, assign) |
2928 | 162 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
163 CONVDECL (complex_matrix_to_float_complex_matrix) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
164 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
165 CAST_CONV_ARG (const octave_complex_matrix&); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
166 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
167 return new octave_float_complex_matrix (FloatComplexNDArray (v.complex_array_value ())); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
168 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
169 |
2928 | 170 void |
171 install_cm_cm_ops (void) | |
172 { | |
3538 | 173 INSTALL_UNOP (op_not, octave_complex_matrix, not); |
4965 | 174 INSTALL_UNOP (op_uplus, octave_complex_matrix, uplus); |
3538 | 175 INSTALL_UNOP (op_uminus, octave_complex_matrix, uminus); |
176 INSTALL_UNOP (op_transpose, octave_complex_matrix, transpose); | |
177 INSTALL_UNOP (op_hermitian, octave_complex_matrix, hermitian); | |
3203 | 178 |
3538 | 179 INSTALL_NCUNOP (op_incr, octave_complex_matrix, incr); |
180 INSTALL_NCUNOP (op_decr, octave_complex_matrix, decr); | |
3203 | 181 |
3538 | 182 INSTALL_BINOP (op_add, octave_complex_matrix, octave_complex_matrix, add); |
183 INSTALL_BINOP (op_sub, octave_complex_matrix, octave_complex_matrix, sub); | |
184 INSTALL_BINOP (op_mul, octave_complex_matrix, octave_complex_matrix, mul); | |
185 INSTALL_BINOP (op_div, octave_complex_matrix, octave_complex_matrix, div); | |
186 INSTALL_BINOP (op_pow, octave_complex_matrix, octave_complex_matrix, pow); | |
187 INSTALL_BINOP (op_ldiv, octave_complex_matrix, octave_complex_matrix, ldiv); | |
7800
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
188 INSTALL_BINOP (op_trans_mul, octave_complex_matrix, octave_complex_matrix, trans_mul); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
189 INSTALL_BINOP (op_mul_trans, octave_complex_matrix, octave_complex_matrix, mul_trans); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
190 INSTALL_BINOP (op_herm_mul, octave_complex_matrix, octave_complex_matrix, herm_mul); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
191 INSTALL_BINOP (op_mul_herm, octave_complex_matrix, octave_complex_matrix, mul_herm); |
3538 | 192 INSTALL_BINOP (op_lt, octave_complex_matrix, octave_complex_matrix, lt); |
193 INSTALL_BINOP (op_le, octave_complex_matrix, octave_complex_matrix, le); | |
194 INSTALL_BINOP (op_eq, octave_complex_matrix, octave_complex_matrix, eq); | |
195 INSTALL_BINOP (op_ge, octave_complex_matrix, octave_complex_matrix, ge); | |
196 INSTALL_BINOP (op_gt, octave_complex_matrix, octave_complex_matrix, gt); | |
197 INSTALL_BINOP (op_ne, octave_complex_matrix, octave_complex_matrix, ne); | |
198 INSTALL_BINOP (op_el_mul, octave_complex_matrix, octave_complex_matrix, el_mul); | |
199 INSTALL_BINOP (op_el_div, octave_complex_matrix, octave_complex_matrix, el_div); | |
200 INSTALL_BINOP (op_el_pow, octave_complex_matrix, octave_complex_matrix, el_pow); | |
201 INSTALL_BINOP (op_el_ldiv, octave_complex_matrix, octave_complex_matrix, el_ldiv); | |
202 INSTALL_BINOP (op_el_and, octave_complex_matrix, octave_complex_matrix, el_and); | |
203 INSTALL_BINOP (op_el_or, octave_complex_matrix, octave_complex_matrix, el_or); | |
2928 | 204 |
4915 | 205 INSTALL_CATOP (octave_complex_matrix, octave_complex_matrix, cm_cm); |
206 | |
3538 | 207 INSTALL_ASSIGNOP (op_asn_eq, octave_complex_matrix, octave_complex_matrix, assign); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
208 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
209 INSTALL_CONVOP (octave_complex_matrix, octave_float_complex_matrix, |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
210 complex_matrix_to_float_complex_matrix); |
2928 | 211 } |
212 | |
213 /* | |
214 ;;; Local Variables: *** | |
215 ;;; mode: C++ *** | |
216 ;;; End: *** | |
217 */ |