o
    oik                     @   sL   d Z ddlZddlmZmZ dejdejfddZdejdejfd	d
ZdS )z4Module containing numerical functionalities for SfM.    N)stack
zeros_likexreturnc              
   C   sx   | j d dkst| j | d }| d }| d }t|}t|| |||| | ||g	dd}| j dd d }|j| S )	a	  Return the cross_product_matrix symmetric matrix of a vector.

    Args:
        x: The input vector to construct the matrix in the shape :math:`(*, 3)`.

    Returns:
        The constructed cross_product_matrix symmetric matrix with shape :math:`(*, 3, 3)`.

       ).r   ).   ).   )dimN)r   r   )shapeAssertionErrorr   r   view)r   x0x1x2zeroscross_product_matrix_flatshape_ r   T/home/ubuntu/.local/lib/python3.10/site-packages/kornia/geometry/epipolar/numeric.pycross_product_matrix   s   

$
r   matrixc                 C   sf   t | }|dk}| dkr/t j| | dd|ddddf  }t | }|||< |S td)zzCofactor matrix, refer to the numpy doc.

    Args:
        matrix: The input matrix in the shape :math:`(*, 3, 3)`.

    r   r   Nzall singular matrices)torchdetsumlinalginv	transposer   	Exception)r   r   singular_maskcofactorreturned_cofactorr   r   r   matrix_cofactor_tensor1   s   
*
r#   )__doc__r   kornia.corer   r   Tensorr   r#   r   r   r   r   <module>   s
   