Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DTYPES = [np.uint8, np.float] # (etc...)
- def do_stuff(np.ndarray[dtype=DTYPES, ndim=2], img):
- cdef (some vars)
- cdef DTYPES pixel
- for i in range(rows):
- for j in range(cols):
- pixel = img[i, j]
- if DTYPES == np.uint8:
- <<datatype specific stuff>>
- <<other stuff>>
- ** run the templater to produce this output: **
- def do_stuff_uint8(np.ndarray[dtype=np.uint8, ndim=2], img):
- cdef (some vars)
- cdef np.uint8 pixel
- for i in range(rows):
- for j in range(cols):
- pixel = img[i, j]
- <<datatype specific stuff>>
- <<other stuff>>
- def do_stuff_float(np.ndarray[dtype=np.float, ndim=2], img):
- cdef (some vars)
- cdef np.float pixel
- for i in range(rows):
- for j in range(cols):
- pixel = img[i, j]
- <<other stuff>>
- def do_stuff(np.ndarray img):
- if img.dtype == np.uint8:
- do_stuff_uint8(img)
- elif img.dtype == np.float:
- do_stuff_float(img)
- else:
- pass
Advertisement
Add Comment
Please, Sign In to add comment