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