Mercurial > octave
annotate libinterp/octave-value/ov-complex.cc @ 22327:d0562b3159c7
move more classes inside octave namespace
* ov-complex.cc, quit.h, lo-array-errwarn.h, lo-array-errwarn.cc,
lo-array-gripes.cc: Move classes inside octave namespace.
* NEWS, file-editor-tab.cc, Cell.cc, __qp__.cc, cellfun.cc, daspk.cc,
dasrt.cc, dassl.cc, data.cc, error.cc, error.h, errwarn.cc, errwarn.h,
file-io.cc, gcd.cc, graphics.cc, graphics.in.h, gripes.cc, gripes.h,
input.cc, interpreter.cc, interpreter.h, inv.cc, jit-typeinfo.cc,
load-path.cc, ls-mat-ascii.cc, ls-mat5.cc, lsode.cc, mex.cc,
oct-handle.h, oct-map.cc, oct-stream.cc, quad.cc, rand.cc,
sparse-xdiv.cc, sparse-xpow.cc, sparse.cc, sub2ind.cc, toplev.cc,
utils.cc, variables.cc, xdiv.cc, xpow.cc, __eigs__.cc,
__init_gnuplot__.cc, ov-base-diag.cc, ov-base-mat.cc,
ov-base-scalar.cc, ov-base-sparse.cc, ov-base.cc, ov-class.cc,
ov-classdef.cc, ov-complex.h, ov-complex.cc, ov-cx-mat.cc,
ov-cx-sparse.cc, ov-fcn-handle.cc, ov-float.cc, ov-float.h,
ov-flt-complex.h, ov-flt-cx-mat.cc, ov-flt-re-mat.cc, ov-java.cc,
ov-oncleanup.cc, ov-perm.cc, ov-range.cc, ov-re-diag.cc, ov-re-mat.cc,
ov-re-sparse.cc, ov-scalar.cc, ov-scalar.h, ov-str-mat.cc, ov.cc,
op-cs-cs.cc, op-fcs-fcs.cc, op-fs-fs.cc, op-int.h, op-s-s.cc, ops.h,
oct-parse.in.yy, pt-assign.cc, pt-eval.cc, pt-idx.cc, pt.cc,
Array-util.cc, Array.cc, CColVector.cc, CDiagMatrix.cc, CMatrix.cc,
CNDArray.cc, CRowVector.cc, CSparse.cc, DiagArray2.cc, MDiagArray2.cc,
MSparse.cc, PermMatrix.cc, Range.cc, Sparse.cc, dColVector.cc,
dDiagMatrix.cc, dMatrix.cc, dNDArray.cc, dRowVector.cc, dSparse.cc,
fCColVector.cc, fCDiagMatrix.cc, fCMatrix.cc, fCNDArray.cc,
fCRowVector.cc, fColVector.cc, fDiagMatrix.cc, fMatrix.cc,
fNDArray.cc, fRowVector.cc, idx-vector.cc, quit.cc, quit.h,
gepbalance.cc, Sparse-diag-op-defs.h, Sparse-op-defs.h,
Sparse-perm-op-defs.h, mx-inlines.cc, mx-op-defs.h, cmd-edit.cc,
lo-array-errwarn.cc, lo-array-errwarn.h, lo-array-gripes.cc,
lo-array-gripes.h, oct-binmap.h: Update to use namespace.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 17 Aug 2016 03:41:42 -0400 |
parents | bac0d6f07a3e |
children | 34ce5be04942 |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
22323
bac0d6f07a3e
maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents:
22296
diff
changeset
|
3 Copyright (C) 1996-2016 John W. Eaton |
2376 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2376 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2376 | 20 |
21 */ | |
22 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21231
diff
changeset
|
24 # include "config.h" |
2376 | 25 #endif |
26 | |
3503 | 27 #include <iostream> |
20653
c16947991354
avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
28 #include <sstream> |
2901 | 29 |
2376 | 30 #include "lo-ieee.h" |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
31 #include "lo-specfun.h" |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
32 #include "lo-mappers.h" |
2376 | 33 |
15149
62a35ae7d6a2
use forward decls for mxArray in ov.h and ov-base.h
John W. Eaton <jwe@octave.org>
parents:
15057
diff
changeset
|
34 #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
|
35 #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
|
36 #include "oct-hdf5.h" |
4944 | 37 #include "oct-stream.h" |
2410 | 38 #include "ops.h" |
2376 | 39 #include "ov-complex.h" |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
40 #include "ov-flt-complex.h" |
3223 | 41 #include "ov-base.h" |
42 #include "ov-base-scalar.h" | |
43 #include "ov-base-scalar.cc" | |
2423 | 44 #include "ov-cx-mat.h" |
2410 | 45 #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
|
46 #include "errwarn.h" |
2376 | 47 #include "pr-output.h" |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
48 #include "ops.h" |
2376 | 49 |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
19863
diff
changeset
|
50 #include "ls-oct-text.h" |
4687 | 51 #include "ls-hdf5.h" |
52 | |
21573
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
19863
diff
changeset
|
53 // 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
|
54 // 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
|
55 |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
19863
diff
changeset
|
56 extern template class OCTINTERP_API octave_base_scalar<double>; |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
19863
diff
changeset
|
57 extern template class OCTINTERP_API octave_base_scalar<FloatComplex>; |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
19863
diff
changeset
|
58 |
3223 | 59 template class octave_base_scalar<Complex>; |
60 | |
4612 | 61 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
|
62 "complex scalar", "double"); |
2376 | 63 |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
64 namespace octave |
20653
c16947991354
avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
65 { |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
66 // 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
|
67 |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
68 class complex_index_exception : public index_exception |
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
69 { |
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
70 public: |
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 complex_index_exception (const std::string& value) |
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
73 : index_exception (value) { } |
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
74 |
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
75 ~complex_index_exception (void) { } |
20653
c16947991354
avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
76 |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
77 std::string details (void) const |
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
78 { |
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
79 return "subscripts must be real (forgot to initialize i or j?)"; |
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
80 } |
20653
c16947991354
avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
81 |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
82 // ID of error to throw. |
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
83 const char *err_id (void) const |
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
84 { |
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
85 return "Octave:invalid-index"; |
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
86 } |
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
87 }; |
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
88 } |
20653
c16947991354
avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
89 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
90 static octave_base_value * |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
91 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
|
92 { |
21647
66cae7a6dc47
eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents:
21574
diff
changeset
|
93 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
|
94 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
95 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
|
96 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
97 |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
98 octave_base_value::type_conv_info |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
99 octave_complex::numeric_demotion_function (void) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
100 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
101 return |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
102 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
|
103 octave_float_complex::static_type_id ()); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
104 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
105 |
5759 | 106 octave_base_value * |
2410 | 107 octave_complex::try_narrowing_conversion (void) |
108 { | |
5759 | 109 octave_base_value *retval = 0; |
2410 | 110 |
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
|
111 double im = scalar.imag (); |
5450 | 112 |
9825
7483fe200fab
narrow complex values with negative zero imaginary parts
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
113 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
|
114 retval = new octave_scalar (scalar.real ()); |
2410 | 115 |
116 return retval; | |
117 } | |
118 | |
2376 | 119 octave_value |
5885 | 120 octave_complex::do_index_op (const octave_value_list& idx, bool resize_ok) |
2376 | 121 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
122 // FIXME: this doesn't solve the problem of |
8437
f00578b495e9
remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
123 // |
f00578b495e9
remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
124 // a = i; a([1,1], [1,1], [1,1]) |
f00578b495e9
remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
125 // |
f00578b495e9
remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
126 // and similar constructions. Hmm... |
2376 | 127 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
128 // FIXME: using this constructor avoids narrowing the |
8437
f00578b495e9
remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
129 // 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
|
130 // to this problem. |
2376 | 131 |
8437
f00578b495e9
remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
132 octave_value tmp (new octave_complex_matrix (complex_matrix_value ())); |
2423 | 133 |
8437
f00578b495e9
remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
134 return tmp.do_index_op (idx, resize_ok); |
2376 | 135 } |
136 | |
21113
2bbbbb96f631
ov-complex.cc: Incorporate gripe_complex_index into calling fcn.
Rik <rik@octave.org>
parents:
21111
diff
changeset
|
137 // 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
|
138 idx_vector |
c16947991354
avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
139 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
|
140 { |
21113
2bbbbb96f631
ov-complex.cc: Incorporate gripe_complex_index into calling fcn.
Rik <rik@octave.org>
parents:
21111
diff
changeset
|
141 std::ostringstream buf; |
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
|
142 buf << scalar.real () << std::showpos << scalar.imag () << "i"; |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
143 octave::complex_index_exception e (buf.str ()); |
20653
c16947991354
avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
144 |
21113
2bbbbb96f631
ov-complex.cc: Incorporate gripe_complex_index into calling fcn.
Rik <rik@octave.org>
parents:
21111
diff
changeset
|
145 throw e; |
20653
c16947991354
avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
146 } |
c16947991354
avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
147 |
2376 | 148 double |
149 octave_complex::double_value (bool force_conversion) const | |
150 { | |
18676
5bd1ca29c5f0
Clean up questionable code bits identified by clang sanitize.
Rik <rik@octave.org>
parents:
18100
diff
changeset
|
151 double retval; |
2376 | 152 |
5781 | 153 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
|
154 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
|
155 "complex scalar", "real scalar"); |
2376 | 156 |
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
|
157 retval = scalar.real (); |
2376 | 158 |
159 return retval; | |
160 } | |
161 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
162 float |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
163 octave_complex::float_value (bool force_conversion) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
164 { |
18676
5bd1ca29c5f0
Clean up questionable code bits identified by clang sanitize.
Rik <rik@octave.org>
parents:
18100
diff
changeset
|
165 float retval; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
166 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
167 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
|
168 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
|
169 "complex scalar", "real scalar"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
170 |
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
|
171 retval = scalar.real (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
172 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
173 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
174 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
175 |
2376 | 176 Matrix |
177 octave_complex::matrix_value (bool force_conversion) const | |
178 { | |
179 Matrix retval; | |
180 | |
5781 | 181 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
|
182 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
|
183 "complex scalar", "real matrix"); |
2376 | 184 |
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
|
185 retval = Matrix (1, 1, scalar.real ()); |
2376 | 186 |
187 return retval; | |
188 } | |
189 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
190 FloatMatrix |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
191 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
|
192 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
193 FloatMatrix retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
194 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
195 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
|
196 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
|
197 "complex scalar", "real matrix"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
198 |
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
|
199 retval = FloatMatrix (1, 1, scalar.real ()); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
200 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
201 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
202 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
203 |
4569 | 204 NDArray |
205 octave_complex::array_value (bool force_conversion) const | |
206 { | |
207 NDArray retval; | |
208 | |
5781 | 209 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
|
210 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
|
211 "complex scalar", "real matrix"); |
4569 | 212 |
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
|
213 retval = NDArray (dim_vector (1, 1), scalar.real ()); |
4569 | 214 |
215 return retval; | |
216 } | |
217 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
218 FloatNDArray |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
219 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
|
220 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
221 FloatNDArray retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
222 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
223 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
|
224 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
|
225 "complex scalar", "real matrix"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
226 |
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
|
227 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
|
228 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
229 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
230 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
231 |
2376 | 232 Complex |
233 octave_complex::complex_value (bool) const | |
234 { | |
235 return scalar; | |
236 } | |
237 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
238 FloatComplex |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
239 octave_complex::float_complex_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
240 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
241 return static_cast<FloatComplex> (scalar); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
242 } |
2376 | 243 |
244 ComplexMatrix | |
245 octave_complex::complex_matrix_value (bool) const | |
246 { | |
247 return ComplexMatrix (1, 1, scalar); | |
248 } | |
249 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
250 FloatComplexMatrix |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
251 octave_complex::float_complex_matrix_value (bool) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
252 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
253 return FloatComplexMatrix (1, 1, static_cast<FloatComplex> (scalar)); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
254 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
255 |
4569 | 256 ComplexNDArray |
4664 | 257 octave_complex::complex_array_value (bool /* force_conversion */) const |
4569 | 258 { |
259 return ComplexNDArray (dim_vector (1, 1), scalar); | |
260 } | |
261 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
262 FloatComplexNDArray |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
263 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
|
264 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
265 return FloatComplexNDArray (dim_vector (1, 1), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
266 static_cast<FloatComplex> (scalar)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
267 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
268 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
269 octave_value |
5731 | 270 octave_complex::resize (const dim_vector& dv, bool fill) const |
271 { | |
272 if (fill) | |
273 { | |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
274 ComplexNDArray retval (dv, Complex (0)); |
5731 | 275 |
276 if (dv.numel ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
277 retval(0) = scalar; |
5731 | 278 |
279 return retval; | |
280 } | |
281 else | |
282 { | |
283 ComplexNDArray retval (dv); | |
284 | |
285 if (dv.numel ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
286 retval(0) = scalar; |
5731 | 287 |
288 return retval; | |
289 } | |
290 } | |
291 | |
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
|
292 octave_value |
22296
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
293 octave_complex::as_double (void) const |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
294 { |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
295 return scalar; |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
296 } |
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 octave_value |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
299 octave_complex::as_single (void) const |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
300 { |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
301 return FloatComplex (scalar); |
8b18f46f6427
revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
302 } |
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 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
|
305 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
|
306 { |
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 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
|
308 } |
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 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
310 bool |
6974 | 311 octave_complex::save_ascii (std::ostream& os) |
4687 | 312 { |
313 Complex c = complex_value (); | |
314 | |
5958 | 315 octave_write_complex (os, c); |
4687 | 316 |
5958 | 317 os << "\n"; |
4687 | 318 |
319 return true; | |
320 } | |
321 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
322 bool |
4687 | 323 octave_complex::load_ascii (std::istream& is) |
324 { | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
325 scalar = octave_read_value<Complex> (is); |
4687 | 326 |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20653
diff
changeset
|
327 if (! is) |
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20653
diff
changeset
|
328 error ("load: failed to load complex scalar constant"); |
4687 | 329 |
330 return true; | |
331 } | |
332 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
333 bool |
4687 | 334 octave_complex::save_binary (std::ostream& os, bool& /* save_as_floats */) |
335 { | |
5760 | 336 char tmp = static_cast<char> (LS_DOUBLE); |
337 os.write (reinterpret_cast<char *> (&tmp), 1); | |
4687 | 338 Complex ctmp = complex_value (); |
5760 | 339 os.write (reinterpret_cast<char *> (&ctmp), 16); |
4687 | 340 |
341 return true; | |
342 } | |
343 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
344 bool |
4687 | 345 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
|
346 octave::mach_info::float_format fmt) |
4687 | 347 { |
348 char tmp; | |
5760 | 349 if (! is.read (reinterpret_cast<char *> (&tmp), 1)) |
4687 | 350 return false; |
351 | |
352 Complex ctmp; | |
5760 | 353 read_doubles (is, reinterpret_cast<double *> (&ctmp), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
354 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
|
355 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
356 if (! is) |
4687 | 357 return false; |
358 | |
359 scalar = ctmp; | |
360 return true; | |
361 } | |
362 | |
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
|
363 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
|
364 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
|
365 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
|
366 { |
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 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
|
368 |
4687 | 369 #if defined (HAVE_HDF5) |
4944 | 370 |
4687 | 371 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
|
372 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
|
373 space_hid = type_hid = data_hid = -1; |
4687 | 374 |
4815 | 375 space_hid = H5Screate_simple (0, dimens, 0); |
4837 | 376 if (space_hid < 0) |
377 return false; | |
4687 | 378 |
379 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
|
380 if (type_hid < 0) |
4687 | 381 { |
382 H5Sclose (space_hid); | |
383 return false; | |
384 } | |
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
|
385 #if defined (HAVE_HDF5_18) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
386 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
|
387 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
|
388 #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
|
389 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
|
390 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
391 if (data_hid < 0) |
4687 | 392 { |
393 H5Sclose (space_hid); | |
394 H5Tclose (type_hid); | |
395 return false; | |
396 } | |
397 | |
398 Complex tmp = complex_value (); | |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21013
diff
changeset
|
399 retval = H5Dwrite (data_hid, type_hid, octave_H5S_ALL, octave_H5S_ALL, octave_H5P_DEFAULT, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
400 &tmp) >= 0; |
4687 | 401 |
402 H5Dclose (data_hid); | |
403 H5Tclose (type_hid); | |
404 H5Sclose (space_hid); | |
4837 | 405 |
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
|
406 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21647
diff
changeset
|
407 octave_unused_parameter (loc_id); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21647
diff
changeset
|
408 octave_unused_parameter (name); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21647
diff
changeset
|
409 |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
410 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
|
411 #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
|
412 |
4687 | 413 return retval; |
414 } | |
415 | |
416 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
|
417 octave_complex::load_hdf5 (octave_hdf5_id loc_id, const char *name) |
4687 | 418 { |
419 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
|
420 |
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 #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
|
422 |
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
|
423 #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
|
424 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
|
425 #else |
4687 | 426 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
|
427 #endif |
4687 | 428 hid_t type_hid = H5Dget_type (data_hid); |
429 | |
430 hid_t complex_type = hdf5_make_complex_type (H5T_NATIVE_DOUBLE); | |
431 | |
432 if (! hdf5_types_compatible (type_hid, complex_type)) | |
433 { | |
4837 | 434 H5Tclose (complex_type); |
4687 | 435 H5Dclose (data_hid); |
436 return false; | |
437 } | |
438 | |
439 hid_t space_id = H5Dget_space (data_hid); | |
440 hsize_t rank = H5Sget_simple_extent_ndims (space_id); | |
441 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
442 if (rank != 0) |
4687 | 443 { |
4837 | 444 H5Tclose (complex_type); |
4687 | 445 H5Sclose (space_id); |
446 H5Dclose (data_hid); | |
447 return false; | |
448 } | |
449 | |
450 // complex scalar: | |
451 Complex ctmp; | |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21013
diff
changeset
|
452 if (H5Dread (data_hid, complex_type, octave_H5S_ALL, octave_H5S_ALL, octave_H5P_DEFAULT, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
453 &ctmp) >= 0) |
4687 | 454 { |
455 retval = true; | |
456 scalar = ctmp; | |
457 } | |
458 | |
4837 | 459 H5Tclose (complex_type); |
4687 | 460 H5Sclose (space_id); |
461 H5Dclose (data_hid); | |
4837 | 462 |
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
|
463 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21647
diff
changeset
|
464 octave_unused_parameter (loc_id); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21647
diff
changeset
|
465 octave_unused_parameter (name); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21647
diff
changeset
|
466 |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
467 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
|
468 #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
|
469 |
4687 | 470 return retval; |
471 } | |
4944 | 472 |
5900 | 473 mxArray * |
474 octave_complex::as_mxArray (void) const | |
475 { | |
476 mxArray *retval = new mxArray (mxDOUBLE_CLASS, 1, 1, mxCOMPLEX); | |
477 | |
478 double *pr = static_cast<double *> (retval->get_data ()); | |
479 double *pi = static_cast<double *> (retval->get_imag_data ()); | |
480 | |
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
|
481 pr[0] = scalar.real (); |
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
|
482 pi[0] = scalar.imag (); |
5900 | 483 |
484 return retval; | |
485 } | |
486 | |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
487 octave_value |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
488 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
|
489 { |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
490 switch (umap) |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
491 { |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
492 #define SCALAR_MAPPER(UMAP, FCN) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
493 case umap_ ## UMAP: \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
494 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
|
495 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
496 SCALAR_MAPPER (abs, std::abs); |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
497 SCALAR_MAPPER (acos, octave::math::acos); |
21786
df064166f180
use namespace for lo-specfun.h functions
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
498 SCALAR_MAPPER (acosh, octave::math::acosh); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
499 SCALAR_MAPPER (angle, std::arg); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
500 SCALAR_MAPPER (arg, std::arg); |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
501 SCALAR_MAPPER (asin, octave::math::asin); |
21786
df064166f180
use namespace for lo-specfun.h functions
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
502 SCALAR_MAPPER (asinh, octave::math::asinh); |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
503 SCALAR_MAPPER (atan, octave::math::atan); |
21786
df064166f180
use namespace for lo-specfun.h functions
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
504 SCALAR_MAPPER (atanh, octave::math::atanh); |
df064166f180
use namespace for lo-specfun.h functions
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
505 SCALAR_MAPPER (erf, octave::math::erf); |
df064166f180
use namespace for lo-specfun.h functions
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
506 SCALAR_MAPPER (erfc, octave::math::erfc); |
df064166f180
use namespace for lo-specfun.h functions
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
507 SCALAR_MAPPER (erfcx, octave::math::erfcx); |
df064166f180
use namespace for lo-specfun.h functions
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
508 SCALAR_MAPPER (erfi, octave::math::erfi); |
df064166f180
use namespace for lo-specfun.h functions
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
509 SCALAR_MAPPER (dawson, octave::math::dawson); |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
510 SCALAR_MAPPER (ceil, octave::math::ceil); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
511 SCALAR_MAPPER (conj, std::conj); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
512 SCALAR_MAPPER (cos, std::cos); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
513 SCALAR_MAPPER (cosh, std::cosh); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
514 SCALAR_MAPPER (exp, std::exp); |
21786
df064166f180
use namespace for lo-specfun.h functions
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
515 SCALAR_MAPPER (expm1, octave::math::expm1); |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
516 SCALAR_MAPPER (fix, octave::math::fix); |
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
517 SCALAR_MAPPER (floor, octave::math::floor); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
518 SCALAR_MAPPER (imag, std::imag); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
519 SCALAR_MAPPER (log, std::log); |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
520 SCALAR_MAPPER (log2, octave::math::log2); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
521 SCALAR_MAPPER (log10, std::log10); |
21786
df064166f180
use namespace for lo-specfun.h functions
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
522 SCALAR_MAPPER (log1p, octave::math::log1p); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
523 SCALAR_MAPPER (real, std::real); |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
524 SCALAR_MAPPER (round, octave::math::round); |
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
525 SCALAR_MAPPER (roundb, octave::math::roundb); |
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
526 SCALAR_MAPPER (signum, octave::math::signum); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
527 SCALAR_MAPPER (sin, std::sin); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
528 SCALAR_MAPPER (sinh, std::sinh); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
529 SCALAR_MAPPER (sqrt, std::sqrt); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
530 SCALAR_MAPPER (tan, std::tan); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
531 SCALAR_MAPPER (tanh, std::tanh); |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
532 SCALAR_MAPPER (isfinite, octave::math::finite); |
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
533 SCALAR_MAPPER (isinf, octave::math::isinf); |
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
534 SCALAR_MAPPER (isna, octave::math::is_NA); |
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
535 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
|
536 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
537 default: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
538 return octave_base_value::map (umap); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
539 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
540 } |