
ʽXc        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 m	 Z	 m
 Z
 m Z m Z m Z m Z m Z m Z d  d l m Z d  d l j j Z d  d l m Z d  d l Z d   Z d   Z e d  Z e j j d	  d? d@ dA dB dC dD 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]$ Z/ x dE D] Z0 e. e/ e0  qWqWd/ e1 f d0     YZ2 d1 e1 f d2     YZ3 d3 e1 f d4     YZ4 d5 e1 f d6     YZ5 d7   Z6 d8 dF d9     YZ7 d: dG d;     YZ8 d< e1 f d=     YZ9 e: d> k re   n  d S(H   i    (   t   divisiont   print_functiont   absolute_importN(   t   assert_equalt   assert_almost_equalt   run_module_suitet   assert_t   dect   assert_allcloset   assert_array_equalt   assert_raises(   t   xrange(   t   cKDTreec         C` s   t  t |    S(   N(   t   tuplet   sorted(   t   x(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyt   sorted_tuple   s    c         C` s   t  t j |    S(   N(   R   t   npt   unique(   R   (    (    s=   /tmp/pip-build-7oUkmx/scipy/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=   /tmp/pip-build-7oUkmx/scipy/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=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyt   _add_inc_dataa   s    

		i   t
   Test_Qhullc           B` s   e  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   closeR
   t   RuntimeErrorR   R   R   R	   (   t   selfR   t   xdt   yt   ydt   xd2t   yd2(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyt   test_swapping   s8    	9		0	



(   t   __name__t
   __module__R@   (    (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyR/      s   t   TestUtilitiesc           B` sq   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 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   R4   t   doubleR2   t   DelaunayR   t   verticest   find_simplext   tsearch(   R:   R'   t   trit   pt   iR,   (    (    s=   /tmp/pip-build-7oUkmx/scipy/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?RD   gB?g?i   (   i    i    (   i   i   (   i   i    (   g]2ʐ?g>mj?(   g~T!?g^Rz?(   R   R4   RF   R2   RG   t   lift_pointst   plane_distancet	   enumerateRH   t   crosst   sqrtt   dott   signR   (   R:   R   RL   RK   t   zt   pzt   distR,   R0   t   x1t   x2t   x3t   nt   d(    (    s=   /tmp/pip-build-7oUkmx/scipy/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   RD   i   i   (   i    i    (   i    i   (   i   i   (   i   i    (   R   R4   RF   R2   RG   R   t   convex_hull(   R:   R'   RK   (    (    s=   /tmp/pip-build-7oUkmx/scipy/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+=RE   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   R4   R2   t
   ConvexHullR   t   volumet   area(   R:   R'   t   hull(    (    s=   /tmp/pip-build-7oUkmx/scipy/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/?Ra   gHz>RE   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   R4   R2   Rb   R   Rc   Rd   (   R:   R'   Re   (    (    s=   /tmp/pip-build-7oUkmx/scipy/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   restartRa   gHz>(
   R   t   randomR2   Rb   t   Truet   ranget
   add_pointsR   Rc   Rd   (   R:   t	   nr_pointst   dimR'   t   inc_hullt   inc_restart_hullRM   Re   (    (    s=   /tmp/pip-build-7oUkmx/scipy/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=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyt   barycentric_transform%  s    %t   invalidt   ignoreg?Ns   %s %sii    (   R'   RH   R(   t   sumR   t   finfot   floatt   epst	   transformt   seterrt   isnant   allt   absR   t   whereR    R4   Rl   t   nsimplext   linalgt   dett   isfiniteRS   RI   t   any(   R:   RK   RE   t	   unit_cubet   unit_cube_tolRH   t   sct	   centroidsRy   R   t   ct   olderrt   okt   qt   kRc   R,   t   at_boundary(    (    s=   /tmp/pip-build-7oUkmx/scipy/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__R8   R2   RG   R   R   R|   R   R   (   R:   R   R'   RK   t	   bad_count(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyt&   test_degenerate_barycentric_transformsK  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=%dRE   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   TR2   RG   R   Rk   Rj   t   seedt   randR   t   r_(
   R:   R   t   npointst   _is_32bit_platformR(   R   t   gridRE   RK   t   m(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyt    test_more_barycentric_transforms\  sH    ";
GGG(   RA   RB   t   __doc__RN   R^   R`   Rf   Rg   Rr   t   FalseR   R   R   t   slowR   (    (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyRC      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   RE   s   %r != %r(   Rl   R'   R   t   sett	   simplicest   addt   vertex_neighbor_verticesR"   R   t   intR   (
   R:   RK   R,   t   expectedt   sR   R   t   indicest   indptrt   got(    (    s=   /tmp/pip-build-7oUkmx/scipy/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   RD   (   i    i    (   i    i   (   i   i    (   R   R4   RF   R2   RG   R   (   R:   R'   RK   (    (    s=   /tmp/pip-build-7oUkmx/scipy/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   RD   (   i    i    (   i    i   (   i   i   (   i   i    (   R   R4   RF   R2   RG   R   (   R:   R'   RK   (    (    s=   /tmp/pip-build-7oUkmx/scipy/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?RD   (   i    i    (   i    i   (   i   i   (   i   i    (   g      ?g      ?(   g?g      ?(   R   R4   RF   R2   RG   R   (   R:   R'   RK   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyt   test_complicated  s    (   RA   RB   R   R   R   R   (    (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyR     s   			t   TestDelaunayc           B` sh   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z 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_allR
   t
   ValueErrorR2   RG   (   R:   t   masked_array(    (    s=   /tmp/pip-build-7oUkmx/scipy/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   RD   (   i    i    (   i    i   (   i   i   (   R   R4   t   nanRF   R
   R   R2   RG   (   R:   t   points_with_nan(    (    s=   /tmp/pip-build-7oUkmx/scipy/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      ?iRD   (   R   R   t   zerosR2   RG   RH   R   R   t   arangeR   R    t	   neighbors(   R:   t   ndR'   R,   RK   (    (    s=   /tmp/pip-build-7oUkmx/scipy/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   RD   i   i   i(   i    i    (   i    i   (   i   i   (   i   i    (   R   R4   RF   R2   RG   R   RH   R   (   R:   R'   RK   (    (    s=   /tmp/pip-build-7oUkmx/scipy/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   RD   (   R   R4   t   float64R   R2   RG   R   (   R:   R   R<   t   xpt   ypRK   t   tri2(    (    s=   /tmp/pip-build-7oUkmx/scipy/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   R2   RG   R   R'   RH   t   maxt   min(   R:   R'   RK   (    (    s=   /tmp/pip-build-7oUkmx/scipy/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   Rj   R   R   R2   RG   R	   R   R   R   R   R!   (   R:   R'   RK   (    (    s=   /tmp/pip-build-7oUkmx/scipy/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   Rj   R   R   R2   RG   R   R!   R   R   R   t   coplanarR   t   vertex_to_simplex(   R:   R'   RK   (    (    s=   /tmp/pip-build-7oUkmx/scipy/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    (   R2   RG   Rk   R   R4   R	   R   (   R:   R'   RK   R   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyt   test_furthest_site  s    c         c` s/   d   } x t  t  D] } | | f Vq Wd  S(   Nc         S` 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(	   NRt   i    Rh   R   i   Ri   t   pathologicalR   (   R#   R   t   concatenateR2   RG   Rk   Rm   R!   t
   startswithR	   R   R   R   R   R   R   R   (   R%   R+   R)   R'   t   objt   chunkt   obj2t   obj3(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyt   check  s*    		
(   R   R#   (   R:   R   R%   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyt   test_incremental  s    	!(   RA   RB   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s=   /tmp/pip-build-7oUkmx/scipy/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   normR4   RT   t   allcloseR$   R   (   R'   t   facets_1t   facets_2R   R   R   t   apt   bpt   tR\   t   c1t   c2t   c3(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyt   assert_hulls_equal?  s4    t   TestConvexHullc           B` s>   e  Z d    Z d   Z d   Z d   Z d   Z d   Z RS(   c         C` s)   t  j j d  } t t t j |  d  S(   Ni   (   R   R   R   R
   R   R2   Rb   (   R:   R   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyR   w  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   RD   (   i    i    (   i   i   (   R   R4   R   RF   R
   R   R2   Rb   (   R:   R   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyR   {  s    *c         c` s/   d   } x t  t  D] } | | f Vq Wd  S(   Nc         S` 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   R2   RG   Rb   R   R_   R   R   R   R   R   R   RH   (   R%   R'   RK   Re   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyR     s    
((   R   R   (   R:   R   R%   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyt   test_hull_consistency_tri  s    	c         c` s/   d   } x t  t  D] } | | f Vq Wd  S(   Nc         S` 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(   NRt   i    Rh   i   Ri   (
   R#   R   R   R2   Rb   Rk   Rm   R!   R   R   (   R%   R+   t   _R'   R   R   R   R   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyR     s    
(   R   R#   (   R:   R   R%   (    (    s=   /tmp/pip-build-7oUkmx/scipy/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   Rj   R   R   R2   Rb   R   R   R   R   RH   R'   R   t   arctan2t   meanR   R   t   difft   unwrap(   R:   R'   Re   R   R<   t   angle(    (    s=   /tmp/pip-build-7oUkmx/scipy/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      ?Ra   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   R4   R2   Rb   R   Rc   Rd   (   R:   R'   RK   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyRf     s
    (   RA   RB   R   R   R   R   R   Rf   (    (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyR   v  s   					t   TestVoronoic           B` s>   e  Z d    Z d   Z d   Z d   Z d   Z d   Z RS(   c         C` s)   t  j j d  } t t t j |  d  S(   Ni   (   R   R   R   R
   R   R2   t   Voronoi(   R:   R   (    (    s=   /tmp/pip-build-7oUkmx/scipy/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=   /tmp/pip-build-7oUkmx/scipy/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=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyt	   sorttuple  s    N(   t   stript
   splitlinesR   R   R~   t   splitR   R   R2   R   R   RH   R   R   t   regionst   zipt   ridge_pointsR   t   ridge_verticesR   (   R:   R'   R   t   kwR   t   nvertexRH   t   nregionR<   R  t   nridgeR  R  t   vorR  t   p1t   p2(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyR     s,    : JBC	3!

c         c` s)   d   } x t  D] } | | f Vq Wd  S(   Nc   
      S` 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    Rt   gư>R   i   (   R   t   KDTreeR2   R   t
   ridge_dictt   itemsR   R   t   asarrayRH   R   t   queryR   (
   R%   R'   t   treeR  RL   R0   t   ridge_midpointR]   RX   R   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyR     s    
(   R   (   R:   R   R%   (    (    s=   /tmp/pip-build-7oUkmx/scipy/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   Rk   (   R:   R'   R   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyR   .  s    c         c` sT   d   } xD t  t  D]6 } t | d d j d d k rA q n  | | f Vq Wd  S(   Nc         ` s  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  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 |	 |  rY|
  | <qYqYWq=W    f d    d	   } t |    j   | | j   t |    j   | | j   qWd  S(
   NRt   i    Rh   R   i   Ri   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$   RH   (   R   R<   (   t   objxt   remapt
   vertex_map(    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyR  g  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=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyt
   simplifiedp  s    +
(   R#   R   R   R2   R   Rk   Rm   R!   R   t   point_regionRQ   RH   R   R  R  (   R%   R+   R)   R'   R   R   R   R   RM   R0   R,   t   v2R  (    (   R  R  R  s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyR   I  s8    		
		i    i   i   (   R   R#   R   (   R:   R   R%   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyR   F  s
    	:(   RA   RB   R   R   R   R  R   R   (    (    (    s=   /tmp/pip-build-7oUkmx/scipy/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    RD   Rt   i   N(   i   (
   R   R   R   R   t   boolR   R   R   Rk   R   (   R:   t   arr1t   arr2Ra   t   truthst   l1t   indexes(    (    s=   /tmp/pip-build-7oUkmx/scipy/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   R4   R2   t   HalfspaceIntersectionR   t   intersections(   R:   t
   halfspacest   feasible_pointR'   Re   (    (    s=   /tmp/pip-build-7oUkmx/scipy/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      Rt   (   i   i   (   R   R   R   R   R   R   t
   genfromtxtt   hstackR4   R2   R*  R   R+  R   R   t   dual_volumeR!   t   dual_facetsRT   R)  R   t   dual_pointst	   itertoolst   permutationsR|   R   (
   R:   t   fnamet   ineqsR,  t
   feas_pointt   hst   facett   distsR'   t   point(    (    s=   /tmp/pip-build-7oUkmx/scipy/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   R4   R
   R   R2   R*  t
   QhullError(   R:   R,  R-  (    (    s=   /tmp/pip-build-7oUkmx/scipy/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   Rh   Ri   (   R   R4   R0  t   vstackR2   R*  Rk   RQ   t   add_halfspacest   newaxisR   R,  R+  R)  R8   (   R:   R,  t   extra_normalst   offsetst   extra_halfspacesR8  t   inc_hst
   inc_res_hsRM   t   ehst   totalR9  (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyR     s4     &/(   RA   RB   R)  R.  R=  R?  R   (    (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyR"    s
   			t   __main__(   i    i    (   i    i   (   i   i    (   i   i   (   g      ?g      ?(   g      ?g      ?(   i   i   i   (    (    (;   t
   __future__R    R   R   R   R5   t   numpyR   t   numpy.testingR   R   R   R   R   R   R	   R
   t   scipy._lib.sixR   t   scipy.spatial.qhullt   spatialR2   t   scipy.spatialR   R  R4  R   R   R   R   Rj   R   R'   R4   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/   RC   R   R   R   R   R   R"  RA   (    (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/spatial/tests/test_qhull.pyt   <module>   s   :		$$$$$$$$$--$$$$$$$$$76;
	("	7Lm