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