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