§
    ’©ºjF  ã                   ój   — d dl Z d dl mZ deddfd„Zdedeeef         fd„Zdedeeef         fd„ZdS )é    N)ÚTensorÚimgÚreturnc                 ó´   — t          | t          ¦  «        st          dt          | ¦  «        › �¦  «        ‚| j        dk    rt          d| j        › d�¦  «        ‚dS )z*Validate whether img is a 4D torch Tensor.z3The `img` expects a value of <Tensor> type but got é   z&The `img` expects a 4D tensor but got zD tensorN)Ú
isinstancer   Ú	TypeErrorÚtypeÚndimÚRuntimeError©r   s    úw/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/functional/image/gradients.pyÚ_image_gradients_validater      sa   € å�c�6Ñ"Ô"ð [ÝÐYÍdÐSVÉiÌiÐYÐYÑZÔZÐZØ
„x�1‚}€}ÝÐVÀCÄHÐVÐVÐVÑWÔWÐWð €}ó    c                 óú  — | j         \  }}}}| ddd…dd…f         | ddd…dd…f         z
  }| ddd…dd…f         | ddd…dd…f         z
  }||d|g}t          j        |t          j        || j        | j        ¬¦  «        gd¬¦  «        }|                     | j         ¦  «        }|||dg}t          j        |t          j        || j        | j        ¬¦  «        gd¬¦  «        }|                     | j         ¦  «        }||fS )	z2Compute image gradients (dy/dx) for a given image..é   Néÿÿÿÿ)ÚdeviceÚdtypeé   )Údimé   )ÚshapeÚtorchÚcatÚzerosr   r   Úview)	r   Ú
batch_sizeÚchannelsÚheightÚwidthÚdyÚdxÚshapeyÚshapexs	            r   Ú_compute_image_gradientsr&      s  € à*-¬)Ñ'€J�˜& %à	ˆS�!�"�"�a�a�aˆZŒ˜3˜s C R C¨¨¨˜{Ô+Ñ	+€BØ	ˆS�!�!�!�Q�R�RˆZŒ˜3˜s A A A s¨ s˜{Ô+Ñ	+€Bà˜( A uÐ-€FÝ	Œ�B�œ F°3´:ÀSÄYÐOÑOÔOÐPÐVWÐ	XÑ	XÔ	X€BØ	�Š�”Ñ	Ô	€Bà˜( F¨AÐ.€FÝ	Œ�B�œ F°3´:ÀSÄYÐOÑOÔOÐPÐVWÐ	XÑ	XÔ	X€BØ	�Š�”Ñ	Ô	€Bàˆrˆ6€Mr   c                 ó>   — t          | ¦  «         t          | ¦  «        S )a„  Compute `Gradient Computation of Image`_ of a given image using finite difference.

    Args:
        img: An ``(N, C, H, W)`` input tensor where ``C`` is the number of image channels

    Return:
        Tuple of ``(dy, dx)`` with each gradient of shape ``[N, C, H, W]``

    Raises:
        TypeError:
            If ``img`` is not of the type :class:`~torch.Tensor`.
        RuntimeError:
            If ``img`` is not a 4D tensor.

    Example:
        >>> from torchmetrics.functional.image import image_gradients
        >>> image = torch.arange(0, 1*1*5*5, dtype=torch.float32)
        >>> image = torch.reshape(image, (1, 1, 5, 5))
        >>> dy, dx = image_gradients(image)
        >>> dy[0, 0, :, :]
        tensor([[5., 5., 5., 5., 5.],
                [5., 5., 5., 5., 5.],
                [5., 5., 5., 5., 5.],
                [5., 5., 5., 5., 5.],
                [0., 0., 0., 0., 0.]])

    .. note::
           The implementation follows the 1-step finite difference method as followed
           by the TF implementation. The values are organized such that the gradient of
           [I(x+1, y)-[I(x, y)]] are at the (x, y) location

    )r   r&   r   s    r   Úimage_gradientsr(   -   s!   € õB ˜cÑ"Ô"Ð"å# CÑ(Ô(Ð(r   )r   r   r   Útupler&   r(   © r   r   ú<module>r+      sª   ðð €€€Ø Ð Ð Ð Ð Ð ðX 6ð X¨dð Xð Xð Xð Xð &ð ¨U°6¸6°>Ô-Bð ð ð ð ð$#)˜ð #) E¨&°&¨.Ô$9ð #)ð #)ð #)ð #)ð #)ð #)r   