def gen_patch1v(): inter_funcs = bf.load_pickle('fun_index.pkl') sum_lst = bf.load_pickle("detect_res_lst.pkl") fid_lst = [] for i in fid_lc: if i not in [62, 97, 104, 119]: test_fun = inter_funcs[i] print test_fun var_num = bf.get_var_num(test_fun) name = "localize_res_files/" + test_fun[0] + ".pkl" rfp = lambda x: rf_f(i, x) temp_lst = bf.load_pickle(name) print len(temp_lst[-2][0]) print len(temp_lst[0]) print len(temp_lst[0][-1][-1]) try: temp_lst = bf.load_pickle(name) if var_num == 1: print temp_lst # print test_fun for j in temp_lst[0]: ori_bound = j[0] type = j[1] print generate_1v_patch(j[-1], ori_bound, type, rfp) # print len(j[3]) # if len(j[3]) > 10: # for idj in j[3][0:10]: # print idj # else: # for idj in j[3]: # print idj fid_lst.append(i) except IOError: continue print fid_lst
def cal_exceptions(): inter_funcs = bf.load_pickle('fun_index.pkl') eva_bound_lst = bf.load_pickle("eva_bound_lst.plk") sum_lst = bf.load_pickle("detect_res_lst.pkl") cal_num = 0 name_lst = [] for fid in range(0, len(inter_funcs)): # fid = 14 flag = 0 test_fun = inter_funcs[fid] fun_pu, stat_fun = load_pure_fun(test_fun[0]) i = sum_lst[fid] print test_fun fpe_lst = [] for j in range(0, len(i[2]), 2): bt = i[2][j] res_lst = i[2][j + 1] if bt == 3: fpe_lst.append(res_lst[0][0] + res_lst[0][1] + res_lst[0][2]) count = 0 rf = lambda x: rf_f(fid, x) new_bounds = [] # new_bounds.append(fid) # new_bounds.append(test_fun[0]) var_num = bf.get_var_num(test_fun) print eva_bound_lst[fid] for i in eva_bound_lst[fid][2:]: print i ret_vals = i[0][1] num_excp = i[0][0] bt = get_bound_type(ret_vals, num_excp) bound = i[1] inp_lst = [] loc_inps = [] # print bound if (bt == 3) & (fid != 97): inp_lst = FPexcption_detector_whole(fun_pu, stat_fun, bound) inp_lst = inp_lst + fpe_lst[count] count = count + 1 for ti in inp_lst: res_p = fun_pu(*ti) res_rf = float(rf(ti)) ty_f = classifer(res_p.val, res_rf, stat_fun()) if ty_f != 0: loc_inps.append(ti) flag = 1 if flag == 1: name_lst.append([fid, test_fun[1]]) cal_num = cal_num + 1 print cal_num print cal_num for nai in name_lst: print nai
def plot_local_res(): inter_funcs = bf.load_pickle('fun_index.pkl') sum_lst = bf.load_pickle("detect_res_lst.pkl") for i in range(0, len(inter_funcs)): if i not in [62, 97, 104, 119]: test_fun = inter_funcs[i] var_num = bf.get_var_num(test_fun) name = "plot_bounds_res/" + test_fun[0] + ".pkl" name2 = "localize_res_files/" + test_fun[0] + ".pkl" try: print test_fun temp_lst = bf.load_pickle(name) temp_lst2 = bf.load_pickle(name2) if var_num == 1: plot_1func_domain(temp_lst) else: plot_2vfunc_domain(temp_lst) except IOError: continue
def get_repairing_time(): inter_funcs = bf.load_pickle('fun_index.pkl') time_lst = [] repair_time = [] for i in fid_lc: test_fun = inter_funcs[i] print test_fun var_num = bf.get_var_num(test_fun) name2 = "final_res_files/" + test_fun[0] + ".pkl" name3 = "localize_res_files/" + test_fun[0] + ".pkl" name4 = "repair_res_files/" + test_fun[0] + ".pkl" det_res = bf.load_pickle(name2) loc_res = bf.load_pickle(name3) rep_res = bf.load_pickle(name4) for ri in rep_res[0:-1]: print ri[-1] temp_t = det_res[-1] + [loc_res[-1] , rep_res[-1]] # print temp_t time_lst.append(temp_t) sum_time_lst = [] count = 0 for i in time_lst: sum_time = 0 for j in i: sum_time = sum_time + j sum_time_lst.append(sum_time) # if sum_time > 1000: print sum_time print inter_funcs[fid_lc[count]] count = count + 1 print np.max(sum_time_lst) print np.min(sum_time_lst) count = 0 for i in sum_time_lst: if i < 1000: count = count + 1 print count print count-len(sum_time_lst) tot_time = 0 for i in sum_time_lst: tot_time = i + tot_time print tot_time
def repair4all(): inter_funcs = bf.load_pickle('fun_index.pkl') for i in fid_lc: test_fun = inter_funcs[i] print test_fun var_num = bf.get_var_num(test_fun) name = "localize_res_files/" + test_fun[0] + ".pkl" name2 = "repair_res_files/" + test_fun[0] + ".pkl" rfp = lambda x: rf_f(i, x) fun_pu, stat_fun = load_pure_fun(test_fun[0]) temp_lst = bf.load_pickle(name) st_time = time.time() repair_lst = [] if var_num == 2: for j in temp_lst[0]: print j[0] print j[1] print len(j[-1]) if len(j[-1]) >= 2: repair_code = generate_2v_patch(4) repair_lst.append([j[0], j[-1], repair_code]) else: typ_j = classify_bound(j[-1][0], rfp, fun_pu, stat_fun) repair_code = generate_2v_patch(typ_j) repair_lst.append([j[0], j[-1], repair_code]) else: for j in temp_lst[0]: if len(j[-1]) >= 2: repair_code = generate_2v_patch(4) repair_lst.append([j[0], j[-1], repair_code]) else: typ_j = classify_bound(j[-1][0], rfp, fun_pu, stat_fun) repair_code = generate_1v_patch(j[-1][0], j[0], typ_j, rfp) print "repair_code" print repair_code repair_lst.append([j[0], j[-1], repair_code]) et = time.time() - st_time repair_lst.append(et) bf.pickle_fun(name2, repair_lst)
def gen_patch(): inter_funcs = bf.load_pickle('fun_index.pkl') sum_lst = bf.load_pickle("detect_res_lst.pkl") fid_lst = [] for i in range(0, len(inter_funcs)): if i not in [62, 97, 104, 119]: test_fun = inter_funcs[i] var_num = bf.get_var_num(test_fun) name = "localize_res_files/" + test_fun[0] + ".pkl" try: temp_lst = bf.load_pickle(name) if var_num == 1: for j in temp_lst[0]: print len(j[3]) if len(j[3]) > 10: for idj in j[3][0:10]: print idj else: for idj in j[3]: print idj fid_lst.append(i) except IOError: continue print len(fid_lst)
def get_detecting_time(): inter_funcs = bf.load_pickle('fun_index.pkl') time_lst = [] repair_time = [] for i in fid_de: test_fun = inter_funcs[i] # print test_fun var_num = bf.get_var_num(test_fun) name2 = "final_res_files/" + test_fun[0] + ".pkl" det_res = bf.load_pickle(name2) # print det_res[-1] time_lst.append(det_res[-1]) sum_time_lst = [] count = 0 for i in time_lst: sum_time = 0 for j in i: sum_time = sum_time + j sum_time_lst.append(sum_time) if sum_time > 1000: print sum_time # print inter_funcs[fid_lc[count]] count = count + 1 print np.max(sum_time_lst) print np.min(sum_time_lst) count = 0 for i in sum_time_lst: if i < 1000: count = count + 1 print count print count-len(sum_time_lst) tot_time = 0 for i in sum_time_lst: tot_time = i + tot_time print tot_time
print "if(axs==" + repr(idx) + "){" print " if(find_bd_" + name + '_' + str(idx) + "(" + var_name + ")){" for rep_str in rep_lst[2]: print " " + rep_str print " }" print "}" idx = idx + 1 sys.stdout = orig_stdout f.close() inter_funcs = bf.load_pickle('fun_index.pkl') for i in fid_lc: test_fun = inter_funcs[i] print test_fun var_num = bf.get_var_num(test_fun) name = "localize_res_files/" + test_fun[0] + ".pkl" name2 = "repair_res_files/" + test_fun[0] + ".pkl" repair_res = bf.load_pickle(name2) print len(repair_res) print repair_res if var_num == 1: var_name = test_fun[1][0][1] convertToC_1v(repair_res, test_fun[0],var_name) else: var_name = test_fun[1][0][1] + "," + test_fun[1][1][1] if (test_fun[0] == "gsl_sf_lnbeta_e") | (test_fun[0] == "gsl_sf_beta_e"): var_name = 'x,y' convertToC_2v(repair_res, test_fun[0],var_name)
def localize_exceptions(): inter_funcs = bf.load_pickle('fun_index.pkl') eva_bound_lst = bf.load_pickle("eva_bound_lst.plk") sum_lst = bf.load_pickle("detect_res_lst.pkl") for fid in range(74, 75): # fid = 14 test_fun = inter_funcs[fid] fun_pu, stat_fun = load_pure_fun(test_fun[0]) i = sum_lst[fid] print test_fun fpe_lst = [] for j in range(0, len(i[2]), 2): bt = i[2][j] res_lst = i[2][j + 1] if bt == 3: fpe_lst.append(res_lst[0][0] + res_lst[0][1] + res_lst[0][2]) count = 0 rf = lambda x: rf_f(fid, x) new_bounds = [] # new_bounds.append(fid) # new_bounds.append(test_fun[0]) var_num = bf.get_var_num(test_fun) print eva_bound_lst[fid] for i in eva_bound_lst[fid][2:]: print i ret_vals = i[0][1] num_excp = i[0][0] bt = get_bound_type(ret_vals, num_excp) bound = i[1] inp_lst = [] loc_inps = [] # print bound if (bt == 3) & (fid != 97): inp_lst = FPexcption_detector_whole(fun_pu, stat_fun, bound) inp_lst = inp_lst + fpe_lst[count] count = count + 1 for ti in inp_lst: res_p = fun_pu(*ti) res_rf = float(rf(ti)) ty_f = classifer(res_p.val, res_rf, stat_fun()) if ty_f != 0: loc_inps.append(ti) if loc_inps == []: new_bounds.append([(0, [-1]), bound]) else: new_bounds.append(i) if var_num == 1: loc_bound_lst = localize_inbound( bound, fun_pu, stat_fun, loc_inps) print "loc_bound_lst" print bound print loc_bound_lst for lcb in loc_bound_lst: new_bounds.append([(0, [-2]), lcb]) else: loc_bound_lst = localize_inbound2v( bound, fun_pu, stat_fun, loc_inps) print "loc_bound_lst" # print loc_bound_lst print len(loc_bound_lst) for lcb in loc_bound_lst: new_bounds.append([(0, [-2]), lcb]) else: new_bounds.append(i) if var_num == 1: plot_1func_domain(new_bounds) if var_num == 2: plot_2vfunc_domain(new_bounds) print new_bounds
def localize4exceptions(fid, test_fun, detect_res, eva_bound_lst, limit_time): fun_pu, stat_fun = load_pure_fun(test_fun[0]) i = detect_res print detect_res print eva_bound_lst # print test_fun fpe_lst = [] for j in range(0, len(i), 2): bt = i[j] res_lst = i[j + 1] if bt == 3: fpe_lst.append(res_lst[0][0] + res_lst[0][1] + res_lst[0][2]) count = 0 rf = lambda x: rf_f(fid, x) new_bounds = [] print fpe_lst # new_bounds.append(fid) # new_bounds.append(test_fun[0]) repair_bounds_final = [] var_num = bf.get_var_num(test_fun) for i in eva_bound_lst: repair_bounds = [] # print i ret_vals = i[0][1] num_excp = i[0][0] bt = get_bound_type(ret_vals, num_excp) bound = i[1] inp_lst = [] loc_inps = [] ty_f = 0 if (bt == 3) & (fid != 97): # inp_lst = FPexcption_detector_whole(fun_pu, stat_fun, bound) inp_lst = inp_lst + fpe_lst[count] count = count + 1 for ti in inp_lst: res_p = fun_pu(*ti) res_rf = float(rf(ti)) signal.alarm(limit_time) ty_f = classifer(res_p.val, res_rf, stat_fun()) print "ty_f" print ty_f if ty_f != 0: loc_inps.append(ti) if loc_inps == []: new_bounds.append([(0, [-1]), bound]) else: repair_bounds.append(bound) repair_bounds.append(ty_f) repair_bounds.append(loc_inps) new_bounds.append(i) if var_num == 1: loc_bound_lst = localize_inbound(bound, fun_pu, stat_fun, loc_inps) for lcb in loc_bound_lst: new_bounds.append([(0, [-2]), lcb]) repair_bounds.append(loc_bound_lst) else: loc_bound_lst = localize_inbound2v(bound, fun_pu, stat_fun, loc_inps) for lcb in loc_bound_lst: new_bounds.append([(0, [-2]), lcb]) repair_bounds.append(loc_bound_lst) repair_bounds_final.append(repair_bounds) else: new_bounds.append(i) return new_bounds, repair_bounds_final