annotate libinterp/octave-value/ov-complex.cc @ 22296:8b18f46f6427

revamp double, single, int type conversions * ov-type-conv.h: Delete. * libinterp/octave-value/module.mk: Update. * op-double-conv.cc, op-float-conv.cc, op-int-conv.cc: Delete. * libinterp/operators/module.mk: Update. * ov.h, ov.cc, ov-base.h, ov-base.cc (octave_value::as_double, octave_value::as_single, octave_value:as_int8, octave_value:as_int16, octave_value:as_int32, octave_value:as_int64, octave_value:as_uint8, octave_value:as_uint16, octave_value:as_uint32, octave_value:as_uint64): New functions. * ov.cc (Fdouble, Fsingle, Fint8, Fint16, Fint32, Fint64, Fuint8, Fuint16, Fuint32, Fuint64): Move here. Simply call as_double, as_single, etc. member functions. * ov-base-int.cc, ov-base-int.h, ov-base-scalar.cc, ov-bool-mat.cc, ov-bool-mat.h, ov-bool-sparse.cc, ov-bool-sparse.h, ov-bool.cc, ov-bool.h, ov-ch-mat.cc, ov-ch-mat.h, ov-complex.cc, ov-complex.h, ov-cx-diag.cc, ov-cx-diag.h, ov-cx-mat.cc, ov-cx-mat.h, ov-cx-sparse.cc, ov-cx-sparse.h, ov-float.cc, ov-float.h, ov-flt-complex.cc, ov-flt-complex.h, ov-flt-cx-diag.cc, ov-flt-cx-diag.h, ov-flt-cx-mat.cc, ov-flt-cx-mat.h, ov-flt-re-diag.cc, ov-flt-re-diag.h, ov-flt-re-mat.cc, ov-flt-re-mat.h, ov-int16.cc, ov-int32.cc, ov-int64.cc, ov-int8.cc, ov-perm.cc, ov-perm.h, ov-range.cc, ov-range.h, ov-re-diag.cc, ov-re-diag.h, ov-re-mat.cc, ov-re-mat.h, ov-re-sparse.cc, ov-re-sparse.h, ov-scalar.cc, ov-scalar.h, ov-uint16.cc, ov-uint32.cc, ov-uint64.cc, ov-uint8.cc: Define as_double, as_single, etc. member functions as appropriate. * ov-typeinfo.h, ov-typeinfo.cc (octave_value_typeinfo::type_conv_ops): Delete data member. Remove all uses. (octave_value_typeinfo::register_type_conv_op): Delete. (octave_value_typeinfo::do_register_type_conv_op): Delete. (octave_value_typeinfo::do_lookup_type_conv_op): Delete. * ops.h (INSTALL_CONVOP, CONVDECLX, DEFCONVFNX, DEFCONVFNX2, DEFDBLCONVFN, DEFFLTCONVFN, DEFSTRINTCONVFN, DEFSTRDBLCONVFN, DEFSTRFLTCONVFN, DEFCONVFN, DEFCONVFN2): Delete obsolete macros. * op-bm-bm.cc, op-cdm-cdm.cc, op-cm-cm.cc, op-cs-cs.cc, op-dm-dm.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc, op-fcs-fcs.cc, op-fdm-fdm.cc, op-fm-fm.cc, op-fs-fs.cc, op-m-m.cc, op-pm-pm.cc, op-s-s.cc, op-sbm-sbm.cc: Delete unused type conversion functions.
author John W. Eaton <jwe@octave.org>
date Mon, 15 Aug 2016 02:01:29 -0400
parents edcad35c364f
children bac0d6f07a3e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
1 /*
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
2
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19598
diff changeset
3 Copyright (C) 1996-2015 John W. Eaton
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
4
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
6
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6974
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6974
diff changeset
10 option) any later version.
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
11
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
15 for more details.
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
16
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6974
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6974
diff changeset
19 <http://www.gnu.org/licenses/>.
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
20
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
21 */
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
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
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
25 #endif
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
26
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3223
diff changeset
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
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
29
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
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
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
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
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4837
diff changeset
37 #include "oct-stream.h"
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
38 #include "ops.h"
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
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
3ee04ff37b3e [project @ 1998-11-20 19:34:15 by jwe]
jwe
parents: 3219
diff changeset
41 #include "ov-base.h"
3ee04ff37b3e [project @ 1998-11-20 19:34:15 by jwe]
jwe
parents: 3219
diff changeset
42 #include "ov-base-scalar.h"
3ee04ff37b3e [project @ 1998-11-20 19:34:15 by jwe]
jwe
parents: 3219
diff changeset
43 #include "ov-base-scalar.cc"
2423
de430cdd9234 [project @ 1996-10-18 20:39:41 by jwe]
jwe
parents: 2410
diff changeset
44 #include "ov-cx-mat.h"
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
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
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
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
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
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
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
51 #include "ls-hdf5.h"
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
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
3ee04ff37b3e [project @ 1998-11-20 19:34:15 by jwe]
jwe
parents: 3219
diff changeset
59 template class octave_base_scalar<Complex>;
3ee04ff37b3e [project @ 1998-11-20 19:34:15 by jwe]
jwe
parents: 3219
diff changeset
60
4612
d44675070f1a [project @ 2003-11-14 19:49:56 by jwe]
jwe
parents: 4569
diff changeset
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
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
63
20653
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
64 // Complain if a complex value is used as a subscript.
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
65
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
66 class complex_index_exception : public index_exception
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
67 {
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
68 public:
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
69
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
70 complex_index_exception (const std::string& value)
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
71 : index_exception (value) { }
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
72
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
73 ~complex_index_exception (void) { }
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
74
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
75 std::string details (void) const
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
76 {
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
77 return "subscripts must be real (forgot to initialize i or j?)";
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
78 }
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
79
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
80 // ID of error to throw.
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
81 const char *err_id (void) const
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
82 {
21111
7bb96a8df912 lo-array-errwarn.h: Don't export string constants unnecessarily.
Rik <rik@octave.org>
parents: 21102
diff changeset
83 return "Octave:invalid-index";
20653
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
84 }
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
85 };
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
86
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
87 static octave_base_value *
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
88 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
89 {
21647
66cae7a6dc47 eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents: 21574
diff changeset
90 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
91
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
92 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
93 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
94
8345
c777f3ce02d8 smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
95 octave_base_value::type_conv_info
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
96 octave_complex::numeric_demotion_function (void) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
97 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
98 return
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
99 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
100 octave_float_complex::static_type_id ());
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
101 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
102
5759
ce79d238f142 [project @ 2006-04-13 13:04:32 by jwe]
jwe
parents: 5731
diff changeset
103 octave_base_value *
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
104 octave_complex::try_narrowing_conversion (void)
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
105 {
5759
ce79d238f142 [project @ 2006-04-13 13:04:32 by jwe]
jwe
parents: 5731
diff changeset
106 octave_base_value *retval = 0;
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
107
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
108 double im = scalar.imag ();
5450
6b42c78c77d3 [project @ 2005-09-15 15:36:26 by jwe]
jwe
parents: 5307
diff changeset
109
9825
7483fe200fab narrow complex values with negative zero imaginary parts
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
110 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
111 retval = new octave_scalar (scalar.real ());
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
112
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
113 return retval;
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
114 }
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2376
diff changeset
115
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
116 octave_value
5885
bd3041e30d97 [project @ 2006-07-14 20:29:35 by jwe]
jwe
parents: 5781
diff changeset
117 octave_complex::do_index_op (const octave_value_list& idx, bool resize_ok)
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
118 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
119 // FIXME: this doesn't solve the problem of
8437
f00578b495e9 remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
120 //
f00578b495e9 remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
121 // a = i; a([1,1], [1,1], [1,1])
f00578b495e9 remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
122 //
f00578b495e9 remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
123 // and similar constructions. Hmm...
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
124
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
125 // FIXME: using this constructor avoids narrowing the
8437
f00578b495e9 remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
126 // 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
127 // to this problem.
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
128
8437
f00578b495e9 remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
129 octave_value tmp (new octave_complex_matrix (complex_matrix_value ()));
2423
de430cdd9234 [project @ 1996-10-18 20:39:41 by jwe]
jwe
parents: 2410
diff changeset
130
8437
f00578b495e9 remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
131 return tmp.do_index_op (idx, resize_ok);
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
132 }
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
133
21113
2bbbbb96f631 ov-complex.cc: Incorporate gripe_complex_index into calling fcn.
Rik <rik@octave.org>
parents: 21111
diff changeset
134 // 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
135 idx_vector
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
136 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
137 {
21113
2bbbbb96f631 ov-complex.cc: Incorporate gripe_complex_index into calling fcn.
Rik <rik@octave.org>
parents: 21111
diff changeset
138 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
139 buf << scalar.real () << std::showpos << scalar.imag () << "i";
21113
2bbbbb96f631 ov-complex.cc: Incorporate gripe_complex_index into calling fcn.
Rik <rik@octave.org>
parents: 21111
diff changeset
140 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
141
21113
2bbbbb96f631 ov-complex.cc: Incorporate gripe_complex_index into calling fcn.
Rik <rik@octave.org>
parents: 21111
diff changeset
142 throw e;
20653
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
143 }
c16947991354 avoid fixed-size buffers in index exception code
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
144
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
145 double
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
146 octave_complex::double_value (bool force_conversion) const
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
147 {
18676
5bd1ca29c5f0 Clean up questionable code bits identified by clang sanitize.
Rik <rik@octave.org>
parents: 18100
diff changeset
148 double retval;
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
149
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
150 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
151 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
152 "complex scalar", "real scalar");
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
153
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
154 retval = scalar.real ();
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
155
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
156 return retval;
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
157 }
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
158
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
159 float
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
160 octave_complex::float_value (bool force_conversion) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
161 {
18676
5bd1ca29c5f0 Clean up questionable code bits identified by clang sanitize.
Rik <rik@octave.org>
parents: 18100
diff changeset
162 float retval;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
163
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
164 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
165 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
166 "complex scalar", "real scalar");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
167
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
168 retval = scalar.real ();
7789
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 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
171 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
172
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
173 Matrix
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
174 octave_complex::matrix_value (bool force_conversion) const
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
175 {
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
176 Matrix retval;
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
177
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
178 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
179 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
180 "complex scalar", "real matrix");
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
181
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
182 retval = Matrix (1, 1, scalar.real ());
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
183
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
184 return retval;
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
185 }
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
186
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
187 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
188 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
189 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
190 FloatMatrix retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
191
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
192 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
193 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
194 "complex scalar", "real matrix");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
195
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
196 retval = FloatMatrix (1, 1, scalar.real ());
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
197
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
198 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
199 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
200
4569
01e4957409a4 [project @ 2003-10-30 05:48:17 by jwe]
jwe
parents: 4451
diff changeset
201 NDArray
01e4957409a4 [project @ 2003-10-30 05:48:17 by jwe]
jwe
parents: 4451
diff changeset
202 octave_complex::array_value (bool force_conversion) const
01e4957409a4 [project @ 2003-10-30 05:48:17 by jwe]
jwe
parents: 4451
diff changeset
203 {
01e4957409a4 [project @ 2003-10-30 05:48:17 by jwe]
jwe
parents: 4451
diff changeset
204 NDArray retval;
01e4957409a4 [project @ 2003-10-30 05:48:17 by jwe]
jwe
parents: 4451
diff changeset
205
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
206 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
207 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
208 "complex scalar", "real matrix");
4569
01e4957409a4 [project @ 2003-10-30 05:48:17 by jwe]
jwe
parents: 4451
diff changeset
209
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
210 retval = NDArray (dim_vector (1, 1), scalar.real ());
4569
01e4957409a4 [project @ 2003-10-30 05:48:17 by jwe]
jwe
parents: 4451
diff changeset
211
01e4957409a4 [project @ 2003-10-30 05:48:17 by jwe]
jwe
parents: 4451
diff changeset
212 return retval;
01e4957409a4 [project @ 2003-10-30 05:48:17 by jwe]
jwe
parents: 4451
diff changeset
213 }
01e4957409a4 [project @ 2003-10-30 05:48:17 by jwe]
jwe
parents: 4451
diff changeset
214
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
215 FloatNDArray
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
216 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
217 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
218 FloatNDArray retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
219
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
220 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
221 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
222 "complex scalar", "real matrix");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
223
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
224 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
225
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
226 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
227 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
228
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
229 Complex
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
230 octave_complex::complex_value (bool) const
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
231 {
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
232 return scalar;
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
233 }
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
234
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
235 FloatComplex
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
236 octave_complex::float_complex_value (bool) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
237 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
238 return static_cast<FloatComplex> (scalar);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
239 }
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
240
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
241 ComplexMatrix
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
242 octave_complex::complex_matrix_value (bool) const
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
243 {
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
244 return ComplexMatrix (1, 1, scalar);
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
245 }
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
246
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
247 FloatComplexMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
248 octave_complex::float_complex_matrix_value (bool) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
249 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
250 return FloatComplexMatrix (1, 1, static_cast<FloatComplex> (scalar));
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
251 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
252
4569
01e4957409a4 [project @ 2003-10-30 05:48:17 by jwe]
jwe
parents: 4451
diff changeset
253 ComplexNDArray
4664
19bcdc6a9bb8 [project @ 2003-11-25 06:22:02 by jwe]
jwe
parents: 4612
diff changeset
254 octave_complex::complex_array_value (bool /* force_conversion */) const
4569
01e4957409a4 [project @ 2003-10-30 05:48:17 by jwe]
jwe
parents: 4451
diff changeset
255 {
01e4957409a4 [project @ 2003-10-30 05:48:17 by jwe]
jwe
parents: 4451
diff changeset
256 return ComplexNDArray (dim_vector (1, 1), scalar);
01e4957409a4 [project @ 2003-10-30 05:48:17 by jwe]
jwe
parents: 4451
diff changeset
257 }
01e4957409a4 [project @ 2003-10-30 05:48:17 by jwe]
jwe
parents: 4451
diff changeset
258
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
259 FloatComplexNDArray
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
260 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
261 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
262 return FloatComplexNDArray (dim_vector (1, 1),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
263 static_cast<FloatComplex> (scalar));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
264 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
265
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
266 octave_value
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5450
diff changeset
267 octave_complex::resize (const dim_vector& dv, bool fill) const
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5450
diff changeset
268 {
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5450
diff changeset
269 if (fill)
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5450
diff changeset
270 {
14616
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
271 ComplexNDArray retval (dv, Complex (0));
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5450
diff changeset
272
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5450
diff changeset
273 if (dv.numel ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
274 retval(0) = scalar;
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5450
diff changeset
275
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5450
diff changeset
276 return retval;
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5450
diff changeset
277 }
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5450
diff changeset
278 else
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5450
diff changeset
279 {
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5450
diff changeset
280 ComplexNDArray retval (dv);
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5450
diff changeset
281
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5450
diff changeset
282 if (dv.numel ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
283 retval(0) = scalar;
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5450
diff changeset
284
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5450
diff changeset
285 return retval;
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5450
diff changeset
286 }
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5450
diff changeset
287 }
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5450
diff changeset
288
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
289 octave_value
22296
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22274
diff changeset
290 octave_complex::as_double (void) const
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22274
diff changeset
291 {
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22274
diff changeset
292 return scalar;
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22274
diff changeset
293 }
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 octave_value
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22274
diff changeset
296 octave_complex::as_single (void) const
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 return FloatComplex (scalar);
8b18f46f6427 revamp double, single, int type conversions
John W. Eaton <jwe@octave.org>
parents: 22274
diff changeset
299 }
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 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
302 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
303 {
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
304 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
305 }
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
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
307 bool
6974
9e32bb109980 [project @ 2007-10-08 11:06:47 by jwe]
jwe
parents: 5958
diff changeset
308 octave_complex::save_ascii (std::ostream& os)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
309 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
310 Complex c = complex_value ();
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
311
5958
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5956
diff changeset
312 octave_write_complex (os, c);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
313
5958
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5956
diff changeset
314 os << "\n";
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
315
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
316 return true;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
317 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
318
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
319 bool
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
320 octave_complex::load_ascii (std::istream& is)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
321 {
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
322 scalar = octave_read_value<Complex> (is);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
323
20893
384ff5aa9437 2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents: 20653
diff changeset
324 if (! is)
384ff5aa9437 2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents: 20653
diff changeset
325 error ("load: failed to load complex scalar constant");
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
326
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
327 return true;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
328 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
329
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
330 bool
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
331 octave_complex::save_binary (std::ostream& os, bool& /* save_as_floats */)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
332 {
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
333 char tmp = static_cast<char> (LS_DOUBLE);
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
334 os.write (reinterpret_cast<char *> (&tmp), 1);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
335 Complex ctmp = complex_value ();
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
336 os.write (reinterpret_cast<char *> (&ctmp), 16);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
337
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
338 return true;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
339 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
340
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
341 bool
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
342 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
343 octave::mach_info::float_format fmt)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
344 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
345 char tmp;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
346 if (! is.read (reinterpret_cast<char *> (&tmp), 1))
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
347 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
348
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
349 Complex ctmp;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
350 read_doubles (is, reinterpret_cast<double *> (&ctmp),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
351 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
352
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
353 if (! is)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
354 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
355
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
356 scalar = ctmp;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
357 return true;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
358 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
359
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
360 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
361 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
362 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
363 {
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 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
365
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
366 #if defined (HAVE_HDF5)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4837
diff changeset
367
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
368 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
369 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
370 space_hid = type_hid = data_hid = -1;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
371
4815
2eb844b27953 [project @ 2004-03-04 00:14:44 by jwe]
jwe
parents: 4687
diff changeset
372 space_hid = H5Screate_simple (0, dimens, 0);
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
373 if (space_hid < 0)
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
374 return false;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
375
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
376 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
377 if (type_hid < 0)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
378 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
379 H5Sclose (space_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
380 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
381 }
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
382 #if defined (HAVE_HDF5_18)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
383 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
384 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
385 #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
386 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
387 #endif
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
388 if (data_hid < 0)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
389 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
390 H5Sclose (space_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
391 H5Tclose (type_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
392 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
393 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
394
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
395 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
396 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
397 &tmp) >= 0;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
398
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
399 H5Dclose (data_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
400 H5Tclose (type_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
401 H5Sclose (space_hid);
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
402
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
403 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21647
diff changeset
404 octave_unused_parameter (loc_id);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21647
diff changeset
405 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21647
diff changeset
406
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
407 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
408 #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
409
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
410 return retval;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
411 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
412
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
413 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
414 octave_complex::load_hdf5 (octave_hdf5_id loc_id, const char *name)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
415 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
416 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
417
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 #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
419
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
420 #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
421 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
422 #else
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
423 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
424 #endif
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
425 hid_t type_hid = H5Dget_type (data_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
426
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
427 hid_t complex_type = hdf5_make_complex_type (H5T_NATIVE_DOUBLE);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
428
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
429 if (! hdf5_types_compatible (type_hid, complex_type))
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
430 {
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
431 H5Tclose (complex_type);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
432 H5Dclose (data_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
433 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
434 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
435
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
436 hid_t space_id = H5Dget_space (data_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
437 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
438
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
439 if (rank != 0)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
440 {
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
441 H5Tclose (complex_type);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
442 H5Sclose (space_id);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
443 H5Dclose (data_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
444 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
445 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
446
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
447 // complex scalar:
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
448 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
449 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
450 &ctmp) >= 0)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
451 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
452 retval = true;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
453 scalar = ctmp;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
454 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
455
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
456 H5Tclose (complex_type);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
457 H5Sclose (space_id);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
458 H5Dclose (data_hid);
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
459
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
460 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21647
diff changeset
461 octave_unused_parameter (loc_id);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21647
diff changeset
462 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21647
diff changeset
463
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
464 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
465 #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
466
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
467 return retval;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4664
diff changeset
468 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4837
diff changeset
469
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
470 mxArray *
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
471 octave_complex::as_mxArray (void) const
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
472 {
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
473 mxArray *retval = new mxArray (mxDOUBLE_CLASS, 1, 1, mxCOMPLEX);
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
474
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
475 double *pr = static_cast<double *> (retval->get_data ());
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
476 double *pi = static_cast<double *> (retval->get_imag_data ());
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
477
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
478 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
479 pi[0] = scalar.imag ();
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
480
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
481 return retval;
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
482 }
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5885
diff changeset
483
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
484 octave_value
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
485 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
486 {
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
487 switch (umap)
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
488 {
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
489 #define SCALAR_MAPPER(UMAP, FCN) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
490 case umap_ ## UMAP: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
491 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
492
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
493 SCALAR_MAPPER (abs, std::abs);
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
494 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
495 SCALAR_MAPPER (acosh, octave::math::acosh);
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
496 SCALAR_MAPPER (angle, std::arg);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
497 SCALAR_MAPPER (arg, std::arg);
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
498 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
499 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
500 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
501 SCALAR_MAPPER (atanh, octave::math::atanh);
df064166f180 use namespace for lo-specfun.h functions
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
502 SCALAR_MAPPER (erf, octave::math::erf);
df064166f180 use namespace for lo-specfun.h functions
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
503 SCALAR_MAPPER (erfc, octave::math::erfc);
df064166f180 use namespace for lo-specfun.h functions
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
504 SCALAR_MAPPER (erfcx, octave::math::erfcx);
df064166f180 use namespace for lo-specfun.h functions
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
505 SCALAR_MAPPER (erfi, octave::math::erfi);
df064166f180 use namespace for lo-specfun.h functions
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
506 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
507 SCALAR_MAPPER (ceil, octave::math::ceil);
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
508 SCALAR_MAPPER (conj, std::conj);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
509 SCALAR_MAPPER (cos, std::cos);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
510 SCALAR_MAPPER (cosh, std::cosh);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
511 SCALAR_MAPPER (exp, std::exp);
21786
df064166f180 use namespace for lo-specfun.h functions
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
512 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
513 SCALAR_MAPPER (fix, octave::math::fix);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
514 SCALAR_MAPPER (floor, octave::math::floor);
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
515 SCALAR_MAPPER (imag, std::imag);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
516 SCALAR_MAPPER (log, std::log);
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
517 SCALAR_MAPPER (log2, octave::math::log2);
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
518 SCALAR_MAPPER (log10, std::log10);
21786
df064166f180 use namespace for lo-specfun.h functions
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
519 SCALAR_MAPPER (log1p, octave::math::log1p);
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
520 SCALAR_MAPPER (real, std::real);
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
521 SCALAR_MAPPER (round, octave::math::round);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
522 SCALAR_MAPPER (roundb, octave::math::roundb);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
523 SCALAR_MAPPER (signum, octave::math::signum);
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
524 SCALAR_MAPPER (sin, std::sin);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
525 SCALAR_MAPPER (sinh, std::sinh);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
526 SCALAR_MAPPER (sqrt, std::sqrt);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
527 SCALAR_MAPPER (tan, std::tan);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
528 SCALAR_MAPPER (tanh, std::tanh);
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
529 SCALAR_MAPPER (isfinite, octave::math::finite);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
530 SCALAR_MAPPER (isinf, octave::math::isinf);
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
531 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
532 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
533
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
534 default:
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
535 return octave_base_value::map (umap);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
536 }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
537 }