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 "ov-cx-mat.h" |
|
33 #include "ov-scalar.h" |
|
34 #include "ops.h" |
|
35 #include "xpow.h" |
|
36 |
|
37 #include "sparse-xpow.h" |
|
38 #include "sparse-xdiv.h" |
|
39 #include "smx-scm-s.h" |
|
40 #include "smx-s-scm.h" |
|
41 #include "ov-re-sparse.h" |
|
42 #include "ov-cx-sparse.h" |
|
43 |
|
44 // sparse complex matrix by scalar ops. |
|
45 |
|
46 DEFBINOP_OP (add, sparse_complex_matrix, scalar, +) |
|
47 DEFBINOP_OP (sub, sparse_complex_matrix, scalar, -) |
|
48 DEFBINOP_OP (mul, sparse_complex_matrix, scalar, *) |
|
49 |
|
50 DEFBINOP (div, sparse_complex_matrix, scalar) |
|
51 { |
|
52 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, |
|
53 const octave_scalar&); |
|
54 |
|
55 double d = v2.double_value (); |
|
56 octave_value retval; |
|
57 |
|
58 if (d == 0.0) |
|
59 { |
|
60 gripe_divide_by_zero (); |
|
61 |
|
62 retval = octave_value (v1.complex_matrix_value () / d); |
|
63 } |
|
64 else |
|
65 retval = octave_value (v1.sparse_complex_matrix_value () / d); |
|
66 |
|
67 return retval; |
|
68 } |
|
69 |
|
70 DEFBINOP (pow, sparse_complex_matrix, scalar) |
|
71 { |
|
72 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, |
|
73 const octave_scalar&); |
|
74 |
|
75 double tmp = v2.scalar_value (); |
|
76 if (static_cast<int> (tmp) == tmp) |
|
77 return xpow (v1.sparse_complex_matrix_value (), tmp); |
|
78 else |
|
79 return xpow (v1.complex_matrix_value (), tmp); |
|
80 } |
|
81 |
|
82 DEFBINOP (ldiv, sparse_complex_matrix, scalar) |
|
83 { |
5760
|
84 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, const octave_scalar&); |
5164
|
85 |
6221
|
86 if (v1.rows() == 1 && v1.columns() == 1) |
|
87 { |
|
88 Complex d = v1.complex_value (); |
|
89 |
|
90 if (d == 0.0) |
|
91 gripe_divide_by_zero (); |
5164
|
92 |
6221
|
93 return octave_value (v2.scalar_value () / d); |
|
94 } |
|
95 else |
|
96 { |
|
97 MatrixType typ = v1.matrix_type (); |
|
98 SparseComplexMatrix m1 = v1.sparse_complex_matrix_value (); |
|
99 Matrix m2 = Matrix (1, 1, v2.scalar_value ()); |
|
100 ComplexMatrix ret = xleftdiv (m1, m2, typ); |
|
101 v1.matrix_type (typ); |
|
102 return ret; |
|
103 } |
5164
|
104 } |
|
105 |
|
106 DEFBINOP_FN (lt, sparse_complex_matrix, scalar, mx_el_lt) |
|
107 DEFBINOP_FN (le, sparse_complex_matrix, scalar, mx_el_le) |
|
108 DEFBINOP_FN (eq, sparse_complex_matrix, scalar, mx_el_eq) |
|
109 DEFBINOP_FN (ge, sparse_complex_matrix, scalar, mx_el_ge) |
|
110 DEFBINOP_FN (gt, sparse_complex_matrix, scalar, mx_el_gt) |
|
111 DEFBINOP_FN (ne, sparse_complex_matrix, scalar, mx_el_ne) |
|
112 |
|
113 DEFBINOP_OP (el_mul, sparse_complex_matrix, scalar, *) |
|
114 |
|
115 DEFBINOP (el_div, sparse_complex_matrix, scalar) |
|
116 { |
|
117 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, |
|
118 const octave_scalar&); |
|
119 |
|
120 double d = v2.double_value (); |
|
121 octave_value retval; |
|
122 |
|
123 if (d == 0.0) |
|
124 { |
|
125 gripe_divide_by_zero (); |
|
126 |
|
127 retval = octave_value (v1.complex_matrix_value () / d); |
|
128 } |
|
129 else |
|
130 retval = octave_value (v1.sparse_complex_matrix_value () / d); |
|
131 |
|
132 return retval; |
|
133 } |
|
134 |
|
135 DEFBINOP_FN (el_pow, sparse_complex_matrix, scalar, elem_xpow) |
|
136 |
|
137 DEFBINOP (el_ldiv, sparse_complex_matrix, scalar) |
|
138 { |
|
139 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, const octave_scalar&); |
|
140 |
|
141 return octave_value |
|
142 (x_el_div (v2.double_value (), v1.sparse_complex_matrix_value ())); |
|
143 } |
|
144 |
|
145 DEFBINOP_FN (el_and, sparse_complex_matrix, scalar, mx_el_and) |
|
146 DEFBINOP_FN (el_or, sparse_complex_matrix, scalar, mx_el_or) |
|
147 |
|
148 DEFCATOP (scm_s, sparse_complex_matrix, scalar) |
|
149 { |
|
150 CAST_BINOP_ARGS (octave_sparse_complex_matrix&, const octave_scalar&); |
|
151 SparseComplexMatrix tmp (1, 1, v2.complex_value ()); |
|
152 return octave_value |
|
153 (v1.sparse_complex_matrix_value (). concat (tmp, ra_idx)); |
|
154 } |
|
155 |
|
156 DEFASSIGNOP (assign, sparse_complex_matrix, scalar) |
|
157 { |
|
158 CAST_BINOP_ARGS (octave_sparse_complex_matrix&, const octave_scalar&); |
|
159 |
|
160 SparseComplexMatrix tmp (1, 1, v2.complex_value ()); |
|
161 v1.assign (idx, tmp); |
|
162 return octave_value (); |
|
163 } |
|
164 |
|
165 void |
|
166 install_scm_s_ops (void) |
|
167 { |
|
168 INSTALL_BINOP (op_add, octave_sparse_complex_matrix, octave_scalar, add); |
|
169 INSTALL_BINOP (op_sub, octave_sparse_complex_matrix, octave_scalar, sub); |
|
170 INSTALL_BINOP (op_mul, octave_sparse_complex_matrix, octave_scalar, mul); |
|
171 INSTALL_BINOP (op_div, octave_sparse_complex_matrix, octave_scalar, div); |
|
172 INSTALL_BINOP (op_pow, octave_sparse_complex_matrix, octave_scalar, pow); |
|
173 INSTALL_BINOP (op_ldiv, octave_sparse_complex_matrix, octave_scalar, ldiv); |
|
174 INSTALL_BINOP (op_lt, octave_sparse_complex_matrix, octave_scalar, lt); |
|
175 INSTALL_BINOP (op_le, octave_sparse_complex_matrix, octave_scalar, le); |
|
176 INSTALL_BINOP (op_eq, octave_sparse_complex_matrix, octave_scalar, eq); |
|
177 INSTALL_BINOP (op_ge, octave_sparse_complex_matrix, octave_scalar, ge); |
|
178 INSTALL_BINOP (op_gt, octave_sparse_complex_matrix, octave_scalar, gt); |
|
179 INSTALL_BINOP (op_ne, octave_sparse_complex_matrix, octave_scalar, ne); |
|
180 INSTALL_BINOP (op_el_mul, octave_sparse_complex_matrix, octave_scalar, |
|
181 el_mul); |
|
182 INSTALL_BINOP (op_el_div, octave_sparse_complex_matrix, octave_scalar, |
|
183 el_div); |
|
184 INSTALL_BINOP (op_el_pow, octave_sparse_complex_matrix, octave_scalar, |
|
185 el_pow); |
|
186 INSTALL_BINOP (op_el_ldiv, octave_sparse_complex_matrix, octave_scalar, |
|
187 el_ldiv); |
|
188 INSTALL_BINOP (op_el_and, octave_sparse_complex_matrix, octave_scalar, |
|
189 el_and); |
|
190 INSTALL_BINOP (op_el_or, octave_sparse_complex_matrix, octave_scalar, |
|
191 el_or); |
|
192 |
|
193 INSTALL_CATOP (octave_sparse_complex_matrix, octave_scalar, scm_s); |
|
194 |
|
195 INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_complex_matrix, octave_scalar, |
|
196 assign); |
|
197 } |
|
198 |
|
199 /* |
|
200 ;;; Local Variables: *** |
|
201 ;;; mode: C++ *** |
|
202 ;;; End: *** |
|
203 */ |