§
    fŠtj.3  ã            
       ób  — U d Z ddlmZ ddlZddlmZ ddlmZ	 g d¢Z
 G d„ d	e¦  «        Z G d
„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Zddddddddddœ	Z ej        e¦  «        Zeed<   	 d„ Zd„ Zddœd„ZeZd Zd!„ Zd*d#„Z G d$„ d%¦  «        Z G d&„ d'¦  «        Zd(„ Zd)„ ZdS )+zf
Base classes for MATLAB file stream reading.

MATLAB is a registered trademark of the Mathworks inc.
é    )ÚFinalN)Údocceré   )Ú_byteordercodes)ÚMatReadErrorÚMatReadWarningÚMatWriteErrorÚMatWriteWarningc                   ó   — e Zd ZdZdS )r   z"Exception indicating a read issue.N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    úV/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/scipy/io/matlab/_miobase.pyr   r      s   € € € € € Ø,Ð,Ð,Ð,r   r   c                   ó   — e Zd ZdZdS )r	   z#Exception indicating a write issue.Nr   r   r   r   r	   r	      s   € € € € € Ø-Ð-Ð-Ð-r   r	   c                   ó   — e Zd ZdZdS )r   zWarning class for read issues.Nr   r   r   r   r   r      s   € € € € € Ø(Ð(Ð(Ð(r   r   c                   ó   — e Zd ZdZdS )r
   zWarning class for write issues.Nr   r   r   r   r
   r
      s   € € € € € Ø)Ð)Ð)Ð)r   r
   zfile_name : str
   Name of the mat file (do not need .mat extension if
   appendmat==True) Can also pass open file-like object.z�appendmat : bool, optional
   True to append the .mat extension to the end of the given
   filename, if not already present. Default is True.až  byte_order : str or None, optional
   None by default, implying byte order guessed from mat
   file. Otherwise can be one of ('native', '=', 'little', '<',
   'BIG', '>').
mat_dtype : bool, 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 : bool, optional
   Whether to squeeze unit matrix dimensions or not.
chars_as_strings : bool, optional
   Whether to convert char arrays to string arrays.
matlab_compatible : bool, optional
   Returns matrices as would be loaded by MATLAB (implies
   squeeze_me=False, chars_as_strings=False, mat_dtype=True,
   struct_as_record=True).ab  struct_as_record : bool, 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 behavior of SciPy version 0.7.x (returning
   numpy object arrays). The default setting is True, because it
   allows easier round-trip load and save of MATLAB files.zAmat_stream : file-like
   Object with file API, open for reading.a  long_field_names : bool, optional
   * False - maximum field name length in a structure is 31 characters
     which is the documented maximum length. This is the default.
   * True - maximum field name length in a structure is 63 characters
     which works for MATLAB 7.6z[do_compression : bool, optional
   Whether to compress matrices on write. Default is False.z’oned_as : {'row', 'column'}, optional
   If 'column', write 1-D NumPy arrays as column vectors.
   If 'row', write 1D NumPy arrays as row vectors.zbunicode_strings : bool, optional
   If True, write strings as Unicode, else MATLAB usual encoding.)	Úfile_argÚ
append_argÚ	load_argsÚ
struct_argÚmatstream_argÚlong_fieldsÚdo_compressionÚoned_asÚunicode_stringsÚ	docfillerc                 ó˜   — |                       ¦   «         }|D ]2}t          j        ||         ¦  «                             |¦  «        ||<   Œ3|S )až   Convert dtypes in mapping to given order

    Parameters
    ----------
    dtype_template : mapping
       mapping with values returning numpy dtype from ``np.dtype(val)``
    order_code : str
       an order code suitable for using in ``dtype.newbyteorder()``

    Returns
    -------
    dtypes : mapping
       mapping where values have been replaced by
       ``np.dtype(val).newbyteorder(order_code)``

    )ÚcopyÚnpÚdtypeÚnewbyteorder)Údtype_templateÚ
