comparison src/OPERATORS/op-m-sm.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-re-mat.h"
31 #include "ops.h"
32 #include "xdiv.h"
33
34 #include "sparse-xpow.h"
35 #include "sparse-xdiv.h"
36 #include "smx-sm-m.h"
37 #include "smx-m-sm.h"
38 #include "ov-re-sparse.h"
39
40 // matrix by sparse matrix ops.
41
42 DEFBINOP_OP (add, matrix, sparse_matrix, +)
43 DEFBINOP_OP (sub, matrix, sparse_matrix, -)
44
45 DEFBINOP (mul, matrix, sparse_matrix)
46 {
47 CAST_BINOP_ARGS (const octave_matrix&, const octave_sparse_matrix&);
48
49 Matrix tmp (v2.matrix_value ());
50
51 return octave_value ( v1.matrix_value() * tmp);
52 }
53
54 DEFBINOP (div, matrix, sparse_matrix)
55 {
56 CAST_BINOP_ARGS (const octave_matrix&, const octave_sparse_matrix&);
57
58 return xdiv (v1.matrix_value (), v2.sparse_matrix_value ());
59 }
60
61 DEFBINOPX (pow, matrix, sparse_matrix)
62 {
63 error ("can't do A ^ B for A and B both matrices");
64 return octave_value ();
65 }
66
67 DEFBINOP (ldiv, matrix, sparse_matrix)
68 {
69 CAST_BINOP_ARGS (const octave_matrix&, const octave_sparse_matrix&);
70
71 return xleftdiv (v1.matrix_value (), v2.matrix_value ());
72 }
73
74 DEFBINOP_FN (lt, matrix, sparse_matrix, mx_el_lt)
75 DEFBINOP_FN (le, matrix, sparse_matrix, mx_el_le)
76 DEFBINOP_FN (eq, matrix, sparse_matrix, mx_el_eq)
77 DEFBINOP_FN (ge, matrix, sparse_matrix, mx_el_ge)
78 DEFBINOP_FN (gt, matrix, sparse_matrix, mx_el_gt)
79 DEFBINOP_FN (ne, matrix, sparse_matrix, mx_el_ne)
80
81 DEFBINOP_FN (el_mul, matrix, sparse_matrix, product)
82 DEFBINOP_FN (el_div, matrix, sparse_matrix, quotient)
83
84 DEFBINOP (el_pow, matrix, sparse_matrix)
85 {
86 CAST_BINOP_ARGS (const octave_matrix&, const octave_sparse_matrix&);
87
88 return octave_value (elem_xpow (SparseMatrix (v1.matrix_value ()),
89 v2.sparse_matrix_value ()));
90 }
91
92 DEFBINOP (el_ldiv, matrix, sparse_matrix)
93 {
94 CAST_BINOP_ARGS (const octave_matrix&, const octave_sparse_matrix&);
95
96 return octave_value
97 (quotient (v2.sparse_matrix_value (), v1.matrix_value ()));
98 }
99
100 DEFBINOP_FN (el_and, matrix, sparse_matrix, mx_el_and)
101 DEFBINOP_FN (el_or, matrix, sparse_matrix, mx_el_or)
102
103 DEFCATOP (m_sm, matrix, sparse_matrix)
104 {
105 CAST_BINOP_ARGS (octave_matrix&, const octave_sparse_matrix&);
106 SparseMatrix tmp (v1.matrix_value ());
107 return octave_value (tmp. concat (v2.sparse_matrix_value (), ra_idx));
108 }
109
110 DEFCONV (sparse_matrix_conv, matrix, sparse_matrix)
111 {
112 CAST_CONV_ARG (const octave_matrix&);
113 return new octave_sparse_matrix (SparseMatrix (v.matrix_value ()));
114 }
115
116 void
117 install_m_sm_ops (void)
118 {
119 INSTALL_BINOP (op_add, octave_matrix, octave_sparse_matrix, add);
120 INSTALL_BINOP (op_sub, octave_matrix, octave_sparse_matrix, sub);
121 INSTALL_BINOP (op_mul, octave_matrix, octave_sparse_matrix, mul);
122 INSTALL_BINOP (op_div, octave_matrix, octave_sparse_matrix, div);
123 INSTALL_BINOP (op_pow, octave_matrix, octave_sparse_matrix, pow);
124 INSTALL_BINOP (op_ldiv, octave_matrix, octave_sparse_matrix, ldiv);
125 INSTALL_BINOP (op_lt, octave_matrix, octave_sparse_matrix, lt);
126 INSTALL_BINOP (op_le, octave_matrix, octave_sparse_matrix, le);
127 INSTALL_BINOP (op_eq, octave_matrix, octave_sparse_matrix, eq);
128 INSTALL_BINOP (op_ge, octave_matrix, octave_sparse_matrix, ge);
129 INSTALL_BINOP (op_gt, octave_matrix, octave_sparse_matrix, gt);
130 INSTALL_BINOP (op_ne, octave_matrix, octave_sparse_matrix, ne);
131 INSTALL_BINOP (op_el_mul, octave_matrix, octave_sparse_matrix, el_mul);
132 INSTALL_BINOP (op_el_div, octave_matrix, octave_sparse_matrix, el_div);
133 INSTALL_BINOP (op_el_pow, octave_matrix, octave_sparse_matrix, el_pow);
134 INSTALL_BINOP (op_el_ldiv, octave_matrix, octave_sparse_matrix, el_ldiv);
135 INSTALL_BINOP (op_el_and, octave_matrix, octave_sparse_matrix, el_and);
136 INSTALL_BINOP (op_el_or, octave_matrix, octave_sparse_matrix, el_or);
137
138 INSTALL_CATOP (octave_matrix, octave_sparse_matrix, m_sm);
139
140 INSTALL_ASSIGNCONV (octave_matrix, octave_sparse_matrix,
141 octave_sparse_matrix);
142
143 INSTALL_WIDENOP (octave_matrix, octave_sparse_matrix,
144 sparse_matrix_conv);
145 }
146
147 /*
148 ;;; Local Variables: ***
149 ;;; mode: C++ ***
150 ;;; End: ***
151 */