
&]\c        S   @` s  d  d l  m Z m Z m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 m
 Z
 m Z m Z m Z m Z d  d l Z d  d l m Z d  d l m Z d  d l j j Z d  d l m Z d  d l m Z d  d l Z d   Z d	   Z e d
  Z e j j  d  d@ dA dB dC dD dE g Z! e j" d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g gQ  Z# e j" d d g d d  g d d g d  d g d  d  g d  d g d d e j$ e j%  j& g d d  g d d g g	  Z' e j j( d d  e j" d  d  g d  d g d d  g d d g g  g Z) e) e j j( d d  d e j" d  d  g d  d g d d  g d d g g  g Z* i
 e j+ e!  d 6e j j( d d  d 6e j j( d d  d  6e j j( d d!  d" 6e j j( d d#  d$ 6e j j( d d%  d& 6e j j( d d'  d( 6e j j( d d)  d* 6e# d+ 6e' d, 6Z, i e) d f d- 6e* d f d. 6Z. d/   Z/ x, e, D]$ Z0 x dF D] Z1 e/ e0 e1  qWqWd1 e2 f d2     YZ3 d3 e2 f d4     YZ4 d5 e2 f d6     YZ5 d7 e2 f d8     YZ6 d9   Z7 d: dG d;     YZ8 d< dH d=     YZ9 d> e2 f d?     YZ: d S(I   i    (   t   divisiont   print_functiont   absolute_importN(   t   assert_equalt   assert_almost_equalt   assert_t   assert_allcloset   assert_array_equal(   t   raises(   t   xrange(   t   cKDTree(   t   Voronoic         C` s   t  t |    S(   N(   t   tuplet   sorted(   t   x(    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   sorted_tuple   s    c         C` s   t  t j |    S(   N(   R   t   npt   unique(   R   (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   sorted_unique_tuple   s    c         C` s   t  |  t j  r! |  j   }  n  t  | t j  rB | j   } n  t t | |    }  |  j   t t | |   } | j   t |  |  d  S(   N(   t
   isinstanceR   t   ndarrayt   tolistt   listt   mapt   sortR   (   t   at   bt   tpl(    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt!   assert_unordered_tuple_list_equal   s    

i  i   g      ?g      ?gQ	gzGgQgHzGg        gHzG?gQ?gzG@gQ	@ii
   i   g      ?s   some-pointsi   s	   random-2di   s	   random-3di   s	   random-4di   s	   random-5di   s	   random-6di   s	   random-7di   s	   random-8ds   pathological-1s   pathological-2s   bug-2850s
   bug-2850-2c   	      C` s   t  |  } | j d } d } | d } |  d k r< d } n |  d k rQ d } n  | |  g } x8 t | t |  |  D] } | j | | | | ! qw Wd |  | f } | t k s t  | | f t | <d S(	   s<   
    Generate incremental datasets from basic data sets
    i   i   s   some-pointss   QJ Pps   pathological-1i   s   %s-chunk-%dN(   t   DATASETSt   shapet   NoneR	   t   lent   appendt   INCREMENTAL_DATASETSt   AssertionError(	   t   namet	   chunksizet   pointst   ndimt   optst   nmint   chunkst   jt   new_name(    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   _add_inc_datae   s    

		i   t
   Test_Qhullc           B` s   e  Z d    Z d   Z RS(   c      	   C` sC  t  j d t j d d g d d g d d g d d g d d g g  d  } t j | j    } t  j d t j d d g d d g d d g d d g g  d  } t j | j    } t j | j    } | j   t j | j    } | j   t t	 | j  t t	 | j  t
 | d | d  t | d | d d t t | d	 | d	 d t t | d
 | d
 d t t | d | d  t
 | d | d  t | d | d d t t | d	 | d	 d t t | d
 | d
 d t t | d | d  | j   t t	 | j  | j   t t	 | j  d  S(   Nt   vi    i   g      ?g      ?t   Qzg       @R   i   i   i   (   t   qhullt   _QhullR   t   arrayt   copyt   deepcopyt   get_voronoi_diagramt   closet   assert_raisest   RuntimeErrorR   R   R   R   (   t   selfR   t   xdt   yt   ydt   xd2t   yd2(    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_swapping   s8    	9		0	



c         C` sn   t  j d d g d d g d d g d d g d d g d d g d d g d d g d d g g	  } t |  d  S(   Ni    i   i   (   R   R3   R   (   R:   R&   (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_issue_8051   s    `(   t   __name__t
   __module__R@   RA   (    (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyR.      s   	&t   TestUtilitiesc           B` st   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d e	 d d	  Z
 d
   Z e j j d    Z RS(   s-   
    Check that utility functions work.

    c         C` s   t  j d d d d g d t  j } t j |  } t | j d d d g d d d g g  xk d d d g D]Z } | j | d   } t | | d d
 d | f t j | | d   } t | |  qk Wd  S(   Ni    i   t   dtypei   i   g      ?g      ?g333333?g?t   err_msgs   %r(   i    i    (   i    i   (   i   i   (   i   i    (   g      ?g      ?i   (   g      ?g      ?i    (   g333333?g?i   (	   R   R3   t   doubleR1   t   DelaunayR   t   verticest   find_simplext   tsearch(   R:   R&   t   trit   pt   iR+   (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_find_simplex   s    $(c         C` sG  t  j d d d d d g d t  j } t  j d d	 g d t  j } t j |  } | j |  } | j |  } | j |  } x t | j  D] \ } } | | d }	 | | d }
 | | d
 } t  j	 |	 | |
 |  } | t  j
 t  j | |   } | t  j | d
  9} t  j | | |  } t | | |  q Wd  S(   Ni    i   g]2ʐ?g>mj?g~T!?g^Rz?RE   gB?g?i   (   i    i    (   i   i   (   i   i    (   g]2ʐ?g>mj?(   g~T!?g^Rz?(   R   R3   RG   R1   RH   t   lift_pointst   plane_distancet	   enumerateRI   t   crosst   sqrtt   dott   signR   (   R:   R   RM   RL   t   zt   pzt   distR+   R/   t   x1t   x2t   x3t   nt   d(    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_plane_distance   s     c         C` sk   t  j d d d d	 g d t  j } t j |  } t | j d d g d d g d d g d d g g  d  S(
   Ni    i   RE   i   i   (   i    i    (   i    i   (   i   i   (   i   i    (   R   R3   RG   R1   RH   R   t   convex_hull(   R:   R&   RL   (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_convex_hull   s    $c         C` sr   t  j d
 d d d d d d d g  } t j |  } t | j d d d d d t | j d d d d d	 d  S(   Ni    i   g      ?t   rtolg+=RF   s   Volume of cube is incorrectg      @s   Area of cube is incorrect(   i    i    i    (   i    i   i    (   i   i    i    (   i   i   i    (   i    i    i   (   i    i   i   (   i   i    i   (   i   i   i   (   R   R3   R1   t
   ConvexHullR   t   volumet   area(   R:   R&   t   hull(    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_volume_area   s    c         C` sx   t  j d& d' d( d) d* d+ d, d- d. d/ g
  } t j |  } t | j d d  d! d" d# t | j d$ d  d! d" d% d  S(0   NgQ4?gΜR@?gX&lL5?gfNz?gjM?g{D흚j?ga?8\?g?gw5K?g,lnq?g6=?gU?gw컝?g`?ga?g+q?g\hϱ?gLg?gGe?gE9;?gd:L?gȊKB?gBYM?g?g~EHy?gUdk?gmVq"?gqp?ge?g\*L?gY/?Rb   gHz>RF   s(   Volume of random polyhedron is incorrectg\4?s&   Area of random polyhedron is incorrect(   gQ4?gΜR@?gX&lL5?(   gfNz?gjM?g{D흚j?(   ga?8\?g?gw5K?(   g,lnq?g6=?gU?(   gw컝?g`?ga?(   g+q?g\hϱ?gLg?(   gGe?gE9;?gd:L?(   gȊKB?gBYM?g?(   g~EHy?gUdk?gmVq"?(   gqp?ge?g\*L?(   R   R3   R1   Rc   R   Rd   Re   (   R:   R&   Rf   (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_random_volume_area   s    	c         C` s  d } d } t  j j | | f  } t j | d | d  d d  f d t } t j | d | d  d d  f d t } x t | d |  D] } t j | d | d  d d  f  } | j | | | d  d d  f  | j | | | d  d d  f d t t | j | j d d t | j | j d d t | j	 | j	 d d t | j	 | j	 d d q Wd S(	   sw   Test that incremental mode gives the same volume/area as
        non-incremental mode and incremental mode with restarti   i   Ni   t   incrementalt   restartRb   gHz>(
   R   t   randomR1   Rc   t   Truet   ranget
   add_pointsR   Rd   Re   (   R:   t	   nr_pointst   dimR&   t   inc_hullt   inc_restart_hullRN   Rf   (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt)   test_incremental_volume_area_random_input  s    //)'-t    i    c      	   C` s  | j  | j } d | j d } | j d d  | } d   } t j t  j }	 | | j |  }
 t j	 d d  } zC t j
 |
  j d d  t |
 |  | d k  j d d  B} Wd t j	 |   Xt | j   d	 | t j |  f  | d d  d d
  d d  f | d d  d
 d d d  f } t j g  t | j  D]1 } t j j | | d d  d d  f  ^ qL } t j | j d d  d d f  | t j |	  k  B} t | j   d	 | t j |  f  | j |  } | d
 k t j
 | j d d  d d f  B} t | j   d	 | t j |  f  | r| | k j d d  } | | d | k j d d  O} | d
 k | B} t | j   d	 | t j |  f  n  d S(   s@   Check that a triangulation has reasonable barycentric transformsi   g      ?t   axisc         S` sh   |  j  d } |  d  d   d d  d   f } |  d  d   d  d  d  d   f } t j d | | |  S(   Ni   is
   ijk,ik->ij(   R   R   t   einsum(   t   trR   R'   t   rt   Tinv(    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   barycentric_transform.  s    %t   invalidt   ignoreg?Ns   %s %sii    (   R&   RI   R'   t   sumR   t   finfot   floatt   epst	   transformt   seterrt   isnant   allt   absR   t   nonzeroR   R3   Rm   t   nsimplext   linalgt   dett   isfiniteRT   RJ   t   any(   R:   RL   RF   t	   unit_cubet   unit_cube_tolRI   t   sct	   centroidsRz   R   t   ct   olderrt   okt   qt   kRd   R+   t   at_boundary(    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   _check_barycentric_transforms#  s0    	C'E	G8'/' c         C` s   t  j t j j t j j t  d d   } | d } | j   t j	 |  } t  j
 | j d  d   d d f  j   } t | d k  |  |  j |  d  S(   Nt   datas   degenerate_pointset.npzR   i    i   (   R   t   loadt   ost   patht   joint   dirnamet   __file__R7   R1   RH   R   R   R}   R   R   (   R:   R   R&   RL   t	   bad_count(    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt&   test_degenerate_barycentric_transformsT  s    !

+c   
   
   C` s0  t  j t  j } i d d 6d d 6d d 6d d 6} t  j d  j d k  } xt d d	  D]} t  j d d
 | |  } t  j t	 t
 t  j t  j t  j | g |       j } d | } t j |  } |  j | d | d t t  j j d  t  j j | j d  d k  }	 | |	 d  d   f c d | t  j j | |	 d  d   f j   d 7<t j |  } |  j | d | d t d d | t j t  j | | f  } |  j | d | d t d d | | s\ t  j j d  t  j j | j d  d k  }	 | |	 d  d   f c d | t  j j | |	 d  d   f j   d 7<t j |  } |  j | d | d t d d | t  j j d  t  j j | j d  d k  }	 | |	 d  d   f c d | t  j j | |	 d  d   f j   d 7<t j |  } |  j | d | d t d d | q\ q\ Wd  S(   NiF   i   i   i   i   i   i    i   i   i   s   ndim=%dRF   R   i  g?g      ?R   i  i  i  g    .Ag    cA(   R   R~   R   R   t   intpt   itemsizeR	   t   linspacet   c_R   R   t   ravelt   broadcast_arrayst   ix_t   TR1   RH   R   Rl   Rk   t   seedt   randR   t   r_(
   R:   R   t   npointst   _is_32bit_platformR'   R   t   gridRF   RL   t   m(    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt    test_more_barycentric_transformse  sH    ";
GGG(   RB   RC   t   __doc__RO   R_   Ra   Rg   Rh   Rs   t   FalseR   R   t   pytestt   markt   slowR   (    (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyRD      s   						/	t   TestVertexNeighborVerticesc           B` s,   e  Z d    Z d   Z d   Z d   Z RS(   c   
   
   C` s  g  t  | j j d  D] } t   ^ q } xS | j D]H } x? | D]7 } x. | D]& } | | k rP | | j |  qP qP WqC Wq6 W| j \ } } g  }	 xM t  | j j d  D]5 } |	 j t t t	 | | | | | d !   q Wt
 |	 | d d |	 | f d  S(   Ni    i   RF   s   %r != %r(   Rm   R&   R   t   sett	   simplicest   addt   vertex_neighbor_verticesR!   R   t   intR   (
   R:   RL   R+   t   expectedt   sR   R   t   indptrt   indicest   got(    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   _check  s    , 3c         C` sA   t  j d d d g d t  j } t j |  } |  j |  d  S(   Ni    i   RE   (   i    i    (   i    i   (   i   i    (   R   R3   RG   R1   RH   R   (   R:   R&   RL   (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_triangle  s    !c         C` sD   t  j d d d d g d t  j } t j |  } |  j |  d  S(   Ni    i   RE   (   i    i    (   i    i   (   i   i   (   i   i    (   R   R3   RG   R1   RH   R   (   R:   R&   RL   (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_rectangle  s    $c         C` sJ   t  j d d d d	 d
 d g d t  j } t j |  } |  j |  d  S(   Ni    i   g      ?g?RE   (   i    i    (   i    i   (   i   i   (   i   i    (   g      ?g      ?(   g?g      ?(   R   R3   RG   R1   RH   R   (   R:   R&   RL   (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_complicated  s    (   RB   RC   R   R   R   R   (    (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyR     s   			t   TestDelaunayc           B` s   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z e j j d
 e e   d    Z RS(   s*   
    Check that triangulation works.

    c         C` s)   t  j j d  } t t t j |  d  S(   Ni   (   R   t   mat
   masked_allR8   t
   ValueErrorR1   RH   (   R:   t   masked_array(    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_masked_array_fails  s    c         C` sD   t  j d d d d t  j f g d t  j } t t t j |  d  S(   Ni    i   RE   (   i    i    (   i    i   (   i   i   (   R   R3   t   nanRG   R8   R   R1   RH   (   R:   t   points_with_nan(    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_array_with_nans_fails  s    -c         C` s   x t  d d  D] } t j | d | f  } x$ t  |  D] } d | | | f <q< Wd | d d  d   f <t j |  } | j j   t | j t j | d d t	 d  d  d   f  t | j d t j | d d t	 d  d  d   f  q Wd  S(   Ni   i   i   g      ?iRE   (   R	   R   t   zerosR1   RH   RI   R   R   t   arangeR   R   t	   neighbors(   R:   t   ndR&   R+   RL   (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_nd_simplex  s    3c         C` s   t  j d d d	 d
 g d t  j } t j |  } t | j d d d g d d d g g  t | j d d d g d d d g g  d  S(   Ni    i   RE   i   i   i(   i    i    (   i    i   (   i   i   (   i   i    (   R   R3   RG   R1   RH   R   RI   R   (   R:   R&   RL   (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_2d_square  s    $(c         C` s   t  j d d d d g d t  j } t  j d d d d g d t  j } t  j | | f } t  j | | f } t j t  j | | f  } t j t  j | | f  } d  S(   Ni    i   RE   (   R   R3   t   float64R   R1   RH   R   (   R:   R   R<   t   xpt   ypRL   t   tri2(    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_duplicate_points  s    $$c         C` s   t  d } t j |  } t | j | j j   | j    t | j | j j   | j    t  d } t j |  } t | j | j j   | j    t | j | j j   | j    d  S(   Ns   pathological-1s   pathological-2(   R   R1   RH   R   R&   RI   t   maxt   min(   R:   R&   RL   (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_pathological  s    
##
#c         C` so   t  j j d d  } t  j | | f } t j | d d } t t  j | j j	    t  j
 t |    d  S(   Ni
   i   t   qhull_optionss	   QJ Qbb Pp(   R   Rk   R   R   R1   RH   R   R   R   R   R   R    (   R:   R&   RL   (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_joggle   s
    c         C` s   t  j j d d  } t  j | | f } t j |  } t t t  j | j	 j
     t |  d k  t t | j  t |  d k  t t t  j | j d  d   d f   t |  d k  t t  j | j d k   d  S(   Ni
   i   i    (   R   Rk   R   R   R1   RH   R   R    R   R   R   t   coplanarR   t   vertex_to_simplex(   R:   R&   RL   (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_coplanar  s    2#<c         C` sS   d d	 d
 d d g } t  j | d t } t j d d g  } t | j |  d  S(   Ni    i   g      ?g?t   furthest_sitei   i   (   i    i    (   i    i   (   i   i    (   g      ?g      ?(   g?g?(   i   i   i    (   i   i   i    (   R1   RH   Rl   R   R3   R   R   (   R:   R&   RL   R   (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_furthest_site  s    R$   c   	      C` su  t  | \ } } t j | d d } t j | d d t d | } x | d D] } | j |  qO Wt j |  } t j | d d t d | } t |  d k r | j t j | d d d d t n  | j d  r?t	 t j
 | j j    t j | j d   t	 t j
 | j j    t j | j d   n t | j | j d t t | j | j d t d  S(	   NRu   i    Ri   R   i   Rj   t   pathologicalR   (   R"   R   t   concatenateR1   RH   Rl   Rn   R    t
   startswithR   R   R   R   R   R   R   R   (	   R:   R$   R*   R(   R&   t   objt   chunkt   obj2t   obj3(    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_incremental   s*    		
(   RB   RC   R   R   R   R   R   R   R   R   R   R   R   R   t   parametrizeR   R"   R   (    (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyR     s   									c         C` s  t  t t |   } t  t t |   } | | k r|  j d d k rd t j t  j } x| D]\ } } x| D]w\ } } |  | |  | } | t j j	 |  } t j
 | d | d g  }	 t j |	 |  | |  |  }
 t j |	 |  | |  |  } t j t j |
 |	  d  s+qy n  t j t j | |	  d  sOqy n  t j | |  | |  |  }
 t j | |  | |  |  } t j | |  | |  |  } |
 | k  sy |
 | | k rqy n  | | k  sy | | | k rqy n  Pqy Wt d   qf Wd  St | |  d  S(   Ni   i   i  i    s   comparison fails(   R   R   R   R   R   R~   R   R   R   t   normR3   RU   t   allcloseR#   R   (   R&   t   facets_1t   facets_2R   R   R   t   apt   bpt   tR]   t   c1t   c2t   c3(    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   assert_hulls_equalE  s4    t   TestConvexHullc           B` st   e  Z d    Z d   Z e j j d e e   d    Z	 e j j d e e
   d    Z d   Z d   Z RS(   c         C` s)   t  j j d  } t t t j |  d  S(   Ni   (   R   R   R   R8   R   R1   Rc   (   R:   R   (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyR   }  s    c         C` sA   t  j d d d t  j f g d t  j } t t t j |  d  S(   Ni    i   i   RE   (   i    i    (   i   i   (   R   R3   R   RG   R8   R   R1   Rc   (   R:   R   (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyR     s    *R$   c         C` s   t  | } t j |  } t j |  } t | | j | j  | j d d k ry t t	 j
 | j  t	 j | j   n t t	 j
 | j  | j  d  S(   Ni   i   (   R   R1   RH   Rc   R   R`   R   R   R   R   R   R   RI   (   R:   R$   R&   RL   Rf   (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_hull_consistency_tri  s    
(c   	      C` s   t  | \ } } t j | d d } t j | d d t } x | d D] } | j |  qI Wt j |  } t j | d d t } t |  d k r | j t j | d d d d t n  t | | j	 | j	  t | | j	 | j	  d  S(   NRu   i    Ri   i   Rj   (
   R"   R   R   R1   Rc   Rl   Rn   R    R   R   (	   R:   R$   R*   t   _R&   R   R   R   R   (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyR     s    
c         C` s   t  j j d  t  j j d d  } t j |  } t t  j | j  t  j	 | j
   | j | j
 j \ } } t  j | | j   | | j    } t t  j t  j t  j |   d k   d  S(   Ni  i   i   i    (   R   Rk   R   R   R1   Rc   R   R   R   R   RI   R&   R   t   arctan2t   meanR   R   t   difft   unwrap(   R:   R&   Rf   R   R<   t   angle(    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_vertices_2d  s    %&c         C` sf   t  j d d d	 d
 d d d d g  } t j |  } t | j d d d t | j d d d d  S(   Ni    i   g      ?Rb   g+=g      @(   i    i    i    (   i    i   i    (   i   i    i    (   i   i   i    (   i    i    i   (   i    i   i   (   i   i    i   (   i   i   i   (   R   R3   R1   Rc   R   Rd   Re   (   R:   R&   RL   (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyRg     s
    (   RB   RC   R   R   R   R   R   R   R   R   R"   R   R   Rg   (    (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyR   |  s   		$$	t   TestVoronoic           B` st   e  Z d    Z d   Z d   Z e j j d e e	   d    Z
 d   Z e j j d e e   d    Z RS(   c         C` s)   t  j j d  } t t t j |  d  S(   Ni   (   R   R   R   R8   R   R1   R   (   R:   R   (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyR     s    c      
   C` s;   d d d d d	 d
 d d d g	 } d } |  j  | |  d  S(   Ni    i   i   s	  
        2
        5 10 1
        -10.101 -10.101
           0.5    0.5
           1.5    0.5
           0.5    1.5
           1.5    1.5
        2 0 1
        3 3 0 1
        2 0 3
        3 2 0 1
        4 4 3 1 2
        3 4 0 3
        2 0 2
        3 4 0 2
        2 0 4
        0
        12
        4 0 3 0 1
        4 0 1 0 1
        4 1 4 1 3
        4 1 2 0 3
        4 2 5 0 3
        4 3 4 1 2
        4 3 6 0 2
        4 4 5 3 4
        4 4 7 2 4
        4 5 8 0 4
        4 6 7 0 2
        4 7 8 0 4
        (   i    i    (   i    i   (   i    i   (   i   i    (   i   i   (   i   i   (   i   i    (   i   i   (   i   i   (   t   _compare_qvoronoi(   R:   R&   t   output(    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_simple  s
    		"c         K` sf  g  | j    j   D]! } t t t | j     ^ q } t | d d  } t t t | d d | !  } t | d d  } g  | d | d | | !D]- } g  | d D] } t |  d ^ q ^ q }	 t | d | | d  }
 g  | d | | D], } g  | d d !D] } t |  ^ q^ q } g  | d | | D]- } g  | d D] } t |  d ^ qT^ qC} t j	 | |  } d   } t
 | j |  t t t t | j   t t t |	    t t t t | |   t t | |     } t t t t | | j j     t t | | j     } | j   | j   t | |  d S(   s:   Compare to output from 'qvoronoi o Fv < data' to Voronoi()i   i    i   i   c         S` s   t  t |    S(   N(   R   R   (   R   (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt	   sorttuple  s    N(   t   stript
   splitlinesR   R   R   t   splitR   R   R1   R   R   RI   R   R   t   regionst   zipt   ridge_pointsR   t   ridge_verticesR   (   R:   R&   R  t   kwR   t   nvertexRI   t   nregionR<   R  t   nridgeR	  R
  t   vorR  t   p1t   p2(    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyR     s,    : JBC	3!

R$   c         C` s   t  | } t |  } t j |  } x | j j   D] \ } } t j t j |  d k  se q5 n  | j	 | j
 d d  } d | | d | } | j | | d d \ }	 }
 t |
 | d  | j | | d d \ }	 }
 t |
 | d  q5 Wd  S(   Ni    Ru   gư>R   i   (   R   t   KDTreeR1   R   t
   ridge_dictt   itemsR   R   t   asarrayRI   R   t   queryR   (   R:   R$   R&   t   treeR  RM   R/   t   ridge_midpointR^   RY   R   (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_ridges  s    
c         C` s5   d d d	 d
 d g } d } |  j  | | d t d  S(   Ni    i   g      ?g?s'  
        2
        3 5 1
        -10.101 -10.101
        0.6000000000000001    0.5
           0.5 0.6000000000000001
        3 0 1 2
        2 0 1
        2 0 2
        0
        3 0 1 2
        5
        4 0 2 0 2
        4 0 1 0 1
        4 0 4 1 2
        4 1 4 0 1
        4 2 4 0 2
        R   (   i    i    (   i    i   (   i   i    (   g      ?g      ?(   g?g?(   R   Rl   (   R:   R&   R  (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyR   +  s    c         ` s  t  | d d j d d k r# d  St  | \ } } t j | d d } t j | d d t d | } x | d D] } | j |  qr Wt j |  } t j | d d t d | } t |  d k r | j t j | d d d d t n  t	 t | j
  t | j
   t	 t | j
  t | j
   x | | f D]   i d d 6 x\ t   j  D]K \ }	 }
 x< t | j  D]+ \ } } t j |
 |  r||  |	 <q|q|Wq`W    f d	    d
   } t	 |    j   | | j   t	 |    j   | | j   q=Wd  S(   Ni    i   i   Ru   Ri   R   Rj   ic         ` sv   t  |  d  r8 t t g  |  D] }  |  ^ q   Sy  |  SWn+ t k
 rq t d   j |  f   n Xd  S(   Nt   __len__s,   incremental result has spurious vertex at %r(   t   hasattrR   R   t   KeyErrorR#   RI   (   R   R<   (   t   objxt   remapt
   vertex_map(    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyR  h  s    )c         S` sj   t  t t |    } d | k r1 | j d  n  g  | D] }  t |   d k r8 |  ^ q8 } | j   | S(   Ni   (    (    (   R   R   R   t   removeR    R   (   R   R  (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt
   simplifiedq  s    +
(   R"   R   R   R   R1   R   Rl   Rn   R    R   t   point_regionRR   RI   R   R  R
  (   R:   R$   R*   R(   R&   R   R   R   R   RN   R/   R+   t   v2R!  (    (   R  R  R  s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyR   C  s<    		
		(   RB   RC   R   R  R   R   R   R   R   R   R  R   R"   R   (    (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyR     s   		)	"$	t   Test_HalfspaceIntersectionc           B` s8   e  Z d  d  Z d   Z d   Z d   Z d   Z RS(   gHz>c         C` s   t  | j | j  t j | j d f d t } x[ | D]S } t j t | |  | k  j d d   d } t  | j d  t | | d <q9 Wt	 | j    d S(   s2   Check that every line in arr1 is only once in arr2i    RE   Ru   i   N(   i   (
   R   R   R   R   t   boolR   R   R   Rl   R   (   R:   t   arr1t   arr2Rb   t   truthst   l1t   indexes(    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   assert_unordered_allclose  s    /c         C` s   t  j d d d g d d d g d d d g d d d g g  } t  j d d g  } t  j d d g d d g d d g d d g g  } t j | |  } t | | j  d  S(   Ng      g        g      ?g      ?(   R   R3   R1   t   HalfspaceIntersectionR   t   intersections(   R:   t
   halfspacest   feasible_pointR&   Rf   (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt    test_cube_halfspace_intersection  s    3c   
      C` s  t  j j t  j j t  d d  } t j |  } t j | d  d   d d   f | d  d   d  d  f f  } t j d d d d g  } t	 j
 | |  } t | j j d  t | j d  t t | j  d  x$ | j D] } t t |  d  q W| d  d   d	 f | d  d   d  d	  f j |  } |  j | d  d   d  d	  f j | j | j  t j d d d
 d g  } x9 | D]1 }	 t t j | j |	 k j d d   d  qWd  S(   NR   s   selfdual-4d-polytope.txti   g        i   i   g      @@i   ig      ?g      Ru   (   i   i   (   R   R   R   R   R   R   t
   genfromtxtt   hstackR3   R1   R,  R   R-  R   R   t   dual_volumeR    t   dual_facetsRU   R+  R   t   dual_pointst	   itertoolst   permutationsR}   R   (
   R:   t   fnamet   ineqsR.  t
   feas_pointt   hst   facett   distsR&   t   point(    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt$   test_self_dual_polytope_intersection  s     	B93c         C` s   t  j d d d g d d d g d d d g d d d g g  } t  j d d d g  } t t t j | |  t  j d g d g g  } t t t j | |  t  j d d g g  } t t t j | |  t  j d d g  } t t j t j | |  d  S(   Ng      g        g      ?g      ?g      (   R   R3   R8   R   R1   R,  t
   QhullError(   R:   R.  R/  (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   test_wrong_feasible_point  s    c      
   C` s/  t  j d d d d g d d d d g d d d d g d d d d g d d d d g d d d d g g  } t  j d d d g d d d g d d d g d d d g g  } t  j d g g d  } t  j t  j | | f  | f  } t  j d d d g  } t j | | d t } t j | | d t } x t |  D] \ } }	 | j |	 t  j	 d  d   f  | j |	 t  j	 d  d   f d t t  j | | d  | d  d  d   f f  }
 t j |
 |  } t
 | j | j  t
 | j | j  t
 | j | j  |  j | j | j  q;W| j   d  S(	   Ng        g      g      g      ?i   i   Ri   Rj   (   R   R3   R2  t   vstackR1   R,  Rl   RR   t   add_halfspacest   newaxisR   R.  R-  R+  R7   (   R:   R.  t   extra_normalst   offsetst   extra_halfspacesR:  t   inc_hst
   inc_res_hsRN   t   ehst   totalR;  (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyR     s4     &/(   RB   RC   R+  R0  R?  RA  R   (    (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyR$    s
   			(   i    i    (   i    i   (   i   i    (   i   i   (   g      ?g      ?(   g      ?g      ?(   i   i   i   (    (    (;   t
   __future__R    R   R   R   R4   R   t   numpyR   t   numpy.testingR   R   R   R   R   R   R8   t   scipy._lib.sixR	   t   scipy.spatial.qhullt   spatialR1   t   scipy.spatialR
   R  R   R6  R   R   R   R   Rk   R   R&   R3   t   pathological_data_1R~   t   float_R   t   pathological_data_2R   t   bug_2850_chunkst   bug_2850_chunks_2R  R   R   R"   R-   R$   R%   t   objectR.   RD   R   R   R   R   R   R$  (    (    (    s=   lib/python2.7/site-packages/scipy/spatial/tests/test_qhull.pyt   <module>   s   (		$$$$$$$$$--$$$$$$$$$76;
	,"	7F