<commit_before>from __future__ import division
from itertools import izip


def load():
    return 'file:output.txt'


def pixels(f):
    for line in f:
        line = line.strip()
        if not line:
            continue
        if 'x' in line:
            # Skip dimensions line.
            continue

        for part in line.split(','):
            yield int(part)


def score(orig, relaxed):
    total_dist = 0
    count = 0

    with open(orig) as orig_f:
        with open(relaxed) as relaxed_f:
            for orig_p, relaxed_p in izip(pixels(orig_f), pixels(relaxed_f)):
                total_dist += abs(orig_p - relaxed_p)
                count += 1

    return total_dist / 255 / count<commit_msg>zynq-sobel eval: avoid crash on length mismatch<commit_after>from __future__ import division
import itertools


def load():
    return 'file:output.txt'


def pixels(f):
    for line in f:
        line = line.strip()
        if not line:
            continue
        if 'x' in line:
            # Skip dimensions line.
            continue

        for part in line.split(','):
            yield int(part or 0)


def score(orig, relaxed):
    total_dist = 0
    count = 0

    with open(orig) as orig_f:
        with open(relaxed) as relaxed_f:
            it = itertools.izip_longest(
                pixels(orig_f),
                pixels(relaxed_f),
                fillvalue=0,
            )
            for orig_p, relaxed_p in it:
                total_dist += abs(orig_p - relaxed_p)
                count += 1

    return total_dist / 255 / count
{'fraction_non_alphanumeric': 0.08498402555910543, 'fraction_numerical': 0.008945686900958467, 'mean_word_length': 1.686106346483705, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2062860', 'n_tokens_mistral': 493, 'n_tokens_neox': 459, 'n_words': 145}