order_codeÚdtypesÚks       r   Úconvert_dtypesr*   †   sR   € ð" × Ò Ñ"Ô"€FØð Að AˆÝ”H˜V AœYÑ'Ô'×4Ò4°ZÑ@Ô@ˆˆq‰	ˆ	Ø€Mr   c                 ój   — |j         }t          j        d||                      |¦  «        d¬¦  «        }|S )af  
    Generic get of byte stream data of known type

    Parameters
    ----------
    mat_stream : file_like object
        MATLAB (tm) mat file stream
    a_dtype : dtype
        dtype of array to read. `a_dtype` is assumed to be correct
        endianness.

    Returns
    -------
    arr : ndarray
        Array of dtype `a_dtype` read from stream.

    r   ÚF)Úshaper$   ÚbufferÚorder)Úitemsizer#   ÚndarrayÚread)Ú
mat_streamÚa_dtypeÚ	num_bytesÚarrs       r   Ú
read_dtyper7   �   s@   € ð$ Ô €IÝ
Œ*˜2Ø"Ø&ŸOšO¨IÑ6Ô6Øð ñ  ô  €Cð €Jr   T©Ú	appendmatc                óz   — ddl m}  || |¬¦  «        5 }t          |¦  «        cddd¦  «         S # 1 swxY w Y   dS )a˜  
    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
    ----------
    file_name : str
       Name of the mat file (do not need .mat extension if
       appendmat==True). Can also pass open file-like object.
    appendmat : bool, optional
       True to append the .mat extension to the end of the given
       filename, if not already present. Default is True.

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

    Raises
    ------
    MatReadError
        If the file is empty.
    ValueError
        The matfile version is unknown.

    Notes
    -----
    Has the side effect of setting the file read pointer to 0
    r   )Ú_open_file_contextr8   N)Ú_mior;   Ú_get_matfile_version)Ú	file_namer9   r;   Úfileobjs       r   Úmatfile_versionr@   ·   s™   € ðJ )Ð(Ð(Ð(Ð(Ð(Ø	Ð	˜I°Ð	;Ñ	;Ô	;ð -¸wÝ# GÑ,Ô,ð-ð -ð -ð -ñ -ô -ð -ð -ð -ð -ð -ð -øøøð -ð -ð -ð -ð -ð -s   ”0°4·4é   c                 óî  — |                       d¦  «         |                      t          ¦  «        }t          |¦  «        t          k     rt	          d¦  «        ‚|                     d¦  «        t          k    rt	          dt          › d�¦  «        ‚t          j        dt          j        |d d…         ¬¦  «        }d|v r|                       d¦  «         dS |                       d	¦  «         |                      d¦  «        }|                       d¦  «         t          |d
         dk    ¦  «        }t          ||         ¦  «        }t          |d|z
           ¦  «        }||f}|dv r|S t           dj        |Ž ¦  «        ‚)Nr   z Mat file appears to be truncatedz&Mat file appears to be corrupt (first z bytes == 0))é   rC   ©r-   r$   r.   ©r   r   é|   é   éI   r   )r   rG   z%Unknown mat file type, version {}, {})Úseekr2   Ú_HDR_N_BYTESÚlenr   Úcountr#   r1   Úuint8ÚintÚ
