Ë
    âQ(h;L  ã                   óÚ   — d Z ddlZddlZddlmZmZ ddlmZm	Z	m
Z
 ddgZ G d„ d	e«      Z G d
„ de«      Zd„ Z G d„ d«      Zdd„Zd„ Zd„ Z G d„ d«      Z G d„ d«      Zddœd„Zdd„Zy)a  
Implementation of Harwell-Boeing read/write.

At the moment not the full Harwell-Boeing format is supported. Supported
features are:

    - assembled, non-symmetric, real matrices
    - integer for pointer/indices
    - exponential format for float values, and int format

é    N)Ú	csc_arrayÚ
csc_matrixé   )ÚFortranFormatParserÚ	IntFormatÚ	ExpFormatÚhb_readÚhb_writec                   ó   — e Zd Zy)ÚMalformedHeaderN©Ú__name__Ú
__module__Ú__qualname__© ó    úY/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/scipy/io/_harwell_boeing/hb.pyr   r      ó   „ Ør   r   c                   ó   — e Zd Zy)ÚLineOverflowNr   r   r   r   r   r   "   r   r   r   c                 óF   — | j                   | j                  z  dz   |dz
  z  S )zcReturn the number of bytes to read to get every full lines for the
    given parsed fortran format.r   )ÚrepeatÚwidth)ÚfmtÚnliness     r   Ú_nbytes_fullr   &   s%   € ð �J‰J˜Ÿ™Ñ" QÑ&¨6°A©:Ñ6Ð6r   c                   ó>   — e Zd Zedd„«       Zed„ «       Z	 dd„Zd„ Zy)ÚHBInfoNc                 ó’  — |j                  d¬«      }|j                  }|j                  }|j                  }|j                  \  }	}
