help-octave
[Top][All Lists]
Advanced

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

Re: why cell arrays are used in 'interp2'


From: Michael Goffioul
Subject: Re: why cell arrays are used in 'interp2'
Date: Tue, 25 Dec 2012 17:51:11 -0500

On Tue, Dec 25, 2012 at 5:36 PM, Sergei Steshenko <address@hidden> wrote:
Sure.

N-d array is a well known entity in computer science; cell array is Matlab/Octave-specific aberration.

Since N-d array implies the same types of all the elements, and cell array allows elements of different types , cell array _definitely_ needs yet another level of indirection (pointer to the actual data structure containing the element, the data structure depends on element type), while N-d array may not need that level of indirection.

In other words, cell array is _necessarily_ something (array ?) of pointers


At least, in "C" N-d arrays do not use the above mentioned pointers. Elements are adjacent to each other in memory.

So, all in all, to me from computational point of view N-d array at _first_ sight looks more attractive. But devil is in the details.

As you know, octave is a community driven project. If you can come with an interp2 implementation that is proven to be more performant, I'm confident it'll be gladly integrated into octave.

However, I can see at least 2 potential performance penalty when using 4D matrices:
1) computing the linear index requires more operation for a 4D matrix than a 2D matrix (in other words: x(1,2,3,4) takes more time to compute than y(1,2)); when using cell array, you also need to index within the cell array, but you only do it once
2) manipulating slices or a larger matrix may result in copying the slice into another temporary location

These 2 issues obviously strongly depend on how the code is written. So again, I encourage you to give it a shot to see whether you can improve interp2 performances.

Michael.


reply via email to

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