Contiguous memory and relational operators

I have a 2D matrix of floats called data (approx size 1E5 x 2E2) and wish to test some conditions many times (>1e9 times) eg
data(i:j, h) <= k, where k is a float
This process is a real bottleneck in my code according to the profiler.
Here the author (Jan) seems to suggest running permute.m to make the memory contiguous before applying the inequality operator.
I am unclear how to order the permutation though. What have I missed? (or is the permute trick only valid in dimensions above 2?)
tmp = permute(data(i:j, h) , orderVec); %where does orderVec come from???
tmp <= k %this is now fast

2 件のコメント

James Tursa
James Tursa 2013 年 2 月 22 日
The permute "trick" was mentioned because the other post had : for the trailing dimension. What is your exact situation for subscripting? Is it always of the form (i:j,h) with i, j, and h scalars but changing each iteration?
Matlab2010
Matlab2010 2013 年 3 月 5 日
編集済み: Matlab2010 2013 年 3 月 5 日
yes thats correct, it is always of the form (i:j,h) with the scalars i, j, and h changing each iteration.
does this help at all?

サインインしてコメントする。

 採用された回答

Jan
Jan 2013 年 2 月 22 日

0 投票

The permute method is useful, when a large multi-dimensional array is indexed repeatedly. In the other thread it was P(M, 4, N) with large M and N. Then calling P(:,i,:) repeatedly consumes much more time than getting Q(:, :, i) after:
Q = permute(P, [1,3,2]);
In your case, the comparison could be performed once only:
comp = (data <= k);
And instead of comparing in a loop, the vector comp(i:j, h) can be used directly. But I assume this is not a dramatic improvement. More precise advices are possible if you post the relevant part of the code.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMultidimensional Arrays についてさらに検索

タグ

質問済み:

2013 年 2 月 22 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by