
    Pha              	       (   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ dZ ed	d
      Zg deD  cg c]  } d| z  	 c} z   eD  cg c]  } d| z  	 c} z   Zg d ee      z   eD  cg c]  } d| z  	 c} z   Zd Zd Zd Zd Zd Zd Ze j8                  j;                  dddd ej<                  dg      g      d        Ze j8                  j;                  dg d      d        Z e j8                  j;                  dddg      d        Z!e j8                  j;                  d g d!      d"        Z"d# Z#d$ Z$d% Z%e j8                  j;                  d&e      e j8                  j;                  d d'      d(               Z&e j8                  j;                  d&e      e j8                  j;                  d d'      d)               Z'e j8                  j;                  d* e(ee            d+        Z)e j8                  j;                  d* e(ee            d,        Z*e j8                  j;                  d* e(ee            d-        Z+e j8                  j;                  de      d.        Z,e j8                  j;                  de      d/        Z-yc c} w c c} w c c} w )0    N)assert_array_almost_equal)Rotation)linear_sum_assignment)cdist)golden)cKDTreeg-q=      )IOTC%dD%d)<            c                     t        | |d      }t        |      }t        j                  ||   j	                               S )zCalculates the root-mean-square distance between the points of P and Q.
    The distance is taken as the minimum over all possible matchings. It is
    zero if P and Q are identical and non-zero if not.
    sqeuclidean)metric)r   r   npsqrtsum)PQdistance_matrixmatchings       }C:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\scipy/spatial/transform/tests/test_rotation_groups.py_calculate_rmsdr      s9    
 Aq7O$_5H77?8,00233    c                 x   t        j                  ddt         j                  z  | dz         d d }t        j                  t        j                  |       t        j
                  |      t        j                  |      g      j                  }t        j                  |g dgf      }t        j                  ||d      S )Nr   r   r	   r	   r   r   axis)
r   linspacepivstackzeroscossinr   concatenateroll)nr%   thetasr   s       r   _generate_pyramidr0      s    [[AIq1u-cr2F
		288A;vv?@BBA
I;'(A771d##r    c                 ,   t        j                  ddt         j                  z  | dz         d d }t        j                  t        j                  |        t        j
                  |      t        j                  |      g      j                  }t        j                  t        j                  |       t        j
                  |      t        j                  |      g      j                  }t        j                  ||f      }t        j                  ||d      S )Nr   r   r	   r"   r$   )
r   r&   r'   r(   onesr*   r+   r   r,   r-   )r.   r%   r/   bottomtopr   s         r   _generate_prismr5   #   s    [[AIq1u-cr2FYYRVVF^RVVF^DEGGF
))bggaj["&&."&&.A
B
D
DC
}%A771d##r    c            
         t        j                  ddt         gddt        gddt         gddt        gg      } t        j                  t	        d      D cg c]  }t        j
                  | |d       c}      S c c}w )Nr   r"   r	      r$   )r   arrayphir,   ranger-   )xis     r   _generate_icosahedronr=   +   st    
