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