file_name
stringlengths
32
36
content
stringlengths
44
898
benchmark_functions_edited/f13606.py
def f(p, n, r): if r[n] >= 0: return r[n] if n == 0: return 0 else: q = -100000 for i in range(n): q = max(q, p[i] + f(p, n - (i + 1), r)) r[n] = q return q assert f([1, 5, 8, 9, 10, 17, 17, 20, 24, 30], 0, [-1] * 11) == 0
benchmark_functions_edited/f12920.py
def f(parens): open_stack = [] for par in parens: if par == '(': open_stack.append(par) if par == ')': try: open_stack.pop() except IndexError: return -1 if open_stack: return 1 else: return 0 assert f( '(()(()))' ) == 0
benchmark_functions_edited/f2589.py
def f(a, b): return a * b if a is not None and b is not None else a if a is not None else b assert f(1, 2) == 2
benchmark_functions_edited/f2317.py
def f(year): return int(year % 4) assert f(1900) == 0
benchmark_functions_edited/f8234.py
def f(ticks, BPM, resolution): # micro seconds per beat #muspb = 60. * 1000000 / BPM #micro seconds per tick #muspt = muspb / resolution #return muspt * ticks . return ticks * 60000000. / (BPM * resolution) assert f(0, 120, 4) == 0
benchmark_functions_edited/f4738.py
def f(val1, val2): return -1 if val1 == -1 or val2 == -1 else val1 - val2 assert f(5, 5) == 0
benchmark_functions_edited/f3946.py
def f(a, b): if a is None: return b if b is None: return a return a + b assert f(None, 5) == 5
benchmark_functions_edited/f2030.py
def f(x, m): return (x % m + m) % m assert f(1,1) == 0
benchmark_functions_edited/f10707.py
def f(true_end, time_span): # The remainder needs +1 because the cut-off is at the end of true_end. # For example, if the true_end is 49, the 1st day is 2 to 25 and the # 2nd day is 26, to 49. return (true_end % time_span) + 1 assert f(101, 50) == 2
benchmark_functions_edited/f593.py
def f(start, end, pos): return start * (end / start) ** pos assert f(1, 1, 0) == 1
benchmark_functions_edited/f2081.py
def f(val): if val < 0: val = ~(-val - 1) return val assert f(4) == 4
benchmark_functions_edited/f6504.py
def f(l, x): for idx in reversed(range(len(l))): if l[idx] == x: return idx raise ValueError("'{}' is not in list".format(x)) assert f(range(10), 7) == 7
benchmark_functions_edited/f8358.py
def f(interval, wrapAt=360.): if wrapAt is None: return (interval[0] + (interval[1] - interval[0]) / 2.) else: return ((interval[0] + ((interval[1] - interval[0]) % wrapAt) / 2.) % wrapAt) assert f((300, -300)) == 0
benchmark_functions_edited/f11304.py
def f(n, m): j = (n * (n+1))/2 + (n+m)/2 if not int(j) == j: raise ValueError("This should never happen, j={:f} should be an integer.".format(j)) return int(j) assert f(1,1) == 2
benchmark_functions_edited/f2731.py
def f(n, m): if n==1 or m==1: return 1 else: return f(n-1, m) + f(n, m-1) assert f(1,1) == 1
benchmark_functions_edited/f1195.py
def f(sentence_pair): return len(sentence_pair[-1]) assert f( ("A",)) == 1
benchmark_functions_edited/f13582.py
def f(capacity, items): if not items or not capacity: return 0 item = items.pop() if (item.weight > capacity): return f(capacity, items) capacity_with_item = capacity - item.weight with_item = item.value + f(capacity_with_item, items) without_item = f(capacity, items) return max(with_item, without_item) assert f(5, []) == 0
benchmark_functions_edited/f3269.py
def f(list): return int(sum([1 for x in list if x != 0.0])) assert f(list([1.0, 0.0, 2.0, 0.0, 3.0])) == 3
benchmark_functions_edited/f9416.py
def f(glTF, name): if glTF.get('cameras') is None: return -1 index = 0 for camera in glTF['cameras']: if camera['name'] == name: return index index += 1 return -1 assert f( {'cameras': [{'name': 'a'}, {'name': 'b'}]}, 'a' ) == 0
benchmark_functions_edited/f13592.py
def f(x, y): # Assume len(x) == len(y) n = len(x) sum_x = float(sum(x)) sum_y = float(sum(y)) sum_x_sq = sum(xi*xi for xi in x) sum_y_sq = sum(yi*yi for yi in y) psum = sum(xi*yi for xi, yi in zip(x, y)) num = psum - (sum_x * sum_y/n) den = pow((sum_x_sq - pow(sum_x, 2) / n) * (sum_y_sq - pow(sum_y, 2) / n), 0.5) if den == 0: return 0 return num / den assert f(range(10), range(10)) == 1
benchmark_functions_edited/f2886.py
def f(coordinates): return sum(abs(coordinate) for coordinate in coordinates) assert f( (-1, 0, 1) ) == 2
benchmark_functions_edited/f14132.py
def f(cg): # N is the total number of comparisons we will make N = 0 for c in cg: # number in this cell nc = len(c) # can make 1/2 n * (n-1) inside the same cell N += (nc - 1) * nc // 2 for addr in c.half_neighbours: o = cg[addr] N += nc * len(o) return N assert f(list()) == 0
benchmark_functions_edited/f491.py
def f(s): return int(s, 8) assert f(b'7') == 7
benchmark_functions_edited/f6650.py
def f(l, idx, default=None): try: if l[idx]: return l[idx] else: return default except IndexError: return default assert f( [None, None, None, 1, 2, 3, 4, 5], 3) == 1
benchmark_functions_edited/f10520.py
def f(gender): if not gender: return None gender = gender.lower() if gender == 'male' or gender == 'm': return 1 elif gender == 'female' or gender == 'f': return 0 else: return None assert f('male') == 1
benchmark_functions_edited/f9112.py
def f(value): return 10**(value/10) assert f(0) == 1
benchmark_functions_edited/f7011.py
def f(hand): count = 0 for i in hand: count += hand[i] return count assert f({"A":1}) == 1
benchmark_functions_edited/f12414.py
def f(val, orders): return val / 1024 ** orders assert f(1024, 1) == 1
benchmark_functions_edited/f3792.py
def f(used, available): return ((used + available) / 100) + 1 assert f(100, 0) == 2
benchmark_functions_edited/f10847.py
def f(superclass: str): superclass_dict = {"L": 0, "S": 1, "T": 2, "U": 3} return superclass_dict[superclass[-1]] assert f("U") == 3
benchmark_functions_edited/f11053.py
def f(n): if n == 0: return 0 if n % 2 == 0: return f(n / 2) if n % 2 == 1: return 1 - f((n - 1) / 2) assert f(13) == 1
benchmark_functions_edited/f2279.py
def f(a, b): if b == 0: return a r = a % b return f(b, r) assert f(4, 6) == 2
benchmark_functions_edited/f12183.py
def f(obj, key, default_value): return obj[key] if type(obj) is dict and key in obj.keys() and obj[key] != '' and obj[key] is not None else default_value assert f({'a': 1}, 'b', 2) == 2
benchmark_functions_edited/f2997.py
def f(value): npow2 = 1<<(value-1).bit_length() return npow2 assert f(1) == 1
benchmark_functions_edited/f3512.py
def f(one_rm, r): return (37 - r) / 36 * one_rm assert f(1, 1) == 1
benchmark_functions_edited/f3892.py
def f(n): if n % 5 in [1, 4]: return 1 elif n % 5 in [2, 3]: return -1 else: return 0 assert f(6) == 1
benchmark_functions_edited/f1185.py
def f(n): r = int(n) return r + 1 if r & 1 else r assert f(2.1) == 2
benchmark_functions_edited/f1558.py
def f(y, slope, intercept): return int((y - intercept)/slope) assert f(2, 1, 0) == 2
benchmark_functions_edited/f11836.py
def f(src, band, fallback=None, override=None): if override is not None: return override band0 = band if isinstance(band, int) else band[0] nodata = src.nodatavals[band0 - 1] if nodata is None: return fallback return nodata assert f(None, 1, 0, 1) == 1
benchmark_functions_edited/f2262.py
def f(coord, L): # 2D hardcoded return coord[0] * L[1] + coord[1] assert f([0, 0], [2, 3]) == 0
benchmark_functions_edited/f9685.py
def f(n_workers, len_iterable, factor=4): chunksize, extra = divmod(len_iterable, n_workers * factor) if extra: chunksize += 1 return chunksize assert f(5, 1) == 1
benchmark_functions_edited/f3138.py
def f(m, n): while m % n != 0: oldm = m oldn = n m = oldn n = oldm % oldn return n assert f(10, 35) == 5
benchmark_functions_edited/f8275.py
def f(values, v_ref): ind = 0 good=values[ind] for i, vv in enumerate(values): if abs(vv - v_ref) < good: good = vv ind = i return ind assert f( [1, 2, 3, 4, 5, 6, 7, 8, 9], 1) == 0
benchmark_functions_edited/f11500.py
def f(x: float, y: float) -> float: return abs(x - y) assert f(1, 2) == 1
benchmark_functions_edited/f5896.py
def f(*args): if len(args) == 0: return None elif len(args) == 1: return args[0] else: raise NotImplementedError(str(args)) assert f(1) == 1
benchmark_functions_edited/f8210.py
def f(*primes): res = 1 for x in list(set(primes)): k = primes.count(x) res *= x ** k - x ** (k - 1) return res assert f(2, 3) == 2
benchmark_functions_edited/f7058.py
def f(aggregate): if len(aggregate) == 0: return 0 total = 0 for col in aggregate: total += sum(col) return total/len(aggregate) assert f( [ [0, 0, 0], [0, 0, 0] ] ) == 0
benchmark_functions_edited/f10082.py
def f(coorSM, maxM): return int(coorSM - maxM) assert f(3, 3) == 0
benchmark_functions_edited/f2821.py
def f(R0, gamma, prob_symptoms, rho): Qs = prob_symptoms return R0 * gamma / (Qs + (1 - Qs) * rho) assert f(2, 1, 1, 0) == 2
benchmark_functions_edited/f4546.py
def f(dist_m, time_start, time_end): return dist_m / (time_end - time_start) if time_end > time_start else 0 assert f(100, 30, 30) == 0
benchmark_functions_edited/f7936.py
def f(a: int, b: int) -> int: return a // b if a >= 0 else (a - 1) // b + 1 assert f(5, 6) == 0
benchmark_functions_edited/f10387.py
def f(instructions): size = len(instructions) index = 0 count = 0 while 0 <= index < size: jump = instructions[index] instructions[index] += 1 index += jump count += 1 return count assert f([1, 2, 3]) == 2
benchmark_functions_edited/f9074.py
def f(results): assert len(results) == 2 CorrectSegs = results[0] TotalSegs = results[1] return ((TotalSegs-CorrectSegs)/TotalSegs) * 100 assert f( (3, 3) ) == 0
benchmark_functions_edited/f5326.py
def f(K,s,b,x): return s*x/(K + x)+b assert f(1,1,2,0) == 2
benchmark_functions_edited/f2853.py
def f(l, pred): for i in l: if pred(i): return i return None assert f(range(10), lambda x: x == 3) == 3
benchmark_functions_edited/f7114.py
def f(a, b): while b != 0: a, b = b, a % b return a assert f(30, 36) == 6
benchmark_functions_edited/f887.py
def f(a,b): if(a == b): return 1 else: return 0 assert f((1, 2, 3), (1, 2, 4)) == 0
benchmark_functions_edited/f12118.py
def f(ranked_list, ground_truth): hits = 0 sum_precs = 0 for index in range(len(ranked_list)): if ranked_list[index] in ground_truth: hits += 1 sum_precs += hits / (index + 1.0) if hits > 0: return sum_precs / len(ground_truth) return 0 assert f( [1, 3, 2], [1, 2, 3]) == 1
benchmark_functions_edited/f12833.py
def f(function, array): y = array[0] for i in range(len(array) - 1): #print("array = ", array) #print("y = ", y) y = function(y, array[i + 1]) return y assert f(lambda a, b: a + b, [1, 2, 3]) == 6
benchmark_functions_edited/f3137.py
def f(p1, p2): dx = p1[0] - p2[0] dy = p1[1] - p2[1] return dx * dx + dy * dy assert f((1, 1), (2, 2)) == 2
benchmark_functions_edited/f752.py
def f(i): return sum(1 for e in i) assert f(set()) == 0
benchmark_functions_edited/f4995.py
def f(mat, z): [a, b], [c, d] = mat return (a*z + b)/(c*z + d) assert f( [[1, 1], [1, 1]], 2) == 1
benchmark_functions_edited/f8727.py
def f(w1, w2): ws1 = set(w1) ws2 = set(w2) return len(ws1.intersection(ws2)) assert f(u"abcd", u"dabc") == 4
benchmark_functions_edited/f3471.py
def f(number): last = 0 curr = 1 for _ in range(0, number): last, curr = curr, curr + last return last assert f(6) == 8
benchmark_functions_edited/f12322.py
def f(low_corr: float, high_corr: float) -> float: return (low_corr - 1) ** 2 + (high_corr - 1) ** 2 assert f(1, 0) == 1
benchmark_functions_edited/f12351.py
def f(adapters, position): if position == len(adapters) - 1: return 1 else: answer = 0 for new_position in range(position + 1, len(adapters)): if adapters[new_position] - adapters[position] <= 3: answer += f(adapters, new_position) return answer assert f( [1, 5, 6, 10, 11, 12, 15, 16, 19], 3 ) == 2
benchmark_functions_edited/f7883.py
def f(x): if x == 'adult': return 1 else: return 0 assert f('child') == 0
benchmark_functions_edited/f269.py
def f(x, y): return (y << 5) | x assert f(0, 0) == 0
benchmark_functions_edited/f13932.py
def f(index): if isinstance(index, str): return int(index.strip('S').strip('R')) elif index is None: return None else: return int(index) assert f('S1') == 1
benchmark_functions_edited/f6041.py
def f(xs): count = 0 for i in xs: count += i return count / len(xs) assert f([2, 2]) == 2
benchmark_functions_edited/f3495.py
def f(n): try: return int(n) except ValueError: return float("nan") assert f("-000") == 0
benchmark_functions_edited/f3752.py
def f(xtrue, x): # L2 (Euclidian norm) return abs(xtrue - x) assert f(1, 3) == 2
benchmark_functions_edited/f3018.py
def f(data: list): res = sum(data) / len(data) return res assert f(range(5)) == 2
benchmark_functions_edited/f7966.py
def f(f, t): return f['a_x'] + f['b_x'] * t + f['c_x'] * t * t + f['d_x'] * t * t * t assert f( {'a_x': 1, 'b_x': 2, 'c_x': 3, 'd_x': 4}, 0) == 1
benchmark_functions_edited/f12935.py
def f(vals): if vals[0] is not None and vals[0] == min(x for x in vals if x is not None): return 1 elif vals[1] is not None and vals[1] == min(x for x in vals if x is not None): return 2 elif vals[2] is not None and vals[2] == min(x for x in vals if x is not None): return 3 else: return 0 assert f([0.1, None, 0.1]) == 1
benchmark_functions_edited/f8861.py
def f(val, bits): if (val & (1 << (bits - 1))) != 0: # if sign bit is set e.g., 8bit: 128-255 val = val - (1 << bits) # compute negative value return val # return positive value as is assert f(0, 32) == 0
benchmark_functions_edited/f3554.py
def f(l, m): return (l+1)**2 -1 -l + m assert f(0, 1) == 1
benchmark_functions_edited/f7364.py
def f(source_text, minified_text): orig_size = len(source_text) mini_size = len(minified_text) delta = orig_size - mini_size return delta assert f( ) == 0
benchmark_functions_edited/f3545.py
def f(d,key,default): if key in d: return d[key] else: return default assert f(dict(),"a",1) == 1
benchmark_functions_edited/f10220.py
def f(datetime_in): try: return int((datetime_in.month - 1) / 3) + 1 except AttributeError: return int((datetime_in - 1) / 3) + 1 assert f(3) == 1
benchmark_functions_edited/f1852.py
def f(x: float): return -1 if x < 0 else (1 if x > 0 else 0) assert f(0) == 0
benchmark_functions_edited/f936.py
def f(x, y): if x == y: return 0 if x < y: return -1 return 1 assert f(100, 100) == 0
benchmark_functions_edited/f7063.py
def f(z, alpha): return 1.0 * (z > 0) + alpha * (z <= 0) assert f(-1, 2) == 2
benchmark_functions_edited/f1601.py
def f(counts): return sum([sum(vals.values()) for vals in counts.values()]) assert f({}) == 0
benchmark_functions_edited/f1156.py
def f(xloc, yloc, hw): return ((xloc - hw)**2 + (yloc - hw)**2)**0.5 assert f(3, 4, 0) == 5
benchmark_functions_edited/f10071.py
def f(k, n): N = n/k return k*N*(N+1)/2 assert f(3, 3) == 3
benchmark_functions_edited/f5600.py
def f(value): return round(value + 1e-6 + 1000) - 1000 assert f(2.675) == 3
benchmark_functions_edited/f3860.py
def f(p1, p2): return (2*(p1[0] - p2[0])**2 + 4*(p1[1] - p2[1])**2 + 3*(p1[2] - p2[2])**2)**0.5 assert f( (1, 1, 1), (1, 1, 1) ) == 0
benchmark_functions_edited/f5317.py
def f(a): b = sorted(a) n = len(b) if n % 2 == 0: return (b[n//2-1] + b[n//2]) / 2 return b[n//2] assert f( [1, 2, 3] ) == 2
benchmark_functions_edited/f333.py
def f(x, y): return -x**2 + y assert f(0, 0) == 0
benchmark_functions_edited/f9824.py
def f(B, v): me = 9.10938356e-31 p = me * v e = 1.6e-19 r = p / (e * B) return r assert f(-5, 0) == 0
benchmark_functions_edited/f12832.py
def f( segs ): sc = 0 seglist = segs if segs and len(segs[0])==2 and segs[0][1]==None: seglist = segs[1:] for s in seglist: sc += s[0] return sc assert f( [(0,None), (1,None), (2,None), (3,None)] ) == 6
benchmark_functions_edited/f10738.py
def f(location): locations = { 'USA_AK_FAIRBANKS': 1, 'USA_CA_LOS_ANGELES': 2, 'USA_IL_CHICAGO-OHARE': 3, 'USA_MN_MINNEAPOLIS': 4, 'USA_TX_HOUSTON': 5, 'USA_WA_SEATTLE': 6 } return locations.get(location, 0) assert f('USA_IL_CHICAGO-OHARE') == 3
benchmark_functions_edited/f5274.py
def f(al, br, delta): if br < al: ch = 4294967295 - al return (ch + br) / float(delta) return (br - al) / float(delta) assert f(0, 5, 1) == 5
benchmark_functions_edited/f13029.py
def f(args, attr, default=None): if hasattr(args, attr): return getattr(args, attr) return default assert f({}, 'foo', 1) == 1
benchmark_functions_edited/f11420.py
def f(x, x0, xm, y0, d_y0): return y0 + d_y0 * (1. - (x - x0) / (xm - x0)) * (x - x0) assert f(10, 0, 10, 0, 0) == 0
benchmark_functions_edited/f11531.py
def f(longitude): one_pada = (360 / (12 * 9)) # There are also 108 navamsas one_sign = 12 * one_pada # = 40 degrees exactly signs_elapsed = longitude / one_sign fraction_left = signs_elapsed % 1 return int(fraction_left * 12) assert f(360.0) == 0
benchmark_functions_edited/f13395.py
def f(targets, cat, kwargs): targ = targets[0] if cat: s = cat[targ] if kwargs and targ in kwargs: s = kwargs.configure_new(**kwargs[targ]) return s else: # pragma: no cover # for testing only return targ assert f(list('abcd'), {'a': 1}, None) == 1
benchmark_functions_edited/f4091.py
def f(digits): count = 0 for i in range(5): if digits[i] == digits[i+1]: count += 1 return count assert f(list('122333')) == 3
benchmark_functions_edited/f4837.py
def f(string): return int(float(string)) assert f('0') == 0