o
    Yi                  	   @   s0  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dd eD  dd eD  Zg dee dd eD  Zdd Zdd Zdd Zdd Zdd Zdd Ze jdddded ggd!d" Ze jdg d#d$d% Z e jdd&d'gd(d) Z!e jd*g d+d,d- Z"d.d/ Z#d0d1 Z$d2d3 Z%e jd4ee jd*d5d6d7 Z&e jd4ee jd*d5d8d9 Z'e jd:e(eed;d< Z)e jd:e(eed=d> Z*e jd:e(eed?d@ Z+e jdedAdB Z,e jdedCdD Z-dS )E    N)assert_array_almost_equal)Rotation)linear_sum_assignment)cdist)golden)cKDTreeg-q=      )IOTc                 C      g | ]}d | qS )C%d .0nr   r   Y/tmp/pip-target-1s0edx8b/lib/python/scipy/spatial/transform/tests/test_rotation_groups.py
<listcomp>       r   c                 C   r   )D%dr   r   r   r   r   r      r   )<         c                 C   s   g | ]}d | qS )   r   r   r   r   r   r      r   c                 C   s(   t | |dd}t|}t||  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matchingr   r   r   _calculate_rmsd   s   r$   c                 C   sh   t ddt j | d d d }t t | t |t |gj}t |g dgf}t j	||ddS )Nr   r   r   r   r   r   axis)
r   linspacepivstackzeroscossinr   concatenateroll)r   r(   thetasr    r   r   r   _generate_pyramid   s    $r2   c                 C   s   t ddt j | d d d }t t |  t |t |gj}t t | 
 t |t |gj}t ||f}t j	||ddS )Nr   r   r   r%   r'   )
r   r)   r*   r+   onesr-   r.   r   r/   r0   )r   r(   r1   bottomtopr    r   r   r   _generate_prism#   s
    &&r6   c                      sN   t ddt gddt
 gddt gddt
 gg t  fddtdD S )Nr   r%   r   c                    s   g | ]
}t j |d dqS )r   r'   )r   r0   )r   ixr   r   r   0   s    z)_generate_icosahedron.<locals>.<listcomp>   )r   arrayphir/   ranger   r   r8   r   _generate_icosahedron+   s   


r>   c                	   C   s.   t 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   r;   r   r   r   r   _generate_octahedron3   s   r@   c                   C   s"   t 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   _generate_tetrahedron8   s   "rA   namer%   TC3c                 C   >   t jtdd t|  W d    d S 1 sw   Y  d S )Nzmust be a stringmatchpytestraises
ValueErrorr   create_grouprB   r   r   r   test_group_type<   
   "rM   )r!    CAzC DAzD I2 c                 C   rD   )Nz(must be one of 'I', 'O', 'T', 'Dn', 'Cn'rE   rG   rL   r   r   r   test_group_nameC   rN   rT   C0D0c                 C   rD   )NzGroup order must be positiverE   rG   rL   r   r   r   test_group_order_positiveJ   rN   rW   r(   )Abr   r   r      FNc                 C   s@   t jtdd td|  W d    d S 1 sw   Y  d S )Nz`axis` must be one ofrE   C1rG   r'   r   r   r   test_axis_validQ   s
   "r\   c                  C   s@   t  } tdD ]}t| }t| || tk sJ qdS )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   rK   	from_quatas_quatr$   applyTOLr    gr   r   r   test_icosahedralX   s
   rc   c                  C   2   t  } tdD ]}t| || tk sJ qdS )zRTest that the octahedral group correctly fixes the rotations of an
    octahedron.r   N)r@   r   rK   r$   r_   r`   ra   r   r   r   test_octahedralb      re   c                  C   rd   )zSTest that the tetrahedral group correctly fixes the rotations of a
    tetrahedron.r   N)rA   r   rK   r$   r_   r`   ra   r   r   r   test_tetrahedralj   rf   rg   r   XYZc                 C   F   t | d|d}tjd|  |dD ]}t|||tk s J qdS )zJTest that the dicyclic group correctly fixes the rotations of a
    prism.rh   r'   r   N)r6   indexr   rK   r$   r_   r`   r   r(   r    rb   r   r   r   test_dicyclicr      rl   c                 C   ri   )zJTest that the cyclic group correctly fixes the rotations of a
    pyramid.rh   r'   r   N)r2   rj   r   rK   r$   r_   r`   rk   r   r   r   test_cyclic|   rm   rn   z
name, sizec                 C   s   t t| |ksJ d S )N)lenr   rK   )rB   sizer   r   r   test_group_sizes   s   rq   c                 C   s0   t | }t| }t|ddksJ d S )NgMbP?r   )r   rK   r   r^   ro   query_pairs)rB   rp   rb   kdtreer   r   r   test_group_no_duplicates   s   
rt   c                 C   sb   t | }t|  | f}tt||}tj|ddtj|dd }|t	k 
 s/J d S )Nr   r'   )r   rK   r   r/   r^   sortr   maxminr`   all)rB   rp   rb   qdistancedeltasr   r   r   test_group_symmetry   s
   
r|   c                 C   s0   t | }||}t| tt| dS )zaTest that the elements of the rotation group are correctly
    mapped onto the identity rotation.N)r   rK   reducer   	magnituder   r,   ro   rB   rb   fr   r   r   test_reduction   s   

r   c                 C   s<   t | }|d |}t| d | jdksJ d S )Nr%   r   )rZ   )r   rK   r}   r   r~   r^   shaper   r   r   r   test_single_reduction   s   
r   ).rH   numpyr   numpy.testingr   scipy.spatial.transformr   scipy.optimizer   scipy.spatial.distancer   scipy.constantsr   r<   scipy.spatialr   r`   r=   NSNAMESlistSIZESr$   r2   r6   r>   r@   rA   markparametrizer;   rM   rT   rW   r\   rc   re   rg   rl   rn   ziprq   rt   r|   r   r   r   r   r   r   <module>   sZ    
$









