Mercurial > hg > octave-nkf
annotate src/ov-bool-sparse.cc @ 14348:95c43fc8dbe1 stable rc-3-6-1-0
3.6.1 release candidate 0
* configure.ac (AC_INIT): Version is now 3.6.1-rc0.
(OCTAVE_RELEASE_DATE): Now 2012-02-07.
* liboctave/Makefile.am: Bump liboctave revision version.
* src/Makefile.am: Bump liboctave revision version.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 09 Feb 2012 11:25:04 -0500 |
parents | 72c96de7a403 |
children | 29aabe9b37a2 |
rev | line source |
---|---|
5164 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
3 Copyright (C) 2004-2012 David Bateman |
11523 | 4 Copyright (C) 1998-2004 Andy Adler |
7016 | 5 |
6 This file is part of Octave. | |
5164 | 7 |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
5164 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
5164 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include <climits> | |
29 | |
30 #include <iostream> | |
31 #include <vector> | |
32 | |
33 #include "ov-base.h" | |
34 #include "ov-scalar.h" | |
35 #include "ov-bool.h" | |
36 #include "ov-bool-mat.h" | |
37 #include "gripes.h" | |
38 #include "ops.h" | |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
39 #include "oct-locbuf.h" |
5164 | 40 |
41 #include "ov-re-sparse.h" | |
42 #include "ov-cx-sparse.h" | |
43 #include "ov-bool-sparse.h" | |
44 | |
45 #include "ov-base-sparse.h" | |
46 #include "ov-base-sparse.cc" | |
47 | |
6109 | 48 template class OCTINTERP_API octave_base_sparse<SparseBoolMatrix>; |
5164 | 49 |
50 DEFINE_OCTAVE_ALLOCATOR (octave_sparse_bool_matrix); | |
51 | |
6823 | 52 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_sparse_bool_matrix, "sparse bool matrix", "logical"); |
5164 | 53 |
5759 | 54 static octave_base_value * |
55 default_numeric_conversion_function (const octave_base_value& a) | |
5164 | 56 { |
57 CAST_CONV_ARG (const octave_sparse_bool_matrix&); | |
58 | |
59 return new octave_sparse_matrix (SparseMatrix (v.sparse_bool_matrix_value ())); | |
60 } | |
61 | |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7503
diff
changeset
|
62 octave_base_value::type_conv_info |
5164 | 63 octave_sparse_bool_matrix::numeric_conversion_function (void) const |
64 { | |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7503
diff
changeset
|
65 return octave_base_value::type_conv_info (default_numeric_conversion_function, |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7503
diff
changeset
|
66 octave_sparse_matrix::static_type_id ()); |
5164 | 67 } |
68 | |
5759 | 69 octave_base_value * |
5164 | 70 octave_sparse_bool_matrix::try_narrowing_conversion (void) |
71 { | |
5759 | 72 octave_base_value *retval = 0; |
5164 | 73 |
7193 | 74 if (Vsparse_auto_mutate) |
5164 | 75 { |
7193 | 76 // Don't use numel, since it can overflow for very large matrices |
77 // Note that for the second test, this means it becomes approximative | |
78 // since it involves a cast to double to avoid issues of overflow | |
79 if (matrix.rows () == 1 && matrix.cols () == 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
80 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
81 // 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
|
82 const SparseBoolMatrix tmp (matrix); |
5164 | 83 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
84 retval = new octave_bool (tmp (0)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
85 } |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
86 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
|
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 (bool))) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
89 retval = new octave_bool_matrix (matrix.matrix_value ()); |
5164 | 90 } |
91 | |
92 return retval; | |
93 } | |
94 | |
95 double | |
96 octave_sparse_bool_matrix::double_value (bool) const | |
97 { | |
98 double retval = lo_ieee_nan_value (); | |
99 | |
100 if (numel () > 0) | |
101 { | |
6221 | 102 if (numel () > 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
103 gripe_implicit_conversion ("Octave:array-as-scalar", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
104 "bool sparse matrix", "real scalar"); |
5164 | 105 |
106 retval = matrix (0, 0); | |
107 } | |
108 else | |
109 gripe_invalid_conversion ("bool sparse matrix", "real scalar"); | |
110 | |
111 return retval; | |
112 } | |
113 | |
114 Complex | |
115 octave_sparse_bool_matrix::complex_value (bool) const | |
116 { | |
117 double tmp = lo_ieee_nan_value (); | |
118 | |
119 Complex retval (tmp, tmp); | |
120 | |
121 if (rows () > 0 && columns () > 0) | |
122 { | |
6221 | 123 if (numel () > 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
124 gripe_implicit_conversion ("Octave:array-as-scalar", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
125 "bool sparse matrix", "complex scalar"); |
5164 | 126 |
127 retval = matrix (0, 0); | |
128 } | |
129 else | |
130 gripe_invalid_conversion ("bool sparse matrix", "complex scalar"); | |
131 | |
132 return retval; | |
133 } | |
134 | |
135 octave_value | |
5279 | 136 octave_sparse_bool_matrix::convert_to_str_internal (bool pad, bool force, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
137 char type) const |
5164 | 138 { |
139 octave_value tmp = octave_value (array_value ()); | |
5279 | 140 return tmp.convert_to_str (pad, force, type); |
5164 | 141 } |
142 | |
5775 | 143 // FIXME These are inefficient ways of creating full matrices |
5164 | 144 |
145 Matrix | |
146 octave_sparse_bool_matrix::matrix_value (bool) const | |
147 { | |
148 return Matrix (matrix.matrix_value ()); | |
149 } | |
150 | |
151 ComplexMatrix | |
152 octave_sparse_bool_matrix::complex_matrix_value (bool) const | |
153 { | |
154 return ComplexMatrix (matrix.matrix_value ()); | |
155 } | |
156 | |
157 ComplexNDArray | |
158 octave_sparse_bool_matrix::complex_array_value (bool) const | |
159 { | |
160 return ComplexNDArray (ComplexMatrix (matrix.matrix_value ())); | |
161 } | |
162 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
163 NDArray |
5164 | 164 octave_sparse_bool_matrix::array_value (bool) const |
165 { | |
166 return NDArray (Matrix(matrix.matrix_value ())); | |
167 } | |
168 | |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
169 charNDArray |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
170 octave_sparse_bool_matrix::char_array_value (bool) const |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
171 { |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
172 charNDArray retval (dims (), 0); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
173 octave_idx_type nc = matrix.cols (); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
174 octave_idx_type nr = matrix.rows (); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
175 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
176 for (octave_idx_type j = 0; j < nc; j++) |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
177 for (octave_idx_type i = matrix.cidx(j); i < matrix.cidx(j+1); i++) |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
178 retval(matrix.ridx(i) + nr * j) = static_cast<char>(matrix.data (i)); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
179 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
180 return retval; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
181 } |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7193
diff
changeset
|
182 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
183 boolMatrix |
5944 | 184 octave_sparse_bool_matrix::bool_matrix_value (bool) const |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
185 { |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
186 return matrix.matrix_value (); |
5164 | 187 } |
188 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
189 boolNDArray |
5944 | 190 octave_sparse_bool_matrix::bool_array_value (bool) const |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
191 { |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
192 return boolNDArray (matrix.matrix_value ()); |
5164 | 193 } |
194 | |
195 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
196 SparseMatrix |
5188 | 197 octave_sparse_bool_matrix::sparse_matrix_value (bool) const |
5164 | 198 { |
199 return SparseMatrix (this->matrix); | |
200 } | |
201 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
202 SparseComplexMatrix |
5188 | 203 octave_sparse_bool_matrix::sparse_complex_matrix_value (bool) const |
5164 | 204 { |
205 return SparseComplexMatrix (this->matrix); | |
206 } | |
207 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
208 bool |
5164 | 209 octave_sparse_bool_matrix::save_binary (std::ostream& os, bool&) |
210 { | |
211 dim_vector d = this->dims (); | |
212 if (d.length() < 1) | |
213 return false; | |
214 | |
215 // Ensure that additional memory is deallocated | |
216 matrix.maybe_compress (); | |
217 | |
218 int nr = d(0); | |
219 int nc = d(1); | |
10527
b4d2080b6df7
Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents:
10315
diff
changeset
|
220 int nz = nnz (); |
5164 | 221 |
5828 | 222 int32_t itmp; |
5164 | 223 // Use negative value for ndims to be consistent with other formats |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
224 itmp= -2; |
5760 | 225 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
|
226 |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
227 itmp= nr; |
5760 | 228 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
|
229 |
5164 | 230 itmp= nc; |
5760 | 231 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
|
232 |
5164 | 233 itmp= nz; |
5760 | 234 os.write (reinterpret_cast<char *> (&itmp), 4); |
5164 | 235 |
236 // add one to the printed indices to go from | |
237 // zero-based to one-based arrays | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
238 for (int i = 0; i < nc+1; i++) |
5164 | 239 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
240 octave_quit (); |
5164 | 241 itmp = matrix.cidx(i); |
5760 | 242 os.write (reinterpret_cast<char *> (&itmp), 4); |
5164 | 243 } |
244 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
245 for (int i = 0; i < nz; i++) |
5164 | 246 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
247 octave_quit (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
248 itmp = matrix.ridx(i); |
5760 | 249 os.write (reinterpret_cast<char *> (&itmp), 4); |
5164 | 250 } |
251 | |
252 OCTAVE_LOCAL_BUFFER (char, htmp, nz); | |
253 | |
254 for (int i = 0; i < nz; i++) | |
255 htmp[i] = (matrix.data (i) ? 1 : 0); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
256 |
5164 | 257 os.write (htmp, nz); |
258 | |
259 return true; | |
260 } | |
261 | |
262 bool | |
263 octave_sparse_bool_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
|
264 oct_mach_info::float_format /* fmt */) |
5164 | 265 { |
5828 | 266 int32_t nz, nc, nr, tmp; |
5760 | 267 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
5164 | 268 return false; |
269 | |
270 if (swap) | |
271 swap_bytes<4> (&tmp); | |
272 | |
273 if (tmp != -2) { | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
274 error ("load: only 2D sparse matrices are supported"); |
5164 | 275 return false; |
276 } | |
277 | |
5760 | 278 if (! is.read (reinterpret_cast<char *> (&nr), 4)) |
5164 | 279 return false; |
5760 | 280 if (! is.read (reinterpret_cast<char *> (&nc), 4)) |
5164 | 281 return false; |
5760 | 282 if (! is.read (reinterpret_cast<char *> (&nz), 4)) |
5164 | 283 return false; |
284 | |
285 if (swap) | |
286 { | |
287 swap_bytes<4> (&nr); | |
288 swap_bytes<4> (&nc); | |
289 swap_bytes<4> (&nz); | |
290 } | |
291 | |
5275 | 292 SparseBoolMatrix m (static_cast<octave_idx_type> (nr), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
293 static_cast<octave_idx_type> (nc), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
294 static_cast<octave_idx_type> (nz)); |
5164 | 295 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
296 for (int i = 0; i < nc+1; i++) |
5164 | 297 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
298 octave_quit (); |
5760 | 299 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
|
300 return false; |
5164 | 301 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
302 swap_bytes<4> (&tmp); |
5164 | 303 m.cidx(i) = tmp; |
304 } | |
305 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
306 for (int i = 0; i < nz; i++) |
5164 | 307 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
308 octave_quit (); |
5760 | 309 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
|
310 return false; |
5164 | 311 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
312 swap_bytes<4> (&tmp); |
5164 | 313 m.ridx(i) = tmp; |
314 } | |
315 | |
316 if (error_state || ! is) | |
317 return false; | |
318 | |
319 OCTAVE_LOCAL_BUFFER (char, htmp, nz); | |
320 | |
321 if (! is.read (htmp, nz)) | |
322 return false; | |
323 | |
324 for (int i = 0; i < nz; i++) | |
325 m.data(i) = (htmp[i] ? 1 : 0); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
326 |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
327 if (! m.indices_ok ()) |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
328 return false; |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
329 |
5164 | 330 matrix = m; |
331 | |
332 return true; | |
333 } | |
334 | |
335 #if defined (HAVE_HDF5) | |
5900 | 336 |
5164 | 337 bool |
338 octave_sparse_bool_matrix::save_hdf5 (hid_t loc_id, const char *name, bool) | |
339 { | |
340 dim_vector dv = dims (); | |
341 int empty = save_hdf5_empty (loc_id, name, dv); | |
342 if (empty) | |
343 return (empty > 0); | |
344 | |
345 // Ensure that additional memory is deallocated | |
346 matrix.maybe_compress (); | |
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
|
347 #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
|
348 hid_t group_hid = H5Gcreate (loc_id, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
349 #else |
5164 | 350 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
|
351 #endif |
5164 | 352 if (group_hid < 0) |
353 return false; | |
354 | |
355 hid_t space_hid = -1, data_hid = -1; | |
356 bool retval = true; | |
357 SparseBoolMatrix m = sparse_bool_matrix_value (); | |
5351 | 358 octave_idx_type tmp; |
5164 | 359 hsize_t hdims[2]; |
360 | |
5760 | 361 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
|
362 if (space_hid < 0) |
5164 | 363 { |
364 H5Gclose (group_hid); | |
365 return false; | |
366 } | |
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
|
367 #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
|
368 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
|
369 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
|
370 #else |
5760 | 371 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
|
372 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
|
373 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
374 if (data_hid < 0) |
5164 | 375 { |
376 H5Sclose (space_hid); | |
377 H5Gclose (group_hid); | |
378 return false; | |
379 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
380 |
5164 | 381 tmp = m.rows (); |
5760 | 382 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, &tmp) >= 0; |
5164 | 383 H5Dclose (data_hid); |
384 if (!retval) | |
385 { | |
386 H5Sclose (space_hid); | |
387 H5Gclose (group_hid); | |
388 return false; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
389 } |
5164 | 390 |
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
|
391 #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
|
392 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
|
393 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
|
394 #else |
5760 | 395 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
|
396 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
|
397 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
398 if (data_hid < 0) |
5164 | 399 { |
400 H5Sclose (space_hid); | |
401 H5Gclose (group_hid); | |
402 return false; | |
403 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
404 |
5164 | 405 tmp = m.cols (); |
5351 | 406 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
|
407 H5P_DEFAULT, &tmp) >= 0; |
5164 | 408 H5Dclose (data_hid); |
409 if (!retval) | |
410 { | |
411 H5Sclose (space_hid); | |
412 H5Gclose (group_hid); | |
413 return false; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
414 } |
5164 | 415 |
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
|
416 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
417 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
|
418 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
|
419 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
420 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
|
421 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
|
422 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
423 if (data_hid < 0) |
5164 | 424 { |
425 H5Sclose (space_hid); | |
426 H5Gclose (group_hid); | |
427 return false; | |
428 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
429 |
10527
b4d2080b6df7
Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents:
10315
diff
changeset
|
430 tmp = m.nnz (); |
5351 | 431 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
|
432 H5P_DEFAULT, &tmp) >= 0; |
5164 | 433 H5Dclose (data_hid); |
434 if (!retval) | |
435 { | |
436 H5Sclose (space_hid); | |
437 H5Gclose (group_hid); | |
438 return false; | |
439 } | |
440 | |
441 H5Sclose (space_hid); | |
442 | |
443 hdims[0] = m.cols() + 1; | |
444 hdims[1] = 1; | |
445 | |
446 space_hid = H5Screate_simple (2, hdims, 0); | |
447 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
448 if (space_hid < 0) |
5164 | 449 { |
450 H5Gclose (group_hid); | |
451 return false; | |
452 } | |
453 | |
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
|
454 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
455 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
|
456 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
|
457 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
458 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
|
459 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
|
460 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
461 if (data_hid < 0) |
5164 | 462 { |
463 H5Sclose (space_hid); | |
464 H5Gclose (group_hid); | |
465 return false; | |
466 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
467 |
5351 | 468 octave_idx_type * itmp = m.xcidx (); |
469 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
|
470 H5P_DEFAULT, itmp) >= 0; |
5164 | 471 H5Dclose (data_hid); |
472 if (!retval) | |
473 { | |
474 H5Sclose (space_hid); | |
475 H5Gclose (group_hid); | |
476 return false; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
477 } |
5164 | 478 |
479 H5Sclose (space_hid); | |
480 | |
10527
b4d2080b6df7
Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents:
10315
diff
changeset
|
481 hdims[0] = m.nnz (); |
5164 | 482 hdims[1] = 1; |
483 | |
484 space_hid = H5Screate_simple (2, hdims, 0); | |
485 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
486 if (space_hid < 0) |
5164 | 487 { |
488 H5Gclose (group_hid); | |
489 return false; | |
490 } | |
491 | |
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
|
492 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
493 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
|
494 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
|
495 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
496 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
|
497 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
|
498 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
499 if (data_hid < 0) |
5164 | 500 { |
501 H5Sclose (space_hid); | |
502 H5Gclose (group_hid); | |
503 return false; | |
504 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
505 |
5164 | 506 itmp = m.xridx (); |
5351 | 507 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
|
508 H5P_DEFAULT, itmp) >= 0; |
5164 | 509 H5Dclose (data_hid); |
510 if (!retval) | |
511 { | |
512 H5Sclose (space_hid); | |
513 H5Gclose (group_hid); | |
514 return false; | |
515 } | |
516 | |
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
|
517 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
518 data_hid = H5Dcreate (group_hid, "data", H5T_NATIVE_HBOOL, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
519 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
|
520 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
521 data_hid = H5Dcreate (group_hid, "data", H5T_NATIVE_HBOOL, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
522 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
|
523 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
524 if (data_hid < 0) |
5164 | 525 { |
526 H5Sclose (space_hid); | |
527 H5Gclose (group_hid); | |
528 return false; | |
529 } | |
6276 | 530 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
531 OCTAVE_LOCAL_BUFFER (hbool_t, htmp, m.nnz ()); |
10527
b4d2080b6df7
Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents:
10315
diff
changeset
|
532 for (int i = 0; i < m.nnz (); i++) |
5164 | 533 htmp[i] = m.xdata(i); |
534 | |
535 retval = H5Dwrite (data_hid, H5T_NATIVE_HBOOL, H5S_ALL, H5S_ALL, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
536 H5P_DEFAULT, htmp) >= 0; |
5164 | 537 H5Dclose (data_hid); |
538 H5Sclose (space_hid); | |
539 H5Gclose (group_hid); | |
540 | |
541 return retval; | |
542 } | |
543 | |
544 bool | |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
9469
diff
changeset
|
545 octave_sparse_bool_matrix::load_hdf5 (hid_t loc_id, const char *name) |
5164 | 546 { |
5351 | 547 octave_idx_type nr, nc, nz; |
5164 | 548 hid_t group_hid, data_hid, space_hid; |
549 hsize_t rank; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
550 |
5164 | 551 dim_vector dv; |
552 int empty = load_hdf5_empty (loc_id, name, dv); | |
553 if (empty > 0) | |
554 matrix.resize(dv); | |
555 if (empty) | |
556 return (empty > 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
|
557 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
558 #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
|
559 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
|
560 #else |
5164 | 561 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
|
562 #endif |
5164 | 563 if (group_hid < 0 ) return false; |
564 | |
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 #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
|
566 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
|
567 #else |
5164 | 568 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
|
569 #endif |
5164 | 570 space_hid = H5Dget_space (data_hid); |
571 rank = H5Sget_simple_extent_ndims (space_hid); | |
572 | |
573 if (rank != 0) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
574 { |
5164 | 575 H5Dclose (data_hid); |
576 H5Gclose (group_hid); | |
577 return false; | |
578 } | |
579 | |
5760 | 580 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, &nr) < 0) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
581 { |
5164 | 582 H5Dclose (data_hid); |
583 H5Gclose (group_hid); | |
584 return false; | |
585 } | |
586 | |
587 H5Dclose (data_hid); | |
588 | |
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
|
589 #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
|
590 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
|
591 #else |
5164 | 592 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
|
593 #endif |
5164 | 594 space_hid = H5Dget_space (data_hid); |
595 rank = H5Sget_simple_extent_ndims (space_hid); | |
596 | |
597 if (rank != 0) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
598 { |
5164 | 599 H5Dclose (data_hid); |
600 H5Gclose (group_hid); | |
601 return false; | |
602 } | |
603 | |
5760 | 604 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, &nc) < 0) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
605 { |
5164 | 606 H5Dclose (data_hid); |
607 H5Gclose (group_hid); | |
608 return false; | |
609 } | |
610 | |
611 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
|
612 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
613 #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
|
614 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
|
615 #else |
5164 | 616 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
|
617 #endif |
5164 | 618 space_hid = H5Dget_space (data_hid); |
619 rank = H5Sget_simple_extent_ndims (space_hid); | |
620 | |
621 if (rank != 0) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
622 { |
5164 | 623 H5Dclose (data_hid); |
624 H5Gclose (group_hid); | |
625 return false; | |
626 } | |
627 | |
5760 | 628 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, &nz) < 0) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
629 { |
5164 | 630 H5Dclose (data_hid); |
631 H5Gclose (group_hid); | |
632 return false; | |
633 } | |
634 | |
635 H5Dclose (data_hid); | |
636 | |
5275 | 637 SparseBoolMatrix m (static_cast<octave_idx_type> (nr), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
638 static_cast<octave_idx_type> (nc), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
639 static_cast<octave_idx_type> (nz)); |
5164 | 640 |
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
|
641 #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
|
642 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
|
643 #else |
5164 | 644 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
|
645 #endif |
5164 | 646 space_hid = H5Dget_space (data_hid); |
647 rank = H5Sget_simple_extent_ndims (space_hid); | |
648 | |
649 if (rank != 2) | |
650 { | |
651 H5Sclose (space_hid); | |
652 H5Dclose (data_hid); | |
653 H5Gclose (group_hid); | |
654 return false; | |
655 } | |
656 | |
657 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); | |
658 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); | |
659 | |
660 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); | |
661 | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
662 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
|
663 || static_cast<int> (hdims[1]) != 1) |
5164 | 664 { |
665 H5Sclose (space_hid); | |
666 H5Dclose (data_hid); | |
667 H5Gclose (group_hid); | |
668 return false; | |
669 } | |
670 | |
5351 | 671 octave_idx_type *itmp = m.xcidx (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
672 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, itmp) < 0) |
5164 | 673 { |
674 H5Sclose (space_hid); | |
675 H5Dclose (data_hid); | |
676 H5Gclose (group_hid); | |
677 return false; | |
678 } | |
679 | |
680 H5Sclose (space_hid); | |
681 H5Dclose (data_hid); | |
682 | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
683 #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
|
684 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
|
685 #else |
5164 | 686 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
|
687 #endif |
5164 | 688 space_hid = H5Dget_space (data_hid); |
689 rank = H5Sget_simple_extent_ndims (space_hid); | |
690 | |
691 if (rank != 2) | |
692 { | |
693 H5Sclose (space_hid); | |
694 H5Dclose (data_hid); | |
695 H5Gclose (group_hid); | |
696 return false; | |
697 } | |
698 | |
699 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); | |
700 | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
701 if (static_cast<int> (hdims[0]) != nz |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
702 || static_cast<int> (hdims[1]) != 1) |
5164 | 703 { |
704 H5Sclose (space_hid); | |
705 H5Dclose (data_hid); | |
706 H5Gclose (group_hid); | |
707 return false; | |
708 } | |
709 | |
710 itmp = m.xridx (); | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
711 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
712 H5P_DEFAULT, itmp) < 0) |
5164 | 713 { |
714 H5Sclose (space_hid); | |
715 H5Dclose (data_hid); | |
716 H5Gclose (group_hid); | |
717 return false; | |
718 } | |
719 | |
720 H5Sclose (space_hid); | |
721 H5Dclose (data_hid); | |
722 | |
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
|
723 #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
|
724 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
|
725 #else |
5164 | 726 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
|
727 #endif |
5164 | 728 space_hid = H5Dget_space (data_hid); |
729 rank = H5Sget_simple_extent_ndims (space_hid); | |
730 | |
731 if (rank != 2) | |
732 { | |
733 H5Sclose (space_hid); | |
734 H5Dclose (data_hid); | |
735 H5Gclose (group_hid); | |
736 return false; | |
737 } | |
738 | |
739 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); | |
740 | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
741 if (static_cast<int> (hdims[0]) != nz |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
742 || static_cast<int> (hdims[1]) != 1) |
5164 | 743 { |
744 H5Sclose (space_hid); | |
745 H5Dclose (data_hid); | |
746 H5Gclose (group_hid); | |
747 return false; | |
748 } | |
749 | |
6775 | 750 OCTAVE_LOCAL_BUFFER (hbool_t, htmp, nz); |
5164 | 751 bool retval = false; |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
752 if (H5Dread (data_hid, H5T_NATIVE_HBOOL, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
753 H5P_DEFAULT, htmp) >= 0 |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
754 && m.indices_ok ()) |
5164 | 755 { |
756 retval = true; | |
757 | |
758 for (int i = 0; i < nz; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
759 m.xdata(i) = htmp[i]; |
5164 | 760 |
761 matrix = m; | |
762 } | |
763 | |
764 H5Sclose (space_hid); | |
765 H5Dclose (data_hid); | |
766 H5Gclose (group_hid); | |
767 | |
768 return retval; | |
769 } | |
5900 | 770 |
5164 | 771 #endif |
772 | |
5900 | 773 mxArray * |
774 octave_sparse_bool_matrix::as_mxArray (void) const | |
775 { | |
6686 | 776 mwSize nz = nzmax (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
777 mxArray *retval = new mxArray (mxLOGICAL_CLASS, rows (), columns (), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
778 nz, mxREAL); |
5903 | 779 bool *pr = static_cast<bool *> (retval->get_data ()); |
6686 | 780 mwIndex *ir = retval->get_ir (); |
781 mwIndex *jc = retval->get_jc (); | |
5903 | 782 |
6686 | 783 for (mwIndex i = 0; i < nz; i++) |
5903 | 784 { |
785 pr[i] = matrix.data(i); | |
786 ir[i] = matrix.ridx(i); | |
787 } | |
788 | |
6686 | 789 for (mwIndex i = 0; i < columns () + 1; i++) |
5903 | 790 jc[i] = matrix.cidx(i); |
791 | |
792 return retval; | |
5900 | 793 } |