annotate src/ov-cx-mat.cc @ 8650:a1ae2aae903e

abs,real,imag,conj: use code from mx-inlines rather than the generic map
author Jaroslav Hajek <highegg@gmail.com>
date Mon, 02 Feb 2009 15:35:32 +0100
parents f00578b495e9
children 280fae940bb0
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
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005,
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
4 2006, 2007 John W. Eaton
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"
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
40 #include "oct-obj.h"
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4923
diff changeset
41 #include "oct-stream.h"
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
42 #include "ops.h"
3219
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents: 3109
diff changeset
43 #include "ov-base.h"
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents: 3109
diff changeset
44 #include "ov-base-mat.h"
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents: 3109
diff changeset
45 #include "ov-base-mat.cc"
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
46 #include "ov-complex.h"
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
47 #include "ov-cx-mat.h"
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
48 #include "ov-flt-cx-mat.h"
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
49 #include "ov-re-mat.h"
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
50 #include "ov-scalar.h"
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
51 #include "pr-output.h"
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
52
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
53 #include "byte-swap.h"
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
54 #include "ls-oct-ascii.h"
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
55 #include "ls-hdf5.h"
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
56 #include "ls-utils.h"
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
57
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4455
diff changeset
58 template class octave_base_matrix<ComplexNDArray>;
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
59
3219
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents: 3109
diff changeset
60 DEFINE_OCTAVE_ALLOCATOR (octave_complex_matrix);
2477
3d905d3820a4 [project @ 1996-11-07 16:46:11 by jwe]
jwe
parents: 2466
diff changeset
61
4612
d44675070f1a [project @ 2003-11-14 19:49:56 by jwe]
jwe
parents: 4513
diff changeset
62 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_complex_matrix,
d44675070f1a [project @ 2003-11-14 19:49:56 by jwe]
jwe
parents: 4513
diff changeset
63 "complex matrix", "double");
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
64
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
65 static octave_base_value *
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
66 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
67 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
68 CAST_CONV_ARG (const octave_complex_matrix&);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
69
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
70 return new octave_float_complex_matrix (v.float_complex_matrix_value ());
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
71 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
72
8345
c777f3ce02d8 smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8290
diff changeset
73 octave_base_value::type_conv_info
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
74 octave_complex_matrix::numeric_demotion_function (void) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
75 {
8345
c777f3ce02d8 smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8290
diff changeset
76 return octave_base_value::type_conv_info(default_numeric_demotion_function,
c777f3ce02d8 smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 8290
diff changeset
77 octave_float_complex_matrix::static_type_id ());
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
78 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
79
5759
ce79d238f142 [project @ 2006-04-13 13:04:32 by jwe]
jwe
parents: 5450
diff changeset
80 octave_base_value *
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
81 octave_complex_matrix::try_narrowing_conversion (void)
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
82 {
5759
ce79d238f142 [project @ 2006-04-13 13:04:32 by jwe]
jwe
parents: 5450
diff changeset
83 octave_base_value *retval = 0;
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
84
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4455
diff changeset
85 if (matrix.ndims () == 2)
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4455
diff changeset
86 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4455
diff changeset
87 ComplexMatrix cm = matrix.matrix_value ();
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
88
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5260
diff changeset
89 octave_idx_type nr = cm.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5260
diff changeset
90 octave_idx_type nc = cm.cols ();
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4455
diff changeset
91
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4455
diff changeset
92 if (nr == 1 && nc == 1)
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4455
diff changeset
93 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4455
diff changeset
94 Complex c = matrix (0, 0);
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
95
5450
6b42c78c77d3 [project @ 2005-09-15 15:36:26 by jwe]
jwe
parents: 5307
diff changeset
96 double im = std::imag (c);
6b42c78c77d3 [project @ 2005-09-15 15:36:26 by jwe]
jwe
parents: 5307
diff changeset
97
6b42c78c77d3 [project @ 2005-09-15 15:36:26 by jwe]
jwe
parents: 5307
diff changeset
98 if (im == 0.0 && ! lo_ieee_signbit (im))
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4455
diff changeset
99 retval = new octave_scalar (std::real (c));
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4455
diff changeset
100 else
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4455
diff changeset
101 retval = new octave_complex (c);
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4455
diff changeset
102 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4455
diff changeset
103 else if (nr == 0 || nc == 0)
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4455
diff changeset
104 retval = new octave_matrix (Matrix (nr, nc));
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4455
diff changeset
105 else if (cm.all_elements_are_real ())
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4455
diff changeset
106 retval = new octave_matrix (::real (cm));
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
107 }
4923
b11223097ad4 [project @ 2004-08-02 16:33:11 by jwe]
jwe
parents: 4837
diff changeset
108 else if (matrix.all_elements_are_real ())
b11223097ad4 [project @ 2004-08-02 16:33:11 by jwe]
jwe
parents: 4837
diff changeset
109 retval = new octave_matrix (::real (matrix));
2410
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
110
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
111 return retval;
367485171742 [project @ 1996-10-15 16:50:27 by jwe]
jwe
parents: 2407
diff changeset
112 }
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
113
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
114 void
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
115 octave_complex_matrix::assign (const octave_value_list& idx,
4686
c7ae43dfdea4 [project @ 2004-01-06 19:29:23 by jwe]
jwe
parents: 4643
diff changeset
116 const ComplexNDArray& rhs)
4418
c57f599bf7ea [project @ 2003-05-25 19:13:57 by jwe]
jwe
parents: 4192
diff changeset
117 {
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4455
diff changeset
118 octave_base_matrix<ComplexNDArray>::assign (idx, rhs);
4418
c57f599bf7ea [project @ 2003-05-25 19:13:57 by jwe]
jwe
parents: 4192
diff changeset
119 }
c57f599bf7ea [project @ 2003-05-25 19:13:57 by jwe]
jwe
parents: 4192
diff changeset
120
c57f599bf7ea [project @ 2003-05-25 19:13:57 by jwe]
jwe
parents: 4192
diff changeset
121 void
c57f599bf7ea [project @ 2003-05-25 19:13:57 by jwe]
jwe
parents: 4192
diff changeset
122 octave_complex_matrix::assign (const octave_value_list& idx,
4686
c7ae43dfdea4 [project @ 2004-01-06 19:29:23 by jwe]
jwe
parents: 4643
diff changeset
123 const NDArray& rhs)
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
124 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5260
diff changeset
125 octave_idx_type len = idx.length ();
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
126
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
127 Array<idx_vector> ra_idx (len);
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
128
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5260
diff changeset
129 for (octave_idx_type i = 0; i < len; i++)
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
130 ra_idx(i) = idx(i).index_vector ();
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
131
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
132 matrix.assign (ra_idx, rhs);
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
133 }
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
134
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
135 double
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
136 octave_complex_matrix::double_value (bool force_conversion) const
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
137 {
4102
cbac6756967e [project @ 2002-10-14 20:16:44 by jwe]
jwe
parents: 4066
diff changeset
138 double retval = lo_ieee_nan_value ();
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
139
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
140 if (! force_conversion)
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
141 gripe_implicit_conversion ("Octave:imag-to-real",
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
142 "complex matrix", "real scalar");
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
143
4455
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4451
diff changeset
144 if (rows () > 0 && columns () > 0)
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4451
diff changeset
145 {
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
146 gripe_implicit_conversion ("Octave:array-as-scalar",
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
147 "complex matrix", "real scalar");
4455
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4451
diff changeset
148
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4451
diff changeset
149 retval = std::real (matrix (0, 0));
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4451
diff changeset
150 }
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
151 else
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
152 gripe_invalid_conversion ("complex matrix", "real scalar");
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
153
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
154 return retval;
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
155 }
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
156
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
157 float
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
158 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
159 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
160 float retval = lo_ieee_float_nan_value ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
161
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
162 if (! force_conversion)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
163 gripe_implicit_conversion ("Octave:imag-to-real",
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
164 "complex matrix", "real scalar");
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
165
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
166 if (rows () > 0 && columns () > 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
167 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
168 gripe_implicit_conversion ("Octave:array-as-scalar",
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
169 "complex matrix", "real scalar");
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
170
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
171 retval = std::real (matrix (0, 0));
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
172 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
173 else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
174 gripe_invalid_conversion ("complex matrix", "real scalar");
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
175
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
176 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
177 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
178
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
179 Matrix
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
180 octave_complex_matrix::matrix_value (bool force_conversion) const
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
181 {
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
182 Matrix retval;
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
183
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
184 if (! force_conversion)
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
185 gripe_implicit_conversion ("Octave:imag-to-real",
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
186 "complex matrix", "real matrix");
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
187
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4455
diff changeset
188 retval = ::real (matrix.matrix_value ());
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
189
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
190 return retval;
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
191 }
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
192
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
193 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
194 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
195 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
196 FloatMatrix retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
197
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
198 if (! force_conversion)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
199 gripe_implicit_conversion ("Octave:imag-to-real",
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
200 "complex matrix", "real matrix");
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
201
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
202 retval = ::real (matrix.matrix_value ());
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
203
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
204 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
205 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
206
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
207 Complex
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
208 octave_complex_matrix::complex_value (bool) const
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
209 {
4102
cbac6756967e [project @ 2002-10-14 20:16:44 by jwe]
jwe
parents: 4066
diff changeset
210 double tmp = lo_ieee_nan_value ();
cbac6756967e [project @ 2002-10-14 20:16:44 by jwe]
jwe
parents: 4066
diff changeset
211
cbac6756967e [project @ 2002-10-14 20:16:44 by jwe]
jwe
parents: 4066
diff changeset
212 Complex retval (tmp, tmp);
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
213
4455
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4451
diff changeset
214 if (rows () > 0 && columns () > 0)
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4451
diff changeset
215 {
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
216 gripe_implicit_conversion ("Octave:array-as-scalar",
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
217 "complex matrix", "complex scalar");
4455
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4451
diff changeset
218
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4451
diff changeset
219 retval = matrix (0, 0);
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4451
diff changeset
220 }
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
221 else
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
222 gripe_invalid_conversion ("complex matrix", "complex scalar");
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
223
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
224 return retval;
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
225 }
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
226
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
227 FloatComplex
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
228 octave_complex_matrix::float_complex_value (bool) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
229 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
230 float tmp = lo_ieee_float_nan_value ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
231
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
232 FloatComplex retval (tmp, tmp);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
233
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
234 if (rows () > 0 && columns () > 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
235 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
236 gripe_implicit_conversion ("Octave:array-as-scalar",
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
237 "complex matrix", "complex scalar");
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 retval = matrix (0, 0);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
240 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
241 else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
242 gripe_invalid_conversion ("complex matrix", "complex scalar");
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
243
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
244 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
245 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
246
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
247 ComplexMatrix
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
248 octave_complex_matrix::complex_matrix_value (bool) const
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
249 {
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4455
diff changeset
250 return matrix.matrix_value ();
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
251 }
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
252
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
253 FloatComplexMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
254 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
255 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
256 return FloatComplexMatrix (matrix.matrix_value ());
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
257 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
258
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
259 charNDArray
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
260 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
261 {
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
262 charNDArray retval;
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
263
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
264 if (! frc_str_conv)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
265 gripe_implicit_conversion ("Octave:num-to-str",
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
266 "complex matrix", "string");
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
267 else
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 retval = charNDArray (dims ());
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
270 octave_idx_type nel = numel ();
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
271
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
272 for (octave_idx_type i = 0; i < nel; i++)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
273 retval.elem (i) = static_cast<char>(std::real (matrix.elem (i)));
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
274 }
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
275
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
276 return retval;
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
277 }
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
278
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
279 FloatComplexNDArray
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
280 octave_complex_matrix::float_complex_array_value (bool) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
281 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
282 return FloatComplexNDArray (matrix);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
283 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7740
diff changeset
284
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
285 SparseMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
286 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
287 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
288 SparseMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
289
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
290 if (! force_conversion)
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
291 gripe_implicit_conversion ("Octave:imag-to-real",
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
292 "complex matrix", "real matrix");
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
293
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
294 retval = SparseMatrix (::real (matrix.matrix_value ()));
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
295
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
296 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
297 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
298
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
299 SparseComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
300 octave_complex_matrix::sparse_complex_matrix_value (bool) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
301 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
302 return SparseComplexMatrix (matrix.matrix_value ());
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
303 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5157
diff changeset
304
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
305 octave_value
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
306 octave_complex_matrix::diag (octave_idx_type k) const
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 octave_value retval;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
309 if (k == 0 && matrix.ndims () == 2
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
310 && (matrix.rows () == 1 || matrix.columns () == 1))
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
311 retval = ComplexDiagMatrix (DiagArray2<Complex> (matrix));
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
312 else
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
313 retval = octave_base_matrix<ComplexNDArray>::diag (k);
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
314
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
315 return retval;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
316 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8345
diff changeset
317
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
318 bool
6974
9e32bb109980 [project @ 2007-10-08 11:06:47 by jwe]
jwe
parents: 6717
diff changeset
319 octave_complex_matrix::save_ascii (std::ostream& os)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
320 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
321 dim_vector d = dims ();
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
322 if (d.length () > 2)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
323 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
324 ComplexNDArray tmp = complex_array_value ();
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
325
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
326 os << "# ndims: " << d.length () << "\n";
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
327
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5260
diff changeset
328 for (int i = 0; i < d.length (); i++)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
329 os << " " << d (i);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
330
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
331 os << "\n" << tmp;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
332 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
333 else
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 // Keep this case, rather than use generic code above for backward
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
336 // compatiability. Makes load_ascii much more complex!!
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
337 os << "# rows: " << rows () << "\n"
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
338 << "# columns: " << columns () << "\n";
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
339
5958
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5956
diff changeset
340 os << complex_matrix_value ();
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
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
343 return true;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
344 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
345
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
346 bool
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
347 octave_complex_matrix::load_ascii (std::istream& is)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
348 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
349 bool success = true;
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
350
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
351 string_vector keywords(2);
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
352
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
353 keywords[0] = "ndims";
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
354 keywords[1] = "rows";
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
355
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
356 std::string kw;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5260
diff changeset
357 octave_idx_type val = 0;
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
358
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
359 if (extract_keyword (is, keywords, kw, val, true))
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
360 {
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
361 if (kw == "ndims")
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
362 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5260
diff changeset
363 int mdims = static_cast<int> (val);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
364
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
365 if (mdims >= 0)
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 dim_vector dv;
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
368 dv.resize (mdims);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
369
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
370 for (int i = 0; i < mdims; i++)
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
371 is >> dv(i);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
372
6717
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
373 if (is)
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
374 {
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
375 ComplexNDArray tmp(dv);
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
376
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
377 if (tmp.is_empty ())
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
378 matrix = tmp;
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
379 else
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
380 {
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
381 is >> tmp;
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
382
6717
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
383 if (is)
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
384 matrix = tmp;
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
385 else
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
386 {
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
387 error ("load: failed to load matrix constant");
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
388 success = false;
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
389 }
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
390 }
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
391 }
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
392 else
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
393 {
6717
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
394 error ("load: failed to read dimensions");
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
395 success = false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
396 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
397 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
398 else
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
399 {
6717
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
400 error ("load: failed to extract number of dimensions");
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
401 success = false;
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
402 }
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
403 }
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
404 else if (kw == "rows")
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
405 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5260
diff changeset
406 octave_idx_type nr = val;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5260
diff changeset
407 octave_idx_type nc = 0;
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
408
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
409 if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0)
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
410 {
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
411 if (nr > 0 && nc > 0)
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
412 {
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
413 ComplexMatrix tmp (nr, nc);
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
414 is >> tmp;
6717
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
415 if (is)
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
416 matrix = tmp;
b319df52ba87 [project @ 2007-06-13 20:25:53 by jwe]
jwe
parents: 6686
diff changeset
417 else
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
418 {
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
419 error ("load: failed to load matrix constant");
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
420 success = false;
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
421 }
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
422 }
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
423 else if (nr == 0 || nc == 0)
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
424 matrix = ComplexMatrix (nr, nc);
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
425 else
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
426 panic_impossible ();
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
427 }
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
428 else
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
429 {
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
430 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
431 success = false;
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
432 }
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
433 }
5099
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
434 else
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
435 panic_impossible ();
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
436 }
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
437 else
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
438 {
f7e39f977fe8 [project @ 2004-12-24 19:06:01 by jwe]
jwe
parents: 4944
diff changeset
439 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
440 success = false;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
441 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
442
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
443 return success;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
444 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
445
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
446 bool
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
447 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
448 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
449 dim_vector d = dims ();
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
450 if (d.length() < 1)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
451 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
452
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
453 // Use negative value for ndims to differentiate with old format!!
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5781
diff changeset
454 int32_t tmp = - d.length();
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
455 os.write (reinterpret_cast<char *> (&tmp), 4);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5260
diff changeset
456 for (int i = 0; i < d.length (); i++)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
457 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
458 tmp = d(i);
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
459 os.write (reinterpret_cast<char *> (&tmp), 4);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
460 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
461
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
462 ComplexNDArray m = complex_array_value ();
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
463 save_type st = LS_DOUBLE;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
464 if (save_as_floats)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
465 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
466 if (m.too_large_for_float ())
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 warning ("save: some values too large to save as floats --");
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
469 warning ("save: saving as doubles instead");
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
470 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
471 else
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
472 st = LS_FLOAT;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
473 }
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5760
diff changeset
474 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
475 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
476 double max_val, min_val;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
477 if (m.all_integers (max_val, min_val))
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
478 st = get_save_type (max_val, min_val);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
479 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
480
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 const Complex *mtmp = m.data ();
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
483 write_doubles (os, reinterpret_cast<const double *> (mtmp), st, 2 * d.numel ());
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
484
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
485 return true;
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 bool
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
489 octave_complex_matrix::load_binary (std::istream& is, bool swap,
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
490 oct_mach_info::float_format fmt)
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 char tmp;
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5781
diff changeset
493 int32_t mdims;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
494 if (! is.read (reinterpret_cast<char *> (&mdims), 4))
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
495 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
496 if (swap)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4923
diff changeset
497 swap_bytes<4> (&mdims);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
498 if (mdims < 0)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
499 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
500 mdims = - mdims;
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5781
diff changeset
501 int32_t di;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
502 dim_vector dv;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
503 dv.resize (mdims);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
504
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
505 for (int i = 0; i < mdims; i++)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
506 {
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
507 if (! is.read (reinterpret_cast<char *> (&di), 4))
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
508 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
509 if (swap)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4923
diff changeset
510 swap_bytes<4> (&di);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
511 dv(i) = di;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
512 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
513
5157
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
514 // 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
515 // Octave should never write files like this, other software
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
516 // might.
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
517
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
518 if (mdims == 1)
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
519 {
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
520 mdims = 2;
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
521 dv.resize (mdims);
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
522 dv(1) = dv(0);
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
523 dv(0) = 1;
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
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
526 if (! is.read (reinterpret_cast<char *> (&tmp), 1))
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
527 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
528
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
529 ComplexNDArray m(dv);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
530 Complex *im = m.fortran_vec ();
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
531 read_doubles (is, reinterpret_cast<double *> (im),
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
532 static_cast<save_type> (tmp), 2 * dv.numel (), swap, fmt);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
533 if (error_state || ! is)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
534 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
535 matrix = m;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
536 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
537 else
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
538 {
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5781
diff changeset
539 int32_t nr, nc;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
540 nr = mdims;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
541 if (! is.read (reinterpret_cast<char *> (&nc), 4))
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
542 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
543 if (swap)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4923
diff changeset
544 swap_bytes<4> (&nc);
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
545 if (! is.read (reinterpret_cast<char *> (&tmp), 1))
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
546 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
547 ComplexMatrix m (nr, nc);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
548 Complex *im = m.fortran_vec ();
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5260
diff changeset
549 octave_idx_type len = nr * nc;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
550 read_doubles (is, reinterpret_cast<double *> (im),
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
551 static_cast<save_type> (tmp), 2*len, swap, fmt);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
552 if (error_state || ! is)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
553 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
554 matrix = m;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
555 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
556 return true;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
557 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
558
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
559 #if defined (HAVE_HDF5)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4923
diff changeset
560
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
561 bool
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
562 octave_complex_matrix::save_hdf5 (hid_t loc_id, const char *name,
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
563 bool save_as_floats)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
564 {
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
565 dim_vector dv = dims ();
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
566 int empty = save_hdf5_empty (loc_id, name, dv);
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
567 if (empty)
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
568 return (empty > 0);
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
569
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
570 int rank = dv.length ();
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
571 hid_t space_hid = -1, data_hid = -1, type_hid = -1;
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
572 bool retval = true;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
573 ComplexNDArray m = complex_array_value ();
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
574
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
575 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
576
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
577 // 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
578 for (int i = 0; i < rank; i++)
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
579 hdims[i] = dv (rank-i-1);
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
580
4815
2eb844b27953 [project @ 2004-03-04 00:14:44 by jwe]
jwe
parents: 4805
diff changeset
581 space_hid = H5Screate_simple (rank, hdims, 0);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
582 if (space_hid < 0) return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
583
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
584 hid_t save_type_hid = H5T_NATIVE_DOUBLE;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
585
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
586 if (save_as_floats)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
587 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
588 if (m.too_large_for_float ())
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
589 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
590 warning ("save: some values too large to save as floats --");
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
591 warning ("save: saving as doubles instead");
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
592 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
593 else
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
594 save_type_hid = H5T_NATIVE_FLOAT;
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 #if HAVE_HDF5_INT2FLOAT_CONVERSIONS
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
597 // hdf5 currently doesn't support float/integer conversions
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
598 else
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 double max_val, min_val;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
601
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
602 if (m.all_integers (max_val, min_val))
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
603 save_type_hid
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
604 = save_type_to_hdf5 (get_save_type (max_val, min_val));
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
605 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
606 #endif /* HAVE_HDF5_INT2FLOAT_CONVERSIONS */
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 type_hid = hdf5_make_complex_type (save_type_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
609 if (type_hid < 0)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
610 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
611 H5Sclose (space_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
612 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
613 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
614
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
615 data_hid = H5Dcreate (loc_id, name, type_hid, space_hid, H5P_DEFAULT);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
616 if (data_hid < 0)
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 H5Sclose (space_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
619 H5Tclose (type_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
620 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
621 }
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 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
624 if (complex_type_hid < 0) retval = false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
625
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
626 if (retval)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
627 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
628 Complex *mtmp = m.fortran_vec ();
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
629 if (H5Dwrite (data_hid, complex_type_hid, H5S_ALL, H5S_ALL, H5P_DEFAULT,
4815
2eb844b27953 [project @ 2004-03-04 00:14:44 by jwe]
jwe
parents: 4805
diff changeset
630 mtmp) < 0)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
631 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
632 H5Tclose (complex_type_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
633 retval = false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
634 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
635 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
636
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
637 H5Tclose (complex_type_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
638 H5Dclose (data_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
639 H5Tclose (type_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
640 H5Sclose (space_hid);
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
641
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
642 return 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
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
645 bool
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
646 octave_complex_matrix::load_hdf5 (hid_t loc_id, const char *name,
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
647 bool /* have_h5giterate_bug */)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
648 {
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
649 bool retval = false;
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
650
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
651 dim_vector dv;
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
652 int empty = load_hdf5_empty (loc_id, name, dv);
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
653 if (empty > 0)
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
654 matrix.resize(dv);
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
655 if (empty)
4805
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
656 return (empty > 0);
b0d6da24caeb [project @ 2004-03-02 03:43:15 by jwe]
jwe
parents: 4726
diff changeset
657
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
658 hid_t data_hid = H5Dopen (loc_id, name);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
659 hid_t type_hid = H5Dget_type (data_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
660
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
661 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
662
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
663 if (! hdf5_types_compatible (type_hid, complex_type))
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
664 {
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
665 H5Tclose (complex_type);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
666 H5Dclose (data_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
667 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
668 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
669
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
670 hid_t space_id = H5Dget_space (data_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
671
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
672 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
673
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
674 if (rank < 1)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
675 {
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
676 H5Tclose (complex_type);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
677 H5Sclose (space_id);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
678 H5Dclose (data_hid);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
679 return false;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
680 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
681
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
682 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
683 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
684
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
685 H5Sget_simple_extent_dims (space_id, hdims, maxdims);
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 // 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
688 if (rank == 1)
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
689 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
690 dv.resize (2);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
691 dv(0) = 1;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
692 dv(1) = hdims[0];
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
693 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
694 else
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 dv.resize (rank);
4815
2eb844b27953 [project @ 2004-03-04 00:14:44 by jwe]
jwe
parents: 4805
diff changeset
697 for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
698 dv(j) = hdims[i];
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
699 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
700
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
701 ComplexNDArray m (dv);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
702 Complex *reim = m.fortran_vec ();
4815
2eb844b27953 [project @ 2004-03-04 00:14:44 by jwe]
jwe
parents: 4805
diff changeset
703 if (H5Dread (data_hid, complex_type, H5S_ALL, H5S_ALL, H5P_DEFAULT,
2eb844b27953 [project @ 2004-03-04 00:14:44 by jwe]
jwe
parents: 4805
diff changeset
704 reim) >= 0)
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
705 {
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
706 retval = true;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
707 matrix = m;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
708 }
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
709
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
710 H5Tclose (complex_type);
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
711 H5Sclose (space_id);
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
712 H5Dclose (data_hid);
4837
81f78a2ff8a6 [project @ 2004-03-12 19:13:01 by jwe]
jwe
parents: 4815
diff changeset
713
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
714 return retval;
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
715 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4923
diff changeset
716
4687
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
717 #endif
e95c86d48732 [project @ 2004-01-06 21:53:34 by jwe]
jwe
parents: 4686
diff changeset
718
4643
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
719 void
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
720 octave_complex_matrix::print_raw (std::ostream& os,
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
721 bool pr_as_read_syntax) const
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
722 {
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
723 octave_print_internal (os, matrix, pr_as_read_syntax,
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
724 current_print_indent_level ());
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
725 }
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
726
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
727 mxArray *
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
728 octave_complex_matrix::as_mxArray (void) const
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
729 {
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
730 mxArray *retval = new mxArray (mxDOUBLE_CLASS, dims (), mxCOMPLEX);
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
731
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
732 double *pr = static_cast<double *> (retval->get_data ());
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
733 double *pi = static_cast<double *> (retval->get_imag_data ());
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
734
6686
2aad75fcc93a [project @ 2007-06-03 20:58:28 by dbateman]
dbateman
parents: 5958
diff changeset
735 mwSize nel = numel ();
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
736
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
737 const Complex *p = matrix.data ();
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
738
6686
2aad75fcc93a [project @ 2007-06-03 20:58:28 by dbateman]
dbateman
parents: 5958
diff changeset
739 for (mwIndex i = 0; i < nel; i++)
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
740 {
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
741 pr[i] = std::real (p[i]);
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
742 pi[i] = std::imag (p[i]);
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
743 }
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
744
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
745 return retval;
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
746 }
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5828
diff changeset
747
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
748 static double
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
749 xabs (const Complex& x)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
750 {
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
751 return (xisinf (x.real ()) || xisinf (x.imag ())) ? octave_Inf : abs (x);
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
752 }
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
753
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
754 static double
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
755 ximag (const Complex& x)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
756 {
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
757 return x.imag ();
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
758 }
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
759
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
760 static double
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
761 xreal (const Complex& x)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
762 {
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
763 return x.real ();
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
764 }
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
765
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
766 static bool
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
767 any_element_less_than (const NDArray& a, double val)
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
768 {
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
769 octave_idx_type len = a.length ();
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
770 const double *m = a.fortran_vec ();
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
771
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
772 for (octave_idx_type i = 0; i < len; i++)
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
773 {
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
774 OCTAVE_QUIT;
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
775
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
776 if (m[i] < val)
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
777 return true;
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 }
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
779
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 return false;
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
781 }
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
782
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
783 static bool
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
784 any_element_greater_than (const NDArray& a, double val)
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
785 {
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
786 octave_idx_type len = a.length ();
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
787 const double *m = a.fortran_vec ();
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
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
789 for (octave_idx_type i = 0; i < len; i++)
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
790 {
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
791 OCTAVE_QUIT;
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
792
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
793 if (m[i] > val)
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
794 return true;
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
795 }
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
796
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
797 return false;
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
798 }
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
799
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
800 #define ARRAY_MAPPER(MAP, AMAP, FCN) \
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
801 octave_value \
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
802 octave_complex_matrix::MAP (void) const \
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
803 { \
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
804 static AMAP cmap = FCN; \
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
805 return matrix.map (cmap); \
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
806 }
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
807
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
808 #define DARRAY_MAPPER(MAP, AMAP, FCN) \
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
809 octave_value \
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
810 octave_complex_matrix::MAP (void) const \
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
811 { \
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
812 static ComplexNDArray::dmapper dmap = ximag; \
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
813 NDArray m = matrix.map (dmap); \
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
814 if (m.all_elements_are_zero ()) \
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
815 { \
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
816 dmap = xreal; \
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
817 m = matrix.map (dmap); \
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
818 static AMAP cmap = FCN; \
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
819 return m.map (cmap); \
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
820 } \
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
821 else \
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
822 { \
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
823 error ("%s: not defined for complex arguments", #MAP); \
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
824 return octave_value (); \
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
825 } \
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
826 }
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
827
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
828 #define CD_ARRAY_MAPPER(MAP, RFCN, CFCN, L1, L2) \
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
829 octave_value \
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
830 octave_complex_matrix::MAP (void) const \
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
831 { \
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
832 static ComplexNDArray::dmapper idmap = ximag; \
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
833 NDArray m = matrix.map (idmap); \
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
834 if (m.all_elements_are_zero ()) \
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
835 { \
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
836 static ComplexNDArray::dmapper rdmap = xreal; \
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
837 m = matrix.map (rdmap); \
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
838 static NDArray::dmapper dmap = RFCN; \
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
839 static NDArray::cmapper cmap = CFCN; \
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
840 return (any_element_less_than (m, L1) \
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
841 ? octave_value (m.map (cmap)) \
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
842 : (any_element_greater_than (m, L2) \
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
843 ? octave_value (m.map (cmap)) \
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
844 : octave_value (m.map (dmap)))); \
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
845 } \
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
846 else \
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
847 { \
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
848 /*error ("%s: not defined for complex arguments", #MAP); */ \
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
849 return octave_value (m); \
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
850 } \
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
851 }
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
852
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
853 // The fast mappers.
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
854 octave_value
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
855 octave_complex_matrix::abs (void) const
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
856 {
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
857 return matrix.abs ();
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
858 }
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
859
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
860 octave_value
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
861 octave_complex_matrix::real (void) const
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
862 {
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
863 return ::real (matrix);
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
864 }
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
865
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
866 octave_value
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
867 octave_complex_matrix::conj (void) const
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
868 {
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
869 return ::conj (matrix);
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
870 }
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
871
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
872 octave_value
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
873 octave_complex_matrix::imag (void) const
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
874 {
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
875 return ::imag (matrix);
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
876 }
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8437
diff changeset
877
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
878 DARRAY_MAPPER (erf, NDArray::dmapper, ::erf)
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
879 DARRAY_MAPPER (erfc, NDArray::dmapper, ::erfc)
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
880 DARRAY_MAPPER (gamma, NDArray::dmapper, xgamma)
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
881 CD_ARRAY_MAPPER (lgamma, xlgamma, xlgamma, 0.0, octave_Inf)
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
882
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
883 ARRAY_MAPPER (acos, ComplexNDArray::cmapper, ::acos)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
884 ARRAY_MAPPER (acosh, ComplexNDArray::cmapper, ::acosh)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
885 ARRAY_MAPPER (angle, ComplexNDArray::dmapper, std::arg)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
886 ARRAY_MAPPER (arg, ComplexNDArray::dmapper, std::arg)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
887 ARRAY_MAPPER (asin, ComplexNDArray::cmapper, ::asin)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
888 ARRAY_MAPPER (asinh, ComplexNDArray::cmapper, ::asinh)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
889 ARRAY_MAPPER (atan, ComplexNDArray::cmapper, ::atan)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
890 ARRAY_MAPPER (atanh, ComplexNDArray::cmapper, ::atanh)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
891 ARRAY_MAPPER (ceil, ComplexNDArray::cmapper, ::ceil)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
892 ARRAY_MAPPER (cos, ComplexNDArray::cmapper, std::cos)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
893 ARRAY_MAPPER (cosh, ComplexNDArray::cmapper, std::cosh)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
894 ARRAY_MAPPER (exp, ComplexNDArray::cmapper, std::exp)
7638
2df457529cfa implement expm1 and log1p functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7636
diff changeset
895 ARRAY_MAPPER (expm1, ComplexNDArray::cmapper, ::expm1)
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
896 ARRAY_MAPPER (fix, ComplexNDArray::cmapper, ::fix)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
897 ARRAY_MAPPER (floor, ComplexNDArray::cmapper, ::floor)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
898 ARRAY_MAPPER (log, ComplexNDArray::cmapper, std::log)
7740
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7667
diff changeset
899 ARRAY_MAPPER (log2, ComplexNDArray::cmapper, xlog2)
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
900 ARRAY_MAPPER (log10, ComplexNDArray::cmapper, std::log10)
7638
2df457529cfa implement expm1 and log1p functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7636
diff changeset
901 ARRAY_MAPPER (log1p, ComplexNDArray::cmapper, ::log1p)
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
902 ARRAY_MAPPER (round, ComplexNDArray::cmapper, xround)
7636
99c410f7f0b0 implement mapper function for banker's rounding
Jaroslav Hajek <highegg@gmail.com>
parents: 7503
diff changeset
903 ARRAY_MAPPER (roundb, ComplexNDArray::cmapper, xroundb)
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
904 ARRAY_MAPPER (signum, ComplexNDArray::cmapper, ::signum)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
905 ARRAY_MAPPER (sin, ComplexNDArray::cmapper, std::sin)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
906 ARRAY_MAPPER (sinh, ComplexNDArray::cmapper, std::sinh)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
907 ARRAY_MAPPER (sqrt, ComplexNDArray::cmapper, std::sqrt)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
908 ARRAY_MAPPER (tan, ComplexNDArray::cmapper, std::tan)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
909 ARRAY_MAPPER (tanh, ComplexNDArray::cmapper, std::tanh)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
910 ARRAY_MAPPER (finite, ComplexNDArray::bmapper, xfinite)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
911 ARRAY_MAPPER (isinf, ComplexNDArray::bmapper, xisinf)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
912 ARRAY_MAPPER (isna, ComplexNDArray::bmapper, octave_is_NA)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
913 ARRAY_MAPPER (isnan, ComplexNDArray::bmapper, xisnan)
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
914
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
915 /*
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
916 ;;; Local Variables: ***
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
917 ;;; mode: C++ ***
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
918 ;;; End: ***
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
919 */