+
    /iK                         R t ^ RIt^ RIt^ RIHtHt ^RIHtH	t	H
t
 RR.t ! R R]4      t ! R R	]4      tR
 t ! R R4      tRR ltR tR t ! R R4      t ! R R4      tRR/R ltRR ltR# )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                       ] tR t^tRtR# )MalformedHeader N__name__
__module____qualname____firstlineno____static_attributes__r       Y/var/www/html/photoedit/myenv/lib/python3.14/site-packages/scipy/io/_harwell_boeing/hb.pyr
   r
          r   r
   c                       ] tR t^"tRtR# )LineOverflowr   Nr   r   r   r   r   r   "   r   r   r   c                f    V P                   V P                  ,          ^,           V^,
          ,          # )z_Return the number of bytes to read to get every full lines for the
given parsed fortran format.)repeatwidth)fmtnliness   &&r   _nbytes_fullr   &   s%     JJ"Q&6A:66r   c                   T   a  ] tR t^,t o ]RR l4       t]R 4       tRR ltR tRt	V t
R# )	HBInfoNc                   VP                  RR7      pVP                  pVP                  pVP                  pVP                  w  rVP
                  pVEfh   \        P                  ! \        P                  ! V^,           4      4      p\        P                  ! \        P                  ! V^,           4      4      pVP                  P                  \        P                  R,          9   dA   \        P                  ! \        P                  ! \        P                  ! V4      4      ) 4      pMVP                  P                  \        P                  R,          9   dA   \        P                  ! \        P                  ! \        P                  ! V4      4      ) 4      pM0RVP                  P                   R2p\        V4      h\        R4      hVf   \        P                   ! V4      '       g   \#        R4      hVP                  P                  \        P                  R,          9   d   R	pMLVP                  P                  \        P                  R,          9   d   R
pM\        RVP                   R24      h\%        VRR4      pM\#        R4      hR pV! WP&                  4      pV! WP&                  4      pV! WP&                  4      pVV,           V,           pV ! W#VVVVWIWVP(                  VP(                  VP(                  4      # )ab  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copy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                 j    WP                   ,          pW P                   ,          V8w  d
   V^,          pV# )   )r   )r   sizer   s   && r   _nlines!HBInfo.from_data.<locals>._nlinesi   s+    ZZ'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_dataHBInfo.from_data-   sD   * GGG(())wwUU
