
˽Xc        	   @` s  d  Z  d d l m Z m Z m Z d d l Z d d l m Z m	 Z	 d d l
 m
 Z
 d d l m Z d d l m Z d d l m Z m Z m Z d d l Z d d l Z d d l Z d d	 l m Z m Z m Z m Z m Z m Z d d l Z d d
 l m Z d d l  j! Z" d d l# j j$ j% Z& d d l' m( Z( m) Z) m* Z* d d l+ m, Z, m- Z- m. Z. m/ Z/ d d l0 m1 Z1 m2 Z2 m3 Z3 m4 Z4 m5 Z5 m6 Z6 m7 Z7 d d l8 m9 Z: e e	 e;  d  Z< d   Z= e j> d e j? d d e@ jA d d  ZB i d d 6i d d 6d 6i eB d 6d 6g ZC eC jD i d d 6i d d 6d 6i e e d  g  d 6d 6 eC jD i d d 6i d d 6d 6i e jE eB  d  e jF eB  d 6d 6 e jG d  ZH eI eJ d d#   eH d <eI eJ d d   eH d d  d f <eC jD i d$ d 6i d d% 6d 6i eH d% 6d 6 eC jD i d& d 6i d& d' 6d 6i e" jK eH  d' 6d 6 eH jL eM  ZN eN d c d  7<eC jD i d( d 6i d& d) 6d 6i e" jK eN  d) 6d 6 eC jD i d* d 6i d d+ 6d d, 6d 6i eB d+ 6eH d, 6d 6 eC jD i d- d 6i d d. 6d 6i e= d/  d. 6d 6 eC jD i d0 d 6i d d1 6d 6i e e d2  g  d1 6d 6 e= g  e= d g  e= d d3 g g  e= d d3 d! g g  f d eO jA d d/  ZP e e d4  g  eP d <i d5 d 6i d5 d6 6d 6i eP d6 6d 6g ZQ e= e= d  e= d3  e= g   e= g   e= d!  f d eO jA d d/  ZR e jS d d eO ZT e= d  eT d <eQ jD i d7 d 6i d5 d8 6d 6i eT d8 6d 6 eQ jD i d9 d 6i d5 d: 6d 6i eR d: 6d 6 eQ jD i d; d 6i d d< 6d 6i e e d=  e d>  e d?  g  d< 6d 6 eQ jD i d@ d 6i d dA 6d 6i e jU e jA eI eJ d dB   d   dA 6d 6 e e jV d3  e jW d  e j> g  jA d d!  ZX g  dC dD dE g D] ZY eY eO f ^ qZZ e jG d eZ  Z[ e e dF  g  e[ dC d <eX e[ dD d <eX d e[ dE d <eQ jD i dG d 6i dG dH 6d 6i e[ dH 6d 6 e jG d d eO Z\ e= d  e\ d <e jG d d eO e\ d <e= d3 d e j] e\ d d <e= d! g g d e j] e\ d d <e jG d d eO e\ d d <e= d d e j] e\ d d d <e= d" d e j] e\ d d d <eQ jD i dI d 6i d5 dJ 6d 6i e\ dJ 6d 6 e jS d d g  dK dL g D] ZY eY eO f ^ quZ^ e= d  e^ d dK <e jS d d d? eO f g e^ d dL <e e dM  g  e^ d dL d d? <eQ jD i dN d 6i dG dO 6d 6i e^ dO 6d 6 e jS d d g  dK dL g D] ZY eY eO f ^ q8	Z_ e= d  e_ d dK <e= d3  e_ d dL <e e dP  g  e_ d dK <e e dQ  g  e_ d dL <eQ jD i dR d 6i dG dS 6d 6i e_ dS 6d 6 e jZ g  dT dU dV dW dX dY g D] ZY eY eO f ^ q
 Z` e1 e jG d d e` dZ  Za ea d Zb e e d[  g  eb dT <e e d\  g  eb dU <e e d[  g  eb dV <e= d  eb dW <e= d  eb dX <e= d  eb dY <eQ jD i d] d 6i d] d^ 6d 6i ea d^ 6d 6 ec e e< d_  d`  Zd ed je   jf da  Zg ed jh   eQ jD i db d 6i d dc 6d 6i e eg g  dc 6d 6 eQ jD i d& d 6i d& d' 6d 6i e" jK eH  d' 6d 6 eQ jD i d( d 6i d& d) 6d 6i e" jK eN  d) 6d 6 eQ jD i dd d 6i de df 6d 6i e ei g ej g g  df 6d 6 eQ Zk ek jD i dg d 6i d] dh 6d 6i e jl ea d3  jA d d3  dh 6d 6 di   Zm dj   Zn dk   Zo dl   Zp dm   Zq dn   Zr do   Zs dp   Zt dq   Zu dr   Zv ds   Zw dt   Zx du   Zy dv   Zz dw   Z{ dx   Z| dy   Z} dz   Z~ d{   Z d|   Z d}   Z d~   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z e d k re   n  d S(   sD    Nose test generators

