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