[Changeset] Re: Subscripted assignment issue
David Bateman
David.Bateman at motorola.com
Wed Mar 26 05:45:23 CDT 2008
John W. Eaton wrote:
> On 26-Mar-2008, David Bateman wrote:
>
> | John W. Eaton wrote:
> |
> | > I'm thinking this code needs to be refactored into something like
> | >
> | > if (lhs is empty)
> | > if (rhs is scalar)
> | > resize based on indices
> | > do scalar assignment
> | > else if (rhs is vector)
> | > resize based on indices and vector length
> | > do vector assignment
> | > else
> | > resize based on indices and dimensions
> | > do general case
> | > else
> | > if (rhs is [])
> | > maybe delete elements
> | > else if (rhs is scalar)
> | > do scalar assignment
> | > else if (rhs is vector)
> | > do vector assignment
> | > else
> | > do general case
> | >
> |
> | I think the attached is a step in that direction, and appears to work
> | for the test cases and a few others I added. Note the behavior of matlab
> | for things like
> |
> | clear a; a(:,:,1) = 1:4
> | clear a; a(:,:,1)=[1:4]'
> | clear a; a(:,:,1)=reshape(1:4,[1,1,4])
> | clear a; a(1,:,:) = 1:4
> | clear a; a(1,:,:) = [1:4]'
> | clear a; a(1,:,:) = reshape (1:4,[1,1,4])
> |
> | Matlab has some strange ideas about how row vectors should be treated!!!
>
> Yes, the cases with the 3-d RHS values are somewhat surprising.
>
> | In any case my patch duplicates matlab's behavior for these.
>
> I applied it. Thanks for looking at this.
>
> I can also apply this to the release-3-0-x branch. Is that OK?
>
> Thanks,
>
> jwe
>
>
Ok, here is the updated changeset that also addresses the case
a(1,:,:,:) = reshape(1:4,[1,1,4])
It seems that how matlab handles cases like the above is that
1) If the number of element defined by the indices on the LHS (colon
counts as 1) is 1, and
2) There are as many colons on the LHS as dimensions on the RHS, then
3) Copy the dimensions of the RHS into the colons on the LHS, else
4) The vector is assigned in the direction of the first colon.
Note that this is strange as consider
clear a; a(1,:,:,:) = reshape(1:4,[1,1,4])
against
clear a; a(1,:,:,:) = reshape(1:4,[1,4,1])
In the first case it results in a vector along the 4th dimension,
whereas in the second case the trailing singleton is dropped on the RHS
before the assignment and therefore the result of the second assignment
is a row vector.
The changeset implements the above behavior, refactors some of the test
code to be make it easier to find failing tests and adds additional
tests. Please rollback my previous changeset before applying this one.
D.
--
David Bateman David.Bateman at motorola.com
Motorola Labs - Paris +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob)
91193 Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax)
The information contained in this communication has been classified as:
[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch7825
Url: https://www.cae.wisc.edu/pipermail/bug-octave/attachments/20080326/f7031dde/attachment-0001.ksh
More information about the Bug-octave
mailing list