|j
                  }|�€Gt        j                  t        j                  |dz   «      «      }t        j                  t        j                  |dz   «      «      }|j                  j                  t        j                  d   v r=t        j                  t        j                  t        j                  |«      «       «      }n–|j                  j                  t        j                  d   v r=t        j                  t        j                  t        j                  |«      «       «      }n0d|j                  j                  › d�}t        |«      ‚t        d«      ‚|€Ÿt        j                   |«      st#        d	«      ‚|j                  j                  t        j                  d   v rd
}nE|j                  j                  t        j                  d   v rd}nt        d|j                  › d�«      ‚t%        |dd«      }nt#        d«      ‚d„ } |||j&                  «      } |||j&                  «      } |||j&                  «      }||z   |z   } | ||||||||	|
||j(                  |j(                  |j(                  «      S )aâ  Create a HBInfo instance from an existing sparse matrix.

        Parameters
        ----------
        m : sparse array or matrix
            the HBInfo instance will derive its parameters from m
        title : str
            Title to put in the HB header
        key : str
            Key
        mxtype : HBMatrixType
            type of the input matrix
        fmt : dict
            not implemented

        Returns
        -------
        hb_info : HBInfo instance
        F©Úcopyr   ÚAllFloatÚ
AllIntegerztype z not implemented yetzfmt argument not supported yet.z Complex values not supported yetÚintegerÚrealz for values not implementedÚunsymmetricÚ	assembledz mxtype argument not handled yet.c                 óR   — || j                   z  }|| j                   z  |k7  r|dz  }|S )Nr   )r   )r   Úsizer   s      r   Ú_nlinesz!HBInfo.from_data.<locals>._nlinesi   s/   € Ø˜SŸZ™ZÑ'ˆFØ˜Ÿ
™
Ñ" dÒ*Ø˜!‘�ØˆMr   )ÚtocscÚindptrÚindicesÚdataÚshapeÚnnzr   Úfrom_numberÚnpÚmaxÚdtypeÚkindÚ	typecodesr   ÚabsÚNotImplementedErrorÚ	isrealobjÚ
ValueErrorÚHBMatrixTyper)   Úfortran_format)ÚclsÚmÚtitleÚkeyÚmxtyper   Úpointerr-   ÚvaluesÚnrowsÚncolsÚ
nnon_zerosÚpointer_fmtÚindices_fmtÚ
values_fmtÚmessageÚtpr*   Úpointer_nlinesÚindices_nlinesÚvalues_nlinesÚtotal_nliness                         r   Ú	from_datazHBInfo.from_data-   sO  € ð* �G‰G˜ˆGÓˆà—(‘(ˆØ—)‘)ˆØ—‘ˆà—w‘w‰ˆˆuØ—U‘Uˆ
à‰;ô $×/Ñ/´·±°w¸q±yÓ0AÓBˆKÜ#×/Ñ/´·±°w¸q±yÓ0AÓBˆKà�|‰|× Ñ ¤B§L¡L°Ñ$<Ñ<Ü&×2Ñ2´B·F±F¼2¿6¹6À&»>Ó4JÐ3JÓK‘
Ø—‘×"Ñ"¤b§l¡l°<Ñ&@Ñ@Ü&×2Ñ2´B·F±F¼2¿6¹6À&»>Ó4JÐ3JÓK‘
à! &§,¡,×"3Ñ"3Ð!4Ð4HÐI�Ü)¨'Ó2Ð2ä%Ð&GÓHÐHàˆ>Ü—<‘< Ô'Ü Ð!CÓDÐDØ�|‰|× Ñ ¤B§L¡L°Ñ$>Ñ>Ø‘Ø—‘×"Ñ"¤b§l¡l°:Ñ&>Ñ>Ø‘ä)Ø˜FŸL™L˜>Ð)DÐEóGð Gä! " m°[ÓA‰FäÐ?Ó@Ð@ò	ñ ! ¨g¯l©lÓ;ˆÙ  ¨g¯l©lÓ;ˆÙ 
¨F¯K©KÓ8ˆà%¨Ñ6¸ÑFˆá�5˜#Ø˜.¨.¸-Ø�E˜5 *Ø×&Ñ&¨×(BÑ(BØ×%Ñ%ó	'ð 	'r   c                 ó2  — |j                  «       j                  d«      }t        |«      dkD  st        d|› �«      ‚|dd }|dd }|j                  «       j                  d«      }t        |j	                  «       «      dk\  st        d|› �«      ‚t        |dd «      }t        |dd «      }t        |dd	 «      }t        |d	d «      }|dd j                  «       }	|	d
k(  rd}	nt        |	«      }	|	dk(  st        d«      ‚|j                  «       j                  d«      }t        |«      dk\  st        d|› �«      ‚|dd j                  «       }
t        |
«      dk(  st        d«      ‚t        j                  |
«      }|j                  dvrt        d|› d�«      ‚|j                  dk(  st        d|› d�«      ‚|j                  dk(  st        d«      ‚|dd dk(  st        d|› �«      ‚t        |dd «      }t        |dd	 «      }t        |d	d «      }t        |dd «      }|dk(  st        d|z  «      ‚|j                  «       j                  d«      }|j                  «       }t        |«      dk(  st        d|› �«      ‚ | |||||||||||d   |d   |d   |	|«      S )a6  Create a HBInfo instance from a file object containing a matrix in the
        HB format.

        Parameters
        ----------
        fid : file-like matrix
            File or file-like object containing a matrix in the HB format.

        Returns
        -------
        hb_info : HBInfo instance
        ú