ValueErrorÚformat)r?   Ú	hdr_bytesÚ	mopt_intsÚtst_strÚmaj_indÚmaj_valÚmin_valÚrets           r   r=   r=   ç   sj  € à‡L‚L��O„O€OØ—’�\Ñ*Ô*€IÝ
ˆ9�~„~�Ò$Ð$ÝÐ=Ñ>Ô>Ð>Ø‡‚�qÑÔ�\Ò)Ð)Ýð @Ý%1ð@ð @ð @ñ Aô Að 	Aå”
 ­R¬X¸iÈÈÈ¼mÐLÑLÔL€IØˆI€~€~Ø�Š�Q‰ŒˆØˆuð ‡L‚L�ÑÔÐØ�lŠl˜1‰oŒo€GØ‡L‚L��O„O€OÝ�'˜!”* Ò'Ñ(Ô(€GÝ�'˜'Ô"Ñ#Ô#€GÝ�'˜!˜g™+Ô&Ñ'Ô'€GØ�GÐ
€CØ�&ÐÐØˆ
Ý
ÐCÐ<ÔCÀSÐIÑ
JÔ
JÐJr   Úcolumnc                 ó¸   — | j         }|dk    rdS t          |¦  «        dk    r7|d         dk    rdS |dk    r|dz   S |dk    rd|z   S t          d	|› d
�¦  «        ‚|S )aú  
    Determine equivalent MATLAB dimensions for given array

    Parameters
    ----------
    arr : ndarray
        Input array
    oned_as : {'column', 'row'}, optional
        Whether 1-D arrays are returned as MATLAB row or column matrices.
        Default is 'column'.

    Returns
    -------
    dims : tuple
        Shape tuple, in the form MATLAB expects it.

    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.11 resulted (accidentally)
    in 1-D arrays being read as column vectors. For the moment, we
    maintain the same tradition here.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.io.matlab._miobase import matdims
    >>> matdims(np.array(1)) # NumPy scalar
    (1, 1)
    >>> matdims(np.array([1])) # 1-D array, 1 element
    (1, 1)
    >>> matdims(np.array([1,2])) # 1-D array, 2 elements
    (2, 1)
    >>> matdims(np.array([[2],[3]])) # 2-D array, column vector
    (2, 1)
    >>> matdims(np.array([[2,3]])) # 2-D array, row vector
    (1, 2)
    >>> matdims(np.array([[[2,3]]])) # 3-D array, rowish vector
    (1, 1, 2)
    >>> matdims(np.array([])) # empty 1-D array
    (0, 0)
    >>> matdims(np.array([[]])) # empty 2-D array
    (0, 0)
    >>> matdims(np.array([[[]]])) # empty 3-D array
    (0, 0, 0)

    Optional argument flips 1-D shape behavior.

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

    The argument has to make sense though

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

    r   )r   r   r   r   rE   rX   )r   Úrowz1-D option "z" is strange)r-   rK   rO   )r6   r   r-   s      r   Úmatdimsr[     s„   € ð~ ŒI€EØ�‚{€{ØˆvÝ
ˆ5�z„z�Q‚€Ø�Œ8�qŠ=ˆ=Ø�6Ø˜Ò Ð Ø˜4‘<ÐØ˜ÒÐØ˜%‘<ÐåÐA¨GÐAÐAÐAÑBÔBÐBØ€Lr   c                   ó$   — e Zd ZdZd„ Zd„ Zd„ ZdS )ÚMatVarReaderz; Abstract class defining required interface for var readersc                 ó   — d S )Nr   )ÚselfÚfile_readers     r   Ú__init__zMatVarReader.__init__S  s   € Øˆr   c                 ó   — dS )z Returns header Nr   ©r_   s    r   Úread_headerzMatVarReader.read_headerV  ó   € àˆr   c                 ó   — dS )z Reads array given header Nr   )r_   Úheaders     r   Úarray_from_headerzMatVarReader.array_from_headerZ  re   r   N)r   r   r   r   ra   rd   rh   r   r   r   r]   r]   Q  sG   € € € € € ØEÐEðð ð ðð ð ðð ð ð ð r   r]   c                   óL   — e Zd ZdZe	 	 	 	 	 	 	 	 d	d„¦   «         Zd„ Zd„ Zd„ ZdS )
ÚMatFileReadera   Base object for reading mat files

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

    matrix_getter_factory   - gives object to fetch next matrix from stream
    guess_byte_order        - guesses file byte order from file
    NFTc
                 ó,  — || _         i | _        |s|                      ¦   «         }nt          j        |¦  «        }|| _        || _        |r|                      ¦   «          n|| _        || _	        || _
        || _        |	| _        |	rd| _        d| _        dS dS )z–
        Initializer for mat file reader

        mat_stream : file-like
            object with file API, open for reading
    %(load_args)s
        TFN)r3   r(   Úguess_byte_orderÚbocÚto_numpy_codeÚ
byte_orderÚstruct_as_recordÚset_matlab_compatibleÚ
squeeze_meÚchars_as_stringsÚ	mat_dtypeÚ verify_compressed_data_integrityÚsimplify_cells)
r_   r3   ro   rt   rr   rs   Úmatlab_compatiblerp   ru   rv   s
             r   ra   zMatFileReader.__init__i  s¶   € ð$ %ˆŒØˆŒØð 	7Ø×.Ò.Ñ0Ô0ˆJˆJåÔ*¨:Ñ6Ô6ˆJØ$ˆŒØ 0ˆÔØð 	'Ø×&Ò&Ñ(Ô(Ð(Ð(à(ˆDŒOØ$4ˆDÔ!Ø&ˆDŒNØ0PˆÔ-Ø,ˆÔØð 	*Ø"ˆDŒOØ$)ˆDÔ!Ð!Ð!ð	*ð 	*r   c                 ó0   — d| _         d| _        d| _        dS )z4 Sets options to return arrays as MATLAB loads them TFN)rt   rr   rs   rc   s    r   rq   z#MatFileReader.set_matlab_compatible�  s   € àˆŒØˆŒØ %ˆÔÐÐr   c                 ó   — t           j        S )z9 As we do not know what file type we have, assume native )rm   Únative_coderc   s    r   rl   zMatFileReader.guess_byte_order•  s
   € åŒÐr   c                 óÈ   — | j                              d¦  «        }| j                              ¦   «         }| j                              |dz
  ¦  «         t	          |¦  «        dk    S )Nr   r   )r3   r2   ÚtellrI   rK   )r_   ÚbÚcurposs      r   Úend_of_streamzMatFileReader.end_of_stream™  sT   € ØŒO× Ò  Ñ#Ô#ˆØ”×%Ò%Ñ'Ô'ˆØŒ×Ò˜V A™XÑ&Ô&Ð&Ý�1‰vŒv˜Š{Ðr   )NFFTFTTF)	r   r   r   r   r    ra   rq   rl   r   r   r   r   rj   rj   _  s„   € € € € € ðð ð à Ø Ø!Ø"&Ø#(Ø"&Ø26Ø %ð#*ð #*ð #*ñ „Yð#*ðJ&ð &ð &ðð ð ðð ð ð ð r   rj   c                 ón   — t          j        | j        j        dd…         t          |¦  «        z   ¦  «        S )z3 Return dtype for given number of items per elementNrG   )r#   r$   Ústr)r6   Únums     r   Úarr_dtype_numberrƒ      s*   € åŒ8�C”I”M " 1 "Ô%­¨C©¬Ñ0Ñ1Ô1Ð1r   c                 ó¢  — t          | j        ¦  «        }|sdg}|                     t          | j        j        dd…         ¦  «        ¦  «         t          j        |t          | d¦  «        | ¬¦  «        } | t          j	        d| j        ¬¦  «        k    g}t          j
        |¦  «        s| S |                      ¦   «         } d| t          |¦  «        <   | S )z$ Convert string array to char array r   rG   NrD   Ú )r$   ú )Úlistr-   ÚappendrN   r$   r�   r#   r1   rƒ   ÚarrayÚanyr"   Útuple)r6   ÚdimsÚemptiess      r   Úarr_to_charsrŽ   ¥  sÄ   € å�”	‰?Œ?€DØð ØˆsˆØ‡K‚K•�C”I”M ! " "Ô%Ñ&Ô&Ñ'Ô'Ð'Ý
