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 { |
|
75 CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_complex&); |
|
76 |
|
77 SparseMatrix m1 = v1.sparse_matrix_value (); |
|
78 ComplexMatrix m2 = ComplexMatrix (1, 1, v2.complex_value ()); |
|
79 |
|
80 return xleftdiv (m1, m2); |
|
81 } |
|
82 |
|
83 DEFBINOP_FN (lt, sparse_matrix, complex, mx_el_lt) |
|
84 DEFBINOP_FN (le, sparse_matrix, complex, mx_el_le) |
|
85 DEFBINOP_FN (eq, sparse_matrix, complex, mx_el_eq) |
|
86 DEFBINOP_FN (ge, sparse_matrix, complex, mx_el_ge) |
|
87 DEFBINOP_FN (gt, sparse_matrix, complex, mx_el_gt) |
|
88 DEFBINOP_FN (ne, sparse_matrix, complex, mx_el_ne) |
|
89 |
|
90 DEFBINOP_OP (el_mul, sparse_matrix, complex, *) |
|
91 |
|
92 DEFBINOP (el_div, sparse_matrix, complex) |
|
93 { |
|
94 CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_complex&); |
|
95 |
|
96 Complex d = v2.complex_value (); |
|
97 octave_value retval; |
|
98 |
|
99 if (d == 0.0) |
|
100 { |
|
101 gripe_divide_by_zero (); |
|
102 |
|
103 retval = octave_value (v1.matrix_value () / d); |
|
104 } |
|
105 else |
|
106 retval = octave_value (v1.sparse_matrix_value () / d); |
|
107 |
|
108 return retval; |
|
109 } |
|
110 |
|
111 DEFBINOP_FN (el_pow, sparse_matrix, complex, elem_xpow) |
|
112 |
|
113 DEFBINOP (el_ldiv, sparse_matrix, complex) |
|
114 { |
|
115 CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_complex&); |
|
116 |
|
117 return octave_value (x_el_div (v2.complex_value (), |
|
118 v1.sparse_matrix_value ())); |
|
119 } |
|
120 |
|
121 DEFBINOP_FN (el_and, sparse_matrix, complex, mx_el_and) |
|
122 DEFBINOP_FN (el_or, sparse_matrix, complex, mx_el_or) |
|
123 |
|
124 DEFCATOP (sm_cs, sparse_matrix, complex) |
|
125 { |
|
126 CAST_BINOP_ARGS (octave_sparse_matrix&, const octave_complex&); |
|
127 SparseComplexMatrix tmp (1, 1, v2.complex_value ()); |
|
128 return octave_value (v1.sparse_matrix_value (). concat (tmp, ra_idx)); |
|
129 } |
|
130 |
|
131 void |
|
132 install_sm_cs_ops (void) |
|
133 { |
|
134 INSTALL_BINOP (op_add, octave_sparse_matrix, octave_complex, add); |
|
135 INSTALL_BINOP (op_sub, octave_sparse_matrix, octave_complex, sub); |
|
136 INSTALL_BINOP (op_mul, octave_sparse_matrix, octave_complex, mul); |
|
137 INSTALL_BINOP (op_div, octave_sparse_matrix, octave_complex, div); |
|
138 INSTALL_BINOP (op_pow, octave_sparse_matrix, octave_complex, pow); |
|
139 INSTALL_BINOP (op_ldiv, octave_sparse_matrix, octave_complex, ldiv); |
|
140 |
|
141 INSTALL_BINOP (op_lt, octave_sparse_matrix, octave_complex, lt); |
|
142 INSTALL_BINOP (op_le, octave_sparse_matrix, octave_complex, le); |
|
143 INSTALL_BINOP (op_eq, octave_sparse_matrix, octave_complex, eq); |
|
144 INSTALL_BINOP (op_ge, octave_sparse_matrix, octave_complex, ge); |
|
145 INSTALL_BINOP (op_gt, octave_sparse_matrix, octave_complex, gt); |
|
146 INSTALL_BINOP (op_ne, octave_sparse_matrix, octave_complex, ne); |
|
147 INSTALL_BINOP (op_el_mul, octave_sparse_matrix, octave_complex, el_mul); |
|
148 INSTALL_BINOP (op_el_div, octave_sparse_matrix, octave_complex, el_div); |
|
149 INSTALL_BINOP (op_el_pow, octave_sparse_matrix, octave_complex, el_pow); |
|
150 INSTALL_BINOP (op_el_ldiv, octave_sparse_matrix, octave_complex, el_ldiv); |
|
151 INSTALL_BINOP (op_el_and, octave_sparse_matrix, octave_complex, el_and); |
|
152 INSTALL_BINOP (op_el_or, octave_sparse_matrix, octave_complex, el_or); |
|
153 |
|
154 INSTALL_CATOP (octave_sparse_matrix, octave_complex, sm_cs); |
|
155 |
|
156 INSTALL_ASSIGNCONV (octave_sparse_matrix, octave_complex, |
|
157 octave_sparse_complex_matrix); |
|
158 } |
|
159 |
|
160 /* |
|
161 ;;; Local Variables: *** |
|
162 ;;; mode: C++ *** |
|
163 ;;; End: *** |
|
164 */ |