; $//wqy0ABK#//wqy0ABK||  BLL$<<&22BFF266&>4J3JK
""bll<&@@&22BFF266&>4J3JK
!&,,"3"3!44HI)'22%&GHH><<'' !CDD||  BLL$>>""bll:&>>)FLL>)DEG G!"m[AF?@@	 !ll; ll;
KK8%6F5..-5&&(B(B%%	' 	'r   c                   VP                  4       P                  R4      p\        V4      ^H8  g   \        RV 24      hVR,          pVR,          pVP                  4       P                  R4      p\        VP	                  4       4      ^88  g   \        RV 24      h\        VR,          4      p\        VR,          4      p\        VR,          4      p\        VR	,          4      pVR
,          P                  4       p	V	R8X  d   ^ p	M\        V	4      p	V	^ 8X  g   \        R4      hVP                  4       P                  R4      p\        V4      ^F8  g   \        RV 24      hVR,          P                  4       p
\        V
4      ^8X  g   \        R4      h\        P                  V
4      pVP                  R9  d   \        RV R24      hVP                  R8X  g   \        RV R24      hVP                  R8X  g   \        R4      hVR,          R8X  g   \        RV 24      h\        VR,          4      p\        VR,          4      p\        VR	,          4      p\        VR,          4      pV^ 8X  g   \        RV R24      hVP                  4       P                  R4      pVP                  4       p\        V4      ^8X  g   \        RV 24      hV ! W4WVWxWWV^ ,          V^,          V^,          W4      # )zCreate 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

z6Expected at least 72 characters for first line, got: 
:NH   N:rV   NNz7Expected at least 56 characters for second line, got: 
:N   N:rW      N:rX   *   N:rY   8   N:rZ   rV   N z5Only files without right hand side supported for now.z4Expected at least 72 character for third line, got:
:N   Nz'mxtype expected to be 3 characters longz:Only real or integer matrices supported for now (detected )r&   z6Only unsymmetric matrices supported for now (detected r'   z)Only assembled matrices supported for now:r\   rW   NzMalformed data for third line: :rZ   F   NzUnexpected value z! for nltvl (last entry of line 3)zExpected 3 formats, got )r%   r$   z           )readlinestriplenr<   rstrip_expect_intupperr=   from_fortran
value_type	structurestoragesplit)r?   fidlinerA   rB   rQ   rN   rO   rP   
rhs_nlinesmxtype_srC   rF   rG   rH   nelementalscts   &&               r   	from_fileHBInfo.from_file{   s    ||~##D)4y2~ ''+f. / /S	3i ||~##D)4;;=!R' ''+f. / /"49-$T%[1$T%[1#DK0%[&&(
J$Z0JQ $ % % ||~##D)4yB  &&*V- . . 8>>#8}!FGG**84$77 ..4XQ8 9 9=0 ..4XQ8 9 9~~,HIIDzX%>tfEFFDK(DK( e-
!$u+.a#K=0QR 
 ||~##D)ZZ\2w!|7t<==5%a5"Q%A	, 	,r   c                   Vf   Rp\        V4      ^H8  d   \        R4      hVf   Rp\        V4      ^8  d"   \        P                  ! RV R2\        ^R7       Wn        W n        W0n        W@n        WPn	        W`n
        \        4       pVP                  V4      p\        V\        4      '       g   \        RV 24      hVP                  V4      p\        V\        4      '       g   \        R	V 24      hVP                  V4      p\        V\        4      '       d4   VP                   R9  d   \        R
V RV 24      h\"        P$                  pMN\        V\        4      '       d*   VP                   R9  d   \        R
V RV 24      h\&        pM\        RV: 24      hVV n        VV n        VV n        \"        P.                  V n        \"        P.                  V n        VV n        W@n        \7        VV4      V n        WPn	        \7        VV4      V n        W`n
        \7        VV4      V n        Wn        Wn         Wn!        Wn"        Wpn#        R# )z@Do not use this directly, but the class ctrs (from_* functions).NzNo Titleztitle cannot be > 72 charactersz|No Keyzkey is > 8 characters (key is r]   )
stacklevelz,Expected int format for pointer format, got z,Expected int format for indices format, got z"Inconsistency between matrix type z and value type zUnsupported format for values )r%   complex)r$   )$ra   r<   warningswarnr   rA   rB   rQ   rN   rO   rP   r   parse
isinstancer   r   rf   r4   float64intpointer_formatindices_formatvalues_formatint32pointer_dtypeindices_dtypevalues_dtyper   pointer_nbytes_fullindices_nbytes_fullvalues_nbytes_fullrF   rG   rH   rn   rC   )selfrA   rB   rQ   rN   rO   rP   rC   rF   rG   rH   pointer_format_strindices_format_strvalues_format_strright_hand_sides_nlinesrn   parserr{   r|   r}   r   s   &&&&&&&&&&&&&&&&     r   __init__HBInfo.__init__   s:    =Eu:?>??;Cs8a<MM:3%qA&16
(,,*$&&89.)44K ./1 2 2  &89.)44K ./1 2 2 %67mY//  (;; #EfX N//<o"? @ @::Ly11  3 #EfX N//<o"? @ @ L=m=NOPP,,*XXXX(,#/#O ,#/#O *".}m"L

