[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Would you consider this a bug?
In article <firstname.lastname@example.org>,
David Kastrup <email@example.com> wrote:
> Kevin Ivory <Kevin.Ivory@linmpi.mpg.de> writes:
> > Leaving the bug topic - switching to algorithms
> > David Kastrup wrote:
> > > Unfortunately, translating something like
> > >
> > > a[[5,2,3,0,4,1]] = a
> > > into the equivalent
> > > a = a[[3,5,1,2,4,0]]
> > > is not easy to do in the general case.
> > Actually it is: you need a second call to sort. See example below.
> > > some data that needed to be processed in sorted order, the results
> > > needed to be rearranged in original order.
> > >
> > > Something like
> > > s = sort(a)
> > > a = a[s]
> > > process(a)
> > ; a[s] = a ; I still think this a dangerous thing to do.
> > r = sort(s)
> > a = a[r]
> First, it is extremely impolite to send a copy of a followup in the
> newsgroup to the original poster without marking it as such. Now I
> have to type my reply all over again. Double work.
> Second, I refuse to call a significantly time-consuming routine like
> "sort" (O(n log n)) twice without good reason. Especially when a
> simple workaround like writing
> a[s] = a+0
> will do the trick.
Actually I don't think it is a bug. One needs to carefully review how IDL
handles arrays and indices.
If we go back to the original posted question:
> a = [3,4,5]
> a[[2,1,0]] = a
> a will be set to [3,4,3]
Which is correct, based on 'a' being overwritten. This is avoid huge memory
overhead in many cases where the right side equation is complex.
David Kastrup then suggested:
> One has to write
> a[[2,1,0]] = a + 0
> in order to get the more correct seeming [5,4,3].
Which does work, however this is not necessary to get the desired answer.
The following works just fine and follows the access methods shown in
a[[2,1,0]] = a[*]
the IDL manuals, but not fully explained. In every example in the IDL
manuals where left side subscripting is be used, the right hand is subscripted
(even if with only the asteriks) except where left variable is not the same.
So, I do not consider the original question a bug, since the above works just
fine by using [*]. It is also about 5 percent faster on large arrays versus
University Hospitals of Cleveland.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own