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