def compare(s_try, s_actual, v_try, v_actual, name):
"""
Compares properties of a new implementation and the original slow one.
Raises Error if they are not equal and plots the comparison
"""
compare_s = np.logical_xor(s_try,s_actual)
compare_v = np.logical_xor(v_try,v_actual)
if compare_s.any () or compare_v.any ():
plt.figure(figsize = (6 ,9 ))
plt.subplot(321 )
plt.title("Compare Solid" )
plt.imshow(compare_s, vmax= 1 , vmin= 0 )
plt.subplot(322 )
plt.title("Compare Void" )
plt.imshow(compare_v, vmax= 1 , vmin= 0 )
plt.subplot(323 )
plt.title(f" { name} Solid" )
plt.imshow(s_try, vmax= 1 , vmin= 0 )
plt.subplot(324 )
plt.title(f" { name} Void" )
plt.imshow(v_try, vmax= 1 , vmin= 0 )
plt.subplot(325 )
plt.title(f"Actual { name} Solid" )
plt.imshow(s_actual, vmax= 1 , vmin= 0 )
plt.subplot(326 )
plt.title(f"Actual { name} Void" )
plt.imshow(v_actual, vmax= 1 , vmin= 0 )
plt.show()
raise ValueError (f"Calculation of { name} wrong" )
def check_valid(state: GeneratorState):
if debug> 2 :
times.possible -= time.process_time()
p_s_possible_real = possible_pixels(state.t_s_valid,state.t_s,brush)
p_v_possible_real = possible_pixels(state.t_v_valid,state.t_v,brush)
times.possible += time.process_time()
compare(state.p_s_possible,p_s_possible_real, state.p_v_possible,p_v_possible_real, "possible" )
if debug> 2 :
p_s_possible_dilated_real = dilate(state.p_s_possible, state.brush, False )
p_v_possible_dilated_real = dilate(state.p_v_possible, state.brush, False )
compare(state.dilated_p_s_possible,p_s_possible_dilated_real, state.dilated_p_v_possible,p_v_possible_dilated_real, "dilated possible" )
t_s_free_real = free_touches(state.p_v_possible, state.t_s_valid, state.brush)
t_v_free_real = free_touches(state.p_s_possible, state.t_v_valid, state.brush)
compare(state.t_s_free,t_s_free_real, state.t_v_free,t_v_free_real, "free" )
if debug> 1 :
t_s_valid_real = valid_touches(state.t_s_impossible, state.t_s)
t_v_valid_real = valid_touches(state.t_v_impossible, state.t_v)
compare(state.t_s_valid, t_s_valid_real, state.t_v_valid, t_v_valid_real, "valid" )
if state.t_s_free.any () or state.t_v_free.any ():
return
if debug> 1 :
p_s_required_real = required_pixels(state.p_s_existing, state.p_v_possible)
p_v_required_real = required_pixels(state.p_v_existing, state.p_s_possible)
compare(state.p_s_required,p_s_required_real, state.p_v_required,p_v_required_real, "required" )
if debug> 1 :
p_s_required_dilated_real = dilate(state.p_s_required, state.brush)
p_v_required_dilated_real = dilate(state.p_v_required, state.brush)
compare(state.dilated_p_s_required, p_s_required_dilated_real, state.dilated_p_v_required, p_v_required_dilated_real, "dilated required" )
t_s_resolving_real = resolving_touches(state.p_s_required, state.t_s_valid, state.brush)
t_v_resolving_real = resolving_touches(state.p_v_required, state.t_v_valid, state.brush)
compare(state.t_s_resolving,t_s_resolving_real, state.t_v_resolving,t_v_resolving_real, "resolving" )