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

Home » Public Forums » archive » Re: about replicate_inplace
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: about replicate_inplace [message #35899 is a reply to message #35898] Tue, 22 July 2003 15:25 Go to previous messageGo to previous message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Tue, 22 Jul 2003 13:37:15 -0700, Xiaoying Jin wrote:

> Hi, there,
>
> I am really puzzled by the IDL usage of memory. Here is an example:
>
> T = systime(1)
> b = bytarr(nreg, nreg)
> print, systime(1) - T, ' seconds.'
>
> T = systime(1)
> replicate_inplace, b, 0
> print, systime(1) - T, ' seconds.'
>
> In the example, the first part is to create an array with values 0. The
> second part is to assign each element in the array the value 0. The
> running time for the first part is 0.12sec, while the running time for
> the second part is 0.37sec.
>
> My question is: since the first part needs to allocate the memory and
> assign values to elements, it should take longer time than the second
> part. In IDL help, it says: "REPLICATE_INPLACE can be faster and use
> less memory than the IDL function REPLICATE or the IDL array notation
> for large arrays that already exist. " However, why the first part takes
> less time?
>
> If this is really the case in IDL, then it's better to allocate a new
> array than to use the current array. It's really strange for me.
>


If you want that array to be full of zeroes, then it looks like yes,
but I submit this for your inspection:

nreg=2000
T = systime(1)
b = bytarr(nreg, nreg)
b[*]=1b
print, systime(1) - T, ' seconds, BYTARR and [*]'

T = systime(1)
b = bytarr(nreg, nreg)
replicate_inplace, b, 1b
print, systime(1) - T, ' seconds, BYTARR and REPLICATE_INPLACE'

T = systime(1)
replicate_inplace, b, 1b
print, systime(1) - T, ' seconds, REPLICATE_INPLACE'

T = systime(1)
b = make_array(/BYTE,nreg,nreg,VALUE=1b)
print, systime(1) - T, ' seconds, MAKE_ARRAY'

0.15847003 seconds, BYTARR and [*]
0.027868986 seconds, BYTARR and REPLICATE_INPLACE
0.016924024 seconds, REPLICATE_INPLACE
0.021242023 seconds, MAKE_ARRAY

Looks like REPLICATE_INPLACE is the fastest way to populate an
existing array with 1's (or some arbitrary value, for that matter).
If you have to make the array in the first place, MAKE_ARRAY is your
best bet. Using [*] or other lhs index range notations is, as has
been discussed here before, a real performance penalty, since it
implies first creating an implicit array of indices (which in this
case just span from [0 - (2000^2-1)]). This can get you into memory
trouble too, since it amounts to temporary doubling the memory usage
for a (numerical, anyway) array.

JD
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Leading zeros in Format
Next Topic: IDL 6.0 is released!

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

Current Time: Fri Oct 10 16:58:57 PDT 2025

Total time taken to generate the page: 0.24164 seconds