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