Ñò
pXJc           @   s’  d  Z  d d k Z d d k Z d d k l Z d d k Z d e f d „  ƒ  YZ	 h
 d d 6d d	 6d
 d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6Z
 e i e
 ƒ Z d „  Z d „  Z d e f d „  ƒ  YZ	 d d „ Z d e f d  „  ƒ  YZ e i d! ƒ e ƒ Z d" e f d# „  ƒ  YZ d$ e f d% „  ƒ  YZ d& e f d' „  ƒ  YZ d( e f d) „  ƒ  YZ d* e f d+ „  ƒ  YZ d, e f d- „  ƒ  YZ d S(.   s2   
Base classes for matlab (TM) file stream reading
iÿÿÿÿN(   t   doccert   MatReadErrorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyR      s    s  file_name : string
   Name of the mat file (do not need .mat extension if
   appendmat==True) If name not a full path name, search for the
   file on the sys.path list and use the first one found (the
   current directory is searched first).  Can also pass open
   file-like objectt   file_argsƒ   appendmat : {True, False} optional
   True to append the .mat extension to the end of the given
   filename, if not already presentt
   append_args¼   base_name : string, optional, unused
   base name for unnamed variables.  The code no longer uses
   this.  We deprecate for this version of scipy, and will remove
   it in future versionst   basename_args³  byte_order : {None, string}, optional
   None by default, implying byte order guessed from mat
   file. Otherwise can be one of ('native', '=', 'little', '<',
   'BIG', '>')
mat_dtype : {False, True} optional
   If True, return arrays in same dtype as would be loaded into
   matlab (instead of the dtype with which they are saved)
squeeze_me : {False, True} optional
   whether to squeeze unit matrix dimensions or not
chars_as_strings : {True, False} optional
   whether to convert char arrays to string arrays
matlab_compatible : {False, True}
   returns matrices as would be loaded by matlab (implies
   squeeze_me=False, chars_as_strings=False, mat_dtype=True,
   struct_as_record=True)t	   load_argss“  struct_as_record : {False, True} optional
   Whether to load matlab structs as numpy record arrays, or as
   old-style numpy arrays with dtype=object.  Setting this flag to
   False replicates the behaviour of scipy version 0.6 (returning
   numpy object arrays).  The preferred setting is True, because it
   allows easier round-trip load and save of matlab files.  In a
   future version of scipy, we will change the default setting to
   True, and following versions may remove this flag entirely.  For
   now, we set the default to False, for backwards compatibility, but
   issue a warning.  Note that non-record arrays cannot be exported
   via savemat.t
   struct_args@   mat_stream : file-like
   object with file API, open for readingt   matstream_args  long_field_names : boolean, optional, default=False
   * False - maximum field name length in a structure is 31 characters
     which is the documented maximum length
   * True - maximum field name length in a structure is 63 characters
     which works for Matlab 7.6t   long_fieldssh   do_compression : {False, True} bool, optional
   Whether to compress matrices on write. Default is Falset   do_compressions–   oned_as : {'column', 'row'} string, optional
   If 'column', write 1D numpy arrays as column vectors
   If 'row', write 1D numpy arrays as row vectorst   oned_assr   unicode_strings : {True, False} boolean, optional
   If True, write strings as Unicode, else matlab usual encodingt   unicode_stringsc         C   s%   d } x |  D] } | | 9} q W| S(   s&    Faster than product for small arrays i   (    (   t   arrt   rest   e(    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt   small_productT   s
     c         C   së   |  i  d ƒ t i d d d t i d |  i d ƒ ƒ } d | j o |  i  d ƒ d S|  i  d ƒ |  i d ƒ } |  i  d ƒ t | d d j ƒ } t | | ƒ } t | d	 | ƒ } | | f } | d j o | St d
 | ƒ ‚ d S(   sV   Return major, minor tuple depending on apparent mat file type

    Where:

     #. 0,x -> version 4 format mat files
     #. 1,x -> version 5 format mat files
     #. 2,x -> version 7.3 format mat files (HDF format)

    Parameters
    ----------
    fileobj : {file-like}
              object implementing seek() and read()

    Returns
    -------
    major_version : {0, 1, 2}
                    major matlab file format version
    minor_version : int
                    major matlab file format version

    Notes
    -----
    Has the side effect of setting the file read pointer to 0
    i    t   shapei   t   dtypet   bufferi|   i   t   Ii   s%   Unknown mat file type, version %s, %sN(   i   (   i    i    (   i   i   (   t   seekt   npt   ndarrayt   uint8t   readt   intt   ordt
   ValueError(   t   fileobjt
   mopt_bytest   tst_strt   maj_indt   maj_valt   min_valt   ret(    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt   get_matfile_version\   s$    	c           B   s   e  Z RS(    (   R   R   (    (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyR      s    t   columnc         C   s   |  i  d j o d t i |  i d g ƒ S|  i } | d j o d	 St | ƒ d j o@ | d j o	 | d
 S| d j o	 d | St d | ƒ ‚ n | S(   sü   Determine equivalent matlab dimensions for given array 
    
    Parameters
    ----------
    arr : ndarray
    oned_as : {'column', 'row'} string, optional

    Returns
    -------
    dims : shape as matlab expects

    Examples
    --------
    >>> matdims(np.array(1)) # numpy scalar
    (1, 1)
    >>> matdims(np.array([1])) # 1d array, 1 element
    (1, 1)
    >>> matdims(np.array([1,2])) # 1d array, 2 elements
    (2, 1)
    >>> matdims(np.array([[2],[3]])) # 2d array, column vector
    (2, 1)
    >>> matdims(np.array([[2,3]])) # 2d array, row vector
    (1, 2)
    >>> matdims(np.array([[[2,3]]])) # 3d array, rowish vector
    (1, 1, 2)
    >>> matdims(np.array([])) # empty 1d array
    (0, 0)
    >>> matdims(np.array([[]])) # empty 2d
    (0, 0)
    >>> matdims(np.array([[[]]])) # empty 3d
    (0, 0, 0)

    Optional argument flips 1d shape behavior

    >>> matdims(np.array([1,2]), 'row') # 1d array, 2 elements
    (1, 2)

    The argument has to make sense though

    >>> matdims(np.array([1,2]), 'bizarre')
    Traceback (most recent call last):
       ...
    ValueError: 1D option "bizarre" is strange

    Notes
    -----
    We had to decide what shape a 1 dimensional array would be by
    default.  ``np.atleast_2d`` thinks it is a row vector.  The
    default for a vector in matlab (e.g. ``>> 1:12``) is a row vector.

    Versions of scipy up to and including 0.7 resulted (accidentally)
    in 1d arrays being read as column vectors.  For the moment, we
    maintain the same tradition here.
    i    i   i   R&   t   rows   1D option "%s" is strange(   i    (    (   i   i   (   i   (   i   (   t   sizeR   t   maxt   ndimR   t   lenR   (   R   R   R   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt   matdims’   s    7			t	   ByteOrderc           B   s2   e  Z d  Z e i Z e i Z e i Z e i Z RS(   s    Namespace for byte ordering (	   R   R   t   __doc__t   boct	   sys_is_let   little_endiant   native_codet   swapped_codet   to_numpy_code(    (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyR-   Ù   s
   			s§   
We no longer use the ByteOrder class, and deprecate it; we will remove
it in future versions of scipy.  Please use the
scipy.io.matlab.byteordercodes module instead.
t   MatStreamAgentc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sÁ   Base object for readers / getters from mat file streams

    Attaches to initialized stream

    Base class for "getters" - which do store state of what they are
    reading on initialization, and therefore need to be initialized
    before each read, and "readers" which do not store state, and only
    need to be initialized once on object creation

    Implements common array reading functions

    Inputs mat_steam - MatFileReader object
    c         C   s   | |  _  d  S(   N(   t
   mat_stream(   t   selfR6   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt   __init__ö   s    c      	   C   s=   | i  } t i d d d | d |  i i | ƒ d d ƒ } | S(   s¡    Generic get of byte stream data of known type

        Inputs
        a_dtype     - dtype of array

        a_dtype is assumed to be correct endianness
        R   R   R   t   ordert   F(    (   t   itemsizeR   R   R6   R   (   R7   t   a_dtypet	   num_bytesR   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt
   read_dtypeù   s    		c         C   s   |  i  i | ƒ i d ƒ S(   Nt    (   R6   R   t   strip(   R7   R=   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt   read_ztstring  s    (   R   R   R.   R8   R>   RA   (    (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyR5   ç   s   		t   MatFileReaderc           B   s(  e  Z d  Z e d e e e e d d „ ƒ Z d „  Z d „  Z	 d „  Z
 e e	 e
 d d ƒ Z d „  Z d „  Z e e e d d ƒ Z d	 „  Z d
 „  Z e e e d d ƒ Z d „  Z d „  Z e e e d d ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z RS(   sP   Base object for reading mat files

    To make this class functional, you will need to override the
    following methods:

    set_dtypes              - sets data types defs from byte order
    matrix_getter_factory   - gives object to fetch next matrix from stream
    guess_byte_order        - guesses file byte order from file
    c         C   su   | |  _  h  |  _ | p |  i ƒ  } n | |  _ | o |  i ƒ  n+ | |  _ | |  _ | |  _ |  i ƒ  |  _	 d S(   s–   
        Initializer for mat file reader

        mat_stream : file-like
            object with file API, open for reading
    %(load_args)s
        N(
   R6   t   dtypest   guess_byte_ordert
   order_codet   set_matlab_compatiblet   _squeeze_met   _chars_as_stringst
   _mat_dtypet   get_processor_funct   processor_func(   R7   R6   t
   byte_ordert	   mat_dtypet
   squeeze_met   chars_as_stringst   matlab_compatiblet   struct_as_record(    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyR8     s    						c         C   s.   t  |  _ t |  _ t |  _ |  i ƒ  |  _ d S(   s9    Sets options to return arrays as matlab (tm) loads them N(   t   TrueRI   t   FalseRG   RH   RJ   RK   (   R7   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyRF   5  s    			c         C   s   |  i  S(   N(   RI   (   R7   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt   get_mat_dtype<  s    c         C   s   | |  _  |  i ƒ  |  _ d  S(   N(   RI   RJ   RK   (   R7   RM   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt   set_mat_dtype>  s    	s   get/set mat_dtype propertyc         C   s   |  i  S(   N(   RG   (   R7   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt   get_squeeze_meF  s    c         C   s   | |  _  |  i ƒ  |  _ d  S(   N(   RG   RJ   RK   (   R7   RN   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt   set_squeeze_meH  s    	s   get/set squeeze me propertyc         C   s   |  i  S(   N(   RH   (   R7   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt   get_chars_as_stringsP  s    c         C   s   | |  _  |  i ƒ  |  _ d  S(   N(   RH   RJ   RK   (   R7   RO   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt   set_chars_as_stringsR  s    	s!   get/set chars_as_strings propertyc         C   s   |  i  S(   N(   t   _order_code(   R7   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt   get_order_codeZ  s    c         C   s&   t  i | ƒ } | |  _ |  i ƒ  d  S(   N(   R/   R4   RZ   t
   set_dtypes(   R7   RE   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt   set_order_code\  s    	s   get/set order codec         C   s   d S(   s6    Set dtype endianness. In this case we have no dtypes N(    (   R7   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyR\   e  s    c         C   sD   | i  ƒ  } x1 | D]) } t i | | ƒ i |  i ƒ | | <q W| S(   N(   t   copyR   R   t   newbyteorderRE   (   R7   t   dtype_templateRC   t   k(    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt   convert_dtypesi  s
     'c         C   s   t  p
 t d ‚ d  S(   Ns   Not implemented(   RS   t   AssertionError(   R7   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt   matrix_getter_factoryo  s    c         C   s   h  S(   N(    (   R7   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt   file_headerr  s    c         C   s   t  i S(   s9    As we do not know what file type we have, assume native (   R-   R2   (   R7   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyRD   u  s    c            s   ‡  f d †  } | S(   s   Processing to apply to read matrices

        Function applies options to matrices. We have to pass this
        function into the reader routines because Mat5 matrices
        occur as submatrices - in cell arrays, structs and objects -
        so we will not see these in the main variable getting routine
        here.

        The read array is the first argument.
        The getter, passed as second argument to the function, must
        define properties, iff mat_dtype option is True:

        mat_dtype    - data type when loaded into matlab (tm)
                       (None for no conversion)

        func returns the processed array
        c            s  |  i  i d j oÔ ˆ  i oÊ |  i } t | ƒ d j o› | d  } | d } |  i t | ƒ | f ƒ } d | o | p d } t i | d | ƒ}  xK t	 d | d ƒ D]# } ˆ  i
 | | ƒ |  d | f <q© Wqç ˆ  i
 |  ƒ }  n ˆ  i o* | i d  j	 o |  i | i ƒ }  qn ˆ  i oX t i |  ƒ }  |  i p t i g  ƒ }  q}|  i o |  i  i o |  i ƒ  }  q}n |  S(	   Nt   Ui   iÿÿÿÿs   U%di   R   i    .(   R   t   kindRO   R   R+   t   reshapeR   R   t   emptyt   ranget   chars_to_strRM   t   Nonet   astypeRN   t   squeezeR(   t   arrayt	   isbuiltint   item(   R   t   gettert   dimst   n_dimst   last_dimt   str_arrt   dtstrt   i(   R7   (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt   funcŒ  s0    	

	 %


(    (   R7   Ry   (    (   R7   sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyRJ   y  s    c         C   sJ   t  i d t t | i ƒ ƒ ƒ } t  i d d d | d | i ƒ  ƒ i ƒ  S(   s     Convert string array to string Rf   R   R   R   (    (   R   R   t   strR   R   R   R^   Rq   (   R7   Rv   t   dt(    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyRk   ª  s    "c         C   s?  t  | t ƒ o | g } n |  i i d ƒ |  i ƒ  } g  | d <xõ |  i ƒ  pç |  i ƒ  } | i } | o | | j o | i ƒ  qF n y | i	 ƒ  } WnI t
 j
 o= } t i d | | f t d d ƒd | } | i ƒ  n X| | | <| i o | d i | ƒ n | o | i | ƒ | p Pq6qF qF W| S(   s·    get variables from stream as dictionary

        variable_names   - optional list of variable names to get

        If variable_names is None, then get all variables in file
        i    t   __globals__s&   Unreadable variable "%s", because "%s"t
   stackleveli   s   Read error: %s(   t
   isinstancet
   basestringR6   R   Re   t   end_of_streamRd   t   namet   to_nextt	   get_arrayR   t   warningst   warnt   Warningt	   is_globalt   appendt   remove(   R7   t   variable_namest   mdictRr   R   R   t   err(    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt   get_variables±  s:    
 	




c         C   sE   |  i  i d ƒ } |  i  i ƒ  } |  i  i | d ƒ t | ƒ d j S(   Ni   i    (   R6   R   t   tellR   R+   (   R7   t   bt   curpos(    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyR€   Õ  s    N(   R   R   R.   t	   docfillerRl   RS   RR   R8   RF   RT   RU   t   propertyRM   RV   RW   RN   RX   RY   RO   R[   R]   RE   R\   Rb   Rd   Re   RD   RJ   Rk   R   R€   (    (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyRB     sT   																				1	$t   MatMatrixGetterc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   sŽ   Base class for matrix getters

    Getters are stateful versions of agents, and record state of
    current read on initialization, so need to be created for each
    read - one-shot objects.

    MatrixGetters are initialized with the content of the matrix
    header

    Accepts
    array_reader - array reading object (see below)
    header       - header dictionary for matrix being read
    c         C   sH   t  t |  ƒ i | i ƒ | |  _ | i |  _ | |  _ | d |  _ d  S(   NR   (   t   superR“   R8   R6   t   array_readerRC   t   headerR   (   R7   R•   R–   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyR8   ë  s
    		c         C   s   |  i  ƒ  } |  i i | |  ƒ S(   sA    Gets an array from matrix, and applies any necessary processing (   t   get_raw_arrayR•   RK   (   R7   R   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyRƒ   ò  s    c         C   s   t  p
 t d ‚ d  S(   Ns   Not implemented(   RS   Rc   (   R7   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyR—   ÷  s    c         C   s   |  i  i |  i ƒ d  S(   N(   R6   R   t   next_position(   R7   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyR‚   ú  s    (   R   R   R.   R8   Rƒ   R—   R‚   (    (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyR“   Ü  s
   			t   MatArrayReaderc           B   s    e  Z d  Z d „  Z d „  Z RS(   s   Base class for array readers

    The array_reader contains information about the current reading
    process, such as byte ordered dtypes and the processing function
    to apply to matrices as they are read, as well as routines for
    reading matrix compenents.
    c         C   s   | |  _  | |  _ | |  _ d  S(   N(   R6   RC   RK   (   R7   R6   RC   RK   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyR8     s    		c         C   s   t  p
 t d ‚ d  S(   Ns   Not implemented(   RS   Rc   (   R7   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyRd     s    (   R   R   R.   R8   Rd   (    (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyR™   þ  s   	t   MatStreamWriterc           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s&    Base object for writing to mat files c         C   s`   | |  _  | |  _ |  i i } | i p" |  i i | i d ƒ ƒ |  _ n | |  _ | |  _ d  S(   Nt   =(   t   file_streamR   R   t   isnativeRm   R_   R   R   (   R7   Rœ   R   R   R   R{   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyR8     s    		
"	c         C   s   |  i  i d ƒ d  S(   Ni    (   Rœ   R   (   R7   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt   rewind  s    c         C   s$   t  i |  i i i d  t | ƒ ƒ S(   s3    Return dtype for given number of items per elementi   (   R   R   R   Rz   (   R7   t   num(    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt   arr_dtype_number  s    c         C   sw   t  |  i i ƒ } | p d g } n | i t |  i i i d ƒ ƒ t i d | d |  i	 d ƒ d |  i ƒ |  _ d S(   s$    Convert string array to char array i   i   R   R   R   N(
   t   listR   R   Rˆ   R   R   Rz   R   R   R    (   R7   Rs   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt   arr_to_chars"  s     c         C   s    |  i  i | i d d ƒ ƒ d  S(   NR9   R:   (   Rœ   t   writet   tostring(   R7   R   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt   write_bytes,  s    c         C   s   |  i  i | ƒ d  S(   N(   Rœ   R£   (   R7   t   s(    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt   write_string/  s    (	   R   R   R.   R8   Rž   R    R¢   R¥   R§   (    (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyRš     s   					
	t   MatFileWriterc           B   s   e  Z d  Z d „  Z RS(   s!    Base class for Mat file writers c         C   s   | |  _  d  S(   N(   Rœ   (   R7   Rœ   (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyR8   5  s    (   R   R   R.   R8   (    (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyR¨   3  s   (   R.   R„   t   numpyR   t   scipy.ndimageR    t   byteordercodesR/   t	   ExceptionR   t   doc_dictt   filldocR‘   R   R%   R,   t   objectR-   t   deprecate_with_docR5   RB   R“   R™   Rš   R¨   (    (    (    sG   P:\graphics\Tools\Python26\lib\site-packages\scipy\io\matlab\miobase.pyt   <module>   s<   
		3G%Ð"#