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 |
|
17 along with this program; see the file COPYING. If not, write to the Free |
|
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
19 |
|
20 */ |
|
21 |
|
22 #ifdef HAVE_CONFIG_H |
|
23 #include <config.h> |
|
24 #endif |
|
25 |
|
26 #include "gripes.h" |
|
27 #include "oct-obj.h" |
|
28 #include "ov.h" |
|
29 #include "ov-typeinfo.h" |
|
30 #include "ov-scalar.h" |
|
31 #include "ops.h" |
|
32 #include "xpow.h" |
|
33 |
|
34 #include "sparse-xpow.h" |
|
35 #include "sparse-xdiv.h" |
|
36 #include "ov-re-sparse.h" |
|
37 |
|
38 // sparse matrix by scalar ops. |
|
39 |
|
40 DEFBINOP_OP (add, sparse_matrix, scalar, +) |
|
41 DEFBINOP_OP (sub, sparse_matrix, scalar, -) |
|
42 DEFBINOP_OP (mul, sparse_matrix, scalar, *) |
|
43 |
|
44 DEFBINOP (div, sparse_matrix, scalar) |
|
45 { |
|
46 CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_scalar&); |
|
47 |
|
48 double d = v2.double_value (); |
|
49 octave_value retval; |
|
50 |
|
51 if (d == 0.0) |
|
52 { |
|
53 gripe_divide_by_zero (); |
|
54 |
|
55 retval = octave_value (v1.matrix_value () / d); |
|
56 } |
|
57 else |
|
58 retval = octave_value (v1.sparse_matrix_value () / d); |
|
59 |
|
60 return retval; |
|
61 } |
|
62 |
|
63 DEFBINOP (pow, sparse_matrix, scalar) |
|
64 { |
|
65 CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_scalar&); |
|
66 |
|
67 double tmp = v2.scalar_value (); |
|
68 if (static_cast<int> (tmp) == tmp) |
|
69 return xpow (v1.sparse_matrix_value (), tmp); |
|
70 else |
|
71 return xpow (v1.matrix_value (), tmp); |
|
72 } |
|
73 |
|
74 DEFBINOP (ldiv, sparse_matrix, scalar) |
|
75 { |
|
76 CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_scalar&); |
|
77 |
|
78 SparseMatrix m1 = v1.sparse_matrix_value (); |
|
79 Matrix m2 = Matrix (1, 1, v2.scalar_value ()); |
|
80 |
|
81 return xleftdiv (m1, m2); |
|
82 } |
|
83 |
|
84 DEFBINOP_FN (lt, sparse_matrix, scalar, mx_el_lt) |
|
85 DEFBINOP_FN (le, sparse_matrix, scalar, mx_el_le) |
|
86 DEFBINOP_FN (eq, sparse_matrix, scalar, mx_el_eq) |
|
87 DEFBINOP_FN (ge, sparse_matrix, scalar, mx_el_ge) |
|
88 DEFBINOP_FN (gt, sparse_matrix, scalar, mx_el_gt) |
|
89 DEFBINOP_FN (ne, sparse_matrix, scalar, mx_el_ne) |
|
90 |
|
91 DEFBINOP_OP (el_mul, sparse_matrix, scalar, *) |
|
92 |
|
93 DEFBINOP (el_div, sparse_matrix, scalar) |
|
94 { |
|
95 CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_scalar&); |
|
96 |
|
97 double d = v2.double_value (); |
|
98 octave_value retval; |
|
99 |
|
100 if (d == 0.0) |
|
101 { |
|
102 gripe_divide_by_zero (); |
|
103 |
|
104 retval = octave_value (v1.matrix_value () / d); |
|
105 } |
|
106 else |
|
107 retval = octave_value (v1.sparse_matrix_value () / d); |
|
108 |
|
109 return retval; |
|
110 } |
|
111 |
|
112 DEFBINOP_FN (el_pow, sparse_matrix, scalar, elem_xpow) |
|
113 |
|
114 DEFBINOP (el_ldiv, sparse_matrix, scalar) |
|
115 { |
|
116 CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_scalar&); |
|
117 |
|
118 return octave_value |
|
119 (x_el_div (v2.complex_value (), v1.sparse_matrix_value ())); |
|
120 } |
|
121 |
|
122 DEFBINOP_FN (el_and, sparse_matrix, scalar, mx_el_and) |
|
123 DEFBINOP_FN (el_or, sparse_matrix, scalar, mx_el_or) |
|
124 |
|
125 DEFCATOP (sm_s, sparse_matrix, scalar) |
|
126 { |
|
127 CAST_BINOP_ARGS (octave_sparse_matrix&, const octave_scalar&); |
|
128 SparseMatrix tmp (1, 1, v2.scalar_value ()); |
|
129 return octave_value (v1.sparse_matrix_value (). concat (tmp, ra_idx)); |
|
130 } |
|
131 |
|
132 DEFASSIGNOP (assign, sparse_matrix, scalar) |
|
133 { |
|
134 CAST_BINOP_ARGS (octave_sparse_matrix&, const octave_scalar&); |
|
135 |
|
136 SparseMatrix tmp (1, 1, v2.scalar_value ()); |
|
137 v1.assign (idx, tmp); |
|
138 return octave_value (); |
|
139 } |
|
140 |
|
141 void |
|
142 install_sm_s_ops (void) |
|
143 { |
|
144 INSTALL_BINOP (op_add, octave_sparse_matrix, octave_scalar, add); |
|
145 INSTALL_BINOP (op_sub, octave_sparse_matrix, octave_scalar, sub); |
|
146 INSTALL_BINOP (op_mul, octave_sparse_matrix, octave_scalar, mul); |
|
147 INSTALL_BINOP (op_div, octave_sparse_matrix, octave_scalar, div); |
|
148 INSTALL_BINOP (op_pow, octave_sparse_matrix, octave_scalar, pow); |
|
149 INSTALL_BINOP (op_ldiv, octave_sparse_matrix, octave_scalar, ldiv); |
|
150 |
|
151 INSTALL_BINOP (op_lt, octave_sparse_matrix, octave_scalar, lt); |
|
152 INSTALL_BINOP (op_le, octave_sparse_matrix, octave_scalar, le); |
|
153 INSTALL_BINOP (op_eq, octave_sparse_matrix, octave_scalar, eq); |
|
154 INSTALL_BINOP (op_ge, octave_sparse_matrix, octave_scalar, ge); |
|
155 INSTALL_BINOP (op_gt, octave_sparse_matrix, octave_scalar, gt); |
|
156 INSTALL_BINOP (op_ne, octave_sparse_matrix, octave_scalar, ne); |
|
157 INSTALL_BINOP (op_el_mul, octave_sparse_matrix, octave_scalar, el_mul); |
|
158 INSTALL_BINOP (op_el_div, octave_sparse_matrix, octave_scalar, el_div); |
|
159 INSTALL_BINOP (op_el_pow, octave_sparse_matrix, octave_scalar, el_pow); |
|
160 INSTALL_BINOP (op_el_ldiv, octave_sparse_matrix, octave_scalar, el_ldiv); |
|
161 INSTALL_BINOP (op_el_and, octave_sparse_matrix, octave_scalar, el_and); |
|
162 INSTALL_BINOP (op_el_or, octave_sparse_matrix, octave_scalar, el_or); |
|
163 |
|
164 INSTALL_CATOP (octave_sparse_matrix, octave_scalar, sm_s); |
|
165 |
|
166 INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_matrix, octave_scalar, assign); |
|
167 } |
|
168 |
|
169 /* |
|
170 ;;; Local Variables: *** |
|
171 ;;; mode: C++ *** |
|
172 ;;; End: *** |
|
173 */ |