<commit_before>from finiteelementbase import FiniteElementBase
from points import StroudPointSet
from ast import ForAll, Recipe, Wave, Let, IndexSum
import pymbolic as p
from index import BasisFunctionIndex

class Bernstein(FiniteElementBase):
    """Scalar-valued Bernstein element. Note: need to work out the
    correct heirarchy for different Bernstein elements."""

    def __init__(self, cell, degree):
        super(Bernstein, self).__init__()

        self._cell = cell
        self._degree = degree

    def _points_variable(self, points, kernel_data):
        """Return the symbolic variables for the static data
        corresponding to the :class:`PointSet` ``points``."""

        static_key = (id(points),)
        if static_key in kernel_data.static:
            xi = kernel_data.static[static_key][0]
        else:
            xi = p.Variable(kernel_data.point_variable_name(points))
            kernel_data.static[static_key] = (xi, lambda: points.points)

        return xi

    def field_evaluation(self, field_var, q, kernel_data, derivative=None):

        if not isinstance(q.points, StroudPointSet):
            raise ValueError("Only Stroud points may be employed with Bernstien polynomials")

        # Get the symbolic names for the points.
        xi = [self._points_variable(f, kernel_data)
              for f in q.factors.points]

        qs = q.factors[0]
        r = kernel_data.new_variable("r")
        w = kernel_data.new_variable("w")
        alpha = BasisFunctionIndex(self.degree+1)
        s = 1-xi[qs[0]]

        # 1D first
        expr = ForAll(qs[0],
                      Let((r, xi[qs[0]]/s),
                          IndexSum((alpha,),
                                   Wave(w,
                                        alpha,
                                        s**self.degree,
                                        w * r * (self.degree - alpha) / (alpha + 1.0),
                                        w * field_var[alpha])
                                   )
                          )
                      )
        return Recipe(((), (), (q)), expr)<commit_msg>Bug fix in 1d field evaluation<commit_after>from finiteelementbase import FiniteElementBase
from points import StroudPointSet
from ast import ForAll, Recipe, Wave, Let, IndexSum
import pymbolic as p
from index import BasisFunctionIndex

class Bernstein(FiniteElementBase):
    """Scalar-valued Bernstein element. Note: need to work out the
    correct heirarchy for different Bernstein elements."""

    def __init__(self, cell, degree):
        super(Bernstein, self).__init__()

        self._cell = cell
        self._degree = degree

    def _points_variable(self, points, kernel_data):
        """Return the symbolic variables for the static data
        corresponding to the :class:`PointSet` ``points``."""

        static_key = (id(points),)
        if static_key in kernel_data.static:
            xi = kernel_data.static[static_key][0]
        else:
            xi = p.Variable(kernel_data.point_variable_name(points))
            kernel_data.static[static_key] = (xi, lambda: points.points)

        return xi

    def field_evaluation(self, field_var, q, kernel_data, derivative=None):

        if not isinstance(q.points, StroudPointSet):
            raise ValueError("Only Stroud points may be employed with Bernstein polynomials")

        if derivative is not None:
            raise NotImplementedError

        # Get the symbolic names for the points.
        xi = [self._points_variable(f, kernel_data)
              for f in q.factors.points]

        qs = q.factors
        r = kernel_data.new_variable("r")
        w = kernel_data.new_variable("w")
        alpha = BasisFunctionIndex(self.degree+1)
        s = 1-xi[qs[0]]

        # 1D first
        expr = Let((r, xi[qs[0]]/s),
                   IndexSum((alpha,),
                            Wave(w,
                                 alpha,
                                 s**self.degree,
                                 w * r * (self.degree - alpha) / (alpha + 1.0),
                                 w * field_var[alpha])
                            )
                   )

        return Recipe(((), (), (q)), expr)
{'fraction_non_alphanumeric': 0.09395017793594305, 'fraction_numerical': 0.0045077105575326215, 'mean_word_length': 1.8125416944629753, '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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1156588', 'n_tokens_mistral': 1160, 'n_tokens_neox': 1087, 'n_words': 312}