Mercurial > hg > octave-nkf
annotate src/OPERATORS/op-m-m.cc @ 12121:87237a866c71 release-3-2-x
this branch is no longer maintained and is closed for further development
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 22 Jan 2011 01:00:54 -0500 |
parents | 6769599e3458 |
children | 1beb23d2b892 |
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) | |
60 | |
2928 | 61 // matrix by matrix ops. |
62 | |
4543 | 63 DEFNDBINOP_OP (add, matrix, matrix, array, array, +) |
64 DEFNDBINOP_OP (sub, matrix, matrix, array, array, -) | |
65 | |
2928 | 66 DEFBINOP_OP (mul, matrix, matrix, *) |
5785 | 67 |
68 DEFBINOP (div, matrix, matrix) | |
69 { | |
70 CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&); | |
71 MatrixType typ = v2.matrix_type (); | |
72 | |
73 Matrix ret = xdiv (v1.matrix_value (), v2.matrix_value (), typ); | |
74 | |
75 v2.matrix_type (typ); | |
76 return ret; | |
77 } | |
2928 | 78 |
79 DEFBINOPX (pow, matrix, matrix) | |
80 { | |
81 error ("can't do A ^ B for A and B both matrices"); | |
82 return octave_value (); | |
83 } | |
84 | |
5785 | 85 DEFBINOP (ldiv, matrix, matrix) |
86 { | |
87 CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&); | |
88 MatrixType typ = v1.matrix_type (); | |
89 | |
90 Matrix ret = xleftdiv (v1.matrix_value (), v2.matrix_value (), typ); | |
91 | |
92 v1.matrix_type (typ); | |
93 return ret; | |
94 } | |
2928 | 95 |
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
|
96 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
|
97 { |
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 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
|
99 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
|
100 } |
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 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
|
103 { |
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 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
|
105 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
|
106 } |
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 |
4543 | 108 DEFNDBINOP_FN (lt, matrix, matrix, array, array, mx_el_lt) |
109 DEFNDBINOP_FN (le, matrix, matrix, array, array, mx_el_le) | |
110 DEFNDBINOP_FN (eq, matrix, matrix, array, array, mx_el_eq) | |
111 DEFNDBINOP_FN (ge, matrix, matrix, array, array, mx_el_ge) | |
112 DEFNDBINOP_FN (gt, matrix, matrix, array, array, mx_el_gt) | |
113 DEFNDBINOP_FN (ne, matrix, matrix, array, array, mx_el_ne) | |
2928 | 114 |
4543 | 115 DEFNDBINOP_FN (el_mul, matrix, matrix, array, array, product) |
116 DEFNDBINOP_FN (el_div, matrix, matrix, array, array, quotient) | |
117 DEFNDBINOP_FN (el_pow, matrix, matrix, array, array, elem_xpow) | |
2928 | 118 |
119 DEFBINOP (el_ldiv, matrix, matrix) | |
120 { | |
121 CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&); | |
122 | |
4543 | 123 return octave_value (quotient (v2.array_value (), v1.array_value ())); |
2928 | 124 } |
125 | |
4543 | 126 DEFNDBINOP_FN (el_and, matrix, matrix, array, array, mx_el_and) |
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 |
4532 | 133 |
4915 | 134 DEFNDCATOP_FN (m_m, matrix, matrix, array, array, concat) |
135 | |
4686 | 136 DEFNDASSIGNOP_FN (assign, matrix, matrix, array, assign) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
137 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
|
138 |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
139 DEFNULLASSIGNOP_FN (null_assign, matrix, delete_elements) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
140 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
141 CONVDECL (matrix_to_float_matrix) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
142 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
143 CAST_CONV_ARG (const octave_matrix&); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
144 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
145 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
|
146 } |
2928 | 147 |
148 void | |
149 install_m_m_ops (void) | |
150 { | |
3538 | 151 INSTALL_UNOP (op_not, octave_matrix, not); |
4965 | 152 INSTALL_UNOP (op_uplus, octave_matrix, uplus); |
3538 | 153 INSTALL_UNOP (op_uminus, octave_matrix, uminus); |
154 INSTALL_UNOP (op_transpose, octave_matrix, transpose); | |
155 INSTALL_UNOP (op_hermitian, octave_matrix, transpose); | |
3203 | 156 |
3538 | 157 INSTALL_NCUNOP (op_incr, octave_matrix, incr); |
158 INSTALL_NCUNOP (op_decr, octave_matrix, decr); | |
3203 | 159 |
3538 | 160 INSTALL_BINOP (op_add, octave_matrix, octave_matrix, add); |
161 INSTALL_BINOP (op_sub, octave_matrix, octave_matrix, sub); | |
162 INSTALL_BINOP (op_mul, octave_matrix, octave_matrix, mul); | |
163 INSTALL_BINOP (op_div, octave_matrix, octave_matrix, div); | |
164 INSTALL_BINOP (op_pow, octave_matrix, octave_matrix, pow); | |
165 INSTALL_BINOP (op_ldiv, octave_matrix, octave_matrix, ldiv); | |
166 INSTALL_BINOP (op_lt, octave_matrix, octave_matrix, lt); | |
167 INSTALL_BINOP (op_le, octave_matrix, octave_matrix, le); | |
168 INSTALL_BINOP (op_eq, octave_matrix, octave_matrix, eq); | |
169 INSTALL_BINOP (op_ge, octave_matrix, octave_matrix, ge); | |
170 INSTALL_BINOP (op_gt, octave_matrix, octave_matrix, gt); | |
171 INSTALL_BINOP (op_ne, octave_matrix, octave_matrix, ne); | |
172 INSTALL_BINOP (op_el_mul, octave_matrix, octave_matrix, el_mul); | |
173 INSTALL_BINOP (op_el_div, octave_matrix, octave_matrix, el_div); | |
174 INSTALL_BINOP (op_el_pow, octave_matrix, octave_matrix, el_pow); | |
175 INSTALL_BINOP (op_el_ldiv, octave_matrix, octave_matrix, el_ldiv); | |
176 INSTALL_BINOP (op_el_and, octave_matrix, octave_matrix, el_and); | |
177 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
|
178 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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 INSTALL_BINOP (op_mul_herm, octave_matrix, octave_matrix, mul_trans); |
2928 | 186 |
4915 | 187 INSTALL_CATOP (octave_matrix, octave_matrix, m_m); |
188 | |
3538 | 189 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
|
190 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
|
191 |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
192 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
|
193 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
|
194 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
|
195 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
196 INSTALL_CONVOP (octave_matrix, octave_float_matrix, matrix_to_float_matrix); |
2928 | 197 } |
198 | |
199 /* | |
200 ;;; Local Variables: *** | |
201 ;;; mode: C++ *** | |
202 ;;; End: *** | |
203 */ |