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