annotate libinterp/octave-value/ov-cx-mat.cc @ 20587:f90c8372b7ba

eliminate many more simple uses of error_state * Cell.cc, __ichol__.cc, __ilu__.cc, balance.cc, bsxfun.cc, colloc.cc, det.cc, dlmread.cc, dynamic-ld.cc, eig.cc, fft.cc, fft2.cc, fftn.cc, gcd.cc, getgrent.cc, getpwent.cc, givens.cc, hess.cc, input.cc, levenshtein.cc, load-path.cc, lookup.cc, ls-mat-ascii.cc, ls-mat4.cc, lsode.cc, lu.cc, max.cc, md5sum.cc, mex.cc, pager.cc, pinv.cc, pr-output.cc, qz.cc, schur.cc, sparse.cc, sqrtm.cc, str2double.cc, strfns.cc, sub2ind.cc, sysdep.cc, time.cc, toplev.cc, tril.cc, tsearch.cc, typecast.cc, __init_gnuplot__.cc, __magick_read__.cc, __osmesa_print__.cc, amd.cc, audiodevinfo.cc, dmperm.cc, fftw.cc, symrcm.cc, ov-base-diag.cc, ov-base-sparse.cc, ov-base.cc, ov-bool-sparse.cc, ov-builtin.cc, ov-complex.cc, ov-cx-diag.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-fcn-handle.cc, ov-fcn-inline.cc, ov-float.cc, ov-flt-complex.cc, ov-flt-cx-diag.cc, ov-flt-cx-mat.cc, ov-flt-re-diag.cc, ov-flt-re-mat.cc, ov-lazy-idx.cc, ov-mex-fcn.cc, ov-perm.cc, ov-range.cc, ov-re-diag.cc, ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc, ov-str-mat.cc, op-bm-b.cc, op-bm-bm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-str-m.cc, op-str-s.cc, oct-parse.in.yy, pt-cbinop.cc, pt-colon.cc, pt-decl.cc, pt-exp.cc, pt-id.cc, pt-misc.cc, pt-select.cc, pt-unop.cc: Eliminate simple uses of error_state.
author John W. Eaton <jwe@octave.org>
date Mon, 05 Oct 2015 19:29:36 -0400
parents df4165dfc676
children
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
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19632
diff changeset
3 Copyright (C) 1996-2015 John W. Eaton
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11129
diff changeset
4 Copyright (C) 2009-2010 VZLU Prague
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
5
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
7
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
8 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
9 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
10 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
11 option) any later version.
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
12
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
13 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
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
15 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
16 for more details.
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
17
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
18 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
19 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
20 <http://www.gnu.org/licenses/>.
2376
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 */
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
23
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
25 #include <config.h>
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
26 #endif
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
27
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3418
diff changeset
28 #include <iostream>
4726
14dc2267c343 [project @ 2004-01-23 20:04:35 by jwe]
jwe
parents: 4687
diff changeset
29 #include <vector>
2901
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
30
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4923
diff changeset
31 #include "data-conv.h"
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
32 #include "lo-ieee.h"
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
33 #include "lo-specfun.h"
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
34 #include "lo-mappers.h"
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
35 #include "mx-base.h"
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4923
diff changeset
36 #include "mach-info.h"
8377
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
37 #include "oct-locbuf.h"
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
38
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
39 #include "gripes.h"
15149
62a35ae7d6a2 use forward decls for mxArray in ov.h and ov-base.h
John W. Eaton <jwe@octave.org>
parents: 15057
diff changeset
40 #include "mxarray.h"
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
41 #include "oct-obj.h"
19897
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: 19762
diff changeset
42 #include "oct-hdf5.h"
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4923
diff changeset
43 #include "oct-stream.h"
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
44 #include "ops.h"
3219
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents: 3109
diff changeset
45 #include "ov-base.h"
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents: 3109
diff changeset
46 #include "ov-base-mat.h"
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents: 3109
diff changeset
47 #include "ov-base-mat.cc"
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
48 #include "ov-complex.h"
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
49 #include "ov-cx-mat.h"
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
50 #include "ov-flt-cx-mat.h"
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
51 #include "ov-re-mat.h"
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
52 #include "ov-scalar.h"
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
53 #include "pr-output.h"
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
54
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
55 #include "byte-swap.h"
20482
c6224b4e7774 maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents: 20253
diff changeset
56 #include "ls-oct-text.h"
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
57 #include "ls-hdf5.h"
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
58 #include "ls-utils.h"
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
59
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4455
diff changeset
60 template class octave_base_matrix<ComplexNDArray>;
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
61
2477
3d905d3820a4 [project @ 1996-11-07 16:46:11 by jwe]
jwe
parents: 2466
diff changeset
62
4612
d44675070f1a [project @ 2003-11-14 19:49:56 by jwe]
jwe
parents: 4513
diff changeset
63 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_complex_matrix,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
64 "complex matrix", "double");
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
65
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
66 static octave_base_value *
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
67 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
68 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
69 CAST_CONV_ARG (const octave_complex_matrix&);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
70
16781
e88c14f4dbb2 Use complex_array_value in ov-cx-mat.cc(default_numeric_demotion_function) (bug #39254)
David Bateman <dbateman@free.fr>
parents: 15696
diff changeset
71 return new octave_float_complex_matrix (v.float_complex_array_value ());
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
72 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
73
8345
c777f3ce02d8 smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8290
diff changeset
74 octave_base_value::type_conv_info
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
75 octave_complex_matrix::numeric_demotion_function (void) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
76 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
77 return octave_base_value::type_conv_info
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
78 (default_numeric_demotion_function,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
79 octave_float_complex_matrix::static_type_id ());
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
80 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
81
5759
ce79d238f142 [project @ 2006-04-13 13:04:32 by jwe]
jwe
parents: 5450
diff changeset
82 octave_base_value *
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
83 octave_complex_matrix::try_narrowing_conversion (void)
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
84 {
5759
ce79d238f142 [project @ 2006-04-13 13:04:32 by jwe]
jwe
parents: 5450
diff changeset
85 octave_base_value *retval = 0;
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
86
9825
7483fe200fab narrow complex values with negative zero imaginary parts
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
87 if (matrix.numel () == 1)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4455
diff changeset
88 {
9825
7483fe200fab narrow complex values with negative zero imaginary parts
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
89 Complex c = matrix (0);
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
90
9825
7483fe200fab narrow complex values with negative zero imaginary parts
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
91 if (std::imag (c) == 0.0)
7483fe200fab narrow complex values with negative zero imaginary parts
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
92 retval = new octave_scalar (std::real (c));
7483fe200fab narrow complex values with negative zero imaginary parts
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
93 else
7483fe200fab narrow complex values with negative zero imaginary parts
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
94 retval = new octave_complex (c);
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
95 }
4923
b11223097ad4 [project @ 2004-08-02 16:33:11 by jwe]
jwe
parents: 4837
diff changeset
96 else if (matrix.all_elements_are_real ())
b11223097ad4 [project @ 2004-08-02 16:33:11 by jwe]
jwe
parents: 4837
diff changeset
97 retval = new octave_matrix (::real (matrix));
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
98
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
99 return retval;
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
100 }
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
101
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
102 double
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
103 octave_complex_matrix::double_value (bool force_conversion) const
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
104 {
4102
cbac6756967e [project @ 2002-10-14 20:16:44 by jwe]
jwe
parents: 4066
diff changeset
105 double retval = lo_ieee_nan_value ();
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
106
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
107 if (! force_conversion)
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
108 gripe_implicit_conversion ("Octave:imag-to-real",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
109 "complex matrix", "real scalar");
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
110
4455
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4451
diff changeset
111 if (rows () > 0 && columns () > 0)
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4451
diff changeset
112 {
14469
29aabe9b37a2 Rename array-as-vector, array-as-scalar warning IDs to match documentation (bug #35838)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
113 gripe_implicit_conversion ("Octave:array-to-scalar",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
114 "complex matrix", "real scalar");
4455
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4451
diff changeset
115
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4451
diff changeset
116 retval = std::real (matrix (0, 0));
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4451
diff changeset
117 }
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
118 else
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
119 gripe_invalid_conversion ("complex matrix", "real scalar");
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
120
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
121 return retval;
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
122 }
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
123
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
124 float
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
125 octave_complex_matrix::float_value (bool force_conversion) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
126 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
127 float retval = lo_ieee_float_nan_value ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
128
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
129 if (! force_conversion)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
130 gripe_implicit_conversion ("Octave:imag-to-real",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
131 "complex matrix", "real scalar");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
132
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
133 if (rows () > 0 && columns () > 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
134 {
14469
29aabe9b37a2 Rename array-as-vector, array-as-scalar warning IDs to match documentation (bug #35838)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
135 gripe_implicit_conversion ("Octave:array-to-scalar",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
136 "complex matrix", "real scalar");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
137
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
138 retval = std::real (matrix (0, 0));
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
139 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
140 else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
141 gripe_invalid_conversion ("complex matrix", "real scalar");
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
142
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
143 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
144 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
145
19762
928ecc95f395 implement missing complex array extraction function
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
146 NDArray
928ecc95f395 implement missing complex array extraction function
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
147 octave_complex_matrix::array_value (bool force_conversion) const
928ecc95f395 implement missing complex array extraction function
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
148 {
928ecc95f395 implement missing complex array extraction function
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
149 NDArray retval;
928ecc95f395 implement missing complex array extraction function
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
150
928ecc95f395 implement missing complex array extraction function
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
151 if (! force_conversion)
928ecc95f395 implement missing complex array extraction function
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
152 gripe_implicit_conversion ("Octave:imag-to-real",
928ecc95f395 implement missing complex array extraction function
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
153 "complex matrix", "real matrix");
928ecc95f395 implement missing complex array extraction function
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
154
928ecc95f395 implement missing complex array extraction function
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
155 retval = ::real (matrix);
928ecc95f395 implement missing complex array extraction function
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
156
928ecc95f395 implement missing complex array extraction function
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
157 return retval;
928ecc95f395 implement missing complex array extraction function
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
158 }
928ecc95f395 implement missing complex array extraction function
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
159
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
160 Matrix
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
161 octave_complex_matrix::matrix_value (bool force_conversion) const
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
162 {
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
163 Matrix retval;
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
164
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
165 if (! force_conversion)
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
166 gripe_implicit_conversion ("Octave:imag-to-real",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
167 "complex matrix", "real matrix");
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
168
19352
d0c73e23a505 Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents: 18099
diff changeset
169 retval = ::real (ComplexMatrix (matrix));
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
170
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
171 return retval;
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
172 }
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
173
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
174 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
175 octave_complex_matrix::float_matrix_value (bool force_conversion) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
176 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
177 FloatMatrix retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
178
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
179 if (! force_conversion)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
180 gripe_implicit_conversion ("Octave:imag-to-real",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
181 "complex matrix", "real matrix");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
182
19352
d0c73e23a505 Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents: 18099
diff changeset
183 retval = ::real (ComplexMatrix (matrix));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
184
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
185 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
186 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
187
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
188 Complex
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
189 octave_complex_matrix::complex_value (bool) const
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
190 {
4102
cbac6756967e [project @ 2002-10-14 20:16:44 by jwe]
jwe
parents: 4066
diff changeset
191 double tmp = lo_ieee_nan_value ();
cbac6756967e [project @ 2002-10-14 20:16:44 by jwe]
jwe
parents: 4066
diff changeset
192
cbac6756967e [project @ 2002-10-14 20:16:44 by jwe]
jwe
parents: 4066
diff changeset
193 Complex retval (tmp, tmp);
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
194
4455
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4451
diff changeset
195 if (rows () > 0 && columns () > 0)
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4451
diff changeset
196 {
14469
29aabe9b37a2 Rename array-as-vector, array-as-scalar warning IDs to match documentation (bug #35838)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
197 gripe_implicit_conversion ("Octave:array-to-scalar",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
198 "complex matrix", "complex scalar");
4455
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4451
diff changeset
199
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4451
diff changeset
200 retval = matrix (0, 0);
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4451
diff changeset
201 }
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
202 else
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
203 gripe_invalid_conversion ("complex matrix", "complex scalar");
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
204
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
205 return retval;
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
206 }
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
207
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
208 FloatComplex
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
209 octave_complex_matrix::float_complex_value (bool) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
210 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
211 float tmp = lo_ieee_float_nan_value ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
212
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
213 FloatComplex retval (tmp, tmp);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
214
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
215 if (rows () > 0 && columns () > 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
216 {
14469
29aabe9b37a2 Rename array-as-vector, array-as-scalar warning IDs to match documentation (bug #35838)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
217 gripe_implicit_conversion ("Octave:array-to-scalar",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
218 "complex matrix", "complex scalar");
7789
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 retval = matrix (0, 0);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
221 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
222 else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
223 gripe_invalid_conversion ("complex matrix", "complex scalar");
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
224
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
225 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
226 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
227
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
228 ComplexMatrix
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
229 octave_complex_matrix::complex_matrix_value (bool) const
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
230 {
19352
d0c73e23a505 Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents: 18099
diff changeset
231 return ComplexMatrix (matrix);
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
232 }
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
233
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
234 FloatComplexMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
235 octave_complex_matrix::float_complex_matrix_value (bool) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
236 {
19352
d0c73e23a505 Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents: 18099
diff changeset
237 return FloatComplexMatrix (ComplexMatrix (matrix));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
238 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
239
9853
8d9e4752441a implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 9825
diff changeset
240 boolNDArray
8d9e4752441a implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 9825
diff changeset
241 octave_complex_matrix::bool_array_value (bool warn) const
8d9e4752441a implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 9825
diff changeset
242 {
8d9e4752441a implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 9825
diff changeset
243 if (matrix.any_element_is_nan ())
11129
0de5cc44e690 use gripe functions for NaN to logical and NaN to character conversions more consistently
John W. Eaton <jwe@octave.org>
parents: 10521
diff changeset
244 gripe_nan_to_logical_conversion ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
245 else if (warn && (! matrix.all_elements_are_real ()
9853
8d9e4752441a implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 9825
diff changeset
246 || real (matrix).any_element_not_one_or_zero ()))
8d9e4752441a implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 9825
diff changeset
247 gripe_logical_conversion ();
8d9e4752441a implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 9825
diff changeset
248
8d9e4752441a implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 9825
diff changeset
249 return mx_el_ne (matrix, Complex (0.0));
8d9e4752441a implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 9825
diff changeset
250 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
251
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
252 charNDArray
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
253 octave_complex_matrix::char_array_value (bool frc_str_conv) const
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
254 {
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
255 charNDArray retval;
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
256
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
257 if (! frc_str_conv)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
258 gripe_implicit_conversion ("Octave:num-to-str",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
259 "complex matrix", "string");
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
260 else
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
261 {
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
262 retval = charNDArray (dims ());
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
263 octave_idx_type nel = numel ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
264
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
265 for (octave_idx_type i = 0; i < nel; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
266 retval.elem (i) = static_cast<char>(std::real (matrix.elem (i)));
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
267 }
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
268
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
269 return retval;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
270 }
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
271
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
272 FloatComplexNDArray
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
273 octave_complex_matrix::float_complex_array_value (bool) const
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
274 {
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
275 return FloatComplexNDArray (matrix);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
276 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
277
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
278 SparseMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
279 octave_complex_matrix::sparse_matrix_value (bool force_conversion) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
280 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
281 SparseMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
282
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
283 if (! force_conversion)
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
284 gripe_implicit_conversion ("Octave:imag-to-real",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
285 "complex matrix", "real matrix");
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
286
19352
d0c73e23a505 Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents: 18099
diff changeset
287 retval = SparseMatrix (::real (ComplexMatrix (matrix)));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
288
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
289 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
290 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
291
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
292 SparseComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
293 octave_complex_matrix::sparse_complex_matrix_value (bool) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
294 {
19352
d0c73e23a505 Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents: 18099
diff changeset
295 return SparseComplexMatrix (ComplexMatrix (matrix));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
296 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
297
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
298 octave_value
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
299 octave_complex_matrix::diag (octave_idx_type k) const
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
300 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
301 octave_value retval;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
302 if (k == 0 && matrix.ndims () == 2
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
303 && (matrix.rows () == 1 || matrix.columns () == 1))
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
304 retval = ComplexDiagMatrix (DiagArray2<Complex> (matrix));
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
305 else
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
306 retval = octave_base_matrix<ComplexNDArray>::diag (k);
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
307
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
308 return retval;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
309 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
310
14557
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14469
diff changeset
311 octave_value
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14469
diff changeset
312 octave_complex_matrix::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: 14469
diff changeset
313 {
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14469
diff changeset
314 octave_value retval;
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14469
diff changeset
315
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14469
diff changeset
316 if (matrix.ndims () == 2
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14469
diff changeset
317 && (matrix.rows () == 1 || matrix.columns () == 1))
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14469
diff changeset
318 {
19352
d0c73e23a505 Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents: 18099
diff changeset
319 ComplexMatrix mat (matrix);
14557
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14469
diff changeset
320
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14469
diff changeset
321 retval = mat.diag (m, n);
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14469
diff changeset
322 }
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14469
diff changeset
323 else
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14469
diff changeset
324 error ("diag: expecting vector argument");
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14469
diff changeset
325
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14469
diff changeset
326 return retval;
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14469
diff changeset
327 }
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14469
diff changeset
328
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
329 bool
6974
9e32bb109980 [project @ 2007-10-08 11:06:47 by jwe]
jwe
parents: 6717
diff changeset
330 octave_complex_matrix::save_ascii (std::ostream& os)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
331 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
332 dim_vector d = dims ();
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
333 if (d.length () > 2)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
334 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
335 ComplexNDArray tmp = complex_array_value ();
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
336
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
337 os << "# ndims: " << d.length () << "\n";
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
338
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5260
diff changeset
339 for (int i = 0; i < d.length (); i++)
20253
b2100e1659ac maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents: 19897
diff changeset
340 os << " " << d(i);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
341
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
342 os << "\n" << tmp;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
343 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
344 else
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
345 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
346 // Keep this case, rather than use generic code above for backward
20484
df4165dfc676 maint: Fix misspelled word compatibility in code comments.
Rik <rik@octave.org>
parents: 20482
diff changeset
347 // compatibility. Makes load_ascii much more complex!!
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
348 os << "# rows: " << rows () << "\n"
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
349 << "# columns: " << columns () << "\n";
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
350
5958
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5956
diff changeset
351 os << complex_matrix_value ();
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
352 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
353
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
354 return true;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
355 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
356
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
357 bool
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
358 octave_complex_matrix::load_ascii (std::istream& is)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
359 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
360 bool success = true;
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
361
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
362 string_vector keywords(2);
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
363
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
364 keywords[0] = "ndims";
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
365 keywords[1] = "rows";
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
366
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
367 std::string kw;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5260
diff changeset
368 octave_idx_type val = 0;
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
369
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
370 if (extract_keyword (is, keywords, kw, val, true))
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
371 {
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
372 if (kw == "ndims")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
373 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
374 int mdims = static_cast<int> (val);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
375
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
376 if (mdims >= 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
377 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
378 dim_vector dv;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
379 dv.resize (mdims);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
380
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
381 for (int i = 0; i < mdims; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
382 is >> dv(i);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
383
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
384 if (is)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
385 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
386 ComplexNDArray tmp(dv);
6717
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
387
8999
dc07bc4157b8 allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
388 is >> tmp;
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
389
8999
dc07bc4157b8 allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
390 if (is)
dc07bc4157b8 allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
391 matrix = tmp;
dc07bc4157b8 allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
392 else
dc07bc4157b8 allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
393 {
dc07bc4157b8 allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
394 error ("load: failed to load matrix constant");
dc07bc4157b8 allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
395 success = false;
dc07bc4157b8 allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents: 8998
diff changeset
396 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
397 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
398 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
399 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
400 error ("load: failed to read dimensions");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
401 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
402 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
403 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
404 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
405 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
406 error ("load: failed to extract number of dimensions");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
407 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
408 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
409 }
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
410 else if (kw == "rows")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
411 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
412 octave_idx_type nr = val;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
413 octave_idx_type nc = 0;
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
414
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
415 if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
416 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
417 if (nr > 0 && nc > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
418 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
419 ComplexMatrix tmp (nr, nc);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
420 is >> tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
421 if (is)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
422 matrix = tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
423 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
424 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
425 error ("load: failed to load matrix constant");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
426 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
427 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
428 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
429 else if (nr == 0 || nc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
430 matrix = ComplexMatrix (nr, nc);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
431 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
432 panic_impossible ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
433 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
434 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
435 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
436 error ("load: failed to extract number of rows and columns");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
437 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
438 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
439 }
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
440 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
441 panic_impossible ();
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
442 }
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
443 else
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
444 {
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
445 error ("load: failed to extract number of rows and columns");
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
446 success = false;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
447 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
448
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
449 return success;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
450 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
451
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
452 bool
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
453 octave_complex_matrix::save_binary (std::ostream& os, bool& save_as_floats)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
454 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
455 dim_vector d = dims ();
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14557
diff changeset
456 if (d.length () < 1)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
457 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
458
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
459 // Use negative value for ndims to differentiate with old format!!
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14557
diff changeset
460 int32_t tmp = - d.length ();
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
461 os.write (reinterpret_cast<char *> (&tmp), 4);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5260
diff changeset
462 for (int i = 0; i < d.length (); i++)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
463 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
464 tmp = d(i);
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
465 os.write (reinterpret_cast<char *> (&tmp), 4);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
466 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
467
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
468 ComplexNDArray m = complex_array_value ();
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
469 save_type st = LS_DOUBLE;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
470 if (save_as_floats)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
471 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
472 if (m.too_large_for_float ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
473 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
474 warning ("save: some values too large to save as floats --");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
475 warning ("save: saving as doubles instead");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
476 }
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
477 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
478 st = LS_FLOAT;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
479 }
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
480 else if (d.numel () > 4096) // FIXME: make this configurable.
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
481 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
482 double max_val, min_val;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
483 if (m.all_integers (max_val, min_val))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
484 st = get_save_type (max_val, min_val);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
485 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
486
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
487
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
488 const Complex *mtmp = m.data ();
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
489 write_doubles (os, reinterpret_cast<const double *> (mtmp), st,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
490 2 * d.numel ());
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
491
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
492 return true;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
493 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
494
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
495 bool
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
496 octave_complex_matrix::load_binary (std::istream& is, bool swap,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
497 oct_mach_info::float_format fmt)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
498 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
499 char tmp;
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5781
diff changeset
500 int32_t mdims;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
501 if (! is.read (reinterpret_cast<char *> (&mdims), 4))
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
502 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
503 if (swap)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4923
diff changeset
504 swap_bytes<4> (&mdims);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
505 if (mdims < 0)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
506 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
507 mdims = - mdims;
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5781
diff changeset
508 int32_t di;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
509 dim_vector dv;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
510 dv.resize (mdims);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
511
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
512 for (int i = 0; i < mdims; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
513 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
514 if (! is.read (reinterpret_cast<char *> (&di), 4))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
515 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
516 if (swap)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
517 swap_bytes<4> (&di);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
518 dv(i) = di;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
519 }
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
520
5157
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
521 // Convert an array with a single dimension to be a row vector.
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
522 // Octave should never write files like this, other software
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
523 // might.
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
524
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
525 if (mdims == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
526 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
527 mdims = 2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
528 dv.resize (mdims);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
529 dv(1) = dv(0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
530 dv(0) = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
531 }
5157
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
532
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
533 if (! is.read (reinterpret_cast<char *> (&tmp), 1))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
534 return false;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
535
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
536 ComplexNDArray m(dv);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
537 Complex *im = m.fortran_vec ();
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
538 read_doubles (is, reinterpret_cast<double *> (im),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
539 static_cast<save_type> (tmp), 2 * dv.numel (), swap, fmt);
20587
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20484
diff changeset
540
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20484
diff changeset
541 if (! is)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
542 return false;
20587
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20484
diff changeset
543
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
544 matrix = m;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
545 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
546 else
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
547 {
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5781
diff changeset
548 int32_t nr, nc;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
549 nr = mdims;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
550 if (! is.read (reinterpret_cast<char *> (&nc), 4))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
551 return false;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
552 if (swap)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
553 swap_bytes<4> (&nc);
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
554 if (! is.read (reinterpret_cast<char *> (&tmp), 1))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
555 return false;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
556 ComplexMatrix m (nr, nc);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
557 Complex *im = m.fortran_vec ();
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5260
diff changeset
558 octave_idx_type len = nr * nc;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
559 read_doubles (is, reinterpret_cast<double *> (im),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
560 static_cast<save_type> (tmp), 2*len, swap, fmt);
20587
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20484
diff changeset
561
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20484
diff changeset
562 if (! is)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
563 return false;
20587
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20484
diff changeset
564
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
565 matrix = m;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
566 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
567 return true;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
568 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
569
19897
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: 19762
diff changeset
570 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: 19762
diff changeset
571 octave_complex_matrix::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: 19762
diff changeset
572 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: 19762
diff changeset
573 {
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
574 #if defined (HAVE_HDF5)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4923
diff changeset
575
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
576 dim_vector dv = dims ();
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
577 int empty = save_hdf5_empty (loc_id, name, dv);
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
578 if (empty)
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
579 return (empty > 0);
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
580
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
581 int rank = dv.length ();
18099
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17787
diff changeset
582 hid_t space_hid, data_hid, type_hid;
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17787
diff changeset
583 space_hid = data_hid = type_hid = -1;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
584 bool retval = true;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
585 ComplexNDArray m = complex_array_value ();
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
586
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
587 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
588
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
589 // Octave uses column-major, while HDF5 uses row-major ordering
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
590 for (int i = 0; i < rank; i++)
20253
b2100e1659ac maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents: 19897
diff changeset
591 hdims[i] = dv(rank-i-1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
592
4815
2eb844b27953 [project @ 2004-03-04 00:14:44 by jwe]
jwe
parents: 4805
diff changeset
593 space_hid = H5Screate_simple (rank, hdims, 0);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
594 if (space_hid < 0) return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
595
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
596 hid_t save_type_hid = H5T_NATIVE_DOUBLE;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
597
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
598 if (save_as_floats)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
599 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
600 if (m.too_large_for_float ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
601 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
602 warning ("save: some values too large to save as floats --");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
603 warning ("save: saving as doubles instead");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
604 }
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
605 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
606 save_type_hid = H5T_NATIVE_FLOAT;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
607 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
608 #if HAVE_HDF5_INT2FLOAT_CONVERSIONS
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
609 // hdf5 currently doesn't support float/integer conversions
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
610 else
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
611 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
612 double max_val, min_val;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
613
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
614 if (m.all_integers (max_val, min_val))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
615 save_type_hid
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
616 = save_type_to_hdf5 (get_save_type (max_val, min_val));
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
617 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
618 #endif /* HAVE_HDF5_INT2FLOAT_CONVERSIONS */
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
619
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
620 type_hid = hdf5_make_complex_type (save_type_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
621 if (type_hid < 0)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
622 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
623 H5Sclose (space_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
624 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
625 }
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
626 #if HAVE_HDF5_18
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
627 data_hid = H5Dcreate (loc_id, name, type_hid, space_hid,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
628 H5P_DEFAULT, H5P_DEFAULT, 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
629 #else
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
630 data_hid = H5Dcreate (loc_id, name, type_hid, space_hid, 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
631 #endif
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
632 if (data_hid < 0)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
633 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
634 H5Sclose (space_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
635 H5Tclose (type_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
636 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
637 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
638
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
639 hid_t complex_type_hid = hdf5_make_complex_type (H5T_NATIVE_DOUBLE);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
640 if (complex_type_hid < 0) retval = false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
641
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
642 if (retval)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
643 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
644 Complex *mtmp = m.fortran_vec ();
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
645 if (H5Dwrite (data_hid, complex_type_hid, H5S_ALL, H5S_ALL, H5P_DEFAULT,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
646 mtmp) < 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
647 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
648 H5Tclose (complex_type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
649 retval = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
650 }
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
651 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
652
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
653 H5Tclose (complex_type_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
654 H5Dclose (data_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
655 H5Tclose (type_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
656 H5Sclose (space_hid);
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
657
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
658 return retval;
19897
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: 19762
diff changeset
659
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: 19762
diff changeset
660 #else
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: 19762
diff changeset
661 gripe_save ("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: 19762
diff changeset
662 return 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: 19762
diff changeset
663 #endif
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
664 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
665
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
666 bool
19897
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: 19762
diff changeset
667 octave_complex_matrix::load_hdf5 (octave_hdf5_id loc_id, const char *name)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
668 {
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
669 bool retval = false;
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
670
19897
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: 19762
diff changeset
671 #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: 19762
diff changeset
672
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
673 dim_vector dv;
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
674 int empty = load_hdf5_empty (loc_id, name, dv);
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
675 if (empty > 0)
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
676 matrix.resize (dv);
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
677 if (empty)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
678 return (empty > 0);
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
679
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
680 #if HAVE_HDF5_18
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
681 hid_t data_hid = H5Dopen (loc_id, name, H5P_DEFAULT);
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
682 #else
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
683 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
684 #endif
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
685 hid_t type_hid = H5Dget_type (data_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
686
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
687 hid_t complex_type = hdf5_make_complex_type (H5T_NATIVE_DOUBLE);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
688
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
689 if (! hdf5_types_compatible (type_hid, complex_type))
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
690 {
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
691 H5Tclose (complex_type);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
692 H5Dclose (data_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
693 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
694 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
695
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
696 hid_t space_id = H5Dget_space (data_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
697
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
698 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
699
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
700 if (rank < 1)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
701 {
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
702 H5Tclose (complex_type);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
703 H5Sclose (space_id);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
704 H5Dclose (data_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
705 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
706 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
707
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
708 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
709 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
710
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
711 H5Sget_simple_extent_dims (space_id, hdims, maxdims);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
712
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
713 // Octave uses column-major, while HDF5 uses row-major ordering
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
714 if (rank == 1)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
715 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
716 dv.resize (2);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
717 dv(0) = 1;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
718 dv(1) = hdims[0];
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
719 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
720 else
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
721 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
722 dv.resize (rank);
4815
2eb844b27953 [project @ 2004-03-04 00:14:44 by jwe]
jwe
parents: 4805
diff changeset
723 for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
724 dv(j) = hdims[i];
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
725 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
726
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
727 ComplexNDArray m (dv);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
728 Complex *reim = m.fortran_vec ();
4815
2eb844b27953 [project @ 2004-03-04 00:14:44 by jwe]
jwe
parents: 4805
diff changeset
729 if (H5Dread (data_hid, complex_type, H5S_ALL, H5S_ALL, H5P_DEFAULT,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
730 reim) >= 0)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
731 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
732 retval = true;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
733 matrix = m;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
734 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
735
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
736 H5Tclose (complex_type);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
737 H5Sclose (space_id);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
738 H5Dclose (data_hid);
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
739
19897
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: 19762
diff changeset
740 #else
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: 19762
diff changeset
741 gripe_load ("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: 19762
diff changeset
742 #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: 19762
diff changeset
743
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
744 return retval;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
745 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4923
diff changeset
746
4643
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
747 void
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
748 octave_complex_matrix::print_raw (std::ostream& os,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
749 bool pr_as_read_syntax) const
4643
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
750 {
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
751 octave_print_internal (os, matrix, pr_as_read_syntax,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
752 current_print_indent_level ());
4643
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
753 }
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
754
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
755 mxArray *
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
756 octave_complex_matrix::as_mxArray (void) const
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
757 {
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
758 mxArray *retval = new mxArray (mxDOUBLE_CLASS, dims (), mxCOMPLEX);
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
759
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
760 double *pr = static_cast<double *> (retval->get_data ());
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
761 double *pi = static_cast<double *> (retval->get_imag_data ());
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
762
6686
2aad75fcc93a [project @ 2007-06-03 20:58:28 by dbateman]
dbateman
parents: 5958
diff changeset
763 mwSize nel = numel ();
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
764
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
765 const Complex *p = matrix.data ();
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
766
6686
2aad75fcc93a [project @ 2007-06-03 20:58:28 by dbateman]
dbateman
parents: 5958
diff changeset
767 for (mwIndex i = 0; i < nel; i++)
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
768 {
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
769 pr[i] = std::real (p[i]);
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
770 pi[i] = std::imag (p[i]);
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
771 }
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
772
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
773 return retval;
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
774 }
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
775
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
776 octave_value
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
777 octave_complex_matrix::map (unary_mapper_t umap) const
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
778 {
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
779 switch (umap)
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
780 {
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
781 // Mappers handled specially.
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
782 case umap_real:
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
783 return ::real (matrix);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
784 case umap_imag:
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
785 return ::imag (matrix);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
786 case umap_conj:
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
787 return ::conj (matrix);
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
788
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
789 #define ARRAY_METHOD_MAPPER(UMAP, FCN) \
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
790 case umap_ ## UMAP: \
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
791 return octave_value (matrix.FCN ())
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
792
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
793 ARRAY_METHOD_MAPPER (abs, abs);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
794 ARRAY_METHOD_MAPPER (isnan, isnan);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
795 ARRAY_METHOD_MAPPER (isinf, isinf);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
796 ARRAY_METHOD_MAPPER (finite, isfinite);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
797
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
798 #define ARRAY_MAPPER(UMAP, TYPE, FCN) \
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
799 case umap_ ## UMAP: \
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
800 return octave_value (matrix.map<TYPE> (FCN))
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
801
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
802 ARRAY_MAPPER (acos, Complex, ::acos);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
803 ARRAY_MAPPER (acosh, Complex, ::acosh);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
804 ARRAY_MAPPER (angle, double, std::arg);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
805 ARRAY_MAPPER (arg, double, std::arg);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
806 ARRAY_MAPPER (asin, Complex, ::asin);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
807 ARRAY_MAPPER (asinh, Complex, ::asinh);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
808 ARRAY_MAPPER (atan, Complex, ::atan);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
809 ARRAY_MAPPER (atanh, Complex, ::atanh);
15696
2fac72a256ce Add complex erf,erfc,erfcx,erfi,dawson routines from Faddeeva package.
Steven G. Johnson <stevenj@alum.mit.edu>
parents: 15195
diff changeset
810 ARRAY_MAPPER (erf, Complex, ::erf);
2fac72a256ce Add complex erf,erfc,erfcx,erfi,dawson routines from Faddeeva package.
Steven G. Johnson <stevenj@alum.mit.edu>
parents: 15195
diff changeset
811 ARRAY_MAPPER (erfc, Complex, ::erfc);
2fac72a256ce Add complex erf,erfc,erfcx,erfi,dawson routines from Faddeeva package.
Steven G. Johnson <stevenj@alum.mit.edu>
parents: 15195
diff changeset
812 ARRAY_MAPPER (erfcx, Complex, ::erfcx);
2fac72a256ce Add complex erf,erfc,erfcx,erfi,dawson routines from Faddeeva package.
Steven G. Johnson <stevenj@alum.mit.edu>
parents: 15195
diff changeset
813 ARRAY_MAPPER (erfi, Complex, ::erfi);
2fac72a256ce Add complex erf,erfc,erfcx,erfi,dawson routines from Faddeeva package.
Steven G. Johnson <stevenj@alum.mit.edu>
parents: 15195
diff changeset
814 ARRAY_MAPPER (dawson, Complex, ::dawson);
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
815 ARRAY_MAPPER (ceil, Complex, ::ceil);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
816 ARRAY_MAPPER (cos, Complex, std::cos);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
817 ARRAY_MAPPER (cosh, Complex, std::cosh);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
818 ARRAY_MAPPER (exp, Complex, std::exp);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
819 ARRAY_MAPPER (expm1, Complex, ::expm1);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
820 ARRAY_MAPPER (fix, Complex, ::fix);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
821 ARRAY_MAPPER (floor, Complex, ::floor);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
822 ARRAY_MAPPER (log, Complex, std::log);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
823 ARRAY_MAPPER (log2, Complex, xlog2);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
824 ARRAY_MAPPER (log10, Complex, std::log10);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
825 ARRAY_MAPPER (log1p, Complex, ::log1p);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
826 ARRAY_MAPPER (round, Complex, xround);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
827 ARRAY_MAPPER (roundb, Complex, xroundb);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
828 ARRAY_MAPPER (signum, Complex, ::signum);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
829 ARRAY_MAPPER (sin, Complex, std::sin);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
830 ARRAY_MAPPER (sinh, Complex, std::sinh);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
831 ARRAY_MAPPER (sqrt, Complex, std::sqrt);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
832 ARRAY_MAPPER (tan, Complex, std::tan);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
833 ARRAY_MAPPER (tanh, Complex, std::tanh);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
834 ARRAY_MAPPER (isna, bool, octave_is_NA);
8650
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
835
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
836 default:
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
837 return octave_base_value::map (umap);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 8999
diff changeset
838 }
8998
a48fba01e4ac optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
839 }