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