<commit_before>#!/usr/bin/env python
"""Python representations of kernel signatures."""
from __future__ import division, print_function

import numbers
import symbolic


named_attributes = ("lower", "upper", "symm", "herm", "spd", "hpd", "work")

datatype_prefixes = {
    "i": "integer",
    "s": "single precision",
    "d": "double precision",
    "c": "single precision complex",
    "z": "double precision complex"
}


class Signature(list):

    """Representation of a kernel signature."""

    def __init__(self, *args, **kwargs):
        """Initialize from file ore arguments."""
        list.__init__(self, args)
        self.flopsstr = None
        self.flops = None

        if not isinstance(self[0], Name):
            self[0] = Name(self[0])

        # infer and compile flops, min, max, attr
        self.init_lambdas(kwargs)

        # lookup for fast argument selection
        self.argtypelookup = {}

    def init_lambdas(self, kwargs):
        """Initialize lambda expressions."""
        lambdaargs = ", ".join(arg.name for arg in self)
        if "complexity" in kwargs and "flops" not in kwargs:
            # legacy support
            kwargs["flops"] = kwargs["complexity"]
        if "flops" in kwargs:
            self.flopsstr = kwargs["flops"]
            self.flops = eval("lambda %s: %s" % (lambdaargs, kwargs["flops"]))
        for arg in self:
            arg.min = None
            arg.max = None
            if isinstance(arg, ArgWithMin) and arg.minstr:
                arg.min = eval("lambda %s: %s" % (lambdaargs, arg.minstr),
                               symbolic.__dict__)
            if isinstance(arg, ArgWithMin) and arg.maxstr:
                arg.max = eval("lambda %s: %s" % (lambdaargs, arg.maxstr),
                               symbolic.__dict__)
            arg.properties = lambda *args: ()
            if arg.propertiesstr:
                lambdarhs = arg.propertiesstr
                for attrname in named_attributes:
                    lambdarhs = lambdarhs.replace(attrname, repr(attrname))
                arg.properties = eval("lambda %s: filter(None, (%s,))" %
                                      (lambdaargs, lambdarhs),
                                      symbolic.__dict__)

        self.check_lambdas()
<commit_msg>evaluate functions in flops symbolically<commit_after>#!/usr/bin/env python
"""Python representations of kernel signatures."""
from __future__ import division, print_function

import numbers
import symbolic


named_attributes = ("lower", "upper", "symm", "herm", "spd", "hpd", "work")

datatype_prefixes = {
    "i": "integer",
    "s": "single precision",
    "d": "double precision",
    "c": "single precision complex",
    "z": "double precision complex"
}


class Signature(list):

    """Representation of a kernel signature."""

    def __init__(self, *args, **kwargs):
        """Initialize from file ore arguments."""
        list.__init__(self, args)
        self.flopsstr = None
        self.flops = None

        if not isinstance(self[0], Name):
            self[0] = Name(self[0])

        # infer and compile flops, min, max, attr
        self.init_lambdas(kwargs)

        # lookup for fast argument selection
        self.argtypelookup = {}

    def init_lambdas(self, kwargs):
        """Initialize lambda expressions."""
        lambdaargs = ", ".join(arg.name for arg in self)
        if "complexity" in kwargs and "flops" not in kwargs:
            # legacy support
            kwargs["flops"] = kwargs["complexity"]
        if "flops" in kwargs:
            self.flopsstr = kwargs["flops"]
            self.flops = eval("lambda %s: %s" % (lambdaargs, kwargs["flops"]),
                              symbolic.__dict__)
        for arg in self:
            arg.min = None
            arg.max = None
            if isinstance(arg, ArgWithMin) and arg.minstr:
                arg.min = eval("lambda %s: %s" % (lambdaargs, arg.minstr),
                               symbolic.__dict__)
            if isinstance(arg, ArgWithMin) and arg.maxstr:
                arg.max = eval("lambda %s: %s" % (lambdaargs, arg.maxstr),
                               symbolic.__dict__)
            arg.properties = lambda *args: ()
            if arg.propertiesstr:
                lambdarhs = arg.propertiesstr
                for attrname in named_attributes:
                    lambdarhs = lambdarhs.replace(attrname, repr(attrname))
                arg.properties = eval("lambda %s: filter(None, (%s,))" %
                                      (lambdaargs, lambdarhs),
                                      symbolic.__dict__)

        self.check_lambdas()

{'fraction_non_alphanumeric': 0.12005163511187608, 'fraction_numerical': 0.0012908777969018934, 'mean_word_length': 1.9368288060644345, 'pattern_counts': {'":': 10, '<': 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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2051216', 'n_tokens_mistral': 1314, 'n_tokens_neox': 1287, 'n_words': 355}