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 |
|
51 octave_value * |
|
52 octave_sparse_complex_matrix::try_narrowing_conversion (void) |
|
53 { |
|
54 octave_value *retval = 0; |
|
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); |
|
214 int nz = nnz (); |
|
215 |
|
216 FOUR_BYTE_INT itmp; |
|
217 // Use negative value for ndims to be consistent with other formats |
|
218 itmp= -2; |
|
219 os.write (X_CAST (char *, &itmp), 4); |
|
220 |
|
221 itmp= nr; |
|
222 os.write (X_CAST (char *, &itmp), 4); |
|
223 |
|
224 itmp= nc; |
|
225 os.write (X_CAST (char *, &itmp), 4); |
|
226 |
|
227 itmp= nz; |
|
228 os.write (X_CAST (char *, &itmp), 4); |
|
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 } |
|
241 else if (matrix.nnz () > 8192) // XXX FIXME XXX -- make this configurable. |
|
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); |
|
254 os.write (X_CAST (char *, &itmp), 4); |
|
255 } |
|
256 |
|
257 for (int i = 0; i < nz; i++) |
|
258 { |
|
259 OCTAVE_QUIT; |
|
260 itmp = matrix.ridx(i); |
|
261 os.write (X_CAST (char *, &itmp), 4); |
|
262 } |
|
263 |
|
264 write_doubles (os, X_CAST (const double *, matrix.data()), st, 2 * nz); |
|
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 |
5164
|
276 if (! is.read (X_CAST (char *, &tmp), 4)) |
|
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 |
|
287 if (! is.read (X_CAST (char *, &nr), 4)) |
|
288 return false; |
|
289 if (! is.read (X_CAST (char *, &nc), 4)) |
|
290 return false; |
|
291 if (! is.read (X_CAST (char *, &nz), 4)) |
|
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; |
|
308 if (! is.read (X_CAST (char *, &tmp), 4)) |
|
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; |
|
318 if (! is.read (X_CAST (char *, &tmp), 4)) |
|
319 return false; |
|
320 if (swap) |
|
321 swap_bytes<4> (&tmp); |
|
322 m.ridx(i) = tmp; |
|
323 } |
|
324 |
5327
|
325 if (! is.read (X_CAST (char *, &ctmp), 1)) |
5164
|
326 return false; |
|
327 |
5327
|
328 read_doubles (is, X_CAST(double *, m.data()), X_CAST (save_type, ctmp), |
5164
|
329 2 * nz, swap, fmt); |
|
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 |
|
361 space_hid = H5Screate_simple (0, hdims, (hsize_t*) 0); |
|
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, |
|
379 H5P_DEFAULT, (void*) &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, |
|
399 H5P_DEFAULT, (void*) &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 |
|
417 tmp = m.nnz (); |
5351
|
418 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
|
419 H5P_DEFAULT, (void*) &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, |
|
452 H5P_DEFAULT, (void*) 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 |
|
463 hdims[0] = m.nnz(); |
|
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 (); |
5351
|
484 retval = H5Dwrite (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
|
485 H5P_DEFAULT, (void*) 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 |
5351
|
526 data_hid = H5Dcreate (group_hid, "data", type_hid, space_hid, |
|
527 H5P_DEFAULT); |
5164
|
528 if (data_hid < 0) |
|
529 { |
|
530 H5Sclose (space_hid); |
|
531 H5Tclose (type_hid); |
|
532 H5Gclose (group_hid); |
|
533 return false; |
|
534 } |
|
535 |
|
536 hid_t complex_type_hid = hdf5_make_complex_type (H5T_NATIVE_DOUBLE); |
|
537 retval = false; |
|
538 if (complex_type_hid >= 0) |
|
539 { |
|
540 Complex * ctmp = m.xdata (); |
|
541 |
|
542 retval = H5Dwrite (data_hid, complex_type_hid, H5S_ALL, H5S_ALL, |
|
543 H5P_DEFAULT, (void*) ctmp) >= 0; |
|
544 } |
|
545 |
|
546 H5Dclose (data_hid); |
|
547 H5Sclose (space_hid); |
|
548 H5Tclose (type_hid); |
|
549 H5Gclose (group_hid); |
|
550 |
|
551 return retval; |
|
552 } |
|
553 |
|
554 bool |
|
555 octave_sparse_complex_matrix::load_hdf5 (hid_t loc_id, const char *name, |
|
556 bool /* have_h5giterate_bug */) |
|
557 { |
5351
|
558 octave_idx_type nr, nc, nz; |
5164
|
559 hid_t group_hid, data_hid, space_hid; |
|
560 hsize_t rank; |
|
561 |
|
562 dim_vector dv; |
|
563 int empty = load_hdf5_empty (loc_id, name, dv); |
|
564 if (empty > 0) |
|
565 matrix.resize(dv); |
|
566 if (empty) |
|
567 return (empty > 0); |
|
568 |
|
569 group_hid = H5Gopen (loc_id, name); |
|
570 if (group_hid < 0 ) return false; |
|
571 |
|
572 data_hid = H5Dopen (group_hid, "nr"); |
|
573 space_hid = H5Dget_space (data_hid); |
|
574 rank = H5Sget_simple_extent_ndims (space_hid); |
|
575 |
|
576 if (rank != 0) |
|
577 { |
|
578 H5Dclose (data_hid); |
|
579 H5Gclose (group_hid); |
|
580 return false; |
|
581 } |
|
582 |
5351
|
583 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
5164
|
584 H5P_DEFAULT, (void *) &nr) < 0) |
|
585 { |
|
586 H5Dclose (data_hid); |
|
587 H5Gclose (group_hid); |
|
588 return false; |
|
589 } |
|
590 |
|
591 H5Dclose (data_hid); |
|
592 |
|
593 data_hid = H5Dopen (group_hid, "nc"); |
|
594 space_hid = H5Dget_space (data_hid); |
|
595 rank = H5Sget_simple_extent_ndims (space_hid); |
|
596 |
|
597 if (rank != 0) |
|
598 { |
|
599 H5Dclose (data_hid); |
|
600 H5Gclose (group_hid); |
|
601 return false; |
|
602 } |
|
603 |
5351
|
604 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
5164
|
605 H5P_DEFAULT, (void *) &nc) < 0) |
|
606 { |
|
607 H5Dclose (data_hid); |
|
608 H5Gclose (group_hid); |
|
609 return false; |
|
610 } |
|
611 |
|
612 H5Dclose (data_hid); |
|
613 |
|
614 data_hid = H5Dopen (group_hid, "nz"); |
|
615 space_hid = H5Dget_space (data_hid); |
|
616 rank = H5Sget_simple_extent_ndims (space_hid); |
|
617 |
|
618 if (rank != 0) |
|
619 { |
|
620 H5Dclose (data_hid); |
|
621 H5Gclose (group_hid); |
|
622 return false; |
|
623 } |
|
624 |
5351
|
625 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
5164
|
626 H5P_DEFAULT, (void *) &nz) < 0) |
|
627 { |
|
628 H5Dclose (data_hid); |
|
629 H5Gclose (group_hid); |
|
630 return false; |
|
631 } |
|
632 |
|
633 H5Dclose (data_hid); |
|
634 |
5275
|
635 SparseComplexMatrix m (static_cast<octave_idx_type> (nr), |
|
636 static_cast<octave_idx_type> (nc), |
|
637 static_cast<octave_idx_type> (nz)); |
5164
|
638 |
|
639 data_hid = H5Dopen (group_hid, "cidx"); |
|
640 space_hid = H5Dget_space (data_hid); |
|
641 rank = H5Sget_simple_extent_ndims (space_hid); |
|
642 |
|
643 if (rank != 2) |
|
644 { |
|
645 H5Sclose (space_hid); |
|
646 H5Dclose (data_hid); |
|
647 H5Gclose (group_hid); |
|
648 return false; |
|
649 } |
|
650 |
|
651 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); |
|
652 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); |
|
653 |
|
654 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); |
|
655 |
5322
|
656 if (static_cast<int> (hdims[0]) != nc + 1 || |
|
657 static_cast<int> (hdims[1]) != 1) |
5164
|
658 { |
|
659 H5Sclose (space_hid); |
|
660 H5Dclose (data_hid); |
|
661 H5Gclose (group_hid); |
|
662 return false; |
|
663 } |
|
664 |
5351
|
665 octave_idx_type *itmp = m.xcidx (); |
|
666 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
5164
|
667 H5P_DEFAULT, (void *) itmp) < 0) |
|
668 { |
|
669 H5Sclose (space_hid); |
|
670 H5Dclose (data_hid); |
|
671 H5Gclose (group_hid); |
|
672 return false; |
|
673 } |
|
674 |
|
675 H5Sclose (space_hid); |
|
676 H5Dclose (data_hid); |
|
677 |
|
678 data_hid = H5Dopen (group_hid, "ridx"); |
|
679 space_hid = H5Dget_space (data_hid); |
|
680 rank = H5Sget_simple_extent_ndims (space_hid); |
|
681 |
|
682 if (rank != 2) |
|
683 { |
|
684 H5Sclose (space_hid); |
|
685 H5Dclose (data_hid); |
|
686 H5Gclose (group_hid); |
|
687 return false; |
|
688 } |
|
689 |
|
690 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); |
|
691 |
5351
|
692 if (static_cast<int> (hdims[0]) != nz || |
|
693 static_cast<int> (hdims[1]) != 1) |
5164
|
694 { |
|
695 H5Sclose (space_hid); |
|
696 H5Dclose (data_hid); |
|
697 H5Gclose (group_hid); |
|
698 return false; |
|
699 } |
|
700 |
|
701 itmp = m.xridx (); |
5351
|
702 if (H5Dread (data_hid, H5T_NATIVE_IDX, H5S_ALL, H5S_ALL, |
5164
|
703 H5P_DEFAULT, (void *) itmp) < 0) |
|
704 { |
|
705 H5Sclose (space_hid); |
|
706 H5Dclose (data_hid); |
|
707 H5Gclose (group_hid); |
|
708 return false; |
|
709 } |
|
710 |
|
711 H5Sclose (space_hid); |
|
712 H5Dclose (data_hid); |
|
713 |
|
714 data_hid = H5Dopen (group_hid, "data"); |
|
715 hid_t type_hid = H5Dget_type (data_hid); |
|
716 |
|
717 hid_t complex_type = hdf5_make_complex_type (H5T_NATIVE_DOUBLE); |
|
718 |
|
719 if (! hdf5_types_compatible (type_hid, complex_type)) |
|
720 { |
|
721 H5Tclose (complex_type); |
|
722 H5Dclose (data_hid); |
|
723 H5Gclose (group_hid); |
|
724 return false; |
|
725 } |
|
726 |
|
727 space_hid = H5Dget_space (data_hid); |
|
728 rank = H5Sget_simple_extent_ndims (space_hid); |
|
729 |
|
730 if (rank != 2) |
|
731 { |
|
732 H5Sclose (space_hid); |
|
733 H5Dclose (data_hid); |
|
734 H5Gclose (group_hid); |
|
735 return false; |
|
736 } |
|
737 |
|
738 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); |
|
739 |
5351
|
740 if (static_cast<int> (hdims[0]) != nz || |
|
741 static_cast<int> (hdims[1]) != 1) |
5164
|
742 { |
|
743 H5Sclose (space_hid); |
|
744 H5Dclose (data_hid); |
|
745 H5Gclose (group_hid); |
|
746 return false; |
|
747 } |
|
748 |
|
749 Complex *ctmp = m.xdata (); |
|
750 bool retval = false; |
|
751 if (H5Dread (data_hid, complex_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, |
|
752 (void *) ctmp) >= 0) |
|
753 { |
|
754 retval = true; |
|
755 matrix = m; |
|
756 } |
|
757 |
|
758 H5Tclose (complex_type); |
|
759 H5Sclose (space_hid); |
|
760 H5Dclose (data_hid); |
|
761 H5Gclose (group_hid); |
|
762 |
|
763 return retval; |
|
764 } |
|
765 |
|
766 #endif |
|
767 |
|
768 /* |
|
769 ;;; Local Variables: *** |
|
770 ;;; mode: C++ *** |
|
771 ;;; End: *** |
|
772 */ |