éH   z6Expected at least 72 characters for first line, got: 
Né8   z7Expected at least 56 characters for second line, got: 
é   é   é*   Ú r   z5Only files without right hand side supported for now.éF   z4Expected at least 72 character for third line, got:
é   z'mxtype expected to be 3 characters long)r%   r$   z:Only real or integer matrices supported for now (detected ú)r&   z6Only unsymmetric matrices supported for now (detected r'   z)Only assembled matrices supported for nowz           zMalformed data for third line: z4Unexpected value %d for nltvl (last entry of line 3)zExpected 3 formats, got r   é   )ÚreadlineÚstripÚlenr:   ÚrstripÚ_expect_intÚupperr;   Úfrom_fortranÚ
value_typeÚ	structureÚstorageÚsplit)r=   ÚfidÚliner?   r@   rO   rL   rM   rN   Ú
rhs_nlinesÚmxtype_srA   rD   rE   rF   ÚnelementalsÚcts                    r   Ú	from_filezHBInfo.from_file{   s  € ð �|‰|‹~×#Ñ# DÓ)ˆÜ�4‹y˜2Š~Üð 'Ø'+ fð.ó /ð /à�S�b�	ˆØ�2�3ˆiˆð �|‰|‹~×#Ñ# DÓ)ˆÜ�4—;‘;“=Ó! RÒ'Üð 'Ø'+ fð.ó /ð /ä" 4¨¨ 9Ó-ˆÜ$ T¨"¨R [Ó1ˆÜ$ T¨"¨R [Ó1ˆÜ# D¨¨B KÓ0ˆà˜"˜R�[×&Ñ&Ó(ˆ
Ø˜ÒØ‰Jä$ ZÓ0ˆJØ˜QŠÜð $ó %ð %ð �|‰|‹~×#Ñ# DÓ)ˆÜ�4‹y˜BŠÜð  &Ø&* Vð-ó .ð .ð ˜˜�8—>‘>Ó#ˆÜ�8‹} Ò!ÜÐFÓGÐGä×*Ñ*¨8Ó4ˆØ×ÑÐ$7Ñ7Üð .Ø.4¨X°Qð8ó 9ð 9à×Ñ =Ò0Üð .Ø.4¨X°Qð8ó 9ð 9à�~‰~ Ò,ÜÐHÓIÐIà�A�bˆz˜XÒ%ÜÐ>¸t¸fÐEÓFÐFä˜D  B˜KÓ(ˆÜ˜D  B˜KÓ(ˆÜ   b¨ Ó-ˆ
Ü! $ r¨" +Ó.ˆØ˜aÒÜÐSØ*ñ+ó ,ð ,ð �|‰|‹~×#Ñ# DÓ)ˆà�Z‰Z‹\ˆÜ�2‹w˜!Š|ÜÐ7¸°tÐ<Ó=Ð=á�5˜#Ø °ÀØ˜5 %¨Ø�a‘5˜"˜Q™%  A¡Ø˜{ó	,ð 	,r   c                 óR  — |€d}t        |«      dkD  rt        d«      ‚|€d}t        |«      dkD  r t        j                  d|› d�t        d	¬
«       || _        || _        || _        || _        || _	        || _
        t        «       }|j                  |«      }t        |t        «      st        d|› �«      ‚|j                  |«      }t        |t        «      st        d|› �«      ‚|j                  |«      }t        |t        «      r0|j                   dvrt        d|› d|› �«      ‚t"        j$                  }nDt        |t        «      r&|j                   dvrt        d|› d|› �«      ‚t&        }nt        d|›�«      ‚|| _        || _        || _        t"        j.                  | _        t"        j.                  | _        || _        || _        t7        ||«      | _        || _	        t7        ||«      | _        || _
        t7        ||«      | _        || _        |	| _         |
