comparison src/pr-output.cc @ 4559:802818bfac91

[project @ 2003-10-28 19:13:43 by jwe]
author jwe
date Tue, 28 Oct 2003 19:13:43 +0000
parents 01ee68d18069
children 6cb22b9e3942
comparison
equal deleted inserted replaced
4558:239df9c618ef 4559:802818bfac91
1271 os << "zeros (" << nr << ", " << nc << ")"; 1271 os << "zeros (" << nr << ", " << nc << ")";
1272 } 1272 }
1273 else 1273 else
1274 { 1274 {
1275 os << "[]"; 1275 os << "[]";
1276
1276 if (Vprint_empty_dimensions) 1277 if (Vprint_empty_dimensions)
1277 os << "(" << nr << "x" << nc << ")"; 1278 os << "(" << nr << "x" << nc << ")";
1279 }
1280 }
1281
1282 static void
1283 print_empty_nd_array (std::ostream& os, const dim_vector& dims,
1284 bool pr_as_read_syntax)
1285 {
1286 assert (dims.any_zero ());
1287
1288 if (pr_as_read_syntax)
1289 os << "zeros (" << dims.str (',') << ")";
1290 else
1291 {
1292 os << "[]";
1293
1294 if (Vprint_empty_dimensions)
1295 os << "(" << dims.str () << ")";
1278 } 1296 }
1279 } 1297 }
1280 1298
1281 static void 1299 static void
1282 pr_scale_header (std::ostream& os, double scale) 1300 pr_scale_header (std::ostream& os, double scale)
1486 } 1504 }
1487 1505
1488 #define PRINT_ND_ARRAY(os, nda, NDA_T, ELT_T, MAT_T) \ 1506 #define PRINT_ND_ARRAY(os, nda, NDA_T, ELT_T, MAT_T) \
1489 do \ 1507 do \
1490 { \ 1508 { \
1491 int ndims = nda.ndims (); \ 1509 if (nda.is_empty ()) \
1510 print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); \
1511 else \
1512 { \
1492 \ 1513 \
1493 dim_vector dims = nda.dims (); \ 1514 int ndims = nda.ndims (); \
1494 \ 1515 \
1495 Array<int> ra_idx (ndims, 0); \ 1516 dim_vector dims = nda.dims (); \
1496 \ 1517 \
1497 int m = 1; \ 1518 Array<int> ra_idx (ndims, 0); \
1498 \ 1519 \
1499 for (int i = 2; i < ndims; i++) \ 1520 int m = 1; \
1500 m *= dims(i); \
1501 \ 1521 \
1502 int nr = dims(0); \ 1522 for (int i = 2; i < ndims; i++) \
1503 int nc = dims(1); \ 1523 m *= dims(i); \
1504 \ 1524 \
1505 for (int i = 0; i < m; i++) \ 1525 int nr = dims(0); \
1506 { \ 1526 int nc = dims(1); \
1507 std::string nm = "ans"; \
1508 \ 1527 \
1509 if (m > 1) \ 1528 for (int i = 0; i < m; i++) \
1510 { \ 1529 { \
1511 nm += "(:,:,"; \ 1530 std::string nm = "ans"; \
1512 \ 1531 \
1513 OSSTREAM buf; \ 1532 if (m > 1) \
1533 { \
1534 nm += "(:,:,"; \
1514 \ 1535 \
1515 for (int k = 2; k < ndims; k++) \ 1536 OSSTREAM buf; \
1516 { \
1517 buf << ra_idx(k) + 1; \
1518 \ 1537 \
1519 if (k < ndims - 1) \ 1538 for (int k = 2; k < ndims; k++) \
1520 buf << ","; \ 1539 { \
1521 else \ 1540 buf << ra_idx(k) + 1; \
1522 buf << ")"; \
1523 } \
1524 \ 1541 \
1525 buf << OSSTREAM_ENDS; \ 1542 if (k < ndims - 1) \
1543 buf << ","; \
1544 else \
1545 buf << ")"; \
1546 } \
1526 \ 1547 \
1527 nm += OSSTREAM_STR (buf); \ 1548 buf << OSSTREAM_ENDS; \
1528 \ 1549 \
1529 OSSTREAM_FREEZE (buf); \ 1550 nm += OSSTREAM_STR (buf); \
1530 } \
1531 \ 1551 \
1532 Array<idx_vector> idx (ndims); \ 1552 OSSTREAM_FREEZE (buf); \
1553 } \
1533 \ 1554 \
1534 idx(0) = idx_vector (':'); \ 1555 Array<idx_vector> idx (ndims); \
1535 idx(1) = idx_vector (':'); \
1536 \ 1556 \
1537 for (int k = 2; k < ndims; k++) \ 1557 idx(0) = idx_vector (':'); \
1538 idx(k) = idx_vector (ra_idx(k) + 1); \ 1558 idx(1) = idx_vector (':'); \
1539 \ 1559 \
1540 octave_value page \ 1560 for (int k = 2; k < ndims; k++) \
1541 = MAT_T (Array2<ELT_T> (nda.index (idx), nr, nc)); \ 1561 idx(k) = idx_vector (ra_idx(k) + 1); \
1542 \ 1562 \
1543 page.print_with_name (os, nm); \ 1563 octave_value page \
1564 = MAT_T (Array2<ELT_T> (nda.index (idx), nr, nc)); \
1544 \ 1565 \
1545 if (i < m) \ 1566 page.print_with_name (os, nm); \
1546 NDA_T::increment_index (ra_idx, dims, 2); \ 1567 \
1547 } \ 1568 if (i < m) \
1569 NDA_T::increment_index (ra_idx, dims, 2); \
1570 } \
1571 } \
1548 } \ 1572 } \
1549 while (0) 1573 while (0)
1550 1574
1551 void 1575 void
1552 octave_print_internal (std::ostream& os, const NDArray& nda, 1576 octave_print_internal (std::ostream& os, const NDArray& nda,