I have tried unrolling the loop but it always changes the outcome. Can anyone te
ID: 3546317 • Letter: I
Question
I have tried unrolling the loop but it always changes the outcome. Can anyone tell me any way to unroll the loops within this code?int a = filter -> getDivisor(); int n = filter -> getSize(); for(int row = 1; row < (input -> height) - 1 ; row = row + 1) { for(int col = 1; col < (input -> width) - 1; col = col + 1) { int value = 0; for (int plane = 0; plane < 3; plane++){ for (int j = 0; j < n; j++) { for (int i = 0; i < n; i++) { value = value + input -> color[plane][row + i - 1][col + j - 1] * filter -> get(i, j); } } value = value / a; if ( value < 0 ) { value = 0; } if ( value > 255 ) { value = 255; } output -> color[plane][row][col] = value; } I have tried unrolling the loop but it always changes the outcome. Can anyone tell me any way to unroll the loops within this code?
int a = filter -> getDivisor(); int n = filter -> getSize(); for(int row = 1; row < (input -> height) - 1 ; row = row + 1) { for(int col = 1; col < (input -> width) - 1; col = col + 1) { int value = 0; for (int plane = 0; plane < 3; plane++){ for (int j = 0; j < n; j++) { for (int i = 0; i < n; i++) { value = value + input -> color[plane][row + i - 1][col + j - 1] * filter -> get(i, j); } } value = value / a; if ( value < 0 ) { value = 0; } if ( value > 255 ) { value = 255; } output -> color[plane][row][col] = value; }
Explanation / Answer
which language ? i can do it :) do u need to reduce ur loop ?