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