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