o
    .wi
                     @   sp   d dl mZ d dlZd dlmZmZ d dlmZ d dlmZ 	ddeded	e	d
eee
eeef f fddZdS )    )UnionN)Tensorlinalg)_check_same_shape)rank_zero_warnFpoint_cloud1point_cloud2
return_allreturnc           
   
   C   sr  t | | | jdkrtd| j d| | jddd } ||jddd }| tj| ddgdd } |tj|ddgdd }ztjt|	dd| 	dddd	\}}}W n/ t
y } z#td
| dt tdt| jd t| jd fW  Y d}~S d}~ww t||}|jddd}|dddf t||	dd }| |  jddgd}	|r|	||fS |	S )aZ  Runs procrustrus analysis on a batch of data points.

    Works similar ``scipy.spatial.procrustes`` but for batches of data points.

    Args:
        point_cloud1: The first set of data points
        point_cloud2: The second set of data points
        return_all: If True, returns the scale and rotation matrices along with the disparity

       zExpected both datasets to be 3D tensors of shape (N, M, D), where N is the batch size, M is the number of data points and D is the dimensionality of the data points, but got z dimensions.   T)dimkeepdim   F)full_matricesz>SVD calculation in procrustes_disparity failed with exception z4. Returning 0 disparity and identity scale/rotation.g        r   N)r   )r   )r   ndim
ValueErrormeanr   normsvdtorchmatmul	transpose	Exceptionr   UserWarningtensoronesshapeeyesumsquare)
r   r   r	   uwvexrotationscale	disparity r(   e/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/torchmetrics/functional/shape/procrustes.pyprocrustes_disparity   s<   


4$
r*   )F)typingr   r   r   r   torchmetrics.utilities.checksr   torchmetrics.utilities.printsr   booltupler*   r(   r(   r(   r)   <module>   s   