5164
|
1 /* |
|
2 |
|
3 Copyright (C) 2004 David Bateman |
7016
|
4 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Andy Adler |
|
5 |
|
6 This file is part of Octave. |
5164
|
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. |
5164
|
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/>. |
5164
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include "gripes.h" |
|
29 #include "oct-obj.h" |
|
30 #include "ov.h" |
|
31 #include "ov-typeinfo.h" |
|
32 #include "ops.h" |
|
33 |
|
34 #include "sparse-xdiv.h" |
|
35 #include "sparse-xpow.h" |
|
36 #include "ov-re-sparse.h" |
|
37 #include "ov-cx-sparse.h" |
|
38 |
|
39 #ifdef HAVE_CONFIG_H |
|
40 #include <config.h> |
|
41 #endif |
|
42 |
|
43 #include "gripes.h" |
|
44 #include "oct-obj.h" |
|
45 #include "ov.h" |
|
46 #include "ov-cx-mat.h" |
|
47 #include "ov-typeinfo.h" |
|
48 #include "ops.h" |
|
49 #include "xdiv.h" |
|
50 #include "xpow.h" |
|
51 |
|
52 // unary sparse complex matrix ops. |
|
53 |
|
54 DEFUNOP_OP (not, sparse_complex_matrix, !) |
|
55 DEFUNOP_OP (uplus, sparse_complex_matrix, /* no-op */) |
|
56 DEFUNOP_OP (uminus, sparse_complex_matrix, -) |
|
57 |
|
58 DEFUNOP (transpose, sparse_complex_matrix) |
|
59 { |
|
60 CAST_UNOP_ARG (const octave_sparse_complex_matrix&); |
5322
|
61 return octave_value |
|
62 (v.sparse_complex_matrix_value().transpose (), |
5785
|
63 v.matrix_type ().transpose ()); |
5164
|
64 } |
|
65 |
|
66 DEFUNOP (hermitian, sparse_complex_matrix) |
|
67 { |
|
68 CAST_UNOP_ARG (const octave_sparse_complex_matrix&); |
5322
|
69 return octave_value |
|
70 (v.sparse_complex_matrix_value().hermitian (), |
5785
|
71 v.matrix_type ().transpose ()); |
5164
|
72 } |
|
73 |
|
74 #if 0 |
|
75 DEFUNOP (incr, sparse_complex_matrix) |
|
76 { |
|
77 CAST_UNOP_ARG (const octave_sparse_complex_matrix&); |
|
78 |
|
79 return octave_value (v.complex_matrix_value () .increment ()); |
|
80 } |
|
81 |
|
82 DEFUNOP (decr, sparse_complex_matrix) |
|
83 { |
|
84 CAST_UNOP_ARG (const octave_sparse_complex_matrix&); |
|
85 |
|
86 return octave_value (v.complex_matrix_value () .decrement ()); |
|
87 } |
|
88 #endif |
|
89 |
|
90 // complex matrix by complex matrix ops. |
|
91 |
|
92 DEFBINOP_OP (add, sparse_complex_matrix, sparse_complex_matrix, +) |
|
93 DEFBINOP_OP (sub, sparse_complex_matrix, sparse_complex_matrix, -) |
|
94 |
|
95 DEFBINOP_OP (mul, sparse_complex_matrix, sparse_complex_matrix, *) |
|
96 |
5322
|
97 DEFBINOP (div, sparse_complex_matrix, sparse_complex_matrix) |
|
98 { |
|
99 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, |
5760
|
100 const octave_sparse_complex_matrix&); |
6221
|
101 |
|
102 if (v2.rows() == 1 && v2.columns() == 1) |
|
103 { |
|
104 Complex d = v2.complex_value (); |
|
105 |
|
106 if (d == 0.0) |
|
107 gripe_divide_by_zero (); |
|
108 |
|
109 return octave_value (v1.sparse_complex_matrix_value () / d); |
|
110 } |
|
111 else |
|
112 { |
|
113 MatrixType typ = v2.matrix_type (); |
|
114 SparseComplexMatrix ret = xdiv (v1.sparse_complex_matrix_value (), |
|
115 v2.sparse_complex_matrix_value (), typ); |
5322
|
116 |
6221
|
117 v2.matrix_type (typ); |
|
118 return ret; |
|
119 } |
5322
|
120 } |
5164
|
121 |
|
122 DEFBINOPX (pow, sparse_complex_matrix, sparse_complex_matrix) |
|
123 { |
|
124 error ("can't do A ^ B for A and B both matrices"); |
|
125 return octave_value (); |
|
126 } |
|
127 |
5322
|
128 DEFBINOP (ldiv, sparse_complex_matrix, sparse_complex_matrix) |
|
129 { |
5760
|
130 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, |
5322
|
131 const octave_sparse_complex_matrix&); |
6221
|
132 |
|
133 if (v1.rows() == 1 && v1.columns() == 1) |
|
134 { |
|
135 Complex d = v1.complex_value (); |
|
136 |
|
137 if (d == 0.0) |
|
138 gripe_divide_by_zero (); |
5322
|
139 |
6221
|
140 return octave_value (v2.sparse_complex_matrix_value () / d); |
|
141 } |
|
142 else |
|
143 { |
|
144 MatrixType typ = v1.matrix_type (); |
5322
|
145 |
6221
|
146 SparseComplexMatrix ret = |
|
147 xleftdiv (v1.sparse_complex_matrix_value (), |
|
148 v2.sparse_complex_matrix_value (), typ); |
|
149 |
|
150 v1.matrix_type (typ); |
|
151 return ret; |
|
152 } |
5322
|
153 } |
5164
|
154 |
|
155 DEFBINOP_FN (lt, sparse_complex_matrix, sparse_complex_matrix, mx_el_lt) |
|
156 DEFBINOP_FN (le, sparse_complex_matrix, sparse_complex_matrix, mx_el_le) |
|
157 DEFBINOP_FN (eq, sparse_complex_matrix, sparse_complex_matrix, mx_el_eq) |
|
158 DEFBINOP_FN (ge, sparse_complex_matrix, sparse_complex_matrix, mx_el_ge) |
|
159 DEFBINOP_FN (gt, sparse_complex_matrix, sparse_complex_matrix, mx_el_gt) |
|
160 DEFBINOP_FN (ne, sparse_complex_matrix, sparse_complex_matrix, mx_el_ne) |
|
161 |
|
162 DEFBINOP_FN (el_mul, sparse_complex_matrix, sparse_complex_matrix, product) |
|
163 DEFBINOP_FN (el_div, sparse_complex_matrix, sparse_complex_matrix, quotient) |
|
164 DEFBINOP_FN (el_pow, sparse_complex_matrix, sparse_complex_matrix, elem_xpow) |
|
165 |
|
166 DEFBINOP (el_ldiv, sparse_complex_matrix, sparse_complex_matrix) |
|
167 { |
|
168 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, |
|
169 const octave_sparse_complex_matrix&); |
|
170 |
|
171 return octave_value (quotient (v2.sparse_complex_matrix_value (), |
|
172 v1.sparse_complex_matrix_value ())); |
|
173 } |
|
174 |
|
175 DEFBINOP_FN (el_and, sparse_complex_matrix, sparse_complex_matrix, mx_el_and) |
|
176 DEFBINOP_FN (el_or, sparse_complex_matrix, sparse_complex_matrix, mx_el_or) |
|
177 |
|
178 DEFCATOP_FN (scm_scm, sparse_complex_matrix, sparse_complex_matrix, concat) |
|
179 |
|
180 DEFASSIGNOP_FN (assign, sparse_complex_matrix, sparse_complex_matrix, assign) |
|
181 |
|
182 void |
|
183 install_scm_scm_ops (void) |
|
184 { |
|
185 INSTALL_UNOP (op_not, octave_sparse_complex_matrix, not); |
|
186 INSTALL_UNOP (op_uplus, octave_sparse_complex_matrix, uplus); |
|
187 INSTALL_UNOP (op_uminus, octave_sparse_complex_matrix, uminus); |
|
188 INSTALL_UNOP (op_transpose, octave_sparse_complex_matrix, transpose); |
|
189 INSTALL_UNOP (op_hermitian, octave_sparse_complex_matrix, hermitian); |
|
190 |
|
191 #if 0 |
|
192 INSTALL_NCUNOP (op_incr, octave_sparse_complex_matrix, incr); |
|
193 INSTALL_NCUNOP (op_decr, octave_sparse_complex_matrix, decr); |
|
194 #endif |
|
195 |
|
196 INSTALL_BINOP (op_add, octave_sparse_complex_matrix, |
|
197 octave_sparse_complex_matrix, add); |
|
198 INSTALL_BINOP (op_sub, octave_sparse_complex_matrix, |
|
199 octave_sparse_complex_matrix, sub); |
|
200 INSTALL_BINOP (op_mul, octave_sparse_complex_matrix, |
|
201 octave_sparse_complex_matrix, mul); |
|
202 INSTALL_BINOP (op_div, octave_sparse_complex_matrix, |
|
203 octave_sparse_complex_matrix, div); |
|
204 INSTALL_BINOP (op_pow, octave_sparse_complex_matrix, |
|
205 octave_sparse_complex_matrix, pow); |
|
206 INSTALL_BINOP (op_ldiv, octave_sparse_complex_matrix, |
|
207 octave_sparse_complex_matrix, ldiv); |
|
208 INSTALL_BINOP (op_lt, octave_sparse_complex_matrix, |
|
209 octave_sparse_complex_matrix, lt); |
|
210 INSTALL_BINOP (op_le, octave_sparse_complex_matrix, |
|
211 octave_sparse_complex_matrix, le); |
|
212 INSTALL_BINOP (op_eq, octave_sparse_complex_matrix, |
|
213 octave_sparse_complex_matrix, eq); |
|
214 INSTALL_BINOP (op_ge, octave_sparse_complex_matrix, |
|
215 octave_sparse_complex_matrix, ge); |
|
216 INSTALL_BINOP (op_gt, octave_sparse_complex_matrix, |
|
217 octave_sparse_complex_matrix, gt); |
|
218 INSTALL_BINOP (op_ne, octave_sparse_complex_matrix, |
|
219 octave_sparse_complex_matrix, ne); |
|
220 INSTALL_BINOP (op_el_mul, octave_sparse_complex_matrix, |
|
221 octave_sparse_complex_matrix, el_mul); |
|
222 INSTALL_BINOP (op_el_div, octave_sparse_complex_matrix, |
|
223 octave_sparse_complex_matrix, el_div); |
|
224 INSTALL_BINOP (op_el_pow, octave_sparse_complex_matrix, |
|
225 octave_sparse_complex_matrix, el_pow); |
|
226 INSTALL_BINOP (op_el_ldiv, octave_sparse_complex_matrix, |
|
227 octave_sparse_complex_matrix, el_ldiv); |
|
228 INSTALL_BINOP (op_el_and, octave_sparse_complex_matrix, |
|
229 octave_sparse_complex_matrix, el_and); |
|
230 INSTALL_BINOP (op_el_or, octave_sparse_complex_matrix, |
|
231 octave_sparse_complex_matrix, el_or); |
|
232 |
|
233 INSTALL_CATOP (octave_sparse_complex_matrix, |
|
234 octave_sparse_complex_matrix, scm_scm); |
|
235 |
|
236 INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_complex_matrix, |
|
237 octave_sparse_complex_matrix, assign); |
|
238 } |
|
239 |
|
240 /* |
|
241 ;;; Local Variables: *** |
|
242 ;;; mode: C++ *** |
|
243 ;;; End: *** |
|
244 */ |