2376
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2376
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
2376
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
3503
|
28 #include <iostream> |
4726
|
29 #include <vector> |
2901
|
30 |
4944
|
31 #include "data-conv.h" |
2376
|
32 #include "lo-ieee.h" |
|
33 #include "mx-base.h" |
4944
|
34 #include "mach-info.h" |
2376
|
35 |
|
36 #include "gripes.h" |
|
37 #include "oct-obj.h" |
4944
|
38 #include "oct-stream.h" |
2410
|
39 #include "ops.h" |
3219
|
40 #include "ov-base.h" |
|
41 #include "ov-base-mat.h" |
|
42 #include "ov-base-mat.cc" |
2410
|
43 #include "ov-complex.h" |
2376
|
44 #include "ov-cx-mat.h" |
2410
|
45 #include "ov-re-mat.h" |
|
46 #include "ov-scalar.h" |
2376
|
47 #include "pr-output.h" |
|
48 |
4687
|
49 #include "byte-swap.h" |
|
50 #include "ls-oct-ascii.h" |
|
51 #include "ls-hdf5.h" |
|
52 #include "ls-utils.h" |
|
53 |
4513
|
54 template class octave_base_matrix<ComplexNDArray>; |
2376
|
55 |
3219
|
56 DEFINE_OCTAVE_ALLOCATOR (octave_complex_matrix); |
2477
|
57 |
4612
|
58 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_complex_matrix, |
|
59 "complex matrix", "double"); |
2376
|
60 |
5759
|
61 octave_base_value * |
2410
|
62 octave_complex_matrix::try_narrowing_conversion (void) |
|
63 { |
5759
|
64 octave_base_value *retval = 0; |
2410
|
65 |
4513
|
66 if (matrix.ndims () == 2) |
|
67 { |
|
68 ComplexMatrix cm = matrix.matrix_value (); |
2410
|
69 |
5275
|
70 octave_idx_type nr = cm.rows (); |
|
71 octave_idx_type nc = cm.cols (); |
4513
|
72 |
|
73 if (nr == 1 && nc == 1) |
|
74 { |
|
75 Complex c = matrix (0, 0); |
2410
|
76 |
5450
|
77 double im = std::imag (c); |
|
78 |
|
79 if (im == 0.0 && ! lo_ieee_signbit (im)) |
4513
|
80 retval = new octave_scalar (std::real (c)); |
|
81 else |
|
82 retval = new octave_complex (c); |
|
83 } |
|
84 else if (nr == 0 || nc == 0) |
|
85 retval = new octave_matrix (Matrix (nr, nc)); |
|
86 else if (cm.all_elements_are_real ()) |
|
87 retval = new octave_matrix (::real (cm)); |
2410
|
88 } |
4923
|
89 else if (matrix.all_elements_are_real ()) |
|
90 retval = new octave_matrix (::real (matrix)); |
2410
|
91 |
|
92 return retval; |
|
93 } |
2376
|
94 |
|
95 void |
|
96 octave_complex_matrix::assign (const octave_value_list& idx, |
4686
|
97 const ComplexNDArray& rhs) |
4418
|
98 { |
4513
|
99 octave_base_matrix<ComplexNDArray>::assign (idx, rhs); |
4418
|
100 } |
|
101 |
|
102 void |
|
103 octave_complex_matrix::assign (const octave_value_list& idx, |
4686
|
104 const NDArray& rhs) |
2376
|
105 { |
5275
|
106 octave_idx_type len = idx.length (); |
2376
|
107 |
5275
|
108 for (octave_idx_type i = 0; i < len; i++) |
4513
|
109 matrix.set_index (idx(i).index_vector ()); |
2376
|
110 |
4513
|
111 ::assign (matrix, rhs); |
2376
|
112 } |
|
113 |
|
114 bool |
|
115 octave_complex_matrix::valid_as_scalar_index (void) const |
|
116 { |
5775
|
117 // FIXME |
2376
|
118 return false; |
|
119 } |
|
120 |
|
121 double |
|
122 octave_complex_matrix::double_value (bool force_conversion) const |
|
123 { |
4102
|
124 double retval = lo_ieee_nan_value (); |
2376
|
125 |
5781
|
126 if (! force_conversion) |
|
127 gripe_implicit_conversion ("Octave:imag-to-real", |
|
128 "complex matrix", "real scalar"); |
2376
|
129 |
4455
|
130 if (rows () > 0 && columns () > 0) |
|
131 { |
5781
|
132 gripe_implicit_conversion ("Octave:array-as-scalar", |
|
133 "complex matrix", "real scalar"); |
4455
|
134 |
|
135 retval = std::real (matrix (0, 0)); |
|
136 } |
2376
|
137 else |
|
138 gripe_invalid_conversion ("complex matrix", "real scalar"); |
|
139 |
|
140 return retval; |
|
141 } |
|
142 |
|
143 Matrix |
|
144 octave_complex_matrix::matrix_value (bool force_conversion) const |
|
145 { |
|
146 Matrix retval; |
|
147 |
5781
|
148 if (! force_conversion) |
|
149 gripe_implicit_conversion ("Octave:imag-to-real", |
|
150 "complex matrix", "real matrix"); |
2376
|
151 |
4513
|
152 retval = ::real (matrix.matrix_value ()); |
2376
|
153 |
|
154 return retval; |
|
155 } |
|
156 |
|
157 Complex |
|
158 octave_complex_matrix::complex_value (bool) const |
|
159 { |
4102
|
160 double tmp = lo_ieee_nan_value (); |
|
161 |
|
162 Complex retval (tmp, tmp); |
2376
|
163 |
4455
|
164 if (rows () > 0 && columns () > 0) |
|
165 { |
5781
|
166 gripe_implicit_conversion ("Octave:array-as-scalar", |
|
167 "complex matrix", "complex scalar"); |
4455
|
168 |
|
169 retval = matrix (0, 0); |
|
170 } |
2376
|
171 else |
|
172 gripe_invalid_conversion ("complex matrix", "complex scalar"); |
|
173 |
|
174 return retval; |
|
175 } |
|
176 |
|
177 ComplexMatrix |
|
178 octave_complex_matrix::complex_matrix_value (bool) const |
|
179 { |
4513
|
180 return matrix.matrix_value (); |
2376
|
181 } |
|
182 |
5164
|
183 SparseMatrix |
|
184 octave_complex_matrix::sparse_matrix_value (bool force_conversion) const |
|
185 { |
|
186 SparseMatrix retval; |
|
187 |
5781
|
188 if (! force_conversion) |
|
189 gripe_implicit_conversion ("Octave:imag-to-real", |
|
190 "complex matrix", "real matrix"); |
5164
|
191 |
|
192 retval = SparseMatrix (::real (matrix.matrix_value ())); |
|
193 |
|
194 return retval; |
|
195 } |
|
196 |
|
197 SparseComplexMatrix |
|
198 octave_complex_matrix::sparse_complex_matrix_value (bool) const |
|
199 { |
|
200 return SparseComplexMatrix (matrix.matrix_value ()); |
|
201 } |
|
202 |
4687
|
203 static ComplexMatrix |
|
204 strip_infnan (const ComplexMatrix& m) |
|
205 { |
5275
|
206 octave_idx_type nr = m.rows (); |
|
207 octave_idx_type nc = m.columns (); |
4687
|
208 |
|
209 ComplexMatrix retval (nr, nc); |
|
210 |
5275
|
211 octave_idx_type k = 0; |
|
212 for (octave_idx_type i = 0; i < nr; i++) |
4687
|
213 { |
5275
|
214 for (octave_idx_type j = 0; j < nc; j++) |
4687
|
215 { |
|
216 Complex c = m (i, j); |
|
217 if (xisnan (c)) |
|
218 goto next_row; |
|
219 else |
|
220 { |
5260
|
221 double re = std::real (c); |
|
222 double im = std::imag (c); |
4687
|
223 |
|
224 re = xisinf (re) ? (re > 0 ? OCT_RBV : -OCT_RBV) : re; |
|
225 im = xisinf (im) ? (im > 0 ? OCT_RBV : -OCT_RBV) : im; |
|
226 |
|
227 retval (k, j) = Complex (re, im); |
|
228 } |
|
229 } |
|
230 k++; |
|
231 |
|
232 next_row: |
|
233 continue; |
|
234 } |
|
235 |
|
236 if (k > 0) |
|
237 retval.resize (k, nc); |
|
238 |
|
239 return retval; |
|
240 } |
|
241 |
|
242 bool |
|
243 octave_complex_matrix::save_ascii (std::ostream& os, bool& infnan_warned, |
|
244 bool strip_nan_and_inf) |
|
245 { |
|
246 dim_vector d = dims (); |
|
247 if (d.length () > 2) |
|
248 { |
|
249 ComplexNDArray tmp = complex_array_value (); |
|
250 |
|
251 if (strip_nan_and_inf) |
|
252 { |
|
253 warning ("save: Can not strip Inf or NaN values"); |
|
254 warning ("save: Inf or NaN values may not be reloadable"); |
|
255 infnan_warned = true; |
|
256 } |
|
257 else if (! infnan_warned && tmp.any_element_is_inf_or_nan ()) |
|
258 { |
|
259 warning ("save: Inf or NaN values may not be reloadable"); |
|
260 infnan_warned = true; |
|
261 } |
|
262 |
|
263 os << "# ndims: " << d.length () << "\n"; |
|
264 |
5275
|
265 for (int i = 0; i < d.length (); i++) |
4687
|
266 os << " " << d (i); |
|
267 |
|
268 os << "\n" << tmp; |
|
269 } |
|
270 else |
|
271 { |
|
272 // Keep this case, rather than use generic code above for backward |
|
273 // compatiability. Makes load_ascii much more complex!! |
|
274 os << "# rows: " << rows () << "\n" |
|
275 << "# columns: " << columns () << "\n"; |
|
276 |
|
277 ComplexMatrix tmp = complex_matrix_value (); |
|
278 |
|
279 if (strip_nan_and_inf) |
|
280 tmp = strip_infnan (tmp); |
|
281 else if (! infnan_warned && tmp.any_element_is_inf_or_nan ()) |
|
282 { |
|
283 warning ("save: Inf or NaN values may not be reloadable"); |
|
284 infnan_warned = true; |
|
285 } |
|
286 |
|
287 os << tmp; |
|
288 } |
|
289 |
|
290 return true; |
|
291 } |
|
292 |
|
293 bool |
|
294 octave_complex_matrix::load_ascii (std::istream& is) |
|
295 { |
|
296 bool success = true; |
5099
|
297 |
|
298 string_vector keywords(2); |
|
299 |
|
300 keywords[0] = "ndims"; |
|
301 keywords[1] = "rows"; |
4687
|
302 |
5099
|
303 std::string kw; |
5275
|
304 octave_idx_type val = 0; |
5099
|
305 |
|
306 if (extract_keyword (is, keywords, kw, val, true)) |
4687
|
307 { |
5099
|
308 if (kw == "ndims") |
4687
|
309 { |
5275
|
310 int mdims = static_cast<int> (val); |
4687
|
311 |
5099
|
312 if (mdims >= 0) |
4687
|
313 { |
5099
|
314 dim_vector dv; |
|
315 dv.resize (mdims); |
4687
|
316 |
5099
|
317 for (int i = 0; i < mdims; i++) |
|
318 is >> dv(i); |
4687
|
319 |
5099
|
320 ComplexNDArray tmp(dv); |
4687
|
321 is >> tmp; |
5099
|
322 |
4687
|
323 if (!is) |
|
324 { |
|
325 error ("load: failed to load matrix constant"); |
|
326 success = false; |
|
327 } |
|
328 matrix = tmp; |
|
329 } |
|
330 else |
5099
|
331 { |
|
332 error ("load: failed to extract number of rows and columns"); |
|
333 success = false; |
|
334 } |
4687
|
335 } |
5099
|
336 else if (kw == "rows") |
4687
|
337 { |
5275
|
338 octave_idx_type nr = val; |
|
339 octave_idx_type nc = 0; |
5099
|
340 |
|
341 if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0) |
|
342 { |
|
343 if (nr > 0 && nc > 0) |
|
344 { |
|
345 ComplexMatrix tmp (nr, nc); |
|
346 is >> tmp; |
|
347 if (!is) |
|
348 { |
|
349 error ("load: failed to load matrix constant"); |
|
350 success = false; |
|
351 } |
|
352 matrix = tmp; |
|
353 } |
|
354 else if (nr == 0 || nc == 0) |
|
355 matrix = ComplexMatrix (nr, nc); |
|
356 else |
|
357 panic_impossible (); |
|
358 } |
|
359 else |
|
360 { |
|
361 error ("load: failed to extract number of rows and columns"); |
|
362 success = false; |
|
363 } |
4687
|
364 } |
5099
|
365 else |
|
366 panic_impossible (); |
|
367 } |
|
368 else |
|
369 { |
|
370 error ("load: failed to extract number of rows and columns"); |
|
371 success = false; |
4687
|
372 } |
|
373 |
|
374 return success; |
|
375 } |
|
376 |
|
377 bool |
|
378 octave_complex_matrix::save_binary (std::ostream& os, bool& save_as_floats) |
|
379 { |
|
380 dim_vector d = dims (); |
|
381 if (d.length() < 1) |
|
382 return false; |
|
383 |
|
384 // Use negative value for ndims to differentiate with old format!! |
5828
|
385 int32_t tmp = - d.length(); |
5760
|
386 os.write (reinterpret_cast<char *> (&tmp), 4); |
5275
|
387 for (int i = 0; i < d.length (); i++) |
4687
|
388 { |
|
389 tmp = d(i); |
5760
|
390 os.write (reinterpret_cast<char *> (&tmp), 4); |
4687
|
391 } |
|
392 |
|
393 ComplexNDArray m = complex_array_value (); |
|
394 save_type st = LS_DOUBLE; |
|
395 if (save_as_floats) |
|
396 { |
|
397 if (m.too_large_for_float ()) |
|
398 { |
|
399 warning ("save: some values too large to save as floats --"); |
|
400 warning ("save: saving as doubles instead"); |
|
401 } |
|
402 else |
|
403 st = LS_FLOAT; |
|
404 } |
5775
|
405 else if (d.numel () > 4096) // FIXME -- make this configurable. |
4687
|
406 { |
|
407 double max_val, min_val; |
|
408 if (m.all_integers (max_val, min_val)) |
|
409 st = get_save_type (max_val, min_val); |
|
410 } |
|
411 |
|
412 |
|
413 const Complex *mtmp = m.data (); |
5760
|
414 write_doubles (os, reinterpret_cast<const double *> (mtmp), st, 2 * d.numel ()); |
4687
|
415 |
|
416 return true; |
|
417 } |
|
418 |
|
419 bool |
|
420 octave_complex_matrix::load_binary (std::istream& is, bool swap, |
|
421 oct_mach_info::float_format fmt) |
|
422 { |
|
423 char tmp; |
5828
|
424 int32_t mdims; |
5760
|
425 if (! is.read (reinterpret_cast<char *> (&mdims), 4)) |
4687
|
426 return false; |
|
427 if (swap) |
4944
|
428 swap_bytes<4> (&mdims); |
4687
|
429 if (mdims < 0) |
|
430 { |
|
431 mdims = - mdims; |
5828
|
432 int32_t di; |
4687
|
433 dim_vector dv; |
|
434 dv.resize (mdims); |
|
435 |
|
436 for (int i = 0; i < mdims; i++) |
|
437 { |
5760
|
438 if (! is.read (reinterpret_cast<char *> (&di), 4)) |
4687
|
439 return false; |
|
440 if (swap) |
4944
|
441 swap_bytes<4> (&di); |
4687
|
442 dv(i) = di; |
|
443 } |
|
444 |
5157
|
445 // Convert an array with a single dimension to be a row vector. |
|
446 // Octave should never write files like this, other software |
|
447 // might. |
|
448 |
|
449 if (mdims == 1) |
|
450 { |
|
451 mdims = 2; |
|
452 dv.resize (mdims); |
|
453 dv(1) = dv(0); |
|
454 dv(0) = 1; |
|
455 } |
|
456 |
5760
|
457 if (! is.read (reinterpret_cast<char *> (&tmp), 1)) |
4687
|
458 return false; |
|
459 |
|
460 ComplexNDArray m(dv); |
|
461 Complex *im = m.fortran_vec (); |
5760
|
462 read_doubles (is, reinterpret_cast<double *> (im), |
|
463 static_cast<save_type> (tmp), 2 * dv.numel (), swap, fmt); |
4687
|
464 if (error_state || ! is) |
|
465 return false; |
|
466 matrix = m; |
|
467 } |
|
468 else |
|
469 { |
5828
|
470 int32_t nr, nc; |
4687
|
471 nr = mdims; |
5760
|
472 if (! is.read (reinterpret_cast<char *> (&nc), 4)) |
4687
|
473 return false; |
|
474 if (swap) |
4944
|
475 swap_bytes<4> (&nc); |
5760
|
476 if (! is.read (reinterpret_cast<char *> (&tmp), 1)) |
4687
|
477 return false; |
|
478 ComplexMatrix m (nr, nc); |
|
479 Complex *im = m.fortran_vec (); |
5275
|
480 octave_idx_type len = nr * nc; |
5760
|
481 read_doubles (is, reinterpret_cast<double *> (im), |
|
482 static_cast<save_type> (tmp), 2*len, swap, fmt); |
4687
|
483 if (error_state || ! is) |
|
484 return false; |
|
485 matrix = m; |
|
486 } |
|
487 return true; |
|
488 } |
|
489 |
|
490 #if defined (HAVE_HDF5) |
4944
|
491 |
4687
|
492 bool |
|
493 octave_complex_matrix::save_hdf5 (hid_t loc_id, const char *name, |
|
494 bool save_as_floats) |
|
495 { |
4837
|
496 dim_vector dv = dims (); |
|
497 int empty = save_hdf5_empty (loc_id, name, dv); |
|
498 if (empty) |
4805
|
499 return (empty > 0); |
|
500 |
4837
|
501 int rank = dv.length (); |
4805
|
502 hid_t space_hid = -1, data_hid = -1, type_hid = -1; |
4687
|
503 bool retval = true; |
|
504 ComplexNDArray m = complex_array_value (); |
|
505 |
4805
|
506 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); |
|
507 |
4687
|
508 // Octave uses column-major, while HDF5 uses row-major ordering |
4805
|
509 for (int i = 0; i < rank; i++) |
4837
|
510 hdims[i] = dv (rank-i-1); |
4805
|
511 |
4815
|
512 space_hid = H5Screate_simple (rank, hdims, 0); |
4687
|
513 if (space_hid < 0) return false; |
|
514 |
|
515 hid_t save_type_hid = H5T_NATIVE_DOUBLE; |
|
516 |
|
517 if (save_as_floats) |
|
518 { |
|
519 if (m.too_large_for_float ()) |
|
520 { |
|
521 warning ("save: some values too large to save as floats --"); |
|
522 warning ("save: saving as doubles instead"); |
|
523 } |
|
524 else |
|
525 save_type_hid = H5T_NATIVE_FLOAT; |
|
526 } |
|
527 #if HAVE_HDF5_INT2FLOAT_CONVERSIONS |
|
528 // hdf5 currently doesn't support float/integer conversions |
|
529 else |
|
530 { |
|
531 double max_val, min_val; |
|
532 |
|
533 if (m.all_integers (max_val, min_val)) |
|
534 save_type_hid |
|
535 = save_type_to_hdf5 (get_save_type (max_val, min_val)); |
|
536 } |
|
537 #endif /* HAVE_HDF5_INT2FLOAT_CONVERSIONS */ |
|
538 |
|
539 type_hid = hdf5_make_complex_type (save_type_hid); |
|
540 if (type_hid < 0) |
|
541 { |
|
542 H5Sclose (space_hid); |
|
543 return false; |
|
544 } |
|
545 |
|
546 data_hid = H5Dcreate (loc_id, name, type_hid, space_hid, H5P_DEFAULT); |
|
547 if (data_hid < 0) |
|
548 { |
|
549 H5Sclose (space_hid); |
|
550 H5Tclose (type_hid); |
|
551 return false; |
|
552 } |
|
553 |
|
554 hid_t complex_type_hid = hdf5_make_complex_type (H5T_NATIVE_DOUBLE); |
|
555 if (complex_type_hid < 0) retval = false; |
|
556 |
|
557 if (retval) |
|
558 { |
|
559 Complex *mtmp = m.fortran_vec (); |
|
560 if (H5Dwrite (data_hid, complex_type_hid, H5S_ALL, H5S_ALL, H5P_DEFAULT, |
4815
|
561 mtmp) < 0) |
4687
|
562 { |
|
563 H5Tclose (complex_type_hid); |
|
564 retval = false; |
|
565 } |
|
566 } |
|
567 |
|
568 H5Tclose (complex_type_hid); |
|
569 H5Dclose (data_hid); |
|
570 H5Tclose (type_hid); |
|
571 H5Sclose (space_hid); |
4837
|
572 |
4687
|
573 return retval; |
|
574 } |
|
575 |
|
576 bool |
|
577 octave_complex_matrix::load_hdf5 (hid_t loc_id, const char *name, |
|
578 bool /* have_h5giterate_bug */) |
|
579 { |
4837
|
580 bool retval = false; |
|
581 |
4805
|
582 dim_vector dv; |
|
583 int empty = load_hdf5_empty (loc_id, name, dv); |
|
584 if (empty > 0) |
|
585 matrix.resize(dv); |
4837
|
586 if (empty) |
4805
|
587 return (empty > 0); |
|
588 |
4687
|
589 hid_t data_hid = H5Dopen (loc_id, name); |
|
590 hid_t type_hid = H5Dget_type (data_hid); |
|
591 |
|
592 hid_t complex_type = hdf5_make_complex_type (H5T_NATIVE_DOUBLE); |
|
593 |
|
594 if (! hdf5_types_compatible (type_hid, complex_type)) |
|
595 { |
4837
|
596 H5Tclose (complex_type); |
4687
|
597 H5Dclose (data_hid); |
|
598 return false; |
|
599 } |
|
600 |
|
601 hid_t space_id = H5Dget_space (data_hid); |
|
602 |
|
603 hsize_t rank = H5Sget_simple_extent_ndims (space_id); |
|
604 |
|
605 if (rank < 1) |
|
606 { |
4837
|
607 H5Tclose (complex_type); |
4687
|
608 H5Sclose (space_id); |
|
609 H5Dclose (data_hid); |
|
610 return false; |
|
611 } |
|
612 |
|
613 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); |
|
614 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); |
|
615 |
|
616 H5Sget_simple_extent_dims (space_id, hdims, maxdims); |
|
617 |
|
618 // Octave uses column-major, while HDF5 uses row-major ordering |
|
619 if (rank == 1) |
|
620 { |
|
621 dv.resize (2); |
|
622 dv(0) = 1; |
|
623 dv(1) = hdims[0]; |
|
624 } |
|
625 else |
|
626 { |
|
627 dv.resize (rank); |
4815
|
628 for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--) |
4687
|
629 dv(j) = hdims[i]; |
|
630 } |
|
631 |
|
632 ComplexNDArray m (dv); |
|
633 Complex *reim = m.fortran_vec (); |
4815
|
634 if (H5Dread (data_hid, complex_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, |
|
635 reim) >= 0) |
4687
|
636 { |
|
637 retval = true; |
|
638 matrix = m; |
|
639 } |
|
640 |
4837
|
641 H5Tclose (complex_type); |
4687
|
642 H5Sclose (space_id); |
|
643 H5Dclose (data_hid); |
4837
|
644 |
4687
|
645 return retval; |
|
646 } |
4944
|
647 |
4687
|
648 #endif |
|
649 |
4643
|
650 void |
|
651 octave_complex_matrix::print_raw (std::ostream& os, |
|
652 bool pr_as_read_syntax) const |
|
653 { |
|
654 octave_print_internal (os, matrix, pr_as_read_syntax, |
|
655 current_print_indent_level ()); |
|
656 } |
|
657 |
5900
|
658 mxArray * |
|
659 octave_complex_matrix::as_mxArray (void) const |
|
660 { |
|
661 mxArray *retval = new mxArray (mxDOUBLE_CLASS, dims (), mxCOMPLEX); |
|
662 |
|
663 double *pr = static_cast<double *> (retval->get_data ()); |
|
664 double *pi = static_cast<double *> (retval->get_imag_data ()); |
|
665 |
|
666 int nel = numel (); |
|
667 |
|
668 const Complex *p = matrix.data (); |
|
669 |
|
670 for (int i = 0; i < nel; i++) |
|
671 { |
|
672 pr[i] = real (p[i]); |
|
673 pi[i] = imag (p[i]); |
|
674 } |
|
675 |
|
676 return retval; |
|
677 } |
|
678 |
2376
|
679 /* |
|
680 ;;; Local Variables: *** |
|
681 ;;; mode: C++ *** |
|
682 ;;; End: *** |
|
683 */ |