<commit_before>"""
This module defines a class representing an arbitrary Simplex in arbitrary
dimensional space.
"""

from __future__ import division

__author__ = "<NAME>"
__version__ = "2.0"
__maintainer__ = "<NAME>"
__email__ = "<EMAIL>"
__date__ = "May 15, 2012"

import itertools

import numpy as np


class Simplex(object):
    """
    A generalized simplex object. See http://en.wikipedia.org/wiki/Simplex.
    """

    def __init__(self, coords):
        """
        Initializes a Simplex from coordinates.

        Args:
            coords ([[float]]): Coords of the vertices of the simplex. E.g.,
                [[1, 2, 3], [2, 4, 5], [6, 7, 8]].
        """
        self.simplex_dim = len(coords) - 1
        self.space_dim = len(coords[0])
        for c in coords:
            if len(c) != self.space_dim:
                raise ValueError("All coords must have the same space "
                                 "dimension.")
        self._coords = np.array(coords)

    def in_simplex(self, point, tolerance=1e-8):
        """
        Checks if a point is in the simplex using the standard barycentric
        coordinate system algorithm.

        Taking an arbitrary vertex as an origin, we compute the basis for the
        simplex from this origin by subtracting all other vertices from the
        origin. We then project the point into this coordinate system and
        determine the linear decomposition coefficients in this coordinate
        system.  If the coeffs satisfy that all coeffs >= 0 and
        sum(coeffs) <= 1, the composition is in the facet.

        For example, take a tetrahedron. For a tetrahedron, let's label
        the vertices as O, A, B anc C.  Let's call our point coordinate as X.
        We form the composition matrix M with vectors OA, OB and OB, transponse
        it, and solve for M'.a = OX where a are the coefficients.

        If (a >= 0).all() and sum(a) <= 1, X is in the tetrahedron.
        Note that in reality, the test needs to provide a tolerance (set to
        1e-8 by default) for numerical errors.

        Args:
            point ([float]): Point to test
            tolerance (float): Tolerance to test if point is in simplex.
        """
        origin = self._coords[0]
        bary_coords = np.array([self._coords[i] - origin
                                for i in xrange(1, self.simplex_dim + 1)])
        shifted_point = np.array(point) - origin<commit_msg>Xrange -> range for py3k.<commit_after>"""
This module defines a class representing an arbitrary Simplex in arbitrary
dimensional space.
"""

from __future__ import division

__author__ = "<NAME>"
__version__ = "2.0"
__maintainer__ = "<NAME>"
__email__ = "<EMAIL>"
__date__ = "May 15, 2012"

import itertools

import numpy as np


class Simplex(object):
    """
    A generalized simplex object. See http://en.wikipedia.org/wiki/Simplex.
    """

    def __init__(self, coords):
        """
        Initializes a Simplex from coordinates.

        Args:
            coords ([[float]]): Coords of the vertices of the simplex. E.g.,
                [[1, 2, 3], [2, 4, 5], [6, 7, 8]].
        """
        self.simplex_dim = len(coords) - 1
        self.space_dim = len(coords[0])
        for c in coords:
            if len(c) != self.space_dim:
                raise ValueError("All coords must have the same space "
                                 "dimension.")
        self._coords = np.array(coords)

    def in_simplex(self, point, tolerance=1e-8):
        """
        Checks if a point is in the simplex using the standard barycentric
        coordinate system algorithm.

        Taking an arbitrary vertex as an origin, we compute the basis for the
        simplex from this origin by subtracting all other vertices from the
        origin. We then project the point into this coordinate system and
        determine the linear decomposition coefficients in this coordinate
        system.  If the coeffs satisfy that all coeffs >= 0 and
        sum(coeffs) <= 1, the composition is in the facet.

        For example, take a tetrahedron. For a tetrahedron, let's label
        the vertices as O, A, B anc C.  Let's call our point coordinate as X.
        We form the composition matrix M with vectors OA, OB and OB, transponse
        it, and solve for M'.a = OX where a are the coefficients.

        If (a >= 0).all() and sum(a) <= 1, X is in the tetrahedron.
        Note that in reality, the test needs to provide a tolerance (set to
        1e-8 by default) for numerical errors.

        Args:
            point ([float]): Point to test
            tolerance (float): Tolerance to test if point is in simplex.
        """
        origin = self._coords[0]
        bary_coords = np.array([self._coords[i] - origin
                                for i in range(1, self.simplex_dim + 1)])
        shifted_point = np.array(point) - origin
{'fraction_non_alphanumeric': 0.08826541060823265, 'fraction_numerical': 0.012492320294900676, 'mean_word_length': 2.1652624756966947, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4778220', 'n_tokens_mistral': 1437, 'n_tokens_neox': 1338, 'n_words': 570}