
    i
                     r    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
Zy)    )UnionN)Tensorlinalg)_check_same_shape)rank_zero_warnpoint_cloud1point_cloud2
return_allreturnc                    t        | |       | j                  dk7  rt        d| j                   d      | | j                  dd      z
  } ||j                  dd      z
  }| t	        j
                  | ddgd      z  } |t	        j
                  |ddgd      z  }	 t	        j                  t        j                  |j                  dd      |       j                  dd      d	      \  }}}t        j                  ||      }|j#                  dd      }|dddf   t        j                  ||j                  dd            z  }| |z
  j%                         j#                  ddg      }	|r|	||fS |	S # t        $ rv}t        d
| dt               t        j                  d      t        j                  | j                  d         t        j                   | j                  d         fcY d}~S d}~ww xY w)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	disparitys
             }/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/torchmetrics/functional/shape/procrustes.pyprocrustes_disparityr+      s    lL1ATT`TeTeSffrt
 	

  ,"3"34"3"HHL,"3"34"3"HHLFKK1a&$GGLFKK1a&$GGL
f**LL//15|DNNqRSTdi
1a ||Aq!HEE!TE"ED>ELLx?Q?QRSUV?W$XXL,446::1v:FI%))  fLRD Q 	

 ||C %**\-?-?-B"CUYY|OaOabcOdEeeefs    AE2 2	G1;A+G,&G1,G1)F)typingr   r   r   r   torchmetrics.utilities.checksr   torchmetrics.utilities.printsr   booltupler+        r*   <module>r3      sX        ; 8 DI++(.+<@+
65/001+r2   