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

« back to all changes in this revision

Viewing changes to src/OPERATORS/op-scm-s.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-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-scm-s.h"
 
40
#include "smx-s-scm.h"
 
41
#include "ov-re-sparse.h"
 
42
#include "ov-cx-sparse.h"
 
43
 
 
44
// sparse complex matrix by scalar ops.
 
45
 
 
46
DEFBINOP_OP (add, sparse_complex_matrix, scalar, +)
 
47
DEFBINOP_OP (sub, sparse_complex_matrix, scalar, -)
 
48
DEFBINOP_OP (mul, sparse_complex_matrix, scalar, *)
 
49
 
 
50
DEFBINOP (div, sparse_complex_matrix, scalar)
 
51
{
 
52
  CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, 
 
53
                   const octave_scalar&);
 
54
 
 
55
  double d = v2.double_value ();
 
56
  octave_value retval;
 
57
 
 
58
  if (d == 0.0)
 
59
    {
 
60
      gripe_divide_by_zero ();
 
61
 
 
62
      retval = octave_value (v1.complex_matrix_value () / d);
 
63
    }
 
64
  else
 
65
    retval = octave_value (v1.sparse_complex_matrix_value () / d);
 
66
 
 
67
  return retval;
 
68
}
 
69
 
 
70
DEFBINOP (pow, sparse_complex_matrix, scalar)
 
71
{
 
72
  CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, 
 
73
                   const octave_scalar&);
 
74
 
 
75
  double tmp = v2.scalar_value ();
 
76
  if (static_cast<int> (tmp) == tmp)
 
77
    return xpow (v1.sparse_complex_matrix_value (), tmp);
 
78
  else
 
79
    return xpow (v1.complex_matrix_value (), tmp);
 
80
}
 
81
 
 
82
DEFBINOP (ldiv, sparse_complex_matrix, scalar)
 
83
{
 
84
  CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, const octave_scalar&);
 
85
 
 
86
  if (v1.rows() == 1 && v1.columns() == 1)
 
87
    {
 
88
      Complex d = v1.complex_value ();
 
89
 
 
90
      if (d == 0.0)
 
91
        gripe_divide_by_zero ();
 
92
 
 
93
      return octave_value (v2.scalar_value () / d);
 
94
    }
 
95
  else
 
96
    {
 
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);
 
102
      return ret;
 
103
    }
 
104
}
 
105
 
 
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)
 
112
 
 
113
DEFBINOP_OP (el_mul, sparse_complex_matrix, scalar, *)
 
114
 
 
115
DEFBINOP (el_div, sparse_complex_matrix, scalar)
 
116
{
 
117
  CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, 
 
118
                   const octave_scalar&);
 
119
 
 
120
  double d = v2.double_value ();
 
121
  octave_value retval;
 
122
 
 
123
  if (d == 0.0)
 
124
    {
 
125
      gripe_divide_by_zero ();
 
126
 
 
127
      retval = octave_value (v1.complex_matrix_value () / d);
 
128
    }
 
129
  else
 
130
    retval = octave_value (v1.sparse_complex_matrix_value () / d);
 
131
 
 
132
  return retval;
 
133
}
 
134
 
 
135
DEFBINOP_FN (el_pow, sparse_complex_matrix, scalar, elem_xpow)
 
136
 
 
137
DEFBINOP (el_ldiv, sparse_complex_matrix, scalar)
 
138
{
 
139
  CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, const octave_scalar&);
 
140
 
 
141
  return octave_value
 
142
    (x_el_div (v2.double_value (), v1.sparse_complex_matrix_value ()));
 
143
}
 
144
 
 
145
DEFBINOP_FN (el_and, sparse_complex_matrix, scalar, mx_el_and)
 
146
DEFBINOP_FN (el_or,  sparse_complex_matrix, scalar, mx_el_or)
 
147
 
 
148
DEFCATOP (scm_s, sparse_complex_matrix, scalar)
 
149
{
 
150
  CAST_BINOP_ARGS (octave_sparse_complex_matrix&, const octave_scalar&);
 
151
  SparseComplexMatrix tmp (1, 1, v2.complex_value ());
 
152
  return octave_value
 
153
    (v1.sparse_complex_matrix_value (). concat (tmp, ra_idx));
 
154
}
 
155
 
 
156
DEFASSIGNOP (assign, sparse_complex_matrix, scalar)
 
157
{
 
158
  CAST_BINOP_ARGS (octave_sparse_complex_matrix&, const octave_scalar&);
 
159
 
 
160
  SparseComplexMatrix tmp (1, 1, v2.complex_value ());
 
161
  v1.assign (idx, tmp);
 
162
  return octave_value ();
 
163
}
 
164
 
 
165
void
 
166
install_scm_s_ops (void)
 
167
{
 
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, 
 
181
                 el_mul);
 
182
  INSTALL_BINOP (op_el_div, octave_sparse_complex_matrix, octave_scalar, 
 
183
                 el_div);
 
184
  INSTALL_BINOP (op_el_pow, octave_sparse_complex_matrix, octave_scalar, 
 
185
                 el_pow);
 
186
  INSTALL_BINOP (op_el_ldiv, octave_sparse_complex_matrix, octave_scalar, 
 
187
                 el_ldiv);
 
188
  INSTALL_BINOP (op_el_and, octave_sparse_complex_matrix, octave_scalar, 
 
189
                 el_and);
 
190
  INSTALL_BINOP (op_el_or, octave_sparse_complex_matrix, octave_scalar, 
 
191
                 el_or);
 
192
 
 
193
  INSTALL_CATOP (octave_sparse_complex_matrix, octave_scalar, scm_s);
 
194
 
 
195
  INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_complex_matrix, octave_scalar, 
 
196
                    assign);
 
197
}
 
198
 
 
199
/*
 
200
;;; Local Variables: ***
 
201
;;; mode: C++ ***
 
202
;;; End: ***
 
203
*/