From bug-octave-request at bevo dot che dot wisc dot edu Tue Nov 13 13:21:47 2001 Subject: array indexed by matrix returns wrong shape From: "John W. Eaton" To: "Andre L." Cc: bug-octave at bevo dot che dot wisc dot edu Date: Tue, 13 Nov 2001 13:20:41 -0600 On 13-Nov-2001, Andre L. wrote: | Bug report for Octave 2.1.33 configured for %OCTAVE_CANONICAL_HOST_TYPE% | (version that ships with RedHat 7.1) | | Description: | ----------- | | The problem is demonstrated by the following code: | | k = [4 3 2 1]; | a = [1 2; 3 4]; | foo = k(a); | | foo winds up being a 1x4 array, although it seems like 2x2 | is more logical. (I discovered this porting some code | originally written using Matlab5 which returns 2x2.) I'm not sure what the correct result is in this case. Why is it more logical that the shape is determined by the index rather than the shape of the object being indexed? In any case, I'm somewhat reluctant to copy Matlab exactly in this area since it also does this: >> x = [1,2,3]; >> x([3,1]) ans = 3 1 >> x([3;1]) ans = 3 1 That is, the shape of the index matters unless one of the dimensions happens to be 1. This seems like a bad inconsistency to me, in the same class as the diag() bug: diag (x) => matrix with x on diagonal if x happens to be a vector OR diagonal elements of x if x happens to be a matrix These kinds of inconsistencies can result in quite puzzling and possibly hard to find bugs (everything seems to be working fine until the data changes, and then suddenly some obscure code mysteriously fails). Are you sure you want them in the languages you use? And yes, Octave does have the diag() bug. Any ideas about the best way to fix that? jwe ------------------------------------------------------------- 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 -------------------------------------------------------------