$&r   c                   V P                   P                  ^H4      V P                  P                  ^4      ,           .pVP                  V P                  R V P
                  R V P                  R V P                  R 24       VP                  V P                  P                  P                  ^4      R V P                  R V P                  R V P                  R ^ R 24       V P                  P                  pV P                  P                  pV P                  P                  pVP                  VP                  ^4      R VP                  ^4      R VP                  ^4      R 24       RP!                  V4      # )z<Gives the header corresponding to this instance as a string.14d14s16s20srU   )rA   ljustrB   appendrQ   rN   rO   rP   rC   r>   rF   rG   rH   r{   r|   r}   join)r   headerpffmtiffmtvffmts   &    r   dumpHBInfo.dump  sJ   **""2&)::;**3/0C0CC/HI\I\]`Habfbtbtuxayz{3399"=cB4::cBRSWS]S]^aRbcgcrcrsvbwxyz}w~  	A##22##22""11R-ekk"oc-B5;;r?SVBWXYyy  r   )r   r|   r   rO   rB   rC   rG   rn   rH   rF   r   r{   r   rN   rA   rQ   r   r}   r   rP   )zDefault title0NN)    r   )r   r   r   r   classmethodrR   rp   r   r   r   __classdictcell____classdict__s   @r   r   r   ,   sB     K' K'Z S, S,jGR! !r   r   c                 p     \        V 4      #   \         d   pTf   Rp\        Y,          4      ThR p?ii ; i)NzExpected an int, got %s)rz   r<   )valuemsges   && r   rc   rc   (  s:    -5z -;+C%1,-s   
 505c                 ~   R P                  V P                  VP                  4      V P                  4       .4      p\        P
                  ! V\        RR7      pR P                  V P                  VP                  4      V P                  4       .4      p\        P
                  ! V\        RR7      pR P                  V P                  VP                  4      V P                  4       .4      p\        P
                  ! VVP                  RR7      p\        Wu^,
          V^,
          3VP                  VP                  3R7      # )r[    )r6   sep)r1   )r   readr   r_   r4   
fromstringrz   r   r   r   r   rF   rG   )contentr   
ptr_stringptr
ind_stringind
val_stringvals   &&      r   _read_hb_datar   1  s   ',,v'A'AB"++-/ 0J
--
3 C ',,v'A'AB'')+ ,J
--
3 C ',,v'@'@A!**,. /J
--
%%30C cq5#a%(v||0LMMr   c                    V P                  R R7      p R pVP                  VP                  4       4       VP                  R4       V! WP                  ^,           VP                  VP
                  4       V! WP                  ^,           VP                  VP                  4       V! WP                  VP                  VP                  4       R# )Fr    c                    VP                   pWCP                  ,          pVR V^,
          VP                  ,           pVP                  V^,
          VP                  34       F+  pV P                  V\	        V4      ,          R,           4       K-  	  VP
                  VP
                  ,
          pV^ 8  dD   V P                  WH,          \	        WP
                  V,
          R  4      ,          R,           4       R # R # )NrU   )python_formatr   reshapewritetupler*   )	farr   r   pyfmt
pyfmt_fullfullrownremains	   &&&&     r   write_array _write_data.<locals>.write_arrayH  s     !!ZZ'
 ,FQJ#**,-<<3:: 67CGGJs+d23 8''DII%Q;GGU_b71B1C.D(EELM r   rU   N)r-   r   r   r.   rN   r{   r/   rO   r|   r0   rP   r}   )r@   rj   r   r   s   &&& r   _write_datar   E  s    	UAN IIfkkmIIdOXXaZ!6!6%%'YYq[&"7"7%%'VVV11$$&r   c            
         a ] tR tRt oRtRRRRRRR	R
/tRRRRRRRRRR/tRRRR/t]P                  4        U Uu/ uF  w  rWbK	  	  upp t	]P                  4        U Uu/ uF  w  rWbK	  	  upp t
]P                  4        U Uu/ uF  w  rWbK	  	  upp t]R 4       tRR lt]R 4       tR tRtVtR# u upp i u upp i u upp i )r=   ib  zClass to hold the matrix type.r%   Rrt   CpatternPr$   I	symmetricSr&   U	hermitianHskewsymmetricZrectangularr'   A	elementalEc                ,   \        V4      ^8X  g   \        R4      h V P                  V^ ,          ,          pV P                  V^,          ,          pV P                  V^,          ,          pV ! W#V4      #   \
         d   p\        RT 24      ThRp?ii ; i)r\   z:Fortran format for matrix type should be 3 characters longzUnrecognized format N)ra   r<   	_f2q_type_f2q_structure_f2q_storageKeyError)r?   r   rf   rg   rh   r   s   &&    r   re   HBMatrixType.from_fortran{  s    3x1} / 0 0	Bs1v.J**3q62I&&s1v.Gzg66 	B3C59:A	Bs   AA4 4B?BBc                    Wn         W n        W0n        WP                  9  d   \	        R V 24      hW P
                  9  d   \	        RV 24      hW0P                  9  d   \	        RV 24      hR# )zUnrecognized type zUnrecognized structure zUnrecognized storage N)rf   rg   rh   	_q2f_typer<   _q2f_structure_q2f_storage)r   rf   rg   rh   s   &&&&r   r   HBMatrixType.__init__  sq    $"^^+1*>??///6ykBCC+++4WI>?? ,r   c                    V P                   V P                  ,          V P                  V P                  ,          ,           V P                  V P
                  ,          ,           # N)r   rf   r   rg   r   rh   r   s   &r   r>   HBMatrixType.fortran_format  sE    ~~doo.""4>>23  ./ 	/r   c                V    R V P                    RV P                   RV P                   R2# )zHBMatrixType(z, r]   )rf   rg   rh   r   s   &r   __repr__HBMatrixType.__repr__  s,    t/r$..1ADLL>QRSSr   )rh   rg   rf   N)r'   )r   r   r   r   __doc__r   r   r   itemsr   r   r   r   re   r   propertyr>   r   r   r   )ijr   s   00@r   r=   r=   b  s	    ( 	333	I 3S3N 	SSL
 #,//"34"3$!"34I'5';';'=>'=tqad'=>N%1%7%7%9:%9TQAD%9:L
