Mercurial > octave
annotate src/OPERATORS/op-cm-cm.cc @ 9546:1beb23d2b892
optimize op= in common cases
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 19 Aug 2009 13:47:59 +0200 |
parents | eb63fbe60fab |
children | 3a1dd361f978 |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 2000, 2002, 2003, 2004, 2005, 2006, |
8920 | 4 2007, 2008 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" |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
34 #include "ov-null-mat.h" |
2928 | 35 #include "ops.h" |
36 #include "xdiv.h" | |
37 #include "xpow.h" | |
38 | |
3203 | 39 // unary complex matrix ops. |
40 | |
4550 | 41 DEFNDUNOP_OP (not, complex_matrix, complex_array, !) |
4965 | 42 DEFNDUNOP_OP (uplus, complex_matrix, complex_array, /* no-op */) |
4550 | 43 DEFNDUNOP_OP (uminus, complex_matrix, complex_array, -) |
3203 | 44 |
45 DEFUNOP (transpose, complex_matrix) | |
46 { | |
47 CAST_UNOP_ARG (const octave_complex_matrix&); | |
48 | |
4673 | 49 if (v.ndims () > 2) |
50 { | |
51 error ("transpose not defined for N-d objects"); | |
52 return octave_value (); | |
53 } | |
54 else | |
55 return octave_value (v.complex_matrix_value().transpose ()); | |
3203 | 56 } |
57 | |
58 DEFUNOP (hermitian, complex_matrix) | |
59 { | |
60 CAST_UNOP_ARG (const octave_complex_matrix&); | |
61 | |
4673 | 62 if (v.ndims () > 2) |
63 { | |
64 error ("complex-conjugate transpose not defined for N-d objects"); | |
65 return octave_value (); | |
66 } | |
67 else | |
68 return octave_value (v.complex_matrix_value().hermitian ()); | |
3203 | 69 } |
70 | |
71 DEFNCUNOP_METHOD (incr, complex_matrix, increment) | |
72 DEFNCUNOP_METHOD (decr, complex_matrix, decrement) | |
73 | |
2928 | 74 // complex matrix by complex matrix ops. |
75 | |
4550 | 76 DEFNDBINOP_OP (add, complex_matrix, complex_matrix, complex_array, complex_array, +) |
77 DEFNDBINOP_OP (sub, complex_matrix, complex_matrix, complex_array, complex_array, -) | |
4543 | 78 |
2928 | 79 DEFBINOP_OP (mul, complex_matrix, complex_matrix, *) |
5785 | 80 |
81 DEFBINOP (div, complex_matrix, complex_matrix) | |
82 { | |
83 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&); | |
84 MatrixType typ = v2.matrix_type (); | |
85 | |
86 ComplexMatrix ret = xdiv (v1.complex_matrix_value (), | |
87 v2.complex_matrix_value (), typ); | |
88 | |
89 v2.matrix_type (typ); | |
90 return ret; | |
91 } | |
2928 | 92 |
93 DEFBINOPX (pow, complex_matrix, complex_matrix) | |
94 { | |
95 error ("can't do A ^ B for A and B both matrices"); | |
96 return octave_value (); | |
97 } | |
98 | |
5785 | 99 DEFBINOP (ldiv, complex_matrix, complex_matrix) |
100 { | |
101 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&); | |
102 MatrixType typ = v1.matrix_type (); | |
103 | |
104 ComplexMatrix ret = xleftdiv (v1.complex_matrix_value (), | |
105 v2.complex_matrix_value (), typ); | |
106 | |
107 v1.matrix_type (typ); | |
108 return ret; | |
109 } | |
2928 | 110 |
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
|
111 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
|
112 { |
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 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
|
114 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
|
115 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
|
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 |
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 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
|
119 { |
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 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
|
121 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
|
122 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
|
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 |
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 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
|
126 { |
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 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
|
128 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
|
129 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
|
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 |
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 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
|
133 { |
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 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
|
135 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
|
136 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
|
137 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
138 |
4550 | 139 DEFNDBINOP_FN (lt, complex_matrix, complex_matrix, complex_array, complex_array, mx_el_lt) |
140 DEFNDBINOP_FN (le, complex_matrix, complex_matrix, complex_array, complex_array, mx_el_le) | |
141 DEFNDBINOP_FN (eq, complex_matrix, complex_matrix, complex_array, complex_array, mx_el_eq) | |
142 DEFNDBINOP_FN (ge, complex_matrix, complex_matrix, complex_array, complex_array, mx_el_ge) | |
143 DEFNDBINOP_FN (gt, complex_matrix, complex_matrix, complex_array, complex_array, mx_el_gt) | |
144 DEFNDBINOP_FN (ne, complex_matrix, complex_matrix, complex_array, complex_array, mx_el_ne) | |
2928 | 145 |
4550 | 146 DEFNDBINOP_FN (el_mul, complex_matrix, complex_matrix, complex_array, complex_array, product) |
147 DEFNDBINOP_FN (el_div, complex_matrix, complex_matrix, complex_array, complex_array, quotient) | |
148 DEFNDBINOP_FN (el_pow, complex_matrix, complex_matrix, complex_array, complex_array, elem_xpow) | |
2928 | 149 |
150 DEFBINOP (el_ldiv, complex_matrix, complex_matrix) | |
151 { | |
152 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&); | |
153 | |
4550 | 154 return octave_value (quotient (v2.complex_array_value (), v1.complex_array_value ())); |
2928 | 155 } |
156 | |
4550 | 157 DEFNDBINOP_FN (el_and, complex_matrix, complex_matrix, complex_array, complex_array, mx_el_and) |
158 DEFNDBINOP_FN (el_or, complex_matrix, complex_matrix, complex_array, complex_array, mx_el_or) | |
2928 | 159 |
4915 | 160 DEFNDCATOP_FN (cm_cm, complex_matrix, complex_matrix, complex_array, complex_array, concat) |
161 | |
4686 | 162 DEFNDASSIGNOP_FN (assign, complex_matrix, complex_matrix, complex_array, assign) |
2928 | 163 |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
164 DEFNULLASSIGNOP_FN (null_assign, complex_matrix, delete_elements) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
165 |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
166 DEFNDASSIGNOP_OP (assign_add, complex_matrix, complex_matrix, complex_array, +=) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
167 DEFNDASSIGNOP_OP (assign_sub, complex_matrix, complex_matrix, complex_array, -=) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
168 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
169 CONVDECL (complex_matrix_to_float_complex_matrix) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
170 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
171 CAST_CONV_ARG (const octave_complex_matrix&); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
172 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
173 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
|
174 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
175 |
2928 | 176 void |
177 install_cm_cm_ops (void) | |
178 { | |
3538 | 179 INSTALL_UNOP (op_not, octave_complex_matrix, not); |
4965 | 180 INSTALL_UNOP (op_uplus, octave_complex_matrix, uplus); |
3538 | 181 INSTALL_UNOP (op_uminus, octave_complex_matrix, uminus); |
182 INSTALL_UNOP (op_transpose, octave_complex_matrix, transpose); | |
183 INSTALL_UNOP (op_hermitian, octave_complex_matrix, hermitian); | |
3203 | 184 |
3538 | 185 INSTALL_NCUNOP (op_incr, octave_complex_matrix, incr); |
186 INSTALL_NCUNOP (op_decr, octave_complex_matrix, decr); | |
3203 | 187 |
3538 | 188 INSTALL_BINOP (op_add, octave_complex_matrix, octave_complex_matrix, add); |
189 INSTALL_BINOP (op_sub, octave_complex_matrix, octave_complex_matrix, sub); | |
190 INSTALL_BINOP (op_mul, octave_complex_matrix, octave_complex_matrix, mul); | |
191 INSTALL_BINOP (op_div, octave_complex_matrix, octave_complex_matrix, div); | |
192 INSTALL_BINOP (op_pow, octave_complex_matrix, octave_complex_matrix, pow); | |
193 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
|
194 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
|
195 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
|
196 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
|
197 INSTALL_BINOP (op_mul_herm, octave_complex_matrix, octave_complex_matrix, mul_herm); |
3538 | 198 INSTALL_BINOP (op_lt, octave_complex_matrix, octave_complex_matrix, lt); |
199 INSTALL_BINOP (op_le, octave_complex_matrix, octave_complex_matrix, le); | |
200 INSTALL_BINOP (op_eq, octave_complex_matrix, octave_complex_matrix, eq); | |
201 INSTALL_BINOP (op_ge, octave_complex_matrix, octave_complex_matrix, ge); | |
202 INSTALL_BINOP (op_gt, octave_complex_matrix, octave_complex_matrix, gt); | |
203 INSTALL_BINOP (op_ne, octave_complex_matrix, octave_complex_matrix, ne); | |
204 INSTALL_BINOP (op_el_mul, octave_complex_matrix, octave_complex_matrix, el_mul); | |
205 INSTALL_BINOP (op_el_div, octave_complex_matrix, octave_complex_matrix, el_div); | |
206 INSTALL_BINOP (op_el_pow, octave_complex_matrix, octave_complex_matrix, el_pow); | |
207 INSTALL_BINOP (op_el_ldiv, octave_complex_matrix, octave_complex_matrix, el_ldiv); | |
208 INSTALL_BINOP (op_el_and, octave_complex_matrix, octave_complex_matrix, el_and); | |
209 INSTALL_BINOP (op_el_or, octave_complex_matrix, octave_complex_matrix, el_or); | |
2928 | 210 |
4915 | 211 INSTALL_CATOP (octave_complex_matrix, octave_complex_matrix, cm_cm); |
212 | |
3538 | 213 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
|
214 |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
215 INSTALL_ASSIGNOP (op_asn_eq, octave_complex_matrix, octave_null_matrix, null_assign); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
216 INSTALL_ASSIGNOP (op_asn_eq, octave_complex_matrix, octave_null_str, null_assign); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
217 INSTALL_ASSIGNOP (op_asn_eq, octave_complex_matrix, octave_null_sq_str, null_assign); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
218 |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
219 INSTALL_ASSIGNOP (op_add_eq, octave_complex_matrix, octave_complex_matrix, assign_add); |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
220 INSTALL_ASSIGNOP (op_sub_eq, octave_complex_matrix, octave_complex_matrix, assign_sub); |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
221 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
222 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
|
223 complex_matrix_to_float_complex_matrix); |
2928 | 224 } |
225 | |
226 /* | |
227 ;;; Local Variables: *** | |
228 ;;; mode: C++ *** | |
229 ;;; End: *** | |
230 */ |