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