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