简体   繁体   English

循环平铺以旋转矩阵

[英]Loop-Tiling to Rotate a Matrix

I'm trying to write a function to rotate an image matrix using the loop-tiling technique. 我正在尝试使用循环平铺技术编写一个旋转图像矩阵的函数。 However, I'm running into some issues with getting it to work properly. 但是,我遇到了让它正常工作的一些问题。

EDIT: Here's my updated code that works, but only when n is a multiple of the block size. 编辑:这是我的更新代码,但只有当n是块大小的倍数时才有效。 How would I go about handling varying matrix sizes? 我将如何处理不同的矩阵尺寸? Right now, I'm just using square blocks, and it works very well for those square blocks. 现在,我只是使用方块,它对那些方块非常有效。 How would I go about changing this to use rectangular blocks based on the size of the array I'm given. 我将如何改变它以使用基于我给出的数组大小的矩形块。 Specifically, if I'm given an nxn array, how do I choose the rectangular block dimensions to split it up into? 具体来说,如果我给了一个nxn数组,我如何选择矩形块尺寸将其拆分成?

  //Block size to tune
  int block = 20;
  int i1, j1, k1,  i, j, k;

  for(i1 = 0; i1 < n; i1 += block) {
    for(j1 = 0; j1< n; j1 += block) {
            for(i = i1; i < i1 + block; i++){
                for(j = j1; j < j1 + block; j++){
                    dest[getInd(j, i, n)] = src[getInd(i, n - 1 - j, n)]; 

                }
            }
        }
    }

} }

The first two for loops look wrong: 前两个for循环看起来错误:

  for(i1 = 0; i1 < n/block; i1 += block) {
    for(j1 = 0; j1< n/block; j1 += block) {

should probably be: 应该是:

  for(i1 = 0; i1 < n; i1 += block) {
    for(j1 = 0; j1 < n; j1 += block) {

When that's corrected though you'll probably just need to step through the code in your debugger to work out what else needs fixing. 当这个问题得到纠正时,你可能只需要调试调试器中的代码就可以解决其他需要修复的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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