
    9i                        S SK rS SKrS SKJs  Jr  S rSS jrSS jr	SS jr
\S:X  a  \R                  " SS/SS	//5      r\R                  " SS/SS	//5      r\R                  " \\5      r\	" \S5      rS\R                  " \S5      R#                  5       -
  r\" \5        \" \5        \" \5        \R                  " \5      r\R                  \5      r\" \/ S
QS9r\" \\R.                  5        gg)    Nc                    [        U[        [        45      (       a  U Vs/ s H%  o"S:  a  UOU[        U R                  5      -   S-   PM'     nn[        USS9n[        U R                  5      nU H  nUR                  US5        M     [        R                  " X5      $ [        U[        5      (       a  U R                  U5      $ [        S5      es  snf )z.Implement multi-dimension unsqueeze function. r      T)reversez/Warning: type(dims) must in (list, tuple, int)!)
isinstancelisttuplelenshapesortedinserttorchreshapeint	unsqueeze
ValueError)inputdimsdimr
   s       m/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/models/nlp/space/modules/functions.pyr   r      s    $u&&GK
GK!8Cs5;;'7!7!!;;t 	 
 dD)U[[!CLLa  }}U**	D#		t$$JKK
s   ,Cr   c                    [         R                  " [        R                  R                  " U R
                  6 5      nS[         R                  " U[         R                  " X2-   5      -
  5      -
  nX-   n[        R                  " XQ-  5      $ )z#Basic implement of gumbel_softmax. g        )	r   tensornprandomrandr
   logFsoftmax)r   tauepsUgumbelys         r   gumbel_softmaxr#      s\    RYY^^U[[12A599S599QW#5566FA99QW    c                 >   Uc  Sn[        U [        R                  5      (       a  U R                  5       n [        U[        R                  5      (       a  UR                  5       n[        R
                  " X5      R                  U5      n[        R                  " U5      $ )z*Implement equal in dygraph mode. (paddle) float32)r   r   Tensornumpyr   equalastyper   )xr"   dtypeouts       r   r)   r)   !   sk    }!U\\""GGI!U\\""GGI
((1.


&C<<r$   c                      S[        XU5      -
  $ )z.Implement not_equal in dygraph mode. (paddle) r   )r)   )r+   r"   r,   s      r   	not_equalr/   -   s    uQ5!!!r$   __main__      )r   r   r   )r   )r   g|=)N)r(   r   r   torch.nn.functionalnn
functionalr   r   r#   r)   r/   __name__r   abcc1floatdprintefgr
    r$   r   <module>rB      s       L"	"
 zq!fq!f%&Aq!fq!f%&AAqA	q!B	EOOAq!''))A	!H	"I	!H	A	AA!)$A	!QWW r$   