1b3$-b3$-b3$-b3$-! 	"A >>%(C(Q2771aa0(CDDCs   A<c            	      P    t        j                  g dg dg dg dg dg dg      S )N)r"   r   r   r#   )r   r"   r   )r   r	   r   )r   r   r"   )r   r   r	   r   r8    r    r   _generate_octahedronrA   3   s%    88ZZZ9 : :r    c                  D    t        j                  g dg dg dg dg      S )N)r	   r	   r	   )r	   r"   r"   )r"   r	   r"   )r"   r"   r	   r?   r@   r    r   _generate_tetrahedronrC   8   s    88Y[+FGGr    namer"   TC3c                     t        j                  t        d      5  t        j                  |        d d d        y # 1 sw Y   y xY w)Nzmust be a stringmatchpytestraises
ValueErrorr   create_grouprD   s    r   test_group_typerO   <   s1    	z/
1d#
1 
1 
1	   ;A)r    CAzC DAzD I2 c                     t        j                  t        d      5  t        j                  |        d d d        y # 1 sw Y   y xY w)Nz(must be one of 'I', 'O', 'T', 'Dn', 'Cn'rG   rI   rN   s    r   test_group_namerW   C   s5    	zG
Id#
I 
I 
IrP   C0D0c                     t        j                  t        d      5  t        j                  |        d d d        y # 1 sw Y   y xY w)NzGroup order must be positiverG   rI   rN   s    r   test_group_order_positiver[   J   s1    	z;
=d#
= 
= 
=rP   r%   )Abr   r	   r      FNc                     t        j                  t        d      5  t        j                  d|        d d d        y # 1 sw Y   y xY w)Nz`axis` must be one ofrG   C1rI   r$   s    r   test_axis_validra   Q   s3    	z4
6dD)
6 
6 
6s	   <Ac                      t               } t        j                  d      D ]I  }t        j                  |j	                               }t        | |j                  |             t        k  rIJ  y)zThe icosahedral group fixes the rotations of an icosahedron. Here we
    test that the icosahedron is invariant after application of the elements
    of the rotation group.r   N)r=   r   rM   	from_quatas_quatr   applyTOLr   gs     r   test_icosahedralri   X   sT     	A""3'qyy{+q!''!*-333 (r    c                      t               } t        j                  d      D ]&  }t        | |j	                  |             t
        k  r&J  y)zRTest that the octahedral group correctly fixes the rotations of an
    octahedron.r   N)rA   r   rM   r   re   rf   rg   s     r   test_octahedralrk   b   s>     	A""3'q!''!*-333 (r    c                      t               } t        j                  d      D ]&  }t        | |j	                  |             t
        k  r&J  y)zSTest that the tetrahedral group correctly fixes the rotations of a
    tetrahedron.r   N)rC   r   rM   r   re   rf   rg   s     r   test_tetrahedralrm   j   s>     	A""3'q!''!*-333 (r    r.   XYZc                     t        | dj                  |            }t        j                  d| z  |      D ]&  }t	        ||j                  |            t        k  r&J  y)zJTest that the dicyclic group correctly fixes the rotations of a
    prism.rn   r$   r   N)r5   indexr   rM   r   re   rf   r.   r%   r   rh   s       r   test_dicyclicrr   r   sQ    
 	D 12A""51948q!''!*-333 9r    c                     t        | dj                  |            }t        j                  d| z  |      D ]&  }t	        ||j                  |            t        k  r&J  y)zJTest that the cyclic group correctly fixes the rotations of a
    pyramid.rn   r$   r   N)r0   rp   r   rM   r   re   rf   rq   s       r   test_cyclicrt   |   sQ    
 	!%++d"34A""51948q!''!*-333 9r    z
name, sizec                 J    t        t        j                  |             |k(  sJ y )N)lenr   rM   )rD   sizes     r   test_group_sizesrx      s     x$$T*+t333r    c                     t        j                  |       }t        |j                               }t	        |j                  d            dk(  sJ y )NgMbP?r   )r   rM   r   rd   rv   query_pairs)rD   rw   rh   kdtrees       r   test_group_no_duplicatesr|      s@    d#AQYY[!Fv!!$'(A---r    c                 d   t        j                  |       }t        j                  |j	                          |j	                         f      }t        j
                  t        ||            }t        j                  |d      t        j                  |d      z
  }|t        k  j                         sJ y )Nr   r$   )r   rM   r   r,   rd   sortr   maxminrf   all)rD   rw   rh   qdistancedeltass         r   test_group_symmetryr      s}    d#A
aiik23AwwuQ{#HVVH1%xa(@@FSLr    c                     t        j                  |       }|j                  |      }t        |j	                         t        j                  t        |                   y)zaTest that the elements of the rotation group are correctly
    mapped onto the identity rotation.N)r   rM   reducer   	magnituder   r)   rv   rD   rh   fs      r   test_reductionr      s>     	d#A	AakkmRXXc!f-=>r    c                     t        j                  |       }|d   j                  |      }t        |j	                         d       |j                         j                  dk(  sJ y )Nr"   r   )r^   )r   rM   r   r   r   rd   shaper   s      r   test_single_reductionr      sM    d#A	"QAakkmQ/99;$$$r    ).rJ   numpyr   numpy.testingr   scipy.spatial.transformr   scipy.optimizer   scipy.spatial.distancer   scipy.constantsr   r9   scipy.spatialr   rf   r:   NSNAMESlistSIZESr   r0   r5   r=   rA   rC   markparametrizer8   rO   rW   r[   ra   ri   rk   rm   rr   rt   ziprx   r|   r   r   r   )r.   s   0r   <module>r      s     3 , 0 ( ) ! 
1b\b1b519b114K1UQY4KKtBx""5"Q1q5""554$$E:
H "dD("((D62B!CD$ E$ !MN$ O$ $.$ /$ !DE* F*444 b!'4 ( "4 b!'4 ( "4 s5%'894 :4 s5%'89. :. s5%'89  :  '? (? '% (%o 24K"5s   JJ
4J