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