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