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