| _!        || _"        || _#        y)z@Do not use this directly, but the class ctrs (from_* functions).NzNo TitlerS   ztitle cannot be > 72 charactersz|No Keyé   zkey is > 8 characters (key is r[   rZ   )Ú
stacklevelz,Expected int format for pointer format, got z,Expected int format for indices format, got )r%   Úcomplexz"Inconsistency between matrix type z and value type )r$   zUnsupported format for values )$r_   r:   ÚwarningsÚwarnr   r?   r@   rO   rL   rM   rN   r   ÚparseÚ
isinstancer   r   rd   r2   Úfloat64ÚintÚpointer_formatÚindices_formatÚvalues_formatÚint32Úpointer_dtypeÚindices_dtypeÚvalues_dtyper   Úpointer_nbytes_fullÚindices_nbytes_fullÚvalues_nbytes_fullrD   rE   rF   rl   rA   )Úselfr?   r@   rO   rL   rM   rN   rA   rD   rE   rF   Úpointer_format_strÚindices_format_strÚvalues_format_strÚright_hand_sides_nlinesrl   Úparserry   rz   r{   r   s                        r   Ú__init__zHBInfo.__init__Ð   sJ  € ð ˆ=ØˆEÜˆu‹:˜Š?ÜÐ>Ó?Ð?àˆ;ØˆCÜˆs‹8�aŠ<Ü�M‰MÐ:¸3¸%¸qÐAÜ&°1õ6àˆŒ
ØˆŒà(ˆÔØ,ˆÔØ,ˆÔØ*ˆÔä$Ó&ˆØŸ™Ð&8Ó9ˆÜ˜.¬)Ô4ÜÐKØ .Ð/ð1ó 2ð 2ð  Ÿ™Ð&8Ó9ˆÜ˜.¬)Ô4ÜÐKØ .Ð/ð1ó 2ð 2ð Ÿ™Ð%6Ó7ˆÜ�m¤YÔ/Ø× Ñ Ð(;Ñ;Ü Ð#EÀfÀXð N/Ø/<¨oð"?ó @ð @äŸ:™:‰LÜ˜¤yÔ1Ø× Ñ ¨Ñ3Ü Ð#EÀfÀXð N/Ø/<¨oð"?ó @ð @ô ‰LäÐ=¸mÐ=NÐOÓPÐPà,ˆÔØ,ˆÔØ*ˆÔäŸX™XˆÔÜŸX™XˆÔØ(ˆÔà,ˆÔÜ#/°ÀÓ#OˆÔ à,ˆÔÜ#/°ÀÓ#OˆÔ à*ˆÔÜ".¨}¸mÓ"LˆÔàˆŒ
ØˆŒ
Ø$ˆŒØ&ˆÔØˆ�r   c                 óÚ  — | j                   j                  d«      | j                  j                  d«      z   g}|j                  d| j                  | j
                  | j                  | j                  fz  «       |j                  d| j                  j                  j                  d«      | j                  | j                  | j                  dfz  «       | j                  j                  }| j                  j                  }| j                  j                  }|j                  |j                  d«      d›|j                  d«      d›|j                  d	«      d
›�«       dj!                  |«      S )z<Gives the header corresponding to this instance as a string.rS   rp   z%14d%14d%14d%14dz%14s%14d%14d%14d%14drU   r   é   z>16é   z>20rR   )r?   Úljustr@   ÚappendrO   rL   rM   rN   rA   r<   rD   rE   rF   ry   rz   r{   Újoin)rƒ   ÚheaderÚpffmtÚiffmtÚvffmts        r   ÚdumpzHBInfo.dump  s'  € à—*‘*×"Ñ" 2Ó&¨¯©¯©¸Ó):Ñ:Ð;ˆà�‰Ð(Ø×(Ñ(¨$×*=Ñ*=Ø×*Ñ*¨D×,>Ñ,>ð@ñ@ô 	Að 	�‰Ð,Ø—{‘{×1Ñ1×7Ñ7¸Ó;¸T¿Z¹ZØ—z‘z 4§?¡?°Að7ñ7ô 	8ð ×#Ñ#×2Ñ2ˆØ×#Ñ#×2Ñ2ˆØ×"Ñ"×1Ñ1ˆØ�‰Ø—{‘{ 2•¨¯©°B­¸¿¹ÀR½ðJô 	Kà�y‰y˜Ó Ð r   )zDefault titleÚ0NN)r   r   )r   r   r   ÚclassmethodrP   rn   r‰   r”   r   r   r   r   r   ,   s?   „ ØòK'ó ðK'ðZ ñR,ó ðR,ðp 45ó	GóR!r   r   c                 ób   — 	 t        | «      S # t        $ r}|€d}t        || z  «      |‚d }~ww xY w)NzExpected an int, got %s)rx   r:   )ÚvalueÚmsgÚes      r   ra   ra   ,  s<   € ð-Ü�5‹zÐøÜò -Øˆ;Ø+ˆCÜ˜˜u™Ó%¨1Ð,ûð-ús   ‚
 �	.–)©.c                 ój  — dj                  | j                  |j                  «      | j                  «       g«      }t	        j
                  |t        d¬«      }dj                  | j                  |j                  «      | j                  «       g«      }t	        j
                  |t        d¬«      }dj                  | j                  |j                  «      | j                  «       g«      }t	        j
                  ||j                  d¬«      }t        ||dz
  |dz
  f|j                  |j                  f¬«      S )NrX   ú )r4   Úsepr   )r/   )r�   Úreadr€   r]   r2   Ú