Need function load / save / roundtrip tests

i    (   t   divisiont   print_functiont   absolute_importN(   t   joint   dirname(   t   glob(   t   BytesIO(   t   mkdtemp(   t   ut	   text_typet   string_types(   t   assert_array_equalt   assert_array_almost_equalt   assert_equalt   assert_raisest   run_module_suitet   assert_(   t   array(   t   matdimst   MatWriteErrort   MatReadError(   t   mat_reader_factoryt   loadmatt   savematt   whosmat(   t   MatlabObjectt   MatFile5Writert   MatFile5Readert   MatlabFunctiont   varmats_from_matt   to_writeablet   EmptyStructMarker(   t   mio5_paramst   datac          O` s%   t  j |  |   } t |  | _ | S(   s:   Convenience function to return matlab-compatible 2D array.(   t   npR   R   t   shape(   t   argst   kwargst   arr(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   mlarr(   s    i   i	   t   dtypei   t   doublet   namet
   testdoublet   classest   expectedt   stringt   chart
   teststrings+   "Do nine men interpret?" "Nine men," I nod.t   complext   testcomplexy              ?i   i   i   t   matrixt
   testmatrixt   sparset
   testsparset   sparsecomplext   testsparsecomplext   multit   thetat   at   minust	   testminusit   onechart   testonechart   ri   s@   This cell contains this string and 3 arrays of increasing lengtht   cellt   testcellt
   scalarcellt   testscalarcellt	   emptycellt   testemptycellt   stringarrayt   teststringarrays   one  s   two  t   threet   3dmatrixt   test3dmatrixi   t   stringfieldt   doublefieldt   complexfields   Rats live on no evil star.t   structt
   teststructt   cellnestt   testcellnestt   onet   twos   number 3t
   structnestt   teststructnests   number 1s   number 2t	   structarrt   teststructarrt   exprt	   inputExprR$   t   isEmptyt   numArgst   versiont   inlinet   xs    x = INLINE_INPUTS_{1};t   objectt
   testobjects   japanese_utf8.txtt   rbs   utf-8t   unicodet   testunicodet   boolt   logicalt	   testboolst   objectarrayt   testobjectarrayc         C` s   t  |   } t  |  } | | k r( t S| t j k r\ |  j d k r\ t  |  j    | k S| t j k r | j d k r t  | j    | k St S(   sk   Check if types are same or compatible.

    0-D numpy scalars are compatible with bare python scalars.
    (    (    (   t   typet   TrueR"   t   ndarrayR#   t   itemt   False(   t   var1t   var2t   type1t   type2(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   types_compatible   s    c         C` s  t  j |  rK t t  j |   t | j   | j   d |  d d d St t | |  d t |  t |  |  f  t | t j	 t j
 t f  s t | |  d St | j | j k d d | j | j |  f | j } | j rTt | t  rt | j | j  n  x> t |  D]0 \ } } d |  | f } t | | | |  qWd S| j rx9 | j D]. } d	 |  | f } t | | | | |  qgWd S| j t t j t j f k rt | | d |  d St | | d |  d d d S(
   s/    Check one level of a potentially nested array t   err_msgt   decimali   Ns   Expected type %s, got %s at %st   msgs   Expected shape %s, got %s at %ss
   %s, [%d], s   %s, field %s, (   t   SPt   issparseR   R   t   todenseRs   Rj   t
   isinstanceR"   t   voidRl   R   R   R#   R(   t	   hasobjectt	   classnamet	   enumeratet   _check_levelt   fieldsR	   t   unicode_t   bool_(   t   labelR-   t   actualt   ex_dtypet   it   evt   level_labelt   fn(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyR      sL    					c   	      C` s   x | D] } t  | d t } d |  | f } xU | j   D]G \ } } d | | f } t | | k d |  t | | | |  q< Wq Wd  S(   Nt   struct_as_records   test %s; file %ss   %s, variable %ss   Missing key at %s(   R   Rk   t   itemsR   R   (	   R*   t   filest   caset	   file_namet   matdictR   t   kR-   t   k_label(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   _load_check_case'  s    c   
      C` s   x | D] } d |  | f } t  |  } g  } x7 | j   D]) \ } }	 | j | |	 j | | f  q< W| j   | j   t | | d | | | f  q Wd  S(   Ns   test %s; file %ss   %s: %r != %r(   R   R   t   appendR#   t   sortR   (
   R*   R   R   R,   R   R   t   whost   expected_whosR   R-   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   _whos_check_case1  s    !

	c         C` s@   t    } t | | d | | j d  t |  | g |  d  S(   Nt   formati    (   R   R   t   seekR   (   R*   R-   R   t
   mat_stream(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   _rt_check_caseC  s    	c          c` s   xy t  t D]m }  |  d } |  d } t t d |  } t |  } t t |  d k d | | f  t | | | f Vq Wd  S(   NR*   R-   s   test%s_*.mati    s$   No files for test %s using filter %s(   t   case_table4t   case_table5t   pjoint   test_data_pathR   R   t   lenR   (   R   R*   R-   t   filtR   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt	   test_loadK  s    

c          c` s   x t  t D]z }  |  d } |  d } |  d } t t d |  } t |  } t t |  d k d | | f  t | | | | f Vq Wd  S(   NR*   R-   R,   s   test%s_*.mati    s$   No files for test %s using filter %s(   R   R   R   R   R   R   R   R   (   R   R*   R-   R,   R   R   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt	   test_whosW  s    


c          c` s   x t  t D]| }  g  t  D] }  |  d ^ q } |  d d } |  d } x> |  d | k re d d g n d g D] } t | | | f Vql Wq Wd  S(   NR*   t   _round_tripR-   t   4t   5(   R   t   case_table5_rtR   (   R   t   case_table4_namesR*   R-   R   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_round_tripd  s    
,c    	      C` s  t  j d  }  d |  d <d |  d <t j |   } d } i | d	 6} d
 } t   } zv t | |  } t j | d d } t | | d | | j	   t j | d d } t
 | d t } | j	   Wd  t j |  Xt | d	 j   | d	 j   d t |  d  S(   Ni   gffffff@i   i   g      @i   i   t	   gzip_testR_   R   t   modet   wbR   Rb   R   Rt   (   i   i   (   i   i   (   i   i   (   R"   t   zerosRw   t
   csc_matrixR   R   t   gzipt   openR   t   closeR   Rk   t   shutilt   rmtreeR   Ry   t   repr(	   t   xdenseR_   R*   R-   R   t   tmpdirt   fnameR   R   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_gzip_simplem  s(    

	
c          C` s   t    }  z t d t j d   } t |  d  } t | |  t j |  t | |  t |  t j |  t	 | d  } t | |  | j
 d  | j   t	 | d  } t |  | j
 d  | j   Wd  t j |   Xd  S(   NR_   i   s   a.matR   i    Rb   (   i   i   (   R   t   dictR"   R   R   R   t   ost   unlinkR   R   R   R   R   R   (   R   R_   R   t   f(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_multiple_open  s$    	


c          C` so   t  t t d   }  t t |   d k  x= |  D]5 } t | d  } t t t | d t	 | j
   q2 Wd  S(   Ns   testhdf5*.mati    Rb   R   (   R   R   R   R   R   R   R   t   NotImplementedErrorR   Rk   R   (   t	   filenamest   filenamet   fp(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt
   test_mat73  s    c          C` sW   t  t d  }  t j   6 t j d  t |  d t } t |  d t } Wd  QXd  S(   Ns   testdouble_7.1_GLNX86.matt   errorR   (   R   R   t   warningst   catch_warningst   simplefilterR   Rk   Rn   (   R   t   mres(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_warnings  s
    c          C` s{   t    }  t |  i i d d 6d 6d d t |   d } t | j d  t | j t j t   t | d d  k  d  S(	   Ni   i   t   dR   R   i    (   i   i   (   i    i    (
   R   R   R   R   R#   R(   R"   R`   R   t   None(   t   siot   back(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_regression_653  s    	!c          C` s   d }  d |  } t  j d d | t f g } t t   i | d 6d d d |  d } t  j d	 d | t f g } t t t t   i | d 6d d d  S(
   Ni   R;   i   R(   t
   longstructR   R   (   i   i   (   i   i   (   R"   R   R`   R   R   R   t
   ValueError(   t   limt   fldnamet   st1(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_structname_len  s    
c       	   C` sK   t  j d d d t f g }  t t t t   i |  d 6d d d t d  S(	   Ni   R(   t   my_fieldnamet	   my_structR   R   t   long_field_names(   i   i   (   R"   R   R`   R   R   R   R   Rk   (   R   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt(   test_4_and_long_field_names_incompatible  s    c       	   C` s   d }  d |  } t  j d	 d | t f g } t t   i | d 6d d d t d |  d } t  j d
 d | t f g } t t t t   i | d 6d d d t d  S(   Ni?   R;   i   R(   R   R   R   R   (   i   i   (   i   i   (   R"   R   R`   R   R   Rk   R   R   (   R   R   R   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_long_field_names  s    
#c       	   C` s   d }  d |  } t  j d d t } t  j d d | t f g } | | d <| | d <t t   i | d 6d d	 d
 t t t t t   i | d 6d d	 d
 t	 d  S(   Ni?   R;   i   i   R(   i    R   R   R   R   (   i   i   (   i   i   (   i    i    (   i    i   (
   R"   Rl   R`   R   R   R   Rk   R   R   Rn   (   R   R   RA   R   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_long_field_names_in_struct  s    


#c          C` s   t  j d d t }  d |  d <d |  d <t t   i |  d 6d d	 t  j d d t }  d
 |  d <t t   i |  d 6d d	 d  S(   Ni   i   R(   t   Helloi    t   WorldR_   R   R   s   Hello, world(   i   i   (   i    i    (   i    i   (   i   i   (   i    i    (   R"   Rl   R`   R   R   (   t   cells(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_cell_with_one_thing_in_it  s    


c          c` s   t  t    }  t |  j g  f Vd g |  _ t |  j d g f Vt |  j t f Vt |  _ t |  j t f Vt |  j t f Vt |  _ t |  j t f Vd  S(   Nt   avar(   R   R   R   t   global_varst   unicode_stringsRn   Rk   R   (   t   mfw(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_writer_properties  s    		c          c` s   t    }  t |   } t j d  } | j i | d 6 t |  j    } |  j d  |  j d  | j i | d 6 t	 | t |  j    d k f V|  j d  |  j d  | j i | d 6 t	 t |  j    | d k  f Vd  S(   Ni
   t   aaaaai    t   aaaai   t   aaaaaa(
   R   R   R"   R   t   put_variablesR   t   getvaluet   truncateR   R   (   R   t   wtrR&   t   w_sz(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_use_small_element  s    	!c    	      C` sy  t  t f f }  y d d l m } Wn t k
 r6 n X|  | t f f 7}  t j d	 g g d d t f d t f g } t j d
 g g d d t f d t f g } x |  D] \ } } | d d g  } t	   } t
 | i | d 6 | j d  t |  d } t t | j j  t d d g   | r>t | |  q | j j d d k rdt | |  q t | |  q Wd  S(   Ni    (   t   OrderedDicti   i   R(   R;   t   bR   (   i   i   (   i   i   (   R;   i   (   R   i   (   R   Rn   t   collectionsR   t   ImportErrorRk   R"   R   R`   R   R   R   R   R   t   setR(   t   namesR   (	   t
   dict_typesR   t   ab_expt   ba_expt	   dict_typet
   is_orderedR   t   streamt   vals(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_save_dict-  s(    --	%c          C` s   t  j d  }  x d
 D] } t   } t | i |  d 6d | t |  } t | d j d  t   } t | i |  d 6d | d d t |  } t | d j d  t   } t | i |  d 6d | d d	 t |  } t | d j d  q Wd  S(   Ni   R   R   t   onedR   i   t   oned_ast   columnt   row(   R   R   (   i   i   (   i   i   (   i   i   (   R"   t   arangeR   R   R   R   R#   (   R&   R   R   R   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_1d_shapeI  s$    			c          c` s}  t  j d  j d  }  d |  d <t   } t | i |  d 6 t | j    } t |  } t | d |  f Vt   } t | i |  d 6d t	 t | j    } t |  } t | d |  f Vt
 | | k f V|  j   } d | d <t   } t | i |  d 6| d
 6d t t |  } t | d
 | f Vt   } t | i |  d 6| d
 6d t	 t |  } t | d
 | f Vd  S(   Nid   i   i   i   i   i
   R&   t   do_compressioni    t   arr2(   i   i   (   i   i
   (   i    i    (   R"   R   t   reshapeR   R   R   R   R   R   Rk   R   t   copyRn   (   R&   R   t   raw_lenR   t   compressed_lenR  (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_compressionb  s.    
		
	!	!c          C` s0   t    }  t |  i t j d d t d 6 d  S(   Ni   R(   t   A(   R   R   R"   R   R`   (   R   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_single_object}  s    	c          c` s   t  t d  }  t |  d t } t d | k f Vt d | k f Vt |  d t } | j d  } t d | k f V| j j   d  S(   Ns   test_skip_variable.matR   t   firstt   second(	   R   R   R   Rk   R   R   t   get_variablesR   R   (   R   R   t   factory(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_skip_variable  s    c          C` s   t  t d  }  t |  d t } | d } t | j d	  t | j t j t   t	 | d
 d  k  t   } t j d d d } t | i | d 6 t |  } | d } t | |  d  S(   Ns   test_empty_struct.matR   R;   i   i    R(   t   UR&   (   i   i   (   i    i    (    (   R   R   R   Rk   R   R#   R(   R"   R`   R   R   R   R   R   R   (   R   R   R;   R   R&   t   a2(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_empty_struct  s    
	
c          C` st   t    }  t |  i i  d 6 t |   } | d } t | j d  t | j t j t   t | d d  k  d  S(   NR&   i   i    (   i   i   (   i    i    (
   R   R   R   R   R#   R(   R"   R`   R   R   (   R   R   R;   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_save_empty_dict  s    	
c         C` sD   t  } x- | D]% } t j |  | k  r t } Pq q Wt |  d S(   sH    Assert `output` is equal to at least one element in `alternatives`
    N(   Rn   R"   t   allRk   R   (   t   outputt   alternativest	   one_equalR-   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   assert_any_equal  s    c          C` sG  t  t j d g   }  t |  j d  t |  d  t j d g d d d g } t j d g d d d g } | | f } t t  i d d 6d d 6 |  t t  i d d 6d d 6d d 6 |  t t  i d d 6d d 6d d	 6 |  t t  i d d 6d d 6d d
 6 |  d t f d     Y} | } d | _ d | _	 t t  |  |  t  g   }  t |  j d  t |  j
 j t j  t  d  }  t |  j d  t |  j
 j t j  t t  d   d  k  t t  d  j
 j t j  t  d  }  t |  j d  t |  j
 j t j d  j
 j  t |  d  t t  i   t k  t t  t    d  k  d t f d     Y} t t  |    t k  t  i d d 6 d }  t |  j d  t |  j
 j t j  t t  i d d 6 t k  t t  i d d 6 t k  t t  i d d 6d d 6 t j d  g d d! g  d  S("   Ni   i   R(   R;   s   |O8R   i   t   _cid   t   99t   klassc           B` s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyR    s   i    s   a stringt   Cc           B` s   e  Z RS(    (   R  R  (    (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyR    s   t   1t   _aR   (   i   (   i   i   (   R;   s   |O8(   R   s   |O8(   i   i   (   R   s   |O8(   R;   s   |O8(   i    (    (   i    (    (   i   (   i   (   R   s   |O8(   R   R"   R   R   R#   R   R  R`   R;   R   R(   Rj   t   float64R   R   t   str_R   t   object_(   t   rest	   expected1t	   expected2R  R  t   cR  (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_to_writeable  sL    !(((		"c          c` sU  d d g }  t  j d d |  } d | d d <d	 | d d <d
 | d d <d | d d <t   } t | i | d 6 t | d t } | d d } t | j d f Vt | j d	 f Vt | d t	 } | d d } t | d d f Vt | d d	 f Vt | j
 t  j
 d d g  f V| d j d } t | d d
 f Vt | d d f Vd  S(   Nt   f1t   f8t   f2t   S10i   R(   g      ?i    t   pythonic   i   s   not perlR&   R   t   O(   s   f1R(  (   s   f2R*  (   i   (   i    i    (   i    i    (   s   f1R,  (   s   f2R,  (   R"   R   R   R   R   Rn   R   R'  R)  Rk   R(   t   flat(   t   dtR&   R   R   t   a20t   a21(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_recarray  s,    		c          C` s   d t  f d     Y}  |    } d | _ d | _ t   } t | i | d 6 t | d t } | d d
 } t | j d  t | j d  t | d t } | d d } t | d d  t | d	 d  d  S(   NR  c           B` s   e  Z RS(    (   R  R  (    (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyR  $  s   i   s   a stringR%  R   i    t   field1t   field2(   i    i    (   i    i    (	   R`   R2  R3  R   R   R   Rn   R   Rk   (   R  R%  R   R   t   c2(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_save_object#  s    				c          C` s  t  j d  j d d  }  t   } t | i |  d 6 t |  } | j   } | d } t | |   t | d t } t | j   d |  j d   t	 | _
 t | |   t | d t j } t | j   d |   t | d t j } t t | j  t j | _ t | j   d |   t  j d g  }  | j d  | j d  t | i |  d 6 t |  } t | j   d |   t | d t	 } t  j t  j t |  j    d	 d
  } t | j   d |  t | _ t | j   d |   d  S(   Ni   i   R;   t
   squeeze_met
   byte_orders   a stringi    t   chars_as_stringsR(   t   U1(   i   (   R"   R   R  R   R   R   R  R   Rk   Rn   R6  t   boct   native_codet   swapped_codeR   t	   ExceptionR7  R   R   R   t
   atleast_2dt   listRm   R8  (   R&   R   t   rdrt	   back_dictt   rarrt   carr(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_read_opts5  s8    	
 	*	c          C` sD  t  t d  }  t |  d  } t |  } | j   } | j   t | d t j g  d d  t	   } t
 | i t j d g  d 6 t |  } | j   } t | d t j g  d d  | j d  | j d  t
 | i t j g  d d d 6 t |  } | j   } t | d t j g  d d  | j   d  S(   Ns   single_empty_string.matRb   R;   R(   R9  t    i    (   R   R   R   R   R  R   R   R"   R   R   R   R   R   (   t   estring_fnameR   R@  R   R   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_empty_stringX  s$    
 	  # c          C` sy   d d  l  }  xf t d f |  j d f g D]I \ } } t t t |  d  # } t |  } t | | j  Wd  QXq( Wd  S(   Ni    s   corrupted_zlib_data.mats   corrupted_zlib_checksum.matRb   (	   t   zlibR   R   R   R   R   R   R   R  (   RH  t   excR   R   R@  (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_corrupted_datas  s    c          C` sA   t  t t d  d  # }  t |  d t } | j   Wd  QXd  S(   Ns   corrupted_zlib_data.matRb   t    verify_compressed_data_integrity(   R   R   R   R   Rn   R  (   R   R@  (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt)   test_corrupted_data_check_can_be_disabled|  s    c          C` s   x d D] }  t  t t |   d  } t |  } | j   } | j   t | d t j d g d g g d t	  t | d t j d	 d
 g d
 d g g d t j
  q Wd  S(   Ns   big_endian.mats   little_endian.matRb   t   stringst   hellot   worldR(   t   floatsg       @g      @g      @(   s   big_endian.mats   little_endian.mat(   R   R   R   R   R  R   R   R"   R   R`   t   float32(   R   R   R@  R   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_read_both_endian  s    


c          C` s   t  j d d g d d g g  }  t  j d  j d  } t  j d d g d	 d
 } t   } t | i |  j   j   d 6| j   j   d 6| j   j   d 6 t |  } | j	   } t
 | d |   t
 | d |  t
 | d |  | j   d  S(   Ng       @g      @g      @i   i   i   RN  RO  R(   R  RP  t   intst   uni_arr(   i   i   (   R"   R   R   R  R   R   t   byteswapt   newbyteorderR   R  R   R   (   t	   float_arrt   int_arrRT  R   R@  R   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_write_opposite_endian  s    	c          C` s   t  t t d  d  % }  t |  d t } | j   } Wd  QXt j t g t g g d t j	 } t
 | d |  t | d j | j  d  S(   Ns   testbool_8_WIN64.matRb   t	   mat_dtypeR(   Rg   (   R   R   R   R   Rk   R  R"   R   Rn   R   R   R   R(   (   t   fobjR@  R   R_   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_logical_array  s    $c          C` s   t    }  t j t t t g  } t |  i | d 6 |  j d  t |   } | j   | j	   | j
   \ } } t | j t j  t | j t  | j | t  } t | j j t j  d  S(   Nt   barrayi    (   R   R"   R   Rn   Rk   R   R   R   t   initialize_readt   read_file_headert   read_var_headerR   t   mclasst   mio5pt   mxUINT8_CLASSt
   is_logicalt   read_var_arrayR(   Rj   t   uint8(   R   t   barrt   readert   hdrt   _t   var(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_logical_out_type  s    	

c          C` sE   t    }  t j d  j d  } t t t |  i | d 6t d  d  S(   Ni   i   i   i   R;   R   (   i   i   i   (   R   R"   R   R  R   R   R   Rk   (   R   R&   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_mat4_3d  s    	c          C` s   t  t d  }  t |  d  } t |  } | j   } | j   t t | d t   t	   } t
 |  } t t | j |  d  S(   Ns   testfunc_7.4_GLNX86.matRb   t   testfunc(   R   R   R   R   R  R   R   Rz   R   R   R   R   R   R   (   t   func_egR   R@  R   R   R   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_func_read  s    
	c          c` s   t  t d  }  t |  d  } t | d t } | j   } | j   t | d j j	 d f Vt |  d  } t | d t
 } | j   } | j   t | d j j	 d f Vd  S(   Ns   testmatrix_6.1_SOL2.matRb   RZ  R4   R   R   (   R   R   R   R   Rn   R  R   R   R(   t   kindRk   (   t	   double_egR   R@  R   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_mat_dtype  s    

c          c` s{   i t  j t j d   d 6}  t   } t | i |  d 6 t | d t } t | d d d j	   t j d  f Vd  S(   Ni   t   sparsefieldR;   R   i    (   i    i    (
   Rw   t
   coo_matrixR"   t   eyeR   R   R   Rk   R   Ry   (   t   stR   R   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_sparse_in_struct  s
    	c          C` s_   t    }  i i d d 6d d 6d 6} t |  |  t |  d t } t |  d t d t } d  S(   Ni   RS   i   RT   Rw  R   R6  (   R   R   R   Rn   Rk   (   R   t   in_dt   out_d(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_mat_struct_squeeze  s    		c          C` s   t    }  i d g g d 6d d 6i d d 6d d 6d	 6} t |  |  t |  d
 t } t t | d t   t t | d t   t t | d	 t j	   d  S(   Ng?t   scalars   my nameR.   i   RS   i   RT   Rw  R6  (
   R   R   R   Rk   R   Rz   t   floatR
   R"   Rl   (   R   Ry  Rz  (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_scalar_squeeze  s    	/c       	   C` sP  t    }  t j d d g  } t j d d g  } t |  t d |   t |   } t | d |  |  j d  |  j d  | j	 d d  } t j
 d t j d	 | j d d d
 |  } t |  t d |   t | d |  |  j d  |  j d  | j d  } | j d  } t |  i | d 6 t |   } t | d |  d  S(   NR   t   Foobs   Foob R;   i    t   ordert   FR#   R(   t   bufferR  (   R   R"   R   R   R   R   R   R   R   t   tostringRl   R;   R#   R(   t   astype(   R   t   in_arrt   out_arrR"  t   in_strt   in_from_strt   in_arr_ut	   out_arr_u(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_str_round  s,    			c          C` sd   t    }  t |  i i d d 6d d 6d 6 t |   } | d j j } t t |  t d   d  S(   Ni   R;   i   R   (   R;   R   (   R   R   R   R(   R   R   R   (   R   R"  t   field_names(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_fieldnames   s
    	"c          C` s  d d d g }  xt  t d  g  f t  t d  |  f f D]\ } } t |  } t t | j    t d d g |   t | d d } t t | j    t d g |   t | d d g } t t | j    t d g |   t | d d g } t t | j    t d g |   t | d d	 } t t | j    t d g |   t | d g  } t t | j    t |   d g } t | d | } t | d g  q: Wd  S(
   Nt   __globals__t
   __header__t   __version__s   testmulti_4.2c_SOL2.mats   testmulti_7.4_GLNX86.matR;   R:   t   variable_names(   s   theta(   R   R   R   R   R   t   keys(   t   mat5_sys_namest   eg_filet   sys_v_namest   varst   vnames(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_loadmat_varnames)  s*    	)&&&&	c          C` s   t  j d  }  t   } xn d D]f } | j d  | j d  t | i |  j |  d 6 t |  } t t  j	 |  | d j	  q Wd  S(   Ni
   R(  t   f4t   i8t   i4t   i2t   i1t   u8t   u4t   u2t   u1t   c16t   c8i    R&   (   s   f8R  s   i8s   i4R  R  s   u8R  s   u2s   u1R  R  (
   R"   R   R   R   R   R   R  R   R   R(   (   R&   R   t   dtsR  (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_round_typesB  s    	
c    	      ` s   d t  t j d   f d t  d  f d t  d  f f   d t f   f d     Y}  t   } t | |     t |  } t t |  d  x^ t	 d  D]P } | | \ } }   | \ } } t | |  t
 |  } t | | |  q Wd  S(	   NR&   i
   t   mystrs   a stringt   mynumR  c           ` s   e  Z   f d    Z RS(   c         ` s     S(   N(    (   t   self(   t
   names_vars(    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyR   W  s    (   R  R  R   (    (   R  (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyR  V  s   i   (   R'   R"   R   R`   R   R   R   R   R   t   rangeR   R   (	   R  R   t   varmatsR   R*   t
   var_streamt   exp_namet   exp_resR"  (    (   R  s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_varmats_from_matO  s    	c          C` sX   t  t d  }  t |  d  } t |  } | j   } | j   t | d j d  d  S(   Ns   one_by_zero_char.matRb   Rk  i    (   i    (   R   R   R   R   R  R   R   R#   (   Ro  R   R@  R   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_one_by_zeroe  s    
c          C` s9   t  t d  }  t |   } t | d d d g g  d  S(   Ns   test_mat4_le_floats.matR;   g?g333333?(   R   R   R   R   (   t
   mat4_fnameR  (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_load_mat4_leo  s    c          C` sT   t    }  i t d  d 6} t |  | d d t |   } t | d | d  d  S(   Ns   Schrödingert
   second_catR   R   (   R   R   R   R   R   (   t   bioRk  t   var_back(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_unicode_mat4w  s
    	c       
   C` s   t  t d  }  t |  d t } | d } t t | t j   t | j	 j
 t j  t | j   t t t t g t t t t g t t t t g t t t t g t t t t g g  d  S(   Ns   logical_sparse.matR   t
   sp_log_5_4(   R   R   R   Rk   R   Rz   Rw   R   R   R(   Rj   R"   R   R   t   toarrayRn   (   R   R   t   log_sp(    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_logical_sparse  s    
c          C` s   t    }  d d  l } | j j d d g d d g g  } t |  t d |   |  j d  t |   } t | d j	 | j	  t | d j
   d  |  j d  t |   } | j   | j   | j   \ } } t | j d  d  S(   Ni    R_   i   (   R   t   scipy.sparseR5   t
   csr_matrixR   R   R   R   R   R#   Ry   R   R^  R_  R`  R   t   nzmax(   R   t   scipyt   empty_sparseR"  Rh  Ri  Rj  (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_empty_sparse  s    	$

c          C` s   t    }  t t t |   d  S(   N(   R   R   R   R   (   R   (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_empty_mat_error  s    	c          C` s   t  t d  }  t |   } t | d t j d  d  d  d   f  t  t d  }  t j d t	   t
 t t |   Wd  QXd  S(   Ns   miuint32_for_miint32.matt   an_arrayi
   s   bad_miuint32.matt   record(   R   R   R   R   R"   R   R   R   R   Rk   R   R   (   R   R"  (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_miuint32_compromise  s    *c          C` sn   t  t d  }  t |   } t | d d g g  t  t d  }  t j d t   t t t |   Wd  QXd  S(   Ns   miutf8_array_name.matt
   array_namei   s   bad_miutf8_array_name.matR  (	   R   R   R   R   R   R   Rk   R   R   (   R   R"  (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt!   test_miutf8_for_miint8_compromise  s    c          C` s<   t  t d  }  t |   } t | d d j d d   d  S(   Ns   broken_utf8.matt
   bad_strings    am brokent   utf8t   replace(   R   R   R   R   t   decode(   R   R"  (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   test_bad_utf8  s    
t   __main__(   i   i   (   i    i    (   i    i    (   i   i   (   i    i    (   i   i   i   (   i   i   (   i    i    (   i    i    y      ?      ?(   i    i    (   i   i   (   i    i    (   i   i   (   i    i   (   i    i   (   i    i    (   i    i   (   i    i   (   i   i   (   i    i   (   i    i   (   i    i   (   i    i   (   i    i    (   i    i   (   i    i   (   i    i   (   i   i   (   i    i    (   i   i   (   i    i    (   i    i    (   i    i    (   i   i   (   i    i    (   i    i    (   i    i   (   i    i   (   i   i   (   i    i    (   t   __doc__t
   __future__R    R   R   R   t   os.pathR   R   R   R   t   ioR   t   tempfileR   t   scipy._lib.sixR   R	   R
   R   R   R   t   numpy.testingR   R   R   R   R   R   t   numpyR"   R   R  R5   Rw   t   scipy.io.matlab.byteordercodest   matlabt   byteordercodesR:  t   scipy.io.matlab.miobaseR   R   R   t   scipy.io.matlab.mioR   R   R   R   t   scipy.io.matlab.mio5R   R   R   R   R   R   R   t   scipy.io.matlabR    Rb  t   __file__R   R'   t   piR   R}  R  R:   R   R   t   cost   sinR   R  R?  R  Ru  R  R1   t   BR`   t   CAR   t   CAEt   emptyt   objarrt	   transposet   sqrtt   expt
   st_sub_arrt   nR(   R   t   CNRf  t   st2R;   t   ODTt   MOt   m0R   t   fp_u_strt   readR  t   u_strR   Rk   Rn   R   t   repeatRs   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  R  R  R&  R1  R5  RD  RG  RJ  RL  RR  RY  R\  Rl  Rm  Rp  Rs  Rx  R{  R~  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  (    (    (    s=   /tmp/pip-build-7oUkmx/scipy/scipy/io/matlab/tests/test_mio.pyt   <module>   s  ."4	,


,%





!0
				$


-
36(
#!!
4&%
4
		(






!
*		/	
																											?			#												
		
							
									