3
Copyright (C) 2004, 2005, 2006, 2007 David Bateman
4
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Andy Adler
6
This file is part of Octave.
8
Octave is free software; you can redistribute it and/or modify it
9
under the terms of the GNU General Public License as published by the
10
Free Software Foundation; either version 3 of the License, or (at your
11
option) any later version.
13
Octave is distributed in the hope that it will be useful, but WITHOUT
14
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18
You should have received a copy of the GNU General Public License
19
along with Octave; see the file COPYING. If not, see
20
<http://www.gnu.org/licenses/>.
31
#include "ov-typeinfo.h"
32
#include "ov-cx-mat.h"
33
#include "ov-scalar.h"
37
#include "sparse-xpow.h"
38
#include "sparse-xdiv.h"
39
#include "smx-scm-s.h"
40
#include "smx-s-scm.h"
41
#include "ov-re-sparse.h"
42
#include "ov-cx-sparse.h"
44
// sparse complex matrix by scalar ops.
46
DEFBINOP_OP (add, sparse_complex_matrix, scalar, +)
47
DEFBINOP_OP (sub, sparse_complex_matrix, scalar, -)
48
DEFBINOP_OP (mul, sparse_complex_matrix, scalar, *)
50
DEFBINOP (div, sparse_complex_matrix, scalar)
52
CAST_BINOP_ARGS (const octave_sparse_complex_matrix&,
53
const octave_scalar&);
55
double d = v2.double_value ();
60
gripe_divide_by_zero ();
62
retval = octave_value (v1.complex_matrix_value () / d);
65
retval = octave_value (v1.sparse_complex_matrix_value () / d);
70
DEFBINOP (pow, sparse_complex_matrix, scalar)
72
CAST_BINOP_ARGS (const octave_sparse_complex_matrix&,
73
const octave_scalar&);
75
double tmp = v2.scalar_value ();
76
if (static_cast<int> (tmp) == tmp)
77
return xpow (v1.sparse_complex_matrix_value (), tmp);
79
return xpow (v1.complex_matrix_value (), tmp);
82
DEFBINOP (ldiv, sparse_complex_matrix, scalar)
84
CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, const octave_scalar&);
86
if (v1.rows() == 1 && v1.columns() == 1)
88
Complex d = v1.complex_value ();
91
gripe_divide_by_zero ();
93
return octave_value (v2.scalar_value () / d);
97
MatrixType typ = v1.matrix_type ();
98
SparseComplexMatrix m1 = v1.sparse_complex_matrix_value ();
99
Matrix m2 = Matrix (1, 1, v2.scalar_value ());
100
ComplexMatrix ret = xleftdiv (m1, m2, typ);
101
v1.matrix_type (typ);
106
DEFBINOP_FN (lt, sparse_complex_matrix, scalar, mx_el_lt)
107
DEFBINOP_FN (le, sparse_complex_matrix, scalar, mx_el_le)
108
DEFBINOP_FN (eq, sparse_complex_matrix, scalar, mx_el_eq)
109
DEFBINOP_FN (ge, sparse_complex_matrix, scalar, mx_el_ge)
110
DEFBINOP_FN (gt, sparse_complex_matrix, scalar, mx_el_gt)
111
DEFBINOP_FN (ne, sparse_complex_matrix, scalar, mx_el_ne)
113
DEFBINOP_OP (el_mul, sparse_complex_matrix, scalar, *)
115
DEFBINOP (el_div, sparse_complex_matrix, scalar)
117
CAST_BINOP_ARGS (const octave_sparse_complex_matrix&,
118
const octave_scalar&);
120
double d = v2.double_value ();
125
gripe_divide_by_zero ();
127
retval = octave_value (v1.complex_matrix_value () / d);
130
retval = octave_value (v1.sparse_complex_matrix_value () / d);
135
DEFBINOP_FN (el_pow, sparse_complex_matrix, scalar, elem_xpow)
137
DEFBINOP (el_ldiv, sparse_complex_matrix, scalar)
139
CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, const octave_scalar&);
142
(x_el_div (v2.double_value (), v1.sparse_complex_matrix_value ()));
145
DEFBINOP_FN (el_and, sparse_complex_matrix, scalar, mx_el_and)
146
DEFBINOP_FN (el_or, sparse_complex_matrix, scalar, mx_el_or)
148
DEFCATOP (scm_s, sparse_complex_matrix, scalar)
150
CAST_BINOP_ARGS (octave_sparse_complex_matrix&, const octave_scalar&);
151
SparseComplexMatrix tmp (1, 1, v2.complex_value ());
153
(v1.sparse_complex_matrix_value (). concat (tmp, ra_idx));
156
DEFASSIGNOP (assign, sparse_complex_matrix, scalar)
158
CAST_BINOP_ARGS (octave_sparse_complex_matrix&, const octave_scalar&);
160
SparseComplexMatrix tmp (1, 1, v2.complex_value ());
161
v1.assign (idx, tmp);
162
return octave_value ();
166
install_scm_s_ops (void)
168
INSTALL_BINOP (op_add, octave_sparse_complex_matrix, octave_scalar, add);
169
INSTALL_BINOP (op_sub, octave_sparse_complex_matrix, octave_scalar, sub);
170
INSTALL_BINOP (op_mul, octave_sparse_complex_matrix, octave_scalar, mul);
171
INSTALL_BINOP (op_div, octave_sparse_complex_matrix, octave_scalar, div);
172
INSTALL_BINOP (op_pow, octave_sparse_complex_matrix, octave_scalar, pow);
173
INSTALL_BINOP (op_ldiv, octave_sparse_complex_matrix, octave_scalar, ldiv);
174
INSTALL_BINOP (op_lt, octave_sparse_complex_matrix, octave_scalar, lt);
175
INSTALL_BINOP (op_le, octave_sparse_complex_matrix, octave_scalar, le);
176
INSTALL_BINOP (op_eq, octave_sparse_complex_matrix, octave_scalar, eq);
177
INSTALL_BINOP (op_ge, octave_sparse_complex_matrix, octave_scalar, ge);
178
INSTALL_BINOP (op_gt, octave_sparse_complex_matrix, octave_scalar, gt);
179
INSTALL_BINOP (op_ne, octave_sparse_complex_matrix, octave_scalar, ne);
180
INSTALL_BINOP (op_el_mul, octave_sparse_complex_matrix, octave_scalar,
182
INSTALL_BINOP (op_el_div, octave_sparse_complex_matrix, octave_scalar,
184
INSTALL_BINOP (op_el_pow, octave_sparse_complex_matrix, octave_scalar,
186
INSTALL_BINOP (op_el_ldiv, octave_sparse_complex_matrix, octave_scalar,
188
INSTALL_BINOP (op_el_and, octave_sparse_complex_matrix, octave_scalar,
190
INSTALL_BINOP (op_el_or, octave_sparse_complex_matrix, octave_scalar,
193
INSTALL_CATOP (octave_sparse_complex_matrix, octave_scalar, scm_s);
195
INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_complex_matrix, octave_scalar,
200
;;; Local Variables: ***