Mercurial > octave
annotate libinterp/octave-value/ov-complex.cc @ 29359:7854d5752dd2
maint: merge stable to default.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 10 Feb 2021 10:10:40 -0500 |
parents | 0a6ed9dcd601 0a5b15007766 |
children | 29a1f8fd8ee6 |
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:
28012
diff
changeset
|
3 // Copyright (C) 1996-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 //////////////////////////////////////////////////////////////////////// |
2376 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21231
diff
changeset
|
27 # include "config.h" |
2376 | 28 #endif |
29 | |
25438
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
30 #include <istream> |
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
31 #include <ostream> |
20653
c16947991354
avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
32 #include <sstream> |
2901 | 33 |
2376 | 34 #include "lo-ieee.h" |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
35 #include "lo-specfun.h" |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
36 #include "lo-mappers.h" |
2376 | 37 |
15149
62a35ae7d6a2
use forward decls for mxArray in ov.h and ov-base.h
John W. Eaton <jwe@octave.org>
parents:
15057
diff
changeset
|
38 #include "mxarray.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
39 #include "ovl.h" |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
40 #include "oct-hdf5.h" |
4944 | 41 #include "oct-stream.h" |
2410 | 42 #include "ops.h" |
2376 | 43 #include "ov-complex.h" |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
44 #include "ov-flt-complex.h" |
3223 | 45 #include "ov-base.h" |
46 #include "ov-base-scalar.h" | |
47 #include "ov-base-scalar.cc" | |
2423 | 48 #include "ov-cx-mat.h" |
2410 | 49 #include "ov-scalar.h" |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
50 #include "errwarn.h" |
2376 | 51 #include "pr-output.h" |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
52 #include "ops.h" |
2376 | 53 |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
19863
diff
changeset
|
54 #include "ls-oct-text.h" |
4687 | 55 #include "ls-hdf5.h" |
56 | |
21573
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
19863
diff
changeset
|
57 // Prevent implicit instantiations on some systems (Windows, others?) |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
19863
diff
changeset
|
58 // that can lead to duplicate definitions of static data members. |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
19863
diff
changeset
|
59 |
29240
0a6ed9dcd601
Silence compiler warnings about ignored attributes (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29171
diff
changeset
|
60 extern template class octave_base_scalar<double>; |
0a6ed9dcd601
Silence compiler warnings about ignored attributes (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29171
diff
changeset
|
61 extern template class octave_base_scalar<FloatComplex>; |
21573
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
19863
diff
changeset
|
62 |
3223 | 63 template class octave_base_scalar<Complex>; |
64 | |
4612 | 65 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_complex, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
66 "complex scalar", "double"); |
2376 | 67 |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
68 namespace octave |
20653
c16947991354
avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
69 { |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
70 // Complain if a complex value is used as a subscript. |
20653
c16947991354
avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
71 |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
72 class complex_index_exception : public index_exception |
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
73 { |
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
74 public: |
20653
c16947991354
avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
75 |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
76 complex_index_exception (const std::string& value) |
28012
9a965fec21c1
refactor index_exception classes to accommodate std::exception::what method
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
77 : index_exception (value) |
9a965fec21c1
refactor index_exception classes to accommodate std::exception::what method
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
78 { |
9a965fec21c1
refactor index_exception classes to accommodate std::exception::what method
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
79 // Virtual, but the one we want to call is defined in this class. |
9a965fec21c1
refactor index_exception classes to accommodate std::exception::what method
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
80 update_message (); |
9a965fec21c1
refactor index_exception classes to accommodate std::exception::what method
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
81 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
82 |
22868
87e3163f6c87
use c++11 "= default" syntax for declaration of trivial destructors
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
83 ~complex_index_exception (void) = default; |
20653
c16947991354
avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
84 |
28012
9a965fec21c1
refactor index_exception classes to accommodate std::exception::what method
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
85 void update_message (void) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
86 { |
28012
9a965fec21c1
refactor index_exception classes to accommodate std::exception::what method
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
87 set_message (expression () |
9a965fec21c1
refactor index_exception classes to accommodate std::exception::what method
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
88 + ": subscripts must be real (forgot to initialize i or j?)"); |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
89 } |
20653
c16947991354
avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
90 |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
91 // ID of error to throw. |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
92 const char * err_id (void) const |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
93 { |
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
94 return "Octave:invalid-index"; |
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
95 } |
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
96 }; |
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
97 } |
20653
c16947991354
avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
98 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
99 static octave_base_value * |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
100 default_numeric_demotion_function (const octave_base_value& a) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
101 { |
21647
66cae7a6dc47
eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents:
21574
diff
changeset
|
102 const octave_complex& v = dynamic_cast<const octave_complex&> (a); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
103 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
104 return new octave_float_complex (v.float_complex_value ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
105 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
106 |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
107 octave_base_value::type_conv_info |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
108 octave_complex::numeric_demotion_function (void) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
109 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
110 return |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
111 octave_base_value::type_conv_info (default_numeric_demotion_function, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
112 octave_float_complex::static_type_id ()); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
113 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
114 |
5759 | 115 octave_base_value * |
2410 | 116 octave_complex::try_narrowing_conversion (void) |
117 { | |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
118 octave_base_value *retval = nullptr; |
2410 | 119 |
22274
edcad35c364f
don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
120 double im = scalar.imag (); |
5450 | 121 |
9825
7483fe200fab
narrow complex values with negative zero imaginary parts
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
122 if (im == 0.0) |
22274
edcad35c364f
don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
123 retval = new octave_scalar (scalar.real ()); |
2410 | 124 |
125 return retval; | |
126 } | |
127 | |
2376 | 128 octave_value |
5885 | 129 octave_complex::do_index_op (const octave_value_list& idx, bool resize_ok) |
2376 | 130 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
131 // FIXME: this doesn't solve the problem of |
8437
f00578b495e9
remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
132 // |
f00578b495e9
remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
133 // a = i; a([1,1], [1,1], [1,1]) |
f00578b495e9
remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
134 // |
f00578b495e9
remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
135 // and similar constructions. Hmm... |
2376 | 136 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
137 // FIXME: using this constructor avoids narrowing the |
8437
f00578b495e9
remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
138 // 1x1 matrix back to a scalar value. Need a better solution |
f00578b495e9
remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
139 // to this problem. |
2376 | 140 |
8437
f00578b495e9
remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
141 octave_value tmp (new octave_complex_matrix (complex_matrix_value ())); |
2423 | 142 |
28631
70cdf8de553d
move non-member octave_value operator functions to octave namespace
John W. Eaton <jwe@octave.org>
parents:
28628
diff
changeset
|
143 return tmp.index_op (idx, resize_ok); |
2376 | 144 } |
145 | |
21113
2bbbbb96f631
ov-complex.cc: Incorporate gripe_complex_index into calling fcn.
Rik <rik@octave.org>
parents:
21111
diff
changeset
|
146 // Can't make an index_vector from a complex number. Throw an error. |
20653
c16947991354
avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
147 idx_vector |
c16947991354
avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
148 octave_complex::index_vector (bool) const |
c16947991354
avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
149 { |
21113
2bbbbb96f631
ov-complex.cc: Incorporate gripe_complex_index into calling fcn.
Rik <rik@octave.org>
parents:
21111
diff
changeset
|
150 std::ostringstream buf; |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
151 buf << scalar.real () << std::showpos << scalar.imag () << 'i'; |
29171
254ee9af5014
maint: More updates to standardize exception naming scheme.
Rik <rik@octave.org>
parents:
28631
diff
changeset
|
152 octave::complex_index_exception cie (buf.str ()); |
20653
c16947991354
avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
153 |
29171
254ee9af5014
maint: More updates to standardize exception naming scheme.
Rik <rik@octave.org>
parents:
28631
diff
changeset
|
154 throw cie; |
20653
c16947991354
avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
155 } |
c16947991354
avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
156 |
2376 | 157 double |
158 octave_complex::double_value (bool force_conversion) const | |
159 { | |
5781 | 160 if (! force_conversion) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
161 warn_implicit_conversion ("Octave:imag-to-real", |
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
162 "complex scalar", "real scalar"); |
2376 | 163 |
22477
6bf1cbb90705
Remove unnecessary initializations in float_value and double_value methods
Julien Bect <julien.bect@centralesupelec.fr>
parents:
22407
diff
changeset
|
164 return scalar.real (); |
2376 | 165 } |
166 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
167 float |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
168 octave_complex::float_value (bool force_conversion) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
169 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
170 if (! force_conversion) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
171 warn_implicit_conversion ("Octave:imag-to-real", |
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
172 "complex scalar", "real scalar"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
173 |
22477
6bf1cbb90705
Remove unnecessary initializations in float_value and double_value methods
Julien Bect <julien.bect@centralesupelec.fr>
parents:
22407
diff
changeset
|
174 return scalar.real (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
175 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
176 |
2376 | 177 Matrix |
178 octave_complex::matrix_value (bool force_conversion) const | |
179 { | |
180 Matrix retval; | |
181 | |
5781 | 182 if (! force_conversion) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
183 warn_implicit_conversion ("Octave:imag-to-real", |
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
184 "complex scalar", "real matrix"); |
2376 | 185 |
22274
edcad35c364f
don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
186 retval = Matrix (1, 1, scalar.real ()); |
2376 | 187 |
188 return retval; | |
189 } | |
190 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
191 FloatMatrix |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
192 octave_complex::float_matrix_value (bool force_conversion) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
193 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
194 FloatMatrix retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
195 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
196 if (! force_conversion) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
197 warn_implicit_conversion ("Octave:imag-to-real", |
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
198 "complex scalar", "real matrix"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
199 |
22274
edcad35c364f
don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
200 retval = FloatMatrix (1, 1, scalar.real ()); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
201 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
202 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
203 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
204 |
4569 | 205 NDArray |
206 octave_complex::array_value (bool force_conversion) const | |
207 { | |
208 NDArray retval; | |
209 | |
5781 | 210 if (! force_conversion) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
211 warn_implicit_conversion ("Octave:imag-to-real", |
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
212 "complex scalar", "real matrix"); |
4569 | 213 |
22274
edcad35c364f
don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
214 retval = NDArray (dim_vector (1, 1), scalar.real ()); |
4569 | 215 |
216 return retval; | |
217 } | |
218 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
219 FloatNDArray |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
220 octave_complex::float_array_value (bool force_conversion) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
221 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
222 FloatNDArray retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
223 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
224 if (! force_conversion) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
225 warn_implicit_conversion ("Octave:imag-to-real", |
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
226 "complex scalar", "real matrix"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
227 |
22274
edcad35c364f
don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
228 retval = FloatNDArray (dim_vector (1, 1), scalar.real ()); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
229 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
230 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
231 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
232 |
2376 | 233 Complex |
234 octave_complex::complex_value (bool) const | |
235 { | |
236 return scalar; | |
237 } | |
238 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
239 FloatComplex |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
240 octave_complex::float_complex_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
241 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
242 return static_cast<FloatComplex> (scalar); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
243 } |
2376 | 244 |
245 ComplexMatrix | |
246 octave_complex::complex_matrix_value (bool) const | |
247 { | |
248 return ComplexMatrix (1, 1, scalar); | |
249 } | |
250 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
251 FloatComplexMatrix |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
252 octave_complex::float_complex_matrix_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
253 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
254 return FloatComplexMatrix (1, 1, static_cast<FloatComplex> (scalar)); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
255 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
256 |
4569 | 257 ComplexNDArray |
4664 | 258 octave_complex::complex_array_value (bool /* force_conversion */) const |
4569 | 259 { |
260 return ComplexNDArray (dim_vector (1, 1), scalar); | |
261 } | |
262 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
263 FloatComplexNDArray |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
264 octave_complex::float_complex_array_value (bool /* force_conversion */) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
265 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
266 return FloatComplexNDArray (dim_vector (1, 1), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
267 static_cast<FloatComplex> (scalar)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
268 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
269 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
270 octave_value |
5731 | 271 octave_complex::resize (const dim_vector& dv, bool fill) const |
272 { | |
273 if (fill) | |
274 { | |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
275 ComplexNDArray retval (dv, Complex (0)); |
5731 | 276 |
277 if (dv.numel ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
278 retval(0) = scalar; |
5731 | 279 |
280 return retval; | |
281 } | |
282 else | |
283 { | |
284 ComplexNDArray retval (dv); | |
285 | |
286 if (dv.numel ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
287 retval(0) = scalar; |
5731 | 288 |
289 return retval; | |
290 } | |
291 } | |
292 | |
14557
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
293 octave_value |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
294 octave_complex::as_double (void) const |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
295 { |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
296 return scalar; |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
297 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
298 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
299 octave_value |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
300 octave_complex::as_single (void) const |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
301 { |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
302 return FloatComplex (scalar); |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
303 } |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
304 |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
305 octave_value |
14557
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
306 octave_complex::diag (octave_idx_type m, octave_idx_type n) const |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
307 { |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
308 return ComplexDiagMatrix (Array<Complex> (dim_vector (1, 1), scalar), m, n); |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
309 } |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
310 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
311 bool |
6974 | 312 octave_complex::save_ascii (std::ostream& os) |
4687 | 313 { |
314 Complex c = complex_value (); | |
315 | |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
28126
diff
changeset
|
316 octave::write_value<Complex> (os, c); |
4687 | 317 |
5958 | 318 os << "\n"; |
4687 | 319 |
320 return true; | |
321 } | |
322 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
323 bool |
4687 | 324 octave_complex::load_ascii (std::istream& is) |
325 { | |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
28126
diff
changeset
|
326 scalar = octave::read_value<Complex> (is); |
4687 | 327 |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20653
diff
changeset
|
328 if (! is) |
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20653
diff
changeset
|
329 error ("load: failed to load complex scalar constant"); |
4687 | 330 |
331 return true; | |
332 } | |
333 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
334 bool |
26399
586413770c7f
pass save_as_floats by value in octave_value save_binary functions
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
335 octave_complex::save_binary (std::ostream& os, bool /* save_as_floats */) |
4687 | 336 { |
5760 | 337 char tmp = static_cast<char> (LS_DOUBLE); |
338 os.write (reinterpret_cast<char *> (&tmp), 1); | |
4687 | 339 Complex ctmp = complex_value (); |
5760 | 340 os.write (reinterpret_cast<char *> (&ctmp), 16); |
4687 | 341 |
342 return true; | |
343 } | |
344 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
345 bool |
4687 | 346 octave_complex::load_binary (std::istream& is, bool swap, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
347 octave::mach_info::float_format fmt) |
4687 | 348 { |
349 char tmp; | |
5760 | 350 if (! is.read (reinterpret_cast<char *> (&tmp), 1)) |
4687 | 351 return false; |
352 | |
353 Complex ctmp; | |
5760 | 354 read_doubles (is, reinterpret_cast<double *> (&ctmp), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
355 static_cast<save_type> (tmp), 2, swap, fmt); |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
356 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
357 if (! is) |
4687 | 358 return false; |
359 | |
360 scalar = ctmp; | |
361 return true; | |
362 } | |
363 | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
364 bool |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
365 octave_complex::save_hdf5 (octave_hdf5_id loc_id, const char *name, |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
366 bool /* save_as_floats */) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
367 { |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
368 bool retval = false; |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
369 |
4687 | 370 #if defined (HAVE_HDF5) |
4944 | 371 |
4687 | 372 hsize_t dimens[3]; |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
373 hid_t space_hid, type_hid, data_hid; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
374 space_hid = type_hid = data_hid = -1; |
4687 | 375 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23619
diff
changeset
|
376 space_hid = H5Screate_simple (0, dimens, nullptr); |
4837 | 377 if (space_hid < 0) |
378 return false; | |
4687 | 379 |
380 type_hid = hdf5_make_complex_type (H5T_NATIVE_DOUBLE); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
381 if (type_hid < 0) |
4687 | 382 { |
383 H5Sclose (space_hid); | |
384 return false; | |
385 } | |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
386 #if defined (HAVE_HDF5_18) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
387 data_hid = H5Dcreate (loc_id, name, type_hid, space_hid, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21013
diff
changeset
|
388 octave_H5P_DEFAULT, octave_H5P_DEFAULT, octave_H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
389 #else |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21013
diff
changeset
|
390 data_hid = H5Dcreate (loc_id, name, type_hid, space_hid, octave_H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
391 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
392 if (data_hid < 0) |
4687 | 393 { |
394 H5Sclose (space_hid); | |
395 H5Tclose (type_hid); | |
396 return false; | |
397 } | |
398 | |
399 Complex tmp = complex_value (); | |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
400 retval = H5Dwrite (data_hid, type_hid, octave_H5S_ALL, octave_H5S_ALL, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
401 octave_H5P_DEFAULT, &tmp) >= 0; |
4687 | 402 |
403 H5Dclose (data_hid); | |
404 H5Tclose (type_hid); | |
405 H5Sclose (space_hid); | |
4837 | 406 |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
407 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21647
diff
changeset
|
408 octave_unused_parameter (loc_id); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21647
diff
changeset
|
409 octave_unused_parameter (name); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21647
diff
changeset
|
410 |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
411 warn_save ("hdf5"); |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
412 #endif |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
413 |
4687 | 414 return retval; |
415 } | |
416 | |
417 bool | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
418 octave_complex::load_hdf5 (octave_hdf5_id loc_id, const char *name) |
4687 | 419 { |
420 bool retval = false; | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
421 |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
422 #if defined (HAVE_HDF5) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
423 |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
424 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21013
diff
changeset
|
425 hid_t data_hid = H5Dopen (loc_id, name, octave_H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
426 #else |
4687 | 427 hid_t data_hid = H5Dopen (loc_id, name); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
428 #endif |
4687 | 429 hid_t type_hid = H5Dget_type (data_hid); |
430 | |
431 hid_t complex_type = hdf5_make_complex_type (H5T_NATIVE_DOUBLE); | |
432 | |
433 if (! hdf5_types_compatible (type_hid, complex_type)) | |
434 { | |
4837 | 435 H5Tclose (complex_type); |
4687 | 436 H5Dclose (data_hid); |
437 return false; | |
438 } | |
439 | |
440 hid_t space_id = H5Dget_space (data_hid); | |
441 hsize_t rank = H5Sget_simple_extent_ndims (space_id); | |
442 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
443 if (rank != 0) |
4687 | 444 { |
4837 | 445 H5Tclose (complex_type); |
4687 | 446 H5Sclose (space_id); |
447 H5Dclose (data_hid); | |
448 return false; | |
449 } | |
450 | |
451 // complex scalar: | |
452 Complex ctmp; | |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
453 if (H5Dread (data_hid, complex_type, octave_H5S_ALL, octave_H5S_ALL, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
454 octave_H5P_DEFAULT, &ctmp) >= 0) |
4687 | 455 { |
456 retval = true; | |
457 scalar = ctmp; | |
458 } | |
459 | |
4837 | 460 H5Tclose (complex_type); |
4687 | 461 H5Sclose (space_id); |
462 H5Dclose (data_hid); | |
4837 | 463 |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
464 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21647
diff
changeset
|
465 octave_unused_parameter (loc_id); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21647
diff
changeset
|
466 octave_unused_parameter (name); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21647
diff
changeset
|
467 |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
468 warn_load ("hdf5"); |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
469 #endif |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
470 |
4687 | 471 return retval; |
472 } | |
4944 | 473 |
5900 | 474 mxArray * |
28126
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
28012
diff
changeset
|
475 octave_complex::as_mxArray (bool interleaved) const |
5900 | 476 { |
28126
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
28012
diff
changeset
|
477 mxArray *retval = new mxArray (interleaved, mxDOUBLE_CLASS, 1, 1, mxCOMPLEX); |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
28012
diff
changeset
|
478 |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
28012
diff
changeset
|
479 if (interleaved) |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
28012
diff
changeset
|
480 { |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
28012
diff
changeset
|
481 mxComplexDouble *pd |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
28012
diff
changeset
|
482 = reinterpret_cast<mxComplexDouble *> (retval->get_complex_doubles ()); |
5900 | 483 |
28126
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
28012
diff
changeset
|
484 pd[0].real = scalar.real (); |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
28012
diff
changeset
|
485 pd[0].imag = scalar.imag (); |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
28012
diff
changeset
|
486 } |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
28012
diff
changeset
|
487 else |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
28012
diff
changeset
|
488 { |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
28012
diff
changeset
|
489 mxDouble *pr = static_cast<mxDouble *> (retval->get_data ()); |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
28012
diff
changeset
|
490 mxDouble *pi = static_cast<mxDouble *> (retval->get_imag_data ()); |
5900 | 491 |
28126
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
28012
diff
changeset
|
492 pr[0] = scalar.real (); |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
28012
diff
changeset
|
493 pi[0] = scalar.imag (); |
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
28012
diff
changeset
|
494 } |
5900 | 495 |
496 return retval; | |
497 } | |
498 | |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
499 octave_value |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
500 octave_complex::map (unary_mapper_t umap) const |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
501 { |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
502 switch (umap) |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
503 { |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
504 #define SCALAR_MAPPER(UMAP, FCN) \ |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
505 case umap_ ## UMAP: \ |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
506 return octave_value (FCN (scalar)) |
7667
fb3a6c53c2b2
Allow negative zero imaginary part to be treated as zero for erf, erfc, gamma and lgamma mapper function
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
507 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
508 SCALAR_MAPPER (abs, std::abs); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
509 SCALAR_MAPPER (acos, octave::math::acos); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
510 SCALAR_MAPPER (acosh, octave::math::acosh); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
511 SCALAR_MAPPER (angle, std::arg); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
512 SCALAR_MAPPER (arg, std::arg); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
513 SCALAR_MAPPER (asin, octave::math::asin); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
514 SCALAR_MAPPER (asinh, octave::math::asinh); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
515 SCALAR_MAPPER (atan, octave::math::atan); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
516 SCALAR_MAPPER (atanh, octave::math::atanh); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
517 SCALAR_MAPPER (erf, octave::math::erf); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
518 SCALAR_MAPPER (erfc, octave::math::erfc); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
519 SCALAR_MAPPER (erfcx, octave::math::erfcx); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
520 SCALAR_MAPPER (erfi, octave::math::erfi); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
521 SCALAR_MAPPER (dawson, octave::math::dawson); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
522 SCALAR_MAPPER (ceil, octave::math::ceil); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
523 SCALAR_MAPPER (conj, std::conj); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
524 SCALAR_MAPPER (cos, std::cos); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
525 SCALAR_MAPPER (cosh, std::cosh); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
526 SCALAR_MAPPER (exp, std::exp); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
527 SCALAR_MAPPER (expm1, octave::math::expm1); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
528 SCALAR_MAPPER (fix, octave::math::fix); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
529 SCALAR_MAPPER (floor, octave::math::floor); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
530 SCALAR_MAPPER (imag, std::imag); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
531 SCALAR_MAPPER (log, std::log); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
532 SCALAR_MAPPER (log2, octave::math::log2); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
533 SCALAR_MAPPER (log10, std::log10); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
534 SCALAR_MAPPER (log1p, octave::math::log1p); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
535 SCALAR_MAPPER (real, std::real); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
536 SCALAR_MAPPER (round, octave::math::round); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
537 SCALAR_MAPPER (roundb, octave::math::roundb); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
538 SCALAR_MAPPER (signum, octave::math::signum); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
539 SCALAR_MAPPER (sin, std::sin); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
540 SCALAR_MAPPER (sinh, std::sinh); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
541 SCALAR_MAPPER (sqrt, std::sqrt); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
542 SCALAR_MAPPER (tan, std::tan); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
543 SCALAR_MAPPER (tanh, std::tanh); |
23564
7049da1648c0
Deprecate octave::math::finite in favor of octave::math::isfinite.
Rik <rik@octave.org>
parents:
23457
diff
changeset
|
544 SCALAR_MAPPER (isfinite, octave::math::isfinite); |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
545 SCALAR_MAPPER (isinf, octave::math::isinf); |
23619
6ed4d6e306ba
maint: Deprecate is_NA and replace with isna.
Rik <rik@octave.org>
parents:
23564
diff
changeset
|
546 SCALAR_MAPPER (isna, octave::math::isna); |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
547 SCALAR_MAPPER (isnan, octave::math::isnan); |
7667
fb3a6c53c2b2
Allow negative zero imaginary part to be treated as zero for erf, erfc, gamma and lgamma mapper function
David Bateman <dbateman@free.fr>
parents:
7638
diff
changeset
|
548 |
24587
6ece7c7e4912
tolower/toupper functions return complex numbers unchanged (bug #52380).
Stevie Schraudner <stevietodd@hotmail.com>
parents:
24534
diff
changeset
|
549 // Special cases for Matlab compatibility. |
6ece7c7e4912
tolower/toupper functions return complex numbers unchanged (bug #52380).
Stevie Schraudner <stevietodd@hotmail.com>
parents:
24534
diff
changeset
|
550 case umap_xtolower: |
6ece7c7e4912
tolower/toupper functions return complex numbers unchanged (bug #52380).
Stevie Schraudner <stevietodd@hotmail.com>
parents:
24534
diff
changeset
|
551 case umap_xtoupper: |
6ece7c7e4912
tolower/toupper functions return complex numbers unchanged (bug #52380).
Stevie Schraudner <stevietodd@hotmail.com>
parents:
24534
diff
changeset
|
552 return scalar; |
6ece7c7e4912
tolower/toupper functions return complex numbers unchanged (bug #52380).
Stevie Schraudner <stevietodd@hotmail.com>
parents:
24534
diff
changeset
|
553 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
554 default: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
555 return octave_base_value::map (umap); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
556 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
557 } |