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 |
|
17 along with this program; see the file COPYING. If not, write to the Free |
|
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
19 |
|
20 */ |
|
21 |
|
22 #ifdef HAVE_CONFIG_H |
|
23 #include <config.h> |
|
24 #endif |
|
25 |
|
26 #include "gripes.h" |
|
27 #include "oct-obj.h" |
|
28 #include "ov.h" |
|
29 #include "ov-typeinfo.h" |
|
30 #include "ov-cx-mat.h" |
|
31 #include "ov-scalar.h" |
|
32 #include "ops.h" |
|
33 #include "xpow.h" |
|
34 |
|
35 #include "sparse-xpow.h" |
|
36 #include "sparse-xdiv.h" |
|
37 #include "smx-scm-s.h" |
|
38 #include "smx-s-scm.h" |
|
39 #include "ov-re-sparse.h" |
|
40 #include "ov-cx-sparse.h" |
|
41 |
|
42 // sparse complex matrix by scalar ops. |
|
43 |
|
44 DEFBINOP_OP (add, sparse_complex_matrix, scalar, +) |
|
45 DEFBINOP_OP (sub, sparse_complex_matrix, scalar, -) |
|
46 DEFBINOP_OP (mul, sparse_complex_matrix, scalar, *) |
|
47 |
|
48 DEFBINOP (div, sparse_complex_matrix, scalar) |
|
49 { |
|
50 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, |
|
51 const octave_scalar&); |
|
52 |
|
53 double d = v2.double_value (); |
|
54 octave_value retval; |
|
55 |
|
56 if (d == 0.0) |
|
57 { |
|
58 gripe_divide_by_zero (); |
|
59 |
|
60 retval = octave_value (v1.complex_matrix_value () / d); |
|
61 } |
|
62 else |
|
63 retval = octave_value (v1.sparse_complex_matrix_value () / d); |
|
64 |
|
65 return retval; |
|
66 } |
|
67 |
|
68 DEFBINOP (pow, sparse_complex_matrix, scalar) |
|
69 { |
|
70 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, |
|
71 const octave_scalar&); |
|
72 |
|
73 double tmp = v2.scalar_value (); |
|
74 if (static_cast<int> (tmp) == tmp) |
|
75 return xpow (v1.sparse_complex_matrix_value (), tmp); |
|
76 else |
|
77 return xpow (v1.complex_matrix_value (), tmp); |
|
78 } |
|
79 |
|
80 DEFBINOP (ldiv, sparse_complex_matrix, scalar) |
|
81 { |
|
82 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, |
|
83 const octave_scalar&); |
|
84 |
|
85 SparseComplexMatrix m1 = v1.sparse_complex_matrix_value (); |
|
86 Matrix m2 = Matrix (1, 1, v2.scalar_value ()); |
|
87 |
|
88 return xleftdiv (m1, m2); |
|
89 } |
|
90 |
|
91 DEFBINOP_FN (lt, sparse_complex_matrix, scalar, mx_el_lt) |
|
92 DEFBINOP_FN (le, sparse_complex_matrix, scalar, mx_el_le) |
|
93 DEFBINOP_FN (eq, sparse_complex_matrix, scalar, mx_el_eq) |
|
94 DEFBINOP_FN (ge, sparse_complex_matrix, scalar, mx_el_ge) |
|
95 DEFBINOP_FN (gt, sparse_complex_matrix, scalar, mx_el_gt) |
|
96 DEFBINOP_FN (ne, sparse_complex_matrix, scalar, mx_el_ne) |
|
97 |
|
98 DEFBINOP_OP (el_mul, sparse_complex_matrix, scalar, *) |
|
99 |
|
100 DEFBINOP (el_div, sparse_complex_matrix, scalar) |
|
101 { |
|
102 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, |
|
103 const octave_scalar&); |
|
104 |
|
105 double d = v2.double_value (); |
|
106 octave_value retval; |
|
107 |
|
108 if (d == 0.0) |
|
109 { |
|
110 gripe_divide_by_zero (); |
|
111 |
|
112 retval = octave_value (v1.complex_matrix_value () / d); |
|
113 } |
|
114 else |
|
115 retval = octave_value (v1.sparse_complex_matrix_value () / d); |
|
116 |
|
117 return retval; |
|
118 } |
|
119 |
|
120 DEFBINOP_FN (el_pow, sparse_complex_matrix, scalar, elem_xpow) |
|
121 |
|
122 DEFBINOP (el_ldiv, sparse_complex_matrix, scalar) |
|
123 { |
|
124 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, const octave_scalar&); |
|
125 |
|
126 return octave_value |
|
127 (x_el_div (v2.double_value (), v1.sparse_complex_matrix_value ())); |
|
128 } |
|
129 |
|
130 DEFBINOP_FN (el_and, sparse_complex_matrix, scalar, mx_el_and) |
|
131 DEFBINOP_FN (el_or, sparse_complex_matrix, scalar, mx_el_or) |
|
132 |
|
133 DEFCATOP (scm_s, sparse_complex_matrix, scalar) |
|
134 { |
|
135 CAST_BINOP_ARGS (octave_sparse_complex_matrix&, const octave_scalar&); |
|
136 SparseComplexMatrix tmp (1, 1, v2.complex_value ()); |
|
137 return octave_value |
|
138 (v1.sparse_complex_matrix_value (). concat (tmp, ra_idx)); |
|
139 } |
|
140 |
|
141 DEFASSIGNOP (assign, sparse_complex_matrix, scalar) |
|
142 { |
|
143 CAST_BINOP_ARGS (octave_sparse_complex_matrix&, const octave_scalar&); |
|
144 |
|
145 SparseComplexMatrix tmp (1, 1, v2.complex_value ()); |
|
146 v1.assign (idx, tmp); |
|
147 return octave_value (); |
|
148 } |
|
149 |
|
150 void |
|
151 install_scm_s_ops (void) |
|
152 { |
|
153 INSTALL_BINOP (op_add, octave_sparse_complex_matrix, octave_scalar, add); |
|
154 INSTALL_BINOP (op_sub, octave_sparse_complex_matrix, octave_scalar, sub); |
|
155 INSTALL_BINOP (op_mul, octave_sparse_complex_matrix, octave_scalar, mul); |
|
156 INSTALL_BINOP (op_div, octave_sparse_complex_matrix, octave_scalar, div); |
|
157 INSTALL_BINOP (op_pow, octave_sparse_complex_matrix, octave_scalar, pow); |
|
158 INSTALL_BINOP (op_ldiv, octave_sparse_complex_matrix, octave_scalar, ldiv); |
|
159 INSTALL_BINOP (op_lt, octave_sparse_complex_matrix, octave_scalar, lt); |
|
160 INSTALL_BINOP (op_le, octave_sparse_complex_matrix, octave_scalar, le); |
|
161 INSTALL_BINOP (op_eq, octave_sparse_complex_matrix, octave_scalar, eq); |
|
162 INSTALL_BINOP (op_ge, octave_sparse_complex_matrix, octave_scalar, ge); |
|
163 INSTALL_BINOP (op_gt, octave_sparse_complex_matrix, octave_scalar, gt); |
|
164 INSTALL_BINOP (op_ne, octave_sparse_complex_matrix, octave_scalar, ne); |
|
165 INSTALL_BINOP (op_el_mul, octave_sparse_complex_matrix, octave_scalar, |
|
166 el_mul); |
|
167 INSTALL_BINOP (op_el_div, octave_sparse_complex_matrix, octave_scalar, |
|
168 el_div); |
|
169 INSTALL_BINOP (op_el_pow, octave_sparse_complex_matrix, octave_scalar, |
|
170 el_pow); |
|
171 INSTALL_BINOP (op_el_ldiv, octave_sparse_complex_matrix, octave_scalar, |
|
172 el_ldiv); |
|
173 INSTALL_BINOP (op_el_and, octave_sparse_complex_matrix, octave_scalar, |
|
174 el_and); |
|
175 INSTALL_BINOP (op_el_or, octave_sparse_complex_matrix, octave_scalar, |
|
176 el_or); |
|
177 |
|
178 INSTALL_CATOP (octave_sparse_complex_matrix, octave_scalar, scm_s); |
|
179 |
|
180 INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_complex_matrix, octave_scalar, |
|
181 assign); |
|
182 } |
|
183 |
|
184 /* |
|
185 ;;; Local Variables: *** |
|
186 ;;; mode: C++ *** |
|
187 ;;; End: *** |
|
188 */ |