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

Home » Public Forums » archive » Unable to allocate memory: to make an array. Not enough space
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
Unable to allocate memory: to make an array. Not enough space [message #91764] Mon, 24 August 2015 13:43 Go to next message
fd_luni is currently offline  fd_luni
Messages: 66
Registered: January 2013
Member
Hi

I have a 4D array A = [240,256,256,10] and I call this array into FOR loops as a 3D array.

Data = A

FOR k=0L, 9 DO BEGIN ;looping over levels
A = A[*,*,*,k]

FOR l=0L,n_elements(N)-1 DO BEGIN

FOR iter=1L,1 DO BEGIN

ENDFOR
ENDFOR
A = Data
ENDFOR

I set the A=Data because in the next level (k=1) I wanted the matrix to be 4D otherwise it's 3D [240,256,256] and I've got the following error. 'Attempt to subscript ARRAYSOURCE with K is out of range.'

Once I set the A = Data I got this error 'Unable to allocate memory: to make an array. Not enough space'. Can anyone please help with this?
Re: Unable to allocate memory: to make an array. Not enough space [message #91765 is a reply to message #91764] Mon, 24 August 2015 14:13 Go to previous messageGo to next message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
On Monday, August 24, 2015 at 3:43:34 PM UTC-5, fd_...@mail.com wrote:
> Hi
>
> I have a 4D array A = [240,256,256,10] and I call this array into FOR loops as a 3D array.
>
> Data = A
>
> FOR k=0L, 9 DO BEGIN ;looping over levels
> A = A[*,*,*,k]
>
> FOR l=0L,n_elements(N)-1 DO BEGIN
>
> FOR iter=1L,1 DO BEGIN
>
> ENDFOR
> ENDFOR
> A = Data
> ENDFOR
>
> I set the A=Data because in the next level (k=1) I wanted the matrix to be 4D otherwise it's 3D [240,256,256] and I've got the following error. 'Attempt to subscript ARRAYSOURCE with K is out of range.'
>
> Once I set the A = Data I got this error 'Unable to allocate memory: to make an array. Not enough space'. Can anyone please help with this?

At that point, you're asking for 2 copies of the 4D array -- one in Data and one in A. And you don't have enough memory to do that!

What you want to do is change this line:

A = A[*,*,*,k]

to

A = Data[*,*,*,k]

and then completely get rid of the "A = Data" at the end. This way, you only ever need one copy of the 4D array at a time, and A just gets assigned to the relevant slice.

(incidentally, is there a good reason why you can't operate directly on the 4D array, and completely avoid making a copy of the 3D slice?)

-Jeremy.
Re: Unable to allocate memory: to make an array. Not enough space [message #91772 is a reply to message #91765] Tue, 25 August 2015 01:48 Go to previous messageGo to next message
g.nacarts is currently offline  g.nacarts
Messages: 148
Registered: November 2013
Senior Member
Thanks a lot Jeremy. Your explanation makes perfect sense.

Well, the other arrays enclosed in the FOR loops are 3D that's way I wanted to do it like that.

Is there is another way more efficient?
Re: Unable to allocate memory: to make an array. Not enough space [message #91775 is a reply to message #91772] Tue, 25 August 2015 07:02 Go to previous message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
On Tuesday, August 25, 2015 at 3:48:03 AM UTC-5, g.na...@gmail.com wrote:
> Thanks a lot Jeremy. Your explanation makes perfect sense.
>
> Well, the other arrays enclosed in the FOR loops are 3D that's way I wanted to do it like that.
>
> Is there is another way more efficient?

It depends on what kind of processing you're doing inside those for loops. Generally, if you can find a way of doing an operation on the full array instead of using a for loop, it will run faster (that's especially true if you are looping a large number of times -- here you only have 10 iterations, so it's not such a big deal), but it completely depends on the type of operations you are doing. Also, if you are running into memory constraints (like you are), then that might prevent you from operating on the whole array at once and you might need to operate on individual slices, like you are.

Cheers,
-Jeremy.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Plot and Legend problem
Next Topic: Mean = NaN if NaN present

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

Current Time: Wed Oct 08 13:29:42 PDT 2025

Total time taken to generate the page: 0.40551 seconds