Team Ai
Apppublic

cactus183/patchbench-dev

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
buggy_code.py23 linesDownload Raw Back to medium_02
1import math2 3 4def magnitude(v):5    """Return the magnitude (Euclidean norm) of vector v."""6    return math.sqrt(sum(x * x for x in v))7 8 9def normalize(v):10    """Return the unit vector in the same direction as v."""11    # BUG: divides by sum of components instead of magnitude12    s = sum(v)13    if s == 0:14        return [0.0] * len(v)15    return [x / s for x in v]16 17 18def cosine_similarity(a, b):19    """Return the cosine similarity between vectors a and b."""20    na = normalize(a)21    nb = normalize(b)22    return sum(x * y for x, y in zip(na, nb))23