From bug-octave-request at bevo dot che dot wisc dot edu Sat Feb 14 16:33:35 2004 Subject: SQUEEZE returns result with less than two dimensions From: "John W. Eaton" To: Schloegl Alois Cc: bug-octave at bevo dot che dot wisc dot edu Date: Sat, 14 Feb 2004 16:26:52 -0600 On 14-Feb-2004, Schloegl Alois wrote: | Usually, all data elements have at least two dimensions, (i.e. rows | and columns) For scalars, both are 1, for vectors either the number | of rows or columns is 1. | | But the result of squeeze behaves differently. In case the result of | SQUEEZE is a scalar or vector, rows and columns can not be obtained | for this element. This is an inconsistancy. Please try the following patch. Thanks, jwe liboctave/ChangeLog: 2004-02-14 John W. Eaton * Array.cc (Array::squeeze): Always return an array with at least two dimensions. src/ChangeLog: 2004-02-14 John W. Eaton * ov-base-scalar.h (octave_base_scalar::squeeze): New function. Index: liboctave/Array.cc =================================================================== RCS file: /usr/local/cvsroot/octave/liboctave/Array.cc,v retrieving revision 1.101 diff -u -r1.101 Array.cc --- liboctave/Array.cc 13 Feb 2004 22:13:52 -0000 1.101 +++ liboctave/Array.cc 14 Feb 2004 22:20:42 -0000 at @ -76,10 +76,35 @@ if (dims_changed) { - if (k == 0) - new_dimensions = dim_vector (1); - else - new_dimensions.resize (k); + switch (k) + { + case 0: + new_dimensions = dim_vector (1, 1); + break; + + case 1: + { + int tmp = new_dimensions(0); + + new_dimensions.resize (2); + + if (dimensions(0) == 1) + { + new_dimensions(0) = 1; + new_dimensions(1) = tmp; + } + else + { + new_dimensions(0) = tmp; + new_dimensions(1) = 1; + } + } + break; + + default: + new_dimensions.resize (k); + break; + } retval.make_unique (); Index: src/ov-base-scalar.h =================================================================== RCS file: /usr/local/cvsroot/octave/src/ov-base-scalar.h,v retrieving revision 1.16 diff -u -r1.16 ov-base-scalar.h --- src/ov-base-scalar.h 25 Nov 2003 05:41:36 -0000 1.16 +++ src/ov-base-scalar.h 14 Feb 2004 22:20:54 -0000 at @ -59,6 +59,8 @@ ~octave_base_scalar (void) { } + octave_value squeeze (void) const { return scalar; } + octave_value subsref (const std::string& type, const std::list& idx); ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------