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