Mercurial > octave
annotate libinterp/corefcn/xpow.cc @ 29816:f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
* xpow.cc (xpow (double, ComplexMatrix), xpow (float, FloatComplexMatrix)):
Check for base < 0.0 and if found use std::pow with std::complex first argument
so that math library chooses a different template for function which can handle
negative bases.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 24 Jun 2021 13:51:52 -0700 |
parents | 540f25090412 |
children | 004e63a7a501 |
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:
27932
diff
changeset
|
3 // Copyright (C) 1993-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 //////////////////////////////////////////////////////////////////////// |
1 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
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" |
1 | 28 #endif |
29 | |
1343 | 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> |
1343 | 33 |
4669 | 34 #include "Array-util.h" |
1352 | 35 #include "CColVector.h" |
453 | 36 #include "CDiagMatrix.h" |
8382
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
37 #include "fCDiagMatrix.h" |
19269
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
19018
diff
changeset
|
38 #include "fCMatrix.h" |
1352 | 39 #include "CMatrix.h" |
453 | 40 #include "EIG.h" |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
41 #include "fEIG.h" |
1352 | 42 #include "dDiagMatrix.h" |
8382
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
43 #include "fDiagMatrix.h" |
1352 | 44 #include "dMatrix.h" |
8958
6ccc12cc65ef
implement raising a permutation matrix to integer power
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
45 #include "PermMatrix.h" |
3585 | 46 #include "mx-cm-cdm.h" |
19269
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
19018
diff
changeset
|
47 #include "mx-fcm-fcdm.h" |
1651 | 48 #include "oct-cmplx.h" |
9103
10bed8fbec99
optimize scalar .^ range operation
Jaroslav Hajek <highegg@gmail.com>
parents:
8979
diff
changeset
|
49 #include "Range.h" |
4153 | 50 #include "quit.h" |
1352 | 51 |
52 #include "error.h" | |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20679
diff
changeset
|
53 #include "ovl.h" |
1567 | 54 #include "utils.h" |
1352 | 55 #include "xpow.h" |
1 | 56 |
13005
4061106b1c4b
Enable automatic bsxfun for power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
57 #include "bsxfun.h" |
4061106b1c4b
Enable automatic bsxfun for power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
58 |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
59 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
60 static void |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
61 err_failed_diagonalization (void) |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
62 { |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
63 error ("Failed to diagonalize matrix while calculating matrix exponential"); |
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
64 } |
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
65 |
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
66 static void |
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
67 err_nonsquare_matrix (void) |
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
68 { |
25553
986ba7f21a85
xpow.cc (err_nonsquare_matrix): Clarify error message (bug #54248).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25054
diff
changeset
|
69 error ("for x^y, only square matrix arguments are permitted and one " \ |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
70 "argument must be scalar. Use .^ for elementwise power."); |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
71 } |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
72 |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
73 template <typename T> |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
74 static inline bool |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
75 xisint (T x) |
1567 | 76 { |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
77 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
|
78 && ((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
|
79 || (x <= 0 && x > std::numeric_limits<int>::min ()))); |
1567 | 80 } |
81 | |
767 | 82 // Safer pow functions. |
83 // | |
84 // op2 \ op1: s m cs cm | |
85 // +-- +---+---+----+----+ | |
86 // scalar | | 1 | 5 | 7 | 11 | | |
87 // +---+---+----+----+ | |
2365 | 88 // matrix | 2 | * | 8 | * | |
767 | 89 // +---+---+----+----+ |
90 // complex_scalar | 3 | 6 | 9 | 12 | | |
91 // +---+---+----+----+ | |
2365 | 92 // complex_matrix | 4 | * | 10 | * | |
767 | 93 // +---+---+----+----+ |
1 | 94 |
767 | 95 // -*- 1 -*- |
2086 | 96 octave_value |
1 | 97 xpow (double a, double b) |
98 { | |
7543
b84c5cbc0812
print.m: handle gif and jpg devices
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
99 double retval; |
b84c5cbc0812
print.m: handle gif and jpg devices
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
100 |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
101 if (a < 0.0 && ! xisint (b)) |
1 | 102 { |
5260 | 103 Complex atmp (a); |
4682 | 104 |
5260 | 105 return std::pow (atmp, b); |
1 | 106 } |
107 else | |
7543
b84c5cbc0812
print.m: handle gif and jpg devices
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
108 retval = std::pow (a, b); |
b84c5cbc0812
print.m: handle gif and jpg devices
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
109 |
b84c5cbc0812
print.m: handle gif and jpg devices
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
110 return retval; |
1 | 111 } |
112 | |
767 | 113 // -*- 2 -*- |
2086 | 114 octave_value |
164 | 115 xpow (double a, const Matrix& b) |
1 | 116 { |
2086 | 117 octave_value retval; |
1 | 118 |
5275 | 119 octave_idx_type nr = b.rows (); |
120 octave_idx_type nc = b.cols (); | |
1 | 121 |
29389
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
122 if (nr == 0 || nc == 0) |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
123 return Matrix (); |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
124 |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
125 if (nr != nc) |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
126 err_nonsquare_matrix (); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
127 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
128 try |
1 | 129 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
130 EIG b_eig (b); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
131 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
132 ComplexColumnVector lambda (b_eig.eigenvalues ()); |
22305
510886d03ef2
eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22197
diff
changeset
|
133 ComplexMatrix Q (b_eig.right_eigenvectors ()); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
134 |
29803
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
135 if (a < 0.0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
136 { |
29803
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
137 Complex acplx (a); |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
138 for (octave_idx_type i = 0; i < nr; i++) |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
139 { |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
140 Complex elt = lambda(i); |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
141 if (std::imag (elt) == 0.0) |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
142 lambda(i) = std::pow (acplx, std::real (elt)); |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
143 else |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
144 lambda(i) = std::pow (a, elt); |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
145 } |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
146 } |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
147 else |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
148 { |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
149 for (octave_idx_type i = 0; i < nr; i++) |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
150 { |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
151 Complex elt = lambda(i); |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
152 if (std::imag (elt) == 0.0) |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
153 lambda(i) = std::pow (a, std::real (elt)); |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
154 else |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
155 lambda(i) = std::pow (a, elt); |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
156 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
157 } |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
158 ComplexDiagMatrix D (lambda); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
159 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
160 ComplexMatrix C = Q * D * Q.inverse (); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
161 if (a > 0) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
162 retval = real (C); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
163 else |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
164 retval = C; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
165 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
166 catch (const octave::execution_exception&) |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
167 { |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
168 err_failed_diagonalization (); |
1 | 169 } |
170 | |
171 return retval; | |
172 } | |
173 | |
767 | 174 // -*- 3 -*- |
2086 | 175 octave_value |
164 | 176 xpow (double a, const Complex& b) |
1 | 177 { |
10144
1b883ce66707
avoid redundant real->complex conversions in xpow
Jaroslav Hajek <highegg@gmail.com>
parents:
10142
diff
changeset
|
178 Complex result = std::pow (a, b); |
1567 | 179 return result; |
1 | 180 } |
181 | |
767 | 182 // -*- 4 -*- |
2086 | 183 octave_value |
164 | 184 xpow (double a, const ComplexMatrix& b) |
1 | 185 { |
2086 | 186 octave_value retval; |
1 | 187 |
5275 | 188 octave_idx_type nr = b.rows (); |
189 octave_idx_type nc = b.cols (); | |
1 | 190 |
29389
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
191 if (nr == 0 || nc == 0) |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
192 return Matrix (); |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
193 |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
194 if (nr != nc) |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
195 err_nonsquare_matrix (); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
196 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
197 EIG b_eig (b); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
198 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
199 try |
1 | 200 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
201 ComplexColumnVector lambda (b_eig.eigenvalues ()); |
22305
510886d03ef2
eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22197
diff
changeset
|
202 ComplexMatrix Q (b_eig.right_eigenvectors ()); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
203 |
29816
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
204 if (a < 0.0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
205 { |
29816
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
206 Complex acplx (a); |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
207 for (octave_idx_type i = 0; i < nr; i++) |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
208 { |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
209 Complex elt = lambda(i); |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
210 if (std::imag (elt) == 0.0) |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
211 lambda(i) = std::pow (acplx, std::real (elt)); |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
212 else |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
213 lambda(i) = std::pow (a, elt); |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
214 } |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
215 } |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
216 else |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
217 { |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
218 for (octave_idx_type i = 0; i < nr; i++) |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
219 { |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
220 Complex elt = lambda(i); |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
221 if (std::imag (elt) == 0.0) |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
222 lambda(i) = std::pow (a, std::real (elt)); |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
223 else |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
224 lambda(i) = std::pow (a, elt); |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
225 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
226 } |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
227 ComplexDiagMatrix D (lambda); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
228 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
229 retval = ComplexMatrix (Q * D * Q.inverse ()); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
230 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
231 catch (const octave::execution_exception&) |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
232 { |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
233 err_failed_diagonalization (); |
1 | 234 } |
235 | |
236 return retval; | |
237 } | |
238 | |
767 | 239 // -*- 5 -*- |
2086 | 240 octave_value |
164 | 241 xpow (const Matrix& a, double b) |
1 | 242 { |
2086 | 243 octave_value retval; |
1 | 244 |
5275 | 245 octave_idx_type nr = a.rows (); |
246 octave_idx_type nc = a.cols (); | |
1 | 247 |
29389
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
248 if (nr == 0 || nc == 0) |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
249 return Matrix (); |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
250 |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
251 if (nr != nc) |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
252 err_nonsquare_matrix (); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
253 |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
254 if (xisint (b)) |
1 | 255 { |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
256 int bint = static_cast<int> (b); |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
257 if (bint == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
258 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
259 retval = DiagMatrix (nr, nr, 1.0); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
260 } |
1 | 261 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
262 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
263 // Too much copying? |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
264 // FIXME: we shouldn't do this if the exponent is large... |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
265 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
266 Matrix atmp; |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
267 if (bint < 0) |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
268 { |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
269 bint = -bint; |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
270 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
271 octave_idx_type info; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
272 double rcond = 0.0; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
273 MatrixType mattype (a); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
274 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
275 atmp = a.inverse (mattype, info, rcond, 1); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
276 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
277 if (info == -1) |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
278 warning ("inverse: matrix singular to machine precision, rcond = %g", rcond); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
279 } |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
280 else |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
281 atmp = a; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
282 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
283 Matrix result (atmp); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
284 |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
285 bint--; |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
286 |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
287 while (bint > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
288 { |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
289 if (bint & 1) |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
290 // Use atmp * result instead of result * atmp |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
291 // for ML compatibility (bug #52706). |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
292 result = atmp * result; |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
293 |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
294 bint >>= 1; |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
295 |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
296 if (bint > 0) |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
297 atmp = atmp * atmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
298 } |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
299 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
300 retval = result; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
301 } |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
302 } |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
303 else |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
304 { |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
305 EIG a_eig (a); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
306 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
307 try |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
308 { |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
309 ComplexColumnVector lambda (a_eig.eigenvalues ()); |
22305
510886d03ef2
eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22197
diff
changeset
|
310 ComplexMatrix Q (a_eig.right_eigenvectors ()); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
311 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
312 for (octave_idx_type i = 0; i < nr; i++) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
313 lambda(i) = std::pow (lambda(i), b); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
314 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
315 ComplexDiagMatrix D (lambda); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
316 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
317 retval = ComplexMatrix (Q * D * Q.inverse ()); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
318 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
319 catch (const octave::execution_exception&) |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
320 { |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
321 err_failed_diagonalization (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
322 } |
1567 | 323 } |
1358 | 324 |
1567 | 325 return retval; |
326 } | |
1 | 327 |
8382
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
328 // -*- 5d -*- |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
329 octave_value |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
330 xpow (const DiagMatrix& a, double b) |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
331 { |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
332 octave_value retval; |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
333 |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
334 octave_idx_type nr = a.rows (); |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
335 octave_idx_type nc = a.cols (); |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
336 |
29389
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
337 if (nr == 0 || nc == 0) |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
338 return Matrix (); |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
339 |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
340 if (nr != nc) |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
341 err_nonsquare_matrix (); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
342 |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
343 if (xisint (b)) |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
344 { |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
345 DiagMatrix r (nr, nc); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
346 for (octave_idx_type i = 0; i < nc; i++) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
347 r.dgelem (i) = std::pow (a.dgelem (i), b); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
348 retval = r; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
349 } |
8382
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
350 else |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
351 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
352 ComplexDiagMatrix r (nr, nc); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
353 for (octave_idx_type i = 0; i < nc; i++) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
354 r.dgelem (i) = std::pow (static_cast<Complex> (a.dgelem (i)), b); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
355 retval = r; |
8382
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
356 } |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
357 |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
358 return retval; |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
359 } |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
360 |
8958
6ccc12cc65ef
implement raising a permutation matrix to integer power
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
361 // -*- 5p -*- |
6ccc12cc65ef
implement raising a permutation matrix to integer power
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
362 octave_value |
6ccc12cc65ef
implement raising a permutation matrix to integer power
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
363 xpow (const PermMatrix& a, double b) |
6ccc12cc65ef
implement raising a permutation matrix to integer power
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
364 { |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
365 if (xisint (b)) |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
366 return a.power (static_cast<int> (b)); |
8958
6ccc12cc65ef
implement raising a permutation matrix to integer power
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
367 else |
6ccc12cc65ef
implement raising a permutation matrix to integer power
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
368 return xpow (Matrix (a), b); |
6ccc12cc65ef
implement raising a permutation matrix to integer power
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
369 } |
6ccc12cc65ef
implement raising a permutation matrix to integer power
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
370 |
1567 | 371 // -*- 6 -*- |
2086 | 372 octave_value |
1567 | 373 xpow (const Matrix& a, const Complex& b) |
374 { | |
2086 | 375 octave_value retval; |
1 | 376 |
5275 | 377 octave_idx_type nr = a.rows (); |
378 octave_idx_type nc = a.cols (); | |
1567 | 379 |
29389
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
380 if (nr == 0 || nc == 0) |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
381 return Matrix (); |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
382 |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
383 if (nr != nc) |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
384 err_nonsquare_matrix (); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
385 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
386 EIG a_eig (a); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
387 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
388 try |
1 | 389 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
390 ComplexColumnVector lambda (a_eig.eigenvalues ()); |
22305
510886d03ef2
eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22197
diff
changeset
|
391 ComplexMatrix Q (a_eig.right_eigenvectors ()); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
392 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
393 for (octave_idx_type i = 0; i < nr; i++) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
394 lambda(i) = std::pow (lambda(i), b); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
395 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
396 ComplexDiagMatrix D (lambda); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
397 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
398 retval = ComplexMatrix (Q * D * Q.inverse ()); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
399 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
400 catch (const octave::execution_exception&) |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
401 { |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
402 err_failed_diagonalization (); |
1 | 403 } |
404 | |
405 return retval; | |
406 } | |
407 | |
767 | 408 // -*- 7 -*- |
2086 | 409 octave_value |
164 | 410 xpow (const Complex& a, double b) |
1 | 411 { |
412 Complex result; | |
1567 | 413 |
414 if (xisint (b)) | |
5260 | 415 result = std::pow (a, static_cast<int> (b)); |
1567 | 416 else |
5260 | 417 result = std::pow (a, b); |
1567 | 418 |
419 return result; | |
1 | 420 } |
421 | |
767 | 422 // -*- 8 -*- |
2086 | 423 octave_value |
164 | 424 xpow (const Complex& a, const Matrix& b) |
1 | 425 { |
2086 | 426 octave_value retval; |
1 | 427 |
5275 | 428 octave_idx_type nr = b.rows (); |
429 octave_idx_type nc = b.cols (); | |
1 | 430 |
29389
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
431 if (nr == 0 || nc == 0) |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
432 return Matrix (); |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
433 |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
434 if (nr != nc) |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
435 err_nonsquare_matrix (); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
436 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
437 EIG b_eig (b); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
438 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
439 try |
1 | 440 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
441 ComplexColumnVector lambda (b_eig.eigenvalues ()); |
22305
510886d03ef2
eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22197
diff
changeset
|
442 ComplexMatrix Q (b_eig.right_eigenvectors ()); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
443 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
444 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
|
445 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
446 Complex elt = lambda(i); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
447 if (std::imag (elt) == 0.0) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
448 lambda(i) = std::pow (a, std::real (elt)); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
449 else |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
450 lambda(i) = std::pow (a, elt); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
451 } |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
452 ComplexDiagMatrix D (lambda); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
453 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
454 retval = ComplexMatrix (Q * D * Q.inverse ()); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
455 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
456 catch (const octave::execution_exception&) |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
457 { |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
458 err_failed_diagonalization (); |
1 | 459 } |
460 | |
461 return retval; | |
462 } | |
463 | |
767 | 464 // -*- 9 -*- |
2086 | 465 octave_value |
164 | 466 xpow (const Complex& a, const Complex& b) |
1 | 467 { |
468 Complex result; | |
5260 | 469 result = std::pow (a, b); |
1567 | 470 return result; |
1 | 471 } |
472 | |
767 | 473 // -*- 10 -*- |
2086 | 474 octave_value |
164 | 475 xpow (const Complex& a, const ComplexMatrix& b) |
1 | 476 { |
2086 | 477 octave_value retval; |
1 | 478 |
5275 | 479 octave_idx_type nr = b.rows (); |
480 octave_idx_type nc = b.cols (); | |
1 | 481 |
29389
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
482 if (nr == 0 || nc == 0) |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
483 return Matrix (); |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
484 |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
485 if (nr != nc) |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
486 err_nonsquare_matrix (); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
487 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
488 EIG b_eig (b); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
489 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
490 try |
1 | 491 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
492 ComplexColumnVector lambda (b_eig.eigenvalues ()); |
22305
510886d03ef2
eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22197
diff
changeset
|
493 ComplexMatrix Q (b_eig.right_eigenvectors ()); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
494 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
495 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
|
496 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
497 Complex elt = lambda(i); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
498 if (std::imag (elt) == 0.0) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
499 lambda(i) = std::pow (a, std::real (elt)); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
500 else |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
501 lambda(i) = std::pow (a, elt); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
502 } |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
503 ComplexDiagMatrix D (lambda); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
504 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
505 retval = ComplexMatrix (Q * D * Q.inverse ()); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
506 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
507 catch (const octave::execution_exception&) |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
508 { |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
509 err_failed_diagonalization (); |
1 | 510 } |
511 | |
512 return retval; | |
513 } | |
514 | |
767 | 515 // -*- 11 -*- |
2086 | 516 octave_value |
164 | 517 xpow (const ComplexMatrix& a, double b) |
1 | 518 { |
2086 | 519 octave_value retval; |
1 | 520 |
5275 | 521 octave_idx_type nr = a.rows (); |
522 octave_idx_type nc = a.cols (); | |
1 | 523 |
29389
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
524 if (nr == 0 || nc == 0) |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
525 return Matrix (); |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
526 |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
527 if (nr != nc) |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
528 err_nonsquare_matrix (); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
529 |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
530 if (xisint (b)) |
1 | 531 { |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
532 int bint = static_cast<int> (b); |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
533 if (bint == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
534 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
535 retval = DiagMatrix (nr, nr, 1.0); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
536 } |
1 | 537 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
538 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
539 // Too much copying? |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
540 // FIXME: we shouldn't do this if the exponent is large... |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
541 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
542 ComplexMatrix atmp; |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
543 if (bint < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
544 { |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
545 bint = -bint; |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
546 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
547 octave_idx_type info; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
548 double rcond = 0.0; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
549 MatrixType mattype (a); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
550 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
551 atmp = a.inverse (mattype, info, rcond, 1); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
552 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
553 if (info == -1) |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
554 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
|
555 } |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
556 else |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
557 atmp = a; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
558 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
559 ComplexMatrix result (atmp); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
560 |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
561 bint--; |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
562 |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
563 while (bint > 0) |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
564 { |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
565 if (bint & 1) |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
566 // Use atmp * result instead of result * atmp |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
567 // for ML compatibility (bug #52706). |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
568 result = atmp * result; |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
569 |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
570 bint >>= 1; |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
571 |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
572 if (bint > 0) |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
573 atmp = atmp * atmp; |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
574 } |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
575 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
576 retval = result; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
577 } |
1567 | 578 } |
1 | 579 else |
580 { | |
581 EIG a_eig (a); | |
7578
91f8446ce4ae
handle possible error from EIG
John W. Eaton <jwe@octave.org>
parents:
7543
diff
changeset
|
582 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
583 try |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
584 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
585 ComplexColumnVector lambda (a_eig.eigenvalues ()); |
22305
510886d03ef2
eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22197
diff
changeset
|
586 ComplexMatrix Q (a_eig.right_eigenvectors ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
587 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
588 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
|
589 lambda(i) = std::pow (lambda(i), b); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
590 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
591 ComplexDiagMatrix D (lambda); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
592 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
593 retval = ComplexMatrix (Q * D * Q.inverse ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
594 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
595 catch (const octave::execution_exception&) |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
596 { |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
597 err_failed_diagonalization (); |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
598 } |
1 | 599 } |
600 | |
601 return retval; | |
602 } | |
603 | |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
604 // -*- 12 -*- |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
605 octave_value |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
606 xpow (const ComplexMatrix& a, const Complex& b) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
607 { |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
608 octave_value retval; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
609 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
610 octave_idx_type nr = a.rows (); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
611 octave_idx_type nc = a.cols (); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
612 |
29389
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
613 if (nr == 0 || nc == 0) |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
614 return Matrix (); |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
615 |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
616 if (nr != nc) |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
617 err_nonsquare_matrix (); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
618 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
619 EIG a_eig (a); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
620 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
621 try |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
622 { |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
623 ComplexColumnVector lambda (a_eig.eigenvalues ()); |
22305
510886d03ef2
eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22197
diff
changeset
|
624 ComplexMatrix Q (a_eig.right_eigenvectors ()); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
625 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
626 for (octave_idx_type i = 0; i < nr; i++) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
627 lambda(i) = std::pow (lambda(i), b); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
628 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
629 ComplexDiagMatrix D (lambda); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
630 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
631 retval = ComplexMatrix (Q * D * Q.inverse ()); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
632 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
633 catch (const octave::execution_exception&) |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
634 { |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
635 err_failed_diagonalization (); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
636 } |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
637 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
638 return retval; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
639 } |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
640 |
8382
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
641 // -*- 12d -*- |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
642 octave_value |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
643 xpow (const ComplexDiagMatrix& a, const Complex& b) |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
644 { |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
645 octave_value retval; |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
646 |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
647 octave_idx_type nr = a.rows (); |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
648 octave_idx_type nc = a.cols (); |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
649 |
29389
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
650 if (nr == 0 || nc == 0) |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
651 return Matrix (); |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
652 |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
653 if (nr != nc) |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
654 err_nonsquare_matrix (); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
655 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
656 ComplexDiagMatrix r (nr, nc); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
657 for (octave_idx_type i = 0; i < nc; i++) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
658 r(i, i) = std::pow (a(i, i), b); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
659 retval = r; |
8382
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
660 |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
661 return retval; |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
662 } |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
663 |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
664 // mixed |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
665 octave_value |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
666 xpow (const ComplexDiagMatrix& a, double b) |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
667 { |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
668 return xpow (a, static_cast<Complex> (b)); |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
669 } |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
670 |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
671 octave_value |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
672 xpow (const DiagMatrix& a, const Complex& b) |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
673 { |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
674 return xpow (ComplexDiagMatrix (a), b); |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
675 } |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
676 |
767 | 677 // Safer pow functions that work elementwise for matrices. |
678 // | |
679 // op2 \ op1: s m cs cm | |
680 // +-- +---+---+----+----+ | |
681 // scalar | | * | 3 | * | 9 | | |
682 // +---+---+----+----+ | |
683 // matrix | 1 | 4 | 7 | 10 | | |
684 // +---+---+----+----+ | |
685 // complex_scalar | * | 5 | * | 11 | | |
686 // +---+---+----+----+ | |
687 // complex_matrix | 2 | 6 | 8 | 12 | | |
688 // +---+---+----+----+ | |
689 // | |
690 // * -> not needed. | |
1 | 691 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17749
diff
changeset
|
692 // FIXME: these functions need to be fixed so that things like |
3162 | 693 // |
694 // a = -1; b = [ 0, 0.5, 1 ]; r = a .^ b | |
695 // | |
696 // and | |
697 // | |
698 // a = -1; b = [ 0, 0.5, 1 ]; for i = 1:3, r(i) = a .^ b(i), end | |
699 // | |
700 // produce identical results. Also, it would be nice if -1^0.5 | |
701 // produced a pure imaginary result instead of a complex number with a | |
702 // small real part. But perhaps that's really a problem with the math | |
703 // library... | |
704 | |
767 | 705 // -*- 1 -*- |
2086 | 706 octave_value |
164 | 707 elem_xpow (double a, const Matrix& b) |
1 | 708 { |
2086 | 709 octave_value retval; |
1 | 710 |
5275 | 711 octave_idx_type nr = b.rows (); |
712 octave_idx_type nc = b.cols (); | |
1 | 713 |
3162 | 714 double d1, d2; |
1358 | 715 |
3162 | 716 if (a < 0.0 && ! b.all_integers (d1, d2)) |
1 | 717 { |
718 Complex atmp (a); | |
719 ComplexMatrix result (nr, nc); | |
5275 | 720 |
721 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
|
722 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
|
723 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
724 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
725 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
|
726 } |
1 | 727 |
1567 | 728 retval = result; |
1 | 729 } |
730 else | |
731 { | |
732 Matrix result (nr, nc); | |
5275 | 733 |
734 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
|
735 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
|
736 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
737 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
738 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
|
739 } |
1 | 740 |
1567 | 741 retval = result; |
1 | 742 } |
743 | |
744 return retval; | |
745 } | |
746 | |
767 | 747 // -*- 2 -*- |
2086 | 748 octave_value |
164 | 749 elem_xpow (double a, const ComplexMatrix& b) |
1 | 750 { |
5275 | 751 octave_idx_type nr = b.rows (); |
752 octave_idx_type nc = b.cols (); | |
1 | 753 |
754 ComplexMatrix result (nr, nc); | |
3125 | 755 Complex atmp (a); |
5275 | 756 |
757 for (octave_idx_type j = 0; j < nc; j++) | |
758 for (octave_idx_type i = 0; i < nr; i++) | |
4153 | 759 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
760 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
761 result(i, j) = std::pow (atmp, b(i, j)); |
4153 | 762 } |
1 | 763 |
1567 | 764 return result; |
1 | 765 } |
766 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
767 static inline bool |
9123
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
768 same_sign (double a, double b) |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
769 { |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
770 return (a >= 0 && b >= 0) || (a <= 0 && b <= 0); |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
771 } |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
772 |
9103
10bed8fbec99
optimize scalar .^ range operation
Jaroslav Hajek <highegg@gmail.com>
parents:
8979
diff
changeset
|
773 octave_value |
28638
98192ec1621f
replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents:
28637
diff
changeset
|
774 elem_xpow (double a, const octave::range<double>& r) |
9103
10bed8fbec99
optimize scalar .^ range operation
Jaroslav Hajek <highegg@gmail.com>
parents:
8979
diff
changeset
|
775 { |
10bed8fbec99
optimize scalar .^ range operation
Jaroslav Hajek <highegg@gmail.com>
parents:
8979
diff
changeset
|
776 octave_value retval; |
10bed8fbec99
optimize scalar .^ range operation
Jaroslav Hajek <highegg@gmail.com>
parents:
8979
diff
changeset
|
777 |
9123
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
778 // Only optimize powers with ranges that are integer and monotonic in |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
779 // magnitude. |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
780 if (r.numel () > 1 && r.all_elements_are_ints () |
9123
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
781 && same_sign (r.base (), r.limit ())) |
9103
10bed8fbec99
optimize scalar .^ range operation
Jaroslav Hajek <highegg@gmail.com>
parents:
8979
diff
changeset
|
782 { |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
783 octave_idx_type n = r.numel (); |
9123
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
784 Matrix result (1, n); |
28636
a3db48e66ef8
use Range::increment instead of Range::inc
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
785 if (same_sign (r.base (), r.increment ())) |
9123
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
786 { |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
787 double base = std::pow (a, r.base ()); |
28636
a3db48e66ef8
use Range::increment instead of Range::inc
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
788 double inc = std::pow (a, r.increment ()); |
9123
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
789 result(0) = base; |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
790 for (octave_idx_type i = 1; i < n; i++) |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
791 result(i) = (base *= inc); |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
792 } |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
793 else |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
794 { |
28637
fb37f50d5ba8
new Range::final_value function
John W. Eaton <jwe@octave.org>
parents:
28636
diff
changeset
|
795 double limit = std::pow (a, r.final_value ()); |
28636
a3db48e66ef8
use Range::increment instead of Range::inc
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
796 double inc = std::pow (a, -r.increment ()); |
9123
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
797 result(n-1) = limit; |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
798 for (octave_idx_type i = n-2; i >= 0; i--) |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
799 result(i) = (limit *= inc); |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
800 } |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
801 |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
802 retval = result; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
803 } |
9103
10bed8fbec99
optimize scalar .^ range operation
Jaroslav Hajek <highegg@gmail.com>
parents:
8979
diff
changeset
|
804 else |
28638
98192ec1621f
replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents:
28637
diff
changeset
|
805 { |
98192ec1621f
replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents:
28637
diff
changeset
|
806 Matrix tmp = r.array_value (); |
98192ec1621f
replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents:
28637
diff
changeset
|
807 retval = elem_xpow (a, tmp); |
98192ec1621f
replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents:
28637
diff
changeset
|
808 } |
9103
10bed8fbec99
optimize scalar .^ range operation
Jaroslav Hajek <highegg@gmail.com>
parents:
8979
diff
changeset
|
809 |
10bed8fbec99
optimize scalar .^ range operation
Jaroslav Hajek <highegg@gmail.com>
parents:
8979
diff
changeset
|
810 return retval; |
10bed8fbec99
optimize scalar .^ range operation
Jaroslav Hajek <highegg@gmail.com>
parents:
8979
diff
changeset
|
811 } |
10bed8fbec99
optimize scalar .^ range operation
Jaroslav Hajek <highegg@gmail.com>
parents:
8979
diff
changeset
|
812 |
767 | 813 // -*- 3 -*- |
2086 | 814 octave_value |
164 | 815 elem_xpow (const Matrix& a, double b) |
1 | 816 { |
2086 | 817 octave_value retval; |
1 | 818 |
5275 | 819 octave_idx_type nr = a.rows (); |
820 octave_idx_type nc = a.cols (); | |
1 | 821 |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
822 if (! xisint (b) && a.any_element_is_negative ()) |
1 | 823 { |
824 ComplexMatrix result (nr, nc); | |
5275 | 825 |
826 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
|
827 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
|
828 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
829 octave_quit (); |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
830 |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
831 Complex atmp (a(i, j)); |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
832 |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
833 result(i, j) = std::pow (atmp, b); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
834 } |
1 | 835 |
1567 | 836 retval = result; |
1 | 837 } |
838 else | |
839 { | |
840 Matrix result (nr, nc); | |
5275 | 841 |
842 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
|
843 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
|
844 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
845 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
846 result(i, j) = std::pow (a(i, j), b); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
847 } |
1 | 848 |
1567 | 849 retval = result; |
1 | 850 } |
851 | |
852 return retval; | |
853 } | |
854 | |
767 | 855 // -*- 4 -*- |
2086 | 856 octave_value |
164 | 857 elem_xpow (const Matrix& a, const Matrix& b) |
1 | 858 { |
2086 | 859 octave_value retval; |
1567 | 860 |
5275 | 861 octave_idx_type nr = a.rows (); |
862 octave_idx_type nc = a.cols (); | |
2365 | 863 |
5275 | 864 octave_idx_type b_nr = b.rows (); |
865 octave_idx_type b_nc = b.cols (); | |
1 | 866 |
2365 | 867 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
|
868 octave::err_nonconformant ("operator .^", nr, nc, b_nr, b_nc); |
1 | 869 |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
870 bool convert_to_complex = false; |
5275 | 871 for (octave_idx_type j = 0; j < nc; j++) |
872 for (octave_idx_type i = 0; i < nr; i++) | |
1 | 873 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
874 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
875 double atmp = a(i, j); |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
876 double btmp = b(i, j); |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
877 if (atmp < 0.0 && ! xisint (btmp)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
878 { |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
879 convert_to_complex = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
880 goto done; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
881 } |
1 | 882 } |
883 | |
2365 | 884 done: |
1 | 885 |
886 if (convert_to_complex) | |
887 { | |
888 ComplexMatrix complex_result (nr, nc); | |
889 | |
5275 | 890 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
|
891 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
|
892 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
893 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
894 Complex atmp (a(i, j)); |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
895 Complex btmp (b(i, j)); |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
896 complex_result(i, j) = std::pow (atmp, btmp); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
897 } |
1567 | 898 |
899 retval = complex_result; | |
1 | 900 } |
901 else | |
902 { | |
903 Matrix result (nr, nc); | |
904 | |
5275 | 905 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
|
906 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
|
907 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
908 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
909 result(i, j) = std::pow (a(i, j), b(i, j)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
910 } |
1 | 911 |
1567 | 912 retval = result; |
1 | 913 } |
1567 | 914 |
915 return retval; | |
1 | 916 } |
917 | |
767 | 918 // -*- 5 -*- |
2086 | 919 octave_value |
164 | 920 elem_xpow (const Matrix& a, const Complex& b) |
1 | 921 { |
5275 | 922 octave_idx_type nr = a.rows (); |
923 octave_idx_type nc = a.cols (); | |
1 | 924 |
925 ComplexMatrix result (nr, nc); | |
5275 | 926 |
927 for (octave_idx_type j = 0; j < nc; j++) | |
928 for (octave_idx_type i = 0; i < nr; i++) | |
4153 | 929 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
930 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
931 result(i, j) = std::pow (Complex (a(i, j)), b); |
4153 | 932 } |
1 | 933 |
1567 | 934 return result; |
1 | 935 } |
936 | |
767 | 937 // -*- 6 -*- |
2086 | 938 octave_value |
164 | 939 elem_xpow (const Matrix& a, const ComplexMatrix& b) |
1 | 940 { |
5275 | 941 octave_idx_type nr = a.rows (); |
942 octave_idx_type nc = a.cols (); | |
2365 | 943 |
5275 | 944 octave_idx_type b_nr = b.rows (); |
945 octave_idx_type b_nc = b.cols (); | |
1 | 946 |
2365 | 947 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
|
948 octave::err_nonconformant ("operator .^", nr, nc, b_nr, b_nc); |
1 | 949 |
950 ComplexMatrix result (nr, nc); | |
5275 | 951 |
952 for (octave_idx_type j = 0; j < nc; j++) | |
953 for (octave_idx_type i = 0; i < nr; i++) | |
4153 | 954 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
955 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
956 result(i, j) = std::pow (Complex (a(i, j)), b(i, j)); |
4153 | 957 } |
1 | 958 |
1567 | 959 return result; |
1 | 960 } |
961 | |
767 | 962 // -*- 7 -*- |
2086 | 963 octave_value |
164 | 964 elem_xpow (const Complex& a, const Matrix& b) |
1 | 965 { |
5275 | 966 octave_idx_type nr = b.rows (); |
967 octave_idx_type nc = b.cols (); | |
1 | 968 |
969 ComplexMatrix result (nr, nc); | |
5275 | 970 |
971 for (octave_idx_type j = 0; j < nc; j++) | |
972 for (octave_idx_type i = 0; i < nr; i++) | |
1567 | 973 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
974 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
975 double btmp = b(i, j); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
976 if (xisint (btmp)) |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
977 result(i, j) = std::pow (a, static_cast<int> (btmp)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
978 else |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
979 result(i, j) = std::pow (a, btmp); |
1567 | 980 } |
1 | 981 |
1567 | 982 return result; |
1 | 983 } |
984 | |
767 | 985 // -*- 8 -*- |
2086 | 986 octave_value |
164 | 987 elem_xpow (const Complex& a, const ComplexMatrix& b) |
1 | 988 { |
5275 | 989 octave_idx_type nr = b.rows (); |
990 octave_idx_type nc = b.cols (); | |
1 | 991 |
992 ComplexMatrix result (nr, nc); | |
5275 | 993 |
994 for (octave_idx_type j = 0; j < nc; j++) | |
995 for (octave_idx_type i = 0; i < nr; i++) | |
4153 | 996 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
997 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
998 result(i, j) = std::pow (a, b(i, j)); |
4153 | 999 } |
1 | 1000 |
1567 | 1001 return result; |
1 | 1002 } |
1003 | |
9103
10bed8fbec99
optimize scalar .^ range operation
Jaroslav Hajek <highegg@gmail.com>
parents:
8979
diff
changeset
|
1004 octave_value |
28638
98192ec1621f
replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents:
28637
diff
changeset
|
1005 elem_xpow (const Complex& a, const octave::range<double>& r) |
9103
10bed8fbec99
optimize scalar .^ range operation
Jaroslav Hajek <highegg@gmail.com>
parents:
8979
diff
changeset
|
1006 { |
10bed8fbec99
optimize scalar .^ range operation
Jaroslav Hajek <highegg@gmail.com>
parents:
8979
diff
changeset
|
1007 octave_value retval; |
10bed8fbec99
optimize scalar .^ range operation
Jaroslav Hajek <highegg@gmail.com>
parents:
8979
diff
changeset
|
1008 |
9123
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
1009 // Only optimize powers with ranges that are integer and monotonic in |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
1010 // magnitude. |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
1011 if (r.numel () > 1 && r.all_elements_are_ints () |
9123
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
1012 && same_sign (r.base (), r.limit ())) |
9103
10bed8fbec99
optimize scalar .^ range operation
Jaroslav Hajek <highegg@gmail.com>
parents:
8979
diff
changeset
|
1013 { |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
1014 octave_idx_type n = r.numel (); |
9123
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
1015 ComplexMatrix result (1, n); |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
1016 |
28636
a3db48e66ef8
use Range::increment instead of Range::inc
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
1017 if (same_sign (r.base (), r.increment ())) |
9123
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
1018 { |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
1019 Complex base = std::pow (a, r.base ()); |
28636
a3db48e66ef8
use Range::increment instead of Range::inc
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
1020 Complex inc = std::pow (a, r.increment ()); |
9123
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
1021 result(0) = base; |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
1022 for (octave_idx_type i = 1; i < n; i++) |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
1023 result(i) = (base *= inc); |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
1024 } |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
1025 else |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
1026 { |
28637
fb37f50d5ba8
new Range::final_value function
John W. Eaton <jwe@octave.org>
parents:
28636
diff
changeset
|
1027 Complex limit = std::pow (a, r.final_value ()); |
28636
a3db48e66ef8
use Range::increment instead of Range::inc
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
1028 Complex inc = std::pow (a, -r.increment ()); |
9123
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
1029 result(n-1) = limit; |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
1030 for (octave_idx_type i = n-2; i >= 0; i--) |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
1031 result(i) = (limit *= inc); |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
1032 } |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
1033 |
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
1034 retval = result; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1035 } |
9123
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
1036 else |
28638
98192ec1621f
replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents:
28637
diff
changeset
|
1037 { |
98192ec1621f
replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents:
28637
diff
changeset
|
1038 Matrix tmp = r.array_value (); |
98192ec1621f
replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents:
28637
diff
changeset
|
1039 retval = elem_xpow (a, tmp); |
98192ec1621f
replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents:
28637
diff
changeset
|
1040 } |
9123
f39b98237d5c
use more robust and less aggressive scalar .^ range optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9103
diff
changeset
|
1041 |
9103
10bed8fbec99
optimize scalar .^ range operation
Jaroslav Hajek <highegg@gmail.com>
parents:
8979
diff
changeset
|
1042 return retval; |
10bed8fbec99
optimize scalar .^ range operation
Jaroslav Hajek <highegg@gmail.com>
parents:
8979
diff
changeset
|
1043 } |
10bed8fbec99
optimize scalar .^ range operation
Jaroslav Hajek <highegg@gmail.com>
parents:
8979
diff
changeset
|
1044 |
767 | 1045 // -*- 9 -*- |
2086 | 1046 octave_value |
164 | 1047 elem_xpow (const ComplexMatrix& a, double b) |
1 | 1048 { |
5275 | 1049 octave_idx_type nr = a.rows (); |
1050 octave_idx_type nc = a.cols (); | |
1 | 1051 |
1052 ComplexMatrix result (nr, nc); | |
1053 | |
1567 | 1054 if (xisint (b)) |
1055 { | |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1056 int bint = static_cast<int> (b); |
5275 | 1057 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
|
1058 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
|
1059 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1060 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1061 result(i, j) = std::pow (a(i, j), bint); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1062 } |
1567 | 1063 } |
1064 else | |
1065 { | |
5275 | 1066 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
|
1067 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
|
1068 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1069 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1070 result(i, j) = std::pow (a(i, j), b); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1071 } |
1567 | 1072 } |
1073 | |
1074 return result; | |
1 | 1075 } |
1076 | |
767 | 1077 // -*- 10 -*- |
2086 | 1078 octave_value |
164 | 1079 elem_xpow (const ComplexMatrix& a, const Matrix& b) |
1 | 1080 { |
5275 | 1081 octave_idx_type nr = a.rows (); |
1082 octave_idx_type nc = a.cols (); | |
2365 | 1083 |
5275 | 1084 octave_idx_type b_nr = b.rows (); |
1085 octave_idx_type b_nc = b.cols (); | |
1 | 1086 |
2365 | 1087 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
|
1088 octave::err_nonconformant ("operator .^", nr, nc, b_nr, b_nc); |
1 | 1089 |
1090 ComplexMatrix result (nr, nc); | |
5275 | 1091 |
1092 for (octave_idx_type j = 0; j < nc; j++) | |
1093 for (octave_idx_type i = 0; i < nr; i++) | |
1567 | 1094 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1095 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1096 double btmp = b(i, j); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1097 if (xisint (btmp)) |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1098 result(i, j) = std::pow (a(i, j), static_cast<int> (btmp)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1099 else |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1100 result(i, j) = std::pow (a(i, j), btmp); |
1567 | 1101 } |
1 | 1102 |
1567 | 1103 return result; |
1 | 1104 } |
1105 | |
767 | 1106 // -*- 11 -*- |
2086 | 1107 octave_value |
164 | 1108 elem_xpow (const ComplexMatrix& a, const Complex& b) |
1 | 1109 { |
5275 | 1110 octave_idx_type nr = a.rows (); |
1111 octave_idx_type nc = a.cols (); | |
1 | 1112 |
1113 ComplexMatrix result (nr, nc); | |
5275 | 1114 |
1115 for (octave_idx_type j = 0; j < nc; j++) | |
1116 for (octave_idx_type i = 0; i < nr; i++) | |
4153 | 1117 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1118 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1119 result(i, j) = std::pow (a(i, j), b); |
4153 | 1120 } |
1 | 1121 |
1567 | 1122 return result; |
1 | 1123 } |
1124 | |
767 | 1125 // -*- 12 -*- |
2086 | 1126 octave_value |
164 | 1127 elem_xpow (const ComplexMatrix& a, const ComplexMatrix& b) |
1 | 1128 { |
5275 | 1129 octave_idx_type nr = a.rows (); |
1130 octave_idx_type nc = a.cols (); | |
2365 | 1131 |
5275 | 1132 octave_idx_type b_nr = b.rows (); |
1133 octave_idx_type b_nc = b.cols (); | |
2365 | 1134 |
1135 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
|
1136 octave::err_nonconformant ("operator .^", nr, nc, b_nr, b_nc); |
1 | 1137 |
1138 ComplexMatrix result (nr, nc); | |
5275 | 1139 |
1140 for (octave_idx_type j = 0; j < nc; j++) | |
1141 for (octave_idx_type i = 0; i < nr; i++) | |
4153 | 1142 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1143 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1144 result(i, j) = std::pow (a(i, j), b(i, j)); |
4153 | 1145 } |
1 | 1146 |
1567 | 1147 return result; |
1 | 1148 } |
1149 | |
21014
b9d4c3615e89
maint: Capitalize D for dimension in messages and comments.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1150 // Safer pow functions that work elementwise for N-D arrays. |
4543 | 1151 // |
1152 // op2 \ op1: s nd cs cnd | |
1153 // +-- +---+---+----+----+ | |
1154 // scalar | | * | 3 | * | 9 | | |
1155 // +---+---+----+----+ | |
1156 // N_d | 1 | 4 | 7 | 10 | | |
1157 // +---+---+----+----+ | |
1158 // complex_scalar | * | 5 | * | 11 | | |
1159 // +---+---+----+----+ | |
1160 // complex_N_d | 2 | 6 | 8 | 12 | | |
1161 // +---+---+----+----+ | |
1162 // | |
1163 // * -> not needed. | |
1164 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17749
diff
changeset
|
1165 // FIXME: these functions need to be fixed so that things like |
4543 | 1166 // |
1167 // a = -1; b = [ 0, 0.5, 1 ]; r = a .^ b | |
1168 // | |
1169 // and | |
1170 // | |
1171 // a = -1; b = [ 0, 0.5, 1 ]; for i = 1:3, r(i) = a .^ b(i), end | |
1172 // | |
1173 // produce identical results. Also, it would be nice if -1^0.5 | |
1174 // produced a pure imaginary result instead of a complex number with a | |
1175 // small real part. But perhaps that's really a problem with the math | |
1176 // library... | |
1177 | |
1178 // -*- 1 -*- | |
1179 octave_value | |
1180 elem_xpow (double a, const NDArray& b) | |
1181 { | |
1182 octave_value retval; | |
1183 | |
11011
a046d03e2417
slight simplifications in xpow.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
1184 if (a < 0.0 && ! b.all_integers ()) |
4543 | 1185 { |
1186 Complex atmp (a); | |
1187 ComplexNDArray result (b.dims ()); | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
1188 for (octave_idx_type i = 0; i < b.numel (); i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1189 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1190 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1191 result(i) = std::pow (atmp, b(i)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1192 } |
4543 | 1193 |
1194 retval = result; | |
1195 } | |
1196 else | |
1197 { | |
1198 NDArray result (b.dims ()); | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
1199 for (octave_idx_type i = 0; i < b.numel (); i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1200 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1201 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1202 result(i) = std::pow (a, b(i)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1203 } |
4543 | 1204 |
1205 retval = result; | |
1206 } | |
1207 | |
1208 return retval; | |
1209 } | |
1210 | |
1211 // -*- 2 -*- | |
1212 octave_value | |
1213 elem_xpow (double a, const ComplexNDArray& b) | |
1214 { | |
1215 ComplexNDArray result (b.dims ()); | |
5275 | 1216 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
1217 for (octave_idx_type i = 0; i < b.numel (); i++) |
4543 | 1218 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
1219 octave_quit (); |
10144
1b883ce66707
avoid redundant real->complex conversions in xpow
Jaroslav Hajek <highegg@gmail.com>
parents:
10142
diff
changeset
|
1220 result(i) = std::pow (a, b(i)); |
4543 | 1221 } |
1222 | |
1223 return result; | |
1224 } | |
1225 | |
1226 // -*- 3 -*- | |
1227 octave_value | |
1228 elem_xpow (const NDArray& a, double b) | |
1229 { | |
1230 octave_value retval; | |
1231 | |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1232 if (! xisint (b)) |
4543 | 1233 { |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1234 if (a.any_element_is_negative ()) |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1235 { |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1236 ComplexNDArray result (a.dims ()); |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1237 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
1238 for (octave_idx_type i = 0; i < a.numel (); i++) |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1239 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
1240 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1241 Complex atmp (a(i)); |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1242 result(i) = std::pow (atmp, b); |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1243 } |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1244 |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1245 retval = result; |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1246 } |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1247 else |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1248 { |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1249 NDArray result (a.dims ()); |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
1250 for (octave_idx_type i = 0; i < a.numel (); i++) |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1251 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
1252 octave_quit (); |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1253 result(i) = std::pow (a(i), b); |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1254 } |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1255 |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1256 retval = result; |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1257 } |
4543 | 1258 } |
1259 else | |
1260 { | |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26376
diff
changeset
|
1261 NDArray result (a.dims ()); |
4543 | 1262 |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1263 int ib = static_cast<int> (b); |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1264 if (ib == 2) |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1265 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
1266 for (octave_idx_type i = 0; i < a.numel (); i++) |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26376
diff
changeset
|
1267 result.xelem (i) = a(i) * a(i); |
10129 | 1268 } |
1269 else if (ib == 3) | |
1270 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
1271 for (octave_idx_type i = 0; i < a.numel (); i++) |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26376
diff
changeset
|
1272 result.xelem (i) = a(i) * a(i) * a(i); |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1273 } |
8979
a7c00773a089
optimize also .^-1 case
Jaroslav Hajek <highegg@gmail.com>
parents:
8978
diff
changeset
|
1274 else if (ib == -1) |
a7c00773a089
optimize also .^-1 case
Jaroslav Hajek <highegg@gmail.com>
parents:
8978
diff
changeset
|
1275 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
1276 for (octave_idx_type i = 0; i < a.numel (); i++) |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26376
diff
changeset
|
1277 result.xelem (i) = 1.0 / a(i); |
8979
a7c00773a089
optimize also .^-1 case
Jaroslav Hajek <highegg@gmail.com>
parents:
8978
diff
changeset
|
1278 } |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1279 else |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1280 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
1281 for (octave_idx_type i = 0; i < a.numel (); i++) |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1282 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
1283 octave_quit (); |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26376
diff
changeset
|
1284 result.xelem (i) = std::pow (a(i), ib); |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1285 } |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1286 } |
4543 | 1287 |
1288 retval = result; | |
1289 } | |
1290 | |
1291 return retval; | |
1292 } | |
1293 | |
1294 // -*- 4 -*- | |
1295 octave_value | |
1296 elem_xpow (const NDArray& a, const NDArray& b) | |
1297 { | |
1298 octave_value retval; | |
1299 | |
1300 dim_vector a_dims = a.dims (); | |
1301 dim_vector b_dims = b.dims (); | |
1302 | |
1303 if (a_dims != b_dims) | |
1304 { | |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1305 if (! is_valid_bsxfun ("operator .^", a_dims, b_dims)) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1306 octave::err_nonconformant ("operator .^", a_dims, b_dims); |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1307 |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1308 // Potentially complex results |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1309 NDArray xa = octave_value_extract<NDArray> (a); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1310 NDArray xb = octave_value_extract<NDArray> (b); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1311 if (! xb.all_integers () && xa.any_element_is_negative ()) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1312 return octave_value (bsxfun_pow (ComplexNDArray (xa), xb)); |
13005
4061106b1c4b
Enable automatic bsxfun for power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
1313 else |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1314 return octave_value (bsxfun_pow (xa, xb)); |
4543 | 1315 } |
1316 | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
1317 int len = a.numel (); |
4543 | 1318 |
1319 bool convert_to_complex = false; | |
1320 | |
5275 | 1321 for (octave_idx_type i = 0; i < len; i++) |
4543 | 1322 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
1323 octave_quit (); |
4543 | 1324 double atmp = a(i); |
1325 double btmp = b(i); | |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1326 if (atmp < 0.0 && ! xisint (btmp)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1327 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1328 convert_to_complex = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1329 goto done; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1330 } |
4543 | 1331 } |
1332 | |
1333 done: | |
1334 | |
1335 if (convert_to_complex) | |
1336 { | |
1337 ComplexNDArray complex_result (a_dims); | |
1338 | |
5275 | 1339 for (octave_idx_type i = 0; i < len; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1340 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1341 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1342 Complex atmp (a(i)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1343 complex_result(i) = std::pow (atmp, b(i)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1344 } |
4543 | 1345 |
1346 retval = complex_result; | |
1347 } | |
1348 else | |
1349 { | |
1350 NDArray result (a_dims); | |
1351 | |
5275 | 1352 for (octave_idx_type i = 0; i < len; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1353 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1354 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1355 result(i) = std::pow (a(i), b(i)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1356 } |
4543 | 1357 |
1358 retval = result; | |
1359 } | |
1360 | |
1361 return retval; | |
1362 } | |
1363 | |
1364 // -*- 5 -*- | |
1365 octave_value | |
1366 elem_xpow (const NDArray& a, const Complex& b) | |
1367 { | |
1368 ComplexNDArray result (a.dims ()); | |
1369 | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
1370 for (octave_idx_type i = 0; i < a.numel (); i++) |
4543 | 1371 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
1372 octave_quit (); |
10144
1b883ce66707
avoid redundant real->complex conversions in xpow
Jaroslav Hajek <highegg@gmail.com>
parents:
10142
diff
changeset
|
1373 result(i) = std::pow (a(i), b); |
4543 | 1374 } |
1375 | |
1376 return result; | |
1377 } | |
1378 | |
1379 // -*- 6 -*- | |
1380 octave_value | |
1381 elem_xpow (const NDArray& a, const ComplexNDArray& b) | |
1382 { | |
1383 dim_vector a_dims = a.dims (); | |
1384 dim_vector b_dims = b.dims (); | |
1385 | |
1386 if (a_dims != b_dims) | |
1387 { | |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1388 if (! is_valid_bsxfun ("operator .^", a_dims, b_dims)) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1389 octave::err_nonconformant ("operator .^", a_dims, b_dims); |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1390 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1391 return bsxfun_pow (a, b); |
4543 | 1392 } |
1393 | |
1394 ComplexNDArray result (a_dims); | |
5275 | 1395 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
1396 for (octave_idx_type i = 0; i < a.numel (); i++) |
4543 | 1397 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
1398 octave_quit (); |
10144
1b883ce66707
avoid redundant real->complex conversions in xpow
Jaroslav Hajek <highegg@gmail.com>
parents:
10142
diff
changeset
|
1399 result(i) = std::pow (a(i), b(i)); |
4543 | 1400 } |
1401 | |
1402 return result; | |
1403 } | |
1404 | |
1405 // -*- 7 -*- | |
1406 octave_value | |
1407 elem_xpow (const Complex& a, const NDArray& b) | |
1408 { | |
1409 ComplexNDArray result (b.dims ()); | |
5275 | 1410 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
1411 for (octave_idx_type i = 0; i < b.numel (); i++) |
4543 | 1412 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
1413 octave_quit (); |
4543 | 1414 double btmp = b(i); |
1415 if (xisint (btmp)) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1416 result(i) = std::pow (a, static_cast<int> (btmp)); |
4543 | 1417 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1418 result(i) = std::pow (a, btmp); |
4543 | 1419 } |
1420 | |
1421 return result; | |
1422 } | |
1423 | |
1424 // -*- 8 -*- | |
1425 octave_value | |
1426 elem_xpow (const Complex& a, const ComplexNDArray& b) | |
1427 { | |
1428 ComplexNDArray result (b.dims ()); | |
5275 | 1429 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
1430 for (octave_idx_type i = 0; i < b.numel (); i++) |
4543 | 1431 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
1432 octave_quit (); |
5260 | 1433 result(i) = std::pow (a, b(i)); |
4543 | 1434 } |
1435 | |
1436 return result; | |
1437 } | |
1438 | |
1439 // -*- 9 -*- | |
1440 octave_value | |
1441 elem_xpow (const ComplexNDArray& a, double b) | |
1442 { | |
1443 ComplexNDArray result (a.dims ()); | |
1444 | |
1445 if (xisint (b)) | |
1446 { | |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1447 int bint = static_cast<int> (b); |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1448 if (bint == -1) |
8979
a7c00773a089
optimize also .^-1 case
Jaroslav Hajek <highegg@gmail.com>
parents:
8978
diff
changeset
|
1449 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
1450 for (octave_idx_type i = 0; i < a.numel (); i++) |
10144
1b883ce66707
avoid redundant real->complex conversions in xpow
Jaroslav Hajek <highegg@gmail.com>
parents:
10142
diff
changeset
|
1451 result.xelem (i) = 1.0 / a(i); |
8979
a7c00773a089
optimize also .^-1 case
Jaroslav Hajek <highegg@gmail.com>
parents:
8978
diff
changeset
|
1452 } |
a7c00773a089
optimize also .^-1 case
Jaroslav Hajek <highegg@gmail.com>
parents:
8978
diff
changeset
|
1453 else |
a7c00773a089
optimize also .^-1 case
Jaroslav Hajek <highegg@gmail.com>
parents:
8978
diff
changeset
|
1454 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
1455 for (octave_idx_type i = 0; i < a.numel (); i++) |
8979
a7c00773a089
optimize also .^-1 case
Jaroslav Hajek <highegg@gmail.com>
parents:
8978
diff
changeset
|
1456 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
1457 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1458 result(i) = std::pow (a(i), bint); |
8979
a7c00773a089
optimize also .^-1 case
Jaroslav Hajek <highegg@gmail.com>
parents:
8978
diff
changeset
|
1459 } |
a7c00773a089
optimize also .^-1 case
Jaroslav Hajek <highegg@gmail.com>
parents:
8978
diff
changeset
|
1460 } |
4543 | 1461 } |
1462 else | |
1463 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
1464 for (octave_idx_type i = 0; i < a.numel (); i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1465 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1466 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1467 result(i) = std::pow (a(i), b); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1468 } |
4543 | 1469 } |
1470 | |
1471 return result; | |
1472 } | |
1473 | |
1474 // -*- 10 -*- | |
1475 octave_value | |
1476 elem_xpow (const ComplexNDArray& a, const NDArray& b) | |
1477 { | |
1478 dim_vector a_dims = a.dims (); | |
1479 dim_vector b_dims = b.dims (); | |
1480 | |
1481 if (a_dims != b_dims) | |
1482 { | |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1483 if (! is_valid_bsxfun ("operator .^", a_dims, b_dims)) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1484 octave::err_nonconformant ("operator .^", a_dims, b_dims); |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1485 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1486 return bsxfun_pow (a, b); |
4543 | 1487 } |
1488 | |
1489 ComplexNDArray result (a_dims); | |
5275 | 1490 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
1491 for (octave_idx_type i = 0; i < a.numel (); i++) |
4543 | 1492 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
1493 octave_quit (); |
4543 | 1494 double btmp = b(i); |
1495 if (xisint (btmp)) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1496 result(i) = std::pow (a(i), static_cast<int> (btmp)); |
4543 | 1497 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1498 result(i) = std::pow (a(i), btmp); |
4543 | 1499 } |
1500 | |
1501 return result; | |
1502 } | |
1503 | |
1504 // -*- 11 -*- | |
1505 octave_value | |
1506 elem_xpow (const ComplexNDArray& a, const Complex& b) | |
1507 { | |
1508 ComplexNDArray result (a.dims ()); | |
5275 | 1509 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
1510 for (octave_idx_type i = 0; i < a.numel (); i++) |
4543 | 1511 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
1512 octave_quit (); |
5260 | 1513 result(i) = std::pow (a(i), b); |
4543 | 1514 } |
1515 | |
1516 return result; | |
1517 } | |
1518 | |
1519 // -*- 12 -*- | |
1520 octave_value | |
1521 elem_xpow (const ComplexNDArray& a, const ComplexNDArray& b) | |
1522 { | |
1523 dim_vector a_dims = a.dims (); | |
1524 dim_vector b_dims = b.dims (); | |
1525 | |
1526 if (a_dims != b_dims) | |
1527 { | |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1528 if (! is_valid_bsxfun ("operator .^", a_dims, b_dims)) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1529 octave::err_nonconformant ("operator .^", a_dims, b_dims); |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1530 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
1531 return bsxfun_pow (a, b); |
4543 | 1532 } |
1533 | |
1534 ComplexNDArray result (a_dims); | |
5275 | 1535 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
1536 for (octave_idx_type i = 0; i < a.numel (); i++) |
4543 | 1537 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
1538 octave_quit (); |
5260 | 1539 result(i) = std::pow (a(i), b(i)); |
4543 | 1540 } |
1541 | |
1542 return result; | |
1543 } | |
1544 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1545 // Safer pow functions. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1546 // |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1547 // op2 \ op1: s m cs cm |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1548 // +-- +---+---+----+----+ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1549 // scalar | | 1 | 5 | 7 | 11 | |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1550 // +---+---+----+----+ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1551 // matrix | 2 | * | 8 | * | |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1552 // +---+---+----+----+ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1553 // complex_scalar | 3 | 6 | 9 | 12 | |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1554 // +---+---+----+----+ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1555 // complex_matrix | 4 | * | 10 | * | |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1556 // +---+---+----+----+ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1557 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1558 // -*- 1 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1559 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1560 xpow (float a, float b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1561 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1562 float retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1563 |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1564 if (a < 0.0 && ! xisint (b)) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1565 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1566 FloatComplex atmp (a); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1567 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1568 return std::pow (atmp, b); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1569 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1570 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1571 retval = std::pow (a, b); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1572 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1573 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1574 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1575 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1576 // -*- 2 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1577 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1578 xpow (float a, const FloatMatrix& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1579 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1580 octave_value retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1581 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1582 octave_idx_type nr = b.rows (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1583 octave_idx_type nc = b.cols (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1584 |
29389
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1585 if (nr == 0 || nc == 0) |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1586 return FloatMatrix (); |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1587 |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1588 if (nr != nc) |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
1589 err_nonsquare_matrix (); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1590 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1591 FloatEIG b_eig (b); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1592 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1593 try |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1594 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1595 FloatComplexColumnVector lambda (b_eig.eigenvalues ()); |
22305
510886d03ef2
eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22197
diff
changeset
|
1596 FloatComplexMatrix Q (b_eig.right_eigenvectors ()); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1597 |
29803
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
1598 if (a < 0.0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1599 { |
29803
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
1600 FloatComplex acplx (a); |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
1601 for (octave_idx_type i = 0; i < nr; i++) |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
1602 { |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
1603 FloatComplex elt = lambda(i); |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
1604 if (std::imag (elt) == 0.0) |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
1605 lambda(i) = std::pow (acplx, std::real (elt)); |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
1606 else |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
1607 lambda(i) = std::pow (a, elt); |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
1608 } |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
1609 } |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
1610 else |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
1611 { |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
1612 for (octave_idx_type i = 0; i < nr; i++) |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
1613 { |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
1614 FloatComplex elt = lambda(i); |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
1615 if (std::imag (elt) == 0.0) |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
1616 lambda(i) = std::pow (a, std::real (elt)); |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
1617 else |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
1618 lambda(i) = std::pow (a, elt); |
540f25090412
Fix mpower when negative scalar base is used (bug #60786)
Rik <rik@octave.org>
parents:
29389
diff
changeset
|
1619 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1620 } |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1621 FloatComplexDiagMatrix D (lambda); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1622 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1623 FloatComplexMatrix C = Q * D * Q.inverse (); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1624 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1625 if (a > 0) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1626 retval = real (C); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1627 else |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1628 retval = C; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1629 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1630 catch (const octave::execution_exception&) |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1631 { |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
1632 err_failed_diagonalization (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1633 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1634 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1635 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1636 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1637 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1638 // -*- 3 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1639 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1640 xpow (float a, const FloatComplex& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1641 { |
10144
1b883ce66707
avoid redundant real->complex conversions in xpow
Jaroslav Hajek <highegg@gmail.com>
parents:
10142
diff
changeset
|
1642 FloatComplex result = std::pow (a, b); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1643 return result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1644 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1645 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1646 // -*- 4 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1647 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1648 xpow (float a, const FloatComplexMatrix& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1649 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1650 octave_value retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1651 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1652 octave_idx_type nr = b.rows (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1653 octave_idx_type nc = b.cols (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1654 |
29389
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1655 if (nr == 0 || nc == 0) |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1656 return FloatMatrix (); |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1657 |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1658 if (nr != nc) |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
1659 err_nonsquare_matrix (); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1660 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1661 FloatEIG b_eig (b); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1662 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1663 try |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1664 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1665 FloatComplexColumnVector lambda (b_eig.eigenvalues ()); |
22305
510886d03ef2
eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22197
diff
changeset
|
1666 FloatComplexMatrix Q (b_eig.right_eigenvectors ()); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1667 |
29816
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
1668 if (a < 0.0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1669 { |
29816
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
1670 FloatComplex acplx (a); |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
1671 for (octave_idx_type i = 0; i < nr; i++) |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
1672 { |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
1673 FloatComplex elt = lambda(i); |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
1674 if (std::imag (elt) == 0.0) |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
1675 lambda(i) = std::pow (acplx, std::real (elt)); |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
1676 else |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
1677 lambda(i) = std::pow (a, elt); |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
1678 } |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
1679 } |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
1680 else |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
1681 { |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
1682 for (octave_idx_type i = 0; i < nr; i++) |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
1683 { |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
1684 FloatComplex elt = lambda(i); |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
1685 if (std::imag (elt) == 0.0) |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
1686 lambda(i) = std::pow (a, std::real (elt)); |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
1687 else |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
1688 lambda(i) = std::pow (a, elt); |
f54cfd60725e
Fix mpower for additional cases where negative scalar base is used (bug #60786).
Rik <rik@octave.org>
parents:
29803
diff
changeset
|
1689 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1690 } |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1691 FloatComplexDiagMatrix D (lambda); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1692 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1693 retval = FloatComplexMatrix (Q * D * Q.inverse ()); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1694 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1695 catch (const octave::execution_exception&) |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1696 { |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
1697 err_failed_diagonalization (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1698 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1699 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1700 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1701 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1702 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1703 // -*- 5 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1704 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1705 xpow (const FloatMatrix& a, float b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1706 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1707 octave_value retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1708 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1709 octave_idx_type nr = a.rows (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1710 octave_idx_type nc = a.cols (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1711 |
29389
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1712 if (nr == 0 || nc == 0) |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1713 return FloatMatrix (); |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1714 |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1715 if (nr != nc) |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
1716 err_nonsquare_matrix (); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1717 |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1718 if (xisint (b)) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1719 { |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1720 int bint = static_cast<int> (b); |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1721 if (bint == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1722 { |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1723 retval = FloatDiagMatrix (nr, nr, 1.0f); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1724 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1725 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1726 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1727 // Too much copying? |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1728 // FIXME: we shouldn't do this if the exponent is large... |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1729 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1730 FloatMatrix atmp; |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1731 if (bint < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1732 { |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1733 bint = -bint; |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1734 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1735 octave_idx_type info; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1736 float rcond = 0.0; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1737 MatrixType mattype (a); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1738 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1739 atmp = a.inverse (mattype, info, rcond, 1); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1740 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1741 if (info == -1) |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1742 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
|
1743 } |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1744 else |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1745 atmp = a; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1746 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1747 FloatMatrix result (atmp); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1748 |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1749 bint--; |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1750 |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1751 while (bint > 0) |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
1752 { |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1753 if (bint & 1) |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1754 // Use atmp * result instead of result * atmp |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1755 // for ML compatibility (bug #52706). |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1756 result = atmp * result; |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1757 |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1758 bint >>= 1; |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1759 |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1760 if (bint > 0) |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1761 atmp = atmp * atmp; |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
1762 } |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1763 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1764 retval = result; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1765 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1766 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1767 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1768 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1769 FloatEIG a_eig (a); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1770 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
1771 try |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1772 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1773 FloatComplexColumnVector lambda (a_eig.eigenvalues ()); |
22305
510886d03ef2
eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22197
diff
changeset
|
1774 FloatComplexMatrix Q (a_eig.right_eigenvectors ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1775 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1776 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
|
1777 lambda(i) = std::pow (lambda(i), b); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1778 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1779 FloatComplexDiagMatrix D (lambda); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1780 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1781 retval = FloatComplexMatrix (Q * D * Q.inverse ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1782 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1783 catch (const octave::execution_exception&) |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
1784 { |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
1785 err_failed_diagonalization (); |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
1786 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1787 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1788 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1789 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1790 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1791 |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1792 // -*- 5d -*- |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1793 octave_value |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1794 xpow (const FloatDiagMatrix& a, float b) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1795 { |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1796 octave_value retval; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1797 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1798 octave_idx_type nr = a.rows (); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1799 octave_idx_type nc = a.cols (); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1800 |
29389
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1801 if (nr == 0 || nc == 0) |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1802 return FloatMatrix (); |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1803 |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1804 if (nr != nc) |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
1805 err_nonsquare_matrix (); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1806 |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1807 if (xisint (b)) |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1808 { |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1809 FloatDiagMatrix r (nr, nc); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1810 for (octave_idx_type i = 0; i < nc; i++) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1811 r.dgelem (i) = std::pow (a.dgelem (i), b); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1812 retval = r; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1813 } |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1814 else |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1815 { |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1816 FloatComplexDiagMatrix r (nr, nc); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1817 for (octave_idx_type i = 0; i < nc; i++) |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1818 r.dgelem (i) = std::pow (static_cast<FloatComplex> (a.dgelem (i)), b); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1819 retval = r; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1820 } |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1821 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1822 return retval; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1823 } |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1824 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1825 // -*- 6 -*- |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1826 octave_value |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1827 xpow (const FloatMatrix& a, const FloatComplex& b) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1828 { |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1829 octave_value retval; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1830 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1831 octave_idx_type nr = a.rows (); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1832 octave_idx_type nc = a.cols (); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1833 |
29389
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1834 if (nr == 0 || nc == 0) |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1835 return FloatMatrix (); |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1836 |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1837 if (nr != nc) |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
1838 err_nonsquare_matrix (); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1839 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1840 FloatEIG a_eig (a); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1841 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1842 try |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1843 { |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1844 FloatComplexColumnVector lambda (a_eig.eigenvalues ()); |
22305
510886d03ef2
eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22197
diff
changeset
|
1845 FloatComplexMatrix Q (a_eig.right_eigenvectors ()); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1846 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1847 for (octave_idx_type i = 0; i < nr; i++) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1848 lambda(i) = std::pow (lambda(i), b); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1849 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1850 FloatComplexDiagMatrix D (lambda); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1851 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1852 retval = FloatComplexMatrix (Q * D * Q.inverse ()); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1853 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1854 catch (const octave::execution_exception&) |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1855 { |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
1856 err_failed_diagonalization (); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1857 } |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1858 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1859 return retval; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1860 } |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1861 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1862 // -*- 7 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1863 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1864 xpow (const FloatComplex& a, float b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1865 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1866 FloatComplex result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1867 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1868 if (xisint (b)) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1869 result = std::pow (a, static_cast<int> (b)); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1870 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1871 result = std::pow (a, b); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1872 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1873 return result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1874 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1875 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1876 // -*- 8 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1877 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1878 xpow (const FloatComplex& a, const FloatMatrix& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1879 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1880 octave_value retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1881 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1882 octave_idx_type nr = b.rows (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1883 octave_idx_type nc = b.cols (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1884 |
29389
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1885 if (nr == 0 || nc == 0) |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1886 return FloatMatrix (); |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1887 |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1888 if (nr != nc) |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
1889 err_nonsquare_matrix (); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1890 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1891 FloatEIG b_eig (b); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1892 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1893 try |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1894 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1895 FloatComplexColumnVector lambda (b_eig.eigenvalues ()); |
22305
510886d03ef2
eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22197
diff
changeset
|
1896 FloatComplexMatrix Q (b_eig.right_eigenvectors ()); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1897 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1898 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
|
1899 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1900 FloatComplex elt = lambda(i); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1901 if (std::imag (elt) == 0.0) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1902 lambda(i) = std::pow (a, std::real (elt)); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1903 else |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1904 lambda(i) = std::pow (a, elt); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1905 } |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1906 FloatComplexDiagMatrix D (lambda); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1907 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1908 retval = FloatComplexMatrix (Q * D * Q.inverse ()); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1909 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1910 catch (const octave::execution_exception&) |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1911 { |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
1912 err_failed_diagonalization (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1913 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1914 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1915 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1916 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1917 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1918 // -*- 9 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1919 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1920 xpow (const FloatComplex& a, const FloatComplex& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1921 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1922 FloatComplex result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1923 result = std::pow (a, b); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1924 return result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1925 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1926 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1927 // -*- 10 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1928 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1929 xpow (const FloatComplex& a, const FloatComplexMatrix& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1930 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1931 octave_value retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1932 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1933 octave_idx_type nr = b.rows (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1934 octave_idx_type nc = b.cols (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1935 |
29389
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1936 if (nr == 0 || nc == 0) |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1937 return FloatMatrix (); |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1938 |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1939 if (nr != nc) |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
1940 err_nonsquare_matrix (); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1941 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1942 FloatEIG b_eig (b); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1943 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1944 try |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1945 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1946 FloatComplexColumnVector lambda (b_eig.eigenvalues ()); |
22305
510886d03ef2
eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22197
diff
changeset
|
1947 FloatComplexMatrix Q (b_eig.right_eigenvectors ()); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1948 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1949 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
|
1950 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1951 FloatComplex elt = lambda(i); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1952 if (std::imag (elt) == 0.0) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1953 lambda(i) = std::pow (a, std::real (elt)); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1954 else |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1955 lambda(i) = std::pow (a, elt); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1956 } |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1957 FloatComplexDiagMatrix D (lambda); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1958 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1959 retval = FloatComplexMatrix (Q * D * Q.inverse ()); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1960 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1961 catch (const octave::execution_exception&) |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1962 { |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
1963 err_failed_diagonalization (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1964 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1965 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1966 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1967 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1968 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1969 // -*- 11 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1970 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1971 xpow (const FloatComplexMatrix& a, float b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1972 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1973 octave_value retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1974 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1975 octave_idx_type nr = a.rows (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1976 octave_idx_type nc = a.cols (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1977 |
29389
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1978 if (nr == 0 || nc == 0) |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1979 return FloatMatrix (); |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1980 |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
1981 if (nr != nc) |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
1982 err_nonsquare_matrix (); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1983 |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1984 if (xisint (b)) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1985 { |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1986 int bint = static_cast<int> (b); |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1987 if (bint == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1988 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1989 retval = FloatDiagMatrix (nr, nr, 1.0); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1990 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
1991 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1992 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1993 // Too much copying? |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1994 // FIXME: we shouldn't do this if the exponent is large... |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1995 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
1996 FloatComplexMatrix atmp; |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1997 if (bint < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1998 { |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
1999 bint = -bint; |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2000 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2001 octave_idx_type info; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2002 float rcond = 0.0; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2003 MatrixType mattype (a); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2004 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2005 atmp = a.inverse (mattype, info, rcond, 1); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2006 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2007 if (info == -1) |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2008 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
|
2009 } |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2010 else |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2011 atmp = a; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2012 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2013 FloatComplexMatrix result (atmp); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2014 |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2015 bint--; |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2016 |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2017 while (bint > 0) |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
2018 { |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2019 if (bint & 1) |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2020 // Use atmp * result instead of result * atmp |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2021 // for ML compatibility (bug #52706). |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2022 result = atmp * result; |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2023 |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2024 bint >>= 1; |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2025 |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2026 if (bint > 0) |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2027 atmp = atmp * atmp; |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
2028 } |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2029 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2030 retval = result; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2031 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2032 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2033 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2034 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2035 FloatEIG a_eig (a); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2036 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
2037 try |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2038 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2039 FloatComplexColumnVector lambda (a_eig.eigenvalues ()); |
22305
510886d03ef2
eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22197
diff
changeset
|
2040 FloatComplexMatrix Q (a_eig.right_eigenvectors ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2041 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2042 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
|
2043 lambda(i) = std::pow (lambda(i), b); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2044 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2045 FloatComplexDiagMatrix D (lambda); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2046 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2047 retval = FloatComplexMatrix (Q * D * Q.inverse ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2048 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2049 catch (const octave::execution_exception&) |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
2050 { |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
2051 err_failed_diagonalization (); |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
2052 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2053 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2054 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2055 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2056 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2057 |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2058 // -*- 12 -*- |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2059 octave_value |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2060 xpow (const FloatComplexMatrix& a, const FloatComplex& b) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2061 { |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2062 octave_value retval; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2063 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2064 octave_idx_type nr = a.rows (); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2065 octave_idx_type nc = a.cols (); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2066 |
29389
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
2067 if (nr == 0 || nc == 0) |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
2068 return FloatMatrix (); |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
2069 |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
2070 if (nr != nc) |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
2071 err_nonsquare_matrix (); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2072 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2073 FloatEIG a_eig (a); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2074 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2075 try |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2076 { |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2077 FloatComplexColumnVector lambda (a_eig.eigenvalues ()); |
22305
510886d03ef2
eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22197
diff
changeset
|
2078 FloatComplexMatrix Q (a_eig.right_eigenvectors ()); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2079 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2080 for (octave_idx_type i = 0; i < nr; i++) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2081 lambda(i) = std::pow (lambda(i), b); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2082 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2083 FloatComplexDiagMatrix D (lambda); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2084 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2085 retval = FloatComplexMatrix (Q * D * Q.inverse ()); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2086 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2087 catch (const octave::execution_exception&) |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2088 { |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
2089 err_failed_diagonalization (); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2090 } |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2091 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2092 return retval; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2093 } |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2094 |
8382
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2095 // -*- 12d -*- |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2096 octave_value |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2097 xpow (const FloatComplexDiagMatrix& a, const FloatComplex& b) |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2098 { |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2099 octave_value retval; |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2100 |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2101 octave_idx_type nr = a.rows (); |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2102 octave_idx_type nc = a.cols (); |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2103 |
29389
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
2104 if (nr == 0 || nc == 0) |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
2105 return FloatMatrix (); |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
2106 |
85998370816a
Return empty matrix when using an empty matrix as base or exponent in '^' operator (bug #68006).
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
2107 if (nr != nc) |
21161
4c54a269ad44
xpow.cc: Use local err_XXX routines to simplify code.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
2108 err_nonsquare_matrix (); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2109 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2110 FloatComplexDiagMatrix r (nr, nc); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2111 for (octave_idx_type i = 0; i < nc; i++) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2112 r(i, i) = std::pow (a(i, i), b); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
2113 retval = r; |
8382
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2114 |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2115 return retval; |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2116 } |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2117 |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2118 // mixed |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2119 octave_value |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2120 xpow (const FloatComplexDiagMatrix& a, float b) |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2121 { |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2122 return xpow (a, static_cast<FloatComplex> (b)); |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2123 } |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2124 |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2125 octave_value |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2126 xpow (const FloatDiagMatrix& a, const FloatComplex& b) |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2127 { |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2128 return xpow (FloatComplexDiagMatrix (a), b); |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2129 } |
9b20a4847056
implement scalar powers of diag matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2130 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2131 // Safer pow functions that work elementwise for matrices. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2132 // |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2133 // op2 \ op1: s m cs cm |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2134 // +-- +---+---+----+----+ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2135 // scalar | | * | 3 | * | 9 | |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2136 // +---+---+----+----+ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2137 // matrix | 1 | 4 | 7 | 10 | |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2138 // +---+---+----+----+ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2139 // complex_scalar | * | 5 | * | 11 | |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2140 // +---+---+----+----+ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2141 // complex_matrix | 2 | 6 | 8 | 12 | |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2142 // +---+---+----+----+ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2143 // |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2144 // * -> not needed. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2145 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17749
diff
changeset
|
2146 // FIXME: these functions need to be fixed so that things like |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2147 // |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2148 // a = -1; b = [ 0, 0.5, 1 ]; r = a .^ b |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2149 // |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2150 // and |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2151 // |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2152 // a = -1; b = [ 0, 0.5, 1 ]; for i = 1:3, r(i) = a .^ b(i), end |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2153 // |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2154 // produce identical results. Also, it would be nice if -1^0.5 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2155 // produced a pure imaginary result instead of a complex number with a |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2156 // small real part. But perhaps that's really a problem with the math |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2157 // library... |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2158 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2159 // -*- 1 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2160 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2161 elem_xpow (float a, const FloatMatrix& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2162 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2163 octave_value retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2164 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2165 octave_idx_type nr = b.rows (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2166 octave_idx_type nc = b.cols (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2167 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2168 float d1, d2; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2169 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2170 if (a < 0.0 && ! b.all_integers (d1, d2)) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2171 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2172 FloatComplex atmp (a); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2173 FloatComplexMatrix result (nr, nc); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2174 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2175 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
|
2176 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
|
2177 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2178 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2179 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
|
2180 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2181 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2182 retval = result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2183 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2184 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2185 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2186 FloatMatrix result (nr, nc); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2187 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2188 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
|
2189 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
|
2190 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2191 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2192 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
|
2193 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2194 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2195 retval = result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2196 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2197 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2198 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2199 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2200 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2201 // -*- 2 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2202 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2203 elem_xpow (float a, const FloatComplexMatrix& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2204 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2205 octave_idx_type nr = b.rows (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2206 octave_idx_type nc = b.cols (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2207 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2208 FloatComplexMatrix result (nr, nc); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2209 FloatComplex atmp (a); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2210 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2211 for (octave_idx_type j = 0; j < nc; j++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2212 for (octave_idx_type i = 0; i < nr; i++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2213 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2214 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2215 result(i, j) = std::pow (atmp, b(i, j)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2216 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2217 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2218 return result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2219 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2220 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2221 // -*- 3 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2222 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2223 elem_xpow (const FloatMatrix& a, float b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2224 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2225 octave_value retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2226 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2227 octave_idx_type nr = a.rows (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2228 octave_idx_type nc = a.cols (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2229 |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2230 if (! xisint (b) && a.any_element_is_negative ()) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2231 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2232 FloatComplexMatrix result (nr, nc); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2233 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2234 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
|
2235 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
|
2236 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2237 octave_quit (); |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2238 |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2239 FloatComplex atmp (a(i, j)); |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2240 |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2241 result(i, j) = std::pow (atmp, b); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2242 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2243 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2244 retval = result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2245 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2246 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2247 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2248 FloatMatrix result (nr, nc); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2249 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2250 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
|
2251 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
|
2252 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2253 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2254 result(i, j) = std::pow (a(i, j), b); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2255 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2256 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2257 retval = result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2258 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2259 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2260 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2261 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2262 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2263 // -*- 4 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2264 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2265 elem_xpow (const FloatMatrix& a, const FloatMatrix& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2266 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2267 octave_value retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2268 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2269 octave_idx_type nr = a.rows (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2270 octave_idx_type nc = a.cols (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2271 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2272 octave_idx_type b_nr = b.rows (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2273 octave_idx_type b_nc = b.cols (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2274 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2275 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
|
2276 octave::err_nonconformant ("operator .^", nr, nc, b_nr, b_nc); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2277 |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2278 bool convert_to_complex = false; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2279 for (octave_idx_type j = 0; j < nc; j++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2280 for (octave_idx_type i = 0; i < nr; i++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2281 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2282 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2283 float atmp = a(i, j); |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2284 float btmp = b(i, j); |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2285 if (atmp < 0.0 && ! xisint (btmp)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2286 { |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2287 convert_to_complex = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2288 goto done; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2289 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2290 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2291 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2292 done: |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2293 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2294 if (convert_to_complex) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2295 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2296 FloatComplexMatrix complex_result (nr, nc); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2297 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2298 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
|
2299 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
|
2300 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2301 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2302 FloatComplex atmp (a(i, j)); |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2303 FloatComplex btmp (b(i, j)); |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2304 complex_result(i, j) = std::pow (atmp, btmp); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2305 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2306 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2307 retval = complex_result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2308 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2309 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2310 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2311 FloatMatrix result (nr, nc); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2312 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2313 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
|
2314 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
|
2315 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2316 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2317 result(i, j) = std::pow (a(i, j), b(i, j)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2318 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2319 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2320 retval = result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2321 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2322 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2323 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2324 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2325 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2326 // -*- 5 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2327 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2328 elem_xpow (const FloatMatrix& a, const FloatComplex& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2329 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2330 octave_idx_type nr = a.rows (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2331 octave_idx_type nc = a.cols (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2332 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2333 FloatComplexMatrix result (nr, nc); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2334 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2335 for (octave_idx_type j = 0; j < nc; j++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2336 for (octave_idx_type i = 0; i < nr; i++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2337 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2338 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2339 result(i, j) = std::pow (FloatComplex (a(i, j)), b); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2340 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2341 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2342 return result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2343 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2344 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2345 // -*- 6 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2346 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2347 elem_xpow (const FloatMatrix& a, const FloatComplexMatrix& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2348 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2349 octave_idx_type nr = a.rows (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2350 octave_idx_type nc = a.cols (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2351 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2352 octave_idx_type b_nr = b.rows (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2353 octave_idx_type b_nc = b.cols (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2354 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2355 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
|
2356 octave::err_nonconformant ("operator .^", nr, nc, b_nr, b_nc); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2357 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2358 FloatComplexMatrix result (nr, nc); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2359 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2360 for (octave_idx_type j = 0; j < nc; j++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2361 for (octave_idx_type i = 0; i < nr; i++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2362 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2363 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2364 result(i, j) = std::pow (FloatComplex (a(i, j)), b(i, j)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2365 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2366 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2367 return result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2368 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2369 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2370 // -*- 7 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2371 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2372 elem_xpow (const FloatComplex& a, const FloatMatrix& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2373 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2374 octave_idx_type nr = b.rows (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2375 octave_idx_type nc = b.cols (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2376 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2377 FloatComplexMatrix result (nr, nc); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2378 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2379 for (octave_idx_type j = 0; j < nc; j++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2380 for (octave_idx_type i = 0; i < nr; i++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2381 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2382 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2383 float btmp = b(i, j); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2384 if (xisint (btmp)) |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2385 result(i, j) = std::pow (a, static_cast<int> (btmp)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2386 else |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2387 result(i, j) = std::pow (a, btmp); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2388 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2389 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2390 return result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2391 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2392 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2393 // -*- 8 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2394 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2395 elem_xpow (const FloatComplex& a, const FloatComplexMatrix& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2396 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2397 octave_idx_type nr = b.rows (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2398 octave_idx_type nc = b.cols (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2399 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2400 FloatComplexMatrix result (nr, nc); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2401 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2402 for (octave_idx_type j = 0; j < nc; j++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2403 for (octave_idx_type i = 0; i < nr; i++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2404 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2405 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2406 result(i, j) = std::pow (a, b(i, j)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2407 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2408 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2409 return result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2410 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2411 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2412 // -*- 9 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2413 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2414 elem_xpow (const FloatComplexMatrix& a, float b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2415 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2416 octave_idx_type nr = a.rows (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2417 octave_idx_type nc = a.cols (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2418 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2419 FloatComplexMatrix result (nr, nc); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2420 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2421 if (xisint (b)) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2422 { |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2423 int bint = static_cast<int> (b); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2424 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
|
2425 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
|
2426 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2427 octave_quit (); |
24527
abd196490ed3
Fix unused variable warning in xpow.cc.
Rik <rik@octave.org>
parents:
24453
diff
changeset
|
2428 result(i, j) = std::pow (a(i, j), bint); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2429 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2430 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2431 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2432 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2433 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
|
2434 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
|
2435 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2436 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2437 result(i, j) = std::pow (a(i, j), b); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2438 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2439 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2440 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2441 return result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2442 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2443 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2444 // -*- 10 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2445 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2446 elem_xpow (const FloatComplexMatrix& a, const FloatMatrix& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2447 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2448 octave_idx_type nr = a.rows (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2449 octave_idx_type nc = a.cols (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2450 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2451 octave_idx_type b_nr = b.rows (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2452 octave_idx_type b_nc = b.cols (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2453 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2454 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
|
2455 octave::err_nonconformant ("operator .^", nr, nc, b_nr, b_nc); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2456 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2457 FloatComplexMatrix result (nr, nc); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2458 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2459 for (octave_idx_type j = 0; j < nc; j++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2460 for (octave_idx_type i = 0; i < nr; i++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2461 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2462 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2463 float btmp = b(i, j); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2464 if (xisint (btmp)) |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2465 result(i, j) = std::pow (a(i, j), static_cast<int> (btmp)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2466 else |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2467 result(i, j) = std::pow (a(i, j), btmp); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2468 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2469 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2470 return result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2471 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2472 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2473 // -*- 11 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2474 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2475 elem_xpow (const FloatComplexMatrix& a, const FloatComplex& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2476 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2477 octave_idx_type nr = a.rows (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2478 octave_idx_type nc = a.cols (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2479 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2480 FloatComplexMatrix result (nr, nc); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2481 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2482 for (octave_idx_type j = 0; j < nc; j++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2483 for (octave_idx_type i = 0; i < nr; i++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2484 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2485 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2486 result(i, j) = std::pow (a(i, j), b); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2487 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2488 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2489 return result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2490 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2491 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2492 // -*- 12 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2493 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2494 elem_xpow (const FloatComplexMatrix& a, const FloatComplexMatrix& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2495 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2496 octave_idx_type nr = a.rows (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2497 octave_idx_type nc = a.cols (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2498 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2499 octave_idx_type b_nr = b.rows (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2500 octave_idx_type b_nc = b.cols (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2501 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2502 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
|
2503 octave::err_nonconformant ("operator .^", nr, nc, b_nr, b_nc); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2504 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2505 FloatComplexMatrix result (nr, nc); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2506 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2507 for (octave_idx_type j = 0; j < nc; j++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2508 for (octave_idx_type i = 0; i < nr; i++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2509 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2510 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2511 result(i, j) = std::pow (a(i, j), b(i, j)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2512 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2513 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2514 return result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2515 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2516 |
21014
b9d4c3615e89
maint: Capitalize D for dimension in messages and comments.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
2517 // Safer pow functions that work elementwise for N-D arrays. |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2518 // |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2519 // op2 \ op1: s nd cs cnd |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2520 // +-- +---+---+----+----+ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2521 // scalar | | * | 3 | * | 9 | |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2522 // +---+---+----+----+ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2523 // N_d | 1 | 4 | 7 | 10 | |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2524 // +---+---+----+----+ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2525 // complex_scalar | * | 5 | * | 11 | |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2526 // +---+---+----+----+ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2527 // complex_N_d | 2 | 6 | 8 | 12 | |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2528 // +---+---+----+----+ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2529 // |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2530 // * -> not needed. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2531 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17749
diff
changeset
|
2532 // FIXME: these functions need to be fixed so that things like |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2533 // |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2534 // a = -1; b = [ 0, 0.5, 1 ]; r = a .^ b |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2535 // |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2536 // and |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2537 // |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2538 // a = -1; b = [ 0, 0.5, 1 ]; for i = 1:3, r(i) = a .^ b(i), end |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2539 // |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2540 // produce identical results. Also, it would be nice if -1^0.5 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2541 // produced a pure imaginary result instead of a complex number with a |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2542 // small real part. But perhaps that's really a problem with the math |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2543 // library... |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2544 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2545 // -*- 1 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2546 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2547 elem_xpow (float a, const FloatNDArray& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2548 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2549 octave_value retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2550 |
11011
a046d03e2417
slight simplifications in xpow.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
2551 if (a < 0.0 && ! b.all_integers ()) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2552 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2553 FloatComplex atmp (a); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2554 FloatComplexNDArray result (b.dims ()); |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
2555 for (octave_idx_type i = 0; i < b.numel (); i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2556 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2557 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2558 result(i) = std::pow (atmp, b(i)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2559 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2560 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2561 retval = result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2562 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2563 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2564 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2565 FloatNDArray result (b.dims ()); |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
2566 for (octave_idx_type i = 0; i < b.numel (); i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2567 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2568 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2569 result(i) = std::pow (a, b(i)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2570 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2571 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2572 retval = result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2573 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2574 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2575 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2576 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2577 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2578 // -*- 2 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2579 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2580 elem_xpow (float a, const FloatComplexNDArray& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2581 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2582 FloatComplexNDArray result (b.dims ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2583 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
2584 for (octave_idx_type i = 0; i < b.numel (); i++) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2585 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
2586 octave_quit (); |
10144
1b883ce66707
avoid redundant real->complex conversions in xpow
Jaroslav Hajek <highegg@gmail.com>
parents:
10142
diff
changeset
|
2587 result(i) = std::pow (a, b(i)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2588 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2589 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2590 return result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2591 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2592 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2593 // -*- 3 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2594 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2595 elem_xpow (const FloatNDArray& a, float b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2596 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2597 octave_value retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2598 |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2599 if (! xisint (b)) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2600 { |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2601 if (a.any_element_is_negative ()) |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2602 { |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2603 FloatComplexNDArray result (a.dims ()); |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2604 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
2605 for (octave_idx_type i = 0; i < a.numel (); i++) |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2606 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
2607 octave_quit (); |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2608 |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2609 FloatComplex atmp (a(i)); |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2610 |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2611 result(i) = std::pow (atmp, b); |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2612 } |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2613 |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2614 retval = result; |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2615 } |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2616 else |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2617 { |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2618 FloatNDArray result (a.dims ()); |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
2619 for (octave_idx_type i = 0; i < a.numel (); i++) |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2620 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
2621 octave_quit (); |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2622 result(i) = std::pow (a(i), b); |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2623 } |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2624 |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2625 retval = result; |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2626 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2627 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2628 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2629 { |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26376
diff
changeset
|
2630 FloatNDArray result (a.dims ()); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2631 |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2632 int ib = static_cast<int> (b); |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2633 if (ib == 2) |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2634 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
2635 for (octave_idx_type i = 0; i < a.numel (); i++) |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26376
diff
changeset
|
2636 result.xelem (i) = a(i) * a(i); |
10129 | 2637 } |
2638 else if (ib == 3) | |
2639 { | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
2640 for (octave_idx_type i = 0; i < a.numel (); i++) |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26376
diff
changeset
|
2641 result.xelem (i) = a(i) * a(i) * a(i); |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2642 } |
8979
a7c00773a089
optimize also .^-1 case
Jaroslav Hajek <highegg@gmail.com>
parents:
8978
diff
changeset
|
2643 else if (ib == -1) |
a7c00773a089
optimize also .^-1 case
Jaroslav Hajek <highegg@gmail.com>
parents:
8978
diff
changeset
|
2644 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
2645 for (octave_idx_type i = 0; i < a.numel (); i++) |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26376
diff
changeset
|
2646 result.xelem (i) = 1.0f / a(i); |
8979
a7c00773a089
optimize also .^-1 case
Jaroslav Hajek <highegg@gmail.com>
parents:
8978
diff
changeset
|
2647 } |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2648 else |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2649 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
2650 for (octave_idx_type i = 0; i < a.numel (); i++) |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2651 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
2652 octave_quit (); |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
26376
diff
changeset
|
2653 result.xelem (i) = std::pow (a(i), ib); |
8978
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2654 } |
0a58c4cd1405
optimize element-wise power
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2655 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2656 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2657 retval = result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2658 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2659 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2660 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2661 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2662 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2663 // -*- 4 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2664 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2665 elem_xpow (const FloatNDArray& a, const FloatNDArray& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2666 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2667 octave_value retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2668 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2669 dim_vector a_dims = a.dims (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2670 dim_vector b_dims = b.dims (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2671 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2672 if (a_dims != b_dims) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2673 { |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
2674 if (! is_valid_bsxfun ("operator .^", a_dims, b_dims)) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2675 octave::err_nonconformant ("operator .^", a_dims, b_dims); |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
2676 |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2677 // Potentially complex results |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
2678 FloatNDArray xa = octave_value_extract<FloatNDArray> (a); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
2679 FloatNDArray xb = octave_value_extract<FloatNDArray> (b); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
2680 if (! xb.all_integers () && xa.any_element_is_negative ()) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
2681 return octave_value (bsxfun_pow (FloatComplexNDArray (xa), xb)); |
13012
15eefbd9d4e8
Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
13005
diff
changeset
|
2682 else |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
2683 return octave_value (bsxfun_pow (xa, xb)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2684 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2685 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
2686 int len = a.numel (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2687 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2688 bool convert_to_complex = false; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2689 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2690 for (octave_idx_type i = 0; i < len; i++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2691 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
2692 octave_quit (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2693 float atmp = a(i); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2694 float btmp = b(i); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2695 if (atmp < 0.0 && ! xisint (btmp)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2696 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2697 convert_to_complex = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2698 goto done; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2699 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2700 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2701 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2702 done: |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2703 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2704 if (convert_to_complex) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2705 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2706 FloatComplexNDArray complex_result (a_dims); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2707 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2708 for (octave_idx_type i = 0; i < len; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2709 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2710 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2711 FloatComplex atmp (a(i)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2712 complex_result(i) = std::pow (atmp, b(i)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2713 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2714 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2715 retval = complex_result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2716 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2717 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2718 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2719 FloatNDArray result (a_dims); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2720 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2721 for (octave_idx_type i = 0; i < len; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2722 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2723 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2724 result(i) = std::pow (a(i), b(i)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2725 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2726 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2727 retval = result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2728 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2729 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2730 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2731 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2732 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2733 // -*- 5 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2734 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2735 elem_xpow (const FloatNDArray& a, const FloatComplex& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2736 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2737 FloatComplexNDArray result (a.dims ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2738 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
2739 for (octave_idx_type i = 0; i < a.numel (); i++) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2740 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
2741 octave_quit (); |
10144
1b883ce66707
avoid redundant real->complex conversions in xpow
Jaroslav Hajek <highegg@gmail.com>
parents:
10142
diff
changeset
|
2742 result(i) = std::pow (a(i), b); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2743 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2744 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2745 return result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2746 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2747 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2748 // -*- 6 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2749 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2750 elem_xpow (const FloatNDArray& a, const FloatComplexNDArray& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2751 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2752 dim_vector a_dims = a.dims (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2753 dim_vector b_dims = b.dims (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2754 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2755 if (a_dims != b_dims) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2756 { |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
2757 if (! is_valid_bsxfun ("operator .^", a_dims, b_dims)) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2758 octave::err_nonconformant ("operator .^", a_dims, b_dims); |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
2759 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
2760 return bsxfun_pow (a, b); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2761 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2762 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2763 FloatComplexNDArray result (a_dims); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2764 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
2765 for (octave_idx_type i = 0; i < a.numel (); i++) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2766 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
2767 octave_quit (); |
10144
1b883ce66707
avoid redundant real->complex conversions in xpow
Jaroslav Hajek <highegg@gmail.com>
parents:
10142
diff
changeset
|
2768 result(i) = std::pow (a(i), b(i)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2769 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2770 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2771 return result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2772 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2773 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2774 // -*- 7 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2775 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2776 elem_xpow (const FloatComplex& a, const FloatNDArray& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2777 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2778 FloatComplexNDArray result (b.dims ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2779 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
2780 for (octave_idx_type i = 0; i < b.numel (); i++) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2781 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
2782 octave_quit (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2783 float btmp = b(i); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2784 if (xisint (btmp)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2785 result(i) = std::pow (a, static_cast<int> (btmp)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2786 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2787 result(i) = std::pow (a, btmp); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2788 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2789 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2790 return result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2791 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2792 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2793 // -*- 8 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2794 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2795 elem_xpow (const FloatComplex& a, const FloatComplexNDArray& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2796 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2797 FloatComplexNDArray result (b.dims ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2798 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
2799 for (octave_idx_type i = 0; i < b.numel (); i++) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2800 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
2801 octave_quit (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2802 result(i) = std::pow (a, b(i)); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2803 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2804 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2805 return result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2806 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2807 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2808 // -*- 9 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2809 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2810 elem_xpow (const FloatComplexNDArray& a, float b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2811 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2812 FloatComplexNDArray result (a.dims ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2813 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2814 if (xisint (b)) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2815 { |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2816 int bint = static_cast<int> (b); |
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2817 if (bint == -1) |
8979
a7c00773a089
optimize also .^-1 case
Jaroslav Hajek <highegg@gmail.com>
parents:
8978
diff
changeset
|
2818 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
2819 for (octave_idx_type i = 0; i < a.numel (); i++) |
10144
1b883ce66707
avoid redundant real->complex conversions in xpow
Jaroslav Hajek <highegg@gmail.com>
parents:
10142
diff
changeset
|
2820 result.xelem (i) = 1.0f / a(i); |
8979
a7c00773a089
optimize also .^-1 case
Jaroslav Hajek <highegg@gmail.com>
parents:
8978
diff
changeset
|
2821 } |
a7c00773a089
optimize also .^-1 case
Jaroslav Hajek <highegg@gmail.com>
parents:
8978
diff
changeset
|
2822 else |
a7c00773a089
optimize also .^-1 case
Jaroslav Hajek <highegg@gmail.com>
parents:
8978
diff
changeset
|
2823 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
2824 for (octave_idx_type i = 0; i < a.numel (); i++) |
8979
a7c00773a089
optimize also .^-1 case
Jaroslav Hajek <highegg@gmail.com>
parents:
8978
diff
changeset
|
2825 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
2826 octave_quit (); |
24453
4827cbef0949
Change matrix multiplication order in xpow for compatibility (bug #52706).
Marco Caliari <marco.caliari@univr.it>
parents:
23220
diff
changeset
|
2827 result(i) = std::pow (a(i), bint); |
8979
a7c00773a089
optimize also .^-1 case
Jaroslav Hajek <highegg@gmail.com>
parents:
8978
diff
changeset
|
2828 } |
a7c00773a089
optimize also .^-1 case
Jaroslav Hajek <highegg@gmail.com>
parents:
8978
diff
changeset
|
2829 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2830 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2831 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2832 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
2833 for (octave_idx_type i = 0; i < a.numel (); i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2834 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2835 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2836 result(i) = std::pow (a(i), b); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2837 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2838 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2839 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2840 return result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2841 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2842 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2843 // -*- 10 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2844 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2845 elem_xpow (const FloatComplexNDArray& a, const FloatNDArray& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2846 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2847 dim_vector a_dims = a.dims (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2848 dim_vector b_dims = b.dims (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2849 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2850 if (a_dims != b_dims) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2851 { |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
2852 if (! is_valid_bsxfun ("operator .^", a_dims, b_dims)) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2853 octave::err_nonconformant ("operator .^", a_dims, b_dims); |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
2854 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
2855 return bsxfun_pow (a, b); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2856 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2857 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2858 FloatComplexNDArray result (a_dims); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2859 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
2860 for (octave_idx_type i = 0; i < a.numel (); i++) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2861 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
2862 octave_quit (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2863 float btmp = b(i); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2864 if (xisint (btmp)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2865 result(i) = std::pow (a(i), static_cast<int> (btmp)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2866 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2867 result(i) = std::pow (a(i), btmp); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2868 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2869 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2870 return result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2871 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2872 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2873 // -*- 11 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2874 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2875 elem_xpow (const FloatComplexNDArray& a, const FloatComplex& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2876 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2877 FloatComplexNDArray result (a.dims ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2878 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
2879 for (octave_idx_type i = 0; i < a.numel (); i++) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2880 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
2881 octave_quit (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2882 result(i) = std::pow (a(i), b); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2883 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2884 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2885 return result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2886 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2887 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2888 // -*- 12 -*- |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2889 octave_value |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2890 elem_xpow (const FloatComplexNDArray& a, const FloatComplexNDArray& b) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2891 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2892 dim_vector a_dims = a.dims (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2893 dim_vector b_dims = b.dims (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2894 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2895 if (a_dims != b_dims) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2896 { |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
2897 if (! is_valid_bsxfun ("operator .^", a_dims, b_dims)) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2898 octave::err_nonconformant ("operator .^", a_dims, b_dims); |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
2899 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
2900 return bsxfun_pow (a, b); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2901 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2902 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2903 FloatComplexNDArray result (a_dims); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2904 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20228
diff
changeset
|
2905 for (octave_idx_type i = 0; i < a.numel (); i++) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2906 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10129
diff
changeset
|
2907 octave_quit (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2908 result(i) = std::pow (a(i), b(i)); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2909 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2910 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2911 return result; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7578
diff
changeset
|
2912 } |