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