o
    oit                     @  sn   d dl mZ d dlmZ d dlmZ d dlm  mZ	 d dl
mZmZ eG dd dZeG dd	 d	ZdS )
    )annotations)	dataclass)AnyN)DeviceTensorc                   @  sl   e Zd ZU dZded< ded< ded< eddd	ZedddZedddZedddZ	dddZ
dS )DISKFeaturesu  A data structure holding DISK keypoints, descriptors and detection scores for an image.

    Since DISK detects a varying number of keypoints per image, `DISKFeatures` is not batched.

    Args:
        keypoints: Tensor of shape :math:`(N, 2)`, where :math:`N` is the number of keypoints.
        descriptors: Tensor of shape :math:`(N, D)`, where :math:`D` is the descriptor dimension.
        detection_scores: Tensor of shape :math:`(N,)` where the detection score can be interpreted as
                          the log-probability of keeping a keypoint after it has been proposed (see the paper
                          section *Method → Feature distribution* for details).

    r   	keypointsdescriptorsdetection_scoresreturnintc                 C  s   | j jd S )Nr   )r   shapeself r   O/home/ubuntu/.local/lib/python3.10/site-packages/kornia/feature/disk/structs.pyn/   s   zDISKFeatures.nr   c                 C  s   | j jS )N)r   devicer   r   r   r   r   3   s   zDISKFeatures.devicec                 C     | j dddf S )z<Accesses the x coordinates of keypoints (along image width).Nr   r   r   r   r   r   x7      zDISKFeatures.xc                 C  r   )z=Accesses the y coordinates of keypoints (along image height).N   r   r   r   r   r   y<   r   zDISKFeatures.yargsr   kwargsc                 O  s6   t | jj|i || jj|i || jj|i |S )a  Call :func:`torch.Tensor.to` on each tensor to move the keypoints, descriptors and detection scores to
        the specified device and/or data type.

        Args:
            *args: Arguments passed to :func:`torch.Tensor.to`.
            **kwargs: Keyword arguments passed to :func:`torch.Tensor.to`.

        Returns:
            A new DISKFeatures object with tensors of appropriate type and location.

        )r   r   tor	   r
   )r   r   r   r   r   r   r   A   s
   zDISKFeatures.toN)r   r   )r   r   )r   r   )r   r   r   r   r   r   )__name__
__module____qualname____doc____annotations__propertyr   r   r   r   r   r   r   r   r   r      s   
 r   c                   @  s,   e Zd ZU dZded< ded< ddd	Zd
S )	KeypointszA temporary struct used to store keypoint detections and their log-probabilities.

    After construction, merge_with_descriptors is used to select corresponding descriptors from unet output.
    r   xysdetection_logpr	   r   r   c                 C  sJ   |j }| jj\}}|dd||f j}tj|dd}t| j||| jS )zWSelect descriptors from a dense `descriptors` tensor, at locations given by `self.xys`.N)dim)dtyper$   TF	normalizer   r   r%   )r   r	   r(   r   r   descr   r   r   merge_with_descriptors^   s
   z Keypoints.merge_with_descriptorsN)r	   r   r   r   )r   r   r   r    r!   r-   r   r   r   r   r#   T   s
   
 r#   )
__future__r   dataclassesr   typingr   torch.nn.functionalnn
functionalr*   kornia.corer   r   r   r#   r   r   r   r   <module>   s   7