o
    X۷i                     @  s2   d dl mZ d dlZd dlmZ G dd dZdS )    )annotationsN)GDel2Dc                   @  s6   e Zd ZdZdddZdddZddd	Zd
d ZdS )Delaunaya  
    Delaunay tessellation in 2 dimensions.

    Parameters
    ----------
    points : ndarray of floats, shape (npoints, ndim)
        Coordinates of points to triangulate
    furthest_site : bool, optional
        Whether to compute a furthest-site Delaunay triangulation. This option
        will be ignored, since it is not supported by CuPy
        Default: False
    incremental : bool, optional
        Allow adding new points incrementally. This takes up some additional
        resources. This option will be ignored, since it is not supported by
        CuPy. Default: False

    Attributes
    ----------
    points : ndarray of double, shape (npoints, ndim)
        Coordinates of input points.
    simplices : ndarray of ints, shape (nsimplex, ndim+1)
        Indices of the points forming the simplices in the triangulation.
        For 2-D, the points are oriented counterclockwise.
    neighbors : ndarray of ints, shape (nsimplex, ndim+1)
        Indices of neighbor simplices for each simplex.
        The kth neighbor is opposite to the kth vertex.
        For simplices at the boundary, -1 denotes no neighbor.0
    vertex_neighbor_vertices : tuple of two ndarrays of int; (indptr, indices)
        Neighboring vertices of vertices. The indices of neighboring
        vertices of vertex `k` are ``indices[indptr[k]:indptr[k+1]]``.

    Notes
    -----
    This implementation makes use of GDel2D to perform the triangulation in 2D.
    See [1]_ for more information.

    References
    ----------
    .. [1] A GPU accelerated algorithm for 3D Delaunay triangulation (2014).
        Thanh-Tung Cao, Ashwin Nanjappa, Mingcen Gao, Tiow-Seng Tan.
        Proc. 18th ACM SIGGRAPH Symp. Interactive 3D Graphics and Games, 47-55.
    Fc                 C  sV   |j d dkrtd|rtd|rtd|| _t| j| _| j \| _| _d S )N   /Delaunay only supports 2D inputs at the moment.z0furthest_site argument is not supported by CuPy.z.incremental argument is not supported by CuPy.)shape
ValueErrorpointsr   _triangulatorcompute	simplices	neighbors)selfr
   furthest_siteincremental r   S/home/ubuntu/vllm_env/lib/python3.10/site-packages/cupyx/scipy/spatial/_delaunay.py__init__4   s   zDelaunay.__init__c                 C  st   t j|jd ft jd}t jdt jd}|r(t j|jd |jd d ft jd}| j|||\}}|r8||fS |S )a,  
        Find the simplices containing the given points.

        Parameters
        ----------
        xi : ndarray of double, shape (..., ndim)
            Points to locate
        eps: float
            Tolerance allowed in the inside-triangle check.
        find_coords: bool, optional
            Whether to return the barycentric coordinates of `xi`
            with respect to the found simplices.

        Returns
        -------
        i : ndarray of int, same shape as `xi`
            Indices of simplices containing each point.
            Points outside the triangulation get the value -1.
        c : ndarray of float64, same shape as `xi`, optional
            Barycentric coordinates of `xi` with respect to the enclosing
            simplices. Returned only when `find_coords` is True.
        r   )dtyper      )cupyemptyr   int32float64r   find_point_in_triangulation)r   xiepsfind_coordsoutcr   r   r   _find_simplex_coordinatesD   s   $z"Delaunay._find_simplex_coordinatesNc                 C  sF   |du rdt t jj }nt|}|jd dkrtd| ||S )ak  
        Find the simplices containing the given points.

        Parameters
        ----------
        xi : ndarray of double, shape (..., ndim)
            Points to locate
        bruteforce : bool, optional
            Whether to only perform a brute-force search. Not used by CuPy
        tol : float, optional
            Tolerance allowed in the inside-triangle check.
            Default is ``100*eps``.

        Returns
        -------
        i : ndarray of int, same shape as `xi`
            Indices of simplices containing each point.
            Points outside the triangulation get the value -1.
        Nd   r   r   r   )r   finfodoubler   floatr   r	   r!   )r   r   
bruteforcetolr   r   r   r   find_simplexg   s   zDelaunay.find_simplexc                 C  s
   | j  S )z
        Neighboring vertices of vertices.

        Tuple of two ndarrays of int: (indptr, indices). The indices of
        neighboring vertices of vertex `k` are
        ``indices[indptr[k]:indptr[k+1]]``.
        )r   vertex_neighbor_vertices)r   r   r   r   r)      s   
z!Delaunay.vertex_neighbor_vertices)FF)F)FN)__name__
__module____qualname____doc__r   r!   r(   r)   r   r   r   r   r      s    
+

#r   )
__future__r   r   $cupyx.scipy.spatial.delaunay_2d._trir   r   r   r   r   r   <module>   s    