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