comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Do you find this weird too?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Do you find this weird too? [message #56844] Mon, 19 November 2007 15:38
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On Nov 19, 4:01 am, Allan Whiteford
<allan.rem...@phys.remove.strath.ac.remove.uk> wrote:
> A compile option to turn this behaviour off might be a good compromise.

Good idea. It's called strictarrsubs:

IDL> a = findgen(20)
IDL> print, a[[-1, 2, 20]]
0.00000 2.00000 19.0000
IDL> compile_opt strictarrsubs
IDL> print, a[[-1, 2, 20]]
% Array used to subscript array contains out of range subscript: A.
% Execution halted at: $MAIN$

Mike
--
www.michaelgalloy.com
Tech-X Corporation
Software Developer II
Re: Do you find this weird too? [message #56848 is a reply to message #56844] Mon, 19 November 2007 06:00 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Allan Whiteford writes:

> Can anyone post an example of code where this feature is useful?

Well, I just point out that it eliminates having to use
the > and < operators, which you point out you COULD use
if you were concerned about this. :-)

Ray Sterner (JHUAPL) pointed out to me once why this was
useful to him, and why he relied on it all the time.
But I never have been able to remember the reason.
I don't think I have ever run into it as a problem
in actual coding.

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Do you find this weird too? [message #56850 is a reply to message #56848] Mon, 19 November 2007 03:01 Go to previous message
Allan Whiteford is currently offline  Allan Whiteford
Messages: 117
Registered: June 2006
Senior Member
Lasse Clausen wrote:
> On 19 Nov, 10:36, Allan Whiteford
> <allan.rem...@phys.remove.strath.ac.remove.uk> wrote:
>
>> Lasse,
>>
>> From "Using arrays as subscripts":
>>
>> "Clipping
>> If an element of the subscript array is less than or equal to zero, the
>> first element of the subscripted array is selected. If an element of the
>> subscript array is greater than or equal to the last subscript in the
>> subscripted array, the last element is selected. "
>>
>> this is what it's supposed to do although I've never found any kind of
>> use for it.
>>
>> You can say scary things like:
>>
>> a=findgen(50)
>> a[[100]]=7 ; not the same as a[100]=7
>> print,a[49]
>>
>> for me, it throws away all the nice error checking you thought you had
>> for arrays overrunning.
>>
>> Thanks,
>>
>> Allan
>>
>> Lasse Clausen wrote:
>>
>>> Hi there,
>>
>>> hope this gets through to you guys, now with all the spam and whatnot.
>>> Anywho, maybe this has come up before, here is some code
>>
>>> aa = randomu(12L, 200, 100)
>>> ff = findgen(100)
>>> maxs = max(aa, maxind, dimension=2)
>>> print, maxind[0:10]
>>> help, ff[maxind[0:10]]
>>> plot, ff[maxind[0:10]]
>>
>>> Now I find this weird, because maxind is an array of longs clearly
>>> bigger than the size of ff but IDL does not complain and plots
>>> something (btw not what I want but this is solved with array_indices).
>>> Is this something to do with the fact that maxind is a 1D
>>> representation of 2D array indices? I hope it is because otherwise why
>>> does IDL not fall over complaining that maxind[0], which on my machine
>>> is 19200, is bigger than the size of ff.
>>
>>> Mhmm
>>
>>> print, ff[maxind[0]]
>>
>>> falls over
>>
>>> print, ff[maxind[0:1]]
>>
>>> doesn't.
>>
>>> btw print, !version
>>> { x86 linux unix linux 6.2 Jun 20 2005 32 64}
>>
>>> Cheers
>>> Lasse
>
>
> What the...?! Well, I guess somebody thought this was a good idea.
> Makes no sense to me since you could achieve the same behaviour using
> the < or > operator. Subscripting an array with an index smaller than
> zero or bigger than the size of the array is just wrong and should
> produce an error.
>
> But thanks, I will keep this useful fact in mind.
>
> Cheers
> Lasse

Lasse,

I agree completely.

It's really scary: now you need to go back and check all the code you
thought was correct because IDL throws errors on bad subscript values so
no need to check for errors there... or so you thought!

I guess it's hard to change now since legacy code would break (although,
I rather suspect any code that breaks would be because it's always been
wrong rather than because it's relying on this behaviour).

A compile option to turn this behaviour off might be a good compromise.

Can anyone post an example of code where this feature is useful?

Thanks,

Allan
Re: Do you find this weird too? [message #56851 is a reply to message #56850] Mon, 19 November 2007 02:45 Go to previous message
lasse is currently offline  lasse
Messages: 48
Registered: February 2007
Member
On 19 Nov, 10:36, Allan Whiteford
<allan.rem...@phys.remove.strath.ac.remove.uk> wrote:
> Lasse,
>
> From "Using arrays as subscripts":
>
> "Clipping
> If an element of the subscript array is less than or equal to zero, the
> first element of the subscripted array is selected. If an element of the
> subscript array is greater than or equal to the last subscript in the
> subscripted array, the last element is selected. "
>
> this is what it's supposed to do although I've never found any kind of
> use for it.
>
> You can say scary things like:
>
> a=findgen(50)
> a[[100]]=7 ; not the same as a[100]=7
> print,a[49]
>
> for me, it throws away all the nice error checking you thought you had
> for arrays overrunning.
>
> Thanks,
>
> Allan
>
> Lasse Clausen wrote:
>> Hi there,
>
>> hope this gets through to you guys, now with all the spam and whatnot.
>> Anywho, maybe this has come up before, here is some code
>
>> aa = randomu(12L, 200, 100)
>> ff = findgen(100)
>> maxs = max(aa, maxind, dimension=2)
>> print, maxind[0:10]
>> help, ff[maxind[0:10]]
>> plot, ff[maxind[0:10]]
>
>> Now I find this weird, because maxind is an array of longs clearly
>> bigger than the size of ff but IDL does not complain and plots
>> something (btw not what I want but this is solved with array_indices).
>> Is this something to do with the fact that maxind is a 1D
>> representation of 2D array indices? I hope it is because otherwise why
>> does IDL not fall over complaining that maxind[0], which on my machine
>> is 19200, is bigger than the size of ff.
>
>> Mhmm
>
>> print, ff[maxind[0]]
>
>> falls over
>
>> print, ff[maxind[0:1]]
>
>> doesn't.
>
>> btw print, !version
>> { x86 linux unix linux 6.2 Jun 20 2005 32 64}
>
>> Cheers
>> Lasse

What the...?! Well, I guess somebody thought this was a good idea.
Makes no sense to me since you could achieve the same behaviour using
the < or > operator. Subscripting an array with an index smaller than
zero or bigger than the size of the array is just wrong and should
produce an error.

But thanks, I will keep this useful fact in mind.

Cheers
Lasse
Re: Do you find this weird too? [message #56852 is a reply to message #56851] Mon, 19 November 2007 02:36 Go to previous message
Allan Whiteford is currently offline  Allan Whiteford
Messages: 117
Registered: June 2006
Senior Member
Lasse,

From "Using arrays as subscripts":

"Clipping
If an element of the subscript array is less than or equal to zero, the
first element of the subscripted array is selected. If an element of the
subscript array is greater than or equal to the last subscript in the
subscripted array, the last element is selected. "

this is what it's supposed to do although I've never found any kind of
use for it.

You can say scary things like:

a=findgen(50)
a[[100]]=7 ; not the same as a[100]=7
print,a[49]

for me, it throws away all the nice error checking you thought you had
for arrays overrunning.

Thanks,

Allan

Lasse Clausen wrote:
> Hi there,
>
> hope this gets through to you guys, now with all the spam and whatnot.
> Anywho, maybe this has come up before, here is some code
>
> aa = randomu(12L, 200, 100)
> ff = findgen(100)
> maxs = max(aa, maxind, dimension=2)
> print, maxind[0:10]
> help, ff[maxind[0:10]]
> plot, ff[maxind[0:10]]
>
> Now I find this weird, because maxind is an array of longs clearly
> bigger than the size of ff but IDL does not complain and plots
> something (btw not what I want but this is solved with array_indices).
> Is this something to do with the fact that maxind is a 1D
> representation of 2D array indices? I hope it is because otherwise why
> does IDL not fall over complaining that maxind[0], which on my machine
> is 19200, is bigger than the size of ff.
>
> Mhmm
>
> print, ff[maxind[0]]
>
> falls over
>
> print, ff[maxind[0:1]]
>
> doesn't.
>
> btw print, !version
> { x86 linux unix linux 6.2 Jun 20 2005 32 64}
>
> Cheers
> Lasse
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: NaN Magic Bingo!
Next Topic: BUG REPORT: MIN_CURVE_SURF

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 15:54:41 PDT 2025

Total time taken to generate the page: 0.72044 seconds