c++ - Recursive Func call in Halide -


i'm using halide , trying calculate size of maximum connected cells given 2-dimensional input. idea use recursive function don't know how write in halide language.

refernece python script , expected results follows.

import random  n = 4 data = [[0 in range(n)] j in range(n)] index in range(n*n):     data[index/n][index%n] = (random.randint(0,100) & 1)  print "input"    d in data:     print d  def ret(x, y):     if x < 0 or y < 0 or x >= n or y >= n:         return 0     if data[y][x] == 0:         return 0      data[y][x] = 0      return ret(x, y-1) + ret(x, y+1) + ret(x-1, y) + ret(x+1, y) + 1  result = [[0 in range(n)] j in range(n)]  y in range(4):     x in range(4):         result[y][x] = ret(x, y)  print "output"   r in result:     print r   """ input [1, 0, 1, 0] [0, 0, 1, 1] [0, 0, 1, 1] [1, 1, 0, 1] output [1, 0, 6, 0] [0, 0, 0, 0] [0, 0, 0, 0] [2, 0, 0, 0] """ 

halide implementation here, i've got error message below.

#include "halide.h" using namespace halide;  #define n 6  int main() {      image<uint8_t> input(n, n);     for(int y = 0; y < n; y++) {             for(int x = 0; x < n; x++) {                     input(x, y) = rand() & 1;                     printf("%3d", input(x, y));             }             printf("\n");     }     printf("\n");      var x("x"), y("y");      func input_f("input_f"), f("f");     input_f(x, y) = input(x, y);      f(x, y) = boundaryconditions::constant_exterior(input_f, 0, 0, n, 0, n)(x, y);     f(x, y) = select(f(x, y) != 0, f(x-1, y) + f(x+1, y) + f(x, y-1) + f(x, y+1) + 1, 0);      image<uint8_t> output = f.realize(n, n);     for(int y = 0; y < n; y++) {             for(int x = 0; x < n; x++) {                     printf("%3d", output(x, y));             }             printf("\n");     }      return 0; } 

error message:

in definition of func "f": of functions recursive references must contain same pure variables in same places on left-hand-side. 

according error message, cannot use 'x-1' , 'x+1' in right-hand-side. want so. there way realize such recursive func call?

*i don't stick recursive call if expected result in halide.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -