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