annotate libinterp/corefcn/sparse-xpow.cc @ 30390:a61e1a0f6024 stable

maint: style check C++ files in libinterp/ ahead of 7.1 release. * Cell.cc, __eigs__.cc, __ichol__.cc, __ilu__.cc, __magick_read__.cc, __qp__.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.h, ccolamd.cc, cellfun.cc, data.cc, debug.cc, defun-int.h, dlmread.cc, event-manager.cc, fftn.cc, file-io.cc, ft-text-renderer.cc, gl2ps-print.cc, graphics.cc, graphics.in.h, gzfstream.cc, gzfstream.h, jsondecode.cc, jsonencode.cc, latex-text-renderer.cc, ls-mat5.cc, lu.cc, mex.cc, oct-stream.cc, oct-strstrm.cc, ordqz.cc, pager.h, pr-output.cc, qz.cc, schur.cc, sparse-xdiv.cc, sparse-xpow.cc, sparse.cc, stack-frame.h, strfns.cc, svd.cc, symrcm.cc, symscope.h, sysdep.cc, text-engine.h, text-renderer.h, tril.cc, variables.h, xdiv.h, __glpk__.cc, __init_fltk__.cc, __init_gnuplot__.cc, __voronoi__.cc, audiodevinfo.cc, cdef-class.cc, cdef-class.h, cdef-manager.cc, cdef-manager.h, cdef-method.cc, cdef-object.cc, ov-base-diag.cc, ov-base-diag.h, ov-base-int.cc, ov-base-int.h, ov-base-mat.cc, ov-base-mat.h, ov-base-scalar.h, ov-base-sparse.cc, ov-base-sparse.h, ov-base.h, ov-bool-mat.cc, ov-cell.cc, ov-cell.h, ov-class.cc, ov-class.h, ov-dld-fcn.cc, ov-intx.h, ov-lazy-idx.cc, ov-lazy-idx.h, ov-mex-fcn.h, ov-perm.cc, ov-perm.h, ov-range.cc, ov-re-mat.cc, ov-re-mat.h, ov-str-mat.h, ov-struct.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov.h, parse.h, pt-cell.cc, pt-stmt.cc, pt-tm-const.cc, pt-walk.cc: Style check C++ files in libinterp/ ahead of 7.1 release.
author Rik <rik@octave.org>
date Sun, 28 Nov 2021 21:52:08 -0800
parents b839c36fd106
children 796f54d4ddbf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
29358
0a5b15007766 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 28144
diff changeset
3 // Copyright (C) 1998-2021 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
27 # include "config.h"
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
28 #endif
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
29
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
30 #include <cassert>
15215
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
31
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
32 #include <limits>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
33
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
34 #include "Array-util.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
35 #include "oct-cmplx.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
36 #include "quit.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
37
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
38 #include "error.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 19697
diff changeset
39 #include "ovl.h"
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
40 #include "utils.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
41
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
42 #include "dSparse.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
43 #include "CSparse.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
44 #include "ov-re-sparse.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
45 #include "ov-cx-sparse.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
46 #include "sparse-xpow.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
47
29990
b839c36fd106 move sparse xdiv and xpow operator functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
48 OCTAVE_NAMESPACE_BEGIN
b839c36fd106 move sparse xdiv and xpow operator functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
49
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
50 static inline int
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
51 xisint (double x)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
52 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
53 return (octave::math::x_nint (x) == x
15215
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
54 && ((x >= 0 && x < std::numeric_limits<int>::max ())
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
55 || (x <= 0 && x > std::numeric_limits<int>::min ())));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
56 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
57
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
58 // Safer pow functions. Only two make sense for sparse matrices, the
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
59 // others should all promote to full matrices.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
60
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
61 octave_value
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
62 xpow (const SparseMatrix& a, double b)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
63 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
64 octave_value retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
65
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
66 octave_idx_type nr = a.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
67 octave_idx_type nc = a.cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
68
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
69 if (nr == 0 || nc == 0 || nr != nc)
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
70 error ("for A^b, A must be a square matrix. Use .^ for elementwise power.");
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
71
28144
c31c9eaa1f28 sparse-xpow.cc: use xisint instead of static_cast<int> to check int values
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
72 if (! xisint (b))
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
73 error ("use full(a) ^ full(b)");
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
74
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
75 int btmp = static_cast<int> (b);
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
76 if (btmp == 0)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
77 {
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
78 SparseMatrix tmp = SparseMatrix (nr, nr, nr);
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
79 for (octave_idx_type i = 0; i < nr; i++)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
80 {
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
81 tmp.data (i) = 1.0;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
82 tmp.ridx (i) = i;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
83 }
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
84 for (octave_idx_type i = 0; i < nr + 1; i++)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
85 tmp.cidx (i) = i;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
86
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
87 retval = tmp;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
88 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
89 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
90 {
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
91 SparseMatrix atmp;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
92 if (btmp < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
93 {
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
94 btmp = -btmp;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
95
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
96 octave_idx_type info;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
97 double rcond = 0.0;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
98 MatrixType mattyp (a);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
99
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
100 atmp = a.inverse (mattyp, info, rcond, 1);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
101
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
102 if (info == -1)
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
103 warning ("inverse: matrix singular to machine precision, rcond = %g", rcond);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
104 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
105 else
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
106 atmp = a;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
107
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
108 SparseMatrix result (atmp);
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
109
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
110 btmp--;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
111
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
112 while (btmp > 0)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
113 {
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
114 if (btmp & 1)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
115 result = result * atmp;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
116
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
117 btmp >>= 1;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
118
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
119 if (btmp > 0)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
120 atmp = atmp * atmp;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
121 }
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
122
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
123 retval = result;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
124 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
125
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
126 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
127 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
128
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
129 octave_value
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
130 xpow (const SparseComplexMatrix& a, double b)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
131 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
132 octave_value retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
133
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
134 octave_idx_type nr = a.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
135 octave_idx_type nc = a.cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
136
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
137 if (nr == 0 || nc == 0 || nr != nc)
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
138 error ("for A^b, A must be a square matrix. Use .^ for elementwise power.");
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
139
28144
c31c9eaa1f28 sparse-xpow.cc: use xisint instead of static_cast<int> to check int values
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
140 if (! xisint (b))
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
141 error ("use full(a) ^ full(b)");
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
142
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
143 int btmp = static_cast<int> (b);
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
144 if (btmp == 0)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
145 {
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
146 SparseMatrix tmp = SparseMatrix (nr, nr, nr);
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
147 for (octave_idx_type i = 0; i < nr; i++)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
148 {
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
149 tmp.data (i) = 1.0;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
150 tmp.ridx (i) = i;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
151 }
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
152 for (octave_idx_type i = 0; i < nr + 1; i++)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
153 tmp.cidx (i) = i;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
154
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
155 retval = tmp;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
156 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
157 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
158 {
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
159 SparseComplexMatrix atmp;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
160 if (btmp < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
161 {
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
162 btmp = -btmp;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
163
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
164 octave_idx_type info;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
165 double rcond = 0.0;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
166 MatrixType mattyp (a);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
167
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
168 atmp = a.inverse (mattyp, info, rcond, 1);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
169
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
170 if (info == -1)
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
171 warning ("inverse: matrix singular to machine precision, rcond = %g", rcond);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
172 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
173 else
20982
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
174 atmp = a;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
175
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
176 SparseComplexMatrix result (atmp);
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
177
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
178 btmp--;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
179
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
180 while (btmp > 0)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
181 {
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
182 if (btmp & 1)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
183 result = result * atmp;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
184
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
185 btmp >>= 1;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
186
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
187 if (btmp > 0)
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
188 atmp = atmp * atmp;
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
189 }
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
190
d27f66b4b8e6 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
191 retval = result;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
192 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
193
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
194 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
195 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
196
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
197 // Safer pow functions that work elementwise for matrices.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
198 //
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
199 // op2 \ op1: s m cs cm
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
200 // +-- +---+---+----+----+
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
201 // scalar | | * | 3 | * | 9 |
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
202 // +---+---+----+----+
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
203 // matrix | 1 | 4 | 7 | 10 |
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
204 // +---+---+----+----+
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
205 // complex_scalar | * | 5 | * | 11 |
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
206 // +---+---+----+----+
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
207 // complex_matrix | 2 | 6 | 8 | 12 |
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
208 // +---+---+----+----+
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
209 //
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
210 // * -> not needed.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
211
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17749
diff changeset
212 // FIXME: these functions need to be fixed so that things
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
213 // like
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
214 //
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
215 // a = -1; b = [ 0, 0.5, 1 ]; r = a .^ b
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
216 //
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
217 // and
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
218 //
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
219 // a = -1; b = [ 0, 0.5, 1 ]; for i = 1:3, r(i) = a .^ b(i), end
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
220 //
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
221 // produce identical results. Also, it would be nice if -1^0.5
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
222 // produced a pure imaginary result instead of a complex number with a
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
223 // small real part. But perhaps that's really a problem with the math
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
224 // library...
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
225
15282
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
226 // Handle special case of scalar-sparse-matrix .^ sparse-matrix.
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
227 // Forwarding to the scalar elem_xpow function and then converting the
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
228 // result back to a sparse matrix is a bit wasteful but it does not
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
229 // seem worth the effort to optimize -- how often does this case come up
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
230 // in practice?
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
231
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21121
diff changeset
232 template <typename S, typename SM>
15282
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
233 inline octave_value
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
234 scalar_xpow (const S& a, const SM& b)
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
235 {
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
236 octave_value val = elem_xpow (a, b);
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
237
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23220
diff changeset
238 if (val.iscomplex ())
15282
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
239 return SparseComplexMatrix (val.complex_matrix_value ());
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
240 else
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
241 return SparseMatrix (val.matrix_value ());
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
242 }
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
243
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
244 /*
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
245 %!assert (sparse (2) .^ [3, 4], sparse ([8, 16]))
22470
9d4cb0cf9cd2 maint: tag xtests and tests that fail on some systems with bug numbers
Mike Miller <mtmiller@octave.org>
parents: 22407
diff changeset
246 %!assert <47775> (sparse (2i) .^ [3, 4], sparse ([-0-8i, 16]))
15282
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
247 */
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
248
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
249 // -*- 1 -*-
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
250 octave_value
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
251 elem_xpow (double a, const SparseMatrix& b)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
252 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
253 octave_value retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
254
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
255 octave_idx_type nr = b.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
256 octave_idx_type nc = b.cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
257
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
258 double d1, d2;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
259
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
260 if (a < 0.0 && ! b.all_integers (d1, d2))
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
261 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
262 Complex atmp (a);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
263 ComplexMatrix result (nr, nc);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
264
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
265 for (octave_idx_type j = 0; j < nc; j++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
266 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
267 for (octave_idx_type i = 0; i < nr; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
268 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
269 octave_quit ();
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29990
diff changeset
270 result(i, j) = std::pow (atmp, b(i, j));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
271 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
272 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
273
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
274 retval = result;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
275 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
276 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
277 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
278 Matrix result (nr, nc);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
279
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
280 for (octave_idx_type j = 0; j < nc; j++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
281 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
282 for (octave_idx_type i = 0; i < nr; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
283 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
284 octave_quit ();
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29990
diff changeset
285 result(i, j) = std::pow (a, b(i, j));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
286 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
287 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
288
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
289 retval = result;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
290 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
291
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
292 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
293 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
294
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
295 // -*- 2 -*-
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
296 octave_value
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
297 elem_xpow (double a, const SparseComplexMatrix& b)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
298 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
299 octave_idx_type nr = b.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
300 octave_idx_type nc = b.cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
301
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
302 Complex atmp (a);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
303 ComplexMatrix result (nr, nc);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
304
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
305 for (octave_idx_type j = 0; j < nc; j++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
306 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
307 for (octave_idx_type i = 0; i < nr; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
308 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
309 octave_quit ();
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29990
diff changeset
310 result(i, j) = std::pow (atmp, b(i, j));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
311 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
312 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
313
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
314 return result;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
315 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
316
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
317 // -*- 3 -*-
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
318 octave_value
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
319 elem_xpow (const SparseMatrix& a, double b)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
320 {
17861
870f3e12e163 maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents: 17787
diff changeset
321 // FIXME: What should a .^ 0 give? Matlab gives a
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
322 // sparse matrix with same structure as a, which is strictly
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
323 // incorrect. Keep compatibility.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
324
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
325 octave_value retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
326
10527
b4d2080b6df7 Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents: 10315
diff changeset
327 octave_idx_type nz = a.nnz ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
328
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
329 if (b <= 0.0)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
330 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
331 octave_idx_type nr = a.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
332 octave_idx_type nc = a.cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
333
28144
c31c9eaa1f28 sparse-xpow.cc: use xisint instead of static_cast<int> to check int values
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
334 if (! xisint (b) && a.any_element_is_negative ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
335 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
336 ComplexMatrix result (nr, nc, Complex (std::pow (0.0, b)));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
337
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17749
diff changeset
338 // FIXME: avoid apparent GNU libm bug by
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
339 // converting A and B to complex instead of just A.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
340 Complex btmp (b);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
341
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
342 for (octave_idx_type j = 0; j < nc; j++)
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
343 for (octave_idx_type i = a.cidx (j); i < a.cidx (j+1); i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
344 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
345 octave_quit ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
346
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
347 Complex atmp (a.data (i));
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
348
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
349 result(a.ridx (i), j) = std::pow (atmp, btmp);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
350 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
351
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
352 retval = octave_value (result);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
353 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
354 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
355 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
356 Matrix result (nr, nc, (std::pow (0.0, b)));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
357
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
358 for (octave_idx_type j = 0; j < nc; j++)
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
359 for (octave_idx_type i = a.cidx (j); i < a.cidx (j+1); i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
360 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
361 octave_quit ();
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
362 result(a.ridx (i), j) = std::pow (a.data (i), b);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
363 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
364
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
365 retval = octave_value (result);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
366 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
367 }
28144
c31c9eaa1f28 sparse-xpow.cc: use xisint instead of static_cast<int> to check int values
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
368 else if (! xisint (b) && a.any_element_is_negative ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
369 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
370 SparseComplexMatrix result (a);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
371
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
372 for (octave_idx_type i = 0; i < nz; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
373 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
374 octave_quit ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
375
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17749
diff changeset
376 // FIXME: avoid apparent GNU libm bug by
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
377 // converting A and B to complex instead of just A.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
378
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
379 Complex atmp (a.data (i));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
380 Complex btmp (b);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
381
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
382 result.data (i) = std::pow (atmp, btmp);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
383 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
384
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
385 result.maybe_compress (true);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
386
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
387 retval = result;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
388 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
389 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
390 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
391 SparseMatrix result (a);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
392
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
393 for (octave_idx_type i = 0; i < nz; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
394 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
395 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
396 result.data (i) = std::pow (a.data (i), b);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
397 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
398
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
399 result.maybe_compress (true);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
400
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
401 retval = result;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
402 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
403
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
404 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
405 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
406
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
407 // -*- 4 -*-
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
408 octave_value
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
409 elem_xpow (const SparseMatrix& a, const SparseMatrix& b)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
410 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
411 octave_value retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
412
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
413 octave_idx_type nr = a.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
414 octave_idx_type nc = a.cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
415
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
416 octave_idx_type b_nr = b.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
417 octave_idx_type b_nc = b.cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
418
15282
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
419 if (a.numel () == 1 && b.numel () > 1)
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
420 return scalar_xpow (a(0), b);
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
421
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
422 if (nr != b_nr || nc != b_nc)
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
423 octave::err_nonconformant ("operator .^", nr, nc, b_nr, b_nc);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
424
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
425 int convert_to_complex = 0;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
426 for (octave_idx_type j = 0; j < nc; j++)
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
427 for (octave_idx_type i = a.cidx (j); i < a.cidx (j+1); i++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
428 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
429 if (a.data(i) < 0.0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
430 {
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
431 double btmp = b (a.ridx (i), j);
28144
c31c9eaa1f28 sparse-xpow.cc: use xisint instead of static_cast<int> to check int values
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
432 if (! xisint (btmp))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
433 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
434 convert_to_complex = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
435 goto done;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
436 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
437 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
438 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
439
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
440 done:
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
441
5953
164214586706 [project @ 2006-08-22 15:31:32 by jwe]
jwe
parents: 5785
diff changeset
442 // This is a dumb operator for sparse matrices anyway, and there is
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
443 // no sensible way to handle the 0.^0 versus the 0.^x cases. Therefore
5953
164214586706 [project @ 2006-08-22 15:31:32 by jwe]
jwe
parents: 5785
diff changeset
444 // allocate a full matrix filled for the 0.^0 case and shrink it later
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
445 // as needed.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
446
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
447 if (convert_to_complex)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
448 {
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
449 SparseComplexMatrix complex_result (nr, nc, Complex (1.0, 0.0));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
450
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
451 for (octave_idx_type j = 0; j < nc; j++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
452 {
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
453 for (octave_idx_type i = a.cidx (j); i < a.cidx (j+1); i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
454 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
455 octave_quit ();
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
456 complex_result.xelem (a.ridx (i), j)
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
457 = std::pow (Complex (a.data (i)), Complex (b(a.ridx (i), j)));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
458 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
459 }
5953
164214586706 [project @ 2006-08-22 15:31:32 by jwe]
jwe
parents: 5785
diff changeset
460 complex_result.maybe_compress (true);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
461 retval = complex_result;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
462 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
463 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
464 {
5953
164214586706 [project @ 2006-08-22 15:31:32 by jwe]
jwe
parents: 5785
diff changeset
465 SparseMatrix result (nr, nc, 1.0);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
466
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
467 for (octave_idx_type j = 0; j < nc; j++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
468 {
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
469 for (octave_idx_type i = a.cidx (j); i < a.cidx (j+1); i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
470 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
471 octave_quit ();
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
472 result.xelem (a.ridx (i), j) = std::pow (a.data (i),
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
473 b(a.ridx (i), j));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
474 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
475 }
5953
164214586706 [project @ 2006-08-22 15:31:32 by jwe]
jwe
parents: 5785
diff changeset
476 result.maybe_compress (true);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
477 retval = result;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
478 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
479
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
480 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
481 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
482
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
483 // -*- 5 -*-
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
484 octave_value
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
485 elem_xpow (const SparseMatrix& a, const Complex& b)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
486 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
487 octave_value retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
488
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
489 if (b == 0.0)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
490 // Can this case ever happen, due to automatic retyping with maybe_mutate?
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
491 retval = octave_value (NDArray (a.dims (), 1));
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
492 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
493 {
10527
b4d2080b6df7 Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents: 10315
diff changeset
494 octave_idx_type nz = a.nnz ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
495 SparseComplexMatrix result (a);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
496
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
497 for (octave_idx_type i = 0; i < nz; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
498 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
499 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
500 result.data (i) = std::pow (Complex (a.data (i)), b);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
501 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
502
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
503 result.maybe_compress (true);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
504
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
505 retval = result;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
506 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
507
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
508 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
509 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
510
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
511 // -*- 6 -*-
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
512 octave_value
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
513 elem_xpow (const SparseMatrix& a, const SparseComplexMatrix& b)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
514 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
515 octave_idx_type nr = a.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
516 octave_idx_type nc = a.cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
517
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
518 octave_idx_type b_nr = b.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
519 octave_idx_type b_nc = b.cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
520
15282
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
521 if (a.numel () == 1 && b.numel () > 1)
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
522 return scalar_xpow (a(0), b);
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
523
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
524 if (nr != b_nr || nc != b_nc)
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
525 octave::err_nonconformant ("operator .^", nr, nc, b_nr, b_nc);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
526
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
527 SparseComplexMatrix result (nr, nc, Complex (1.0, 0.0));
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
528 for (octave_idx_type j = 0; j < nc; j++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
529 {
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
530 for (octave_idx_type i = a.cidx (j); i < a.cidx (j+1); i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
531 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
532 octave_quit ();
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
533 result.xelem (a.ridx(i), j) = std::pow (a.data (i), b(a.ridx (i), j));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
534 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
535 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
536
5953
164214586706 [project @ 2006-08-22 15:31:32 by jwe]
jwe
parents: 5785
diff changeset
537 result.maybe_compress (true);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
538
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
539 return result;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
540 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
541
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
542 // -*- 7 -*-
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
543 octave_value
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
544 elem_xpow (const Complex& a, const SparseMatrix& b)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
545 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
546 octave_idx_type nr = b.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
547 octave_idx_type nc = b.cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
548
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
549 ComplexMatrix result (nr, nc);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
550
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
551 for (octave_idx_type j = 0; j < nc; j++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
552 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
553 for (octave_idx_type i = 0; i < nr; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
554 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
555 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
556 double btmp = b (i, j);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
557 if (xisint (btmp))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
558 result (i, j) = std::pow (a, static_cast<int> (btmp));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
559 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
560 result (i, j) = std::pow (a, btmp);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
561 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
562 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
563
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
564 return result;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
565 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
566
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
567 // -*- 8 -*-
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
568 octave_value
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
569 elem_xpow (const Complex& a, const SparseComplexMatrix& b)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
570 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
571 octave_idx_type nr = b.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
572 octave_idx_type nc = b.cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
573
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
574 ComplexMatrix result (nr, nc);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
575 for (octave_idx_type j = 0; j < nc; j++)
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
576 for (octave_idx_type i = 0; i < nr; i++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
577 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
578 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
579 result (i, j) = std::pow (a, b (i, j));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
580 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
581
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
582 return result;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
583 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
584
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
585 // -*- 9 -*-
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
586 octave_value
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
587 elem_xpow (const SparseComplexMatrix& a, double b)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
588 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
589 octave_value retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
590
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
591 if (b <= 0)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
592 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
593 octave_idx_type nr = a.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
594 octave_idx_type nc = a.cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
595
5953
164214586706 [project @ 2006-08-22 15:31:32 by jwe]
jwe
parents: 5785
diff changeset
596 ComplexMatrix result (nr, nc, Complex (std::pow (0.0, b)));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
597
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
598 if (xisint (b))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
599 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
600 for (octave_idx_type j = 0; j < nc; j++)
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
601 for (octave_idx_type i = a.cidx (j); i < a.cidx (j+1); i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
602 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
603 octave_quit ();
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
604 result (a.ridx (i), j)
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
605 = std::pow (a.data (i), static_cast<int> (b));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
606 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
607 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
608 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
609 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
610 for (octave_idx_type j = 0; j < nc; j++)
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
611 for (octave_idx_type i = a.cidx (j); i < a.cidx (j+1); i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
612 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
613 octave_quit ();
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
614 result (a.ridx (i), j) = std::pow (a.data (i), b);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
615 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
616 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
617
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
618 retval = result;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
619 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
620 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
621 {
10527
b4d2080b6df7 Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents: 10315
diff changeset
622 octave_idx_type nz = a.nnz ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
623
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
624 SparseComplexMatrix result (a);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
625
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
626 if (xisint (b))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
627 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
628 for (octave_idx_type i = 0; i < nz; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
629 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
630 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
631 result.data (i) = std::pow (a.data (i), static_cast<int> (b));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
632 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
633 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
634 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
635 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
636 for (octave_idx_type i = 0; i < nz; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
637 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
638 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
639 result.data (i) = std::pow (a.data (i), b);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
640 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
641 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
642
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
643 result.maybe_compress (true);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
644
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
645 retval = result;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
646 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
647
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
648 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
649 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
650
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
651 // -*- 10 -*-
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
652 octave_value
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
653 elem_xpow (const SparseComplexMatrix& a, const SparseMatrix& b)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
654 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
655 octave_idx_type nr = a.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
656 octave_idx_type nc = a.cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
657
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
658 octave_idx_type b_nr = b.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
659 octave_idx_type b_nc = b.cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
660
15282
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
661 if (a.numel () == 1 && b.numel () > 1)
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
662 return scalar_xpow (a(0), b);
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
663
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
664 if (nr != b_nr || nc != b_nc)
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
665 octave::err_nonconformant ("operator .^", nr, nc, b_nr, b_nc);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
666
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
667 SparseComplexMatrix result (nr, nc, Complex (1.0, 0.0));
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
668 for (octave_idx_type j = 0; j < nc; j++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
669 {
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
670 for (octave_idx_type i = a.cidx (j); i < a.cidx (j+1); i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
671 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
672 octave_quit ();
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
673 double btmp = b(a.ridx (i), j);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
674
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
675 if (xisint (btmp))
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
676 result.xelem (a.ridx (i), j) = std::pow (a.data (i),
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
677 static_cast<int> (btmp));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
678 else
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
679 result.xelem (a.ridx (i), j) = std::pow (a.data (i), btmp);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
680 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
681 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
682
5953
164214586706 [project @ 2006-08-22 15:31:32 by jwe]
jwe
parents: 5785
diff changeset
683 result.maybe_compress (true);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
684
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
685 return result;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
686 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
687
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
688 // -*- 11 -*-
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
689 octave_value
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
690 elem_xpow (const SparseComplexMatrix& a, const Complex& b)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
691 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
692 octave_value retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
693
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
694 if (b == 0.0)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
695 // Can this case ever happen, due to automatic retyping with maybe_mutate?
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
696 retval = octave_value (NDArray (a.dims (), 1));
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
697 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
698 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
699
10527
b4d2080b6df7 Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents: 10315
diff changeset
700 octave_idx_type nz = a.nnz ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
701
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
702 SparseComplexMatrix result (a);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
703
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
704 for (octave_idx_type i = 0; i < nz; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
705 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
706 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
707 result.data (i) = std::pow (a.data (i), b);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
708 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
709
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
710 result.maybe_compress (true);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
711
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
712 retval = result;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
713 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
714
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
715 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
716 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
717
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
718 // -*- 12 -*-
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
719 octave_value
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
720 elem_xpow (const SparseComplexMatrix& a, const SparseComplexMatrix& b)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
721 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
722 octave_idx_type nr = a.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
723 octave_idx_type nc = a.cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
724
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
725 octave_idx_type b_nr = b.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
726 octave_idx_type b_nc = b.cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
727
15282
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
728 if (a.numel () == 1 && b.numel () > 1)
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
729 return scalar_xpow (a(0), b);
06ce57277bfb handle scalar-sparse-matrix .^ matrix ops
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
730
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
731 if (nr != b_nr || nc != b_nc)
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
732 octave::err_nonconformant ("operator .^", nr, nc, b_nr, b_nc);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
733
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
734 SparseComplexMatrix result (nr, nc, Complex (1.0, 0.0));
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
735 for (octave_idx_type j = 0; j < nc; j++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
736 {
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
737 for (octave_idx_type i = a.cidx (j); i < a.cidx (j+1); i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
738 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
739 octave_quit ();
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17749
diff changeset
740 result.xelem (a.ridx (i), j) = std::pow (a.data (i),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17749
diff changeset
741 b(a.ridx (i), j));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
742 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
743 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
744 result.maybe_compress (true);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
745
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
746 return result;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
747 }
29990
b839c36fd106 move sparse xdiv and xpow operator functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
748
b839c36fd106 move sparse xdiv and xpow operator functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
749 OCTAVE_NAMESPACE_END