import sys; sys.path += ['..', '.']
import os; os.environ['HL_DISABLE_BOUNDS_CHECKING'] = '1'
from halide import *

OUT_DIMS = (1536, 2560)

def filter_func(dtype=UInt(16)):
    "Simple 3x3 blur."
    input = ImageParam(dtype, 2, 'input')
    x = Var('x')
    y = Var('y')
    #c = Var('c')
    blur_x = Func('blur_x')
    blur_y = Func('blur_y')

    blur_x[x,y] = (input[x,y]+input[x+1,y]+input[x+2,y])/3
    blur_y[x,y] = (blur_x[x,y]+blur_x[x,y+1]+blur_x[x,y+2])/3

    return (input, blur_y, None, locals())

def main():
    (input, out_func, evaluate, local_d) = filter_func()

    x, y = local_d['x'], local_d['y'] #, local_d['c']
    blur_x, blur_y = local_d['blur_x'], local_d['blur_y']

    xi, yi = Var('xi'), Var('yi')

    blur_y.tile(x, y, xi, yi, 8, 4).parallel(y).vectorize(xi, 8)

    maxval = 255
    in_image = Image(UInt(16), '../../apps/images/rgb.png', maxval)
    eval_func = filter_image(input, out_func, in_image, disp_time=True, out_dims = OUT_DIMS, times=5)
    eval_func().show(maxval)

if __name__ == '__main__':
    main()


@@ -142,59 +142,15 @@
 def 
-filter_func(dtype=UInt(16)):%0A    %22Simple 3x3 blur.%22
+main():
 %0A   
@@ -173,13 +173,16 @@
 ram(
-dtype
+UInt(16)
 , 2,
@@ -196,16 +196,19 @@
 ')%0A    x
+, y
  = Var('
@@ -214,16 +214,9 @@
 'x')
-%0A    y =
+,
  Var
@@ -225,25 +225,8 @@
 y')%0A
-    #c = Var('c')
 %0A   
@@ -405,235 +405,8 @@
 /3%0A%0A
-    return (input, blur_y, None, locals())%0A%0Adef main():%0A    (input, out_func, evaluate, local_d) = filter_func()%0A%0A    x, y = local_d%5B'x'%5D, local_d%5B'y'%5D #, local_d%5B'c'%5D%0A    blur_x, blur_y = local_d%5B'blur_x'%5D, local_d%5B'blur_y'%5D%0A%0A
     
@@ -501,17 +501,115 @@
 (xi, 8)%0A
+    #blur_x.compute_at(blur_y, x).vectorize(x, 8)                   # This fail, not sure why%0A    
 %0A
-
     maxv
@@ -725,16 +725,14 @@
 ut, 
-out_func
+blur_y
 , in

simplify blur example