Mercurial > octave-nkf
annotate src/OPERATORS/op-m-m.cc @ 9607:1be3c73ed7b5
reuse temporary arrays in nested expressions
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 03 Sep 2009 08:48:51 +0200 |
parents | 3a1dd361f978 |
children | afcf852256d2 |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, |
8920 | 4 2006, 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-re-mat.h" | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
32 #include "ov-flt-re-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 // matrix unary ops. |
40 | |
4550 | 41 DEFNDUNOP_OP (not, matrix, array, !) |
4965 | 42 DEFNDUNOP_OP (uplus, matrix, array, /* no-op */) |
4550 | 43 DEFNDUNOP_OP (uminus, matrix, array, -) |
3203 | 44 |
45 DEFUNOP (transpose, matrix) | |
46 { | |
47 CAST_UNOP_ARG (const octave_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.matrix_value().transpose ()); | |
3203 | 56 } |
57 | |
58 DEFNCUNOP_METHOD (incr, matrix, increment) | |
59 DEFNCUNOP_METHOD (decr, matrix, decrement) | |
9607
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9557
diff
changeset
|
60 DEFNCUNOP_METHOD (changesign, matrix, changesign) |
3203 | 61 |
2928 | 62 // matrix by matrix ops. |
63 | |
4543 | 64 DEFNDBINOP_OP (add, matrix, matrix, array, array, +) |
65 DEFNDBINOP_OP (sub, matrix, matrix, array, array, -) | |
66 | |
2928 | 67 DEFBINOP_OP (mul, matrix, matrix, *) |
5785 | 68 |
69 DEFBINOP (div, matrix, matrix) | |
70 { | |
71 CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&); | |
72 MatrixType typ = v2.matrix_type (); | |
73 | |
74 Matrix ret = xdiv (v1.matrix_value (), v2.matrix_value (), typ); | |
75 | |
76 v2.matrix_type (typ); | |
77 return ret; | |
78 } | |
2928 | 79 |
80 DEFBINOPX (pow, matrix, matrix) | |
81 { | |
82 error ("can't do A ^ B for A and B both matrices"); | |
83 return octave_value (); | |
84 } | |
85 | |
5785 | 86 DEFBINOP (ldiv, matrix, matrix) |
87 { | |
88 CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&); | |
89 MatrixType typ = v1.matrix_type (); | |
90 | |
91 Matrix ret = xleftdiv (v1.matrix_value (), v2.matrix_value (), typ); | |
92 | |
93 v1.matrix_type (typ); | |
94 return ret; | |
95 } | |
2928 | 96 |
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
|
97 DEFBINOP (trans_mul, matrix, 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
|
98 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
99 CAST_BINOP_ARGS (const octave_matrix&, const octave_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
|
100 return octave_value(xgemm (true, v1.matrix_value (), false, v2.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
|
101 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
102 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
103 DEFBINOP (mul_trans, matrix, 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
|
104 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
105 CAST_BINOP_ARGS (const octave_matrix&, const octave_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
|
106 return octave_value(xgemm (false, v1.matrix_value (), true, v2.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
|
107 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
108 |
4543 | 109 DEFNDBINOP_FN (lt, matrix, matrix, array, array, mx_el_lt) |
110 DEFNDBINOP_FN (le, matrix, matrix, array, array, mx_el_le) | |
111 DEFNDBINOP_FN (eq, matrix, matrix, array, array, mx_el_eq) | |
112 DEFNDBINOP_FN (ge, matrix, matrix, array, array, mx_el_ge) | |
113 DEFNDBINOP_FN (gt, matrix, matrix, array, array, mx_el_gt) | |
114 DEFNDBINOP_FN (ne, matrix, matrix, array, array, mx_el_ne) | |
2928 | 115 |
4543 | 116 DEFNDBINOP_FN (el_mul, matrix, matrix, array, array, product) |
117 DEFNDBINOP_FN (el_div, matrix, matrix, array, array, quotient) | |
118 DEFNDBINOP_FN (el_pow, matrix, matrix, array, array, elem_xpow) | |
2928 | 119 |
120 DEFBINOP (el_ldiv, matrix, matrix) | |
121 { | |
122 CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&); | |
123 | |
4543 | 124 return octave_value (quotient (v2.array_value (), v1.array_value ())); |
2928 | 125 } |
126 | |
4543 | 127 DEFNDBINOP_FN (el_and, matrix, matrix, array, array, mx_el_and) |
128 DEFNDBINOP_FN (el_or, matrix, matrix, array, array, mx_el_or) | |
8982
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
129 DEFNDBINOP_FN (el_not_and, matrix, matrix, array, array, mx_el_not_and) |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
130 DEFNDBINOP_FN (el_not_or, matrix, matrix, array, array, mx_el_not_or) |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
131 DEFNDBINOP_FN (el_and_not, matrix, matrix, array, array, mx_el_and_not) |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
132 DEFNDBINOP_FN (el_or_not, matrix, matrix, array, array, mx_el_or_not) |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
133 |
4532 | 134 |
4915 | 135 DEFNDCATOP_FN (m_m, matrix, matrix, array, array, concat) |
136 | |
4686 | 137 DEFNDASSIGNOP_FN (assign, matrix, matrix, array, assign) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
138 DEFNDASSIGNOP_FN (sgl_assign, float_matrix, matrix, float_array, assign) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
139 |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
140 DEFNULLASSIGNOP_FN (null_assign, matrix, delete_elements) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
141 |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8993
diff
changeset
|
142 DEFNDASSIGNOP_OP (assign_add, matrix, matrix, array, +=) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8993
diff
changeset
|
143 DEFNDASSIGNOP_OP (assign_sub, matrix, matrix, array, -=) |
9557
3a1dd361f978
optimize .*=, ./= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
144 DEFNDASSIGNOP_FNOP (assign_el_mul, matrix, matrix, array, product_eq) |
3a1dd361f978
optimize .*=, ./= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
145 DEFNDASSIGNOP_FNOP (assign_el_div, matrix, matrix, array, quotient_eq) |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8993
diff
changeset
|
146 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
147 CONVDECL (matrix_to_float_matrix) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
148 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
149 CAST_CONV_ARG (const octave_matrix&); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
150 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
151 return new octave_float_matrix (FloatNDArray (v.array_value ())); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
152 } |
2928 | 153 |
154 void | |
155 install_m_m_ops (void) | |
156 { | |
3538 | 157 INSTALL_UNOP (op_not, octave_matrix, not); |
4965 | 158 INSTALL_UNOP (op_uplus, octave_matrix, uplus); |
3538 | 159 INSTALL_UNOP (op_uminus, octave_matrix, uminus); |
160 INSTALL_UNOP (op_transpose, octave_matrix, transpose); | |
161 INSTALL_UNOP (op_hermitian, octave_matrix, transpose); | |
3203 | 162 |
3538 | 163 INSTALL_NCUNOP (op_incr, octave_matrix, incr); |
164 INSTALL_NCUNOP (op_decr, octave_matrix, decr); | |
9607
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9557
diff
changeset
|
165 INSTALL_NCUNOP (op_uminus, octave_matrix, changesign); |
3203 | 166 |
3538 | 167 INSTALL_BINOP (op_add, octave_matrix, octave_matrix, add); |
168 INSTALL_BINOP (op_sub, octave_matrix, octave_matrix, sub); | |
169 INSTALL_BINOP (op_mul, octave_matrix, octave_matrix, mul); | |
170 INSTALL_BINOP (op_div, octave_matrix, octave_matrix, div); | |
171 INSTALL_BINOP (op_pow, octave_matrix, octave_matrix, pow); | |
172 INSTALL_BINOP (op_ldiv, octave_matrix, octave_matrix, ldiv); | |
173 INSTALL_BINOP (op_lt, octave_matrix, octave_matrix, lt); | |
174 INSTALL_BINOP (op_le, octave_matrix, octave_matrix, le); | |
175 INSTALL_BINOP (op_eq, octave_matrix, octave_matrix, eq); | |
176 INSTALL_BINOP (op_ge, octave_matrix, octave_matrix, ge); | |
177 INSTALL_BINOP (op_gt, octave_matrix, octave_matrix, gt); | |
178 INSTALL_BINOP (op_ne, octave_matrix, octave_matrix, ne); | |
179 INSTALL_BINOP (op_el_mul, octave_matrix, octave_matrix, el_mul); | |
180 INSTALL_BINOP (op_el_div, octave_matrix, octave_matrix, el_div); | |
181 INSTALL_BINOP (op_el_pow, octave_matrix, octave_matrix, el_pow); | |
182 INSTALL_BINOP (op_el_ldiv, octave_matrix, octave_matrix, el_ldiv); | |
183 INSTALL_BINOP (op_el_and, octave_matrix, octave_matrix, el_and); | |
184 INSTALL_BINOP (op_el_or, octave_matrix, octave_matrix, el_or); | |
8993
6769599e3458
add missing binops installs
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
185 INSTALL_BINOP (op_el_and_not, octave_matrix, octave_matrix, el_and_not); |
6769599e3458
add missing binops installs
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
186 INSTALL_BINOP (op_el_or_not, octave_matrix, octave_matrix, el_or_not); |
6769599e3458
add missing binops installs
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
187 INSTALL_BINOP (op_el_not_and, octave_matrix, octave_matrix, el_not_and); |
6769599e3458
add missing binops installs
Jaroslav Hajek <highegg@gmail.com>
parents:
8982
diff
changeset
|
188 INSTALL_BINOP (op_el_not_or, octave_matrix, octave_matrix, el_not_or); |
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
|
189 INSTALL_BINOP (op_trans_mul, octave_matrix, octave_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
|
190 INSTALL_BINOP (op_mul_trans, octave_matrix, octave_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
|
191 INSTALL_BINOP (op_herm_mul, octave_matrix, octave_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
|
192 INSTALL_BINOP (op_mul_herm, octave_matrix, octave_matrix, mul_trans); |
2928 | 193 |
4915 | 194 INSTALL_CATOP (octave_matrix, octave_matrix, m_m); |
195 | |
3538 | 196 INSTALL_ASSIGNOP (op_asn_eq, octave_matrix, octave_matrix, assign); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
197 INSTALL_ASSIGNOP (op_asn_eq, octave_float_matrix, octave_matrix, sgl_assign); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
198 |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
199 INSTALL_ASSIGNOP (op_asn_eq, octave_matrix, octave_null_matrix, null_assign); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
200 INSTALL_ASSIGNOP (op_asn_eq, octave_matrix, octave_null_str, null_assign); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
201 INSTALL_ASSIGNOP (op_asn_eq, octave_matrix, octave_null_sq_str, null_assign); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
202 |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8993
diff
changeset
|
203 INSTALL_ASSIGNOP (op_add_eq, octave_matrix, octave_matrix, assign_add); |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8993
diff
changeset
|
204 INSTALL_ASSIGNOP (op_sub_eq, octave_matrix, octave_matrix, assign_sub); |
9557
3a1dd361f978
optimize .*=, ./= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
205 INSTALL_ASSIGNOP (op_el_mul_eq, octave_matrix, octave_matrix, assign_el_mul); |
3a1dd361f978
optimize .*=, ./= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
206 INSTALL_ASSIGNOP (op_el_div_eq, octave_matrix, octave_matrix, assign_el_div); |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8993
diff
changeset
|
207 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
208 INSTALL_CONVOP (octave_matrix, octave_float_matrix, matrix_to_float_matrix); |
2928 | 209 } |
210 | |
211 /* | |
212 ;;; Local Variables: *** | |
213 ;;; mode: C++ *** | |
214 ;;; End: *** | |
215 */ |