fromstringrx   r�   r‚   r   r   rD   rE   )Úcontentr�   Ú
ptr_stringÚptrÚ
ind_stringÚindÚ
val_stringÚvals           r   Ú_read_hb_datar§   5  s  € à—‘˜'Ÿ,™, v×'AÑ'AÓBØ"×+Ñ+Ó-ð/ó 0€Jä
�-‰-˜
Ü˜3ô €Cð —‘˜'Ÿ,™, v×'AÑ'AÓBØ×'Ñ'Ó)ð+ó ,€Jä
�-‰-˜
Ü˜3ô €Cð —‘˜'Ÿ,™, v×'@Ñ'@ÓAØ!×*Ñ*Ó,ð.ó /€Jä
�-‰-˜
Ø×%Ñ%¨3ô0€Cô �c˜3˜q™5 # a¡%Ð(°·±¸v¿|¹|Ð0LÔMÐMr   c                 ó�  — | j                  d¬«      } d„ }|j                  |j                  «       «       |j                  d«        ||| j                  dz   |j                  |j
                  «        ||| j                  dz   |j                  |j                  «        ||| j                  |j                  |j                  «       y )NFr    c                 ó’  — |j                   }||j                  z  }|d |dz
  |j                  z   }|j                  |dz
  |j                  f«      D ]"  }| j                  |t	        |«      z  dz   «       Œ$ |j
                  |j
                  z
  }|dkD  r4| j                  ||z  t	        ||j
                  |z
  d  «      z  dz   «       y y )Nr   rR   r   )Úpython_formatr   ÚreshapeÚwriteÚtupler)   )	ÚfÚarr   r   ÚpyfmtÚ
pyfmt_fullÚfullÚrowÚnremains	            r   Úwrite_arrayz _write_data.<locals>.write_arrayL  sÆ   € ð ×!Ñ!ˆØ˜SŸZ™ZÑ'ˆ
ð Ð,�F˜Q‘J #§*¡*Ñ,Ð-ˆØ—<‘< ¨¡¨3¯:©:Ð 6Ó7ò 	4ˆCØ�G‰G�J¤ s£Ñ+¨dÑ2Õ3ð	4à—'‘'˜DŸI™IÑ%ˆØ�QŠ;Ø�G‰G�U˜W‘_¬¨b°·±¸7Ñ1BÐ1CÐ.DÓ(EÑEÈÑLÕMð r   rR   r   )r+   r¬   r”   r,   rL   ry   r-   rM   rz   r.   rN   r{   )r>   rh   r�   rµ   s       r   Ú_write_datar¶   I  s¢   € Ø	�‰�UˆÓ€AòNð ‡I�Iˆf�k‰k‹mÔØ‡I�Iˆd„Oá��Q—X‘X˜a‘Z ×!6Ñ!6Ø×%Ñ%ô'á��Q—Y‘Y˜q‘[ &×"7Ñ"7Ø×%Ñ%ô'á��Q—V‘V˜V×1Ñ1Ø×$Ñ$õ&r   c                   ót  — e Zd ZdZdddddœZddd	d
ddœZdddœZej                  «       D � ��ci c]  \  }}||“Œ
 c}}} Zej                  «       D � ��ci c]  \  }}||“Œ
 c}}} Z	ej                  «       D � ��ci c]  \  }}||“Œ
 c}}} Z
