ó
àÆ÷Xc           @` s³  d  d l  m Z m Z m Z d  d l Z d  d l Z d  d l m Z d  d l m	 Z	 d  d l
 Z
 d  d l j Z d  d l m Z d  d l m Z d  d l m Z d  d l m Z d  d	 l m Z d  d
 l m Z d  d l m Z d  d l m Z d  d l m Z m Z e
 j j ƒ  j d d d d ƒ Z  d „  Z! d e e f d „  ƒ  YZ" d e e f d „  ƒ  YZ# d e e e f d „  ƒ  YZ$ d e e e f d „  ƒ  YZ% d e f d „  ƒ  YZ& d S(   i    (   t   absolute_importt   print_functiont   divisionN(   t   TestCase(   t   SkipTest(   t   CGer(   t   ScipyGer(   t   Ger(   t   CGemv(   t   Gemv(   t   check_force_gemv_init(   t   unittest_tools(   t   TestOptimizationMixin(   t   BaseGemvt   TestBlasStridest   BlasOptt
   specializet   InplaceBlasOptt   c_blasc          G` sV   t  j j j d k rR d } |  r; d d j |  ƒ d } n  t d | d ƒ ‚ n  d  S(   Nt    s    (at least s   , t   )sA   This test is useful only when Theano can access to BLAS functionss    other than [sd]gemm_.(   t   theanot   configt   blast   ldflagst   joinR   (   t   functions_detectedt   functions_string(    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyt   skip_if_blas_ldflags_empty   s
    t   TestCGerc           B` sn   e  Z d  d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d	 „  Z
 d
 „  Z d „  Z RS(   t   float64c         C` s÷   | |  _  t j j ƒ  j d ƒ |  _ t j d | d t t f ƒ |  _ t j d | d d
 ƒ |  _	 t j d | d t f ƒ |  _
 t j d | d t f ƒ |  _ t j d d | ƒ|  _ t j d d g d | ƒ|  _ t j d d d	 g d | ƒ|  _ d  S(   Nt   fast_runt   dtypet   broadcastablei   i   i   g      ø?gš™™™™™@g333333@(    (   i   i   (   R    R   t   compilet   get_default_modet	   includingt   modet   tensort   Falset   At   at   xt   yt   numpyt   onest   Avalt   asarrayt   xvalt   yval(   t   selfR    (    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyt   setUp'   s    	!c         C` s   t  j | | d |  j ƒS(   NR%   (   R   t   functionR%   (   R2   t   inputst   outputs(    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyR4   3   s    c         C` sR   | |  j  |  j |  j ƒ | |  j  d  d  d … d  d  d … f |  j |  j ƒ d  S(   Niÿÿÿÿ(   R.   R0   R1   (   R2   t   f(    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyt   run_f9   s    c         C` s   t  j t j | d |  j ƒƒ S(   NR    (   R&   t   as_tensor_variableR,   R/   R    (   R2   t   bval(    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyt   b=   s    c         C` s  |  j  t t ƒ t t ƒ k ƒ |  j  t t ƒ t t ƒ k ƒ |  j  t t ƒ t t ƒ k ƒ |  j  t t ƒ t t ƒ k ƒ |  j  t t ƒ t t ƒ k ƒ |  j  t t ƒ t t ƒ k ƒ |  j  t t ƒ t t ƒ k ƒ |  j  t t ƒ d  k	 ƒ |  j  t t ƒ d  k	 ƒ d  S(   N(   t
   assertTrueR   t   TrueR'   R   R   t   None(   R2   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyt   test_eq@   s    c         C` s…   |  j  t t t ƒ ƒ t t t ƒ ƒ k ƒ |  j  t t t ƒ ƒ t t t ƒ ƒ k ƒ |  j  t t t ƒ ƒ t t t ƒ ƒ k ƒ d  S(   N(   R<   t   hashR   R=   R'   (   R2   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyt	   test_hashN   s    ++c         C` sg   t  ƒ  |  j |  j |  j g t j |  j |  j ƒ ƒ } |  j | t d t ƒ ƒ | |  j	 |  j
 ƒ d  S(   Nt   destructive(   R   R4   R*   R+   R&   t   outert   assertFunctionContainsR   R=   R0   R1   (   R2   R7   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyt   test_optimization_pipelineS   s    0c         C` st   t  ƒ  |  j d ƒ |  j |  j |  j g t j |  j |  j ƒ ƒ } |  j | t d t	 ƒ ƒ | |  j
 |  j ƒ d  S(   Nt   float32RB   (   R   R3   R4   R*   R+   R&   RC   RD   R   R=   R0   R1   (   R2   R7   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyt    test_optimization_pipeline_floatY   s
    0c         C` ss   |  j  d ƒ |  j |  j |  j g t j |  j |  j ƒ ƒ } |  j | t d t ƒ ƒ |  j | t d t	 ƒ ƒ d  S(   Nt   int32RB   (
   R3   R4   R*   R+   R&   RC   t   assertFunctionContains0R   R=   R'   (   R2   R7   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyt   test_int_fails`   s    0c         C` sn   t  ƒ  |  j |  j |  j |  j g |  j t j |  j |  j ƒ ƒ } |  j | t d t	 ƒ ƒ |  j
 | ƒ d  S(   NRB   (   R   R4   R(   R*   R+   R&   RC   RD   R   R'   R8   (   R2   R7   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyt   test_A_plus_outerf   s
    "c         C` sr   t  ƒ  |  j |  j |  j |  j g |  j d t j |  j |  j ƒ ƒ } |  j | t d t	 ƒ ƒ |  j
 | ƒ d  S(   Ngš™™™™™¹?RB   (   R   R4   R(   R*   R+   R&   RC   RD   R   R'   R8   (   R2   R7   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyt   test_A_plus_scaled_outerm   s
    &(   t   __name__t
   __module__R3   R4   R8   R;   R?   RA   RE   RG   RJ   RK   RL   (    (    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyR   %   s   									t	   TestCGemvc           B` se   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d	 d
 „ Z
 d „  Z RS(   sž   Tests of CGemv specifically.

    Generic tests of Gemv-compatibility, including both dtypes are
    done below in TestCGemvFloat32 and TestCGemvFloat64

    R   c         C` s÷   | |  _  t j j ƒ  j d ƒ |  _ t j d | d t t f ƒ |  _ t	 j
 d
 d | ƒ|  _ t j d | d t f ƒ |  _ t j d | d t f ƒ |  _ t	 j d d g d | ƒ|  _ t	 j d d d	 g d | ƒ|  _ t j d | d d ƒ |  _ d  S(   NR   R    R!   i   i   i   g      ø?gš™™™™™@g333333@(   i   i   (    (   R    R   R"   R#   R$   R%   R&   R'   R(   R,   R-   R.   R*   R+   R/   R0   R1   R)   (   R2   R    (    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyR3   |   s    	!!c         C` sï   |  j  j ƒ  } t | _ t j |  j |  j |  j |  j	 g |  j	 |  j t j
 |  j |  j ƒ d | ƒ} t j d d |  j ƒ} t j d d |  j ƒ} t d ƒ t j d	 d |  j ƒ} | | | | d ƒ } t j | ƒ j ƒ  së t ‚ d  S(
   NR%   i   i   R    t   NaNi    (   i   i   (   i   (   i   (   R%   R$   R'   t   check_isfiniteR   R4   R(   R*   R+   R)   t   dotR,   R-   R    t   floatt   isnant   anyt   AssertionError(   R2   R%   R7   R.   R0   R1   t   zval(    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyt   test_nan_beta_0   s    	!&	"c      	   C` s  t  ƒ  t j |  j |  j g t j |  j |  j ƒ d |  j ƒ} |  j | t j ƒ |  j	 | t
 d t ƒ ƒ t j | |  j |  j ƒ t j |  j |  j ƒ ƒ s¥ t ‚ t j | |  j |  j d  d  d … d  d  d … f ƒ t j |  j |  j d  d  d … d  d  d … f ƒ ƒ st ‚ d  S(   NR%   t   inplaceiÿÿÿÿ(   R   R   R4   R*   R(   RR   R%   RI   R&   t   assertFunctionContains1R   R=   R,   t   allcloseR0   R.   RV   (   R2   R7   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyt   test_optimizations_vm™   s    !4c         C` s  t  ƒ  t j |  j |  j g t j |  j |  j ƒ d |  j ƒ} |  j | t j ƒ |  j	 | t
 d t ƒ ƒ t j | |  j |  j ƒ t j |  j |  j ƒ ƒ s¥ t ‚ t j | |  j d  d  d … d  d  d … f |  j ƒ t j |  j d  d  d … d  d  d … f |  j ƒ ƒ st ‚ d  S(   NR%   RY   iÿÿÿÿ(   R   R   R4   R(   R+   RR   R%   RI   R&   RZ   R   R=   R,   R[   R.   R1   RV   (   R2   R7   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyt   test_optimizations_mv¯   s    !4c         C` s(   t  ƒ  r$ t j j d d d ƒ n  d  S(   Ns7   WARNING: The current BLAS requires Theano to initializes8    memory for some GEMV calls which will result in a minors+    degradation in performance for such calls.(   R
   t   syst   stderrt   write(   R2   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyt   test_force_gemv_initÄ   s    		c      	   C` sÝ  t  j j t j ƒ  ƒ } t j t  j | j d | d f ƒ d d ƒƒ } t  j | j d | d f ƒ d d ƒ} t j | ƒ } t j t  j | j d | ƒ d d ƒƒ } t j	 g  | t
 j | | ƒ d |  j ƒ} t  j | ƒ  t  j | j ƒ  | j ƒ  ƒ | ƒ st ‚ g  | j j j ƒ  D] } | j ^ q}	 |	 t d t ƒ g k sXt |	 ƒ ‚ t j	 g  g  d | | t j | | ƒ f g d |  j ƒ}
 |
 ƒ  t  j | j ƒ  t  j | j ƒ  | j ƒ  ƒ | ƒ sÓt ‚ g  |
 j j j ƒ  D] } | j ^ qæ}	 |	 t d t ƒ g k st ‚ | j | j d	 t ƒ d
 d
 d … d
 d
 d … f d	 t ƒ| j | ƒ t  j | ƒ  t  j | j ƒ  | j ƒ  ƒ | ƒ s˜t ‚ |
 ƒ  t  j | j ƒ  t  j | j ƒ  | j ƒ  ƒ | ƒ sÙt ‚ d
 S(   s%    test vector2 + dot(matrix, vector1) t   sizei   R    RF   i    R%   RY   t   updatest   borrowNiÿÿÿÿ(   R,   t   randomt   RandomStateR   t
   fetch_seedR   t   sharedt   arrayt   uniformR4   R&   RR   R%   R[   t	   get_valueRV   t   makert   fgrapht   toposortt   opR   R'   R=   t	   set_value(   R2   t   m_shpt   rngt   v1t   v2_origt   v2t   mR7   t   nt   topot   g(    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyt   t_gemv1Ì   s<    %(+($+(.+c         C` ss   t  ƒ  |  j d ƒ |  j d ƒ |  j d ƒ |  j d ƒ |  j d	 ƒ |  j d
 ƒ |  j d ƒ |  j d ƒ d  S(   Ni   i   i   i    (   i   i   (   i   i   (   i    i   (   i   i   (   i   i    (   i   i    (   i    i   (   i    i    (   R   Rz   (   R2   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyt
   test_gemv1ö   s    RF   c         C` s  t  j t  j d d | ƒd d ƒ} t  j t  j d d | ƒd d ƒ} | |  j | t j |  j |  j ƒ } t  j |  j |  j |  j g | d |  j	 ƒ} t
 j d d | ƒ} t
 j d d | ƒ} t
 j d	 d | ƒ} t
 j d d | ƒ}	 t
 j d
 d | ƒ}
 | | | |	 ƒ | | d  d  d … d  d  d … f | |	 ƒ |  j t | | | |	 ƒ |  j t | | | |
 ƒ |  j t | | | |
 ƒ d  S(   Ng      ð?R    t   namet   alphat   betaR%   i   i   i   i   iÿÿÿÿ(   i   i   (   R   Rh   t   _asarrayR+   R&   RR   R(   R*   R4   R%   R,   R-   t   assertRaisest
   ValueError(   R2   R    R}   R~   t   zR7   t   A_valt   ones_3t   ones_4t   ones_5t   ones_6(    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyt   test_gemv_dimensions  s"    		'!,c   
      C` s[  t  ƒ  t j d ƒ } t j d ƒ } t j d ƒ } t j | | | g t j | | ƒ t j | | ƒ g d t ƒ} t j	 j
 d d ƒ } t j	 j
 d ƒ } t j	 j
 d ƒ } | | | | ƒ } t j | d t j | | ƒ ƒ sæ t ‚ t j | d t j | | ƒ ƒ st ‚ t g  | j j j D]! }	 t |	 j t j ƒ r!|	 ^ q!ƒ d k sWt ‚ d  S(	   NR*   R+   R‚   R%   i   i    i   i   (   R   R&   t   dmatrixt   dvectorR   R4   RR   t   mode_blas_optR,   Re   t   randR[   RV   t   lenRl   Rm   t   apply_nodest
   isinstanceRo   t
   AllocEmpty(
   R2   R*   R+   R‚   R7   t   vxt   vyt   vzt   outRw   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyt   test_multiple_inplace  s    $	(((   RM   RN   t   __doc__R3   RX   R\   R]   Ra   Rz   R{   Rˆ   R•   (    (    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyRO   u   s   					*	t   TestCGemvFloat32c           B` s;   e  Z e Z d  Z e d e ƒ Z e d e ƒ Z	 d „  Z
 RS(   RF   RY   c         C` s   t  ƒ  d  S(   N(   R   (   R2   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyR3   1  s    (   RM   RN   R‹   R%   R    R   R'   t   gemvR=   t   gemv_inplaceR3   (    (    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyR—   +  s
   t   TestCGemvFloat64c           B` s;   e  Z e Z d  Z e d e ƒ Z e d e ƒ Z	 d „  Z
 RS(   R   RY   c         C` s   t  ƒ  d  S(   N(   R   (   R2   (    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyR3   ;  s    (   RM   RN   R‹   R%   R    R   R'   R˜   R=   R™   R3   (    (    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyRš   5  s
   t   TestBlasStridesCc           B` s   e  Z e Z RS(    (   RM   RN   R‹   R%   (    (    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyR›   ?  s   ('   t
   __future__R    R   R   R^   R,   t   unittestR   t   nose.plugins.skipR   R   t   theano.tensorR&   t   theano.tensor.blas_cR   t   theano.tensor.blas_scipyR   t   theano.tensor.blasR   R   R	   R
   t   theano.testsR   t   theano.tests.unittest_toolsR   t   theano.tensor.tests.test_blasR   R   R"   R#   R$   R‹   R   R   RO   R—   Rš   R›   (    (    (    s?   /tmp/pip-build-X4mzal/theano/theano/tensor/tests/test_blas_c.pyt   <module>   s.   	P¶

