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