o
    Hi
                     @   s6   d dl Z G dd de jjZde jde jfddZdS )    Nc                   @   s@   e Zd ZedejdejfddZedejdejfddZdS )	_AbsFunctionsparse_tensorreturnc                 C   s`   |j sJ | sJ |  }| }| }| }tj||||j	|j
d}| | |S )a8  Compute the `abs` of a sparse tensor.

        Args:
          sparse_tensor:
            A sparse tensor. It has to satisfy::

                assert sparse_tensor.is_coalesced()

        Returns:
          The absolute value of the sparse tensor.
          The `abs` operation is applied element-wise.
        indicesvaluessizedtypedevice)	is_sparseis_coalescedr   cloner   r   abstorchsparse_coo_tensorr	   r
   save_for_backward)ctxr   r   r   r   
values_absans r   F/home/ubuntu/.local/lib/python3.10/site-packages/k2/sparse/autograd.pyforward   s   

z_AbsFunction.forwardans_gradc                 C   sP   | j \}|  }| }| }| |  }tj||||j|j	d}|S )Nr   )
saved_tensorsr   r   r   r   signr   r   r	   r
   )r   r   r   r   r   r   sparse_tensor_grad_valuessparse_tensor_gradr   r   r   backward5   s   z_AbsFunction.backwardN)__name__
__module____qualname__staticmethodr   Tensorr   r   r   r   r   r   r      s
    r   r   r   c                 C   s
   t | S )a3  Compute the `abs` of a sparse tensor.

    It supports autograd.

    Args:
      sparse_tensor:
        A sparse tensor. It has to satisfy::

            assert sparse_tensor.is_coalesced()

    Returns:
      The absolute value of the sparse tensor.
      The `abs` operation is applied element-wise.
    )r   apply)r   r   r   r   r   I   s   
r   )r   autogradFunctionr   r"   r   r   r   r   r   <module>   s   6