5164
|
1 /* |
|
2 |
|
3 Copyright (C) 2004 David Bateman |
|
4 Copyright (C) 1998-2004 Andy Adler |
|
5 |
|
6 Octave is free software; you can redistribute it and/or modify it |
|
7 under the terms of the GNU General Public License as published by the |
|
8 Free Software Foundation; either version 2, or (at your option) any |
|
9 later version. |
|
10 |
|
11 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 for more details. |
|
15 |
|
16 You should have received a copy of the GNU General Public License |
5307
|
17 along with this program; see the file COPYING. If not, write to the |
|
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
19 Boston, MA 02110-1301, USA. |
5164
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include "gripes.h" |
|
28 #include "oct-obj.h" |
|
29 #include "ov.h" |
|
30 #include "ov-typeinfo.h" |
|
31 #include "ov-cx-mat.h" |
|
32 #include "ov-complex.h" |
|
33 #include "ops.h" |
|
34 #include "xpow.h" |
|
35 |
|
36 #include "sparse-xpow.h" |
|
37 #include "sparse-xdiv.h" |
|
38 #include "ov-cx-sparse.h" |
|
39 |
|
40 // sparse complex matrix by complex scalar ops. |
|
41 |
|
42 DEFBINOP_OP (add, sparse_complex_matrix, complex, +) |
|
43 DEFBINOP_OP (sub, sparse_complex_matrix, complex, -) |
|
44 DEFBINOP_OP (mul, sparse_complex_matrix, complex, *) |
|
45 |
|
46 DEFBINOP (div, sparse_complex_matrix, complex) |
|
47 { |
|
48 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, |
|
49 const octave_complex&); |
|
50 |
|
51 Complex d = v2.complex_value (); |
|
52 octave_value retval; |
|
53 |
|
54 if (d == 0.0) |
|
55 { |
|
56 gripe_divide_by_zero (); |
|
57 |
|
58 retval = (v1.complex_matrix_value () / d); |
|
59 } |
|
60 else |
|
61 retval = octave_value (v1.sparse_complex_matrix_value () / d); |
|
62 |
|
63 return retval; |
|
64 } |
|
65 |
|
66 DEFBINOP (pow, sparse_complex_matrix, complex) |
|
67 { |
|
68 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, |
|
69 const octave_complex&); |
|
70 return xpow (v1.complex_matrix_value (), v2.scalar_value ()); |
|
71 } |
|
72 |
|
73 DEFBINOP (ldiv, sparse_complex_matrix, complex) |
|
74 { |
5760
|
75 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, const octave_complex&); |
5164
|
76 |
5322
|
77 SparseType typ = v1.sparse_type (); |
5164
|
78 SparseComplexMatrix m1 = v1.sparse_complex_matrix_value (); |
|
79 ComplexMatrix m2 = ComplexMatrix (1, 1, v2.complex_value ()); |
5322
|
80 ComplexMatrix ret = xleftdiv (m1, m2, typ); |
|
81 v1.sparse_type (typ); |
5164
|
82 |
5322
|
83 return ret; |
5164
|
84 } |
|
85 |
|
86 DEFBINOP_FN (lt, sparse_complex_matrix, complex, mx_el_lt) |
|
87 DEFBINOP_FN (le, sparse_complex_matrix, complex, mx_el_le) |
|
88 DEFBINOP_FN (eq, sparse_complex_matrix, complex, mx_el_eq) |
|
89 DEFBINOP_FN (ge, sparse_complex_matrix, complex, mx_el_ge) |
|
90 DEFBINOP_FN (gt, sparse_complex_matrix, complex, mx_el_gt) |
|
91 DEFBINOP_FN (ne, sparse_complex_matrix, complex, mx_el_ne) |
|
92 |
|
93 DEFBINOP_OP (el_mul, sparse_complex_matrix, complex, *) |
|
94 |
|
95 DEFBINOP (el_div, sparse_complex_matrix, complex) |
|
96 { |
|
97 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, |
|
98 const octave_complex&); |
|
99 |
|
100 octave_value retval; |
|
101 |
|
102 Complex d = v2.complex_value (); |
|
103 |
|
104 if (d == 0.0) |
|
105 { |
|
106 gripe_divide_by_zero (); |
|
107 |
|
108 retval = octave_value (v1.complex_matrix_value () / d); |
|
109 } |
|
110 else |
|
111 retval = octave_value (v1.sparse_complex_matrix_value () / d); |
|
112 |
|
113 return retval; |
|
114 } |
|
115 |
|
116 DEFBINOP_FN (el_pow, sparse_complex_matrix, complex, elem_xpow) |
|
117 |
|
118 DEFBINOP (el_ldiv, sparse_complex_matrix, complex) |
|
119 { |
|
120 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, |
|
121 const octave_complex&); |
|
122 |
|
123 return octave_value |
|
124 (x_el_div (v2.complex_value (), v1.sparse_complex_matrix_value ())); |
|
125 } |
|
126 |
|
127 DEFBINOP_FN (el_and, sparse_complex_matrix, complex, mx_el_and) |
|
128 DEFBINOP_FN (el_or, sparse_complex_matrix, complex, mx_el_or) |
|
129 |
|
130 DEFCATOP (scm_cs, sparse_complex_matrix, complex) |
|
131 { |
|
132 CAST_BINOP_ARGS (octave_sparse_complex_matrix&, const octave_complex&); |
|
133 SparseComplexMatrix tmp (1, 1, v2.complex_value ()); |
|
134 return octave_value |
|
135 (v1.sparse_complex_matrix_value (). concat (tmp, ra_idx)); |
|
136 } |
|
137 |
|
138 DEFASSIGNOP (assign, sparse_complex_matrix, complex) |
|
139 { |
|
140 CAST_BINOP_ARGS (octave_sparse_complex_matrix&, const octave_complex&); |
|
141 |
|
142 SparseComplexMatrix tmp (1, 1, v2.complex_value ()); |
|
143 v1.assign (idx, tmp); |
|
144 return octave_value (); |
|
145 } |
|
146 |
|
147 void |
|
148 install_scm_cs_ops (void) |
|
149 { |
|
150 INSTALL_BINOP (op_add, octave_sparse_complex_matrix, octave_complex, add); |
|
151 INSTALL_BINOP (op_sub, octave_sparse_complex_matrix, octave_complex, sub); |
|
152 INSTALL_BINOP (op_mul, octave_sparse_complex_matrix, octave_complex, mul); |
|
153 INSTALL_BINOP (op_div, octave_sparse_complex_matrix, octave_complex, div); |
|
154 INSTALL_BINOP (op_pow, octave_sparse_complex_matrix, octave_complex, pow); |
|
155 INSTALL_BINOP (op_ldiv, octave_sparse_complex_matrix, octave_complex, |
|
156 ldiv); |
|
157 INSTALL_BINOP (op_lt, octave_sparse_complex_matrix, octave_complex, lt); |
|
158 INSTALL_BINOP (op_le, octave_sparse_complex_matrix, octave_complex, le); |
|
159 INSTALL_BINOP (op_eq, octave_sparse_complex_matrix, octave_complex, eq); |
|
160 INSTALL_BINOP (op_ge, octave_sparse_complex_matrix, octave_complex, ge); |
|
161 INSTALL_BINOP (op_gt, octave_sparse_complex_matrix, octave_complex, gt); |
|
162 INSTALL_BINOP (op_ne, octave_sparse_complex_matrix, octave_complex, ne); |
|
163 INSTALL_BINOP (op_el_mul, octave_sparse_complex_matrix, octave_complex, |
|
164 el_mul); |
|
165 INSTALL_BINOP (op_el_div, octave_sparse_complex_matrix, octave_complex, |
|
166 el_div); |
|
167 INSTALL_BINOP (op_el_pow, octave_sparse_complex_matrix, octave_complex, |
|
168 el_pow); |
|
169 INSTALL_BINOP (op_el_ldiv, octave_sparse_complex_matrix, octave_complex, |
|
170 el_ldiv); |
|
171 INSTALL_BINOP (op_el_and, octave_sparse_complex_matrix, octave_complex, |
|
172 el_and); |
|
173 INSTALL_BINOP (op_el_or, octave_sparse_complex_matrix, octave_complex, |
|
174 el_or); |
|
175 |
|
176 INSTALL_CATOP (octave_sparse_complex_matrix, octave_complex, scm_cs); |
|
177 |
|
178 INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_complex_matrix, octave_complex, |
|
179 assign); |
|
180 } |
|
181 |
|
182 /* |
|
183 ;;; Local Variables: *** |
|
184 ;;; mode: C++ *** |
|
185 ;;; End: *** |
|
186 */ |