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