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