o
    oiQ                     @   s   d dl mZ d dlZd dlmZmZ d dlmZ 			ddedede	d	eej
 d
eej defddZ			ddededede	d	eej
 d
eej defddZdS )    )OptionalN)Tensorstack)torch_meshgridTheightwidthnormalized_coordinatesdevicedtypereturnc                 C   s   t jd|d |||d}t jd| d | ||d}|r.||d  d d }|| d  d d }tt||gdddd	}|ddddS )
ao  Generate a coordinate grid for an image.

    When the flag ``normalized_coordinates`` is set to True, the grid is
    normalized to be in the range :math:`[-1,1]` to be consistent with the pytorch
    function :py:func:`torch.nn.functional.grid_sample`.

    Args:
        height: the image height (rows).
        width: the image width (cols).
        normalized_coordinates: whether to normalize
          coordinates in the range :math:`[-1,1]` in order to be consistent with the
          PyTorch function :py:func:`torch.nn.functional.grid_sample`.
        device: the device on which the grid will be generated.
        dtype: the data type of the generated grid.

    Return:
        grid tensor with shape :math:`(1, H, W, 2)`.

    Example:
        >>> create_meshgrid(2, 2)
        tensor([[[[-1., -1.],
                  [ 1., -1.]],
        <BLANKLINE>
                 [[-1.,  1.],
                  [ 1.,  1.]]]])

        >>> create_meshgrid(2, 2, normalized_coordinates=False)
        tensor([[[[0., 0.],
                  [1., 0.]],
        <BLANKLINE>
                 [[0., 1.],
                  [1., 1.]]]])

    r      r	   r
         ?   ijindexingdimtorchlinspacer   r   permute	unsqueeze)r   r   r   r	   r
   xsys	base_grid r   E/home/ubuntu/.local/lib/python3.10/site-packages/kornia/utils/grid.pycreate_meshgrid   s   )	r    depthc           
      C   s   t jd|d |||d}t jd|d |||d}t jd| d | ||d}|rD||d  d d }||d  d d }|| d  d d }tt|||gdddd	}	|	dddd
dS )a  Generate a coordinate grid for an image.

    When the flag ``normalized_coordinates`` is set to True, the grid is
    normalized to be in the range :math:`[-1,1]` to be consistent with the pytorch
    function :py:func:`torch.nn.functional.grid_sample`.

    Args:
        depth: the image depth (channels).
        height: the image height (rows).
        width: the image width (cols).
        normalized_coordinates: whether to normalize
          coordinates in the range :math:`[-1,1]` in order to be consistent with the
          PyTorch function :py:func:`torch.nn.functional.grid_sample`.
        device: the device on which the grid will be generated.
        dtype: the data type of the generated grid.

    Return:
        grid tensor with shape :math:`(1, D, H, W, 3)`.

    r   r   r   r   r   r   r   r   r      r   )
r!   r   r   r   r	   r
   r   r   zsr   r   r   r   create_meshgrid3dZ   s   r$   )TNN)typingr   r   kornia.corer   r   kornia.utils._compatr   intboolr	   r
   r    r$   r   r   r   r   <module>   sL   
D