help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Structures and tensors


From: Peter Cloetens
Subject: Re: Structures and tensors
Date: Wed, 2 Aug 2006 21:57:19 +0200


On Aug 2, 2006, at 7:30 PM, Jordi Gutierrez Hermoso wrote:

On 02/08/06, Peter Cloetens <address@hidden> wrote:
Then I rewrote everything with cells, where each element of the cell
array corresponds to 1 matrix. This improved the speed very considerably.

I think I'm having similar issues right now with some weather
equations. Any idea what the order of magnitude of the improvement is?

As shown in the previous posts, the difference can be very, very significant.
For example:
With a 3D array:
b=zeros(1024,1024,100);a=rand(1024);tic;for k=1:100;b(:,:,k)=a;end;toc
ans = 44.664
With cells:
b=cell(100,1);a=rand(1024);tic;for k=1:100;b{k}=a;end;toc
ans = 0.0011510
In 4 dimensions:
b=zeros(1024,1024,10,10);a=rand(1024);tic;for k=1:10,for l=1:10,b(:,:,k,l)=a;end;end;toc
ans = 46.512
With cells:
b=cell(10,10);a=rand(1024);tic;for k=1:10;for l=1:10;b{k,l}=a;end;end;toc
ans = 0.0014390





You use:
 E{k}  instead of E(:,:,k)
As long as you do not need to access your data in the third dimension this
is much more efficient and readable.

How about if I need FOUR dimensions? See, I'm modelling some weather
dynamics, and I would like to keep track of the passage of time, and
I'm not assuming the atmosphere to be thin enough to consider it
two-dimensional (though I probably should). So I end up having rank 4
tensors, one for each spacetime dimension. :-/

Any suggestion how to improve this?

Thanks,
- Jordi G. H.


Peter Cloetens
ESRF
BP 220
F-38043 Grenoble
tel  : + 33 (0)4 76 88 26 50
fax : + 33 (0)4 76 88 27 85



reply via email to

[Prev in Thread] Current Thread [Next in Thread]