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