Mercurial > octave
annotate src/OPERATORS/op-cm-cs.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 | 319e2ab9b8ae |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2005, 2006, |
8920 | 4 2007, 2009 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" | |
8679
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
32 #include "ov-flt-cx-mat.h" |
2928 | 33 #include "ov-complex.h" |
34 #include "ov-typeinfo.h" | |
35 #include "ops.h" | |
36 #include "xdiv.h" | |
37 #include "xpow.h" | |
38 | |
39 // complex matrix by complex scalar ops. | |
40 | |
4550 | 41 DEFNDBINOP_OP (add, complex_matrix, complex, complex_array, complex, +) |
42 DEFNDBINOP_OP (sub, complex_matrix, complex, complex_array, complex, -) | |
43 DEFNDBINOP_OP (mul, complex_matrix, complex, complex_array, complex, *) | |
2928 | 44 |
45 DEFBINOP (div, complex_matrix, complex) | |
46 { | |
47 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex&); | |
48 | |
49 Complex d = v2.complex_value (); | |
50 | |
51 if (d == 0.0) | |
52 gripe_divide_by_zero (); | |
53 | |
4550 | 54 return octave_value (v1.complex_array_value () / d); |
2928 | 55 } |
56 | |
57 DEFBINOP_FN (pow, complex_matrix, complex, xpow) | |
58 | |
59 DEFBINOP (ldiv, complex_matrix, complex) | |
60 { | |
3766 | 61 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex&); |
62 | |
63 ComplexMatrix m1 = v1.complex_matrix_value (); | |
64 ComplexMatrix m2 = v2.complex_matrix_value (); | |
5785 | 65 MatrixType typ = v1.matrix_type (); |
3766 | 66 |
5785 | 67 ComplexMatrix ret = xleftdiv (m1, m2, typ); |
68 v1.matrix_type (typ); | |
69 return ret; | |
2928 | 70 } |
71 | |
4550 | 72 DEFNDBINOP_FN (lt, complex_matrix, complex, complex_array, complex, mx_el_lt) |
73 DEFNDBINOP_FN (le, complex_matrix, complex, complex_array, complex, mx_el_le) | |
74 DEFNDBINOP_FN (eq, complex_matrix, complex, complex_array, complex, mx_el_eq) | |
75 DEFNDBINOP_FN (ge, complex_matrix, complex, complex_array, complex, mx_el_ge) | |
76 DEFNDBINOP_FN (gt, complex_matrix, complex, complex_array, complex, mx_el_gt) | |
77 DEFNDBINOP_FN (ne, complex_matrix, complex, complex_array, complex, mx_el_ne) | |
2928 | 78 |
4550 | 79 DEFNDBINOP_OP (el_mul, complex_matrix, complex, complex_array, complex, *) |
2928 | 80 |
81 DEFBINOP (el_div, complex_matrix, complex) | |
82 { | |
83 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex&); | |
84 | |
85 Complex d = v2.complex_value (); | |
86 | |
87 if (d == 0.0) | |
88 gripe_divide_by_zero (); | |
89 | |
4550 | 90 return octave_value (v1.complex_array_value () / d); |
2928 | 91 } |
92 | |
4550 | 93 DEFNDBINOP_FN (el_pow, complex_matrix, complex, complex_array, complex, elem_xpow) |
2928 | 94 |
95 DEFBINOP (el_ldiv, complex_matrix, complex) | |
96 { | |
97 CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex&); | |
98 | |
4550 | 99 return x_el_div (v2.complex_value (), v1.complex_array_value ()); |
2928 | 100 } |
101 | |
4550 | 102 DEFNDBINOP_FN (el_and, complex_matrix, complex, complex_array, complex, mx_el_and) |
103 DEFNDBINOP_FN (el_or, complex_matrix, complex, complex_array, complex, mx_el_or) | |
2928 | 104 |
4915 | 105 DEFNDCATOP_FN (cm_cs, complex_matrix, complex, complex_array, complex_array, concat) |
106 | |
8679
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
107 DEFNDASSIGNOP_FN (assign, complex_matrix, complex, complex, assign) |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
108 DEFNDASSIGNOP_FN (sgl_assign, float_complex_matrix, complex, float_complex, assign) |
2928 | 109 |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
110 DEFNDASSIGNOP_OP (assign_add, complex_matrix, complex_scalar, complex, +=) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
111 DEFNDASSIGNOP_OP (assign_sub, complex_matrix, complex_scalar, complex, -=) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
112 DEFNDASSIGNOP_OP (assign_mul, complex_matrix, complex_scalar, complex, *=) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
113 DEFNDASSIGNOP_OP (assign_div, complex_matrix, complex_scalar, complex, /=) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
114 |
2928 | 115 void |
116 install_cm_cs_ops (void) | |
117 { | |
3538 | 118 INSTALL_BINOP (op_add, octave_complex_matrix, octave_complex, add); |
119 INSTALL_BINOP (op_sub, octave_complex_matrix, octave_complex, sub); | |
120 INSTALL_BINOP (op_mul, octave_complex_matrix, octave_complex, mul); | |
121 INSTALL_BINOP (op_div, octave_complex_matrix, octave_complex, div); | |
122 INSTALL_BINOP (op_pow, octave_complex_matrix, octave_complex, pow); | |
123 INSTALL_BINOP (op_ldiv, octave_complex_matrix, octave_complex, ldiv); | |
124 INSTALL_BINOP (op_lt, octave_complex_matrix, octave_complex, lt); | |
125 INSTALL_BINOP (op_le, octave_complex_matrix, octave_complex, le); | |
126 INSTALL_BINOP (op_eq, octave_complex_matrix, octave_complex, eq); | |
127 INSTALL_BINOP (op_ge, octave_complex_matrix, octave_complex, ge); | |
128 INSTALL_BINOP (op_gt, octave_complex_matrix, octave_complex, gt); | |
129 INSTALL_BINOP (op_ne, octave_complex_matrix, octave_complex, ne); | |
130 INSTALL_BINOP (op_el_mul, octave_complex_matrix, octave_complex, el_mul); | |
131 INSTALL_BINOP (op_el_div, octave_complex_matrix, octave_complex, el_div); | |
132 INSTALL_BINOP (op_el_pow, octave_complex_matrix, octave_complex, el_pow); | |
133 INSTALL_BINOP (op_el_ldiv, octave_complex_matrix, octave_complex, el_ldiv); | |
134 INSTALL_BINOP (op_el_and, octave_complex_matrix, octave_complex, el_and); | |
135 INSTALL_BINOP (op_el_or, octave_complex_matrix, octave_complex, el_or); | |
2928 | 136 |
4915 | 137 INSTALL_CATOP (octave_complex_matrix, octave_complex, cm_cs); |
138 | |
3538 | 139 INSTALL_ASSIGNOP (op_asn_eq, octave_complex_matrix, octave_complex, assign); |
8679
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
140 INSTALL_ASSIGNOP (op_asn_eq, octave_float_complex_matrix, octave_complex, sgl_assign); |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
141 |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
142 INSTALL_ASSIGNOP (op_add_eq, octave_complex_matrix, octave_complex_scalar, assign_add); |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
143 INSTALL_ASSIGNOP (op_sub_eq, octave_complex_matrix, octave_complex_scalar, assign_sub); |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
144 INSTALL_ASSIGNOP (op_mul_eq, octave_complex_matrix, octave_complex_scalar, assign_mul); |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
145 INSTALL_ASSIGNOP (op_div_eq, octave_complex_matrix, octave_complex_scalar, assign_div); |
2928 | 146 } |
147 | |
148 /* | |
149 ;;; Local Variables: *** | |
150 ;;; mode: C++ *** | |
151 ;;; End: *** | |
152 */ |