Mercurial > hg > octave-jordi
changeset 4655:c8829691db47
[project @ 2003-11-24 21:24:37 by jwe]
author | jwe |
---|---|
date | Mon, 24 Nov 2003 21:24:37 +0000 |
parents | a9b22513b7a6 |
children | e3da702f7502 |
files | liboctave/ChangeLog liboctave/dim-vector.h liboctave/so-array.h src/ChangeLog src/ov-fcn-handle.cc src/ov-fcn-handle.h src/pr-output.cc src/pr-output.h |
diffstat | 8 files changed, 122 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,7 @@ +2003-11-24 John W. Eaton <jwe@bevo.che.wisc.edu> + + * dim-vector.h (dim_vector::all_ones): New function. + 2003-11-23 John W. Eaton <jwe@bevo.che.wisc.edu> * idx-vector.h (idx_vector::orig_empty): Check orig_dims for
--- a/liboctave/dim-vector.h +++ b/liboctave/dim-vector.h @@ -266,6 +266,12 @@ return retval; } + bool + all_ones (void) const + { + return (num_ones () == length ()); + } + // This is the number of elements that a matrix with this dimension // vector would have, NOT the number of dimensions (elements in the // dimension vector).
--- a/liboctave/so-array.h +++ b/liboctave/so-array.h @@ -54,10 +54,10 @@ ~streamoff_array (void) { } - streamoff_array& operator = (const streamoff_array& a) + streamoff_array& operator = (const streamoff_array& sa) { - if (this != &a) - ArrayN<std::streamoff>::operator = (a); + if (this != &sa) + ArrayN<std::streamoff>::operator = (sa); return *this; }
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,12 @@ 2003-11-24 John W. Eaton <jwe@bevo.che.wisc.edu> + * pr-output.h (octave_fcn_handle::print_as_scalar): Delete. + + * pr-output.cc (octave_print_internal): New version for + ArrayN<std::string> objects. + * pr-output.h: Provide decl. + * ov-fcn-handle.cc (octave_fcn_handle::print_raw): Use it. + * OPERATORS/op-fcn-handle.cc: New file. * Makefile.in (OP_XSRC): Add it to the list.
--- a/src/ov-fcn-handle.cc +++ b/src/ov-fcn-handle.cc @@ -152,14 +152,8 @@ void octave_fcn_handle::print_raw (std::ostream& os, bool pr_as_read_syntax) const { - dim_vector dv = matrix.dims (); - os << "<" << dv.str () << " function handle object>"; - -#if 0 - indent (os); octave_print_internal (os, name_array (), pr_as_read_syntax, - current_print_indent_level (), true); -#endif + current_print_indent_level ()); } octave_value
--- a/src/ov-fcn-handle.h +++ b/src/ov-fcn-handle.h @@ -162,8 +162,6 @@ ArrayN<std::string> name_array (void) const { return matrix.names (); } - bool print_as_scalar (void) const { return true; } - void print (std::ostream& os, bool pr_as_read_syntax = false) const; void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
--- a/src/pr-output.cc +++ b/src/pr-output.cc @@ -33,6 +33,7 @@ #include <iostream> #include <string> +#include "Array-util.h" #include "CMatrix.h" #include "Range.h" #include "cmd-edit.h" @@ -1527,6 +1528,8 @@ \ for (int i = 0; i < m; i++) \ { \ + OCTAVE_QUIT; \ + \ std::string nm = "ans"; \ \ if (m > 1) \ @@ -1978,6 +1981,97 @@ } } +void +octave_print_internal (std::ostream& os, const ArrayN<std::string>& nda, + bool pr_as_read_syntax, int extra_indent) +{ + // XXX FIXME XXX -- this mostly duplicates the code in the + // PRINT_ND_ARRAY macro. + + if (nda.is_empty ()) + print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); + else if (nda.length () == 1) + { + os << nda(0); + } + else + { + int ndims = nda.ndims (); + + dim_vector dims = nda.dims (); + + Array<int> ra_idx (ndims, 0); + + int m = 1; + + for (int i = 2; i < ndims; i++) + m *= dims(i); + + int nr = dims(0); + int nc = dims(1); + + for (int i = 0; i < m; i++) + { + std::string nm = "ans"; + + if (m > 1) + { + nm += "(:,:,"; + + OSSTREAM buf; + + for (int k = 2; k < ndims; k++) + { + buf << ra_idx(k) + 1; + + if (k < ndims - 1) + buf << ","; + else + buf << ")"; + } + + buf << OSSTREAM_ENDS; + + nm += OSSTREAM_STR (buf); + + OSSTREAM_FREEZE (buf); + } + + Array<idx_vector> idx (ndims); + + idx(0) = idx_vector (':'); + idx(1) = idx_vector (':'); + + for (int k = 2; k < ndims; k++) + idx(k) = idx_vector (ra_idx(k) + 1); + + Array2<std::string> page (nda.index (idx), nr, nc); + + // XXX FIXME XXX -- need to do some more work to put these + // in neatly aligned columns... + + int n_rows = page.rows (); + int n_cols = page.cols (); + + os << nm << " =\n\n"; + + for (int ii = 0; ii < n_rows; ii++) + { + for (int jj = 0; jj < n_cols; jj++) + os << " " << page(ii,jj); + + os << "\n"; + } + + if (i < m - 1) + os << "\n"; + + if (i < m) + increment_index (ra_idx, dims, 2); + } + } +} + extern void octave_print_internal (std::ostream&, const Cell&, bool, int, bool) {
--- a/src/pr-output.h +++ b/src/pr-output.h @@ -27,6 +27,7 @@ #include "oct-cmplx.h" +template <typename T> class ArrayN; class ComplexMatrix; class ComplexNDArray; class Matrix; @@ -88,12 +89,17 @@ bool pr_as_string = false); extern void -octave_print_internal (std::ostream& os, const charNDArray& chm, +octave_print_internal (std::ostream& os, const charNDArray& nda, bool pr_as_read_syntax = false, int extra_indent = 0, bool pr_as_string = false); extern void +octave_print_internal (std::ostream& os, const ArrayN<std::string>& sa, + bool pr_as_read_syntax = false, + int extra_indent = 0); + +extern void octave_print_internal (std::ostream& os, const Cell& cell, bool pr_as_read_syntax = false, int extra_indent = 0,