ed„ «       Zdd„Zed„ «       Zd„ Zyc c}}} w c c}}} w c c}}} w )r;   zClass to hold the matrix type.ÚRÚCÚPÚI)r%   rr   Úpatternr$   ÚSÚUÚHÚZ)Ú	symmetricr&   Ú	hermitianÚskewsymmetricÚrectangularÚAÚE)r'   Ú	elementalc                 óö   — t        |«      dk(  st        d«      ‚	 | j                  |d      }| j                  |d      }| j                  |d      } | |||«      S # t
        $ r}t        d|› �«      |‚d }~ww xY w)NrZ   z:Fortran format for matrix type should be 3 characters longr   r   r\   zUnrecognized format )r_   r:   Ú	_f2q_typeÚ_f2q_structureÚ_f2q_storageÚKeyError)r=   r   rd   re   rf   rš   s         r   rc   zHBMatrixType.from_fortran  s•   € ä�3‹x˜1Š}Üð /ó 0ð 0ð	BØŸ™ s¨1¡vÑ.ˆJØ×*Ñ*¨3¨q©6Ñ2ˆIØ×&Ñ& s¨1¡vÑ.ˆGÙ�z 9¨gÓ6Ð6øÜò 	BÜÐ3°C°5Ð9Ó:ÀÐAûð	Bús   ›?A Á	A8Á$A3Á3A8c                 óÖ   — || _         || _        || _        || j                  vrt	        d|› �«      ‚|| j
                  vrt	        d|› �«      ‚|| j                  vrt	        d|› �«      ‚y )NzUnrecognized type zUnrecognized structure zUnrecognized storage )rd   re   rf   Ú	_q2f_typer:   Ú_q2f_structureÚ_q2f_storage)rƒ   rd   re   rf   s       r   r‰   zHBMatrixType.__init__Œ  s}   € Ø$ˆŒØ"ˆŒØˆŒà˜TŸ^™^Ñ+ÜÐ1°*°Ð>Ó?Ð?Ø˜D×/Ñ/Ñ/ÜÐ6°y°kÐBÓCÐCØ˜$×+Ñ+Ñ+ÜÐ4°W°IÐ>Ó?Ð?ð ,r   c                 óœ   — | j                   | j                     | j                  | j                     z   | j                  | j
                     z   S ©N)rÎ   rd   rÏ   re   rÐ   rf   ©rƒ   s    r   r<   zHBMatrixType.fortran_format˜  sE   € à�~‰~˜dŸo™oÑ.Ø×"Ñ" 4§>¡>Ñ2ñ3à× Ñ  §¡Ñ.ñ/ð 	/r   c                 óV   — d| j                   › d| j                  › d| j                  › d�S )NzHBMatrixType(z, r[   )rd   re   rf   rÓ   s    r   Ú__repr__zHBMatrixType.__repr__ž  s,   € Ø˜tŸ™Ð/¨r°$·.±.Ð1AÀÀDÇLÁLÀ>ÐQRÐSÐSr   N)r'   )r   r   r   Ú__doc__rÎ   rÏ   rÐ   ÚitemsrÉ   rÊ   rË   r–   rc   r‰   Úpropertyr<   rÕ   )Ú.0ÚiÚjs   000r   r;   r;   f  sí   „ Ù(ð ØØØñ	€Ið ØØØ Øñ€Nð Øñ€Lð
 #,§/¡/Ó"3×4Ð4™$˜!˜Q��A‘Ô4€IØ'5×';Ñ';Ó'=×>Ð>™t˜q !�a˜‘dÔ>€NØ%1×%7Ñ%7Ó%9×:Ð:™T˜Q �A�q‘DÔ:€Làñ
