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