Re: Oh No... [message #53587 is a reply to message #53505] |
Wed, 18 April 2007 11:44  |
Foldy Lajos
Messages: 268 Registered: October 2001
|
Senior Member |
|
|
On Wed, 18 Apr 2007, mgalloy@gmail.com wrote:
> On Apr 18, 7:45 am, Paolo Grigis <pgri...@astro.phys.ethz.ch> wrote:
>> FĂ–LDY Lajos wrote:
>>
>>> No, invalid code, with undefined result :-)
>
> I don't think it invalid or undefined (very confusing, yes). a is
> created and used to index itself following the "normal" rules of
> indexing in IDL.
>
> Remember that it is valid to use an index array that has indices out
> of range, they are simply brought back into range:
>
> IDL> b = findgen(10)
> IDL> b[[-1, 20]] = 1
> IDL> print, b
> 1.00000 1.00000 2.00000 3.00000 4.00000
> 5.00000 6.00000
> 7.00000 8.00000 1.00000
>
> You can turn this behavior off with COMPILE_OPT:
>
> IDL> compile_opt strictarrsubs
> IDL> a[(a=2*findgen(10))]=1
> % Array used to subscript array contains out of range subscript: A.
> % Execution halted at: $MAIN$
>
Indexing is OK, but the result of writing to a memory location twice in a
single expression is undefined.
This was the original example:
IDL> a[(a=2*findgen(10))]=1 ;agreed, this is a bit crazy, but hold on
IDL> print,a
1.00000 1.00000 1.00000 6.00000 8.00000
10.0000 1.00000 14.0000 1.00000 1.00000
This is the result in IDL 5.3 sun sparc:
IDL> a[(a=2*findgen(10))]=1 & print, a
1.00000 2.00000 1.00000 6.00000 1.00000
10.0000 1.00000 14.0000 1.00000 1.00000
Which is the correct answer? The well-defined version gives the latter:
IDL> a=(b=2*findgen(10)) & a[b]=1 & print, a
1.00000 2.00000 1.00000 6.00000 1.00000
10.0000 1.00000 14.0000 1.00000 1.00000
You can send a bug report to ITTVIS, and see their opinion.
regards,
lajos
|
|
|