comparison src/pr-output.cc @ 8891:d077c590eb88

indicate diag & perm matrices on output
author Jaroslav Hajek <highegg@gmail.com>
date Sun, 01 Mar 2009 09:07:57 +0100
parents 5dd06f19e9be
children eb63fbe60fab
comparison
equal deleted inserted replaced
8890:ae51d068bbd5 8891:d077c590eb88
1791 } 1791 }
1792 os << ")"; 1792 os << ")";
1793 } 1793 }
1794 else 1794 else
1795 { 1795 {
1796 os << "Diagonal Matrix\n\n";
1796 pr_scale_header (os, scale); 1797 pr_scale_header (os, scale);
1797 1798
1798 // kluge. Get the true width of a number. 1799 // kluge. Get the true width of a number.
1799 int zero_fw; 1800 int zero_fw;
1800 1801
2193 } 2194 }
2194 os << ")"; 2195 os << ")";
2195 } 2196 }
2196 else 2197 else
2197 { 2198 {
2199 os << "Diagonal Matrix\n\n";
2198 pr_scale_header (os, scale); 2200 pr_scale_header (os, scale);
2199 2201
2200 // kluge. Get the true width of a number. 2202 // kluge. Get the true width of a number.
2201 int zero_fw; 2203 int zero_fw;
2202 2204
2228 else 2230 else
2229 os << std::setw (zero_fw) << '0'; 2231 os << std::setw (zero_fw) << '0';
2230 } 2232 }
2231 2233
2232 if (i < nr - 1) 2234 if (i < nr - 1)
2235 os << "\n";
2236 }
2237 }
2238 }
2239 }
2240 }
2241
2242 void
2243 octave_print_internal (std::ostream& os, const PermMatrix& m,
2244 bool pr_as_read_syntax, int extra_indent)
2245 {
2246 octave_idx_type nr = m.rows ();
2247 octave_idx_type nc = m.columns ();
2248
2249 if (nr == 0 || nc == 0)
2250 print_empty_matrix (os, nr, nc, pr_as_read_syntax);
2251 else if (plus_format && ! pr_as_read_syntax)
2252 {
2253 for (octave_idx_type i = 0; i < nr; i++)
2254 {
2255 for (octave_idx_type j = 0; j < nc; j++)
2256 {
2257 OCTAVE_QUIT;
2258
2259 pr_plus_format (os, m(i,j));
2260 }
2261
2262 if (i < nr - 1)
2263 os << "\n";
2264 }
2265 }
2266 else
2267 {
2268 int fw = 2;
2269 double scale = 1.0;
2270 int column_width = fw + 2;
2271 octave_idx_type total_width = nc * column_width;
2272 octave_idx_type max_width = command_editor::terminal_cols ();
2273
2274 if (pr_as_read_syntax)
2275 max_width -= 4;
2276 else
2277 max_width -= extra_indent;
2278
2279 if (max_width < 0)
2280 max_width = 0;
2281
2282 if (free_format)
2283 {
2284 if (pr_as_read_syntax)
2285 os << "[\n";
2286
2287 os << Matrix (m);
2288
2289 if (pr_as_read_syntax)
2290 os << "]";
2291
2292 return;
2293 }
2294
2295 octave_idx_type inc = nc;
2296 if (total_width > max_width && Vsplit_long_rows)
2297 {
2298 inc = max_width / column_width;
2299 if (inc == 0)
2300 inc++;
2301 }
2302
2303 if (pr_as_read_syntax)
2304 {
2305 Array<octave_idx_type> pvec = m.pvec ();
2306 bool colp = m.is_col_perm ();
2307
2308 os << "eye (";
2309 if (colp) os << ":, ";
2310
2311 octave_idx_type col = 0;
2312 while (col < nc)
2313 {
2314 octave_idx_type lim = col + inc < nc ? col + inc : nc;
2315
2316 for (octave_idx_type j = col; j < lim; j++)
2317 {
2318 OCTAVE_QUIT;
2319
2320 if (j == 0)
2321 os << "[ ";
2322 else
2323 {
2324 if (j > col && j < lim)
2325 os << ", ";
2326 else
2327 os << " ";
2328 }
2329
2330 os << pvec (j);
2331 }
2332
2333 col += inc;
2334
2335 if (col >= nc)
2336 os << " ]";
2337 else
2338 os << " ...\n";
2339 }
2340 if (! colp) os << ", :";
2341 os << ")";
2342 }
2343 else
2344 {
2345 os << "Permutation Matrix\n\n";
2346
2347 for (octave_idx_type col = 0; col < nc; col += inc)
2348 {
2349 octave_idx_type lim = col + inc < nc ? col + inc : nc;
2350
2351 pr_col_num_header (os, total_width, max_width, lim, col,
2352 extra_indent);
2353
2354 for (octave_idx_type i = 0; i < nr; i++)
2355 {
2356 os << std::setw (extra_indent) << "";
2357
2358 for (octave_idx_type j = col; j < lim; j++)
2359 {
2360 OCTAVE_QUIT;
2361
2362 os << " ";
2363
2364 os << std::setw (fw) << m(i,j);
2365 }
2366
2367 if (i < nr - 1)
2233 os << "\n"; 2368 os << "\n";
2234 } 2369 }
2235 } 2370 }
2236 } 2371 }
2237 } 2372 }