[英]Submatrix extraction from matrix with loop tiling
我有以下4x4矩陣:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
我想提取並存儲(在一些新聞變量中)以下四個子矩陣2x2:
[1 2
5 6]
[3 4
7 8]
[9 10
13 14]
[11 12
15 16]
就像openCV的“ Rect”( http://docs.opencv.org/java/org/opencv/core/Rect.html )函數一樣,但是我不想使用OpenCV。
我必須使用並行化編譯器,因此我想使用文獻中存在的著名循環轉換來提取子矩陣:“循環平鋪”(也稱為“循環阻塞”或“循環展開和卡紙”或“循環”脫衣舞和互換”)。 -( http://en.wikipedia.org/wiki/Loop_tiling )
可能嗎?
可能嗎?
當然 …
int n = 4;
int matrix[4][4] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
int submatrixes[n/2*n/2][2][2];
int i, j, x, y, z;
for (z = i = 0; i < n; i += 2)
for (j = 0; j < n; j += 2, ++z)
for (x = 0; x < 2; x++)
for (y = 0; y < 2; y++)
submatrixes[z][x][y] = matrix[i+x][j+y];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.