简体   繁体   中英

Submatrix extraction from matrix with loop tiling

I have the following matrix 4x4:

1  2  3  4

5  6  7  8

9 10 11 12

13 14 15 16

and I want extract and store (in some news variables) the four following submatrix 2x2:

[1 2

 5 6]

[3 4

 7 8]

[9 10

 13 14]

[11 12

 15 16]

It's like the "Rect" ( http://docs.opencv.org/java/org/opencv/core/Rect.html ) function of openCV, but I don'want to use OpenCV.

I have to use a parallelizing compiler and so I would like to do the extraction of the submatrix with a famous loop transformation present in literature: "loop tiling" (also knows as "loop blocking" or "loop unroll and jam" or "loop stripmine and interchange"). - ( http://en.wikipedia.org/wiki/Loop_tiling )

Is it possible?

Is it possible?

Of course …

    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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM