Guest User

Untitled

a guest
Feb 16th, 2010
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. DTYPES = [np.uint8, np.float] # (etc...)
  2.  
  3. def do_stuff(np.ndarray[dtype=DTYPES, ndim=2], img):
  4.  
  5. cdef (some vars)
  6.  
  7. cdef DTYPES pixel
  8.  
  9. for i in range(rows):
  10. for j in range(cols):
  11.  
  12. pixel = img[i, j]
  13.  
  14. if DTYPES == np.uint8:
  15. <<datatype specific stuff>>
  16.  
  17. <<other stuff>>
  18.  
  19.  
  20.  
  21. ** run the templater to produce this output: **
  22.  
  23. def do_stuff_uint8(np.ndarray[dtype=np.uint8, ndim=2], img):
  24.  
  25. cdef (some vars)
  26.  
  27. cdef np.uint8 pixel
  28.  
  29. for i in range(rows):
  30. for j in range(cols):
  31.  
  32. pixel = img[i, j]
  33.  
  34. <<datatype specific stuff>>
  35.  
  36. <<other stuff>>
  37.  
  38.  
  39. def do_stuff_float(np.ndarray[dtype=np.float, ndim=2], img):
  40.  
  41. cdef (some vars)
  42.  
  43. cdef np.float pixel
  44.  
  45. for i in range(rows):
  46. for j in range(cols):
  47.  
  48. pixel = img[i, j]
  49.  
  50. <<other stuff>>
  51.  
  52.  
  53. def do_stuff(np.ndarray img):
  54. if img.dtype == np.uint8:
  55. do_stuff_uint8(img)
  56. elif img.dtype == np.float:
  57. do_stuff_float(img)
  58. else:
  59. pass
Advertisement
Add Comment
Please, Sign In to add comment