Mercurial > hg > octave-lyh
annotate src/pr-output.cc @ 9732:b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 16 Oct 2009 13:12:31 +0200 |
parents | 85dd3a2c9355 |
children | 09da0bd91412 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, |
8920 | 4 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton |
1 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1 | 21 |
22 */ | |
23 | |
240 | 24 #ifdef HAVE_CONFIG_H |
1192 | 25 #include <config.h> |
1 | 26 #endif |
27 | |
1346 | 28 #include <cfloat> |
2825 | 29 #include <cstdio> |
1346 | 30 #include <cstring> |
1343 | 31 |
3503 | 32 #include <iomanip> |
33 #include <iostream> | |
5765 | 34 #include <sstream> |
1728 | 35 #include <string> |
36 | |
4655 | 37 #include "Array-util.h" |
453 | 38 #include "CMatrix.h" |
1 | 39 #include "Range.h" |
2926 | 40 #include "cmd-edit.h" |
1352 | 41 #include "dMatrix.h" |
2891 | 42 #include "lo-mappers.h" |
7231 | 43 #include "lo-math.h" |
2317 | 44 #include "mach-info.h" |
1651 | 45 #include "oct-cmplx.h" |
4153 | 46 #include "quit.h" |
1755 | 47 #include "str-vec.h" |
1 | 48 |
3933 | 49 #include "Cell.h" |
1352 | 50 #include "defun.h" |
51 #include "error.h" | |
2165 | 52 #include "gripes.h" |
1755 | 53 #include "oct-obj.h" |
3685 | 54 #include "oct-stream.h" |
1352 | 55 #include "pager.h" |
56 #include "pr-output.h" | |
1282 | 57 #include "sysdep.h" |
6803 | 58 #include "unwind-prot.h" |
1 | 59 #include "utils.h" |
1352 | 60 #include "variables.h" |
1 | 61 |
3105 | 62 // TRUE means use a scaled fixed point format for `format long' and |
63 // `format short'. | |
5794 | 64 static bool Vfixed_point_format = false; |
3105 | 65 |
2165 | 66 // The maximum field width for a number printed by the default output |
67 // routines. | |
5794 | 68 static int Voutput_max_field_width = 10; |
2165 | 69 |
70 // The precision of the numbers printed by the default output | |
71 // routines. | |
5794 | 72 static int Voutput_precision = 5; |
2165 | 73 |
5360 | 74 // TRUE means that the dimensions of empty objects should be printed |
2165 | 75 // like this: x = [](2x0). |
5794 | 76 bool Vprint_empty_dimensions = true; |
2165 | 77 |
78 // TRUE means that the rows of big matrices should be split into | |
79 // smaller slices that fit on the screen. | |
5794 | 80 static bool Vsplit_long_rows = true; |
2165 | 81 |
5759 | 82 // How many levels of structure elements should we print? |
5794 | 83 int Vstruct_levels_to_print = 2; |
5759 | 84 |
3018 | 85 // TRUE means don't do any fancy formatting. |
2387 | 86 static bool free_format = false; |
1 | 87 |
3018 | 88 // TRUE means print plus sign for nonzero, blank for zero. |
2387 | 89 static bool plus_format = false; |
1 | 90 |
4632 | 91 // First char for > 0, second for < 0, third for == 0. |
92 static std::string plus_format_chars = "+ "; | |
93 | |
6788 | 94 // TRUE means always print in a rational approximation |
95 static bool rat_format = false; | |
96 | |
97 // Used to force the length of the rational approximation string for Frats | |
98 static int rat_string_len = -1; | |
99 | |
3018 | 100 // TRUE means always print like dollars and cents. |
2387 | 101 static bool bank_format = false; |
1282 | 102 |
3018 | 103 // TRUE means print data in hexadecimal format. |
3608 | 104 static int hex_format = 0; |
1282 | 105 |
3018 | 106 // TRUE means print data in binary-bit-pattern format. |
1309 | 107 static int bit_format = 0; |
108 | |
3018 | 109 // TRUE means don't put newlines around the column number headers. |
2387 | 110 static bool compact_format = false; |
1186 | 111 |
3018 | 112 // TRUE means use an e format. |
2387 | 113 static bool print_e = false; |
1 | 114 |
4509 | 115 // TRUE means use a g format. |
116 static bool print_g = false; | |
117 | |
3018 | 118 // TRUE means print E instead of e for exponent field. |
2387 | 119 static bool print_big_e = false; |
1 | 120 |
3608 | 121 class pr_formatted_float; |
6788 | 122 class pr_rational_float; |
3608 | 123 |
4509 | 124 static int |
125 current_output_max_field_width (void) | |
126 { | |
127 return Voutput_max_field_width; | |
128 } | |
129 | |
130 static int | |
131 current_output_precision (void) | |
132 { | |
133 return Voutput_precision; | |
134 } | |
135 | |
3608 | 136 class |
137 float_format | |
138 { | |
139 public: | |
140 | |
4509 | 141 float_format (int w = current_output_max_field_width (), |
142 int p = current_output_precision (), int f = 0) | |
3608 | 143 : fw (w), prec (p), fmt (f), up (0), sp (0) { } |
144 | |
145 float_format (const float_format& ff) | |
146 : fw (ff.fw), prec (ff.prec), fmt (ff.fmt), up (ff.up), sp (ff.sp) { } | |
147 | |
148 float_format& operator = (const float_format& ff) | |
149 { | |
150 if (&ff != this) | |
151 { | |
152 fw = ff.fw; | |
153 prec = ff.prec; | |
154 fmt = ff.fmt; | |
155 up = ff.up; | |
156 sp = ff.sp; | |
157 } | |
158 | |
159 return *this; | |
160 } | |
161 | |
162 ~float_format (void) { } | |
163 | |
164 float_format& scientific (void) { fmt = std::ios::scientific; return *this; } | |
165 float_format& fixed (void) { fmt = std::ios::fixed; return *this; } | |
166 float_format& general (void) { fmt = 0; return *this; } | |
167 | |
168 float_format& uppercase (void) { up = std::ios::uppercase; return *this; } | |
169 float_format& lowercase (void) { up = 0; return *this; } | |
170 | |
171 float_format& precision (int p) { prec = p; return *this; } | |
172 | |
173 float_format& width (int w) { fw = w; return *this; } | |
174 | |
175 float_format& trailing_zeros (bool tz = true) | |
176 { sp = tz ? std::ios::showpoint : 0; return *this; } | |
177 | |
178 friend std::ostream& operator << (std::ostream& os, | |
179 const pr_formatted_float& pff); | |
180 | |
6788 | 181 friend std::ostream& operator << (std::ostream& os, |
182 const pr_rational_float& pff); | |
183 | |
3608 | 184 private: |
185 | |
186 // Field width. Zero means as wide as necessary. | |
187 int fw; | |
188 | |
189 // Precision. | |
190 int prec; | |
191 | |
192 // Format. | |
193 int fmt; | |
194 | |
195 // E or e. | |
196 int up; | |
197 | |
198 // Show trailing zeros. | |
199 int sp; | |
200 }; | |
201 | |
202 class | |
203 pr_formatted_float | |
204 { | |
205 public: | |
206 | |
207 const float_format& f; | |
208 | |
209 double val; | |
210 | |
211 pr_formatted_float (const float_format& f_arg, double val_arg) | |
212 : f (f_arg), val (val_arg) { } | |
213 }; | |
214 | |
215 std::ostream& | |
216 operator << (std::ostream& os, const pr_formatted_float& pff) | |
217 { | |
3682 | 218 if (pff.f.fw >= 0) |
3608 | 219 os << std::setw (pff.f.fw); |
220 | |
3682 | 221 if (pff.f.prec >= 0) |
3608 | 222 os << std::setprecision (pff.f.prec); |
223 | |
3775 | 224 std::ios::fmtflags oflags = |
225 os.flags (static_cast<std::ios::fmtflags> | |
226 (pff.f.fmt | pff.f.up | pff.f.sp)); | |
3608 | 227 |
228 os << pff.val; | |
229 | |
230 os.flags (oflags); | |
231 | |
232 return os; | |
233 } | |
234 | |
6788 | 235 static inline std::string |
236 rational_approx (double val, int len) | |
237 { | |
238 std::string s; | |
239 | |
240 if (len <= 0) | |
241 len = 10; | |
242 | |
243 if (xisinf (val)) | |
244 s = "1/0"; | |
245 else if (xisnan (val)) | |
246 s = "0/0"; | |
247 else if (val < INT_MIN || val > INT_MAX || D_NINT (val) == val) | |
248 { | |
249 std::ostringstream buf; | |
250 buf.flags (std::ios::fixed); | |
251 buf << std::setprecision (0) << xround(val); | |
252 s = buf.str (); | |
253 } | |
254 else | |
255 { | |
256 double lastn = 1.; | |
257 double lastd = 0.; | |
258 double n = xround (val); | |
259 double d = 1.; | |
260 double frac = val - n; | |
261 int m = 0; | |
262 | |
263 std::ostringstream buf2; | |
264 buf2.flags (std::ios::fixed); | |
265 buf2 << std::setprecision (0) << static_cast<int>(n); | |
266 s = buf2.str(); | |
267 | |
268 while (1) | |
269 { | |
270 double flip = 1. / frac; | |
271 double step = xround (flip); | |
272 double nextn = n; | |
273 double nextd = d; | |
9412
ddcc0da700b8
Fix 'format rat' for values like '1 - eps'
David Bateman <dbateman@free.fr>
parents:
9377
diff
changeset
|
274 |
ddcc0da700b8
Fix 'format rat' for values like '1 - eps'
David Bateman <dbateman@free.fr>
parents:
9377
diff
changeset
|
275 // Have we converged to 1/intmax ? |
ddcc0da700b8
Fix 'format rat' for values like '1 - eps'
David Bateman <dbateman@free.fr>
parents:
9377
diff
changeset
|
276 if (m > 100 || fabs (frac) < 1 / static_cast<double>(INT_MAX)) |
ddcc0da700b8
Fix 'format rat' for values like '1 - eps'
David Bateman <dbateman@free.fr>
parents:
9377
diff
changeset
|
277 { |
ddcc0da700b8
Fix 'format rat' for values like '1 - eps'
David Bateman <dbateman@free.fr>
parents:
9377
diff
changeset
|
278 lastn = n; |
ddcc0da700b8
Fix 'format rat' for values like '1 - eps'
David Bateman <dbateman@free.fr>
parents:
9377
diff
changeset
|
279 lastd = d; |
ddcc0da700b8
Fix 'format rat' for values like '1 - eps'
David Bateman <dbateman@free.fr>
parents:
9377
diff
changeset
|
280 break; |
ddcc0da700b8
Fix 'format rat' for values like '1 - eps'
David Bateman <dbateman@free.fr>
parents:
9377
diff
changeset
|
281 } |
ddcc0da700b8
Fix 'format rat' for values like '1 - eps'
David Bateman <dbateman@free.fr>
parents:
9377
diff
changeset
|
282 |
6788 | 283 frac = flip - step; |
284 n = n * step + lastn; | |
285 d = d * step + lastd; | |
286 lastn = nextn; | |
287 lastd = nextd; | |
288 | |
289 std::ostringstream buf; | |
290 buf.flags (std::ios::fixed); | |
291 buf << std::setprecision (0) << static_cast<int>(n) | |
292 << "/" << static_cast<int>(d); | |
293 m++; | |
294 | |
295 if (n < 0 && d < 0) | |
296 { | |
297 // Double negative, string can be two characters longer.. | |
298 if (buf.str().length() > static_cast<unsigned int>(len + 2) && | |
299 m > 1) | |
300 break; | |
301 } | |
302 else if (buf.str().length() > static_cast<unsigned int>(len) && | |
303 m > 1) | |
304 break; | |
305 | |
306 s = buf.str(); | |
307 } | |
308 | |
309 if (lastd < 0.) | |
310 { | |
311 // Move sign to the top | |
312 lastd = - lastd; | |
313 lastn = - lastn; | |
314 std::ostringstream buf; | |
315 buf.flags (std::ios::fixed); | |
316 buf << std::setprecision (0) << static_cast<int>(lastn) | |
317 << "/" << static_cast<int>(lastd); | |
318 s = buf.str(); | |
319 } | |
320 } | |
321 | |
322 return s; | |
323 } | |
324 | |
325 class | |
326 pr_rational_float | |
327 { | |
328 public: | |
329 | |
330 const float_format& f; | |
331 | |
332 double val; | |
333 | |
334 pr_rational_float (const float_format& f_arg, double val_arg) | |
335 : f (f_arg), val (val_arg) { } | |
336 }; | |
337 | |
338 std::ostream& | |
339 operator << (std::ostream& os, const pr_rational_float& prf) | |
340 { | |
341 int fw = (rat_string_len > 0 ? rat_string_len : prf.f.fw); | |
342 std::string s = rational_approx (prf.val, fw); | |
343 | |
344 if (fw >= 0) | |
345 os << std::setw (fw); | |
346 | |
347 std::ios::fmtflags oflags = | |
348 os.flags (static_cast<std::ios::fmtflags> | |
349 (prf.f.fmt | prf.f.up | prf.f.sp)); | |
350 | |
351 if (fw > 0 && s.length() > static_cast<unsigned int>(fw)) | |
352 os << "*"; | |
353 else | |
354 os << s; | |
355 | |
356 os.flags (oflags); | |
357 | |
358 return os; | |
359 } | |
360 | |
3608 | 361 // Current format for real numbers and the real part of complex |
362 // numbers. | |
363 static float_format *curr_real_fmt = 0; | |
364 | |
365 // Current format for the imaginary part of complex numbers. | |
366 static float_format *curr_imag_fmt = 0; | |
1309 | 367 |
1 | 368 static double |
164 | 369 pr_max_internal (const Matrix& m) |
1 | 370 { |
5275 | 371 octave_idx_type nr = m.rows (); |
372 octave_idx_type nc = m.columns (); | |
1 | 373 |
3130 | 374 double result = -DBL_MAX; |
1 | 375 |
5748 | 376 bool all_inf_or_nan = true; |
377 | |
5275 | 378 for (octave_idx_type j = 0; j < nc; j++) |
379 for (octave_idx_type i = 0; i < nr; i++) | |
1 | 380 { |
3608 | 381 double val = m(i,j); |
5388 | 382 if (xisinf (val) || xisnan (val)) |
1 | 383 continue; |
384 | |
5748 | 385 all_inf_or_nan = false; |
386 | |
1 | 387 if (val > result) |
388 result = val; | |
389 } | |
3608 | 390 |
5748 | 391 if (all_inf_or_nan) |
392 result = 0.0; | |
393 | |
1 | 394 return result; |
395 } | |
396 | |
397 static double | |
164 | 398 pr_min_internal (const Matrix& m) |
1 | 399 { |
5275 | 400 octave_idx_type nr = m.rows (); |
401 octave_idx_type nc = m.columns (); | |
1 | 402 |
403 double result = DBL_MAX; | |
404 | |
5748 | 405 bool all_inf_or_nan = true; |
406 | |
5275 | 407 for (octave_idx_type j = 0; j < nc; j++) |
408 for (octave_idx_type i = 0; i < nr; i++) | |
1 | 409 { |
3608 | 410 double val = m(i,j); |
5389 | 411 if (xisinf (val) || xisnan (val)) |
1 | 412 continue; |
413 | |
5748 | 414 all_inf_or_nan = false; |
415 | |
1 | 416 if (val < result) |
417 result = val; | |
418 } | |
3608 | 419 |
5748 | 420 if (all_inf_or_nan) |
421 result = 0.0; | |
422 | |
1 | 423 return result; |
424 } | |
425 | |
5775 | 426 // FIXME -- it would be nice to share more code among these |
1658 | 427 // functions,.. |
428 | |
1 | 429 static void |
6959 | 430 set_real_format (int digits, bool inf_or_nan, bool int_only, int &fw) |
1 | 431 { |
3608 | 432 static float_format fmt; |
1 | 433 |
2165 | 434 int prec = Voutput_precision; |
1 | 435 |
436 int ld, rd; | |
437 | |
6788 | 438 if (rat_format) |
439 { | |
440 fw = 0; | |
441 rd = 0; | |
442 } | |
443 else if (bank_format) | |
1 | 444 { |
445 fw = digits < 0 ? 4 : digits + 3; | |
5748 | 446 if (inf_or_nan && fw < 4) |
447 fw = 4; | |
1 | 448 rd = 2; |
449 } | |
1282 | 450 else if (hex_format) |
451 { | |
452 fw = 2 * sizeof (double); | |
453 rd = 0; | |
454 } | |
1309 | 455 else if (bit_format) |
456 { | |
457 fw = 8 * sizeof (double); | |
458 rd = 0; | |
459 } | |
3611 | 460 else if (inf_or_nan || int_only) |
1 | 461 { |
5832 | 462 fw = 1 + digits; |
5748 | 463 if (inf_or_nan && fw < 4) |
464 fw = 4; | |
3682 | 465 rd = fw; |
1 | 466 } |
467 else | |
468 { | |
469 if (digits > 0) | |
470 { | |
471 ld = digits; | |
1658 | 472 rd = prec > digits ? prec - digits : prec; |
1 | 473 digits++; |
474 } | |
475 else | |
476 { | |
477 ld = 1; | |
1658 | 478 rd = prec > digits ? prec - digits : prec; |
1 | 479 digits = -digits + 1; |
480 } | |
481 | |
5832 | 482 fw = 1 + ld + 1 + rd; |
5748 | 483 if (inf_or_nan && fw < 4) |
484 fw = 4; | |
1 | 485 } |
486 | |
6788 | 487 if (! (rat_format || bank_format || hex_format || bit_format) |
4509 | 488 && (fw > Voutput_max_field_width || print_e || print_g)) |
1 | 489 { |
4509 | 490 if (print_g) |
491 fmt = float_format (); | |
492 else | |
493 { | |
494 int exp_field = 4; | |
495 if (digits > 100) | |
496 exp_field++; | |
1 | 497 |
4509 | 498 fw = 2 + prec + exp_field; |
5748 | 499 if (inf_or_nan && fw < 4) |
500 fw = 4; | |
1 | 501 |
4509 | 502 fmt = float_format (fw, prec - 1, std::ios::scientific); |
503 } | |
3608 | 504 |
1 | 505 if (print_big_e) |
3608 | 506 fmt.uppercase (); |
1 | 507 } |
5086 | 508 else if (! bank_format && (inf_or_nan || int_only)) |
3611 | 509 fmt = float_format (fw, rd); |
1 | 510 else |
3608 | 511 fmt = float_format (fw, rd, std::ios::fixed); |
1 | 512 |
3608 | 513 curr_real_fmt = &fmt; |
1 | 514 } |
515 | |
1658 | 516 static void |
517 set_format (double d, int& fw) | |
518 { | |
519 curr_real_fmt = 0; | |
520 curr_imag_fmt = 0; | |
521 | |
522 if (free_format) | |
523 return; | |
524 | |
5389 | 525 bool inf_or_nan = (xisinf (d) || xisnan (d)); |
1658 | 526 |
3611 | 527 bool int_only = (! inf_or_nan && D_NINT (d) == d); |
1658 | 528 |
529 double d_abs = d < 0.0 ? -d : d; | |
530 | |
2800 | 531 int digits = (inf_or_nan || d_abs == 0.0) |
532 ? 0 : static_cast<int> (floor (log10 (d_abs) + 1.0)); | |
1658 | 533 |
6959 | 534 set_real_format (digits, inf_or_nan, int_only, fw); |
1658 | 535 } |
536 | |
1 | 537 static inline void |
538 set_format (double d) | |
539 { | |
540 int fw; | |
541 set_format (d, fw); | |
542 } | |
543 | |
544 static void | |
6959 | 545 set_real_matrix_format (int x_max, int x_min, bool inf_or_nan, |
546 int int_or_inf_or_nan, int& fw) | |
1 | 547 { |
3608 | 548 static float_format fmt; |
1 | 549 |
2165 | 550 int prec = Voutput_precision; |
1 | 551 |
552 int ld, rd; | |
553 | |
6788 | 554 if (rat_format) |
555 { | |
556 fw = 9; | |
557 rd = 0; | |
558 } | |
559 else if (bank_format) | |
1 | 560 { |
561 int digits = x_max > x_min ? x_max : x_min; | |
562 fw = digits <= 0 ? 4 : digits + 3; | |
5748 | 563 if (inf_or_nan && fw < 4) |
564 fw = 4; | |
1 | 565 rd = 2; |
566 } | |
1282 | 567 else if (hex_format) |
568 { | |
569 fw = 2 * sizeof (double); | |
570 rd = 0; | |
571 } | |
1309 | 572 else if (bit_format) |
573 { | |
574 fw = 8 * sizeof (double); | |
575 rd = 0; | |
576 } | |
4509 | 577 else if (Vfixed_point_format && ! print_g) |
3268 | 578 { |
579 rd = prec; | |
580 fw = rd + 2; | |
5748 | 581 if (inf_or_nan && fw < 4) |
582 fw = 4; | |
3268 | 583 } |
1715 | 584 else if (int_or_inf_or_nan) |
1 | 585 { |
586 int digits = x_max > x_min ? x_max : x_min; | |
5945 | 587 fw = digits <= 0 ? 2 : digits + 1; |
5748 | 588 if (inf_or_nan && fw < 4) |
589 fw = 4; | |
3682 | 590 rd = fw; |
1 | 591 } |
592 else | |
593 { | |
594 int ld_max, rd_max; | |
595 if (x_max > 0) | |
596 { | |
597 ld_max = x_max; | |
1658 | 598 rd_max = prec > x_max ? prec - x_max : prec; |
1 | 599 x_max++; |
600 } | |
601 else | |
602 { | |
603 ld_max = 1; | |
1658 | 604 rd_max = prec > x_max ? prec - x_max : prec; |
1 | 605 x_max = -x_max + 1; |
606 } | |
607 | |
608 int ld_min, rd_min; | |
609 if (x_min > 0) | |
610 { | |
611 ld_min = x_min; | |
1658 | 612 rd_min = prec > x_min ? prec - x_min : prec; |
1 | 613 x_min++; |
614 } | |
615 else | |
616 { | |
617 ld_min = 1; | |
1658 | 618 rd_min = prec > x_min ? prec - x_min : prec; |
1 | 619 x_min = -x_min + 1; |
620 } | |
621 | |
622 ld = ld_max > ld_min ? ld_max : ld_min; | |
623 rd = rd_max > rd_min ? rd_max : rd_min; | |
624 | |
5832 | 625 fw = 1 + ld + 1 + rd; |
5748 | 626 if (inf_or_nan && fw < 4) |
627 fw = 4; | |
1 | 628 } |
629 | |
6788 | 630 if (! (rat_format || bank_format || hex_format || bit_format) |
3105 | 631 && (print_e |
4509 | 632 || print_g |
3105 | 633 || (! Vfixed_point_format && fw > Voutput_max_field_width))) |
1 | 634 { |
4509 | 635 if (print_g) |
636 fmt = float_format (); | |
637 else | |
638 { | |
639 int exp_field = 4; | |
640 if (x_max > 100 || x_min > 100) | |
641 exp_field++; | |
1 | 642 |
4509 | 643 fw = 2 + prec + exp_field; |
5748 | 644 if (inf_or_nan && fw < 4) |
645 fw = 4; | |
1 | 646 |
4509 | 647 fmt = float_format (fw, prec - 1, std::ios::scientific); |
648 } | |
3608 | 649 |
1 | 650 if (print_big_e) |
3608 | 651 fmt.uppercase (); |
1 | 652 } |
5086 | 653 else if (! bank_format && int_or_inf_or_nan) |
3611 | 654 fmt = float_format (fw, rd); |
1 | 655 else |
3608 | 656 fmt = float_format (fw, rd, std::ios::fixed); |
1 | 657 |
3608 | 658 curr_real_fmt = &fmt; |
1 | 659 } |
660 | |
1658 | 661 static void |
3105 | 662 set_format (const Matrix& m, int& fw, double& scale) |
1658 | 663 { |
664 curr_real_fmt = 0; | |
665 curr_imag_fmt = 0; | |
666 | |
667 if (free_format) | |
668 return; | |
669 | |
2387 | 670 bool inf_or_nan = m.any_element_is_inf_or_nan (); |
1658 | 671 |
2387 | 672 bool int_or_inf_or_nan = m.all_elements_are_int_or_inf_or_nan (); |
1658 | 673 |
2387 | 674 Matrix m_abs = m.abs (); |
1658 | 675 double max_abs = pr_max_internal (m_abs); |
676 double min_abs = pr_min_internal (m_abs); | |
677 | |
2800 | 678 int x_max = max_abs == 0.0 |
679 ? 0 : static_cast<int> (floor (log10 (max_abs) + 1.0)); | |
680 | |
681 int x_min = min_abs == 0.0 | |
682 ? 0 : static_cast<int> (floor (log10 (min_abs) + 1.0)); | |
1658 | 683 |
4270 | 684 scale = (x_max == 0 || int_or_inf_or_nan) ? 1.0 : std::pow (10.0, x_max - 1); |
3105 | 685 |
6959 | 686 set_real_matrix_format (x_max, x_min, inf_or_nan, int_or_inf_or_nan, fw); |
1658 | 687 } |
688 | |
1 | 689 static inline void |
164 | 690 set_format (const Matrix& m) |
1 | 691 { |
692 int fw; | |
3105 | 693 double scale; |
694 set_format (m, fw, scale); | |
1 | 695 } |
696 | |
697 static void | |
6959 | 698 set_complex_format (int x_max, int x_min, int r_x, bool inf_or_nan, |
699 int int_only, int& r_fw, int& i_fw) | |
1 | 700 { |
3608 | 701 static float_format r_fmt; |
702 static float_format i_fmt; | |
1 | 703 |
2165 | 704 int prec = Voutput_precision; |
1 | 705 |
706 int ld, rd; | |
707 | |
6788 | 708 if (rat_format) |
709 { | |
710 i_fw = 0; | |
711 r_fw = 0; | |
712 rd = 0; | |
713 } | |
714 else if (bank_format) | |
1 | 715 { |
716 int digits = r_x; | |
717 i_fw = 0; | |
718 r_fw = digits <= 0 ? 4 : digits + 3; | |
5748 | 719 if (inf_or_nan && r_fw < 4) |
720 r_fw = 4; | |
1 | 721 rd = 2; |
722 } | |
1282 | 723 else if (hex_format) |
724 { | |
725 r_fw = 2 * sizeof (double); | |
726 i_fw = 2 * sizeof (double); | |
727 rd = 0; | |
728 } | |
1309 | 729 else if (bit_format) |
730 { | |
731 r_fw = 8 * sizeof (double); | |
732 i_fw = 8 * sizeof (double); | |
733 rd = 0; | |
734 } | |
1658 | 735 else if (inf_or_nan || int_only) |
1 | 736 { |
737 int digits = x_max > x_min ? x_max : x_min; | |
5945 | 738 i_fw = digits <= 0 ? 1 : digits; |
739 r_fw = i_fw + 1; | |
740 if (inf_or_nan && i_fw < 3) | |
741 { | |
742 i_fw = 3; | |
743 r_fw = 4; | |
744 } | |
3682 | 745 rd = r_fw; |
1 | 746 } |
747 else | |
748 { | |
749 int ld_max, rd_max; | |
750 if (x_max > 0) | |
751 { | |
752 ld_max = x_max; | |
1658 | 753 rd_max = prec > x_max ? prec - x_max : prec; |
1 | 754 x_max++; |
755 } | |
756 else | |
757 { | |
758 ld_max = 1; | |
1658 | 759 rd_max = prec > x_max ? prec - x_max : prec; |
1 | 760 x_max = -x_max + 1; |
761 } | |
762 | |
763 int ld_min, rd_min; | |
764 if (x_min > 0) | |
765 { | |
766 ld_min = x_min; | |
1658 | 767 rd_min = prec > x_min ? prec - x_min : prec; |
1 | 768 x_min++; |
769 } | |
770 else | |
771 { | |
772 ld_min = 1; | |
1658 | 773 rd_min = prec > x_min ? prec - x_min : prec; |
1 | 774 x_min = -x_min + 1; |
775 } | |
776 | |
777 ld = ld_max > ld_min ? ld_max : ld_min; | |
778 rd = rd_max > rd_min ? rd_max : rd_min; | |
779 | |
5945 | 780 i_fw = ld + 1 + rd; |
781 r_fw = i_fw + 1; | |
782 if (inf_or_nan && i_fw < 3) | |
783 { | |
784 i_fw = 3; | |
785 r_fw = 4; | |
786 } | |
1 | 787 } |
788 | |
6788 | 789 if (! (rat_format || bank_format || hex_format || bit_format) |
4509 | 790 && (r_fw > Voutput_max_field_width || print_e || print_g)) |
1 | 791 { |
4509 | 792 if (print_g) |
793 { | |
794 r_fmt = float_format (); | |
795 i_fmt = float_format (); | |
796 } | |
797 else | |
798 { | |
799 int exp_field = 4; | |
800 if (x_max > 100 || x_min > 100) | |
801 exp_field++; | |
1 | 802 |
5945 | 803 i_fw = prec + exp_field; |
804 r_fw = i_fw + 1; | |
805 if (inf_or_nan && i_fw < 3) | |
806 { | |
807 i_fw = 3; | |
808 r_fw = 4; | |
809 } | |
1 | 810 |
4509 | 811 r_fmt = float_format (r_fw, prec - 1, std::ios::scientific); |
812 i_fmt = float_format (i_fw, prec - 1, std::ios::scientific); | |
813 } | |
3608 | 814 |
1 | 815 if (print_big_e) |
816 { | |
3608 | 817 r_fmt.uppercase (); |
818 i_fmt.uppercase (); | |
1 | 819 } |
820 } | |
5086 | 821 else if (! bank_format && (inf_or_nan || int_only)) |
3611 | 822 { |
823 r_fmt = float_format (r_fw, rd); | |
824 i_fmt = float_format (i_fw, rd); | |
825 } | |
1 | 826 else |
827 { | |
3608 | 828 r_fmt = float_format (r_fw, rd, std::ios::fixed); |
829 i_fmt = float_format (i_fw, rd, std::ios::fixed); | |
1 | 830 } |
831 | |
3608 | 832 curr_real_fmt = &r_fmt; |
833 curr_imag_fmt = &i_fmt; | |
1 | 834 } |
835 | |
1658 | 836 static void |
837 set_format (const Complex& c, int& r_fw, int& i_fw) | |
838 { | |
839 curr_real_fmt = 0; | |
840 curr_imag_fmt = 0; | |
841 | |
842 if (free_format) | |
843 return; | |
844 | |
845 double rp = c.real (); | |
846 double ip = c.imag (); | |
847 | |
2387 | 848 bool inf_or_nan = (xisinf (c) || xisnan (c)); |
1658 | 849 |
2387 | 850 bool int_only = (D_NINT (rp) == rp && D_NINT (ip) == ip); |
1658 | 851 |
852 double r_abs = rp < 0.0 ? -rp : rp; | |
853 double i_abs = ip < 0.0 ? -ip : ip; | |
854 | |
9612
66970dd627f6
further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9611
diff
changeset
|
855 int r_x = (xisinf (rp) || xisnan (rp) || r_abs == 0.0) |
2800 | 856 ? 0 : static_cast<int> (floor (log10 (r_abs) + 1.0)); |
857 | |
9611
6f42ea240b3a
pr-output.cc (set_format (const Complex&, int&, int&)): avoid passing NaN or Inf to log10
John W. Eaton <jwe@octave.org>
parents:
9412
diff
changeset
|
858 int i_x = (xisinf (ip) || xisnan (ip) || i_abs == 0.0) |
2800 | 859 ? 0 : static_cast<int> (floor (log10 (i_abs) + 1.0)); |
1658 | 860 |
861 int x_max, x_min; | |
862 | |
863 if (r_x > i_x) | |
864 { | |
865 x_max = r_x; | |
866 x_min = i_x; | |
867 } | |
868 else | |
869 { | |
870 x_max = i_x; | |
871 x_min = r_x; | |
872 } | |
873 | |
6959 | 874 set_complex_format (x_max, x_min, r_x, inf_or_nan, int_only, r_fw, i_fw); |
1658 | 875 } |
876 | |
1 | 877 static inline void |
164 | 878 set_format (const Complex& c) |
1 | 879 { |
880 int r_fw, i_fw; | |
881 set_format (c, r_fw, i_fw); | |
882 } | |
883 | |
884 static void | |
6959 | 885 set_complex_matrix_format (int x_max, int x_min, int r_x_max, |
886 int r_x_min, bool inf_or_nan, | |
1715 | 887 int int_or_inf_or_nan, int& r_fw, int& i_fw) |
1 | 888 { |
3608 | 889 static float_format r_fmt; |
890 static float_format i_fmt; | |
1 | 891 |
2165 | 892 int prec = Voutput_precision; |
1 | 893 |
894 int ld, rd; | |
895 | |
6788 | 896 if (rat_format) |
897 { | |
898 i_fw = 9; | |
899 r_fw = 9; | |
900 rd = 0; | |
901 } | |
902 else if (bank_format) | |
1 | 903 { |
904 int digits = r_x_max > r_x_min ? r_x_max : r_x_min; | |
905 i_fw = 0; | |
906 r_fw = digits <= 0 ? 4 : digits + 3; | |
5945 | 907 if (inf_or_nan && r_fw < 4) |
908 r_fw = 4; | |
1 | 909 rd = 2; |
910 } | |
1282 | 911 else if (hex_format) |
912 { | |
913 r_fw = 2 * sizeof (double); | |
914 i_fw = 2 * sizeof (double); | |
915 rd = 0; | |
916 } | |
1309 | 917 else if (bit_format) |
918 { | |
919 r_fw = 8 * sizeof (double); | |
920 i_fw = 8 * sizeof (double); | |
921 rd = 0; | |
922 } | |
4509 | 923 else if (Vfixed_point_format && ! print_g) |
3268 | 924 { |
925 rd = prec; | |
5945 | 926 i_fw = rd + 1; |
927 r_fw = i_fw + 1; | |
928 if (inf_or_nan && i_fw < 3) | |
929 { | |
930 i_fw = 3; | |
931 r_fw = 4; | |
932 } | |
3268 | 933 } |
1715 | 934 else if (int_or_inf_or_nan) |
1 | 935 { |
936 int digits = x_max > x_min ? x_max : x_min; | |
5945 | 937 i_fw = digits <= 0 ? 1 : digits; |
938 r_fw = i_fw + 1; | |
939 if (inf_or_nan && i_fw < 3) | |
940 { | |
941 i_fw = 3; | |
942 r_fw = 4; | |
943 } | |
3682 | 944 rd = r_fw; |
1 | 945 } |
946 else | |
947 { | |
948 int ld_max, rd_max; | |
949 if (x_max > 0) | |
950 { | |
951 ld_max = x_max; | |
1658 | 952 rd_max = prec > x_max ? prec - x_max : prec; |
1 | 953 x_max++; |
954 } | |
955 else | |
956 { | |
957 ld_max = 1; | |
1658 | 958 rd_max = prec > x_max ? prec - x_max : prec; |
1 | 959 x_max = -x_max + 1; |
960 } | |
961 | |
962 int ld_min, rd_min; | |
963 if (x_min > 0) | |
964 { | |
965 ld_min = x_min; | |
1658 | 966 rd_min = prec > x_min ? prec - x_min : prec; |
1 | 967 x_min++; |
968 } | |
969 else | |
970 { | |
971 ld_min = 1; | |
1658 | 972 rd_min = prec > x_min ? prec - x_min : prec; |
1 | 973 x_min = -x_min + 1; |
974 } | |
975 | |
976 ld = ld_max > ld_min ? ld_max : ld_min; | |
977 rd = rd_max > rd_min ? rd_max : rd_min; | |
978 | |
5945 | 979 i_fw = ld + 1 + rd; |
980 r_fw = i_fw + 1; | |
981 if (inf_or_nan && i_fw < 3) | |
982 { | |
983 i_fw = 3; | |
984 r_fw = 4; | |
985 } | |
1 | 986 } |
987 | |
6788 | 988 if (! (rat_format || bank_format || hex_format || bit_format) |
3105 | 989 && (print_e |
4509 | 990 || print_g |
3105 | 991 || (! Vfixed_point_format && r_fw > Voutput_max_field_width))) |
1 | 992 { |
4509 | 993 if (print_g) |
994 { | |
995 r_fmt = float_format (); | |
996 i_fmt = float_format (); | |
997 } | |
998 else | |
999 { | |
1000 int exp_field = 4; | |
1001 if (x_max > 100 || x_min > 100) | |
1002 exp_field++; | |
1 | 1003 |
5945 | 1004 i_fw = prec + exp_field; |
1005 r_fw = i_fw + 1; | |
1006 if (inf_or_nan && i_fw < 3) | |
1007 { | |
1008 i_fw = 3; | |
1009 r_fw = 4; | |
1010 } | |
1 | 1011 |
4509 | 1012 r_fmt = float_format (r_fw, prec - 1, std::ios::scientific); |
1013 i_fmt = float_format (i_fw, prec - 1, std::ios::scientific); | |
1014 } | |
3608 | 1015 |
1 | 1016 if (print_big_e) |
1017 { | |
3608 | 1018 r_fmt.uppercase (); |
1019 i_fmt.uppercase (); | |
1 | 1020 } |
1021 } | |
5086 | 1022 else if (! bank_format && int_or_inf_or_nan) |
3611 | 1023 { |
1024 r_fmt = float_format (r_fw, rd); | |
1025 i_fmt = float_format (i_fw, rd); | |
1026 } | |
1 | 1027 else |
1028 { | |
3608 | 1029 r_fmt = float_format (r_fw, rd, std::ios::fixed); |
1030 i_fmt = float_format (i_fw, rd, std::ios::fixed); | |
1 | 1031 } |
1032 | |
3608 | 1033 curr_real_fmt = &r_fmt; |
1034 curr_imag_fmt = &i_fmt; | |
1 | 1035 } |
1036 | |
1658 | 1037 static void |
3105 | 1038 set_format (const ComplexMatrix& cm, int& r_fw, int& i_fw, double& scale) |
1658 | 1039 { |
1040 curr_real_fmt = 0; | |
1041 curr_imag_fmt = 0; | |
1042 | |
1043 if (free_format) | |
1044 return; | |
1045 | |
1046 Matrix rp = real (cm); | |
1047 Matrix ip = imag (cm); | |
1048 | |
2387 | 1049 bool inf_or_nan = cm.any_element_is_inf_or_nan (); |
1658 | 1050 |
2387 | 1051 bool int_or_inf_or_nan = (rp.all_elements_are_int_or_inf_or_nan () |
1052 && ip.all_elements_are_int_or_inf_or_nan ()); | |
1658 | 1053 |
2387 | 1054 Matrix r_m_abs = rp.abs (); |
1658 | 1055 double r_max_abs = pr_max_internal (r_m_abs); |
1056 double r_min_abs = pr_min_internal (r_m_abs); | |
1057 | |
2387 | 1058 Matrix i_m_abs = ip.abs (); |
1658 | 1059 double i_max_abs = pr_max_internal (i_m_abs); |
1060 double i_min_abs = pr_min_internal (i_m_abs); | |
1061 | |
2800 | 1062 int r_x_max = r_max_abs == 0.0 |
1063 ? 0 : static_cast<int> (floor (log10 (r_max_abs) + 1.0)); | |
1064 | |
1065 int r_x_min = r_min_abs == 0.0 | |
1066 ? 0 : static_cast<int> (floor (log10 (r_min_abs) + 1.0)); | |
1658 | 1067 |
2800 | 1068 int i_x_max = i_max_abs == 0.0 |
1069 ? 0 : static_cast<int> (floor (log10 (i_max_abs) + 1.0)); | |
1070 | |
1071 int i_x_min = i_min_abs == 0.0 | |
1072 ? 0 : static_cast<int> (floor (log10 (i_min_abs) + 1.0)); | |
1658 | 1073 |
1074 int x_max = r_x_max > i_x_max ? r_x_max : i_x_max; | |
1075 int x_min = r_x_min > i_x_min ? r_x_min : i_x_min; | |
1076 | |
4270 | 1077 scale = (x_max == 0 || int_or_inf_or_nan) ? 1.0 : std::pow (10.0, x_max - 1); |
3105 | 1078 |
6959 | 1079 set_complex_matrix_format (x_max, x_min, r_x_max, r_x_min, inf_or_nan, |
1080 int_or_inf_or_nan, r_fw, i_fw); | |
1658 | 1081 } |
1082 | |
1 | 1083 static inline void |
164 | 1084 set_format (const ComplexMatrix& cm) |
1 | 1085 { |
1086 int r_fw, i_fw; | |
3105 | 1087 double scale; |
1088 set_format (cm, r_fw, i_fw, scale); | |
1 | 1089 } |
1090 | |
1091 static void | |
7465
8d6ab12f8fda
format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
1092 set_range_format (int x_max, int x_min, int all_ints, int& fw) |
1 | 1093 { |
3608 | 1094 static float_format fmt; |
1 | 1095 |
2165 | 1096 int prec = Voutput_precision; |
1 | 1097 |
1098 int ld, rd; | |
1099 | |
6788 | 1100 if (rat_format) |
1101 { | |
1102 fw = 9; | |
1103 rd = 0; | |
1104 } | |
1105 else if (bank_format) | |
1 | 1106 { |
1107 int digits = x_max > x_min ? x_max : x_min; | |
7465
8d6ab12f8fda
format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
1108 fw = digits < 0 ? 5 : digits + 4; |
1 | 1109 rd = 2; |
1110 } | |
1282 | 1111 else if (hex_format) |
1112 { | |
1113 fw = 2 * sizeof (double); | |
1114 rd = 0; | |
1115 } | |
1309 | 1116 else if (bit_format) |
1117 { | |
1118 fw = 8 * sizeof (double); | |
1119 rd = 0; | |
1120 } | |
1658 | 1121 else if (all_ints) |
1 | 1122 { |
1123 int digits = x_max > x_min ? x_max : x_min; | |
7465
8d6ab12f8fda
format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
1124 fw = digits + 1; |
3682 | 1125 rd = fw; |
1 | 1126 } |
4509 | 1127 else if (Vfixed_point_format && ! print_g) |
3105 | 1128 { |
1129 rd = prec; | |
7465
8d6ab12f8fda
format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
1130 fw = rd + 3; |
3105 | 1131 } |
1 | 1132 else |
1133 { | |
1134 int ld_max, rd_max; | |
1135 if (x_max > 0) | |
1136 { | |
1137 ld_max = x_max; | |
1658 | 1138 rd_max = prec > x_max ? prec - x_max : prec; |
1 | 1139 x_max++; |
1140 } | |
1141 else | |
1142 { | |
1143 ld_max = 1; | |
1658 | 1144 rd_max = prec > x_max ? prec - x_max : prec; |
1 | 1145 x_max = -x_max + 1; |
1146 } | |
1147 | |
1148 int ld_min, rd_min; | |
1149 if (x_min > 0) | |
1150 { | |
1151 ld_min = x_min; | |
1658 | 1152 rd_min = prec > x_min ? prec - x_min : prec; |
1 | 1153 x_min++; |
1154 } | |
1155 else | |
1156 { | |
1157 ld_min = 1; | |
1658 | 1158 rd_min = prec > x_min ? prec - x_min : prec; |
1 | 1159 x_min = -x_min + 1; |
1160 } | |
1161 | |
1162 ld = ld_max > ld_min ? ld_max : ld_min; | |
1163 rd = rd_max > rd_min ? rd_max : rd_min; | |
1164 | |
7465
8d6ab12f8fda
format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
1165 fw = ld + rd + 3; |
1 | 1166 } |
1167 | |
6788 | 1168 if (! (rat_format || bank_format || hex_format || bit_format) |
3105 | 1169 && (print_e |
4509 | 1170 || print_g |
3105 | 1171 || (! Vfixed_point_format && fw > Voutput_max_field_width))) |
1 | 1172 { |
4509 | 1173 if (print_g) |
1174 fmt = float_format (); | |
1175 else | |
1176 { | |
1177 int exp_field = 4; | |
1178 if (x_max > 100 || x_min > 100) | |
1179 exp_field++; | |
1 | 1180 |
7465
8d6ab12f8fda
format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
1181 fw = 3 + prec + exp_field; |
1 | 1182 |
4509 | 1183 fmt = float_format (fw, prec - 1, std::ios::scientific); |
1184 } | |
3608 | 1185 |
1 | 1186 if (print_big_e) |
3608 | 1187 fmt.uppercase (); |
1 | 1188 } |
5086 | 1189 else if (! bank_format && all_ints) |
3611 | 1190 fmt = float_format (fw, rd); |
1 | 1191 else |
3608 | 1192 fmt = float_format (fw, rd, std::ios::fixed); |
1 | 1193 |
3608 | 1194 curr_real_fmt = &fmt; |
1 | 1195 } |
1196 | |
1658 | 1197 static void |
3105 | 1198 set_format (const Range& r, int& fw, double& scale) |
1658 | 1199 { |
1200 curr_real_fmt = 0; | |
1201 curr_imag_fmt = 0; | |
1202 | |
1203 if (free_format) | |
1204 return; | |
1205 | |
1206 double r_min = r.base (); | |
1207 double r_max = r.limit (); | |
1208 | |
1209 if (r_max < r_min) | |
1210 { | |
1211 double tmp = r_max; | |
1212 r_max = r_min; | |
1213 r_min = tmp; | |
1214 } | |
1215 | |
2387 | 1216 bool all_ints = r.all_elements_are_ints (); |
1658 | 1217 |
1218 double max_abs = r_max < 0.0 ? -r_max : r_max; | |
1219 double min_abs = r_min < 0.0 ? -r_min : r_min; | |
1220 | |
2800 | 1221 int x_max = max_abs == 0.0 |
1222 ? 0 : static_cast<int> (floor (log10 (max_abs) + 1.0)); | |
1223 | |
1224 int x_min = min_abs == 0.0 | |
1225 ? 0 : static_cast<int> (floor (log10 (min_abs) + 1.0)); | |
1658 | 1226 |
4270 | 1227 scale = (x_max == 0 || all_ints) ? 1.0 : std::pow (10.0, x_max - 1); |
3105 | 1228 |
7465
8d6ab12f8fda
format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
1229 set_range_format (x_max, x_min, all_ints, fw); |
1658 | 1230 } |
1231 | |
1 | 1232 static inline void |
164 | 1233 set_format (const Range& r) |
1 | 1234 { |
1235 int fw; | |
3105 | 1236 double scale; |
1237 set_format (r, fw, scale); | |
1 | 1238 } |
1239 | |
1282 | 1240 union equiv |
1241 { | |
1242 double d; | |
1243 unsigned char i[sizeof (double)]; | |
1244 }; | |
1245 | |
1309 | 1246 #define PRINT_CHAR_BITS(os, c) \ |
1247 do \ | |
1248 { \ | |
1249 unsigned char ctmp = c; \ | |
1250 char stmp[9]; \ | |
1488 | 1251 stmp[0] = (ctmp & 0x80) ? '1' : '0'; \ |
1252 stmp[1] = (ctmp & 0x40) ? '1' : '0'; \ | |
1253 stmp[2] = (ctmp & 0x20) ? '1' : '0'; \ | |
1254 stmp[3] = (ctmp & 0x10) ? '1' : '0'; \ | |
1255 stmp[4] = (ctmp & 0x08) ? '1' : '0'; \ | |
1256 stmp[5] = (ctmp & 0x04) ? '1' : '0'; \ | |
1257 stmp[6] = (ctmp & 0x02) ? '1' : '0'; \ | |
1258 stmp[7] = (ctmp & 0x01) ? '1' : '0'; \ | |
1309 | 1259 stmp[8] = '\0'; \ |
3013 | 1260 os << stmp; \ |
1309 | 1261 } \ |
1262 while (0) | |
1263 | |
1264 #define PRINT_CHAR_BITS_SWAPPED(os, c) \ | |
1265 do \ | |
1266 { \ | |
1267 unsigned char ctmp = c; \ | |
1268 char stmp[9]; \ | |
1488 | 1269 stmp[0] = (ctmp & 0x01) ? '1' : '0'; \ |
1270 stmp[1] = (ctmp & 0x02) ? '1' : '0'; \ | |
1271 stmp[2] = (ctmp & 0x04) ? '1' : '0'; \ | |
1272 stmp[3] = (ctmp & 0x08) ? '1' : '0'; \ | |
1273 stmp[4] = (ctmp & 0x10) ? '1' : '0'; \ | |
1274 stmp[5] = (ctmp & 0x20) ? '1' : '0'; \ | |
1275 stmp[6] = (ctmp & 0x40) ? '1' : '0'; \ | |
1276 stmp[7] = (ctmp & 0x80) ? '1' : '0'; \ | |
1309 | 1277 stmp[8] = '\0'; \ |
3013 | 1278 os << stmp; \ |
1309 | 1279 } \ |
1280 while (0) | |
1281 | |
2522 | 1282 static void |
3608 | 1283 pr_any_float (const float_format *fmt, std::ostream& os, double d, int fw = 0) |
1 | 1284 { |
529 | 1285 if (fmt) |
1 | 1286 { |
5544 | 1287 // Unless explicitly asked for, always print in big-endian |
1288 // format for hex and bit formats. | |
1289 // | |
1290 // {bit,hex}_format == 1: print big-endian | |
1291 // {bit,hex}_format == 2: print native | |
1292 | |
1282 | 1293 if (hex_format) |
1294 { | |
1295 equiv tmp; | |
1296 tmp.d = d; | |
1297 | |
1298 // Unless explicitly asked for, always print in big-endian | |
1299 // format. | |
1300 | |
5775 | 1301 // FIXME -- is it correct to swap bytes for VAX |
1282 | 1302 // formats and not for Cray? |
1303 | |
5775 | 1304 // FIXME -- will bad things happen if we are |
3013 | 1305 // interrupted before resetting the format flags and fill |
1306 // character? | |
1307 | |
2317 | 1308 oct_mach_info::float_format flt_fmt = |
1309 oct_mach_info::native_float_format (); | |
1310 | |
3013 | 1311 char ofill = os.fill ('0'); |
1312 | |
3608 | 1313 std::ios::fmtflags oflags |
1314 = os.flags (std::ios::right | std::ios::hex); | |
3013 | 1315 |
1282 | 1316 if (hex_format > 1 |
4574 | 1317 || flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian |
1318 || flt_fmt == oct_mach_info::flt_fmt_cray | |
1319 || flt_fmt == oct_mach_info::flt_fmt_unknown) | |
1282 | 1320 { |
1322 | 1321 for (size_t i = 0; i < sizeof (double); i++) |
3548 | 1322 os << std::setw (2) << static_cast<int> (tmp.i[i]); |
1282 | 1323 } |
1324 else | |
1325 { | |
1328 | 1326 for (int i = sizeof (double) - 1; i >= 0; i--) |
3548 | 1327 os << std::setw (2) << static_cast<int> (tmp.i[i]); |
1282 | 1328 } |
3013 | 1329 |
1330 os.fill (ofill); | |
1331 os.setf (oflags); | |
1282 | 1332 } |
1309 | 1333 else if (bit_format) |
1334 { | |
1335 equiv tmp; | |
1336 tmp.d = d; | |
1337 | |
5775 | 1338 // FIXME -- is it correct to swap bytes for VAX |
1309 | 1339 // formats and not for Cray? |
1340 | |
2317 | 1341 oct_mach_info::float_format flt_fmt = |
1342 oct_mach_info::native_float_format (); | |
1343 | |
4574 | 1344 if (flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian |
1345 || flt_fmt == oct_mach_info::flt_fmt_cray | |
1346 || flt_fmt == oct_mach_info::flt_fmt_unknown) | |
1309 | 1347 { |
1322 | 1348 for (size_t i = 0; i < sizeof (double); i++) |
1309 | 1349 PRINT_CHAR_BITS (os, tmp.i[i]); |
1350 } | |
1351 else | |
1352 { | |
1353 if (bit_format > 1) | |
1354 { | |
1328 | 1355 for (size_t i = 0; i < sizeof (double); i++) |
1309 | 1356 PRINT_CHAR_BITS_SWAPPED (os, tmp.i[i]); |
1357 } | |
1358 else | |
1359 { | |
1360 for (int i = sizeof (double) - 1; i >= 0; i--) | |
1361 PRINT_CHAR_BITS (os, tmp.i[i]); | |
1362 } | |
1363 } | |
1364 } | |
6788 | 1365 else if (octave_is_NA (d)) |
1366 { | |
1367 if (fw > 0) | |
1368 os << std::setw (fw) << "NA"; | |
1369 else | |
1370 os << "NA"; | |
1371 } | |
1372 else if (rat_format) | |
1373 os << pr_rational_float (*fmt, d); | |
1282 | 1374 else if (xisinf (d)) |
1 | 1375 { |
2804 | 1376 const char *s; |
1 | 1377 if (d < 0.0) |
1378 s = "-Inf"; | |
1379 else | |
1380 s = "Inf"; | |
1381 | |
1382 if (fw > 0) | |
3548 | 1383 os << std::setw (fw) << s; |
1 | 1384 else |
1385 os << s; | |
1386 } | |
1387 else if (xisnan (d)) | |
1388 { | |
1389 if (fw > 0) | |
3548 | 1390 os << std::setw (fw) << "NaN"; |
1 | 1391 else |
1392 os << "NaN"; | |
1393 } | |
1394 else | |
3608 | 1395 os << pr_formatted_float (*fmt, d); |
1 | 1396 } |
529 | 1397 else |
1398 os << d; | |
1 | 1399 } |
1400 | |
1401 static inline void | |
3608 | 1402 pr_float (std::ostream& os, double d, int fw = 0, double scale = 1.0) |
1 | 1403 { |
4509 | 1404 if (Vfixed_point_format && ! print_g && scale != 1.0) |
3608 | 1405 d /= scale; |
1406 | |
1 | 1407 pr_any_float (curr_real_fmt, os, d, fw); |
1408 } | |
1409 | |
1410 static inline void | |
3523 | 1411 pr_imag_float (std::ostream& os, double d, int fw = 0) |
1 | 1412 { |
1413 pr_any_float (curr_imag_fmt, os, d, fw); | |
1414 } | |
1415 | |
2522 | 1416 static void |
3608 | 1417 pr_complex (std::ostream& os, const Complex& c, int r_fw = 0, |
1418 int i_fw = 0, double scale = 1.0) | |
1 | 1419 { |
4509 | 1420 Complex tmp |
1421 = (Vfixed_point_format && ! print_g && scale != 1.0) ? c / scale : c; | |
3608 | 1422 |
1423 double r = tmp.real (); | |
1424 | |
1 | 1425 pr_float (os, r, r_fw); |
3608 | 1426 |
1 | 1427 if (! bank_format) |
1428 { | |
3608 | 1429 double i = tmp.imag (); |
4349 | 1430 if (! (hex_format || bit_format) && lo_ieee_signbit (i)) |
1 | 1431 { |
1432 os << " - "; | |
1433 i = -i; | |
1434 pr_imag_float (os, i, i_fw); | |
1435 } | |
1436 else | |
1437 { | |
1309 | 1438 if (hex_format || bit_format) |
1282 | 1439 os << " "; |
1440 else | |
1441 os << " + "; | |
1442 | |
1 | 1443 pr_imag_float (os, i, i_fw); |
1444 } | |
1445 os << "i"; | |
1446 } | |
1447 } | |
1448 | |
626 | 1449 static void |
5275 | 1450 print_empty_matrix (std::ostream& os, octave_idx_type nr, octave_idx_type nc, bool pr_as_read_syntax) |
626 | 1451 { |
1452 assert (nr == 0 || nc == 0); | |
1453 | |
1454 if (pr_as_read_syntax) | |
1455 { | |
1456 if (nr == 0 && nc == 0) | |
1457 os << "[]"; | |
1458 else | |
1459 os << "zeros (" << nr << ", " << nc << ")"; | |
1460 } | |
1461 else | |
1462 { | |
1463 os << "[]"; | |
4559 | 1464 |
2165 | 1465 if (Vprint_empty_dimensions) |
626 | 1466 os << "(" << nr << "x" << nc << ")"; |
1467 } | |
1468 } | |
1469 | |
1186 | 1470 static void |
4559 | 1471 print_empty_nd_array (std::ostream& os, const dim_vector& dims, |
1472 bool pr_as_read_syntax) | |
1473 { | |
1474 assert (dims.any_zero ()); | |
1475 | |
1476 if (pr_as_read_syntax) | |
1477 os << "zeros (" << dims.str (',') << ")"; | |
1478 else | |
1479 { | |
1480 os << "[]"; | |
1481 | |
1482 if (Vprint_empty_dimensions) | |
1483 os << "(" << dims.str () << ")"; | |
1484 } | |
1485 } | |
1486 | |
1487 static void | |
3523 | 1488 pr_scale_header (std::ostream& os, double scale) |
3105 | 1489 { |
4509 | 1490 if (Vfixed_point_format && ! print_g && scale != 1.0) |
3105 | 1491 { |
3568 | 1492 os << " " |
1493 << std::setw (8) << std::setprecision (1) | |
1494 << std::setiosflags (std::ios::scientific|std::ios::left) | |
1495 << scale | |
1496 << std::resetiosflags (std::ios::scientific|std::ios::left) | |
1497 << " *\n"; | |
3105 | 1498 |
1499 if (! compact_format) | |
1500 os << "\n"; | |
1501 } | |
1502 } | |
1503 | |
1504 static void | |
5275 | 1505 pr_col_num_header (std::ostream& os, octave_idx_type total_width, int max_width, |
1506 octave_idx_type lim, octave_idx_type col, int extra_indent) | |
1186 | 1507 { |
2165 | 1508 if (total_width > max_width && Vsplit_long_rows) |
1186 | 1509 { |
4833 | 1510 if (col != 0) |
1511 { | |
1512 if (compact_format) | |
1513 os << "\n"; | |
1514 else | |
1515 os << "\n\n"; | |
1516 } | |
1186 | 1517 |
5275 | 1518 octave_idx_type num_cols = lim - col; |
1186 | 1519 |
3548 | 1520 os << std::setw (extra_indent) << ""; |
1972 | 1521 |
1186 | 1522 if (num_cols == 1) |
1523 os << " Column " << col + 1 << ":\n"; | |
1524 else if (num_cols == 2) | |
1525 os << " Columns " << col + 1 << " and " << lim << ":\n"; | |
1526 else | |
1527 os << " Columns " << col + 1 << " through " << lim << ":\n"; | |
2915 | 1528 |
1529 if (! compact_format) | |
1530 os << "\n"; | |
1186 | 1531 } |
1532 } | |
1533 | |
5030 | 1534 template <class T> |
6018 | 1535 /* static */ inline void |
5030 | 1536 pr_plus_format (std::ostream& os, const T& val) |
3248 | 1537 { |
5030 | 1538 if (val > T (0)) |
4632 | 1539 os << plus_format_chars[0]; |
5030 | 1540 else if (val < T (0)) |
4632 | 1541 os << plus_format_chars[1]; |
3248 | 1542 else |
4632 | 1543 os << plus_format_chars[2]; |
3248 | 1544 } |
1545 | |
1 | 1546 void |
4661 | 1547 octave_print_internal (std::ostream& os, double d, |
1548 bool /* pr_as_read_syntax */) | |
1 | 1549 { |
1550 if (plus_format) | |
1551 { | |
3608 | 1552 pr_plus_format (os, d); |
1 | 1553 } |
1554 else | |
1555 { | |
1556 set_format (d); | |
1557 if (free_format) | |
1558 os << d; | |
1559 else | |
1560 pr_float (os, d); | |
1561 } | |
1562 } | |
1563 | |
1564 void | |
3608 | 1565 octave_print_internal (std::ostream& os, const Matrix& m, |
1566 bool pr_as_read_syntax, int extra_indent) | |
1 | 1567 { |
5275 | 1568 octave_idx_type nr = m.rows (); |
1569 octave_idx_type nc = m.columns (); | |
1 | 1570 |
2408 | 1571 if (nr == 0 || nc == 0) |
626 | 1572 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
1573 else if (plus_format && ! pr_as_read_syntax) | |
1 | 1574 { |
5275 | 1575 for (octave_idx_type i = 0; i < nr; i++) |
1 | 1576 { |
5275 | 1577 for (octave_idx_type j = 0; j < nc; j++) |
1 | 1578 { |
4153 | 1579 OCTAVE_QUIT; |
1580 | |
3608 | 1581 pr_plus_format (os, m(i,j)); |
1 | 1582 } |
2907 | 1583 |
1584 if (i < nr - 1) | |
1585 os << "\n"; | |
1 | 1586 } |
1587 } | |
1588 else | |
1589 { | |
1590 int fw; | |
3105 | 1591 double scale = 1.0; |
1592 set_format (m, fw, scale); | |
1 | 1593 int column_width = fw + 2; |
5275 | 1594 octave_idx_type total_width = nc * column_width; |
1595 octave_idx_type max_width = command_editor::terminal_cols (); | |
1 | 1596 |
626 | 1597 if (pr_as_read_syntax) |
1598 max_width -= 4; | |
1972 | 1599 else |
1600 max_width -= extra_indent; | |
1601 | |
1602 if (max_width < 0) | |
1603 max_width = 0; | |
626 | 1604 |
1 | 1605 if (free_format) |
1606 { | |
626 | 1607 if (pr_as_read_syntax) |
1608 os << "[\n"; | |
1609 | |
1 | 1610 os << m; |
626 | 1611 |
1612 if (pr_as_read_syntax) | |
1613 os << "]"; | |
1614 | |
1 | 1615 return; |
1616 } | |
1617 | |
5275 | 1618 octave_idx_type inc = nc; |
2165 | 1619 if (total_width > max_width && Vsplit_long_rows) |
1 | 1620 { |
1621 inc = max_width / column_width; | |
1622 if (inc == 0) | |
1623 inc++; | |
1624 } | |
1625 | |
626 | 1626 if (pr_as_read_syntax) |
1 | 1627 { |
5275 | 1628 for (octave_idx_type i = 0; i < nr; i++) |
1 | 1629 { |
5275 | 1630 octave_idx_type col = 0; |
626 | 1631 while (col < nc) |
1 | 1632 { |
5275 | 1633 octave_idx_type lim = col + inc < nc ? col + inc : nc; |
1634 | |
1635 for (octave_idx_type j = col; j < lim; j++) | |
626 | 1636 { |
4153 | 1637 OCTAVE_QUIT; |
1638 | |
626 | 1639 if (i == 0 && j == 0) |
1640 os << "[ "; | |
1641 else | |
1642 { | |
1643 if (j > col && j < lim) | |
1644 os << ", "; | |
1645 else | |
1646 os << " "; | |
1647 } | |
1648 | |
3608 | 1649 pr_float (os, m(i,j)); |
626 | 1650 } |
1651 | |
1652 col += inc; | |
1653 | |
1654 if (col >= nc) | |
1655 { | |
1656 if (i == nr - 1) | |
1657 os << " ]"; | |
1658 else | |
1659 os << ";\n"; | |
1660 } | |
1661 else | |
1662 os << " ...\n"; | |
1 | 1663 } |
1664 } | |
626 | 1665 } |
1666 else | |
1667 { | |
3105 | 1668 pr_scale_header (os, scale); |
1669 | |
5275 | 1670 for (octave_idx_type col = 0; col < nc; col += inc) |
626 | 1671 { |
5275 | 1672 octave_idx_type lim = col + inc < nc ? col + inc : nc; |
626 | 1673 |
1972 | 1674 pr_col_num_header (os, total_width, max_width, lim, col, |
1675 extra_indent); | |
626 | 1676 |
5275 | 1677 for (octave_idx_type i = 0; i < nr; i++) |
626 | 1678 { |
3548 | 1679 os << std::setw (extra_indent) << ""; |
1972 | 1680 |
5275 | 1681 for (octave_idx_type j = col; j < lim; j++) |
626 | 1682 { |
4153 | 1683 OCTAVE_QUIT; |
1684 | |
626 | 1685 os << " "; |
1686 | |
3608 | 1687 pr_float (os, m(i,j), fw, scale); |
626 | 1688 } |
1689 | |
2907 | 1690 if (i < nr - 1) |
1691 os << "\n"; | |
626 | 1692 } |
1693 } | |
1 | 1694 } |
1695 } | |
1696 } | |
1697 | |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1698 void |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1699 octave_print_internal (std::ostream& os, const DiagMatrix& m, |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1700 bool pr_as_read_syntax, int extra_indent) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1701 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1702 octave_idx_type nr = m.rows (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1703 octave_idx_type nc = m.columns (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1704 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1705 if (nr == 0 || nc == 0) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1706 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1707 else if (plus_format && ! pr_as_read_syntax) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1708 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1709 for (octave_idx_type i = 0; i < nr; i++) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1710 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1711 for (octave_idx_type j = 0; j < nc; j++) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1712 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1713 OCTAVE_QUIT; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1714 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1715 pr_plus_format (os, m(i,j)); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1716 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1717 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1718 if (i < nr - 1) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1719 os << "\n"; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1720 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1721 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1722 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1723 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1724 int fw; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1725 double scale = 1.0; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1726 set_format (Matrix (m.diag ()), fw, scale); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1727 int column_width = fw + 2; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1728 octave_idx_type total_width = nc * column_width; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1729 octave_idx_type max_width = command_editor::terminal_cols (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1730 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1731 if (pr_as_read_syntax) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1732 max_width -= 4; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1733 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1734 max_width -= extra_indent; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1735 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1736 if (max_width < 0) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1737 max_width = 0; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1738 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1739 if (free_format) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1740 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1741 if (pr_as_read_syntax) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1742 os << "[\n"; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1743 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1744 os << Matrix (m); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1745 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1746 if (pr_as_read_syntax) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1747 os << "]"; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1748 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1749 return; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1750 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1751 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1752 octave_idx_type inc = nc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1753 if (total_width > max_width && Vsplit_long_rows) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1754 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1755 inc = max_width / column_width; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1756 if (inc == 0) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1757 inc++; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1758 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1759 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1760 if (pr_as_read_syntax) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1761 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1762 os << "diag ("; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1763 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1764 octave_idx_type col = 0; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1765 while (col < nc) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1766 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1767 octave_idx_type lim = col + inc < nc ? col + inc : nc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1768 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1769 for (octave_idx_type j = col; j < lim; j++) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1770 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1771 OCTAVE_QUIT; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1772 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1773 if (j == 0) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1774 os << "[ "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1775 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1776 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1777 if (j > col && j < lim) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1778 os << ", "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1779 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1780 os << " "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1781 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1782 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1783 pr_float (os, m(j,j)); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1784 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1785 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1786 col += inc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1787 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1788 if (col >= nc) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1789 os << " ]"; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1790 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1791 os << " ...\n"; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1792 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1793 os << ")"; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1794 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1795 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1796 { |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
1797 os << "Diagonal Matrix\n\n"; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1798 pr_scale_header (os, scale); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1799 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1800 // kluge. Get the true width of a number. |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1801 int zero_fw; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1802 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1803 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1804 std::ostringstream tmp_oss; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1805 pr_float (tmp_oss, 0.0, fw, scale); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1806 zero_fw = tmp_oss.str ().length (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1807 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1808 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1809 for (octave_idx_type col = 0; col < nc; col += inc) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1810 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1811 octave_idx_type lim = col + inc < nc ? col + inc : nc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1812 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1813 pr_col_num_header (os, total_width, max_width, lim, col, |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1814 extra_indent); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1815 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1816 for (octave_idx_type i = 0; i < nr; i++) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1817 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1818 os << std::setw (extra_indent) << ""; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1819 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1820 for (octave_idx_type j = col; j < lim; j++) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1821 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1822 OCTAVE_QUIT; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1823 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1824 os << " "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1825 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1826 if (i == j) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1827 pr_float (os, m(i,j), fw, scale); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1828 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1829 os << std::setw (zero_fw) << '0'; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1830 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1831 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1832 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1833 if (i < nr - 1) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1834 os << "\n"; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1835 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1836 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1837 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1838 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1839 } |
4532 | 1840 #define PRINT_ND_ARRAY(os, nda, NDA_T, ELT_T, MAT_T) \ |
1841 do \ | |
1842 { \ | |
4559 | 1843 if (nda.is_empty ()) \ |
1844 print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); \ | |
1845 else \ | |
1846 { \ | |
4532 | 1847 \ |
4559 | 1848 int ndims = nda.ndims (); \ |
1849 \ | |
1850 dim_vector dims = nda.dims (); \ | |
4532 | 1851 \ |
5275 | 1852 Array<octave_idx_type> ra_idx (ndims, 0); \ |
4532 | 1853 \ |
5275 | 1854 octave_idx_type m = 1; \ |
4532 | 1855 \ |
4559 | 1856 for (int i = 2; i < ndims; i++) \ |
1857 m *= dims(i); \ | |
1858 \ | |
5275 | 1859 octave_idx_type nr = dims(0); \ |
1860 octave_idx_type nc = dims(1); \ | |
4532 | 1861 \ |
5275 | 1862 for (octave_idx_type i = 0; i < m; i++) \ |
4559 | 1863 { \ |
4655 | 1864 OCTAVE_QUIT; \ |
1865 \ | |
4559 | 1866 std::string nm = "ans"; \ |
4532 | 1867 \ |
4559 | 1868 if (m > 1) \ |
1869 { \ | |
1870 nm += "(:,:,"; \ | |
4532 | 1871 \ |
5765 | 1872 std::ostringstream buf; \ |
4532 | 1873 \ |
4559 | 1874 for (int k = 2; k < ndims; k++) \ |
1875 { \ | |
1876 buf << ra_idx(k) + 1; \ | |
4532 | 1877 \ |
4559 | 1878 if (k < ndims - 1) \ |
1879 buf << ","; \ | |
1880 else \ | |
1881 buf << ")"; \ | |
1882 } \ | |
4532 | 1883 \ |
5765 | 1884 nm += buf.str (); \ |
4559 | 1885 } \ |
4532 | 1886 \ |
4559 | 1887 Array<idx_vector> idx (ndims); \ |
4532 | 1888 \ |
4559 | 1889 idx(0) = idx_vector (':'); \ |
1890 idx(1) = idx_vector (':'); \ | |
1891 \ | |
1892 for (int k = 2; k < ndims; k++) \ | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1893 idx(k) = idx_vector (ra_idx(k)); \ |
4532 | 1894 \ |
4559 | 1895 octave_value page \ |
1896 = MAT_T (Array2<ELT_T> (nda.index (idx), nr, nc)); \ | |
1897 \ | |
1898 page.print_with_name (os, nm); \ | |
4532 | 1899 \ |
4559 | 1900 if (i < m) \ |
1901 NDA_T::increment_index (ra_idx, dims, 2); \ | |
1902 } \ | |
1903 } \ | |
4532 | 1904 } \ |
1905 while (0) | |
1906 | |
4513 | 1907 void |
1908 octave_print_internal (std::ostream& os, const NDArray& nda, | |
1909 bool pr_as_read_syntax, int extra_indent) | |
1910 { | |
1911 switch (nda.ndims ()) | |
1912 { | |
1913 case 1: | |
1914 case 2: | |
1915 octave_print_internal (os, nda.matrix_value (), | |
1916 pr_as_read_syntax, extra_indent); | |
1917 break; | |
1918 | |
1919 default: | |
4532 | 1920 PRINT_ND_ARRAY (os, nda, NDArray, double, Matrix); |
4513 | 1921 break; |
1922 } | |
1923 } | |
1924 | |
5030 | 1925 template <> |
6018 | 1926 /* static */ inline void |
6015 | 1927 pr_plus_format<> (std::ostream& os, const Complex& c) |
3248 | 1928 { |
1929 double rp = c.real (); | |
1930 double ip = c.imag (); | |
1931 | |
1932 if (rp == 0.0) | |
1933 { | |
1934 if (ip == 0.0) | |
1935 os << " "; | |
1936 else | |
1937 os << "i"; | |
1938 } | |
1939 else if (ip == 0.0) | |
3608 | 1940 pr_plus_format (os, rp); |
3248 | 1941 else |
1942 os << "c"; | |
1943 } | |
1944 | |
1 | 1945 void |
3523 | 1946 octave_print_internal (std::ostream& os, const Complex& c, |
4661 | 1947 bool /* pr_as_read_syntax */) |
1 | 1948 { |
1949 if (plus_format) | |
1950 { | |
3608 | 1951 pr_plus_format (os, c); |
1 | 1952 } |
1953 else | |
1954 { | |
1955 set_format (c); | |
1956 if (free_format) | |
1957 os << c; | |
1958 else | |
1959 pr_complex (os, c); | |
1960 } | |
1961 } | |
1962 | |
1963 void | |
3523 | 1964 octave_print_internal (std::ostream& os, const ComplexMatrix& cm, |
1972 | 1965 bool pr_as_read_syntax, int extra_indent) |
1 | 1966 { |
5275 | 1967 octave_idx_type nr = cm.rows (); |
1968 octave_idx_type nc = cm.columns (); | |
1 | 1969 |
2408 | 1970 if (nr == 0 || nc == 0) |
626 | 1971 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
1972 else if (plus_format && ! pr_as_read_syntax) | |
1 | 1973 { |
5275 | 1974 for (octave_idx_type i = 0; i < nr; i++) |
1 | 1975 { |
5275 | 1976 for (octave_idx_type j = 0; j < nc; j++) |
1 | 1977 { |
4153 | 1978 OCTAVE_QUIT; |
1979 | |
3608 | 1980 pr_plus_format (os, cm(i,j)); |
1 | 1981 } |
2907 | 1982 |
1983 if (i < nr - 1) | |
1984 os << "\n"; | |
1 | 1985 } |
1986 } | |
1987 else | |
1988 { | |
1989 int r_fw, i_fw; | |
3105 | 1990 double scale = 1.0; |
1991 set_format (cm, r_fw, i_fw, scale); | |
1 | 1992 int column_width = i_fw + r_fw; |
6788 | 1993 column_width += (rat_format || bank_format || hex_format |
1994 || bit_format) ? 2 : 7; | |
5275 | 1995 octave_idx_type total_width = nc * column_width; |
1996 octave_idx_type max_width = command_editor::terminal_cols (); | |
1 | 1997 |
626 | 1998 if (pr_as_read_syntax) |
1999 max_width -= 4; | |
1972 | 2000 else |
2001 max_width -= extra_indent; | |
2002 | |
2003 if (max_width < 0) | |
2004 max_width = 0; | |
626 | 2005 |
1 | 2006 if (free_format) |
2007 { | |
626 | 2008 if (pr_as_read_syntax) |
2009 os << "[\n"; | |
2010 | |
1 | 2011 os << cm; |
626 | 2012 |
2013 if (pr_as_read_syntax) | |
2014 os << "]"; | |
2015 | |
1 | 2016 return; |
2017 } | |
2018 | |
5275 | 2019 octave_idx_type inc = nc; |
2165 | 2020 if (total_width > max_width && Vsplit_long_rows) |
1 | 2021 { |
2022 inc = max_width / column_width; | |
2023 if (inc == 0) | |
2024 inc++; | |
2025 } | |
2026 | |
626 | 2027 if (pr_as_read_syntax) |
1 | 2028 { |
5275 | 2029 for (octave_idx_type i = 0; i < nr; i++) |
1 | 2030 { |
5275 | 2031 octave_idx_type col = 0; |
626 | 2032 while (col < nc) |
1 | 2033 { |
5275 | 2034 octave_idx_type lim = col + inc < nc ? col + inc : nc; |
2035 | |
2036 for (octave_idx_type j = col; j < lim; j++) | |
626 | 2037 { |
4153 | 2038 OCTAVE_QUIT; |
2039 | |
626 | 2040 if (i == 0 && j == 0) |
2041 os << "[ "; | |
2042 else | |
2043 { | |
2044 if (j > col && j < lim) | |
2045 os << ", "; | |
2046 else | |
2047 os << " "; | |
2048 } | |
2049 | |
3608 | 2050 pr_complex (os, cm(i,j)); |
626 | 2051 } |
2052 | |
2053 col += inc; | |
2054 | |
2055 if (col >= nc) | |
2056 { | |
2057 if (i == nr - 1) | |
2058 os << " ]"; | |
2059 else | |
2060 os << ";\n"; | |
2061 } | |
1 | 2062 else |
626 | 2063 os << " ...\n"; |
1 | 2064 } |
2065 } | |
626 | 2066 } |
2067 else | |
2068 { | |
3105 | 2069 pr_scale_header (os, scale); |
2070 | |
5275 | 2071 for (octave_idx_type col = 0; col < nc; col += inc) |
626 | 2072 { |
5275 | 2073 octave_idx_type lim = col + inc < nc ? col + inc : nc; |
626 | 2074 |
1972 | 2075 pr_col_num_header (os, total_width, max_width, lim, col, |
2076 extra_indent); | |
626 | 2077 |
5275 | 2078 for (octave_idx_type i = 0; i < nr; i++) |
626 | 2079 { |
3548 | 2080 os << std::setw (extra_indent) << ""; |
1972 | 2081 |
5275 | 2082 for (octave_idx_type j = col; j < lim; j++) |
626 | 2083 { |
4153 | 2084 OCTAVE_QUIT; |
2085 | |
626 | 2086 os << " "; |
2087 | |
3608 | 2088 pr_complex (os, cm(i,j), r_fw, i_fw, scale); |
626 | 2089 } |
2907 | 2090 |
2091 if (i < nr - 1) | |
2092 os << "\n"; | |
626 | 2093 } |
2094 } | |
1 | 2095 } |
2096 } | |
2097 } | |
2098 | |
2099 void | |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2100 octave_print_internal (std::ostream& os, const ComplexDiagMatrix& cm, |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2101 bool pr_as_read_syntax, int extra_indent) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2102 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2103 octave_idx_type nr = cm.rows (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2104 octave_idx_type nc = cm.columns (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2105 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2106 if (nr == 0 || nc == 0) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2107 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2108 else if (plus_format && ! pr_as_read_syntax) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2109 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2110 for (octave_idx_type i = 0; i < nr; i++) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2111 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2112 for (octave_idx_type j = 0; j < nc; j++) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2113 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2114 OCTAVE_QUIT; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2115 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2116 pr_plus_format (os, cm(i,j)); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2117 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2118 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2119 if (i < nr - 1) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2120 os << "\n"; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2121 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2122 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2123 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2124 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2125 int r_fw, i_fw; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2126 double scale = 1.0; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2127 set_format (ComplexMatrix (cm.diag ()), r_fw, i_fw, scale); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2128 int column_width = i_fw + r_fw; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2129 column_width += (rat_format || bank_format || hex_format |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2130 || bit_format) ? 2 : 7; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2131 octave_idx_type total_width = nc * column_width; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2132 octave_idx_type max_width = command_editor::terminal_cols (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2133 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2134 if (pr_as_read_syntax) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2135 max_width -= 4; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2136 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2137 max_width -= extra_indent; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2138 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2139 if (max_width < 0) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2140 max_width = 0; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2141 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2142 if (free_format) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2143 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2144 if (pr_as_read_syntax) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2145 os << "[\n"; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2146 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2147 os << ComplexMatrix (cm); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2148 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2149 if (pr_as_read_syntax) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2150 os << "]"; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2151 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2152 return; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2153 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2154 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2155 octave_idx_type inc = nc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2156 if (total_width > max_width && Vsplit_long_rows) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2157 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2158 inc = max_width / column_width; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2159 if (inc == 0) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2160 inc++; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2161 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2162 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2163 if (pr_as_read_syntax) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2164 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2165 os << "diag ("; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2166 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2167 octave_idx_type col = 0; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2168 while (col < nc) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2169 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2170 octave_idx_type lim = col + inc < nc ? col + inc : nc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2171 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2172 for (octave_idx_type j = col; j < lim; j++) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2173 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2174 OCTAVE_QUIT; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2175 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2176 if (j == 0) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2177 os << "[ "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2178 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2179 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2180 if (j > col && j < lim) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2181 os << ", "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2182 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2183 os << " "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2184 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2185 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2186 pr_complex (os, cm(j,j)); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2187 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2188 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2189 col += inc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2190 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2191 if (col >= nc) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2192 os << " ]"; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2193 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2194 os << " ...\n"; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2195 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2196 os << ")"; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2197 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2198 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2199 { |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2200 os << "Diagonal Matrix\n\n"; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2201 pr_scale_header (os, scale); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2202 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2203 // kluge. Get the true width of a number. |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2204 int zero_fw; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2205 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2206 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2207 std::ostringstream tmp_oss; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2208 pr_complex (tmp_oss, Complex (0.0), r_fw, i_fw, scale); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2209 zero_fw = tmp_oss.str ().length (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2210 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2211 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2212 for (octave_idx_type col = 0; col < nc; col += inc) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2213 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2214 octave_idx_type lim = col + inc < nc ? col + inc : nc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2215 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2216 pr_col_num_header (os, total_width, max_width, lim, col, |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2217 extra_indent); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2218 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2219 for (octave_idx_type i = 0; i < nr; i++) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2220 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2221 os << std::setw (extra_indent) << ""; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2222 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2223 for (octave_idx_type j = col; j < lim; j++) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2224 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2225 OCTAVE_QUIT; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2226 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2227 os << " "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2228 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2229 if (i == j) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2230 pr_complex (os, cm(i,j), r_fw, i_fw, scale); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2231 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2232 os << std::setw (zero_fw) << '0'; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2233 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2234 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2235 if (i < nr - 1) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2236 os << "\n"; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2237 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2238 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2239 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2240 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2241 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2242 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2243 void |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2244 octave_print_internal (std::ostream& os, const PermMatrix& m, |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2245 bool pr_as_read_syntax, int extra_indent) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2246 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2247 octave_idx_type nr = m.rows (); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2248 octave_idx_type nc = m.columns (); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2249 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2250 if (nr == 0 || nc == 0) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2251 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2252 else if (plus_format && ! pr_as_read_syntax) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2253 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2254 for (octave_idx_type i = 0; i < nr; i++) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2255 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2256 for (octave_idx_type j = 0; j < nc; j++) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2257 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2258 OCTAVE_QUIT; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2259 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2260 pr_plus_format (os, m(i,j)); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2261 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2262 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2263 if (i < nr - 1) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2264 os << "\n"; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2265 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2266 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2267 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2268 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2269 int fw = 2; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2270 int column_width = fw + 2; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2271 octave_idx_type total_width = nc * column_width; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2272 octave_idx_type max_width = command_editor::terminal_cols (); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2273 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2274 if (pr_as_read_syntax) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2275 max_width -= 4; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2276 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2277 max_width -= extra_indent; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2278 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2279 if (max_width < 0) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2280 max_width = 0; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2281 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2282 if (free_format) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2283 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2284 if (pr_as_read_syntax) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2285 os << "[\n"; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2286 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2287 os << Matrix (m); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2288 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2289 if (pr_as_read_syntax) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2290 os << "]"; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2291 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2292 return; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2293 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2294 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2295 octave_idx_type inc = nc; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2296 if (total_width > max_width && Vsplit_long_rows) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2297 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2298 inc = max_width / column_width; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2299 if (inc == 0) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2300 inc++; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2301 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2302 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2303 if (pr_as_read_syntax) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2304 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2305 Array<octave_idx_type> pvec = m.pvec (); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2306 bool colp = m.is_col_perm (); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2307 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2308 os << "eye ("; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2309 if (colp) os << ":, "; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2310 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2311 octave_idx_type col = 0; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2312 while (col < nc) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2313 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2314 octave_idx_type lim = col + inc < nc ? col + inc : nc; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2315 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2316 for (octave_idx_type j = col; j < lim; j++) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2317 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2318 OCTAVE_QUIT; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2319 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2320 if (j == 0) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2321 os << "[ "; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2322 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2323 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2324 if (j > col && j < lim) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2325 os << ", "; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2326 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2327 os << " "; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2328 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2329 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2330 os << pvec (j); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2331 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2332 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2333 col += inc; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2334 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2335 if (col >= nc) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2336 os << " ]"; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2337 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2338 os << " ...\n"; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2339 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2340 if (! colp) os << ", :"; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2341 os << ")"; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2342 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2343 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2344 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2345 os << "Permutation Matrix\n\n"; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2346 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2347 for (octave_idx_type col = 0; col < nc; col += inc) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2348 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2349 octave_idx_type lim = col + inc < nc ? col + inc : nc; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2350 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2351 pr_col_num_header (os, total_width, max_width, lim, col, |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2352 extra_indent); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2353 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2354 for (octave_idx_type i = 0; i < nr; i++) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2355 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2356 os << std::setw (extra_indent) << ""; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2357 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2358 for (octave_idx_type j = col; j < lim; j++) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2359 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2360 OCTAVE_QUIT; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2361 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2362 os << " "; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2363 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2364 os << std::setw (fw) << m(i,j); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2365 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2366 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2367 if (i < nr - 1) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2368 os << "\n"; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2369 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2370 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2371 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2372 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2373 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2374 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2375 void |
4513 | 2376 octave_print_internal (std::ostream& os, const ComplexNDArray& nda, |
2377 bool pr_as_read_syntax, int extra_indent) | |
2378 { | |
2379 switch (nda.ndims ()) | |
2380 { | |
2381 case 1: | |
2382 case 2: | |
2383 octave_print_internal (os, nda.matrix_value (), | |
2384 pr_as_read_syntax, extra_indent); | |
2385 break; | |
2386 | |
2387 default: | |
4532 | 2388 PRINT_ND_ARRAY (os, nda, ComplexNDArray, Complex, ComplexMatrix); |
4513 | 2389 break; |
2390 } | |
2391 } | |
2392 | |
2393 void | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2394 octave_print_internal (std::ostream& os, bool d, bool pr_as_read_syntax) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2395 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2396 octave_print_internal (os, double (d), pr_as_read_syntax); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2397 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2398 |
8333 | 2399 // FIXME -- write single precision versions of the printing functions. |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2400 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2401 void |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2402 octave_print_internal (std::ostream& os, float d, bool pr_as_read_syntax) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2403 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2404 octave_print_internal (os, double (d), pr_as_read_syntax); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2405 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2406 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2407 void |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2408 octave_print_internal (std::ostream& os, const FloatMatrix& m, |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2409 bool pr_as_read_syntax, int extra_indent) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2410 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2411 octave_print_internal (os, Matrix (m), pr_as_read_syntax, extra_indent); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2412 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2413 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2414 void |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2415 octave_print_internal (std::ostream& os, const FloatDiagMatrix& m, |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2416 bool pr_as_read_syntax, int extra_indent) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2417 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2418 octave_print_internal (os, DiagMatrix (m), pr_as_read_syntax, extra_indent); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2419 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2420 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2421 void |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2422 octave_print_internal (std::ostream& os, const FloatNDArray& nda, |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2423 bool pr_as_read_syntax, int extra_indent) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2424 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2425 octave_print_internal (os, NDArray (nda), pr_as_read_syntax, extra_indent); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2426 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2427 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2428 void |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2429 octave_print_internal (std::ostream& os, const FloatComplex& c, |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2430 bool pr_as_read_syntax) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2431 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2432 octave_print_internal (os, Complex (c), pr_as_read_syntax); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2433 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2434 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2435 void |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2436 octave_print_internal (std::ostream& os, const FloatComplexMatrix& cm, |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2437 bool pr_as_read_syntax, int extra_indent) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2438 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2439 octave_print_internal (os, ComplexMatrix (cm), pr_as_read_syntax, extra_indent); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2440 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2441 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2442 void |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2443 octave_print_internal (std::ostream& os, const FloatComplexDiagMatrix& cm, |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2444 bool pr_as_read_syntax, int extra_indent) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2445 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2446 octave_print_internal (os, ComplexDiagMatrix (cm), pr_as_read_syntax, extra_indent); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2447 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2448 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2449 void |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2450 octave_print_internal (std::ostream& os, const FloatComplexNDArray& nda, |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2451 bool pr_as_read_syntax, int extra_indent) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2452 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2453 octave_print_internal (os, ComplexNDArray (nda), pr_as_read_syntax, extra_indent); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2454 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2455 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2456 void |
3523 | 2457 octave_print_internal (std::ostream& os, const Range& r, |
1972 | 2458 bool pr_as_read_syntax, int extra_indent) |
1 | 2459 { |
626 | 2460 double base = r.base (); |
1 | 2461 double increment = r.inc (); |
626 | 2462 double limit = r.limit (); |
5275 | 2463 octave_idx_type num_elem = r.nelem (); |
1 | 2464 |
626 | 2465 if (plus_format && ! pr_as_read_syntax) |
1 | 2466 { |
5275 | 2467 for (octave_idx_type i = 0; i < num_elem; i++) |
1 | 2468 { |
4153 | 2469 OCTAVE_QUIT; |
2470 | |
626 | 2471 double val = base + i * increment; |
4632 | 2472 |
2473 pr_plus_format (os, val); | |
1 | 2474 } |
2475 } | |
2476 else | |
2477 { | |
2478 int fw; | |
3105 | 2479 double scale = 1.0; |
2480 set_format (r, fw, scale); | |
1 | 2481 |
626 | 2482 if (pr_as_read_syntax) |
1 | 2483 { |
626 | 2484 if (free_format) |
2485 { | |
2486 os << base << " : "; | |
2487 if (increment != 1.0) | |
2488 os << increment << " : "; | |
2489 os << limit; | |
2490 } | |
2491 else | |
2492 { | |
2493 pr_float (os, base, fw); | |
2494 os << " : "; | |
2495 if (increment != 1.0) | |
2496 { | |
2497 pr_float (os, increment, fw); | |
2498 os << " : "; | |
2499 } | |
2500 pr_float (os, limit, fw); | |
2501 } | |
1 | 2502 } |
626 | 2503 else |
2504 { | |
2505 int column_width = fw + 2; | |
5275 | 2506 octave_idx_type total_width = num_elem * column_width; |
2507 octave_idx_type max_width = command_editor::terminal_cols (); | |
1 | 2508 |
626 | 2509 if (free_format) |
2510 { | |
2511 os << r; | |
2512 return; | |
2513 } | |
1 | 2514 |
5275 | 2515 octave_idx_type inc = num_elem; |
2165 | 2516 if (total_width > max_width && Vsplit_long_rows) |
1 | 2517 { |
626 | 2518 inc = max_width / column_width; |
2519 if (inc == 0) | |
2520 inc++; | |
1 | 2521 } |
2522 | |
1972 | 2523 max_width -= extra_indent; |
2524 | |
2525 if (max_width < 0) | |
2526 max_width = 0; | |
2527 | |
3105 | 2528 pr_scale_header (os, scale); |
2529 | |
5275 | 2530 octave_idx_type col = 0; |
626 | 2531 while (col < num_elem) |
1 | 2532 { |
5275 | 2533 octave_idx_type lim = col + inc < num_elem ? col + inc : num_elem; |
626 | 2534 |
1972 | 2535 pr_col_num_header (os, total_width, max_width, lim, col, |
2536 extra_indent); | |
2537 | |
3548 | 2538 os << std::setw (extra_indent) << ""; |
626 | 2539 |
5275 | 2540 for (octave_idx_type i = col; i < lim; i++) |
626 | 2541 { |
4153 | 2542 OCTAVE_QUIT; |
2543 | |
626 | 2544 double val = base + i * increment; |
3105 | 2545 |
4791 | 2546 if (i == num_elem - 1) |
2547 { | |
2548 // See the comments in Range::matrix_value. | |
2549 | |
2550 if ((increment > 0 && val > limit) | |
2551 || (increment < 0 && val < limit)) | |
2552 val = limit; | |
2553 } | |
2554 | |
626 | 2555 os << " "; |
3105 | 2556 |
3608 | 2557 pr_float (os, val, fw, scale); |
626 | 2558 } |
2559 | |
2907 | 2560 col += inc; |
1 | 2561 } |
2562 } | |
2563 } | |
2564 } | |
2565 | |
1343 | 2566 void |
3523 | 2567 octave_print_internal (std::ostream& os, const boolMatrix& bm, |
3215 | 2568 bool pr_as_read_syntax, |
2569 int extra_indent) | |
2570 { | |
2571 Matrix tmp (bm); | |
2572 octave_print_internal (os, tmp, pr_as_read_syntax, extra_indent); | |
2573 } | |
2574 | |
2575 void | |
4513 | 2576 octave_print_internal (std::ostream& os, const boolNDArray& nda, |
2577 bool pr_as_read_syntax, | |
2578 int extra_indent) | |
2579 { | |
2580 switch (nda.ndims ()) | |
2581 { | |
2582 case 1: | |
2583 case 2: | |
2584 octave_print_internal (os, nda.matrix_value (), | |
2585 pr_as_read_syntax, extra_indent); | |
2586 break; | |
2587 | |
2588 default: | |
4532 | 2589 PRINT_ND_ARRAY (os, nda, boolNDArray, bool, boolMatrix); |
4513 | 2590 break; |
2591 } | |
2592 } | |
2593 | |
2594 void | |
3523 | 2595 octave_print_internal (std::ostream& os, const charMatrix& chm, |
3215 | 2596 bool pr_as_read_syntax, |
5775 | 2597 int /* extra_indent FIXME */, |
3215 | 2598 bool pr_as_string) |
1343 | 2599 { |
1572 | 2600 if (pr_as_string) |
2601 { | |
5275 | 2602 octave_idx_type nstr = chm.rows (); |
1343 | 2603 |
1572 | 2604 if (pr_as_read_syntax && nstr > 1) |
2605 os << "[ "; | |
1343 | 2606 |
2907 | 2607 if (nstr != 0) |
1343 | 2608 { |
5275 | 2609 for (octave_idx_type i = 0; i < nstr; i++) |
1572 | 2610 { |
4153 | 2611 OCTAVE_QUIT; |
2612 | |
3523 | 2613 std::string row = chm.row_as_string (i); |
2664 | 2614 |
2615 if (pr_as_read_syntax) | |
2616 { | |
2617 os << "\"" << undo_string_escapes (row) << "\""; | |
1343 | 2618 |
2664 | 2619 if (i < nstr - 1) |
2620 os << "; "; | |
2621 } | |
2622 else | |
2907 | 2623 { |
2624 os << row; | |
2625 | |
2626 if (i < nstr - 1) | |
2627 os << "\n"; | |
2628 } | |
1572 | 2629 } |
1343 | 2630 } |
1572 | 2631 |
2632 if (pr_as_read_syntax && nstr > 1) | |
2633 os << " ]"; | |
1343 | 2634 } |
1572 | 2635 else |
2636 { | |
2637 os << "sorry, printing char matrices not implemented yet\n"; | |
2638 } | |
1343 | 2639 } |
2640 | |
4513 | 2641 void |
2642 octave_print_internal (std::ostream& os, const charNDArray& nda, | |
4663 | 2643 bool pr_as_read_syntax, int extra_indent, |
4513 | 2644 bool pr_as_string) |
2645 { | |
2646 switch (nda.ndims ()) | |
2647 { | |
2648 case 1: | |
2649 case 2: | |
2650 octave_print_internal (os, nda.matrix_value (), | |
2651 pr_as_read_syntax, extra_indent, pr_as_string); | |
2652 break; | |
2653 | |
2654 default: | |
4532 | 2655 PRINT_ND_ARRAY (os, nda, charNDArray, char, charMatrix); |
4513 | 2656 break; |
2657 } | |
2658 } | |
2659 | |
4655 | 2660 void |
4925 | 2661 octave_print_internal (std::ostream& os, const std::string& s, |
2662 bool pr_as_read_syntax, int extra_indent) | |
2663 { | |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9643
diff
changeset
|
2664 Array<std::string> nda (dim_vector (1, 1), s); |
4925 | 2665 |
2666 octave_print_internal (os, nda, pr_as_read_syntax, extra_indent); | |
2667 } | |
2668 | |
2669 void | |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9643
diff
changeset
|
2670 octave_print_internal (std::ostream& os, const Array<std::string>& nda, |
4663 | 2671 bool pr_as_read_syntax, int /* extra_indent */) |
4655 | 2672 { |
5775 | 2673 // FIXME -- this mostly duplicates the code in the |
4655 | 2674 // PRINT_ND_ARRAY macro. |
2675 | |
2676 if (nda.is_empty ()) | |
2677 print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); | |
2678 else if (nda.length () == 1) | |
2679 { | |
2680 os << nda(0); | |
2681 } | |
2682 else | |
2683 { | |
2684 int ndims = nda.ndims (); | |
2685 | |
2686 dim_vector dims = nda.dims (); | |
2687 | |
5275 | 2688 Array<octave_idx_type> ra_idx (ndims, 0); |
2689 | |
2690 octave_idx_type m = 1; | |
4655 | 2691 |
2692 for (int i = 2; i < ndims; i++) | |
2693 m *= dims(i); | |
2694 | |
5275 | 2695 octave_idx_type nr = dims(0); |
2696 octave_idx_type nc = dims(1); | |
2697 | |
2698 for (octave_idx_type i = 0; i < m; i++) | |
4655 | 2699 { |
2700 std::string nm = "ans"; | |
2701 | |
2702 if (m > 1) | |
2703 { | |
2704 nm += "(:,:,"; | |
2705 | |
5765 | 2706 std::ostringstream buf; |
4655 | 2707 |
2708 for (int k = 2; k < ndims; k++) | |
2709 { | |
2710 buf << ra_idx(k) + 1; | |
2711 | |
2712 if (k < ndims - 1) | |
2713 buf << ","; | |
2714 else | |
2715 buf << ")"; | |
2716 } | |
2717 | |
5765 | 2718 nm += buf.str (); |
4655 | 2719 } |
2720 | |
2721 Array<idx_vector> idx (ndims); | |
2722 | |
2723 idx(0) = idx_vector (':'); | |
2724 idx(1) = idx_vector (':'); | |
2725 | |
2726 for (int k = 2; k < ndims; k++) | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
2727 idx(k) = idx_vector (ra_idx(k)); |
4655 | 2728 |
2729 Array2<std::string> page (nda.index (idx), nr, nc); | |
2730 | |
5775 | 2731 // FIXME -- need to do some more work to put these |
4655 | 2732 // in neatly aligned columns... |
2733 | |
5275 | 2734 octave_idx_type n_rows = page.rows (); |
2735 octave_idx_type n_cols = page.cols (); | |
4655 | 2736 |
2737 os << nm << " =\n\n"; | |
2738 | |
5275 | 2739 for (octave_idx_type ii = 0; ii < n_rows; ii++) |
4655 | 2740 { |
5275 | 2741 for (octave_idx_type jj = 0; jj < n_cols; jj++) |
4655 | 2742 os << " " << page(ii,jj); |
2743 | |
2744 os << "\n"; | |
2745 } | |
2746 | |
2747 if (i < m - 1) | |
2748 os << "\n"; | |
2749 | |
2750 if (i < m) | |
2751 increment_index (ra_idx, dims, 2); | |
2752 } | |
2753 } | |
2754 } | |
2755 | |
4901 | 2756 template <class T> |
2757 class | |
2758 octave_print_conv | |
2759 { | |
2760 public: | |
2761 typedef T print_conv_type; | |
2762 }; | |
2763 | |
2764 #define PRINT_CONV(T1, T2) \ | |
2765 template <> \ | |
2766 class \ | |
2767 octave_print_conv<T1> \ | |
2768 { \ | |
2769 public: \ | |
2770 typedef T2 print_conv_type; \ | |
2771 } | |
2772 | |
2773 PRINT_CONV (octave_int8, octave_int16); | |
2774 PRINT_CONV (octave_uint8, octave_uint16); | |
2775 | |
2776 #undef PRINT_CONV | |
2777 | |
2778 template <class T> | |
6018 | 2779 /* static */ inline void |
4949 | 2780 pr_int (std::ostream& os, const T& d, int fw = 0) |
2781 { | |
2782 size_t sz = d.byte_size(); | |
2783 const unsigned char * tmpi = d.iptr(); | |
2784 | |
5544 | 2785 // Unless explicitly asked for, always print in big-endian |
2786 // format for hex and bit formats. | |
2787 // | |
2788 // {bit,hex}_format == 1: print big-endian | |
2789 // {bit,hex}_format == 2: print native | |
2790 | |
4949 | 2791 if (hex_format) |
2792 { | |
2793 char ofill = os.fill ('0'); | |
2794 | |
2795 std::ios::fmtflags oflags | |
2796 = os.flags (std::ios::right | std::ios::hex); | |
2797 | |
2798 if (hex_format > 1 || oct_mach_info::words_big_endian ()) | |
2799 { | |
2800 for (size_t i = 0; i < sz; i++) | |
2801 os << std::setw (2) << static_cast<int> (tmpi[i]); | |
2802 } | |
2803 else | |
2804 { | |
2805 for (int i = sz - 1; i >= 0; i--) | |
2806 os << std::setw (2) << static_cast<int> (tmpi[i]); | |
2807 } | |
2808 | |
2809 os.fill (ofill); | |
2810 os.setf (oflags); | |
2811 } | |
2812 else if (bit_format) | |
2813 { | |
5544 | 2814 if (oct_mach_info::words_big_endian ()) |
4949 | 2815 { |
2816 for (size_t i = 0; i < sz; i++) | |
5544 | 2817 PRINT_CHAR_BITS (os, tmpi[i]); |
4949 | 2818 } |
2819 else | |
2820 { | |
5544 | 2821 if (bit_format > 1) |
2822 { | |
2823 for (size_t i = 0; i < sz; i++) | |
2824 PRINT_CHAR_BITS_SWAPPED (os, tmpi[i]); | |
2825 } | |
2826 else | |
2827 { | |
2828 for (int i = sz - 1; i >= 0; i--) | |
2829 PRINT_CHAR_BITS (os, tmpi[i]); | |
2830 } | |
4949 | 2831 } |
2832 } | |
2833 else | |
2834 { | |
2835 os << std::setw (fw) | |
2836 << typename octave_print_conv<T>::print_conv_type (d); | |
2837 | |
2838 if (bank_format) | |
2839 os << ".00"; | |
2840 } | |
2841 } | |
2842 | |
6120 | 2843 // FIXME -- all this mess with abs is an attempt to avoid seeing |
2844 // | |
2845 // warning: comparison of unsigned expression < 0 is always false | |
2846 // | |
2847 // from GCC. Isn't there a better way | |
2848 | |
4949 | 2849 template <class T> |
6018 | 2850 /* static */ inline T |
6008 | 2851 abs (T x) |
2852 { | |
6120 | 2853 return x < 0 ? -x : x; |
6008 | 2854 } |
2855 | |
6120 | 2856 #define INSTANTIATE_ABS(T) \ |
2857 template /* static */ inline T abs (T) | |
2858 | |
2859 INSTANTIATE_ABS(signed char); | |
2860 INSTANTIATE_ABS(short); | |
2861 INSTANTIATE_ABS(int); | |
2862 INSTANTIATE_ABS(long); | |
2863 INSTANTIATE_ABS(long long); | |
2864 | |
2865 #define SPECIALIZE_UABS(T) \ | |
2866 template <> \ | |
2867 /* static */ inline unsigned T \ | |
2868 abs (unsigned T x) \ | |
2869 { \ | |
2870 return x; \ | |
2871 } | |
2872 | |
2873 SPECIALIZE_UABS(char) | |
2874 SPECIALIZE_UABS(short) | |
2875 SPECIALIZE_UABS(int) | |
2876 SPECIALIZE_UABS(long) | |
2877 SPECIALIZE_UABS(long long) | |
6008 | 2878 |
7215 | 2879 template void |
2880 pr_int (std::ostream&, const octave_int8&, int); | |
2881 | |
2882 template void | |
2883 pr_int (std::ostream&, const octave_int16&, int); | |
2884 | |
2885 template void | |
2886 pr_int (std::ostream&, const octave_int32&, int); | |
2887 | |
2888 template void | |
2889 pr_int (std::ostream&, const octave_int64&, int); | |
2890 | |
2891 template void | |
2892 pr_int (std::ostream&, const octave_uint8&, int); | |
2893 | |
2894 template void | |
2895 pr_int (std::ostream&, const octave_uint16&, int); | |
2896 | |
2897 template void | |
2898 pr_int (std::ostream&, const octave_uint32&, int); | |
2899 | |
2900 template void | |
2901 pr_int (std::ostream&, const octave_uint64&, int); | |
2902 | |
6008 | 2903 template <class T> |
4901 | 2904 void |
7215 | 2905 octave_print_internal_template (std::ostream& os, const octave_int<T>& val, |
2906 bool) | |
2907 { | |
2908 if (plus_format) | |
2909 { | |
2910 pr_plus_format (os, val); | |
2911 } | |
2912 else | |
2913 { | |
2914 if (free_format) | |
2915 os << typename octave_print_conv<octave_int<T> >::print_conv_type (val); | |
2916 else | |
2917 pr_int (os, val); | |
2918 } | |
2919 } | |
2920 | |
2921 #define PRINT_INT_SCALAR_INTERNAL(TYPE) \ | |
2922 OCTINTERP_API void \ | |
2923 octave_print_internal (std::ostream& os, const octave_int<TYPE>& val, bool dummy) \ | |
2924 { \ | |
2925 octave_print_internal_template (os, val, dummy); \ | |
2926 } | |
2927 | |
2928 PRINT_INT_SCALAR_INTERNAL (int8_t) | |
2929 PRINT_INT_SCALAR_INTERNAL (uint8_t) | |
2930 PRINT_INT_SCALAR_INTERNAL (int16_t) | |
2931 PRINT_INT_SCALAR_INTERNAL (uint16_t) | |
2932 PRINT_INT_SCALAR_INTERNAL (int32_t) | |
2933 PRINT_INT_SCALAR_INTERNAL (uint32_t) | |
2934 PRINT_INT_SCALAR_INTERNAL (int64_t) | |
2935 PRINT_INT_SCALAR_INTERNAL (uint64_t) | |
2936 | |
2937 template <class T> | |
2938 /* static */ inline void | |
2939 octave_print_internal_template (std::ostream& os, const intNDArray<T>& nda, | |
2940 bool pr_as_read_syntax, int extra_indent) | |
4901 | 2941 { |
5775 | 2942 // FIXME -- this mostly duplicates the code in the |
4901 | 2943 // PRINT_ND_ARRAY macro. |
2944 | |
2945 if (nda.is_empty ()) | |
2946 print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); | |
2947 else if (nda.length () == 1) | |
7215 | 2948 octave_print_internal_template (os, nda(0), pr_as_read_syntax); |
4949 | 2949 else if (plus_format && ! pr_as_read_syntax) |
4901 | 2950 { |
2951 int ndims = nda.ndims (); | |
2952 | |
5275 | 2953 Array<octave_idx_type> ra_idx (ndims, 0); |
4949 | 2954 |
4901 | 2955 dim_vector dims = nda.dims (); |
2956 | |
5275 | 2957 octave_idx_type m = 1; |
4901 | 2958 |
2959 for (int i = 2; i < ndims; i++) | |
2960 m *= dims(i); | |
2961 | |
5275 | 2962 octave_idx_type nr = dims(0); |
2963 octave_idx_type nc = dims(1); | |
2964 | |
2965 for (octave_idx_type i = 0; i < m; i++) | |
4901 | 2966 { |
2967 if (m > 1) | |
2968 { | |
4949 | 2969 std::string nm = "ans(:,:,"; |
4901 | 2970 |
5765 | 2971 std::ostringstream buf; |
4901 | 2972 |
2973 for (int k = 2; k < ndims; k++) | |
2974 { | |
2975 buf << ra_idx(k) + 1; | |
2976 | |
2977 if (k < ndims - 1) | |
2978 buf << ","; | |
2979 else | |
2980 buf << ")"; | |
2981 } | |
2982 | |
5765 | 2983 nm += buf.str (); |
4949 | 2984 |
2985 os << nm << " =\n\n"; | |
4901 | 2986 } |
2987 | |
2988 Array<idx_vector> idx (ndims); | |
2989 | |
2990 idx(0) = idx_vector (':'); | |
2991 idx(1) = idx_vector (':'); | |
2992 | |
2993 for (int k = 2; k < ndims; k++) | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
2994 idx(k) = idx_vector (ra_idx(k)); |
4901 | 2995 |
2996 Array2<T> page (nda.index (idx), nr, nc); | |
2997 | |
5275 | 2998 for (octave_idx_type ii = 0; ii < nr; ii++) |
4901 | 2999 { |
5275 | 3000 for (octave_idx_type jj = 0; jj < nc; jj++) |
4949 | 3001 { |
3002 OCTAVE_QUIT; | |
3003 | |
3004 pr_plus_format (os, page(ii,jj)); | |
3005 } | |
3006 | |
3007 if ((ii < nr - 1) || (i < m -1)) | |
3008 os << "\n"; | |
4901 | 3009 } |
3010 | |
3011 if (i < m - 1) | |
4949 | 3012 { |
3013 os << "\n"; | |
3014 increment_index (ra_idx, dims, 2); | |
3015 } | |
3016 } | |
3017 } | |
3018 else | |
3019 { | |
3020 int ndims = nda.ndims (); | |
3021 | |
3022 dim_vector dims = nda.dims (); | |
3023 | |
5275 | 3024 Array<octave_idx_type> ra_idx (ndims, 0); |
3025 | |
3026 octave_idx_type m = 1; | |
4949 | 3027 |
3028 for (int i = 2; i < ndims; i++) | |
3029 m *= dims(i); | |
3030 | |
5275 | 3031 octave_idx_type nr = dims(0); |
3032 octave_idx_type nc = dims(1); | |
4949 | 3033 |
3034 int fw = 0; | |
3035 if (hex_format) | |
3036 fw = 2 * nda(0).byte_size (); | |
3037 else if (bit_format) | |
3038 fw = nda(0).nbits (); | |
3039 else | |
3040 { | |
3041 bool isneg = false; | |
3042 int digits = 0; | |
3043 | |
5275 | 3044 for (octave_idx_type i = 0; i < dims.numel (); i++) |
4949 | 3045 { |
3046 int new_digits = static_cast<int> | |
3047 (floor (log10 (double (abs (nda(i).value ()))) + 1.0)); | |
3048 | |
3049 if (new_digits > digits) | |
3050 digits = new_digits; | |
3051 | |
3052 if (! isneg) | |
3053 isneg = (abs (nda(i).value ()) != nda(i).value ()); | |
3054 } | |
3055 | |
3056 fw = digits + isneg; | |
3057 } | |
3058 | |
6788 | 3059 int column_width = fw + (rat_format ? 0 : (bank_format ? 5 : 2)); |
5275 | 3060 octave_idx_type total_width = nc * column_width; |
4949 | 3061 int max_width = command_editor::terminal_cols () - extra_indent; |
5275 | 3062 octave_idx_type inc = nc; |
4949 | 3063 if (total_width > max_width && Vsplit_long_rows) |
3064 { | |
3065 inc = max_width / column_width; | |
3066 if (inc == 0) | |
3067 inc++; | |
3068 } | |
3069 | |
5275 | 3070 for (octave_idx_type i = 0; i < m; i++) |
4949 | 3071 { |
3072 if (m > 1) | |
3073 { | |
3074 std::string nm = "ans(:,:,"; | |
3075 | |
5765 | 3076 std::ostringstream buf; |
4949 | 3077 |
3078 for (int k = 2; k < ndims; k++) | |
3079 { | |
3080 buf << ra_idx(k) + 1; | |
3081 | |
3082 if (k < ndims - 1) | |
3083 buf << ","; | |
3084 else | |
3085 buf << ")"; | |
3086 } | |
3087 | |
5765 | 3088 nm += buf.str (); |
4949 | 3089 |
3090 os << nm << " =\n\n"; | |
3091 } | |
3092 | |
3093 Array<idx_vector> idx (ndims); | |
3094 | |
3095 idx(0) = idx_vector (':'); | |
3096 idx(1) = idx_vector (':'); | |
3097 | |
3098 for (int k = 2; k < ndims; k++) | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
3099 idx(k) = idx_vector (ra_idx(k)); |
4949 | 3100 |
3101 Array2<T> page (nda.index (idx), nr, nc); | |
3102 | |
3103 if (free_format) | |
3104 { | |
3105 if (pr_as_read_syntax) | |
3106 os << "[\n"; | |
3107 | |
5275 | 3108 for (octave_idx_type ii = 0; ii < nr; ii++) |
4949 | 3109 { |
5275 | 3110 for (octave_idx_type jj = 0; jj < nc; jj++) |
4949 | 3111 { |
3112 OCTAVE_QUIT; | |
3113 os << " "; | |
3114 os << typename octave_print_conv<T>::print_conv_type (page(ii,jj)); | |
3115 } | |
3116 os << "\n"; | |
3117 } | |
3118 | |
3119 if (pr_as_read_syntax) | |
3120 os << "]"; | |
3121 } | |
3122 else | |
3123 { | |
5275 | 3124 octave_idx_type n_rows = page.rows (); |
3125 octave_idx_type n_cols = page.cols (); | |
3126 | |
3127 for (octave_idx_type col = 0; col < n_cols; col += inc) | |
4949 | 3128 { |
5275 | 3129 octave_idx_type lim = col + inc < n_cols ? col + inc : n_cols; |
4949 | 3130 |
3131 pr_col_num_header (os, total_width, max_width, lim, col, | |
3132 extra_indent); | |
3133 | |
5275 | 3134 for (octave_idx_type ii = 0; ii < n_rows; ii++) |
4949 | 3135 { |
3136 os << std::setw (extra_indent) << ""; | |
3137 | |
5275 | 3138 for (octave_idx_type jj = col; jj < lim; jj++) |
4949 | 3139 { |
3140 OCTAVE_QUIT; | |
3141 os << " "; | |
3142 pr_int (os, page(ii,jj), fw); | |
3143 } | |
3144 if ((ii < n_rows - 1) || (i < m -1)) | |
3145 os << "\n"; | |
3146 } | |
3147 } | |
3148 } | |
3149 | |
3150 if (i < m - 1) | |
3151 { | |
3152 os << "\n"; | |
3153 increment_index (ra_idx, dims, 2); | |
3154 } | |
4901 | 3155 } |
3156 } | |
3157 } | |
3158 | |
7215 | 3159 #define PRINT_INT_ARRAY_INTERNAL(TYPE) \ |
3160 OCTINTERP_API void \ | |
3161 octave_print_internal (std::ostream& os, const intNDArray<TYPE>& nda, \ | |
3162 bool pr_as_read_syntax, int extra_indent) \ | |
3163 { \ | |
3164 octave_print_internal_template (os, nda, pr_as_read_syntax, extra_indent); \ | |
3165 } | |
3166 | |
3167 PRINT_INT_ARRAY_INTERNAL (octave_int8) | |
3168 PRINT_INT_ARRAY_INTERNAL (octave_uint8) | |
3169 PRINT_INT_ARRAY_INTERNAL (octave_int16) | |
3170 PRINT_INT_ARRAY_INTERNAL (octave_uint16) | |
3171 PRINT_INT_ARRAY_INTERNAL (octave_int32) | |
3172 PRINT_INT_ARRAY_INTERNAL (octave_uint32) | |
3173 PRINT_INT_ARRAY_INTERNAL (octave_int64) | |
3174 PRINT_INT_ARRAY_INTERNAL (octave_uint64) | |
4901 | 3175 |
8012
63dbb85452cc
fix extern decls in .cc files
John W. Eaton <jwe@octave.org>
parents:
7896
diff
changeset
|
3176 void |
3933 | 3177 octave_print_internal (std::ostream&, const Cell&, bool, int, bool) |
3928 | 3178 { |
3933 | 3179 panic_impossible (); |
3928 | 3180 } |
3181 | |
6788 | 3182 DEFUN (rats, args, nargout, |
3183 "-*- texinfo -*-\n\ | |
3184 @deftypefn {Built-in Function} {} rats (@var{x}, @var{len})\n\ | |
3185 Convert @var{x} into a rational approximation represented as a string.\n\ | |
3186 You can convert the string back into a matrix as follows:\n\ | |
3187 \n\ | |
3188 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
3189 @group\n\ |
7097 | 3190 r = rats(hilb(4));\n\ |
3191 x = str2num(r)\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
3192 @end group\n\ |
6788 | 3193 @end example\n\ |
3194 \n\ | |
3195 The optional second argument defines the maximum length of the string\n\ | |
9039
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8930
diff
changeset
|
3196 representing the elements of @var{x}. By default @var{len} is 9.\n\ |
6788 | 3197 @seealso{format, rat}\n\ |
3198 @end deftypefn") | |
3199 { | |
3200 octave_value retval; | |
6803 | 3201 |
6788 | 3202 int nargin = args.length (); |
3203 | |
7896 | 3204 if (nargin < 1 || nargin > 2 || nargout > 1) |
3205 print_usage (); | |
3206 else | |
6788 | 3207 { |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9305
diff
changeset
|
3208 unwind_protect::frame_id_t uwp_frame = unwind_protect::begin_frame (); |
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9305
diff
changeset
|
3209 |
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9305
diff
changeset
|
3210 unwind_protect::protect_var (rat_string_len); |
7896 | 3211 |
3212 rat_string_len = 9; | |
3213 | |
3214 if (nargin == 2) | |
3215 rat_string_len = args(1).nint_value (); | |
3216 | |
3217 if (! error_state) | |
6788 | 3218 { |
6803 | 3219 octave_value arg = args(0); |
3220 | |
3221 if (arg.is_numeric_type ()) | |
3222 { | |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9305
diff
changeset
|
3223 unwind_protect::protect_var (rat_format); |
6803 | 3224 |
3225 rat_format = true; | |
3226 | |
3227 std::ostringstream buf; | |
3228 args(0).print (buf); | |
3229 std::string s = buf.str (); | |
3230 | |
3231 std::list<std::string> lst; | |
3232 | |
3233 size_t n = 0; | |
3234 size_t s_len = s.length (); | |
3235 | |
3236 while (n < s_len) | |
3237 { | |
3238 size_t m = s.find ('\n', n); | |
3239 | |
8021 | 3240 if (m == std::string::npos) |
6803 | 3241 { |
3242 lst.push_back (s.substr (n)); | |
3243 break; | |
3244 } | |
3245 else | |
3246 { | |
3247 lst.push_back (s.substr (n, m - n)); | |
3248 n = m + 1; | |
3249 } | |
3250 } | |
3251 | |
3252 retval = string_vector (lst); | |
3253 } | |
3254 else | |
3255 error ("rats: expecting numeric input"); | |
6788 | 3256 } |
7896 | 3257 |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9305
diff
changeset
|
3258 unwind_protect::run_frame (uwp_frame); |
6788 | 3259 } |
3260 | |
3261 return retval; | |
3262 } | |
3263 | |
3685 | 3264 DEFUN (disp, args, nargout, |
3265 "-*- texinfo -*-\n\ | |
3266 @deftypefn {Built-in Function} {} disp (@var{x})\n\ | |
3267 Display the value of @var{x}. For example,\n\ | |
3268 \n\ | |
3269 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
3270 @group\n\ |
3685 | 3271 disp (\"The value of pi is:\"), disp (pi)\n\ |
3272 \n\ | |
3273 @print{} the value of pi is:\n\ | |
3274 @print{} 3.1416\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
3275 @end group\n\ |
3685 | 3276 @end example\n\ |
3277 \n\ | |
3278 @noindent\n\ | |
3279 Note that the output from @code{disp} always ends with a newline.\n\ | |
3280 \n\ | |
3281 If an output value is requested, @code{disp} prints nothing and\n\ | |
3282 returns the formatted output in a string.\n\ | |
5642 | 3283 @seealso{fdisp}\n\ |
3284 @end deftypefn") | |
3685 | 3285 { |
9643
85dd3a2c9355
avoid returning undefined values from disp & fdisp
Jaroslav Hajek <highegg@gmail.com>
parents:
9629
diff
changeset
|
3286 octave_value_list retval; |
3685 | 3287 |
3288 int nargin = args.length (); | |
3289 | |
3290 if (nargin == 1 && nargout < 2) | |
3291 { | |
3292 if (nargout == 0) | |
3293 args(0).print (octave_stdout); | |
3294 else | |
3295 { | |
7721
9369589f2ba5
disp: produce sq-string unless arg is a dq-string
John W. Eaton <jwe@octave.org>
parents:
7465
diff
changeset
|
3296 octave_value arg = args(0); |
5765 | 3297 std::ostringstream buf; |
7721
9369589f2ba5
disp: produce sq-string unless arg is a dq-string
John W. Eaton <jwe@octave.org>
parents:
7465
diff
changeset
|
3298 arg.print (buf); |
9369589f2ba5
disp: produce sq-string unless arg is a dq-string
John W. Eaton <jwe@octave.org>
parents:
7465
diff
changeset
|
3299 retval = octave_value (buf.str (), arg.is_dq_string () ? '"' : '\''); |
3685 | 3300 } |
3301 } | |
3302 else | |
5823 | 3303 print_usage (); |
3685 | 3304 |
3305 return retval; | |
3306 } | |
3307 | |
3308 DEFUN (fdisp, args, , | |
3309 "-*- texinfo -*-\n\ | |
3310 @deftypefn {Built-in Function} {} fdisp (@var{fid}, @var{x})\n\ | |
3311 Display the value of @var{x} on the stream @var{fid}. For example,\n\ | |
3312 \n\ | |
3313 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
3314 @group\n\ |
4869 | 3315 fdisp (stdout, \"The value of pi is:\"), fdisp (stdout, pi)\n\ |
3685 | 3316 \n\ |
3317 @print{} the value of pi is:\n\ | |
3318 @print{} 3.1416\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
3319 @end group\n\ |
3685 | 3320 @end example\n\ |
3321 \n\ | |
3322 @noindent\n\ | |
4869 | 3323 Note that the output from @code{fdisp} always ends with a newline.\n\ |
5642 | 3324 @seealso{disp}\n\ |
3325 @end deftypefn") | |
3685 | 3326 { |
9643
85dd3a2c9355
avoid returning undefined values from disp & fdisp
Jaroslav Hajek <highegg@gmail.com>
parents:
9629
diff
changeset
|
3327 octave_value_list retval; |
3685 | 3328 |
3329 int nargin = args.length (); | |
3330 | |
3331 if (nargin == 2) | |
3332 { | |
3333 int fid = octave_stream_list::get_file_number (args (0)); | |
3334 | |
3335 octave_stream os = octave_stream_list::lookup (fid, "fdisp"); | |
3336 | |
3337 if (! error_state) | |
3338 { | |
3769 | 3339 std::ostream *osp = os.output_stream (); |
3685 | 3340 |
3341 if (osp) | |
3342 args(1).print (*osp); | |
3343 else | |
3344 error ("fdisp: stream not open for writing"); | |
3345 } | |
3346 } | |
3347 else | |
5823 | 3348 print_usage (); |
3685 | 3349 |
3350 return retval; | |
3351 } | |
3352 | |
9629 | 3353 /* |
3354 %!test | |
3355 %! format short | |
3356 %! fd = tmpfile (); | |
3357 %! for r = [0, Inf -Inf, NaN] | |
3358 %! for i = [0, Inf -Inf, NaN] | |
3359 %! fdisp (fd, complex (r, i)); | |
3360 %! endfor | |
3361 %! endfor | |
3362 %! fclose (fd); | |
3363 */ | |
3364 | |
1 | 3365 static void |
3366 init_format_state (void) | |
3367 { | |
2387 | 3368 free_format = false; |
3369 plus_format = false; | |
6788 | 3370 rat_format = false; |
2387 | 3371 bank_format = false; |
3608 | 3372 hex_format = 0; |
1309 | 3373 bit_format = 0; |
4833 | 3374 compact_format = false; |
2387 | 3375 print_e = false; |
3376 print_big_e = false; | |
4509 | 3377 print_g = false; |
1 | 3378 } |
3379 | |
3380 static void | |
3381 set_output_prec_and_fw (int prec, int fw) | |
3382 { | |
5794 | 3383 Voutput_precision = prec; |
3384 Voutput_max_field_width = fw; | |
1 | 3385 } |
3386 | |
1755 | 3387 static void |
3388 set_format_style (int argc, const string_vector& argv) | |
1 | 3389 { |
1755 | 3390 int idx = 1; |
3391 | |
1899 | 3392 if (--argc > 0) |
1 | 3393 { |
3523 | 3394 std::string arg = argv[idx++]; |
2584 | 3395 |
1755 | 3396 if (arg == "short") |
1 | 3397 { |
1755 | 3398 if (--argc > 0) |
1 | 3399 { |
1755 | 3400 arg = argv[idx++]; |
3401 | |
3402 if (arg == "e") | |
1 | 3403 { |
1755 | 3404 init_format_state (); |
2387 | 3405 print_e = true; |
1755 | 3406 } |
3407 else if (arg == "E") | |
3408 { | |
3409 init_format_state (); | |
2387 | 3410 print_e = true; |
3411 print_big_e = true; | |
1 | 3412 } |
4509 | 3413 else if (arg == "g") |
3414 { | |
3415 init_format_state (); | |
3416 print_g = true; | |
3417 } | |
3418 else if (arg == "G") | |
3419 { | |
3420 init_format_state (); | |
3421 print_g = true; | |
3422 print_big_e = true; | |
3423 } | |
1 | 3424 else |
3425 { | |
1755 | 3426 error ("format: unrecognized option `short %s'", |
3427 arg.c_str ()); | |
3428 return; | |
3429 } | |
3430 } | |
3431 else | |
3432 init_format_state (); | |
3433 | |
4509 | 3434 set_output_prec_and_fw (5, 10); |
1755 | 3435 } |
3436 else if (arg == "long") | |
3437 { | |
3438 if (--argc > 0) | |
3439 { | |
3440 arg = argv[idx++]; | |
3441 | |
3442 if (arg == "e") | |
3443 { | |
3444 init_format_state (); | |
2387 | 3445 print_e = true; |
1755 | 3446 } |
3447 else if (arg == "E") | |
3448 { | |
3449 init_format_state (); | |
2387 | 3450 print_e = true; |
3451 print_big_e = true; | |
1 | 3452 } |
4509 | 3453 else if (arg == "g") |
3454 { | |
3455 init_format_state (); | |
3456 print_g = true; | |
3457 } | |
3458 else if (arg == "G") | |
3459 { | |
3460 init_format_state (); | |
3461 print_g = true; | |
3462 print_big_e = true; | |
3463 } | |
1 | 3464 else |
1755 | 3465 { |
3466 error ("format: unrecognized option `long %s'", | |
3467 arg.c_str ()); | |
3468 return; | |
3469 } | |
1186 | 3470 } |
1 | 3471 else |
1755 | 3472 init_format_state (); |
3473 | |
4509 | 3474 set_output_prec_and_fw (15, 20); |
1755 | 3475 } |
3476 else if (arg == "hex") | |
3477 { | |
3478 init_format_state (); | |
3608 | 3479 hex_format = 1; |
1755 | 3480 } |
3481 else if (arg == "native-hex") | |
3482 { | |
3483 init_format_state (); | |
3484 hex_format = 2; | |
3485 } | |
3486 else if (arg == "bit") | |
3487 { | |
3488 init_format_state (); | |
3489 bit_format = 1; | |
3490 } | |
3491 else if (arg == "native-bit") | |
3492 { | |
3493 init_format_state (); | |
3494 bit_format = 2; | |
3495 } | |
3496 else if (arg == "+" || arg == "plus") | |
3497 { | |
4632 | 3498 if (--argc > 0) |
3499 { | |
3500 arg = argv[idx++]; | |
3501 | |
3502 if (arg.length () == 3) | |
3503 plus_format_chars = arg; | |
3504 else | |
3505 { | |
3506 error ("format: invalid option for plus format"); | |
3507 return; | |
3508 } | |
3509 } | |
3510 else | |
3511 plus_format_chars = "+ "; | |
3512 | |
1755 | 3513 init_format_state (); |
2387 | 3514 plus_format = true; |
1755 | 3515 } |
6788 | 3516 else if (arg == "rat") |
3517 { | |
3518 init_format_state (); | |
3519 rat_format = true; | |
3520 } | |
1755 | 3521 else if (arg == "bank") |
3522 { | |
3523 init_format_state (); | |
2387 | 3524 bank_format = true; |
1755 | 3525 } |
3526 else if (arg == "free") | |
3527 { | |
3528 init_format_state (); | |
2387 | 3529 free_format = true; |
1755 | 3530 } |
3531 else if (arg == "none") | |
3532 { | |
3533 init_format_state (); | |
2387 | 3534 free_format = true; |
1755 | 3535 } |
3536 else if (arg == "compact") | |
3537 { | |
2387 | 3538 compact_format = true; |
1755 | 3539 } |
3540 else if (arg == "loose") | |
3541 { | |
2387 | 3542 compact_format = false; |
1 | 3543 } |
3544 else | |
1755 | 3545 error ("format: unrecognized format state `%s'", arg.c_str ()); |
1 | 3546 } |
3547 else | |
3548 { | |
3549 init_format_state (); | |
3550 set_output_prec_and_fw (5, 10); | |
3551 } | |
3552 } | |
3553 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8625
diff
changeset
|
3554 DEFUN (format, args, , |
3372 | 3555 "-*- texinfo -*-\n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3556 @deffn {Command} format\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3557 @deffnx {Command} format options\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3558 Reset or specify the format of the output produced by @code{disp} and\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3559 Octave's normal echoing mechanism. This command only affects the display\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3560 of numbers but not how they are stored or computed. To change the internal\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3561 representation from the default double use one of the conversion functions\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3562 such as @code{single}, @code{uint8}, @code{int64}, etc.\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3563 \n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3564 By default, Octave displays 5 significant digits in a human readable form\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3565 (option @samp{short} paired with @samp{loose} format for matrices).\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3566 If @code{format} is invoked without any options, this default format\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3567 is restored.\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3568 \n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3569 Valid formats for floating point numbers are listed in the following\n\ |
3372 | 3570 table.\n\ |
3571 \n\ | |
3572 @table @code\n\ | |
3573 @item short\n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3574 Fixed point format with 5 significant figures in a field that is a maximum\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3575 of 10 characters wide. (default).\n\ |
3372 | 3576 \n\ |
3577 If Octave is unable to format a matrix so that columns line up on the\n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3578 decimal point and all numbers fit within the maximum field width then\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3579 it switches to an exponential @samp{e} format.\n\ |
3372 | 3580 \n\ |
3581 @item long\n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3582 Fixed point format with 15 significant figures in a field that is a maximum\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3583 of 20 characters wide.\n\ |
3372 | 3584 \n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3585 As with the @samp{short} format, Octave will switch to an exponential\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3586 @samp{e} format if it is unable to format a matrix properly using the\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3587 current format.\n\ |
3372 | 3588 \n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3589 @item short e\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3590 @itemx long e\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3591 Exponential format. The number to be represented is split between a mantissa\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3592 and an exponent (power of 10). The mantissa has 5 significant digits in the\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3593 short format and 15 digits in the long format.\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3594 For example, with the @samp{short e} format, @code{pi} is displayed as\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3595 @code{3.1416e+00}.\n\ |
3372 | 3596 \n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3597 @item short E\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3598 @itemx long E\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3599 Identical to @samp{short e} or @samp{long e} but displays an uppercase\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3600 @samp{E} to indicate the exponent.\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3601 For example, with the @samp{long E} format, @code{pi} is displayed as\n\ |
3372 | 3602 @code{3.14159265358979E+00}.\n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3603 \n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3604 @item short g\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3605 @itemx long g\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3606 Optimally choose between fixed point and exponential format based on\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3607 the magnitude of the number.\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3608 For example, with the @samp{short g} format,\n\ |
4509 | 3609 @code{pi .^ [2; 4; 8; 16; 32]} is displayed as\n\ |
3610 \n\ | |
3611 @example\n\ | |
3612 @group\n\ | |
3613 ans =\n\ | |
3614 \n\ | |
3615 9.8696\n\ | |
3616 97.409\n\ | |
3617 9488.5\n\ | |
3618 9.0032e+07\n\ | |
3619 8.1058e+15\n\ | |
3620 @end group\n\ | |
3621 @end example\n\ | |
3622 \n\ | |
3623 @item long G\n\ | |
3624 @itemx short G\n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3625 Identical to @samp{short g} or @samp{long g} but displays an uppercase\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3626 @samp{E} to indicate the exponent.\n\ |
3372 | 3627 \n\ |
3628 @item free\n\ | |
3629 @itemx none\n\ | |
3630 Print output in free format, without trying to line up columns of\n\ | |
3631 matrices on the decimal point. This also causes complex numbers to be\n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3632 formatted as numeric pairs like this @samp{(0.60419, 0.60709)} instead\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3633 of like this @samp{0.60419 + 0.60709i}.\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3634 @end table\n\ |
529 | 3635 \n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3636 The following formats affect all numeric output (floating point and\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3637 integer types).\n\ |
3372 | 3638 \n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3639 @table @code\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3640 @item +\n\ |
4632 | 3641 @itemx + @var{chars}\n\ |
3642 @itemx plus\n\ | |
3643 @itemx plus @var{chars}\n\ | |
3372 | 3644 Print a @samp{+} symbol for nonzero matrix elements and a space for zero\n\ |
3645 matrix elements. This format can be very useful for examining the\n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3646 structure of a large sparse matrix.\n\ |
3372 | 3647 \n\ |
4632 | 3648 The optional argument @var{chars} specifies a list of 3 characters to use\n\ |
3649 for printing values greater than zero, less than zero and equal to zero.\n\ | |
3650 For example, with the @samp{+ \"+-.\"} format, @code{[1, 0, -1; -1, 0, 1]}\n\ | |
3651 is displayed as\n\ | |
3652 \n\ | |
3653 @example\n\ | |
3654 @group\n\ | |
3655 ans =\n\ | |
3656 \n\ | |
3657 +.-\n\ | |
3658 -.+\n\ | |
3659 @end group\n\ | |
3660 @end example\n\ | |
3661 \n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3662 @item bank\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3663 Print in a fixed format with two digits to the right of the decimal\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3664 point.\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3665 \n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3666 @item native-hex\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3667 Print the hexadecimal representation of numbers as they are stored in\n\ |
3372 | 3668 memory. For example, on a workstation which stores 8 byte real values\n\ |
3669 in IEEE format with the least significant byte first, the value of\n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3670 @code{pi} when printed in @code{native-hex} format is @code{400921fb54442d18}.\n\ |
3372 | 3671 \n\ |
4833 | 3672 @item hex\n\ |
3673 The same as @code{native-hex}, but always print the most significant\n\ | |
3674 byte first.\n\ | |
3675 @item native-bit\n\ | |
3372 | 3676 Print the bit representation of numbers as stored in memory.\n\ |
3677 For example, the value of @code{pi} is\n\ | |
3678 \n\ | |
3679 @example\n\ | |
3680 @group\n\ | |
3681 01000000000010010010000111111011\n\ | |
3682 01010100010001000010110100011000\n\ | |
3683 @end group\n\ | |
3684 @end example\n\ | |
3685 \n\ | |
3686 (shown here in two 32 bit sections for typesetting purposes) when\n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3687 printed in native-bit format on a workstation which stores 8 byte real values\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3688 in IEEE format with the least significant byte first.\n\ |
4833 | 3689 @item bit\n\ |
3690 The same as @code{native-bit}, but always print the most significant\n\ | |
3691 bits first.\n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3692 \n\ |
6788 | 3693 @item rat\n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3694 Print a rational approximation, i.e., values are approximated\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3695 as the ratio of small integers.\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3696 For example, with the @samp{rat} format,\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3697 @code{pi} is displayed as @code{355/113}.\n\ |
3372 | 3698 @end table\n\ |
3699 \n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3700 The following two options affect the display of all matrices.\n\ |
3372 | 3701 \n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3702 @table @code\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3703 @item compact\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3704 Remove extra blank space around column number labels producing more compact\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3705 output with more data per page.\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3706 @item loose\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3707 Insert blank lines above and below column number labels to produce a more\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3708 readable output with less data per page. (default).\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3709 @end table\n\ |
3372 | 3710 @end deffn") |
529 | 3711 { |
2086 | 3712 octave_value_list retval; |
529 | 3713 |
1755 | 3714 int argc = args.length () + 1; |
3715 | |
1968 | 3716 string_vector argv = args.make_argv ("format"); |
1755 | 3717 |
3718 if (error_state) | |
3719 return retval; | |
529 | 3720 |
3721 set_format_style (argc, argv); | |
3722 | |
3723 return retval; | |
3724 } | |
3725 | |
5794 | 3726 DEFUN (fixed_point_format, args, nargout, |
3727 "-*- texinfo -*-\n\ | |
3728 @deftypefn {Built-in Function} {@var{val} =} fixed_point_format ()\n\ | |
3729 @deftypefnx {Built-in Function} {@var{old_val} =} fixed_point_format (@var{new_val})\n\ | |
3730 Query or set the internal variable that controls whether Octave will\n\ | |
3731 use a scaled format to print matrix values such that the largest\n\ | |
3732 element may be written with a single leading digit with the scaling\n\ | |
3733 factor is printed on the first line of output. For example,\n\ | |
3321 | 3734 \n\ |
3735 @example\n\ | |
3736 @group\n\ | |
3737 octave:1> logspace (1, 7, 5)'\n\ | |
3738 ans =\n\ | |
3739 \n\ | |
3740 1.0e+07 *\n\ | |
3741 \n\ | |
3742 0.00000\n\ | |
3743 0.00003\n\ | |
3744 0.00100\n\ | |
3745 0.03162\n\ | |
3746 1.00000\n\ | |
3747 @end group\n\ | |
3748 @end example\n\ | |
3749 \n\ | |
3750 @noindent\n\ | |
3751 Notice that first value appears to be zero when it is actually 1. For\n\ | |
3752 this reason, you should be careful when setting\n\ | |
3753 @code{fixed_point_format} to a nonzero value.\n\ | |
5794 | 3754 @end deftypefn") |
3755 { | |
3756 return SET_INTERNAL_VARIABLE (fixed_point_format); | |
3757 } | |
3758 | |
3759 DEFUN (print_empty_dimensions, args, nargout, | |
3760 "-*- texinfo -*-\n\ | |
3761 @deftypefn {Built-in Function} {@var{val} =} print_empty_dimensions ()\n\ | |
3762 @deftypefnx {Built-in Function} {@var{old_val} =} print_empty_dimensions (@var{new_val})\n\ | |
7001 | 3763 Query or set the internal variable that controls whether the\n\ |
3321 | 3764 dimensions of empty matrices are printed along with the empty matrix\n\ |
3765 symbol, @samp{[]}. For example, the expression\n\ | |
3766 \n\ | |
3767 @example\n\ | |
3768 zeros (3, 0)\n\ | |
3769 @end example\n\ | |
3770 \n\ | |
3771 @noindent\n\ | |
3772 will print\n\ | |
3773 \n\ | |
3774 @example\n\ | |
3775 ans = [](3x0)\n\ | |
3776 @end example\n\ | |
5794 | 3777 @end deftypefn") |
3778 { | |
3779 return SET_INTERNAL_VARIABLE (print_empty_dimensions); | |
3780 } | |
3781 | |
3782 DEFUN (split_long_rows, args, nargout, | |
3783 "-*- texinfo -*-\n\ | |
3784 @deftypefn {Built-in Function} {@var{val} =} split_long_rows ()\n\ | |
3785 @deftypefnx {Built-in Function} {@var{old_val} =} split_long_rows (@var{new_val})\n\ | |
3786 Query or set the internal variable that controls whether rows of a matrix\n\ | |
3787 may be split when displayed to a terminal window. If the rows are split,\n\ | |
3788 Octave will display the matrix in a series of smaller pieces, each of\n\ | |
3789 which can fit within the limits of your terminal width and each set of\n\ | |
3790 rows is labeled so that you can easily see which columns are currently\n\ | |
3791 being displayed. For example:\n\ | |
3321 | 3792 \n\ |
6670 | 3793 @example\n\ |
3321 | 3794 @group\n\ |
3795 octave:13> rand (2,10)\n\ | |
3796 ans =\n\ | |
3797 \n\ | |
3798 Columns 1 through 6:\n\ | |
3799 \n\ | |
3800 0.75883 0.93290 0.40064 0.43818 0.94958 0.16467\n\ | |
3801 0.75697 0.51942 0.40031 0.61784 0.92309 0.40201\n\ | |
3802 \n\ | |
3803 Columns 7 through 10:\n\ | |
3804 \n\ | |
3805 0.90174 0.11854 0.72313 0.73326\n\ | |
3806 0.44672 0.94303 0.56564 0.82150\n\ | |
3807 @end group\n\ | |
6670 | 3808 @end example\n\ |
5794 | 3809 @end deftypefn") |
3810 { | |
3811 return SET_INTERNAL_VARIABLE (split_long_rows); | |
3812 } | |
3813 | |
3814 DEFUN (output_max_field_width, args, nargout, | |
3815 "-*- texinfo -*-\n\ | |
3816 @deftypefn {Built-in Function} {@var{val} =} output_max_field_width ()\n\ | |
3817 @deftypefnx {Built-in Function} {@var{old_val} =} output_max_field_width (@var{new_val})\n\ | |
3818 Query or set the internal variable that specifies the maximum width\n\ | |
3819 of a numeric output field.\n\ | |
3820 @seealso{format, output_precision}\n\ | |
3821 @end deftypefn") | |
3822 { | |
3823 return SET_INTERNAL_VARIABLE_WITH_LIMITS (output_precision, 0, INT_MAX); | |
3824 } | |
3825 | |
3826 DEFUN (output_precision, args, nargout, | |
3827 "-*- texinfo -*-\n\ | |
3828 @deftypefn {Built-in Function} {@var{val} =} output_precision ()\n\ | |
3829 @deftypefnx {Built-in Function} {@var{old_val} =} output_precision (@var{new_val})\n\ | |
3830 Query or set the internal variable that specifies the minimum number of\n\ | |
3831 significant figures to display for numeric output.\n\ | |
3832 @seealso{format, output_max_field_width}\n\ | |
3833 @end deftypefn") | |
3834 { | |
3835 return SET_INTERNAL_VARIABLE_WITH_LIMITS (output_precision, -1, INT_MAX); | |
3836 } | |
3837 | |
3838 DEFUN (struct_levels_to_print, args, nargout, | |
3839 "-*- texinfo -*-\n\ | |
3840 @deftypefn {Built-in Function} {@var{val} =} struct_levels_to_print ()\n\ | |
3841 @deftypefnx {Built-in Function} {@var{old_val} =} struct_levels_to_print (@var{new_val})\n\ | |
3842 Query or set the internal variable that specifies the number of\n\ | |
3843 structure levels to display.\n\ | |
3844 @end deftypefn") | |
3845 { | |
3846 return SET_INTERNAL_VARIABLE_WITH_LIMITS (struct_levels_to_print, | |
3847 -1, INT_MAX); | |
2165 | 3848 } |
3849 | |
1 | 3850 /* |
3851 ;;; Local Variables: *** | |
3852 ;;; mode: C++ *** | |
3853 ;;; End: *** | |
3854 */ |