
    |2g                     b    d dl mZ d dlZd dlZd dlZ ej                  d        G d de      Zy)    )FunctionN*   c                   ,    e Zd Zed        Zed        Zy)AdaptiveConvc                     | j                  ||       |j                  \  }}}}}||k(  sJ |j                  r&|j                  sJ t        j                  ||      }|S t        j                  ||      }|S )N)save_for_backwardshapeis_cuda	cuda_implforwardcpp_impl)	ctxinputfiltersbh2w2f1f2results	            J/home/cameronsmith/repos/FeatUp/featup/adaptive_conv_cuda/adaptive_conv.pyr   zAdaptiveConv.forward   sr    gu-#MM2r2rRx==??"&&ug6F  %%eW5F    c                    | j                   \  }}d x}}|j                  \  }}}}	}
|	|
k(  sJ |j                         }|j                  rj|j                  sJ |j                  sJ | j                  d   rt        j                  ||      }| j                  d   rt        j                  ||      }||fS | j                  d   rt        j                  ||      }| j                  d   rt        j                  ||      }||fS )Nr      )	saved_tensorsr	   
contiguousr
   needs_input_gradr   
grad_inputgrad_filtersr   )r   grad_outputr   r   r   r   r   r   r   r   r   s              r   backwardzAdaptiveConv.backward   s    **$((
\#MM2r2rRx!,,.== ??"##A&&11+wG
##A&(55k5I <'' ##A&%00gF
##A&'44[%H<''r   N)__name__
__module____qualname__staticmethodr   r!    r   r   r   r   
   s(      ( (r   r   )	torch.autogradr   torchadaptive_conv_cuda_implr   adaptive_conv_cpp_implr   manual_seedr   r&   r   r   <module>r,      s-    #  + )   " %(8 %(r   