From maintainers-request at octave dot org Fri Aug 27 10:13:33 2004 Subject: Re: std in NDArrays From: David Bateman To: "John W. Eaton" Cc: octave maintainers mailing list Date: Fri, 27 Aug 2004 17:09:18 +0200 --opJtzjQTFsWo+cga Content-Type: text/plain; charset=us-ascii Content-Disposition: inline According to John W. Eaton (on 08/26/04): > On 26-Aug-2004, David Bateman wrote: > > | Thanks for thr ToDo list. Anyone else want to attack some of these? > > I intend to work on the fwrite/fread problems first. John, As I believe the bitcmp, bitget, bitset issues are completely addressed by my last patch (patch.bitfcns20040826-3), I attacked the problem of "format hex", etc. I also at the same time fixed up the column alignment of the integer types.. Please find the patch and change log attached... Since you are attacking the fread issues and together with my patch for bit{cmp|get|set}, the only issue remaining on your todo list for a 2.1.58 release is the mixed type double scalar and integer operations. Not sure what you want here though.. D. -- David Bateman David dot Bateman at motorola dot com Motorola CRM +33 1 69 35 48 04 (Ph) Parc Les Algorithmes, Commune de St Aubin +33 1 69 35 77 01 (Fax) 91193 Gif-Sur-Yvette FRANCE The information contained in this communication has been classified as: [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola Confidential Proprietary --opJtzjQTFsWo+cga Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=changelog-pr-output 2004-08-27 David Bateman * pr-output.cc (PRINT_CONV): change types from octave_int8 and octave_uint8 to octave_int8_t and octave_uint8_t. (template static inline void pr_int(std::ostream, T, int)): New template function to print formatted integer types. Instantiate it for all of the integer types. (octave_print_internal (std::ostream, const intNDArray&, bool, int): Adapt to use the pr_int function, and align output up in columns. (octave_print_internal (std::ostream, const octave_int&, bool): Use the pr_int function. --opJtzjQTFsWo+cga Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="patch.pr-output" *** src/pr-output.cc.orig4 2004-08-06 11:44:02.000000000 +0200 --- src/pr-output.cc 2004-08-27 16:25:13.000000000 +0200 *************** *** 2113,2127 **** typedef T2 print_conv_type; \ } ! PRINT_CONV (octave_int8, octave_int16); ! PRINT_CONV (octave_uint8, octave_uint16); #undef PRINT_CONV template void octave_print_internal (std::ostream& os, const intNDArray& nda, ! bool pr_as_read_syntax, int) { // XXX FIXME XXX -- this mostly duplicates the code in the // PRINT_ND_ARRAY macro. --- 2113,2172 ---- typedef T2 print_conv_type; \ } ! PRINT_CONV (octave_int8_t, octave_int16_t); ! PRINT_CONV (octave_uint8_t, octave_uint16_t); #undef PRINT_CONV template + static inline void + pr_int (std::ostream& os, T d, int fw = 0) + { + unsigned char * tmpi = (unsigned char *) &d; + + if (hex_format) + { + char ofill = os.fill ('0'); + + std::ios::fmtflags oflags + = os.flags (std::ios::right | std::ios::hex); + + //if (hex_format > 1 || oct_mach_info::big_chief) + if (hex_format > 1) + { + for (size_t i = 0; i < sizeof (T); i++) + os << std::setw (2) << static_cast (tmpi[i]); + } + else + { + for (int i = sizeof (T) - 1; i >= 0; i--) + os << std::setw (2) << static_cast (tmpi[i]); + } + + os.fill (ofill); + os.setf (oflags); + } + else if (bit_format) + { + if (bit_format > 1) + { + for (size_t i = 0; i < sizeof (T); i++) + PRINT_CHAR_BITS_SWAPPED (os, tmpi[i]); + } + else + { + for (int i = sizeof (T) - 1; i >= 0; i--) + PRINT_CHAR_BITS (os, tmpi[i]); + } + } + else + os << std::setw (fw) << typename octave_print_conv::print_conv_type (d); + } + + template void octave_print_internal (std::ostream& os, const intNDArray& nda, ! bool pr_as_read_syntax, int extra_indent) { // XXX FIXME XXX -- this mostly duplicates the code in the // PRINT_ND_ARRAY macro. *************** *** 2130,2136 **** print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); else if (nda.length () == 1) { ! os << typename octave_print_conv::print_conv_type (nda(0)); } else { --- 2175,2181 ---- print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); else if (nda.length () == 1) { ! pr_int (os, nda(0).value()); } else { *************** *** 2148,2160 **** 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; --- 2193,2238 ---- int nr = dims(0); int nc = dims(1); ! int fw = 0; ! if (hex_format) ! fw = nda(0).nbits() >> 2; ! else if (bit_format) ! fw = nda(0).nbits(); ! else { ! bool sign = false; ! int digits = 0; ! ! for (int i = 0; i < dims.numel(); i++) ! { ! int new_digits = static_cast ! (floor (log10 (double (abs (nda(i).value()))) + 1.0)); + if (new_digits > digits) + digits = new_digits; + + sign = (sign || (abs (nda(i).value()) != nda(i).value()) + ? true : false); + } + fw = digits + (sign ? 1 : 0); + } + + int column_width = fw + 2; + int total_width = nc * column_width; + int max_width = command_editor::terminal_cols () - extra_indent; + int inc = nc; + if (total_width > max_width && Vsplit_long_rows) + { + inc = max_width / column_width; + if (inc == 0) + inc++; + } + + for (int i = 0; i < m; i++) + { if (m > 1) { ! std::string nm = "ans(:,:,"; OSSTREAM buf; *************** *** 2173,2178 **** --- 2251,2258 ---- nm += OSSTREAM_STR (buf); OSSTREAM_FREEZE (buf); + + os << nm << " =\n\n"; } Array idx (ndims); *************** *** 2185,2204 **** Array2 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 << " " << typename octave_print_conv::print_conv_type (page(ii,jj)); ! os << "\n"; } if (i < m - 1) --- 2265,2293 ---- Array2 page (nda.index (idx), nr, nc); int n_rows = page.rows (); int n_cols = page.cols (); ! for (int col = 0; col < n_cols; col += inc) { ! int lim = col + inc < n_cols ? col + inc : n_cols; ! pr_col_num_header (os, total_width, max_width, lim, col, ! extra_indent); ! ! for (int ii = 0; ii < n_rows; ii++) ! { ! os << std::setw (extra_indent) << ""; ! ! for (int jj = col; jj < lim; jj++) ! { ! OCTAVE_QUIT; ! os << " "; ! pr_int (os, (page(ii,jj)).value(), fw); ! } ! if ((ii < n_rows - 1) || (i < m -1)) ! os << "\n"; ! } } if (i < m - 1) *************** *** 2213,2218 **** --- 2302,2331 ---- // XXX FIXME XXX -- this is not the right spot for this... template void + pr_int (std::ostream&, octave_int8_t, int); + + template void + pr_int (std::ostream&, octave_int16_t, int); + + template void + pr_int (std::ostream&, octave_int32_t, int); + + template void + pr_int (std::ostream&, octave_int64_t, int); + + template void + pr_int (std::ostream&, octave_uint8_t, int); + + template void + pr_int (std::ostream&, octave_uint16_t, int); + + template void + pr_int (std::ostream&, octave_uint32_t, int); + + template void + pr_int (std::ostream&, octave_uint64_t, int); + + template void octave_print_internal (std::ostream&, const intNDArray&, bool, int); *************** *** 2248,2256 **** void octave_print_internal (std::ostream& os, const octave_int& val, bool) { ! // XXX FIXME XXX -- we need to handle various formats here... ! ! os << typename octave_print_conv >::print_conv_type (val); } // XXX FIXME XXX -- this is not the right spot for this... --- 2361,2367 ---- void octave_print_internal (std::ostream& os, const octave_int& val, bool) { ! pr_int (os, val.value()); } // XXX FIXME XXX -- this is not the right spot for this... --opJtzjQTFsWo+cga--