Unable to allocate memory: to make an array. Not enough space [message #91764] |
Mon, 24 August 2015 13:43  |
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   |
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 #91775 is a reply to message #91772] |
Tue, 25 August 2015 07:02  |
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.
|
|
|