# Path: growcut/growcut_python.py
# def growcut_python(image, state, state_next, window_radius):
#     changes = 0
#     sqrt_3 = np.sqrt(3.0)
# 
#     height = image.shape[0]
#     width = image.shape[1]
# 
#     for j in xrange(width):
#         for i in xrange(height):
# 
#             winning_colony = state[i, j, 0]
#             defense_strength = state[i, j, 1]
# 
#             for jj in xrange(window_floor(j, window_radius),
#                              window_ceil(j + 1, width, window_radius)):
#                 for ii in xrange(window_floor(i, window_radius),
#                                  window_ceil(i + 1, height, window_radius)):
#                     if ii != i or jj != j:
#                         d = image[i, j, 0] - image[ii, jj, 0]
#                         s = d * d
#                         for k in range(1, 3):
#                             d = image[i, j, k] - image[ii, jj, k]
#                             s += d * d
#                         gval = 1.0 - np.sqrt(s) / sqrt_3
# 
#                         attack_strength = gval * state[ii, jj, 1]
# 
#                         if attack_strength > defense_strength:
#                             defense_strength = attack_strength
#                             winning_colony = state[ii, jj, 0]
#                             changes += 1
# 
#             state_next[i, j, 0] = winning_colony
#             state_next[i, j, 1] = defense_strength
# 
#     return changes


from growcut import growcut_python
from pythran import compile_pythrancode
from inspect import getsource
import imp

# grab imports
imports = 'import numpy as np'
exports = '''
#pythran export growcut_python(float[][][], float[][][], float[][][], int)
'''
modname = 'growcut_pythran'

# grab the source from the original functions
sources = map(getsource,
              (growcut_python.window_floor,
               growcut_python.window_ceil,
               growcut_python.growcut_python)
              )
source = '\n'.join(sources)

# compile to a native module
native = compile_pythrancode(
    modname, '\n'.join([imports, exports, source]))

# load it
native = imp.load_dynamic(modname, native)

benchmarks = (

# Path: growcut/growcut_python.py
# def growcut_python(image, state, state_next, window_radius):
#     changes = 0
#     sqrt_3 = np.sqrt(3.0)
# 
#     height = image.shape[0]
#     width = image.shape[1]
# 
#     for j in xrange(width):
#         for i in xrange(height):
# 
#             winning_colony = state[i, j, 0]
#             defense_strength = state[i, j, 1]
# 
#             for jj in xrange(window_floor(j, window_radius),
#                              window_ceil(j + 1, width, window_radius)):
#                 for ii in xrange(window_floor(i, window_radius),
#                                  window_ceil(i + 1, height, window_radius)):
#                     if ii != i or jj != j:
#                         d = image[i, j, 0] - image[ii, jj, 0]
#                         s = d * d
#                         for k in range(1, 3):
#                             d = image[i, j, k] - image[ii, jj, k]
#                             s += d * d
#                         gval = 1.0 - np.sqrt(s) / sqrt_3
# 
#                         attack_strength = gval * state[ii, jj, 1]
# 
#                         if attack_strength > defense_strength:
#                             defense_strength = attack_strength
#                             winning_colony = state[ii, jj, 0]
#                             changes += 1
# 
#             state_next[i, j, 0] = winning_colony
#             state_next[i, j, 1] = defense_strength
# 
#     return changes


# Path: growcut/growcut_pythran.py
from growcut import growcut_python
from pythran import compile_pythrancode
from inspect import getsource
import imp


# grab imports
imports = 'import numpy as np'
exports = '''
#pythran export growcut_python(float[][][], float[][][], float[][][], int)
'''
modname = 'growcut_pythran'

# grab the source from the original functions
sources = map(getsource,
              (growcut_python.window_floor,
               growcut_python.window_ceil,
               growcut_python.growcut_python)
              )
source = '\n'.join(sources)

# compile to a native module
native = compile_pythrancode(
    modname, '\n'.join([imports, exports, source]))

# load it
native = imp.load_dynamic(modname, native)

benchmarks = (

    ("growcut_pythran", native.growcut_python),