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-re-mat.h"
35
#include "sparse-xpow.h"
36
#include "sparse-xdiv.h"
37
#include "ov-re-sparse.h"
39
// sparse matrix unary ops.
41
DEFUNOP_OP (not, sparse_matrix, !)
42
DEFUNOP_OP (uplus, sparse_matrix, /* no-op */)
43
DEFUNOP_OP (uminus, sparse_matrix, -)
45
DEFUNOP (transpose, sparse_matrix)
47
CAST_UNOP_ARG (const octave_sparse_matrix&);
48
return octave_value (v.sparse_matrix_value().transpose (),
49
v.matrix_type ().transpose ());
52
// sparse matrix by sparse matrix ops.
54
DEFBINOP_OP (add, sparse_matrix, sparse_matrix, +)
55
DEFBINOP_OP (sub, sparse_matrix, sparse_matrix, -)
56
DEFBINOP_OP (mul, sparse_matrix, sparse_matrix, *)
58
DEFBINOP (div, sparse_matrix, sparse_matrix)
60
CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_sparse_matrix&);
62
if (v2.rows() == 1 && v2.columns() == 1)
64
double d = v2.scalar_value ();
67
gripe_divide_by_zero ();
69
return octave_value (v1.sparse_matrix_value () / d);
73
MatrixType typ = v2.matrix_type ();
74
SparseMatrix ret = xdiv (v1.sparse_matrix_value (),
75
v2.sparse_matrix_value (), typ);
82
DEFBINOPX (pow, sparse_matrix, sparse_matrix)
84
error ("can't do A ^ B for A and B both matrices");
85
return octave_value ();
88
DEFBINOP (ldiv, sparse_matrix, sparse_matrix)
90
CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_sparse_matrix&);
92
if (v1.rows() == 1 && v1.columns() == 1)
94
double d = v1.double_value ();
97
gripe_divide_by_zero ();
99
return octave_value (v2.sparse_matrix_value () / d);
103
MatrixType typ = v1.matrix_type ();
105
SparseMatrix ret = xleftdiv (v1.sparse_matrix_value (),
106
v2.sparse_matrix_value (), typ);
108
v1.matrix_type (typ);
113
DEFBINOP_FN (lt, sparse_matrix, sparse_matrix, mx_el_lt)
114
DEFBINOP_FN (le, sparse_matrix, sparse_matrix, mx_el_le)
115
DEFBINOP_FN (eq, sparse_matrix, sparse_matrix, mx_el_eq)
116
DEFBINOP_FN (ge, sparse_matrix, sparse_matrix, mx_el_ge)
117
DEFBINOP_FN (gt, sparse_matrix, sparse_matrix, mx_el_gt)
118
DEFBINOP_FN (ne, sparse_matrix, sparse_matrix, mx_el_ne)
120
DEFBINOP_FN (el_mul, sparse_matrix, sparse_matrix, product)
121
DEFBINOP_FN (el_div, sparse_matrix, sparse_matrix, quotient)
123
DEFBINOP_FN (el_pow, sparse_matrix, sparse_matrix, elem_xpow)
125
DEFBINOP (el_ldiv, sparse_matrix, sparse_matrix)
127
CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_sparse_matrix&);
129
(quotient (v2.sparse_matrix_value (), v1.sparse_matrix_value ()));
132
DEFBINOP_FN (el_and, sparse_matrix, sparse_matrix, mx_el_and)
133
DEFBINOP_FN (el_or, sparse_matrix, sparse_matrix, mx_el_or)
135
DEFCATOP_FN (sm_sm, sparse_matrix, sparse_matrix, concat)
137
DEFASSIGNOP_FN (assign, sparse_matrix, sparse_matrix, assign)
140
install_sm_sm_ops (void)
142
INSTALL_UNOP (op_not, octave_sparse_matrix, not);
143
INSTALL_UNOP (op_uplus, octave_sparse_matrix, uplus);
144
INSTALL_UNOP (op_uminus, octave_sparse_matrix, uminus);
145
INSTALL_UNOP (op_transpose, octave_sparse_matrix, transpose);
146
INSTALL_UNOP (op_hermitian, octave_sparse_matrix, transpose);
148
INSTALL_BINOP (op_add, octave_sparse_matrix, octave_sparse_matrix, add);
149
INSTALL_BINOP (op_sub, octave_sparse_matrix, octave_sparse_matrix, sub);
150
INSTALL_BINOP (op_mul, octave_sparse_matrix, octave_sparse_matrix, mul);
151
INSTALL_BINOP (op_div, octave_sparse_matrix, octave_sparse_matrix, div);
152
INSTALL_BINOP (op_pow, octave_sparse_matrix, octave_sparse_matrix, pow);
153
INSTALL_BINOP (op_ldiv, octave_sparse_matrix, octave_sparse_matrix, ldiv);
154
INSTALL_BINOP (op_lt, octave_sparse_matrix, octave_sparse_matrix, lt);
155
INSTALL_BINOP (op_le, octave_sparse_matrix, octave_sparse_matrix, le);
156
INSTALL_BINOP (op_eq, octave_sparse_matrix, octave_sparse_matrix, eq);
157
INSTALL_BINOP (op_ge, octave_sparse_matrix, octave_sparse_matrix, ge);
158
INSTALL_BINOP (op_gt, octave_sparse_matrix, octave_sparse_matrix, gt);
159
INSTALL_BINOP (op_ne, octave_sparse_matrix, octave_sparse_matrix, ne);
160
INSTALL_BINOP (op_el_mul, octave_sparse_matrix, octave_sparse_matrix,
162
INSTALL_BINOP (op_el_div, octave_sparse_matrix, octave_sparse_matrix,
164
INSTALL_BINOP (op_el_pow, octave_sparse_matrix, octave_sparse_matrix,
166
INSTALL_BINOP (op_el_ldiv, octave_sparse_matrix, octave_sparse_matrix,
168
INSTALL_BINOP (op_el_and, octave_sparse_matrix, octave_sparse_matrix,
170
INSTALL_BINOP (op_el_or, octave_sparse_matrix, octave_sparse_matrix,
173
INSTALL_CATOP (octave_sparse_matrix, octave_sparse_matrix, sm_sm);
175
INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_matrix, octave_sparse_matrix,
180
;;; Local Variables: ***