<commit_before># shard.py

# Imports
import matplotlib.pyplot as plt
import numpy as np

from matplotlib import cm
from scipy.linalg import norm

# Plotter
class Plotter(object):
    def __init__(self, delta=0.0):
        self._delta = delta

        i = np.finfo(np.float64)
        self._xmin = i.max
        self._xmax = i.min
        self._ymin = i.max
        self._ymax = i.min

    def __call__(self, ax, P, *args, **kwargs):
        P = np.atleast_2d(P)
        x, y = np.transpose(P)
        ax.plot(x, y, *args, **kwargs)

        self._xmin = min(self._xmin, np.amin(x))
        self._xmax = max(self._xmax, np.amax(x))
        self._ymin = min(self._ymin, np.amin(y))
        self._ymax = max(self._ymax, np.amax(y))

    def _lim(self, min_, max_):
        d = self._delta * (max_ - min_)
        return (min_ - d, max_ + d)

    @property
    def xlim(self):
        return self._lim(self._xmin, self._xmax)

    @property
    def ylim(self):
        return self._lim(self._ymin, self._ymax)

# LineSegment
class LineSegment(object):
    def __init__(self, m, x0):
        self.m = m
        self.x0 = x0
        self._integral_domain_cache = {}

    @classmethod
    def from_points(cls, *args):
        if len(args) == 1:
            p, q = args[0]
        else:
            p, q = args
        return cls(q - p, p)

    @property
    def points(self):
        return np.r_['0,2', self.x0, self.x0 + self.l * self.m]

    @property
    def m(self):
        return self._m

    @m.setter
    def m(self, m):
        m = np.asarray(m)
        norm_m = norm(m)
        if norm_m == 0.0:
            raise ZeroDivisionError
        self._m = m / norm_m
        self.l = norm_m

    @property
    def n(self):
        return np.r_[-self.m[1], self.m[0]]

    def __call__(self, t):
        t = np.atleast_1d(t)
        return self.m * self.l * t[:, np.newaxis] + self.x0

    # closest_preimage
    def closest_preimage(self, Q):
        Q = np.atleast_2d(Q)
        u = np.atleast_1d(np.dot(Q - self.x0, self.m) / self.l)
        u[u < 0.0] = 0.0
        u[u > 1.0] = 1.0
        return u

    # _integral_domain
    def _integral_domain(self, integral_domain):
        k = tuple(integral_domain)
        try:
            X = self._integral_domain_cache[k]
        except KeyError:
            slice_ = tuple(slice(None, d) for d in integral_domain[::-1])
            G = map(np.ravel, np.mgrid[slice_])
            X = np.transpose(G)
            X = np.fliplr(X)
            X[:,1] *= -1
            X[:,1] += integral_domain[1]
            self._integral_domain_cache[k] = X
        return X

    # dt
    def dt(self, integral_domain, outside_left=None):
        # create `X` as scanning `integral_domain` along rows, from
        # "top" (max y) to "bottom" (min y)
        X = self._integral_domain(integral_domain)
        u = self.closest_preimage(X)
        Y = self(u)
        r = X - Y
        d = np.sqrt(np.sum(r**2, axis=1))

        if outside_left is not None:
            s = np.require((np.dot(r, self.n) > 0),
                           dtype=np.float64)
            s *= 2.0
            s -= 1.0
            if not outside_left:
                s *= -1.0
            d *= s

        return d.reshape(integral_domain[::-1])

    def __repr__(self):
        fmt = '[%s]' % ', '.join('%.7g' for i in xrange(len(self.m)))
        return "%s(%s, %s, %.7g)" % (self.__class__.__name__,
                                     fmt % tuple(self.m),
                                     fmt % tuple(self.x0),<commit_msg>Change `_integral_domain` to the class method `_dt_integral_domain` in `LineSegment` in shard.py<commit_after># shard.py

# Imports
import matplotlib.pyplot as plt
import numpy as np

from matplotlib import cm
from scipy.linalg import norm

# Plotter
class Plotter(object):
    def __init__(self, delta=0.0):
        self._delta = delta

        i = np.finfo(np.float64)
        self._xmin = i.max
        self._xmax = i.min
        self._ymin = i.max
        self._ymax = i.min

    def __call__(self, ax, P, *args, **kwargs):
        P = np.atleast_2d(P)
        x, y = np.transpose(P)
        ax.plot(x, y, *args, **kwargs)

        self._xmin = min(self._xmin, np.amin(x))
        self._xmax = max(self._xmax, np.amax(x))
        self._ymin = min(self._ymin, np.amin(y))
        self._ymax = max(self._ymax, np.amax(y))

    def _lim(self, min_, max_):
        d = self._delta * (max_ - min_)
        return (min_ - d, max_ + d)

    @property
    def xlim(self):
        return self._lim(self._xmin, self._xmax)

    @property
    def ylim(self):
        return self._lim(self._ymin, self._ymax)

# LineSegment
class LineSegment(object):
    def __init__(self, m, x0):
        self.m = m
        self.x0 = x0

    @classmethod
    def from_points(cls, *args):
        if len(args) == 1:
            p, q = args[0]
        else:
            p, q = args
        return cls(q - p, p)

    @property
    def points(self):
        return np.r_['0,2', self.x0, self.x0 + self.l * self.m]

    @property
    def m(self):
        return self._m

    @m.setter
    def m(self, m):
        m = np.asarray(m)
        norm_m = norm(m)
        if norm_m == 0.0:
            raise ZeroDivisionError
        self._m = m / norm_m
        self.l = norm_m

    @property
    def n(self):
        return np.r_[-self.m[1], self.m[0]]

    def __call__(self, t):
        t = np.atleast_1d(t)
        return self.m * self.l * t[:, np.newaxis] + self.x0

    # closest_preimage
    def closest_preimage(self, Q):
        Q = np.atleast_2d(Q)
        u = np.atleast_1d(np.dot(Q - self.x0, self.m) / self.l)
        u[u < 0.0] = 0.0
        u[u > 1.0] = 1.0
        return u


    # _dt_integral_domain
    _dt_integral_domain = {}
    @classmethod
    def _integral_domain(cls, integral_domain):
        k = tuple(integral_domain)
        try:
            X = cls._dt_integral_domain[k]
        except KeyError:
            slice_ = tuple(slice(None, d) for d in integral_domain[::-1])
            G = map(np.ravel, np.mgrid[slice_])
            X = np.transpose(G)
            X = np.fliplr(X)
            X[:,1] *= -1
            X[:,1] += integral_domain[1]
            cls._dt_integral_domain[k] = X
        return X

    # dt
    def dt(self, integral_domain, outside_left=None):
        # create `X` as scanning `integral_domain` along rows, from
        # "top" (max y) to "bottom" (min y)
        X = self._integral_domain(integral_domain)
        u = self.closest_preimage(X)
        Y = self(u)
        r = X - Y
        d = np.sqrt(np.sum(r**2, axis=1))

        if outside_left is not None:
            s = np.require((np.dot(r, self.n) > 0),
                           dtype=np.float64)
            s *= 2.0
            s -= 1.0
            if not outside_left:
                s *= -1.0
            d *= s

        return d.reshape(integral_domain[::-1])

    def __repr__(self):
        fmt = '[%s]' % ', '.join('%.7g' for i in xrange(len(self.m)))
        return "%s(%s, %s, %.7g)" % (self.__class__.__name__,
                                     fmt % tuple(self.m),
                                     fmt % tuple(self.x0),
{'fraction_non_alphanumeric': 0.13583693982968031, 'fraction_numerical': 0.01423984364093257, 'mean_word_length': 1.6622073578595318, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '579504', 'n_tokens_mistral': 2652, 'n_tokens_neox': 2563, 'n_words': 596}