Mercurial > octave
annotate libinterp/operators/op-s-scm.cc @ 25054:6652d3823428 stable
maint: Update copyright dates in all source files.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 30 Mar 2018 09:19:05 -0400 |
parents | 46440078d73b |
children | 078b795c5219 |
rev | line source |
---|---|
5164 | 1 /* |
2 | |
25054
6652d3823428
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
24540
diff
changeset
|
3 Copyright (C) 2004-2018 David Bateman |
11523 | 4 Copyright (C) 1998-2004 Andy Adler |
7016 | 5 |
6 This file is part of Octave. | |
5164 | 7 |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
8 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
9 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
10 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
11 (at your option) any later version. |
5164 | 12 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
16 GNU General Public License for more details. |
5164 | 17 |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
20 <https://www.gnu.org/licenses/>. |
5164 | 21 |
22 */ | |
23 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21647
diff
changeset
|
24 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
25 # include "config.h" |
5164 | 26 #endif |
27 | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
28 #include "errwarn.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
29 #include "ovl.h" |
5164 | 30 #include "ov.h" |
31 #include "ov-typeinfo.h" | |
32 #include "ov-cx-mat.h" | |
33 #include "ov-scalar.h" | |
34 #include "ops.h" | |
35 #include "xpow.h" | |
36 | |
37 #include "sparse-xpow.h" | |
38 #include "sparse-xdiv.h" | |
39 #include "smx-s-scm.h" | |
40 #include "smx-scm-s.h" | |
41 #include "ov-re-sparse.h" | |
42 #include "ov-cx-sparse.h" | |
43 | |
44 // scalar by sparse complex matrix ops. | |
45 | |
46 DEFBINOP_OP (add, scalar, sparse_complex_matrix, +) | |
47 DEFBINOP_OP (sub, scalar, sparse_complex_matrix, -) | |
48 DEFBINOP_OP (mul, scalar, sparse_complex_matrix, *) | |
49 | |
50 DEFBINOP (div, scalar, sparse_complex_matrix) | |
51 { | |
21647
66cae7a6dc47
eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
52 const octave_scalar& v1 = dynamic_cast<const octave_scalar&> (a1); |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
53 const octave_sparse_complex_matrix& v2 |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
54 = dynamic_cast<const octave_sparse_complex_matrix&> (a2); |
5164 | 55 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
56 if (v2.rows () == 1 && v2.columns () == 1) |
6221 | 57 { |
58 Complex d = v2.complex_value (); | |
59 | |
60 if (d == 0.0) | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
61 warn_divide_by_zero (); |
5164 | 62 |
8835
1685c61542f8
Don't perform narrowing to full matrices in mixed spare scalar operators
David Bateman <dbateman@free.fr>
parents:
7289
diff
changeset
|
63 return octave_value (SparseComplexMatrix (1, 1, v1.scalar_value () / d)); |
6221 | 64 } |
65 else | |
66 { | |
67 MatrixType typ = v2.matrix_type (); | |
68 Matrix m1 = Matrix (1, 1, v1.scalar_value ()); | |
69 SparseComplexMatrix m2 = v2.sparse_complex_matrix_value (); | |
70 ComplexMatrix ret = xdiv (m1, m2, typ); | |
71 v2.matrix_type (typ); | |
72 return ret; | |
73 } | |
5164 | 74 } |
75 | |
76 DEFBINOP (pow, scalar, sparse_complex_matrix) | |
77 { | |
21647
66cae7a6dc47
eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
78 const octave_scalar& v1 = dynamic_cast<const octave_scalar&> (a1); |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
79 const octave_sparse_complex_matrix& v2 |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
80 = dynamic_cast<const octave_sparse_complex_matrix&> (a2); |
5164 | 81 return xpow (v1.scalar_value (), v2.complex_matrix_value ()); |
82 } | |
83 | |
84 DEFBINOP (ldiv, scalar, sparse_complex_matrix) | |
85 { | |
21647
66cae7a6dc47
eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
86 const octave_scalar& v1 = dynamic_cast<const octave_scalar&> (a1); |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
87 const octave_sparse_complex_matrix& v2 |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
88 = dynamic_cast<const octave_sparse_complex_matrix&> (a2); |
5164 | 89 |
90 double d = v1.double_value (); | |
91 octave_value retval; | |
92 | |
93 if (d == 0.0) | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
94 warn_divide_by_zero (); |
5164 | 95 |
8835
1685c61542f8
Don't perform narrowing to full matrices in mixed spare scalar operators
David Bateman <dbateman@free.fr>
parents:
7289
diff
changeset
|
96 retval = octave_value (v2.sparse_complex_matrix_value () / d); |
5164 | 97 |
98 return retval; | |
99 } | |
100 | |
101 DEFBINOP_FN (lt, scalar, sparse_complex_matrix, mx_el_lt) | |
102 DEFBINOP_FN (le, scalar, sparse_complex_matrix, mx_el_le) | |
103 DEFBINOP_FN (eq, scalar, sparse_complex_matrix, mx_el_eq) | |
104 DEFBINOP_FN (ge, scalar, sparse_complex_matrix, mx_el_ge) | |
105 DEFBINOP_FN (gt, scalar, sparse_complex_matrix, mx_el_gt) | |
106 DEFBINOP_FN (ne, scalar, sparse_complex_matrix, mx_el_ne) | |
107 | |
108 DEFBINOP_OP (el_mul, scalar, sparse_complex_matrix, *) | |
109 DEFBINOP_FN (el_div, scalar, sparse_complex_matrix, x_el_div) | |
110 DEFBINOP_FN (el_pow, scalar, sparse_complex_matrix, elem_xpow) | |
111 | |
112 DEFBINOP (el_ldiv, scalar, sparse_complex_matrix) | |
113 { | |
21647
66cae7a6dc47
eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
114 const octave_scalar& v1 = dynamic_cast<const octave_scalar&> (a1); |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
115 const octave_sparse_complex_matrix& v2 |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
116 = dynamic_cast<const octave_sparse_complex_matrix&> (a2); |
5164 | 117 |
118 double d = v1.double_value (); | |
119 octave_value retval; | |
120 | |
121 if (d == 0.0) | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
122 warn_divide_by_zero (); |
5164 | 123 |
8835
1685c61542f8
Don't perform narrowing to full matrices in mixed spare scalar operators
David Bateman <dbateman@free.fr>
parents:
7289
diff
changeset
|
124 retval = octave_value (v2.sparse_complex_matrix_value () / d); |
5164 | 125 |
126 return retval; | |
127 } | |
128 | |
129 DEFBINOP_FN (el_and, scalar, sparse_complex_matrix, mx_el_and) | |
130 DEFBINOP_FN (el_or, scalar, sparse_complex_matrix, mx_el_or) | |
131 | |
132 DEFCATOP (s_scm, scalar, sparse_compelx_matrix) | |
133 { | |
21647
66cae7a6dc47
eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
134 octave_scalar& v1 = dynamic_cast<octave_scalar&> (a1); |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
135 const octave_sparse_complex_matrix& v2 |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
136 = dynamic_cast<const octave_sparse_complex_matrix&> (a2); |
5164 | 137 SparseMatrix tmp (1, 1, v1.scalar_value ()); |
138 return octave_value | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
139 (tmp.concat (v2.sparse_complex_matrix_value (), ra_idx)); |
5164 | 140 } |
141 | |
142 DEFCONV (sparse_complex_matrix_conv, scalar, sparse_complex_matrix) | |
143 { | |
21647
66cae7a6dc47
eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
144 const octave_scalar& v = dynamic_cast<const octave_scalar&> (a); |
5164 | 145 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
146 return new octave_sparse_complex_matrix |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
147 (SparseComplexMatrix (v.complex_matrix_value ())); |
5164 | 148 } |
149 | |
150 void | |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
151 install_s_scm_ops (octave::type_info& ti) |
5164 | 152 { |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
153 INSTALL_BINOP_TI (ti, op_add, octave_scalar, octave_sparse_complex_matrix, add); |
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
154 INSTALL_BINOP_TI (ti, op_sub, octave_scalar, octave_sparse_complex_matrix, sub); |
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
155 INSTALL_BINOP_TI (ti, op_mul, octave_scalar, octave_sparse_complex_matrix, mul); |
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
156 INSTALL_BINOP_TI (ti, op_div, octave_scalar, octave_sparse_complex_matrix, div); |
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
157 INSTALL_BINOP_TI (ti, op_pow, octave_scalar, octave_sparse_complex_matrix, pow); |
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
158 INSTALL_BINOP_TI (ti, op_ldiv, octave_scalar, octave_sparse_complex_matrix, ldiv); |
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
159 INSTALL_BINOP_TI (ti, op_lt, octave_scalar, octave_sparse_complex_matrix, lt); |
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
160 INSTALL_BINOP_TI (ti, op_le, octave_scalar, octave_sparse_complex_matrix, le); |
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
161 INSTALL_BINOP_TI (ti, op_eq, octave_scalar, octave_sparse_complex_matrix, eq); |
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
162 INSTALL_BINOP_TI (ti, op_ge, octave_scalar, octave_sparse_complex_matrix, ge); |
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
163 INSTALL_BINOP_TI (ti, op_gt, octave_scalar, octave_sparse_complex_matrix, gt); |
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
164 INSTALL_BINOP_TI (ti, op_ne, octave_scalar, octave_sparse_complex_matrix, ne); |
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
165 INSTALL_BINOP_TI (ti, op_el_mul, octave_scalar, octave_sparse_complex_matrix, |
9931
fb6b6fcafa62
untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
166 el_mul); |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
167 INSTALL_BINOP_TI (ti, op_el_div, octave_scalar, octave_sparse_complex_matrix, |
9931
fb6b6fcafa62
untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
168 el_div); |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
169 INSTALL_BINOP_TI (ti, op_el_pow, octave_scalar, octave_sparse_complex_matrix, |
9931
fb6b6fcafa62
untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
170 el_pow); |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
171 INSTALL_BINOP_TI (ti, op_el_ldiv, octave_scalar, octave_sparse_complex_matrix, |
9931
fb6b6fcafa62
untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
172 el_ldiv); |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
173 INSTALL_BINOP_TI (ti, op_el_and, octave_scalar, octave_sparse_complex_matrix, |
9931
fb6b6fcafa62
untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
174 el_and); |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
175 INSTALL_BINOP_TI (ti, op_el_or, octave_scalar, octave_sparse_complex_matrix, |
9931
fb6b6fcafa62
untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
176 el_or); |
5164 | 177 |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
178 INSTALL_CATOP_TI (ti, octave_scalar, octave_sparse_complex_matrix, s_scm); |
5164 | 179 |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
180 INSTALL_ASSIGNCONV_TI (ti, octave_scalar, octave_sparse_complex_matrix, |
9931
fb6b6fcafa62
untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
181 octave_complex_matrix); |
5164 | 182 |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
183 INSTALL_WIDENOP_TI (ti, octave_scalar, octave_sparse_complex_matrix, |
9931
fb6b6fcafa62
untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
184 sparse_complex_matrix_conv); |
5164 | 185 } |