From: James Tursa on 4 Jul 2010 09:30 "Aristeidis " <aris262(a)hotmail.com> wrote in message <i0prlp$j92$1(a)fred.mathworks.com>... > > I simply therefore, want to input these cells in a mex file which will only return the maximum values back to matlab and I if i can bring the total computation time to 10secs (arbitrary) or even 20 from 35secs I am a happy man. Do you think that this is a good reason why someone should MEX? Can you show your basic m-code? i.e., the current for loops & max calls you are making. James Tursa
From: Aristeidis on 4 Jul 2010 12:45 > > I simply therefore, want to input these cells in a mex file which will only return the maximum values back to matlab and I if i can bring the total computation time to 10secs (arbitrary) or even 20 from 35secs I am a happy man. Do you think that this is a good reason why someone should MEX? > > Can you show your basic m-code? i.e., the current for loops & max calls you are making. > > James Tursa Please see below (both X and Y have been predefined outside the loops) and note that in X{i,j}{k,l} there are 2D matrices of equal dimenions, i.e. 4x4, 8x8 etc. for i = 1: size(X,1) for j = 1:size(X,2) for k = 1: size(X{i,j},1) for l = 1:size(X{i,j},2) Y{i,j}(k,l) = max(max(X{i,j}{k,l})); end end end end
From: Rune Allnor on 4 Jul 2010 12:58 On 4 Jul, 18:45, "Aristeidis " <aris...(a)hotmail.com> wrote: > > > I simply therefore, want to input these cells in a mex file which will only return the maximum values back to matlab and I if i can bring the total computation time to 10secs (arbitrary) or even 20 from 35secs I am a happy man. Do you think that this is a good reason why someone should MEX? > > > Can you show your basic m-code? i.e., the current for loops & max calls you are making. > > > James Tursa > > Please see below (both X and Y have been predefined outside the loops) and note that in X{i,j}{k,l} there are 2D matrices of equal dimenions, i.e. 4x4, 8x8 etc. > > for i = 1: size(X,1) > for j = 1:size(X,2) > for k = 1: size(X{i,j},1) > for l = 1:size(X{i,j},2) > Y{i,j}(k,l) = max(max(X{i,j}{k,l})); > end > end > end > end The problem is ill-stated. I suspect MEX'ing will not help much on the speed of this kind of thing, simply because whatever improvements might be obtained by MEX'ing the loops will be more than offset by the overhead associated with constructing X in the first place. As I said before, get rid of the cell arrays. I have no idea what you are trying to do, but the overall approach is plain wrong - it would be hard to design a less efficient solution. Rune
From: James Tursa on 4 Jul 2010 13:39 "Aristeidis " <aris262(a)hotmail.com> wrote in message <i0qdqo$2no$1(a)fred.mathworks.com>... > > Please see below (both X and Y have been predefined outside the loops) and note that in X{i,j}{k,l} there are 2D matrices of equal dimenions, i.e. 4x4, 8x8 etc. > > for i = 1: size(X,1) > for j = 1:size(X,2) > for k = 1: size(X{i,j},1) > for l = 1:size(X{i,j},2) > Y{i,j}(k,l) = max(max(X{i,j}{k,l})); > end > end > end > end How do you predefine Y? Are you populating each cell with a zero matrix of the appropriate size before you enter this loop? i.e., are you pre-allocating everything or are you growing each Y{i,j} matrix inside a loop? Note that max(max(A)) is just max(A(:)) ... saves some overhead. Also, you might look into cellfun to save some of your looping. James Tursa
From: James Tursa on 4 Jul 2010 13:49
"Aristeidis " <aris262(a)hotmail.com> wrote in message <i0qdqo$2no$1(a)fred.mathworks.com>... > > Please see below (both X and Y have been predefined outside the loops) and note that in X{i,j}{k,l} there are 2D matrices of equal dimenions, i.e. 4x4, 8x8 etc. > > for i = 1: size(X,1) > for j = 1:size(X,2) > for k = 1: size(X{i,j},1) > for l = 1:size(X{i,j},2) > Y{i,j}(k,l) = max(max(X{i,j}{k,l})); > end > end > end > end Also, what class are the individual X{i,j}{k,l} matrices? double? One of the int classes? James Tursa |