ó
àÆ÷Xc           @` sS  d  d l  m Z m Z m Z d  d l m Z d  d l Z d  d l Z d  d l Z d  d l	 m
 Z d  d l m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m  Z  m! Z! m" Z" d  d l m# Z$ d  d l m% Z% m# Z# m& Z& d  d l' m( Z( d	 „  Z) d
 e j* f d „  ƒ  YZ+ d e j* f d „  ƒ  YZ, d e j* f d „  ƒ  YZ- d e j* f d „  ƒ  YZ. d e j* f d „  ƒ  YZ/ d e j* f d „  ƒ  YZ0 d e j* f d „  ƒ  YZ1 d e j* f d „  ƒ  YZ2 d e j* f d „  ƒ  YZ3 d e j* f d „  ƒ  YZ4 d „  Z5 d e j* f d  „  ƒ  YZ6 d S(!   i    (   t   absolute_importt   print_functiont   division(   t   partialN(   t   unittest_tools(   t   SearchsortedOpt   searchsortedt   CumOpt   cumsumt   cumprodt   CpuContiguoust   cpu_contiguoust   bincountt   DiffOpt   difft   squeezet   compresst   RepeatOpt   repeatt   Bartlettt   bartlettt   FillDiagonalt   fill_diagonalt   FillDiagonalOffsett   fill_diagonal_offsett
   to_one_hott   Unique(   t   tensor(   t   configR   t   function(   t   attrc          C` s<  t  j d ƒ }  t  j d ƒ } t j t j j d d ƒ d d ƒ} t j |  | g t	 |  j
 d ƒ d  d  | … ƒ ƒ } | j j j ƒ  } t g  | D] } t | j t ƒ ^ q’ ƒ s¹ t ‚ | | d ƒ j d sÕ t ‚ | | d	 ƒ j d sñ t ‚ | | d
 ƒ j d st ‚ t j j j t	 t j j d d d	 ƒ g ƒ d  S(   Nt   at   ii   i   t   dtypet   float32i   t   C_CONTIGUOUSi   i   i   (   i   i   (   t   Tt   fmatrixt   iscalart   numpyt   asarrayt   randomt   randt   theanoR   R   t   reshapet   makert   fgrapht   toposortt   anyt
   isinstancet   opR
   t   AssertionErrort   flagst   testsR   t   verify_grad(   R   R    t   a_valt   ft   topot   node(    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt   test_cpu_contiguous   s    $41t   TestSearchsortedOpc           B` sY   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   c         C` s¸   t  t |  ƒ j ƒ  t |  _ t ƒ  |  _ t j d ƒ |  _ t j	 d ƒ |  _
 d t j j d ƒ j t j ƒ |  _ d t j j d	 ƒ j t j ƒ |  _ t j |  j ƒ j d ƒ |  _ d  S(
   Nt   xt   vi   i2   i   i
   i   t   int32(   i   i
   i   (   t   superR<   t   setUpR   t   op_classR2   R$   t   vectorR=   t   tensor3R>   t   npR)   t   astypeR   t   floatXR   t   bt   argsortt
   idx_sorted(   t   self(    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRA   )   s    	%%c         C` s  t  j |  j |  j g t |  j |  j ƒ ƒ } t j t j |  j |  j |  j	 ƒ | |  j |  j |  j	 ƒ ƒ st t
 ‚ t j d d d ƒ} t  j |  j |  j | g |  j j |  j d | d d ƒƒ } t j |  j j |  j	 d |  j d d ƒ| |  j |  j	 |  j ƒ ƒ st
 ‚ |  j |  j } t  j |  j |  j g |  j j |  j d d ƒƒ } t j | j |  j	 d d ƒ| | |  j	 ƒ ƒ s‰t
 ‚ d  S(   Nt   sorterR!   R?   t   sidet   right(   R+   R   R=   R>   R   RE   t   allcloseR   RJ   RH   R3   R$   RC   (   RK   R8   RL   t   sa(    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt#   test_searchsortedOp_on_sorted_input5   s    -"%<'$3c         C` s&   |  j  t t |  j |  j d d ƒd  S(   NRM   t   asdfa(   t   assertRaisest
   ValueErrorR   R=   R>   (   RK   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt"   test_searchsortedOp_wrong_side_kwdC   s    c         C` sN   t  j d ƒ } |  j t t | |  j ƒ |  j t t |  j |  j d | ƒd  S(   Nt   no_1dRL   (   R$   t   dmatrixRS   RT   R   R>   R=   (   RK   RV   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt    test_searchsortedOp_on_no_1d_inpF   s    c         C` s;   t  j d d d ƒ} |  j t t |  j |  j d | ƒd  S(   NRL   R!   R"   (   R$   RC   RS   t	   TypeErrorR   R=   R>   (   RK   RL   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt#   test_searchsortedOp_on_float_sorterK   s    c         C` sÖ   d	 } t  j j ƒ  d k r( | d
 7} n  x§ | D]Ÿ } t j d d | ƒ} t  j |  j |  j | g t |  j |  j d | ƒd t	 ƒ} t
 j t
 j |  j |  j d |  j ƒ| |  j |  j |  j ƒ ƒ s/ t ‚ q/ Wd  S(   Nt   int8t   int16R?   i@   t   int64RL   R!   t   allow_input_downcast(   R[   R\   s   int32(   R]   (   R+   t   configdefaultst   python_int_bitwidthR$   RC   R   R=   R>   R   t   TrueRE   RO   R   RH   RJ   R3   (   RK   t   compatible_typesR!   RL   R8   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt!   test_searchsortedOp_on_int_sorterP   s    	$c         C` sv   t  j |  j |  j g t |  j |  j d d ƒƒ } t j t j |  j |  j d d ƒ| |  j |  j ƒ ƒ sr t	 ‚ d  S(   NRM   RN   (
   R+   R   R=   R>   R   RE   RO   R   RH   R3   (   RK   R8   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt!   test_searchsortedOp_on_right_side]   s    !c         C` s1  |  j  |  j |  j g t |  j |  j ƒ g |  j |  j |  j g |  j ƒ t j	 d d d ƒ} |  j  |  j |  j | g t |  j |  j d | ƒg |  j |  j |  j g |  j ƒ t
 j d ƒ j t j ƒ } t
 j d d ƒ j t j ƒ } |  j  |  j |  j g t |  j |  j d	 d
 ƒg | | g |  j ƒ d  S(   NRL   R!   R?   i
   t   shapei   i   i   RM   RN   (   i   i   i   (   t   _compile_and_checkR=   R>   R   R   RJ   RH   RB   R$   RC   RE   t   onesRF   R   RG   (   RK   RL   t   lat   lb(    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt   test_infer_shapec   s    

	c         C` s*   t  j |  j |  j |  j |  j g ƒ d  S(   N(   t   uttR6   R2   R   RJ   RH   (   RK   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt	   test_grady   s    (   t   __name__t
   __module__RA   RQ   RU   RX   RZ   Rc   Rd   Rj   Rl   (    (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyR<   '   s   								t	   TestCumOpc           B` s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C` s,   t  t |  ƒ j ƒ  t |  _ t ƒ  |  _ d  S(   N(   R@   Ro   RA   R   RB   R2   (   RK   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRA      s    	c         C` sÐ  t  j d ƒ } t j j d ƒ j t j ƒ } |  j t t	 | d d ƒ|  j t t	 | d d ƒ|  j t t
 | d d ƒ|  j t t
 | d d ƒt j | g t	 | ƒ t
 | ƒ g ƒ } | | ƒ \ } } t j t j	 | ƒ | ƒ së t ‚ t j t j
 | ƒ | ƒ st ‚ x½ t t | j ƒ t | j ƒ ƒ D]™ } t j | g t	 | d | ƒt
 | d | ƒg ƒ } | | ƒ \ } } t j t j	 | d | ƒ| ƒ s¡t ‚ t j t j
 | d | ƒ| ƒ s/t ‚ q/Wd  S(   NR=   i   i   i   t   axisiüÿÿÿ(   i   i   i   (   R$   RD   RE   R)   RF   R   RG   RS   RT   R   R	   R+   R   RO   R3   t   ranget   lenRe   (   RK   R=   R   R8   t   st   pRp   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt   test_cum_op„   s    '!!)3'c         C` s·   t  j d ƒ } t j j d ƒ j t j ƒ } |  j | g |  j | ƒ g | g |  j	 ƒ xX t
 t | j ƒ t | j ƒ ƒ D]4 } |  j | g t | d | ƒg | g |  j	 ƒ q{ Wd  S(   NR=   i   i   i   Rp   (   i   i   i   (   R$   RD   RE   R)   RF   R   RG   Rf   R2   RB   Rq   Rr   Re   R   (   RK   R=   R   Rp   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRj   ™   s    
)c         C` sã   t  j j d
 ƒ j t j ƒ } t j |  j d d ƒ | g ƒ t j |  j d d ƒ | g ƒ x€ t t	 | j
 ƒ t	 | j
 ƒ ƒ D]\ } t j |  j d | d d ƒ | g d d	 ƒt j |  j d | d d ƒ | g d d	 ƒq Wd  S(   Ni   i   i   t   modet   addt   mulRp   t   epsg-Cëâ6:?(   i   i   i   (   RE   R)   RF   R   RG   Rk   R6   RB   Rq   Rr   Re   (   RK   R   Rp   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRl   ©   s    )+(   Rm   Rn   RA   Ru   Rj   Rl   (    (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRo   }   s   			t   TestBinCountc           B` s   e  Z d  „  Z RS(   c         ` s  t  j d ƒ } d  d  ‡  f d † } xØd D]Ð} t  j d d | ƒ} t j j d d d d ƒj | ƒ ‰  t j j d ƒ j t j ƒ } t	 j
 | g t | ƒ ƒ } t	 j
 | | g t | d | ƒƒ } | ˆ  ƒ | ˆ  ƒ k j ƒ  së t ‚ t j | ˆ  | ƒ | ˆ  | ƒ ƒ st ‚ t	 j
 | g t | d d ƒƒ } t	 j
 | g t | d d ƒƒ }	 | ˆ  d d ƒ| ˆ  ƒ k j ƒ  st ‚ | ˆ  d d ƒ|	 ˆ  ƒ k j ƒ  s«t ‚ | j d ƒ s+ d ˆ  d <t	 j
 | g t | d t ƒƒ }
 |  j t |
 ˆ  ƒ q+ q+ Wd  S(   Nt   wc         ` sÙ   t  |  j ƒ  d ƒ } | r. t | | ƒ } n  | d  k	 r‹ t j | d | j ƒ} x€ t |  j d ƒ D] } | |  | c | | 7<qf WnJ t j | d ˆ  j ƒ} x/ t |  j d ƒ D] } | |  | c d 7<q· W| S(   Ni   R!   i    (   t   intt   maxt   NoneRE   t   zerosR!   Rq   Re   (   t   dataR{   t	   minlengtht   sizet   outR    (   R   (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt   ref¸   s    R[   R\   R?   R]   t   uint8t   uint16t   uint32t   uint64R=   R!   i   i3   R‚   i   t   weightsR   i7   i   t   uiÿÿÿÿi    t   assert_nonneg(   s   int8s   int16s   int32s   int64R…   R†   R‡   Rˆ   (   i   (   R$   RC   R~   RE   R)   t   randintRF   R   RG   R+   R   R   t   allR3   RO   t
   startswithRa   RS   (   RK   R{   R„   R!   R=   R‰   t   f1t   f2t   f3t   f4t   f5(    (   R   sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt   test_bincountFnµ   s&    
$$$*!!**
!(   Rm   Rn   R”   (    (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRz   ´   s   t
   TestDiffOpc           B` s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   i
   c         C` s,   t  t |  ƒ j ƒ  t |  _ t ƒ  |  _ d  S(   N(   R@   R•   RA   R   RB   R2   (   RK   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRA   à   s    	c      
   C` s  t  j d ƒ } t j j d ƒ j t j ƒ } t j | g t	 | ƒ ƒ } t j
 t j	 | ƒ | | ƒ ƒ so t ‚ x‘ t t | j ƒ ƒ D]z } xq t t j ƒ D]` } t j | g t	 | d | d | ƒƒ } t j
 t j	 | d | d | ƒ| | ƒ ƒ s› t ‚ q› Wq… Wd  S(   NR=   i   i2   t   nRp   (   i   i2   (   R$   t   matrixRE   R)   RF   R   RG   R+   R   R   RO   R3   Rq   Rr   Re   R•   t   nb(   RK   R=   R   R8   Rp   t   kt   g(    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt   test_diffOpå   s    ''c      
   C` sÊ   t  j d ƒ } t j j d ƒ j t j ƒ } |  j | g |  j | ƒ g | g |  j	 ƒ xk t
 t | j ƒ ƒ D]T } xK t
 t j ƒ D]: } |  j | g t | d | d | ƒg | g |  j	 ƒ q„ Wqn Wd  S(   NR=   i   i2   R–   Rp   (   i   i2   (   R$   R—   RE   R)   RF   R   RG   Rf   R2   RB   Rq   Rr   Re   R•   R˜   R   (   RK   R=   R   Rp   R™   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRj   ñ   s    
c      	   C` så   t  j d ƒ } t j j d ƒ j t j ƒ } t j | g t  j	 t  j
 t | ƒ ƒ | ƒ ƒ t j |  j | g ƒ xm t t j ƒ D]\ } t j | g t  j	 t  j
 t | d | ƒƒ | ƒ ƒ t j t d | ƒ | g d d ƒq Wd  S(   NR=   i2   R–   Ry   gyé&1¬|?(   R$   RC   RE   R)   RF   R   RG   R+   R   t   gradt   sumR   Rk   R6   R2   Rq   R•   R˜   R   (   RK   R=   R   R™   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRl     s    .4(   Rm   Rn   R˜   RA   R›   Rj   Rl   (    (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyR•   Ý   s
   			t   SqueezeTesterc           B` sq   e  Z d
 d d g Z e e g e e e g e e e e e g g Z d „  Z d „  Z d „  Z d „  Z	 d	 „  Z
 RS(   i   i   i   i   i   c         C` s    t  t |  ƒ j ƒ  t |  _ d  S(   N(   R@   Rž   RA   R   R2   (   RK   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRA     s    c         C` sÒ   xË t  |  j |  j ƒ D]´ \ } } t j j d | ƒ j t j j ƒ } t	 j
 t j j | ƒ ƒ  } t j | g |  j | ƒ ƒ } t j | ƒ } | | ƒ } | j | j k s² t ‚ t j | | ƒ s t ‚ q Wd  S(   NR‚   (   t   zipt
   shape_listt   broadcast_listR'   R)   RF   R+   R   RG   R   t
   TensorTypeR   R2   R   Re   R3   RO   (   RK   Re   t	   broadcastR€   t   variableR8   t   expectedt   tested(    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt   test_op  s    "$c         C` sš   x“ t  |  j |  j ƒ D]| \ } } t j j d | ƒ j t j j ƒ } t	 j
 t j j | ƒ ƒ  } |  j | g |  j | ƒ g | g t	 j d t ƒq Wd  S(   NR‚   t   warn(   RŸ   R    R¡   R'   R)   RF   R+   R   RG   R   R¢   Rf   R2   t
   DimShufflet   False(   RK   Re   R£   R€   R¤   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRj   &  s    "$	c         C` sd   x] t  |  j |  j ƒ D]F \ } } t j j d | ƒ j t j j ƒ } t	 j
 |  j | g ƒ q Wd  S(   NR‚   (   RŸ   R    R¡   R'   R)   RF   R+   R   RG   Rk   R6   R2   (   RK   Re   R£   R€   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRl   1  s    "$c         C` sÏ   xÈ t  |  j |  j ƒ D]± \ } } t j j d | ƒ j t j j ƒ } t	 j
 t j j | ƒ ƒ  } t j | g | j ƒ  ƒ } t j | ƒ } | | ƒ } | j | j k s¯ t ‚ t j | | ƒ s t ‚ q Wd  S(   NR‚   (   RŸ   R    R¡   R'   R)   RF   R+   R   RG   R   R¢   R   R   Re   R3   RO   (   RK   Re   R£   R€   R¤   R8   R¥   R¦   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt   test_var_interface7  s    "$(   i   i   (   i   i   i   (   i   i   i   i   i   (   Rm   Rn   R    Ra   Rª   R¡   RA   R§   Rj   Rl   R«   (    (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRž     s   						t   CompressTesterc        
   B` s§   e  Z d	 d  d d d d g Z d d d d d d g d d d d g d d d d g g  d d d d g d d d d d g g Z d
 d d d d d g Z d „  Z d „  Z RS(   iÿÿÿÿi    i   i   i   i   i   c         C` s    t  t |  ƒ j ƒ  t |  _ d  S(   N(   R@   R¬   RA   R   R2   (   RK   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRA   Z  s    c   
      C` sö   xï t  |  j |  j |  j ƒ D]Ò \ } } } t j j ƒ  } t j j d | ƒ j	 t j
 j ƒ } t j j ƒ  } t j | | g |  j | | d | ƒƒ } t j | | d | ƒ} | | | ƒ }	 |	 j | j k sÖ t ‚ t j |	 | ƒ s t ‚ q Wd  S(   NR‚   Rp   (   RŸ   t	   axis_listt	   cond_listR    R+   R   t   ivectorR'   R)   RF   R   RG   R—   R   R2   R   Re   R3   RO   (
   RK   Rp   t   condRe   t   cond_varR€   t   data_varR8   R¥   R¦   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyR§   ^  s    $N(   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   Rm   Rn   R~   R­   R®   R    RA   R§   (    (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyR¬   F  s(   			t   TestRepeatOpc           B` sJ   e  Z d  „  Z d „  Z d „  Z e d ƒ d „  ƒ Z d „  Z d „  Z RS(   c         C` s5   d  g t t | ƒ ƒ g  t | ƒ D] } | ^ q# S(   N(   R~   t   listRq   (   RK   t   ndimR    (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt   _possible_axisp  s    c         C` sk   t  t |  ƒ j ƒ  t |  _ t ƒ  |  _ t j j ƒ  } | d k rO d |  _	 n  | d k rg d |  _	 n  d  S(   Ni@   Rˆ   i    R‡   R]   (   s   uint64(   s   uint32s   int64s   uint64(
   R@   R³   RA   R   RB   R2   R+   R_   t   local_bitwidtht   numpy_unsupported_dtypes(   RK   t   ptr_bitwidth(    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRA   s  s    	c   
   
   C` sû  xôt  d ƒ D]æ} t j t j t g | ƒ ƒ  } t j j d | ƒ j t j ƒ } xœ|  j	 | ƒ D]‹} x‚t
 j D]w} t j d | ƒ } t j d d | ƒ} | d k sË | |  j k rê | j d k rê |  j t t | | d | ƒqt t j | | g t | | d | ƒƒ } t j t j | | d | ƒ| | | ƒ ƒ sDt ‚ t j d | ƒ } | d  k rŒt j j d d d | j ƒj | ƒ } n$ t j j d d d d ƒj | ƒ } | |  j k rí| j d k rí|  j t t | | d | ƒnZ t j | | g t | | d | ƒƒ } t j t j | | d | ƒ| | | ƒ ƒ sGt ‚ t j j d d	 d d ƒj | ƒ d
 } t j | g t | | g d | ƒƒ } t j t j | | d | ƒ| | ƒ ƒ sÆt ‚ t j g  | j j j ƒ  D] }	 t  |	 j! t" ƒ ^ qßƒ st ‚ t j
 j d t# f d | ƒ ƒ  } t j j d d d d ƒj | ƒ } t j | | g t | | d | ƒƒ } t j t j | | d d | ƒ| | | ƒ ƒ sªt ‚ t j g  | j j j ƒ  D] }	 t  |	 j! t" ƒ ^ qÃƒ st t ‚ qt Wqd Wq Wd  S(   Ni   i
   R!   Rˆ   i   Rp   i   R‚   i   i   t   broadcastablei    (   i
   (   i
   (    (   i   ($   Rq   R$   R¢   R   RG   Rª   RE   R)   RF   R¶   R   t   integer_dtypest   scalarR'   R(   R¸   Rµ   RS   RY   R   R+   R   RO   R3   RC   R~   RŒ   R‚   R0   R-   R.   R/   R1   R2   R   Ra   (
   RK   Rµ   R=   R   Rp   R!   t   r_vart   rR8   R–   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt   test_repeatOp  sZ    "	!				8$	t   slowc   	   	   C` s  xt  d ƒ D]} t j t j t g | ƒ ƒ  } t j | ƒ d d } t j	 j	 | ƒ j
 t j ƒ } x©|  j | ƒ D]˜} xt j D]„} t j d | ƒ } t j d d | ƒ} | |  j k rî t j d | ƒ } |  j t t | | ƒ q‡ |  j | | g t d | ƒ | | ƒ g | | g |  j ƒ t j d | ƒ } | d  k rpt j	 j d d d | j ƒj
 | ƒ } na | j d	 k r­t j	 j d d d | j | ƒj
 | ƒ } n$ t j	 j d d d d ƒj
 | ƒ } |  j | | g t d | ƒ | | ƒ g | | g |  j ƒ q‡ Wqw Wq Wd  S(   Ni   i   i   R!   i   Rp   i   R‚   i    i
   (   i
   (   Rq   R$   R¢   R   RG   Rª   R'   t   arangeRE   R)   RF   R¶   R   R»   R¼   R(   R¸   RC   RS   RY   R   Rf   R   RB   R~   RŒ   R‚   Re   (	   RK   Rµ   R=   t   shpR   Rp   R!   R½   R¾   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRj   ¸  s:    	
	!	%			c         ` ss   xl t  d ƒ D]^ } t j j d | ƒ j t j ƒ } x3 |  j | ƒ D]" ‰  t j ‡  f d †  | g ƒ qE Wq Wd  S(   Ni   i
   c         ` s   t  d ˆ  ƒ |  d ƒ S(   NRp   i   (   R   (   R=   (   Rp   (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt   <lambda>â  s    (   i
   (	   Rq   RE   R)   RF   R   RG   R¶   Rk   R6   (   RK   Rµ   R   (    (   Rp   sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRl   Ý  s    "c         C` sÁ   t  j t j t t t g ƒ ƒ  } t d d ƒ | d ƒ } |  j | j t t t f ƒ t d d ƒ | d ƒ } |  j | j t t t f ƒ t d d ƒ | d ƒ } |  j | j t t t f ƒ d  S(   NRp   i   i   i    (	   R$   R¢   R   RG   Rª   Ra   R   t   assertEqualRº   (   RK   R=   R¾   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt   test_broadcastableä  s    !(	   Rm   Rn   R¶   RA   R¿   R   Rj   Rl   RÅ   (    (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyR³   o  s   			9%	t   TestBartlettc           B` s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C` s)   t  t |  ƒ j ƒ  t |  _ t |  _ d  S(   N(   R@   RÆ   RA   R   RB   R   R2   (   RK   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRA   ð  s    	c         C` s  t  j ƒ  } t | g |  j | ƒ ƒ } t j j d d d d	 ƒ} t j | | ƒ t j | ƒ ƒ si t	 ‚ t j | d ƒ t j d ƒ ƒ s t	 ‚ t j | d ƒ t j d ƒ ƒ s· t	 ‚ t j
 d g d d ƒ} t j | | d ƒ t j | d ƒ ƒ sþ t	 ‚ d  S(
   Ni   i3   R‚   i    iÿÿÿÿi   R!   R…   (    (   R   t   lscalarR   R2   R'   R)   RŒ   RO   R   R3   t   array(   RK   R=   R8   t   MRH   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt   test_performõ  s    '''c         C` s¦   t  j ƒ  } |  j | g |  j | ƒ g t j j d d d d ƒg |  j ƒ |  j | g |  j | ƒ g d g |  j ƒ |  j | g |  j | ƒ g d g |  j ƒ d  S(   Ni   i3   R‚   i    i   (    (   R   RÇ   Rf   R2   R'   R)   RŒ   RB   (   RK   R=   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRj   ÿ  s    
+(   Rm   Rn   RA   RÊ   Rj   (    (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRÆ   î  s   		
t   TestFillDiagonalc           B` sJ   e  Z e j j d  ƒ Z d „  Z d „  Z e d ƒ d „  ƒ Z	 d „  Z
 RS(   i+   c         C` s)   t  t |  ƒ j ƒ  t |  _ t |  _ d  S(   N(   R@   RË   RA   R   RB   R   R2   (   RK   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRA     s    	c         C` sÝ  t  j ƒ  } t  j ƒ  } t | | g t | | ƒ ƒ } x« d d	 d
 g D]š } t j j | Œ  j t	 j
 ƒ } t j t	 j
 t j j ƒ  ƒ } | | | ƒ } t j t j | ƒ | ƒ s¹ t ‚ | | k j ƒ  t | j ƒ k sF t ‚ qF Wt j j d d d ƒ j t	 j
 ƒ } t  j ƒ  } t  j ƒ  } t | | g t | | ƒ ƒ } t j t	 j
 t j j ƒ  d ƒ } | | | ƒ } | d | k s†t ‚ | d | k sœt ‚ | d | k s²t ‚ | | k j ƒ  t | j ƒ k sÙt ‚ d  S(   Ni   i   i   i
   i    i   i   (   i   i   (   i   i   (   i   i   (   i    i    i    (   i   i   i   (   i   i   i   (   R   R—   R¼   R   R   R'   R)   R*   RF   R   RG   t   castRO   t   diagR3   R   t   minRe   RD   (   RK   R=   t   yR8   RÂ   R   t   valRƒ   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRÊ     s&    !+$#RÀ   c         C` s~   t  j t t j j d d ƒ t j j ƒ  g d d d t j ƒt  j t t j j d d ƒ t j j ƒ  g d d d t j ƒd  S(   Ni   i   t   n_testsi   t   rng(   Rk   R6   R   R'   R)   R*   RË   RÒ   (   RK   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt   test_gradient*  s    c         C` sÉ   t  j ƒ  } t  j ƒ  } t  j ƒ  } |  j | | g |  j | | ƒ g t j j d d ƒ t j j ƒ  g |  j	 ƒ |  j | | g |  j | | ƒ g t j j d d d ƒ t j j ƒ  g |  j	 d t
 ƒd  S(   Ni   i   R¨   (   R   t   dtensor3RW   t   dscalarRf   R2   R'   R)   R*   RB   Rª   (   RK   t   zR=   RÏ   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRj   3  s    !
!	(   Rm   Rn   R'   R)   t   RandomStateRÒ   RA   RÊ   R   RÓ   Rj   (    (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRË     s
   			t   TestFillDiagonalOffsetc           B` s>   e  Z e j j d  ƒ Z d „  Z d „  Z d „  Z d „  Z	 RS(   i+   c         C` s)   t  t |  ƒ j ƒ  t |  _ t |  _ d  S(   N(   R@   RØ   RA   R   RB   R   R2   (   RK   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRA   G  s    	c   
      C` sr  t  j ƒ  } t  j ƒ  } t  j ƒ  } t | | | g t | | | ƒ ƒ } x#d	 D]} xd
 d d d g D]þ } t j j | Œ  j	 t
 j ƒ } t j t
 j t j j ƒ  ƒ } | | | | ƒ }	 t j t j |	 | ƒ | ƒ sá t ‚ | d k r+|	 | k j ƒ  t t | j ƒ | j d | ƒ k sft ‚ qh |	 | k j ƒ  t t | j ƒ | j d | ƒ k sh t ‚ qh WqO Wd  S(   Niûÿÿÿiüÿÿÿiÿÿÿÿi    i   i   i   i   (   iûÿÿÿiüÿÿÿiÿÿÿÿi    i   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   R   R—   R¼   R&   R   R   R'   R)   R*   RF   R   RG   RÌ   RO   RÍ   R3   R   RÎ   Re   (
   RK   R=   RÏ   RÖ   R8   t   test_offsetRÂ   R   RÐ   Rƒ   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRÊ   L  s    $$ c         ` sÛ   xÔ d D]Ì ‰  ‡  f d †  } t  j | t j j d d	 ƒ t j j ƒ  g d
 d d t j ƒt  j | t j j d	 d ƒ t j j ƒ  g d
 d d t j ƒt  j | t j j d d ƒ t j j ƒ  g d
 d d t j ƒq Wd  S(   Niûÿÿÿiüÿÿÿiÿÿÿÿi    i   i   i   c         ` s   t  |  | ˆ  ƒ S(   N(   R   (   R   RÐ   (   RÙ   (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt   fill_diagonal_with_fix_offsetc  s    i   RÑ   RÒ   (   iûÿÿÿiüÿÿÿiÿÿÿÿi    i   i   i   (   Rk   R6   R'   R)   R*   RØ   RÒ   (   RK   RÚ   (    (   RÙ   sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRÓ   `  s    	$	$	$c         C` sã   t  j ƒ  } t  j ƒ  } t  j ƒ  } x¸ d	 D]° } |  j | | | g |  j | | | ƒ g t j j d d ƒ t j j ƒ  | g |  j	 ƒ |  j | | | g |  j | | | ƒ g t j j d d ƒ t j j ƒ  | g |  j	 ƒ q+ Wd  S(
   Niûÿÿÿiüÿÿÿiÿÿÿÿi    i   i   i   i   (   iûÿÿÿiüÿÿÿiÿÿÿÿi    i   i   i   (
   R   RW   RÕ   R&   Rf   R2   R'   R)   R*   RB   (   RK   R=   RÏ   RÖ   RÙ   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRj   p  s    '
'(
   Rm   Rn   R'   R)   R×   RÒ   RA   RÊ   RÓ   Rj   (    (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRØ   C  s
   			c          C` sP  t  j j ƒ  }  t |  d ƒ } t  j |  g | ƒ } | d d d d d g ƒ } | j t  j j k si t ‚ t	 j
 | d d d d d d d d d d g
 d d d d d d d d d d g
 d d d d d d d d d d g
 d d d d d d d d d d g
 d d d d d d d d d d g
 g ƒ s&t ‚ t  j j ƒ  }  t |  d d	 d
 ƒ} t  j |  g | ƒ } | d d d d d g ƒ } | j d
 k st ‚ t	 j
 | d d d d d d d d d d g
 d d d d d d d d d d g
 d d d d d d d d d d g
 d d d d d d d d d d g
 d d d d d d d d d d g
 g ƒ sLt ‚ d  S(   Ni
   i   i   i   i   i   g        g      ð?R!   R?   (   R+   R   R¯   R   R   R!   R   RG   R3   R'   RO   (   R>   t   oR8   Rƒ   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt   test_to_one_hot  s0    !!!!0!!!!t   test_Uniquec           B` s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C` sŒ   t  t |  ƒ j ƒ  t |  _ t ƒ  t t ƒ t t t ƒ t t t ƒ t t t t ƒ t t t t ƒ t t t t ƒ t t t t ƒ g |  _ d  S(   N(   R@   RÝ   RA   R   RB   Ra   Rª   t   ops(   RK   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRA   Ÿ  s    		c   
      C` sY  t  j j ƒ  } t j d d d d g d t j ƒ} t j | ƒ g t j | t ƒ t j | t	 t ƒ t j | t t ƒ t j | t	 t	 t ƒ t j | t t	 t ƒ t j | t	 t t ƒ t j | t t t ƒ g } xƒ t
 |  j | ƒ D]o \ } } t  j d | g d | | d t ƒƒ } | | ƒ } x- t
 | | ƒ D] \ } }	 t j | |	 ƒ q1Wqâ Wd S(	   sv   
        Basic test for a vector.
        Done by using the op and checking that it returns the right answer.
        i   i   i   R!   t   inputst   outputst   return_listN(   R+   R   RC   RE   R(   R   RG   t   uniqueRa   Rª   RŸ   RÞ   R   Rk   t   assert_allclose(
   RK   R=   t   inpt   list_outs_expectedR2   t   outs_expectedR8   t   outsRƒ   t   out_exp(    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt   test_basic_vector«  s    $'c   
      C` sh  t  j j ƒ  } t j d d g d d g d d g g d t j ƒ} t j | ƒ g t j | t ƒ t j | t	 t ƒ t j | t t ƒ t j | t	 t	 t ƒ t j | t t	 t ƒ t j | t	 t t ƒ t j | t t t ƒ g } xƒ t
 |  j | ƒ D]o \ } } t  j d | g d | | d t ƒƒ } | | ƒ } x- t
 | | ƒ D] \ } }	 t j | |	 ƒ q@Wqñ Wd S(	   sn    Basic test for a matrix.
        Done by using the op and checking that it returns the right answer.
        i   i   i   R!   Rß   Rà   Rá   N(   R+   R   R—   RE   R(   R   RG   Râ   Ra   Rª   RŸ   RÞ   R   Rk   Rã   (
   RK   R=   Rä   Rå   R2   Ræ   R8   Rç   Rƒ   Rè   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt   test_basic_matrixÁ  s    3'c      
   C` s«   t  j j ƒ  } x• |  j D]Š } | j s. q n  | j rJ | | ƒ d } n | | ƒ d } |  j | g | g t j t j	 d d d d g ƒ d t
 j ƒg |  j ƒ q Wd S(   s8   
        Testing the infer_shape with a vector.
        i   i   i   R!   N(   R+   R   RC   RÞ   t   return_inverset   return_indexRf   RE   R(   RÈ   R   RG   RB   (   RK   R=   R2   R8   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt   test_infer_shape_vectorÖ  s    		!c      
   C` sº   t  j j ƒ  } x¤ |  j D]™ } | j s. q n  | j rJ | | ƒ d } n | | ƒ d } |  j | g | g t j t j	 d d g d d g d d g g ƒ d t
 j ƒg |  j ƒ q Wd S(   s8   
        Testing the infer_shape with a matrix.
        i   i   i   R!   N(   R+   R   R—   RÞ   Rë   Rì   Rf   RE   R(   RÈ   R   RG   RB   (   RK   R=   R2   R8   (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt   test_infer_shape_matrixé  s    		0(   Rm   Rn   RA   Ré   Rê   Rí   Rî   (    (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyRÝ     s
   				(7   t
   __future__R    R   R   t	   functoolsR   R'   RE   R+   t   theano.testsR   Rk   t   theano.tensor.extra_opsR   R   R   R   R	   R
   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R$   R   R   t   theano.tests.unittest_toolsR   R;   t   InferShapeTesterR<   Ro   Rz   R•   Rž   R¬   R³   RÆ   RË   RØ   RÜ   RÝ   (    (    (    sB   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_extra_ops.pyt   <module>   s,   Ž	V7)09);>	