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 |
5275
|
298 SparseComplexMatrix m (static_cast<octave_idx_type> (nr), |
|
299 static_cast<octave_idx_type> (nc), |
|
300 static_cast<octave_idx_type> (nz)); |
5164
|
301 |
|
302 for (int i = 0; i < nc+1; i++) |
|
303 { |
|
304 OCTAVE_QUIT; |
|
305 if (! is.read (X_CAST (char *, &tmp), 4)) |
|
306 return false; |
|
307 if (swap) |
|
308 swap_bytes<4> (&tmp); |
|
309 m.cidx(i) = tmp; |
|
310 } |
|
311 |
|
312 for (int i = 0; i < nz; i++) |
|
313 { |
|
314 OCTAVE_QUIT; |
|
315 if (! is.read (X_CAST (char *, &tmp), 4)) |
|
316 return false; |
|
317 if (swap) |
|
318 swap_bytes<4> (&tmp); |
|
319 m.ridx(i) = tmp; |
|
320 } |
|
321 |
|
322 if (! is.read (X_CAST (char *, &tmp), 1)) |
|
323 return false; |
|
324 |
|
325 read_doubles (is, X_CAST(double *, m.data()), X_CAST (save_type, tmp), |
|
326 2 * nz, swap, fmt); |
|
327 |
|
328 if (error_state || ! is) |
|
329 return false; |
|
330 matrix = m; |
|
331 |
|
332 return true; |
|
333 } |
|
334 |
|
335 #if defined (HAVE_HDF5) |
|
336 bool |
|
337 octave_sparse_complex_matrix::save_hdf5 (hid_t loc_id, const char *name, |
|
338 bool save_as_floats) |
|
339 { |
|
340 dim_vector dv = dims (); |
|
341 int empty = save_hdf5_empty (loc_id, name, dv); |
|
342 if (empty) |
|
343 return (empty > 0); |
|
344 |
|
345 // Ensure that additional memory is deallocated |
|
346 matrix.maybe_compress (); |
|
347 |
|
348 hid_t group_hid = H5Gcreate (loc_id, name, 0); |
|
349 if (group_hid < 0) |
|
350 return false; |
|
351 |
|
352 hid_t space_hid = -1, data_hid = -1; |
|
353 bool retval = true; |
|
354 SparseComplexMatrix m = sparse_complex_matrix_value (); |
|
355 int tmp; |
|
356 hsize_t hdims[2]; |
|
357 |
|
358 space_hid = H5Screate_simple (0, hdims, (hsize_t*) 0); |
|
359 if (space_hid < 0) |
|
360 { |
|
361 H5Gclose (group_hid); |
|
362 return false; |
|
363 } |
|
364 |
|
365 data_hid = H5Dcreate (group_hid, "nr", H5T_NATIVE_INT, space_hid, |
|
366 H5P_DEFAULT); |
|
367 if (data_hid < 0) |
|
368 { |
|
369 H5Sclose (space_hid); |
|
370 H5Gclose (group_hid); |
|
371 return false; |
|
372 } |
|
373 |
|
374 tmp = m.rows (); |
|
375 retval = H5Dwrite (data_hid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, |
|
376 (void*) &tmp) >= 0; |
|
377 H5Dclose (data_hid); |
|
378 if (!retval) |
|
379 { |
|
380 H5Sclose (space_hid); |
|
381 H5Gclose (group_hid); |
|
382 return false; |
|
383 } |
|
384 |
|
385 data_hid = H5Dcreate (group_hid, "nc", H5T_NATIVE_INT, space_hid, |
|
386 H5P_DEFAULT); |
|
387 if (data_hid < 0) |
|
388 { |
|
389 H5Sclose (space_hid); |
|
390 H5Gclose (group_hid); |
|
391 return false; |
|
392 } |
|
393 |
|
394 tmp = m.cols (); |
|
395 retval = H5Dwrite (data_hid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, |
|
396 (void*) &tmp) >= 0; |
|
397 H5Dclose (data_hid); |
|
398 if (!retval) |
|
399 { |
|
400 H5Sclose (space_hid); |
|
401 H5Gclose (group_hid); |
|
402 return false; |
|
403 } |
|
404 |
|
405 data_hid = H5Dcreate (group_hid, "nz", H5T_NATIVE_INT, space_hid, |
|
406 H5P_DEFAULT); |
|
407 if (data_hid < 0) |
|
408 { |
|
409 H5Sclose (space_hid); |
|
410 H5Gclose (group_hid); |
|
411 return false; |
|
412 } |
|
413 |
|
414 tmp = m.nnz (); |
|
415 retval = H5Dwrite (data_hid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, |
|
416 (void*) &tmp) >= 0; |
|
417 H5Dclose (data_hid); |
|
418 if (!retval) |
|
419 { |
|
420 H5Sclose (space_hid); |
|
421 H5Gclose (group_hid); |
|
422 return false; |
|
423 } |
|
424 |
|
425 H5Sclose (space_hid); |
|
426 |
|
427 hdims[0] = m.cols() + 1; |
|
428 hdims[1] = 1; |
|
429 |
|
430 space_hid = H5Screate_simple (2, hdims, 0); |
|
431 |
|
432 if (space_hid < 0) |
|
433 { |
|
434 H5Gclose (group_hid); |
|
435 return false; |
|
436 } |
|
437 |
|
438 data_hid = H5Dcreate (group_hid, "cidx", H5T_NATIVE_INT, space_hid, |
|
439 H5P_DEFAULT); |
|
440 if (data_hid < 0) |
|
441 { |
|
442 H5Sclose (space_hid); |
|
443 H5Gclose (group_hid); |
|
444 return false; |
|
445 } |
|
446 |
|
447 int * itmp = m.xcidx (); |
|
448 retval = H5Dwrite (data_hid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, |
|
449 (void*) itmp) >= 0; |
|
450 H5Dclose (data_hid); |
|
451 if (!retval) |
|
452 { |
|
453 H5Sclose (space_hid); |
|
454 H5Gclose (group_hid); |
|
455 return false; |
|
456 } |
|
457 |
|
458 H5Sclose (space_hid); |
|
459 |
|
460 hdims[0] = m.nnz(); |
|
461 hdims[1] = 1; |
|
462 |
|
463 space_hid = H5Screate_simple (2, hdims, 0); |
|
464 |
|
465 if (space_hid < 0) |
|
466 { |
|
467 H5Gclose (group_hid); |
|
468 return false; |
|
469 } |
|
470 |
|
471 data_hid = H5Dcreate (group_hid, "ridx", H5T_NATIVE_INT, space_hid, |
|
472 H5P_DEFAULT); |
|
473 if (data_hid < 0) |
|
474 { |
|
475 H5Sclose (space_hid); |
|
476 H5Gclose (group_hid); |
|
477 return false; |
|
478 } |
|
479 |
|
480 itmp = m.xridx (); |
|
481 retval = H5Dwrite (data_hid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, |
|
482 (void*) itmp) >= 0; |
|
483 H5Dclose (data_hid); |
|
484 if (!retval) |
|
485 { |
|
486 H5Sclose (space_hid); |
|
487 H5Gclose (group_hid); |
|
488 return false; |
|
489 } |
|
490 |
|
491 hid_t save_type_hid = H5T_NATIVE_DOUBLE; |
|
492 |
|
493 if (save_as_floats) |
|
494 { |
|
495 if (m.too_large_for_float ()) |
|
496 { |
|
497 warning ("save: some values too large to save as floats --"); |
|
498 warning ("save: saving as doubles instead"); |
|
499 } |
|
500 else |
|
501 save_type_hid = H5T_NATIVE_FLOAT; |
|
502 } |
|
503 #if HAVE_HDF5_INT2FLOAT_CONVERSIONS |
|
504 // hdf5 currently doesn't support float/integer conversions |
|
505 else |
|
506 { |
|
507 double max_val, min_val; |
|
508 |
|
509 if (m.all_integers (max_val, min_val)) |
|
510 save_type_hid |
|
511 = save_type_to_hdf5 (get_save_type (max_val, min_val)); |
|
512 } |
|
513 #endif /* HAVE_HDF5_INT2FLOAT_CONVERSIONS */ |
|
514 |
|
515 hid_t type_hid = hdf5_make_complex_type (save_type_hid); |
|
516 if (type_hid < 0) |
|
517 { |
|
518 H5Sclose (space_hid); |
|
519 H5Gclose (group_hid); |
|
520 return false; |
|
521 } |
|
522 |
|
523 data_hid = H5Dcreate (group_hid, "data", type_hid, space_hid, H5P_DEFAULT); |
|
524 if (data_hid < 0) |
|
525 { |
|
526 H5Sclose (space_hid); |
|
527 H5Tclose (type_hid); |
|
528 H5Gclose (group_hid); |
|
529 return false; |
|
530 } |
|
531 |
|
532 hid_t complex_type_hid = hdf5_make_complex_type (H5T_NATIVE_DOUBLE); |
|
533 retval = false; |
|
534 if (complex_type_hid >= 0) |
|
535 { |
|
536 Complex * ctmp = m.xdata (); |
|
537 |
|
538 retval = H5Dwrite (data_hid, complex_type_hid, H5S_ALL, H5S_ALL, |
|
539 H5P_DEFAULT, (void*) ctmp) >= 0; |
|
540 } |
|
541 |
|
542 H5Dclose (data_hid); |
|
543 H5Sclose (space_hid); |
|
544 H5Tclose (type_hid); |
|
545 H5Gclose (group_hid); |
|
546 |
|
547 return retval; |
|
548 } |
|
549 |
|
550 bool |
|
551 octave_sparse_complex_matrix::load_hdf5 (hid_t loc_id, const char *name, |
|
552 bool /* have_h5giterate_bug */) |
|
553 { |
|
554 int nr, nc, nz; |
|
555 hid_t group_hid, data_hid, space_hid; |
|
556 hsize_t rank; |
|
557 |
|
558 dim_vector dv; |
|
559 int empty = load_hdf5_empty (loc_id, name, dv); |
|
560 if (empty > 0) |
|
561 matrix.resize(dv); |
|
562 if (empty) |
|
563 return (empty > 0); |
|
564 |
|
565 group_hid = H5Gopen (loc_id, name); |
|
566 if (group_hid < 0 ) return false; |
|
567 |
|
568 data_hid = H5Dopen (group_hid, "nr"); |
|
569 space_hid = H5Dget_space (data_hid); |
|
570 rank = H5Sget_simple_extent_ndims (space_hid); |
|
571 |
|
572 if (rank != 0) |
|
573 { |
|
574 H5Dclose (data_hid); |
|
575 H5Gclose (group_hid); |
|
576 return false; |
|
577 } |
|
578 |
|
579 if (H5Dread (data_hid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, |
|
580 H5P_DEFAULT, (void *) &nr) < 0) |
|
581 { |
|
582 H5Dclose (data_hid); |
|
583 H5Gclose (group_hid); |
|
584 return false; |
|
585 } |
|
586 |
|
587 H5Dclose (data_hid); |
|
588 |
|
589 data_hid = H5Dopen (group_hid, "nc"); |
|
590 space_hid = H5Dget_space (data_hid); |
|
591 rank = H5Sget_simple_extent_ndims (space_hid); |
|
592 |
|
593 if (rank != 0) |
|
594 { |
|
595 H5Dclose (data_hid); |
|
596 H5Gclose (group_hid); |
|
597 return false; |
|
598 } |
|
599 |
|
600 if (H5Dread (data_hid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, |
|
601 H5P_DEFAULT, (void *) &nc) < 0) |
|
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 |
|
621 if (H5Dread (data_hid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, |
|
622 H5P_DEFAULT, (void *) &nz) < 0) |
|
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 |
|
652 if (hdims[0] != nc + 1 || hdims[1] != 1) |
|
653 { |
|
654 H5Sclose (space_hid); |
|
655 H5Dclose (data_hid); |
|
656 H5Gclose (group_hid); |
|
657 return false; |
|
658 } |
|
659 |
|
660 int *itmp = m.xcidx (); |
|
661 if (H5Dread (data_hid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, |
|
662 H5P_DEFAULT, (void *) itmp) < 0) |
|
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 |
|
687 if (hdims[0] != nz || hdims[1] != 1) |
|
688 { |
|
689 H5Sclose (space_hid); |
|
690 H5Dclose (data_hid); |
|
691 H5Gclose (group_hid); |
|
692 return false; |
|
693 } |
|
694 |
|
695 itmp = m.xridx (); |
|
696 if (H5Dread (data_hid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, |
|
697 H5P_DEFAULT, (void *) itmp) < 0) |
|
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 |
|
734 if (hdims[0] != nz || hdims[1] != 1) |
|
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; |
|
744 if (H5Dread (data_hid, complex_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, |
|
745 (void *) ctmp) >= 0) |
|
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 */ |