Bó ð
Bó
@ð ñ/ó ð/ó
TùôG 5ùÜ>ùÜ:s   ¯B%ÁB,Á;B3r;   c                   óp   — e Zd Zd
d„Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Z	d„ Z
d	„ Zy)ÚHBFileNc                 óZ   — || _         |€t        j                  |«      | _        y|| _        y)a  Create a HBFile instance.

        Parameters
        ----------
        file : file-object
            StringIO work as well
        hb_info : HBInfo, optional
            Should be given as an argument for writing, in which case the file
            should be writable.
        N)Ú_fidr   rn   Ú_hb_info)rƒ   ÚfileÚhb_infos      r   r‰   zHBFile.__init__£  s+   € ð ˆŒ	Øˆ?Ü"×,Ñ,¨TÓ2ˆD�Mð $ˆD�Mr   c                 ó.   — | j                   j                  S rÒ   )rà   r?   rÓ   s    r   r?   zHBFile.title¶  s   € à�}‰}×"Ñ"Ð"r   c                 ó.   — | j                   j                  S rÒ   )rà   r@   rÓ   s    r   r@   z
HBFile.keyº  s   € à�}‰}× Ñ Ð r   c                 óB   — | j                   j                  j                  S rÒ   )rà   rA   rd   rÓ   s    r   ÚtypezHBFile.type¾  s   € à�}‰}×#Ñ#×.Ñ.Ð.r   c                 óB   — | j                   j                  j                  S rÒ   )rà   rA   re   rÓ   s    r   re   zHBFile.structureÂ  s   € à�}‰}×#Ñ#×-Ñ-Ð-r   c                 óB   — | j                   j                  j                  S rÒ   )rà   rA   rf   rÓ   s    r   rf   zHBFile.storageÆ  s   € à�}‰}×#Ñ#×+Ñ+Ð+r   c                 óB   — t        | j                  | j                  «      S rÒ   )r§   rß   rà   rÓ   s    r   Úread_matrixzHBFile.read_matrixÊ  s   € Ü˜TŸY™Y¨¯©Ó6Ð6r   c                 óD   — t        || j                  | j                  «      S rÒ   )r¶   rß   rà   )rƒ   r>   s     r   Úwrite_matrixzHBFile.write_matrixÍ  s   € Ü˜1˜dŸi™i¨¯©Ó7Ð7r   rÒ   )r   r   r   r‰   rØ   r?   r@   ræ   re   rf   rê   rì   r   r   r   rÝ   rÝ   ¢  su   „ ó$ð& ñ#ó ð#ð ñ!ó ð!ð ñ/ó ð/ð ñ.ó ð.ð ñ,ó ð,ò7ó8r   rÝ   T)Úspmatrixc                ó    — d„ }t        | d«      r	 || «      }nt        | «      5 } ||«      }ddd«       |rt        «      S S # 1 sw Y   ŒxY w)aî  Read HB-format file.

    Parameters
    ----------
    path_or_open_file : path-like or file-like
        If a file-like object, it is used as-is. Otherwise, it is opened
        before reading.
    spmatrix : bool, optional (default: True)
        If ``True``, return sparse ``coo_matrix``. Otherwise return ``coo_array``.

    Returns
    -------
    data : csc_array or csc_matrix
        The data read from the HB file as a sparse array.

    Notes
    -----
    At the moment not the full Harwell-Boeing format is supported. Supported
    features are:

        - assembled, non-symmetric, real matrices
        - integer for pointer/indices
        - exponential format for float values, and int format

    Examples
    --------
    We can read and write a harwell-boeing format file:

    >>> from scipy.io import hb_read, hb_write
    >>> from scipy.sparse import csr_array, eye
    >>> data = csr_array(eye(3))  # create a sparse array
    >>> hb_write("data.hb", data)  # write a hb file
    >>> print(hb_read("data.hb", spmatrix=False))  # read a hb file
    <Compressed Sparse Column sparse array of dtype 'float64'
        with 3 stored elements and shape (3, 3)>
        Coords	Values
        (0, 0)	1.0
        (1, 1)	1.0
        (2, 2)	1.0
    c                 ó8   — t        | «      }|j                  «       S rÒ   )rÝ   rê   )rh   Úhbs     r   Ú_get_matrixzhb_read.<locals>._get_matrixú  s   € Ü�C‹[ˆØ�~‰~ÓÐr   rž   N)ÚhasattrÚopenr   )Úpath_or_open_filerí   rñ   r.   r®   s        r   r	   r	   Ñ  s\   € òR ô Ð  &Ô)ÙÐ,Ó-‰äÐ#Ó$ð 	"¨Ù˜q“>ˆD÷	"áÜ˜$ÓÐØ€K÷		"ð 	"ús   ¤	AÁAc                 óà   ‡‡— ‰j                  d¬«      Š‰€t        j                  ‰«      Šˆˆfd„}t        | d«      r || «      S t	        | d«      5 } ||«      cddd«       S # 1 sw Y   yxY w)a™  Write HB-format file.

    Parameters
    ----------
    path_or_open_file : path-like or file-like
        If a file-like object, it is used as-is. Otherwise, it is opened
        before writing.
    m : sparse array or matrix
        the sparse array to write
    hb_info : HBInfo
        contains the meta-data for write

    Returns
    -------
    None

    Notes
    -----
    At the moment not the full Harwell-Boeing format is supported. Supported
    features are:

        - assembled, non-symmetric, real matrices
        - integer for pointer/indices
        - exponential format for float values, and int format

    Examples
    --------
    We can read and write a harwell-boeing format file:

    >>> from scipy.io import hb_read, hb_write
    >>> from scipy.sparse import csr_array, eye
    >>> data = csr_array(eye(3))  # create a sparse array
    >>> hb_write("data.hb", data)  # write a hb file
    >>> print(hb_read("data.hb", spmatrix=False))  # read a hb file
    <Compressed Sparse Column sparse array of dtype 'float64'
        with 3 stored elements and shape (3, 3)>
        Coords	Values
        (0, 0)	1.0
        (1, 1)	1.0
        (2, 2)	1.0
    Fr    Nc                 ó>   •— t        | ‰«      }|j                  ‰«      S rÒ   )rÝ   rì   )rh   rð   râ   r>   s     €€r   Ú_set_matrixzhb_write.<locals>._set_matrix7  s   ø€ Ü�C˜Ó!ˆØ�‰˜qÓ!Ð!r   r¬   Úw)r+   r   rP   rò   ró   )rô   r>   râ   r÷   r®   s    ``  r   r
   r
     sr   ù€ ðT 	
�‰�UˆÓ€Aà€Ü×"Ñ" 1Ó%ˆõ"ô Ð  'Ô*ÙÐ,Ó-Ð-äÐ# SÓ)ð 	"¨QÙ˜q“>÷	"÷ 	"ò 	"ús   ÁA$Á$A-rÒ   )rÖ   rs   Únumpyr2   Úscipy.sparser   r   Ú_fortran_format_parserr   r   r   Ú__all__Ú	Exceptionr   ÚWarningr   r   r   ra   r§   r¶   r;   rÝ   r	   r
   r   r   r   ú<module>rÿ      s‡   ðñ
ó( ã ß .ß MÑ Mà�jÐ
!€ô	�iô 	ô	�7ô 	ò7÷}!ñ }!ó@-òNò(&÷:9Tñ 9T÷x,8ñ ,8ð^ ,0ô 4ôn7"r   