B 
B
@ / /
T TG 5>:s   B2B8B>r=   c                      a  ] tR tRt o RR lt]R 4       t]R 4       t]R 4       t]R 4       t	]R 4       t
R	 tR
 tRtV tR# )HBFilei  Nc                ^    Wn         Vf   \        P                  V4      V n        R# W n        R# )zCreate 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   rp   _hb_info)r   filehb_infos   &&&r   r   HBFile.__init__  s'     	?",,T2DM $Mr   c                .    V P                   P                  # r   )r   rA   r   s   &r   rA   HBFile.title  s    }}"""r   c                .    V P                   P                  # r   )r   rB   r   s   &r   rB   
HBFile.key  s    }}   r   c                B    V P                   P                  P                  # r   )r   rC   rf   r   s   &r   typeHBFile.type  s    }}##...r   c                B    V P                   P                  P                  # r   )r   rC   rg   r   s   &r   rg   HBFile.structure  s    }}##---r   c                B    V P                   P                  P                  # r   )r   rC   rh   r   s   &r   rh   HBFile.storage  s    }}##+++r   c                B    \        V P                  V P                  4      # r   )r   r   r   r   s   &r   read_matrixHBFile.read_matrix  s    TYY66r   c                B    \        WP                  V P                  4      # r   )r   r   r   )r   r@   s   &&r   write_matrixHBFile.write_matrix  s    1ii77r   )r   r   r   )r   r   r   r   r   r   rA   rB   r   rg   rh   r   r  r   r   r   s   @r   r   r     s}     $& # # ! ! / / . . , ,78 8r   r   spmatrixTc                   R p\        V R4      '       d
   V! V 4      pM$\        V 4      ;_uu_ 4       pV! V4      pRRR4       V'       d   \        X4      # X#   + '       g   i     L%; i)ae  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 matrix. Otherwise return sparse 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    \        V 4      pVP                  4       # r   )r   r   )rj   hbs   & r   _get_matrixhb_read.<locals>._get_matrix  s    C[~~r   r   N)hasattropenr   )path_or_open_filer  r  r0   r   s   &$   r   r   r     s[    R   &)),-#$$q>D %$K	 %$s   	AA(	c                  aa SP                  RR7      oSf   \        P                  S4      oVV3R lp\        V R4      '       d	   V! V 4      # \	        V R4      ;_uu_ 4       pV! V4      uuRRR4       #   + '       g   i     R# ; i)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                 >   < \        V S4      pVP                  S4      # r   )r   r  )rj   r  r   r@   s   & r   _set_matrixhb_write.<locals>._set_matrix3  s    C!q!!r   r   w)r-   r   rR   r	  r
  )r  r@   r   r  r   s   &ff  r   r   r     sr    T 	
UA""1%"  '**,--#S))Qq> *)))s   #A66B	r   )r   ru   numpyr4   scipy.sparser   r   _fortran_format_parserr   r   r   __all__	Exceptionr
   Warningr   r   r   rc   r   r   r=   r   r   r   r   r   r   <module>r     s   
(   . M Mj
!	i 		7 	7y! y!x-N(&:9T 9Tx,8 ,8^44 4n7"r   