Œ*˜4Ý+¨C°Ñ3Ô3Øð!ñ !ô !€Cð •b”h˜r¨¬Ð3Ñ3Ô3Ò3Ð4€GÝŒ6�'‰?Œ?ð Øˆ
Ø
�(Š(‰*Œ*€CØ€C�ˆg‰ŒÑØ€Jr   )rX   ) r   Útypingr   Únumpyr#   Ú
scipy._libr   r…   r   rm   Ú__all__Ú	Exceptionr   r	   ÚUserWarningr   r
   Údoc_dictÚfilldocr    Ú__annotations__r*   r7   r@   Úget_matfile_versionrJ   r=   r[   r]   rj   rƒ   rŽ   r   r   r   ú<module>r™      sf  ððð ð ð Ð Ð Ð Ð Ð à Ð Ð Ð Ø Ð Ð Ð Ð Ð à $Ð $Ð $Ð $Ð $Ð $ðð ð €ð-ð -ð -ð -ð -�9ñ -ô -ð -ð.ð .ð .ð .ð .�Iñ .ô .ð .ð)ð )ð )ð )ð )�[ñ )ô )ð )ð*ð *ð *ð *ð *�kñ *ô *ð *ð
<ð
9ð
ð 
>ð
.ð
#ð
?ð
6ð
Eða1Fð 1Fð 	ðh "�6”> (Ñ+Ô+€	ˆ5Ð +Ð +Ñ +ð*ðZð ð ð.ð ð ð4 -1ð '-ð '-ð '-ð '-ð '-ðT &Ð ð €ðKð Kð Kð8Kð Kð Kð Kð\ð ð ð ð ñ ô ð ð>ð >ð >ð >ð >ñ >ô >ð >ðB2ð 2ð 2ð
ð ð ð ð r   