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 { |
|
113 // XXX FIXME XXX |
|
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 |
|
122 if (! force_conversion && Vwarn_imag_to_real) |
|
123 gripe_implicit_conversion ("complex sparse matrix", "real scalar"); |
|
124 |
|
125 // XXX FIXME XXX -- maybe this should be a function, valid_as_scalar() |
|
126 if (numel () > 0) |
|
127 { |
|
128 // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? |
|
129 if (Vwarn_fortran_indexing) |
|
130 gripe_implicit_conversion ("complex sparse matrix", "real scalar"); |
|
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 |
|
145 if (! force_conversion && Vwarn_imag_to_real) |
|
146 gripe_implicit_conversion ("complex sparse matrix", "real matrix"); |
|
147 |
|
148 retval = ::real (matrix.matrix_value ()); |
|
149 |
|
150 return retval; |
|
151 } |
|
152 |
|
153 Complex |
|
154 octave_sparse_complex_matrix::complex_value (bool) const |
|
155 { |
|
156 double tmp = lo_ieee_nan_value (); |
|
157 |
|
158 Complex retval (tmp, tmp); |
|
159 |
|
160 // XXX FIXME XXX -- maybe this should be a function, valid_as_scalar() |
|
161 if (numel () > 0) |
|
162 { |
|
163 // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? |
|
164 if (Vwarn_fortran_indexing) |
|
165 gripe_implicit_conversion ("complex sparse matrix", "real scalar"); |
|
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 |
|
192 if (! force_conversion && Vwarn_imag_to_real) |
|
193 gripe_implicit_conversion ("complex sparse matrix", |
|
194 "real sparse matrix"); |
|
195 |
|
196 retval = ::real (matrix); |
|
197 |
|
198 return retval; |
|
199 } |
|
200 |
|
201 bool |
|
202 octave_sparse_complex_matrix::save_binary (std::ostream& os, |
|
203 bool&save_as_floats) |
|
204 { |
|
205 dim_vector d = this->dims (); |
|
206 if (d.length() < 1) |
|
207 return false; |
|
208 |
|
209 // Ensure that additional memory is deallocated |
|
210 matrix.maybe_compress (); |
|
211 |
|
212 int nr = d(0); |
|
213 int nc = d(1); |
5604
|
214 int nz = nzmax (); |
5164
|
215 |
|
216 FOUR_BYTE_INT itmp; |
|
217 // Use negative value for ndims to be consistent with other formats |
|
218 itmp= -2; |
5760
|
219 os.write (reinterpret_cast<char *> (&itmp), 4); |
5164
|
220 |
|
221 itmp= nr; |
5760
|
222 os.write (reinterpret_cast<char *> (&itmp), 4); |
5164
|
223 |
|
224 itmp= nc; |
5760
|
225 os.write (reinterpret_cast<char *> (&itmp), 4); |
5164
|
226 |
|
227 itmp= nz; |
5760
|
228 os.write (reinterpret_cast<char *> (&itmp), 4); |
5164
|
229 |
|
230 save_type st = LS_DOUBLE; |
|
231 if (save_as_floats) |
|
232 { |
|
233 if (matrix.too_large_for_float ()) |
|
234 { |
|
235 warning ("save: some values too large to save as floats --"); |
|
236 warning ("save: saving as doubles instead"); |
|
237 } |
|
238 else |
|
239 st = LS_FLOAT; |
|
240 } |
5604
|
241 else if (matrix.nzmax () > 8192) // XXX FIXME XXX -- make this configurable. |
5164
|
242 { |
|
243 double max_val, min_val; |
|
244 if (matrix.all_integers (max_val, min_val)) |
|
245 st = get_save_type (max_val, min_val); |
|
246 } |
|
247 |
|
248 // add one to the printed indices to go from |
|
249 // zero-based to one-based arrays |
|
250 for (int i = 0; i < nc+1; i++) |
|
251 { |
|
252 OCTAVE_QUIT; |
|
253 itmp = matrix.cidx(i); |
5760
|
254 os.write (reinterpret_cast<char *> (&itmp), 4); |
5164
|
255 } |
|
256 |
|
257 for (int i = 0; i < nz; i++) |
|
258 { |
|
259 OCTAVE_QUIT; |
|
260 itmp = matrix.ridx(i); |
5760
|
261 os.write (reinterpret_cast<char *> (&itmp), 4); |
5164
|
262 } |
|
263 |
5760
|
264 write_doubles (os, reinterpret_cast<const double *> (matrix.data()), st, 2 * nz); |
5164
|
265 |
|
266 return true; |
|
267 } |
|
268 |
|
269 bool |
|
270 octave_sparse_complex_matrix::load_binary (std::istream& is, bool swap, |
|
271 oct_mach_info::float_format fmt) |
|
272 { |
|
273 FOUR_BYTE_INT nz, nc, nr, tmp; |
5327
|
274 char ctmp; |
|
275 |
5760
|
276 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
5164
|
277 return false; |
|
278 |
|
279 if (swap) |
|
280 swap_bytes<4> (&tmp); |
|
281 |
|
282 if (tmp != -2) { |
|
283 error("load: only 2D sparse matrices are supported"); |
|
284 return false; |
|
285 } |
|
286 |
5760
|
287 if (! is.read (reinterpret_cast<char *> (&nr), 4)) |
5164
|
288 return false; |
5760
|
289 if (! is.read (reinterpret_cast<char *> (&nc), 4)) |
5164
|
290 return false; |
5760
|
291 if (! is.read (reinterpret_cast<char *> (&nz), 4)) |
5164
|
292 return false; |
|
293 |
|
294 if (swap) |
|
295 { |
|
296 swap_bytes<4> (&nr); |
|
297 swap_bytes<4> (&nc); |
|
298 swap_bytes<4> (&nz); |
|
299 } |
|
300 |
5275
|
301 SparseComplexMatrix m (static_cast<octave_idx_type> (nr), |
|
302 static_cast<octave_idx_type> (nc), |
|
303 static_cast<octave_idx_type> (nz)); |
5164
|
304 |
|
305 for (int i = 0; i < nc+1; i++) |
|
306 { |
|
307 OCTAVE_QUIT; |
5760
|
308 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
5164
|
309 return false; |
|
310 if (swap) |
|
311 swap_bytes<4> (&tmp); |
|
312 m.cidx(i) = tmp; |
|
313 } |
|
314 |
|
315 for (int i = 0; i < nz; i++) |
|
316 { |
|
317 OCTAVE_QUIT; |
5760
|
318 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
5164
|
319 return false; |
|
320 if (swap) |
|
321 swap_bytes<4> (&tmp); |
|
322 m.ridx(i) = tmp; |
|
323 } |
|
324 |
5760
|
325 if (! is.read (reinterpret_cast<char *> (&ctmp), 1)) |
5164
|
326 return false; |
|
327 |
5760
|
328 read_doubles (is, reinterpret_cast<double *> (m.data ()), |
|
329 static_cast<save_type> (ctmp), 2 * nz, swap, fmt); |
5164
|
330 |
|
331 if (error_state || ! is) |
|
332 return false; |
|
333 matrix = m; |
|
334 |
|
335 return true; |
|
336 } |
|
337 |
|
338 #if defined (HAVE_HDF5) |
|
339 bool |
|
340 octave_sparse_complex_matrix::save_hdf5 (hid_t loc_id, const char *name, |
|
341 bool save_as_floats) |
|
342 { |
|
343 dim_vector dv = dims (); |
|
344 int empty = save_hdf5_empty (loc_id, name, dv); |
|
345 if (empty) |
|
346 return (empty > 0); |
|
347 |
|
348 // Ensure that additional memory is deallocated |
|
349 matrix.maybe_compress (); |
|
350 |
|
351 hid_t group_hid = H5Gcreate (loc_id, name, 0); |
|
352 if (group_hid < 0) |
|
353 return false; |
|
354 |
|
355 hid_t space_hid = -1, data_hid = -1; |
|
356 bool retval = true; |
|
357 SparseComplexMatrix m = sparse_complex_matrix_value (); |
5351
|
358 octave_idx_type tmp; |
5164
|
359 hsize_t hdims[2]; |
|
360 |
5760
|
361 space_hid = H5Screate_simple (0, hdims, 0); |
5164
|
362 if (space_hid < 0) |
|
363 { |
|
364 H5Gclose (group_hid); |
|
365 return false; |
|
366 } |
|
367 |
5351
|
368 data_hid = H5Dcreate (group_hid, "nr", H5T_NATIVE_IDX, space_hid, |
5164
|
369 H5P_DEFAULT); |
|
370 if (data_hid < 0) |
|
371 { |
|
372 H5Sclose (space_hid); |
|
373 H5Gclose (group_hid); |
|
374 return false; |
|
375 } |
|
376 |
|
377 tmp = m.rows (); |
5351
|
378 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
5760
|
379 H5P_DEFAULT, &tmp) >= 0; |
5164
|
380 H5Dclose (data_hid); |
|
381 if (!retval) |
|
382 { |
|
383 H5Sclose (space_hid); |
|
384 H5Gclose (group_hid); |
|
385 return false; |
|
386 } |
|
387 |
5351
|
388 data_hid = H5Dcreate (group_hid, "nc", H5T_NATIVE_IDX, space_hid, |
5164
|
389 H5P_DEFAULT); |
|
390 if (data_hid < 0) |
|
391 { |
|
392 H5Sclose (space_hid); |
|
393 H5Gclose (group_hid); |
|
394 return false; |
|
395 } |
|
396 |
|
397 tmp = m.cols (); |
5351
|
398 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
5760
|
399 H5P_DEFAULT, &tmp) >= 0; |
5164
|
400 H5Dclose (data_hid); |
|
401 if (!retval) |
|
402 { |
|
403 H5Sclose (space_hid); |
|
404 H5Gclose (group_hid); |
|
405 return false; |
|
406 } |
|
407 |
5351
|
408 data_hid = H5Dcreate (group_hid, "nz", H5T_NATIVE_IDX, space_hid, |
5164
|
409 H5P_DEFAULT); |
|
410 if (data_hid < 0) |
|
411 { |
|
412 H5Sclose (space_hid); |
|
413 H5Gclose (group_hid); |
|
414 return false; |
|
415 } |
|
416 |
5604
|
417 tmp = m.nzmax (); |
5351
|
418 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
5760
|
419 H5P_DEFAULT, &tmp) >= 0; |
5164
|
420 H5Dclose (data_hid); |
|
421 if (!retval) |
|
422 { |
|
423 H5Sclose (space_hid); |
|
424 H5Gclose (group_hid); |
|
425 return false; |
|
426 } |
|
427 |
|
428 H5Sclose (space_hid); |
|
429 |
|
430 hdims[0] = m.cols() + 1; |
|
431 hdims[1] = 1; |
|
432 |
|
433 space_hid = H5Screate_simple (2, hdims, 0); |
|
434 |
|
435 if (space_hid < 0) |
|
436 { |
|
437 H5Gclose (group_hid); |
|
438 return false; |
|
439 } |
|
440 |
5351
|
441 data_hid = H5Dcreate (group_hid, "cidx", H5T_NATIVE_IDX, space_hid, |
5164
|
442 H5P_DEFAULT); |
|
443 if (data_hid < 0) |
|
444 { |
|
445 H5Sclose (space_hid); |
|
446 H5Gclose (group_hid); |
|
447 return false; |
|
448 } |
|
449 |
5351
|
450 octave_idx_type * itmp = m.xcidx (); |
|
451 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
5760
|
452 H5P_DEFAULT, itmp) >= 0; |
5164
|
453 H5Dclose (data_hid); |
|
454 if (!retval) |
|
455 { |
|
456 H5Sclose (space_hid); |
|
457 H5Gclose (group_hid); |
|
458 return false; |
|
459 } |
|
460 |
|
461 H5Sclose (space_hid); |
|
462 |
5604
|
463 hdims[0] = m.nzmax (); |
5164
|
464 hdims[1] = 1; |
|
465 |
|
466 space_hid = H5Screate_simple (2, hdims, 0); |
|
467 |
|
468 if (space_hid < 0) |
|
469 { |
|
470 H5Gclose (group_hid); |
|
471 return false; |
|
472 } |
|
473 |
5351
|
474 data_hid = H5Dcreate (group_hid, "ridx", H5T_NATIVE_IDX, space_hid, |
5164
|
475 H5P_DEFAULT); |
|
476 if (data_hid < 0) |
|
477 { |
|
478 H5Sclose (space_hid); |
|
479 H5Gclose (group_hid); |
|
480 return false; |
|
481 } |
|
482 |
|
483 itmp = m.xridx (); |
5760
|
484 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, itmp) >= 0; |
5164
|
485 H5Dclose (data_hid); |
|
486 if (!retval) |
|
487 { |
|
488 H5Sclose (space_hid); |
|
489 H5Gclose (group_hid); |
|
490 return false; |
|
491 } |
|
492 |
|
493 hid_t save_type_hid = H5T_NATIVE_DOUBLE; |
|
494 |
|
495 if (save_as_floats) |
|
496 { |
|
497 if (m.too_large_for_float ()) |
|
498 { |
|
499 warning ("save: some values too large to save as floats --"); |
|
500 warning ("save: saving as doubles instead"); |
|
501 } |
|
502 else |
|
503 save_type_hid = H5T_NATIVE_FLOAT; |
|
504 } |
|
505 #if HAVE_HDF5_INT2FLOAT_CONVERSIONS |
|
506 // hdf5 currently doesn't support float/integer conversions |
|
507 else |
|
508 { |
|
509 double max_val, min_val; |
|
510 |
|
511 if (m.all_integers (max_val, min_val)) |
|
512 save_type_hid |
|
513 = save_type_to_hdf5 (get_save_type (max_val, min_val)); |
|
514 } |
|
515 #endif /* HAVE_HDF5_INT2FLOAT_CONVERSIONS */ |
|
516 |
|
517 hid_t type_hid = hdf5_make_complex_type (save_type_hid); |
|
518 if (type_hid < 0) |
|
519 { |
|
520 H5Sclose (space_hid); |
|
521 H5Gclose (group_hid); |
|
522 return false; |
|
523 } |
|
524 |
5760
|
525 data_hid = H5Dcreate (group_hid, "data", type_hid, space_hid, H5P_DEFAULT); |
5164
|
526 if (data_hid < 0) |
|
527 { |
|
528 H5Sclose (space_hid); |
|
529 H5Tclose (type_hid); |
|
530 H5Gclose (group_hid); |
|
531 return false; |
|
532 } |
|
533 |
|
534 hid_t complex_type_hid = hdf5_make_complex_type (H5T_NATIVE_DOUBLE); |
|
535 retval = false; |
|
536 if (complex_type_hid >= 0) |
|
537 { |
|
538 Complex * ctmp = m.xdata (); |
|
539 |
|
540 retval = H5Dwrite (data_hid, complex_type_hid, H5S_ALL, H5S_ALL, |
5760
|
541 H5P_DEFAULT, ctmp) >= 0; |
5164
|
542 } |
|
543 |
|
544 H5Dclose (data_hid); |
|
545 H5Sclose (space_hid); |
|
546 H5Tclose (type_hid); |
|
547 H5Gclose (group_hid); |
|
548 |
|
549 return retval; |
|
550 } |
|
551 |
|
552 bool |
|
553 octave_sparse_complex_matrix::load_hdf5 (hid_t loc_id, const char *name, |
|
554 bool /* have_h5giterate_bug */) |
|
555 { |
5351
|
556 octave_idx_type nr, nc, nz; |
5164
|
557 hid_t group_hid, data_hid, space_hid; |
|
558 hsize_t rank; |
|
559 |
|
560 dim_vector dv; |
|
561 int empty = load_hdf5_empty (loc_id, name, dv); |
|
562 if (empty > 0) |
|
563 matrix.resize(dv); |
|
564 if (empty) |
|
565 return (empty > 0); |
|
566 |
|
567 group_hid = H5Gopen (loc_id, name); |
|
568 if (group_hid < 0 ) return false; |
|
569 |
|
570 data_hid = H5Dopen (group_hid, "nr"); |
|
571 space_hid = H5Dget_space (data_hid); |
|
572 rank = H5Sget_simple_extent_ndims (space_hid); |
|
573 |
|
574 if (rank != 0) |
|
575 { |
|
576 H5Dclose (data_hid); |
|
577 H5Gclose (group_hid); |
|
578 return false; |
|
579 } |
|
580 |
5760
|
581 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, &nr) < 0) |
5164
|
582 { |
|
583 H5Dclose (data_hid); |
|
584 H5Gclose (group_hid); |
|
585 return false; |
|
586 } |
|
587 |
|
588 H5Dclose (data_hid); |
|
589 |
|
590 data_hid = H5Dopen (group_hid, "nc"); |
|
591 space_hid = H5Dget_space (data_hid); |
|
592 rank = H5Sget_simple_extent_ndims (space_hid); |
|
593 |
|
594 if (rank != 0) |
|
595 { |
|
596 H5Dclose (data_hid); |
|
597 H5Gclose (group_hid); |
|
598 return false; |
|
599 } |
|
600 |
5760
|
601 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, &nc) < 0) |
5164
|
602 { |
|
603 H5Dclose (data_hid); |
|
604 H5Gclose (group_hid); |
|
605 return false; |
|
606 } |
|
607 |
|
608 H5Dclose (data_hid); |
|
609 |
|
610 data_hid = H5Dopen (group_hid, "nz"); |
|
611 space_hid = H5Dget_space (data_hid); |
|
612 rank = H5Sget_simple_extent_ndims (space_hid); |
|
613 |
|
614 if (rank != 0) |
|
615 { |
|
616 H5Dclose (data_hid); |
|
617 H5Gclose (group_hid); |
|
618 return false; |
|
619 } |
|
620 |
5760
|
621 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, &nz) < 0) |
5164
|
622 { |
|
623 H5Dclose (data_hid); |
|
624 H5Gclose (group_hid); |
|
625 return false; |
|
626 } |
|
627 |
|
628 H5Dclose (data_hid); |
|
629 |
5275
|
630 SparseComplexMatrix m (static_cast<octave_idx_type> (nr), |
|
631 static_cast<octave_idx_type> (nc), |
|
632 static_cast<octave_idx_type> (nz)); |
5164
|
633 |
|
634 data_hid = H5Dopen (group_hid, "cidx"); |
|
635 space_hid = H5Dget_space (data_hid); |
|
636 rank = H5Sget_simple_extent_ndims (space_hid); |
|
637 |
|
638 if (rank != 2) |
|
639 { |
|
640 H5Sclose (space_hid); |
|
641 H5Dclose (data_hid); |
|
642 H5Gclose (group_hid); |
|
643 return false; |
|
644 } |
|
645 |
|
646 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); |
|
647 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); |
|
648 |
|
649 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); |
|
650 |
5322
|
651 if (static_cast<int> (hdims[0]) != nc + 1 || |
|
652 static_cast<int> (hdims[1]) != 1) |
5164
|
653 { |
|
654 H5Sclose (space_hid); |
|
655 H5Dclose (data_hid); |
|
656 H5Gclose (group_hid); |
|
657 return false; |
|
658 } |
|
659 |
5351
|
660 octave_idx_type *itmp = m.xcidx (); |
5760
|
661 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, itmp) < 0) |
5164
|
662 { |
|
663 H5Sclose (space_hid); |
|
664 H5Dclose (data_hid); |
|
665 H5Gclose (group_hid); |
|
666 return false; |
|
667 } |
|
668 |
|
669 H5Sclose (space_hid); |
|
670 H5Dclose (data_hid); |
|
671 |
|
672 data_hid = H5Dopen (group_hid, "ridx"); |
|
673 space_hid = H5Dget_space (data_hid); |
|
674 rank = H5Sget_simple_extent_ndims (space_hid); |
|
675 |
|
676 if (rank != 2) |
|
677 { |
|
678 H5Sclose (space_hid); |
|
679 H5Dclose (data_hid); |
|
680 H5Gclose (group_hid); |
|
681 return false; |
|
682 } |
|
683 |
|
684 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); |
|
685 |
5351
|
686 if (static_cast<int> (hdims[0]) != nz || |
|
687 static_cast<int> (hdims[1]) != 1) |
5164
|
688 { |
|
689 H5Sclose (space_hid); |
|
690 H5Dclose (data_hid); |
|
691 H5Gclose (group_hid); |
|
692 return false; |
|
693 } |
|
694 |
|
695 itmp = m.xridx (); |
5760
|
696 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, H5P_DEFAULT, itmp) < 0) |
5164
|
697 { |
|
698 H5Sclose (space_hid); |
|
699 H5Dclose (data_hid); |
|
700 H5Gclose (group_hid); |
|
701 return false; |
|
702 } |
|
703 |
|
704 H5Sclose (space_hid); |
|
705 H5Dclose (data_hid); |
|
706 |
|
707 data_hid = H5Dopen (group_hid, "data"); |
|
708 hid_t type_hid = H5Dget_type (data_hid); |
|
709 |
|
710 hid_t complex_type = hdf5_make_complex_type (H5T_NATIVE_DOUBLE); |
|
711 |
|
712 if (! hdf5_types_compatible (type_hid, complex_type)) |
|
713 { |
|
714 H5Tclose (complex_type); |
|
715 H5Dclose (data_hid); |
|
716 H5Gclose (group_hid); |
|
717 return false; |
|
718 } |
|
719 |
|
720 space_hid = H5Dget_space (data_hid); |
|
721 rank = H5Sget_simple_extent_ndims (space_hid); |
|
722 |
|
723 if (rank != 2) |
|
724 { |
|
725 H5Sclose (space_hid); |
|
726 H5Dclose (data_hid); |
|
727 H5Gclose (group_hid); |
|
728 return false; |
|
729 } |
|
730 |
|
731 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); |
|
732 |
5351
|
733 if (static_cast<int> (hdims[0]) != nz || |
|
734 static_cast<int> (hdims[1]) != 1) |
5164
|
735 { |
|
736 H5Sclose (space_hid); |
|
737 H5Dclose (data_hid); |
|
738 H5Gclose (group_hid); |
|
739 return false; |
|
740 } |
|
741 |
|
742 Complex *ctmp = m.xdata (); |
|
743 bool retval = false; |
5760
|
744 if (H5Dread (data_hid, complex_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, ctmp) >= 0) |
5164
|
745 { |
|
746 retval = true; |
|
747 matrix = m; |
|
748 } |
|
749 |
|
750 H5Tclose (complex_type); |
|
751 H5Sclose (space_hid); |
|
752 H5Dclose (data_hid); |
|
753 H5Gclose (group_hid); |
|
754 |
|
755 return retval; |
|
756 } |
|
757 |
|
758 #endif |
|
759 |
|
760 /* |
|
761 ;;; Local Variables: *** |
|
762 ;;; mode: C++ *** |
|
763 ;;; End: *** |
|
764 */ |