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