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