Mercurial > hg > octave-lyh
annotate src/ov-cx-sparse.cc @ 14495:319660795df1
Fix gnuplot error when color values are within eps of each other (bug #35761).
* plot/private/__go_draw_axes__.m: Use %.15e for setting cbrange in gnuplot.
author | Marco Caliari <marco.caliari@univr.it> |
---|---|
date | Sun, 25 Mar 2012 13:53:39 -0700 |
parents | 29aabe9b37a2 |
children | 460a3c6d8bf1 |
rev | line source |
---|---|
5164 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13107
diff
changeset
|
3 Copyright (C) 2004-2012 David Bateman |
11523 | 4 Copyright (C) 1998-2004 Andy Adler |
7016 | 5 |
6 This file is part of Octave. | |
5164 | 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. | |
5164 | 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/>. | |
5164 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include <climits> | |
29 | |
30 #include <iostream> | |
31 #include <vector> | |
32 | |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
33 #include "lo-specfun.h" |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
34 #include "lo-mappers.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
7740
diff
changeset
|
35 #include "oct-locbuf.h" |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
36 |
5164 | 37 #include "ov-base.h" |
38 #include "ov-scalar.h" | |
39 #include "ov-complex.h" | |
40 #include "gripes.h" | |
41 | |
42 #include "ov-re-sparse.h" | |
43 #include "ov-cx-sparse.h" | |
44 | |
45 #include "ov-base-sparse.h" | |
46 #include "ov-base-sparse.cc" | |
47 | |
48 #include "ov-bool-sparse.h" | |
49 | |
6109 | 50 template class OCTINTERP_API octave_base_sparse<SparseComplexMatrix>; |
5164 | 51 |
52 DEFINE_OCTAVE_ALLOCATOR (octave_sparse_complex_matrix); | |
53 | |
6823 | 54 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_sparse_complex_matrix, "sparse complex matrix", "double"); |
5164 | 55 |
5759 | 56 octave_base_value * |
5164 | 57 octave_sparse_complex_matrix::try_narrowing_conversion (void) |
58 { | |
5759 | 59 octave_base_value *retval = 0; |
5164 | 60 |
7193 | 61 if (Vsparse_auto_mutate) |
62 { | |
63 int nr = matrix.rows (); | |
64 int nc = matrix.cols (); | |
5164 | 65 |
7193 | 66 // Don't use numel, since it can overflow for very large matrices |
67 // Note that for the tests on matrix size, they become approximative | |
68 // since they involves a cast to double to avoid issues of overflow | |
69 if (matrix.rows () == 1 && matrix.cols () == 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
70 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
71 // Const copy of the matrix, so the right version of () operator used |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
72 const SparseComplexMatrix tmp (matrix); |
5164 | 73 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
74 Complex c = tmp (0, 0); |
5164 | 75 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
76 if (std::imag (c) == 0.0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
77 retval = new octave_scalar (std::real (c)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
78 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
79 retval = new octave_complex (c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
80 } |
7193 | 81 else if (nr == 0 || nc == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
82 retval = new octave_matrix (Matrix (nr, nc)); |
7193 | 83 else if (matrix.all_elements_are_real ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
84 if (matrix.cols () > 0 && matrix.rows () > 0 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
85 && (double (matrix.byte_size ()) > double (matrix.rows ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
86 * double (matrix.cols ()) * sizeof (double))) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
87 retval = new octave_matrix (::real (matrix.matrix_value ())); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
88 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
89 retval = new octave_sparse_matrix (::real (matrix)); |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
90 else if (matrix.cols () > 0 && matrix.rows () > 0 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
91 && (double (matrix.byte_size ()) > double (matrix.rows ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
92 * double (matrix.cols ()) * sizeof (Complex))) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
93 retval = new octave_complex_matrix (matrix.matrix_value ()); |
5164 | 94 } |
7193 | 95 else |
96 { | |
97 if (matrix.all_elements_are_real ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
98 retval = new octave_sparse_matrix (::real (matrix)); |
7193 | 99 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
100 |
5164 | 101 return retval; |
102 } | |
103 | |
104 double | |
105 octave_sparse_complex_matrix::double_value (bool force_conversion) const | |
106 { | |
107 double retval = lo_ieee_nan_value (); | |
108 | |
5781 | 109 if (! force_conversion) |
110 gripe_implicit_conversion ("Octave:imag-to-real", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
111 "complex sparse matrix", "real scalar"); |
5164 | 112 |
5775 | 113 // FIXME -- maybe this should be a function, valid_as_scalar() |
5164 | 114 if (numel () > 0) |
115 { | |
6221 | 116 if (numel () > 1) |
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
|
117 gripe_implicit_conversion ("Octave:array-to-scalar", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
118 "complex sparse matrix", "real scalar"); |
5164 | 119 |
120 retval = std::real (matrix (0, 0)); | |
121 } | |
122 else | |
123 gripe_invalid_conversion ("complex sparse matrix", "real scalar"); | |
124 | |
125 return retval; | |
126 } | |
127 | |
128 Matrix | |
129 octave_sparse_complex_matrix::matrix_value (bool force_conversion) const | |
130 { | |
131 Matrix retval; | |
132 | |
5781 | 133 if (! force_conversion) |
134 gripe_implicit_conversion ("Octave:imag-to-real", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
135 "complex sparse matrix", "real matrix"); |
5164 | 136 |
137 retval = ::real (matrix.matrix_value ()); | |
138 | |
139 return retval; | |
140 } | |
141 | |
142 Complex | |
143 octave_sparse_complex_matrix::complex_value (bool) const | |
144 { | |
145 double tmp = lo_ieee_nan_value (); | |
146 | |
147 Complex retval (tmp, tmp); | |
148 | |
5775 | 149 // FIXME -- maybe this should be a function, valid_as_scalar() |
5164 | 150 if (numel () > 0) |
151 { | |
6221 | 152 if (numel () > 1) |
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
|
153 gripe_implicit_conversion ("Octave:array-to-scalar", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
154 "complex sparse matrix", "real scalar"); |
5164 | 155 |
156 retval = matrix (0, 0); | |
157 } | |
158 else | |
159 gripe_invalid_conversion ("complex sparse matrix", "real scalar"); | |
160 | |
161 return retval; | |
162 } | |
163 | |
164 ComplexMatrix | |
165 octave_sparse_complex_matrix::complex_matrix_value (bool) const | |
166 { | |
167 return matrix.matrix_value (); | |
168 } | |
169 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
170 ComplexNDArray |
5164 | 171 octave_sparse_complex_matrix::complex_array_value (bool) const |
172 { | |
173 return ComplexNDArray (matrix.matrix_value ()); | |
174 } | |
175 | |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
176 charNDArray |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
177 octave_sparse_complex_matrix::char_array_value (bool frc_str_conv) const |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
178 { |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
179 charNDArray retval; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
180 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
181 if (! frc_str_conv) |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
182 gripe_implicit_conversion ("Octave:num-to-str", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
183 "sparse complex matrix", "string"); |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
184 else |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
185 { |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
186 retval = charNDArray (dims (), 0); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
187 octave_idx_type nc = matrix.cols (); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
188 octave_idx_type nr = matrix.rows (); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
189 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
190 for (octave_idx_type j = 0; j < nc; j++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
191 for (octave_idx_type i = matrix.cidx(j); i < matrix.cidx(j+1); i++) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
192 retval(matrix.ridx(i) + nr * j) = |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
193 static_cast<char>(std::real (matrix.data (i))); |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
194 } |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
195 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
196 return retval; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
197 } |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
198 |
5164 | 199 SparseMatrix |
200 octave_sparse_complex_matrix::sparse_matrix_value (bool force_conversion) const | |
201 { | |
202 SparseMatrix retval; | |
203 | |
5781 | 204 if (! force_conversion) |
205 gripe_implicit_conversion ("Octave:imag-to-real", | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
206 "complex sparse matrix", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
207 "real sparse matrix"); |
5164 | 208 |
209 retval = ::real (matrix); | |
210 | |
211 return retval; | |
212 } | |
213 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
214 SparseBoolMatrix |
9853
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
215 octave_sparse_complex_matrix::sparse_bool_matrix_value (bool warn) const |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
216 { |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
217 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:
10527
diff
changeset
|
218 gripe_nan_to_logical_conversion (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
219 else if (warn && (! matrix.all_elements_are_real () |
9853
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
220 || real (matrix).any_element_not_one_or_zero ())) |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
221 gripe_logical_conversion (); |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
222 |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
223 return mx_el_ne (matrix, Complex (0.0)); |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
224 } |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9813
diff
changeset
|
225 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
226 bool |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
227 octave_sparse_complex_matrix::save_binary (std::ostream& os, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
228 bool&save_as_floats) |
5164 | 229 { |
230 dim_vector d = this->dims (); | |
231 if (d.length() < 1) | |
232 return false; | |
233 | |
234 // Ensure that additional memory is deallocated | |
235 matrix.maybe_compress (); | |
236 | |
237 int nr = d(0); | |
238 int nc = d(1); | |
10527
b4d2080b6df7
Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents:
10512
diff
changeset
|
239 int nz = nnz (); |
5164 | 240 |
5828 | 241 int32_t itmp; |
5164 | 242 // Use negative value for ndims to be consistent with other formats |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
243 itmp= -2; |
5760 | 244 os.write (reinterpret_cast<char *> (&itmp), 4); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
245 |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
246 itmp= nr; |
5760 | 247 os.write (reinterpret_cast<char *> (&itmp), 4); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
248 |
5164 | 249 itmp= nc; |
5760 | 250 os.write (reinterpret_cast<char *> (&itmp), 4); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
251 |
5164 | 252 itmp= nz; |
5760 | 253 os.write (reinterpret_cast<char *> (&itmp), 4); |
5164 | 254 |
255 save_type st = LS_DOUBLE; | |
256 if (save_as_floats) | |
257 { | |
258 if (matrix.too_large_for_float ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
259 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
260 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
|
261 warning ("save: saving as doubles instead"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
262 } |
5164 | 263 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
264 st = LS_FLOAT; |
5164 | 265 } |
10527
b4d2080b6df7
Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents:
10512
diff
changeset
|
266 else if (matrix.nnz () > 8192) // FIXME -- make this configurable. |
5164 | 267 { |
268 double max_val, min_val; | |
269 if (matrix.all_integers (max_val, min_val)) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
270 st = get_save_type (max_val, min_val); |
5164 | 271 } |
272 | |
273 // add one to the printed indices to go from | |
274 // zero-based to one-based arrays | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
275 for (int i = 0; i < nc+1; i++) |
5164 | 276 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
277 octave_quit (); |
5164 | 278 itmp = matrix.cidx(i); |
5760 | 279 os.write (reinterpret_cast<char *> (&itmp), 4); |
5164 | 280 } |
281 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
282 for (int i = 0; i < nz; i++) |
5164 | 283 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
284 octave_quit (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
285 itmp = matrix.ridx(i); |
5760 | 286 os.write (reinterpret_cast<char *> (&itmp), 4); |
5164 | 287 } |
288 | |
5760 | 289 write_doubles (os, reinterpret_cast<const double *> (matrix.data()), st, 2 * nz); |
5164 | 290 |
291 return true; | |
292 } | |
293 | |
294 bool | |
295 octave_sparse_complex_matrix::load_binary (std::istream& is, bool swap, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
296 oct_mach_info::float_format fmt) |
5164 | 297 { |
5828 | 298 int32_t nz, nc, nr, tmp; |
5327 | 299 char ctmp; |
300 | |
5760 | 301 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
5164 | 302 return false; |
303 | |
304 if (swap) | |
305 swap_bytes<4> (&tmp); | |
306 | |
307 if (tmp != -2) { | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
308 error ("load: only 2D sparse matrices are supported"); |
5164 | 309 return false; |
310 } | |
311 | |
5760 | 312 if (! is.read (reinterpret_cast<char *> (&nr), 4)) |
5164 | 313 return false; |
5760 | 314 if (! is.read (reinterpret_cast<char *> (&nc), 4)) |
5164 | 315 return false; |
5760 | 316 if (! is.read (reinterpret_cast<char *> (&nz), 4)) |
5164 | 317 return false; |
318 | |
319 if (swap) | |
320 { | |
321 swap_bytes<4> (&nr); | |
322 swap_bytes<4> (&nc); | |
323 swap_bytes<4> (&nz); | |
324 } | |
325 | |
5275 | 326 SparseComplexMatrix m (static_cast<octave_idx_type> (nr), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
327 static_cast<octave_idx_type> (nc), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
328 static_cast<octave_idx_type> (nz)); |
5164 | 329 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
330 for (int i = 0; i < nc+1; i++) |
5164 | 331 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
332 octave_quit (); |
5760 | 333 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
334 return false; |
5164 | 335 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
336 swap_bytes<4> (&tmp); |
5164 | 337 m.cidx(i) = tmp; |
338 } | |
339 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
340 for (int i = 0; i < nz; i++) |
5164 | 341 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
342 octave_quit (); |
5760 | 343 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
344 return false; |
5164 | 345 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
346 swap_bytes<4> (&tmp); |
5164 | 347 m.ridx(i) = tmp; |
348 } | |
349 | |
5760 | 350 if (! is.read (reinterpret_cast<char *> (&ctmp), 1)) |
5164 | 351 return false; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
352 |
5760 | 353 read_doubles (is, reinterpret_cast<double *> (m.data ()), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
354 static_cast<save_type> (ctmp), 2 * nz, swap, fmt); |
5164 | 355 |
356 if (error_state || ! is) | |
357 return false; | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
358 |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
359 if (! m.indices_ok ()) |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
360 return false; |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
361 |
5164 | 362 matrix = m; |
363 | |
364 return true; | |
365 } | |
366 | |
367 #if defined (HAVE_HDF5) | |
5900 | 368 |
5164 | 369 bool |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
370 octave_sparse_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
|
371 bool save_as_floats) |
5164 | 372 { |
373 dim_vector dv = dims (); | |
374 int empty = save_hdf5_empty (loc_id, name, dv); | |
375 if (empty) | |
376 return (empty > 0); | |
377 | |
378 // Ensure that additional memory is deallocated | |
379 matrix.maybe_compress (); | |
380 | |
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
|
381 #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
|
382 hid_t group_hid = H5Gcreate (loc_id, name, H5P_DEFAULT, H5P_DEFAULT, 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
|
383 #else |
5164 | 384 hid_t group_hid = H5Gcreate (loc_id, name, 0); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
385 #endif |
5164 | 386 if (group_hid < 0) |
387 return false; | |
388 | |
389 hid_t space_hid = -1, data_hid = -1; | |
390 bool retval = true; | |
391 SparseComplexMatrix m = sparse_complex_matrix_value (); | |
5351 | 392 octave_idx_type tmp; |
5164 | 393 hsize_t hdims[2]; |
394 | |
5760 | 395 space_hid = H5Screate_simple (0, hdims, 0); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
396 if (space_hid < 0) |
5164 | 397 { |
398 H5Gclose (group_hid); | |
399 return false; | |
400 } | |
401 | |
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
|
402 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
403 data_hid = H5Dcreate (group_hid, "nr", H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
404 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
|
405 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
406 data_hid = H5Dcreate (group_hid, "nr", H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
407 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
|
408 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
409 if (data_hid < 0) |
5164 | 410 { |
411 H5Sclose (space_hid); | |
412 H5Gclose (group_hid); | |
413 return false; | |
414 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
415 |
5164 | 416 tmp = m.rows (); |
5351 | 417 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
418 H5P_DEFAULT, &tmp) >= 0; |
5164 | 419 H5Dclose (data_hid); |
420 if (!retval) | |
421 { | |
422 H5Sclose (space_hid); | |
423 H5Gclose (group_hid); | |
424 return false; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
425 } |
5164 | 426 |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
427 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
428 data_hid = H5Dcreate (group_hid, "nc", H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
429 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
|
430 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
431 data_hid = H5Dcreate (group_hid, "nc", H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
432 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
|
433 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
434 if (data_hid < 0) |
5164 | 435 { |
436 H5Sclose (space_hid); | |
437 H5Gclose (group_hid); | |
438 return false; | |
439 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
440 |
5164 | 441 tmp = m.cols (); |
5351 | 442 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
443 H5P_DEFAULT, &tmp) >= 0; |
5164 | 444 H5Dclose (data_hid); |
445 if (!retval) | |
446 { | |
447 H5Sclose (space_hid); | |
448 H5Gclose (group_hid); | |
449 return false; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
450 } |
5164 | 451 |
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
|
452 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
453 data_hid = H5Dcreate (group_hid, "nz", H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
454 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
|
455 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
456 data_hid = H5Dcreate (group_hid, "nz", H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
457 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
|
458 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
459 if (data_hid < 0) |
5164 | 460 { |
461 H5Sclose (space_hid); | |
462 H5Gclose (group_hid); | |
463 return false; | |
464 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
465 |
10527
b4d2080b6df7
Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents:
10512
diff
changeset
|
466 tmp = m.nnz (); |
5351 | 467 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
468 H5P_DEFAULT, &tmp) >= 0; |
5164 | 469 H5Dclose (data_hid); |
470 if (!retval) | |
471 { | |
472 H5Sclose (space_hid); | |
473 H5Gclose (group_hid); | |
474 return false; | |
475 } | |
476 | |
477 H5Sclose (space_hid); | |
478 | |
479 hdims[0] = m.cols() + 1; | |
480 hdims[1] = 1; | |
481 | |
482 space_hid = H5Screate_simple (2, hdims, 0); | |
483 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
484 if (space_hid < 0) |
5164 | 485 { |
486 H5Gclose (group_hid); | |
487 return false; | |
488 } | |
489 | |
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
|
490 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
491 data_hid = H5Dcreate (group_hid, "cidx", H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
492 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
|
493 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
494 data_hid = H5Dcreate (group_hid, "cidx", H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
495 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
|
496 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
497 if (data_hid < 0) |
5164 | 498 { |
499 H5Sclose (space_hid); | |
500 H5Gclose (group_hid); | |
501 return false; | |
502 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
503 |
5351 | 504 octave_idx_type * itmp = m.xcidx (); |
505 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
506 H5P_DEFAULT, itmp) >= 0; |
5164 | 507 H5Dclose (data_hid); |
508 if (!retval) | |
509 { | |
510 H5Sclose (space_hid); | |
511 H5Gclose (group_hid); | |
512 return false; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
513 } |
5164 | 514 |
515 H5Sclose (space_hid); | |
516 | |
10527
b4d2080b6df7
Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents:
10512
diff
changeset
|
517 hdims[0] = m.nnz (); |
5164 | 518 hdims[1] = 1; |
519 | |
520 space_hid = H5Screate_simple (2, hdims, 0); | |
521 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
522 if (space_hid < 0) |
5164 | 523 { |
524 H5Gclose (group_hid); | |
525 return false; | |
526 } | |
527 | |
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
|
528 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
529 data_hid = H5Dcreate (group_hid, "ridx", H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
530 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
|
531 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
532 data_hid = H5Dcreate (group_hid, "ridx", H5T_NATIVE_IDX, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
533 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
|
534 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
535 if (data_hid < 0) |
5164 | 536 { |
537 H5Sclose (space_hid); | |
538 H5Gclose (group_hid); | |
539 return false; | |
540 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
541 |
5164 | 542 itmp = m.xridx (); |
5760 | 543 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, itmp) >= 0; |
5164 | 544 H5Dclose (data_hid); |
545 if (!retval) | |
546 { | |
547 H5Sclose (space_hid); | |
548 H5Gclose (group_hid); | |
549 return false; | |
550 } | |
551 | |
552 hid_t save_type_hid = H5T_NATIVE_DOUBLE; | |
553 | |
554 if (save_as_floats) | |
555 { | |
556 if (m.too_large_for_float ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
557 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
558 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
|
559 warning ("save: saving as doubles instead"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
560 } |
5164 | 561 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
562 save_type_hid = H5T_NATIVE_FLOAT; |
5164 | 563 } |
564 #if HAVE_HDF5_INT2FLOAT_CONVERSIONS | |
565 // hdf5 currently doesn't support float/integer conversions | |
566 else | |
567 { | |
568 double max_val, min_val; | |
569 | |
570 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
|
571 save_type_hid |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
572 = save_type_to_hdf5 (get_save_type (max_val, min_val)); |
5164 | 573 } |
574 #endif /* HAVE_HDF5_INT2FLOAT_CONVERSIONS */ | |
575 | |
576 hid_t type_hid = hdf5_make_complex_type (save_type_hid); | |
577 if (type_hid < 0) | |
578 { | |
579 H5Sclose (space_hid); | |
580 H5Gclose (group_hid); | |
581 return false; | |
582 } | |
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
|
583 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
584 data_hid = H5Dcreate (group_hid, "data", type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
585 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
|
586 #else |
5760 | 587 data_hid = H5Dcreate (group_hid, "data", type_hid, space_hid, H5P_DEFAULT); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
588 #endif |
5164 | 589 if (data_hid < 0) |
590 { | |
591 H5Sclose (space_hid); | |
592 H5Tclose (type_hid); | |
593 H5Gclose (group_hid); | |
594 return false; | |
595 } | |
596 | |
597 hid_t complex_type_hid = hdf5_make_complex_type (H5T_NATIVE_DOUBLE); | |
598 retval = false; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
599 if (complex_type_hid >= 0) |
5164 | 600 { |
601 Complex * ctmp = m.xdata (); | |
602 | |
603 retval = H5Dwrite (data_hid, complex_type_hid, H5S_ALL, H5S_ALL, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
604 H5P_DEFAULT, ctmp) >= 0; |
5164 | 605 } |
606 | |
607 H5Dclose (data_hid); | |
608 H5Sclose (space_hid); | |
609 H5Tclose (type_hid); | |
610 H5Gclose (group_hid); | |
611 | |
612 return retval; | |
613 } | |
614 | |
615 bool | |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
9853
diff
changeset
|
616 octave_sparse_complex_matrix::load_hdf5 (hid_t loc_id, const char *name) |
5164 | 617 { |
5351 | 618 octave_idx_type nr, nc, nz; |
5164 | 619 hid_t group_hid, data_hid, space_hid; |
620 hsize_t rank; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
621 |
5164 | 622 dim_vector dv; |
623 int empty = load_hdf5_empty (loc_id, name, dv); | |
624 if (empty > 0) | |
625 matrix.resize(dv); | |
626 if (empty) | |
627 return (empty > 0); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
628 |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
629 #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
|
630 group_hid = H5Gopen (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
|
631 #else |
5164 | 632 group_hid = H5Gopen (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
|
633 #endif |
5164 | 634 if (group_hid < 0 ) return false; |
635 | |
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
|
636 #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
|
637 data_hid = H5Dopen (group_hid, "nr", 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
|
638 #else |
5164 | 639 data_hid = H5Dopen (group_hid, "nr"); |
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
|
640 #endif |
5164 | 641 space_hid = H5Dget_space (data_hid); |
642 rank = H5Sget_simple_extent_ndims (space_hid); | |
643 | |
644 if (rank != 0) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
645 { |
5164 | 646 H5Dclose (data_hid); |
647 H5Gclose (group_hid); | |
648 return false; | |
649 } | |
650 | |
5760 | 651 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, &nr) < 0) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
652 { |
5164 | 653 H5Dclose (data_hid); |
654 H5Gclose (group_hid); | |
655 return false; | |
656 } | |
657 | |
658 H5Dclose (data_hid); | |
659 | |
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
|
660 #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
|
661 data_hid = H5Dopen (group_hid, "nc", 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
|
662 #else |
5164 | 663 data_hid = H5Dopen (group_hid, "nc"); |
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
|
664 #endif |
5164 | 665 space_hid = H5Dget_space (data_hid); |
666 rank = H5Sget_simple_extent_ndims (space_hid); | |
667 | |
668 if (rank != 0) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
669 { |
5164 | 670 H5Dclose (data_hid); |
671 H5Gclose (group_hid); | |
672 return false; | |
673 } | |
674 | |
5760 | 675 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, &nc) < 0) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
676 { |
5164 | 677 H5Dclose (data_hid); |
678 H5Gclose (group_hid); | |
679 return false; | |
680 } | |
681 | |
682 H5Dclose (data_hid); | |
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
|
683 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
684 #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
|
685 data_hid = H5Dopen (group_hid, "nz", 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
|
686 #else |
5164 | 687 data_hid = H5Dopen (group_hid, "nz"); |
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
|
688 #endif |
5164 | 689 space_hid = H5Dget_space (data_hid); |
690 rank = H5Sget_simple_extent_ndims (space_hid); | |
691 | |
692 if (rank != 0) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
693 { |
5164 | 694 H5Dclose (data_hid); |
695 H5Gclose (group_hid); | |
696 return false; | |
697 } | |
698 | |
5760 | 699 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, &nz) < 0) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
700 { |
5164 | 701 H5Dclose (data_hid); |
702 H5Gclose (group_hid); | |
703 return false; | |
704 } | |
705 | |
706 H5Dclose (data_hid); | |
707 | |
5275 | 708 SparseComplexMatrix m (static_cast<octave_idx_type> (nr), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
709 static_cast<octave_idx_type> (nc), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
710 static_cast<octave_idx_type> (nz)); |
5164 | 711 |
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
|
712 #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
|
713 data_hid = H5Dopen (group_hid, "cidx", 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
|
714 #else |
5164 | 715 data_hid = H5Dopen (group_hid, "cidx"); |
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
|
716 #endif |
5164 | 717 space_hid = H5Dget_space (data_hid); |
718 rank = H5Sget_simple_extent_ndims (space_hid); | |
719 | |
720 if (rank != 2) | |
721 { | |
722 H5Sclose (space_hid); | |
723 H5Dclose (data_hid); | |
724 H5Gclose (group_hid); | |
725 return false; | |
726 } | |
727 | |
728 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); | |
729 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); | |
730 | |
731 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); | |
732 | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
733 if (static_cast<int> (hdims[0]) != nc + 1 |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
734 || static_cast<int> (hdims[1]) != 1) |
5164 | 735 { |
736 H5Sclose (space_hid); | |
737 H5Dclose (data_hid); | |
738 H5Gclose (group_hid); | |
739 return false; | |
740 } | |
741 | |
5351 | 742 octave_idx_type *itmp = m.xcidx (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
743 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, itmp) < 0) |
5164 | 744 { |
745 H5Sclose (space_hid); | |
746 H5Dclose (data_hid); | |
747 H5Gclose (group_hid); | |
748 return false; | |
749 } | |
750 | |
751 H5Sclose (space_hid); | |
752 H5Dclose (data_hid); | |
753 | |
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
|
754 #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
|
755 data_hid = H5Dopen (group_hid, "ridx", 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
|
756 #else |
5164 | 757 data_hid = H5Dopen (group_hid, "ridx"); |
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
|
758 #endif |
5164 | 759 space_hid = H5Dget_space (data_hid); |
760 rank = H5Sget_simple_extent_ndims (space_hid); | |
761 | |
762 if (rank != 2) | |
763 { | |
764 H5Sclose (space_hid); | |
765 H5Dclose (data_hid); | |
766 H5Gclose (group_hid); | |
767 return false; | |
768 } | |
769 | |
770 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); | |
771 | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
772 if (static_cast<int> (hdims[0]) != nz |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
773 || static_cast<int> (hdims[1]) != 1) |
5164 | 774 { |
775 H5Sclose (space_hid); | |
776 H5Dclose (data_hid); | |
777 H5Gclose (group_hid); | |
778 return false; | |
779 } | |
780 | |
781 itmp = m.xridx (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
782 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, itmp) < 0) |
5164 | 783 { |
784 H5Sclose (space_hid); | |
785 H5Dclose (data_hid); | |
786 H5Gclose (group_hid); | |
787 return false; | |
788 } | |
789 | |
790 H5Sclose (space_hid); | |
791 H5Dclose (data_hid); | |
792 | |
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
|
793 #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
|
794 data_hid = H5Dopen (group_hid, "data", 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
|
795 #else |
5164 | 796 data_hid = H5Dopen (group_hid, "data"); |
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
|
797 #endif |
5164 | 798 hid_t type_hid = H5Dget_type (data_hid); |
799 | |
800 hid_t complex_type = hdf5_make_complex_type (H5T_NATIVE_DOUBLE); | |
801 | |
802 if (! hdf5_types_compatible (type_hid, complex_type)) | |
803 { | |
804 H5Tclose (complex_type); | |
805 H5Dclose (data_hid); | |
806 H5Gclose (group_hid); | |
807 return false; | |
808 } | |
809 | |
810 space_hid = H5Dget_space (data_hid); | |
811 rank = H5Sget_simple_extent_ndims (space_hid); | |
812 | |
813 if (rank != 2) | |
814 { | |
815 H5Sclose (space_hid); | |
816 H5Dclose (data_hid); | |
817 H5Gclose (group_hid); | |
818 return false; | |
819 } | |
820 | |
821 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); | |
822 | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
823 if (static_cast<int> (hdims[0]) != nz |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
824 || static_cast<int> (hdims[1]) != 1) |
5164 | 825 { |
826 H5Sclose (space_hid); | |
827 H5Dclose (data_hid); | |
828 H5Gclose (group_hid); | |
829 return false; | |
830 } | |
831 | |
832 Complex *ctmp = m.xdata (); | |
833 bool retval = false; | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
834 if (H5Dread (data_hid, complex_type, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
835 H5P_DEFAULT, ctmp) >= 0 |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
836 && m.indices_ok ()) |
5164 | 837 { |
838 retval = true; | |
839 matrix = m; | |
840 } | |
841 | |
842 H5Tclose (complex_type); | |
843 H5Sclose (space_hid); | |
844 H5Dclose (data_hid); | |
845 H5Gclose (group_hid); | |
846 | |
847 return retval; | |
848 } | |
849 | |
850 #endif | |
851 | |
5900 | 852 mxArray * |
853 octave_sparse_complex_matrix::as_mxArray (void) const | |
854 { | |
6686 | 855 mwSize nz = nzmax (); |
5903 | 856 mxArray *retval = new mxArray (mxDOUBLE_CLASS, rows (), columns (), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
857 nz, mxCOMPLEX); |
5903 | 858 double *pr = static_cast<double *> (retval->get_data ()); |
859 double *pi = static_cast<double *> (retval->get_imag_data ()); | |
6686 | 860 mwIndex *ir = retval->get_ir (); |
861 mwIndex *jc = retval->get_jc (); | |
5903 | 862 |
6686 | 863 for (mwIndex i = 0; i < nz; i++) |
5903 | 864 { |
865 Complex val = matrix.data(i); | |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
866 pr[i] = std::real (val); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
867 pi[i] = std::imag (val); |
5903 | 868 ir[i] = matrix.ridx(i); |
869 } | |
870 | |
6686 | 871 for (mwIndex i = 0; i < columns() + 1; i++) |
5903 | 872 jc[i] = matrix.cidx(i); |
873 | |
874 return retval; | |
5900 | 875 } |
876 | |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
877 octave_value |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
878 octave_sparse_complex_matrix::map (unary_mapper_t umap) const |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
879 { |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
880 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
|
881 { |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
882 // Mappers handled specially. |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
883 case umap_real: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
884 return ::real (matrix); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
885 case umap_imag: |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
886 return ::imag (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
|
887 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
888 #define ARRAY_METHOD_MAPPER(UMAP, FCN) \ |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
889 case umap_ ## UMAP: \ |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
890 return octave_value (matrix.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
|
891 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
892 ARRAY_METHOD_MAPPER (abs, abs); |
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
|
893 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
894 #define ARRAY_MAPPER(UMAP, TYPE, FCN) \ |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
895 case umap_ ## UMAP: \ |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
896 return octave_value (matrix.map<TYPE> (FCN)) |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
897 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
898 ARRAY_MAPPER (acos, Complex, ::acos); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
899 ARRAY_MAPPER (acosh, Complex, ::acosh); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
900 ARRAY_MAPPER (angle, double, std::arg); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
901 ARRAY_MAPPER (arg, double, std::arg); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
902 ARRAY_MAPPER (asin, Complex, ::asin); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
903 ARRAY_MAPPER (asinh, Complex, ::asinh); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
904 ARRAY_MAPPER (atan, Complex, ::atan); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
905 ARRAY_MAPPER (atanh, Complex, ::atanh); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
906 ARRAY_MAPPER (ceil, Complex, ::ceil); |
13107
353c71c76f22
maint: fix compilation problem with g++ -std=c++0x option
Júlio Hoffimann <julio.hoffimann@gmail.com>
parents:
11586
diff
changeset
|
907 ARRAY_MAPPER (conj, Complex, std::conj<double>); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
908 ARRAY_MAPPER (cos, Complex, std::cos); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
909 ARRAY_MAPPER (cosh, Complex, std::cosh); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
910 ARRAY_MAPPER (exp, Complex, std::exp); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
911 ARRAY_MAPPER (expm1, Complex, ::expm1); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
912 ARRAY_MAPPER (fix, Complex, ::fix); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
913 ARRAY_MAPPER (floor, Complex, ::floor); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
914 ARRAY_MAPPER (log, Complex, std::log); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
915 ARRAY_MAPPER (log2, Complex, xlog2); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
916 ARRAY_MAPPER (log10, Complex, std::log10); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
917 ARRAY_MAPPER (log1p, Complex, ::log1p); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
918 ARRAY_MAPPER (round, Complex, xround); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
919 ARRAY_MAPPER (roundb, Complex, xroundb); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
920 ARRAY_MAPPER (signum, Complex, ::signum); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
921 ARRAY_MAPPER (sin, Complex, std::sin); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
922 ARRAY_MAPPER (sinh, Complex, std::sinh); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
923 ARRAY_MAPPER (sqrt, Complex, std::sqrt); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
924 ARRAY_MAPPER (tan, Complex, std::tan); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
925 ARRAY_MAPPER (tanh, Complex, std::tanh); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
926 ARRAY_MAPPER (isnan, bool, xisnan); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
927 ARRAY_MAPPER (isna, bool, octave_is_NA); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
928 ARRAY_MAPPER (isinf, bool, xisinf); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
929 ARRAY_MAPPER (finite, bool, xfinite); |
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
|
930 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
931 default: // Attempt to go via dense matrix. |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
932 return octave_base_sparse<SparseComplexMatrix>::map (umap); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
933 } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
934 } |