#!/usr/bin/env python

from __future__ import absolute_import

from numpy import *
from geode import *

def test_stencil():
  for n in [10, 100, 255]:
    for m in [10, 100, 255]:
      for r in [1, 2, 3, 10, 50]:
        x = ndarray(shape=(m,n), dtype=numpy.dtype('u1'))
        for i in range(m):
          for j in range(n):
            x[i,j] = m-i

        xo = array(x[:,0], dtype=int).copy()

        print "before (m = %d, n = %d, r = %d): " % (m,n,r)
        print "x[:,0] =", x[:,0]

        apply_stencil_uint8(MaxStencil_uint8(r), r, x)

        print "after:"
        print "x[:,0] =", x[:,0]

        # make sure the pattern makes sense
        diff = xo - array(x[:,0], dtype=int)
        for i in range(min(m,r+1)):
          assert diff[i] == -i
        for i in range(r+1,m):
          assert diff[i] == -r


if __name__ == '__main__':
  test_stencil()

@@ -58,29 +58,8 @@
 port
-%0A%0Afrom numpy import *
 %0Afro
@@ -103,38 +103,31 @@
 %0A  for n in 
-%5B10, 100, 255%5D
+7,11,19
 :%0A    for m 
@@ -133,22 +133,14 @@
  in 
-%5B10, 100, 255%5D
+5,9,13
 :%0A  
@@ -156,25 +156,16 @@
  in 
-%5B
 1,
- 
 2,
- 
 3,
- 
 10
-, 50%5D
 :%0A  
@@ -178,135 +178,63 @@
 x = 
-ndarray(shape=
+m*ones(
 (m,n),
- 
 dtype=
-numpy.dtype('u1'))%0A        for i in range(m):%0A          for j in range(n):%0A            x%5Bi,j%5D = m-i%0A
+uint8)-arange(m,dtype=uint8)%5B:,None%5D
 %0A   
@@ -247,41 +247,43 @@
 o = 
-array(
 x%5B:,0%5D
-, d
+.as
 type
-=
+(
 int)
-.copy()%0A%0A
+%0A        if 0:%0A  
     
@@ -338,32 +338,34 @@
 (m,n,r)%0A        
+  
 print %22x%5B:,0%5D =%22
@@ -365,33 +365,32 @@
 :,0%5D =%22, x%5B:,0%5D%0A
-%0A
         apply_st
@@ -425,16 +425,29 @@
 (r),
- 
 r,
- 
 x)%0A
-%0A
+        if 0:%0A  
     
@@ -465,32 +465,34 @@
 after:%22%0A        
+ 
+ 
 print %22x%5B:,0%5D =%22
@@ -500,17 +500,16 @@
  x%5B:,0%5D%0A
-%0A
         
@@ -510,17 +510,17 @@
       # 
-m
+M
 ake sure
@@ -565,53 +565,29 @@
 = xo
- - array(x%5B:,0%5D, dtype=int)%0A        for i in 
+-x%5B:,0%5D%0A        i = a
 rang
@@ -599,20 +599,17 @@
 (m,r+1))
-:%0A  
+%0A
         
@@ -619,21 +619,24 @@
 ert 
+all(
 diff%5Bi%5D
- 
 ==
- 
 -i
+)
 %0A   
@@ -644,17 +644,13 @@
     
-for i in 
+i = a
 rang
@@ -657,20 +657,17 @@
 e(r+1,m)
-:%0A  
+%0A
         
@@ -677,22 +677,24 @@
 ert 
+all(
 diff%5Bi%5D
- 
 ==
- 
 -r
-%0A
+)
 %0A%0Aif

Make reasonably fast