~ubuntu-branches/debian/sid/octave3.0/sid

« back to all changes in this revision

Viewing changes to src/OPERATORS/op-sm-sm.cc

  • Committer: Bazaar Package Importer
  • Author(s): Rafael Laboissiere
  • Date: 2007-12-23 16:04:15 UTC
  • Revision ID: james.westby@ubuntu.com-20071223160415-n4gk468dihy22e9v
Tags: upstream-3.0.0
ImportĀ upstreamĀ versionĀ 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
3
Copyright (C) 2004, 2005, 2006, 2007 David Bateman
 
4
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Andy Adler
 
5
 
 
6
This file is part of Octave.
 
7
 
 
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.
 
12
 
 
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
 
16
for more details.
 
17
 
 
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/>.
 
21
 
 
22
*/
 
23
 
 
24
#ifdef HAVE_CONFIG_H
 
25
#include <config.h>
 
26
#endif
 
27
 
 
28
#include "gripes.h"
 
29
#include "oct-obj.h"
 
30
#include "ov.h"
 
31
#include "ov-typeinfo.h"
 
32
#include "ov-re-mat.h"
 
33
#include "ops.h"
 
34
 
 
35
#include "sparse-xpow.h"
 
36
#include "sparse-xdiv.h"
 
37
#include "ov-re-sparse.h"
 
38
 
 
39
// sparse matrix unary ops.
 
40
 
 
41
DEFUNOP_OP (not, sparse_matrix, !)
 
42
DEFUNOP_OP (uplus, sparse_matrix, /* no-op */)
 
43
DEFUNOP_OP (uminus, sparse_matrix, -)
 
44
 
 
45
DEFUNOP (transpose, sparse_matrix)
 
46
{
 
47
  CAST_UNOP_ARG (const octave_sparse_matrix&);
 
48
  return octave_value (v.sparse_matrix_value().transpose (),
 
49
                       v.matrix_type ().transpose ());
 
50
}
 
51
 
 
52
// sparse matrix by sparse matrix ops.
 
53
 
 
54
DEFBINOP_OP (add, sparse_matrix, sparse_matrix, +)
 
55
DEFBINOP_OP (sub, sparse_matrix, sparse_matrix, -)
 
56
DEFBINOP_OP (mul, sparse_matrix, sparse_matrix, *)
 
57
 
 
58
DEFBINOP (div, sparse_matrix, sparse_matrix)
 
59
{
 
60
  CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_sparse_matrix&);
 
61
 
 
62
  if (v2.rows() == 1 && v2.columns() == 1)
 
63
    {
 
64
      double d = v2.scalar_value ();
 
65
 
 
66
      if (d == 0.0)
 
67
        gripe_divide_by_zero ();
 
68
 
 
69
      return octave_value (v1.sparse_matrix_value () / d);
 
70
    }
 
71
  else
 
72
    {
 
73
      MatrixType typ = v2.matrix_type ();
 
74
      SparseMatrix ret = xdiv (v1.sparse_matrix_value (), 
 
75
                               v2.sparse_matrix_value (), typ);
 
76
  
 
77
      v2.matrix_type (typ);
 
78
      return ret;
 
79
    }
 
80
}
 
81
 
 
82
DEFBINOPX (pow, sparse_matrix, sparse_matrix)
 
83
{
 
84
  error ("can't do A ^ B for A and B both matrices");
 
85
  return octave_value ();
 
86
}
 
87
 
 
88
DEFBINOP (ldiv, sparse_matrix, sparse_matrix)
 
89
{
 
90
  CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_sparse_matrix&);
 
91
 
 
92
  if (v1.rows() == 1 && v1.columns() == 1)
 
93
    {
 
94
      double d = v1.double_value ();
 
95
 
 
96
      if (d == 0.0)
 
97
        gripe_divide_by_zero ();
 
98
 
 
99
      return octave_value (v2.sparse_matrix_value () / d);
 
100
    }
 
101
  else
 
102
    {
 
103
      MatrixType typ = v1.matrix_type ();
 
104
 
 
105
      SparseMatrix ret = xleftdiv (v1.sparse_matrix_value (), 
 
106
                                   v2.sparse_matrix_value (), typ);
 
107
 
 
108
      v1.matrix_type (typ);
 
109
      return ret;
 
110
    }
 
111
}
 
112
 
 
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)
 
119
 
 
120
DEFBINOP_FN (el_mul, sparse_matrix, sparse_matrix, product)
 
121
DEFBINOP_FN (el_div, sparse_matrix, sparse_matrix, quotient)
 
122
 
 
123
DEFBINOP_FN (el_pow, sparse_matrix, sparse_matrix, elem_xpow)
 
124
 
 
125
DEFBINOP (el_ldiv, sparse_matrix, sparse_matrix)
 
126
{
 
127
  CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_sparse_matrix&);
 
128
  return octave_value
 
129
    (quotient (v2.sparse_matrix_value (), v1.sparse_matrix_value ()));
 
130
}
 
131
 
 
132
DEFBINOP_FN (el_and, sparse_matrix, sparse_matrix, mx_el_and)
 
133
DEFBINOP_FN (el_or,  sparse_matrix, sparse_matrix, mx_el_or)
 
134
 
 
135
DEFCATOP_FN (sm_sm, sparse_matrix, sparse_matrix, concat)
 
136
 
 
137
DEFASSIGNOP_FN (assign, sparse_matrix, sparse_matrix, assign)
 
138
 
 
139
void
 
140
install_sm_sm_ops (void)
 
141
{
 
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);
 
147
 
 
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, 
 
161
                 el_mul);
 
162
  INSTALL_BINOP (op_el_div, octave_sparse_matrix, octave_sparse_matrix, 
 
163
                 el_div);
 
164
  INSTALL_BINOP (op_el_pow, octave_sparse_matrix, octave_sparse_matrix, 
 
165
                 el_pow);
 
166
  INSTALL_BINOP (op_el_ldiv, octave_sparse_matrix, octave_sparse_matrix, 
 
167
                 el_ldiv);
 
168
  INSTALL_BINOP (op_el_and, octave_sparse_matrix, octave_sparse_matrix, 
 
169
                 el_and);
 
170
  INSTALL_BINOP (op_el_or, octave_sparse_matrix, octave_sparse_matrix, 
 
171
                 el_or);
 
172
 
 
173
  INSTALL_CATOP (octave_sparse_matrix, octave_sparse_matrix, sm_sm);
 
174
 
 
175
  INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_matrix, octave_sparse_matrix, 
 
176
                    assign);
 
177
}
 
178
 
 
179
/*
 
180
;;; Local Variables: ***
 
181
;;; mode: C++ ***
 
182
;;; End: ***
 
183
*/