o
    ii                     @   s  d dl mZ d dlZd dlZd dlZd dlZd dlZd dlmZm	Z	m
Z
 d dlmZmZmZmZ d dlZd dlmZ d dlZd dlmZmZmZ ddgZG d	d
 d
ZG dd deZdZdZdZdZdZ dZ!dZ"dZ#G dd dZ$dZ%dZ&dZ'dZ(dZ)dZ*G dd dZ+dd  Z,d!d" Z-dS )#    )mkdtempN)array	transposepi)assert_equalassert_allcloseassert_array_equalassert_array_almost_equal)raises)mminfommreadmmwrite)integerint)unsigned-integerZuintc                   @   s  e Zd Zdd Zdd Zdd Zdd Zej	d	e
d
d Zej	d	e
dd Zdd Zdd Zej	d	e
dd Zej	d	e
dd Zej	d	e
dd Zdd Zdd Zdd Zej	d	e
dd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0S )1TestMMIOArrayc                 C      t  | _tj| jd| _d S Nztestfile.mtxr   tmpdirospathjoinfnself r   g/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/scipy/io/tests/test_mmio.pysetup_method      zTestMMIOArray.setup_methodc                 C      t | j d S Nshutilrmtreer   r   r   r   r   teardown_method      zTestMMIOArray.teardown_methodc                 C   s4   t | j| tt| j| t| j}t|| d S r!   )r   r   r   r   r   r	   r   ainfobr   r   r   check      
zTestMMIOArray.checkc                 C   s4   t | j| tt| j| t| j}t|| d S r!   )r   r   r   r   r   r'   r   r   r   check_exact#   r,   zTestMMIOArray.check_exacttypeval, dtypec              	   C   s0   |  tddgddgg|ddddd|df d S )N            dtyper   generalr-   r   r   typevalr4   r   r   r   test_simple_integer)      z!TestMMIOArray.test_simple_integerc              	   C   s4   t ddgddgg|d}| |dddd|d	f d S )
Nr3   r0   r2   r   r5   )r   r-   )r   r8   r4   r(   r   r   r   test_32bit_integer.   s   z TestMMIOArray.test_32bit_integerc                 C   sN   t ddgddggtjd}tdjdk rttt| j| d S | 	|d d S )	N                        r3   r      r0   r0   r2   r   r   r5   )
r   npint64intpitemsizeassert_raisesOverflowErrorr   r   r-   r   r(   r   r   r   test_64bit_integer3   s   z TestMMIOArray.test_64bit_integerc                 C   s*   t ddgddggtjd}| |d d S )Nr@   rA           r3   )r0   r0   r2   r   r   r5   )r   rF   uint64r-   rL   r   r   r   test_64bit_unsigned_integer:   s   z)TestMMIOArray.test_64bit_unsigned_integerc              	   C   s0   |  tddgddgg|ddddd|df d S Nr   r/   r3   r0   r2   r   r5   r6   r7   r   r   r   "test_simple_upper_triangle_integer>   r:   z0TestMMIOArray.test_simple_upper_triangle_integerc              	   C   s0   |  tddgddgg|ddddd|df d S rR   r6   r7   r   r   r   "test_simple_lower_triangle_integerC   r:   z0TestMMIOArray.test_simple_lower_triangle_integerc              	   C   s0   |  tg dg dg|ddddd|df d S )	Nr/   r0   r1   r2         r3   r0   r1   rX   r   r5   r6   r7   r   r   r   test_simple_rectangular_integerH   r:   z-TestMMIOArray.test_simple_rectangular_integerc                 C   s"   |  ddgddgddggd d S )Nr/   r0         @r2   rW   rX   )r1   r0   rX   r   realr5   r+   r   r   r   r   test_simple_rectangular_floatM      z+TestMMIOArray.test_simple_rectangular_floatc                 C      |  ddgddggd d S )Nr/   r0   r1         @r0   r0   r2   r   r[   r5   r\   r   r   r   r   test_simple_floatQ      zTestMMIOArray.test_simple_floatc                 C   r_   )Nr/   r0   r1                 @)r0   r0   r2   r   complexr5   r\   r   r   r   r   test_simple_complexU   rc   z!TestMMIOArray.test_simple_complexc              	   C   s0   |  tddgddgg|ddddd|df d S )Nr/   r0   r2   r3   r   	symmetricr6   r7   r   r   r   test_simple_symmetric_integerY   r:   z+TestMMIOArray.test_simple_symmetric_integerc                 C   s   |  ddgddggd d S )Nr   r0   )r0   r0   r2   r   r   skew-symmetric)r-   r   r   r   r   "test_simple_skew_symmetric_integer^   rc   z0TestMMIOArray.test_simple_skew_symmetric_integerc                 C   s"   |  tddgddggdd d S )Nr   r0          g        f)r0   r0   r2   r   r[   rj   )r+   r   r   r   r   r    test_simple_skew_symmetric_floatb   r^   z.TestMMIOArray.test_simple_skew_symmetric_floatc                 C   r_   )Nr/          @      @       @      r2   )r0   r0   r2   r   re   	hermitianr\   r   r   r   r   test_simple_hermitian_complexf   rc   z+TestMMIOArray.test_simple_hermitian_complexc                 C   s,   d}t j|}|t| }| |d d S )N   rt   )rt   rt   i  r   r[   rg   )rF   randomr   r+   r   szr(   r   r   r   test_random_symmetric_floatj      z)TestMMIOArray.test_random_symmetric_floatc                 C   s    d}t j|}| |d d S )Nrt      )rt   r{   ,  r   r[   r5   )rF   ru   r+   rv   r   r   r   test_random_rectangular_floatp   s   z+TestMMIOArray.test_random_rectangular_floatc                 C   Z   d}t |d}tjtdd tjt	| W d    d S 1 s&w   Y  d S )Nz            %%MatrixMarket matrix array real general
              3  3 999
            1.0
            2.0
            3.0
            4.0
            5.0
            6.0
            7.0
            8.0
            9.0
            asciiznot of length 2match
textwrapdedentencodepytestr
   
ValueErrorscipyior   BytesIOr   stextr   r   r   &test_bad_number_of_array_header_fieldsu   s
   "z4TestMMIOArray.test_bad_number_of_array_header_fieldsc                 C   &   |  tddgddggtjdd d S )Nr/   r0   ri   c   r3   rE   )r-   r   rF   int32r   r   r   r   #test_gh13634_non_skew_symmetric_int      z1TestMMIOArray.test_gh13634_non_skew_symmetric_intc                 C   r   )Nr/   r0   ri        X@r3   ra   )r+   r   rF   float32r   r   r   r   %test_gh13634_non_skew_symmetric_float   r   z3TestMMIOArray.test_gh13634_non_skew_symmetric_floatN)__name__
__module____qualname__r   r%   r+   r-   r   markparametrizeparametrize_argsr9   r?   rM   rQ   rS   rT   rY   r]   rb   rf   rh   rk   rn   rr   rx   r}   r   r   r   r   r   r   r   r      s<    





r   c                   @   s  e Zd Zdd Zdd Zdd Zdd Zej	d	e
d
d Zdd Zdd Zdd Zdd Zej	d	e
dd Zej	d	e
dd Zej	d	e
dd Zdd Zdd Zdd Zej	d	e
d d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2S )3TestMMIOSparseCSRc                 C   r   r   r   r   r   r   r   r      r   zTestMMIOSparseCSR.setup_methodc                 C   r    r!   r"   r   r   r   r   r%      r&   z!TestMMIOSparseCSR.teardown_methodc                 C   s<   t | j| tt| j| t| j}t| |  d S r!   )r   r   r   r   r   r	   toarrayr'   r   r   r   r+         
zTestMMIOSparseCSR.checkc                 C   s<   t | j| tt| j| t| j}t| |  d S r!   )r   r   r   r   r   r   r'   r   r   r   r-      r   zTestMMIOSparseCSR.check_exactr.   c              	   C   s4   |  tjjddgddgg|ddddd|df d S )Nr/   r0   r1   r2   r3   
coordinater5   r-   r   sparse
csr_matrixr7   r   r   r   r9         z%TestMMIOSparseCSR.test_simple_integerc                 C   2   t jtddgddggtjd}| |d d S )Nr;   i  r=   r>   r3   r0   r0   r2   r   r   r5   )r   r   r   r   rF   r   r-   rL   r   r   r   r?         z$TestMMIOSparseCSR.test_32bit_integerc                 C   sV   t jtddgddggtjd}tdjdk r#tt	t
| j| d S | |d d S )N        rB   r3   r   rD   r   )r   r   r   r   rF   rG   rH   rI   rJ   rK   r   r   r-   rL   r   r   r   rM      s   z$TestMMIOSparseCSR.test_64bit_integerc                 C   r   )Nr;   r<   r=   r>   r3   r0   r0   r2   r   r   r5   )r   r   r   r   rF   Zuint32r-   rL   r   r   r   test_32bit_unsigned_integer   r   z-TestMMIOSparseCSR.test_32bit_unsigned_integerc                 C   s2   t jtddgddggtjd}| |d d S )Nr   rN   rO   r3   r   )r   r   r   r   rF   rP   r-   rL   r   r   r   rQ      r   z-TestMMIOSparseCSR.test_64bit_unsigned_integerc              	   C   s4   |  tjjddgddgg|ddddd|df d S Nr   r/   r3   r0   r   r5   r   r7   r   r   r   rS      r   z4TestMMIOSparseCSR.test_simple_upper_triangle_integerc              	   C   s4   |  tjjddgddgg|ddddd|df d S r   r   r7   r   r   r   rT      r   z4TestMMIOSparseCSR.test_simple_lower_triangle_integerc              	   C   s4   |  tjjg dg dg|ddddd|df d S )	NrU   rV   r3   r0   r1   rX   r   r5   r   r7   r   r   r   rY      r   z1TestMMIOSparseCSR.test_simple_rectangular_integerc                 C   s*   |  tjddgddgddggd d S )Nr/   r0   rZ   r2   rW   rX   )r1   r0   rX   r   r[   r5   r+   r   r   r   r   r   r   r   r]          z/TestMMIOSparseCSR.test_simple_rectangular_floatc                 C   $   |  tjddgddggd d S )Nr/   r0   r1   r`   r0   r0   r2   r   r[   r5   r   r   r   r   r   rb         z#TestMMIOSparseCSR.test_simple_floatc                 C   r   )Nr/   r0   r1   rd   )r0   r0   r2   r   re   r5   r   r   r   r   r   rf      r   z%TestMMIOSparseCSR.test_simple_complexc              	   C   s4   |  tjjddgddgg|ddddd|df d S )Nr/   r0   r2   r3   r1   r   rg   r   r7   r   r   r   rh      r   z/TestMMIOSparseCSR.test_simple_symmetric_integerc                 C   s$   |  tjddgddggd d S )Nr   r0   ri   )r0   r0   r/   r   r   rj   r   r   r   r   r   rk      r   z4TestMMIOSparseCSR.test_simple_skew_symmetric_integerc                 C   s*   |  tjtddgddggdd d S )Nr   r0   rl   rm   )r0   r0   r/   r   r[   rj   )r+   r   r   r   r   r   r   r   r   rn      r   z2TestMMIOSparseCSR.test_simple_skew_symmetric_floatc                 C   r   )Nr/   ro   rp   r2   )r0   r0   r1   r   re   rq   r   r   r   r   r   rr      r   z/TestMMIOSparseCSR.test_simple_hermitian_complexc                 C   s8   d}t j|}|t| }tj|}| |d d S )Nrs   )rt   rt      r   r[   rg   )rF   ru   r   r   r   r   r+   rv   r   r   r   rx      s
   z-TestMMIOSparseCSR.test_random_symmetric_floatc                 C   s,   d}t j|}tj|}| |d d S )Nrz   )rt   r{   r|   r   r[   r5   )rF   ru   r   r   r   r+   rv   r   r   r   r}      ry   z/TestMMIOSparseCSR.test_random_rectangular_floatc                 C   sv   t jddgddgg}t| }d|| dk< d}t| j|dd tt	| j| t
| j}t||  d S )	Nr   g      ?g      @g      @r/   )r0   r0   r1   r   patternr5   r   )field)r   r   r   rF   Z
zeros_liker   r   r   r   r   r   r	   )r   r(   pr)   r*   r   r   r   test_simple_pattern   s   
z%TestMMIOSparseCSR.test_simple_patternc                 C   .   t jjddgddggtjd}| |d d S )Nr/   r0   ri   r   r3   r   )r   r   r   rF   r   r-   rL   r   r   r   r        z5TestMMIOSparseCSR.test_gh13634_non_skew_symmetric_intc                 C   r   )Nr/   r0   ri   r   r3   r   )r   r   r   rF   r   r+   rL   r   r   r   r     r   z7TestMMIOSparseCSR.test_gh13634_non_skew_symmetric_floatN)r   r   r   r   r%   r+   r-   r   r   r   r   r9   r?   rM   r   rQ   rS   rT   rY   r]   rb   rf   rh   rk   rn   rr   rx   r}   r   r   r   r   r   r   r   r      s<    
	




r   z]%%MatrixMarket matrix array integer general
2  2
2147483647
2147483646
2147483647
2147483646
z]%%MatrixMarket matrix coordinate integer symmetric
2  2  2
1  1  2147483647
2  2  2147483646
z%%MatrixMarket matrix array integer general
2  2
          2147483648
-9223372036854775806
         -2147483648
 9223372036854775807
z%%MatrixMarket matrix coordinate integer general
2  2  3
1  1           2147483648
1  2  9223372036854775807
2  2  9223372036854775807
z%%MatrixMarket matrix coordinate integer symmetric
2  2  3
1  1            2147483648
1  2  -9223372036854775807
2  2   9223372036854775807
z%%MatrixMarket matrix coordinate integer skew-symmetric
2  2  3
1  1            2147483648
1  2  -9223372036854775807
2  2   9223372036854775807
z%%MatrixMarket matrix array integer general
2  2
         2147483648
9223372036854775807
         2147483648
9223372036854775808
zq%%MatrixMarket matrix coordinate integer symmetric
2  2  2
1  1            2147483648
2  2  19223372036854775808
c                   @   sd   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd ZdS )TestMMIOReadLargeIntegersc                 C   r   r   r   r   r   r   r   r   S  r   z&TestMMIOReadLargeIntegers.setup_methodc                 C   r    r!   r"   r   r   r   r   r%   W  r&   z)TestMMIOReadLargeIntegers.teardown_methodc           	      C   s   t | jd}|| W d    n1 sw   Y  tt| j| |r-tdjdk s/|r8tt	t
| j d S t
| j}|sC| }t|| d S )Nwr   rD   )openr   writer   r   rF   rH   rI   rJ   rK   r   r   )	r   exampler(   r)   denseover32over64rm   r*   r   r   r   
check_readZ  s   
z$TestMMIOReadLargeIntegers.check_readc                 C   s4   t ddgddggtjd}| jt|ddddd d S )Nr;   r<   r3   rE   TFr   r   r   )r   rF   rG   r   _32bit_integer_dense_examplerL   r   r   r   test_read_32bit_integer_densef     
z7TestMMIOReadLargeIntegers.test_read_32bit_integer_densec                 C   s4   t ddgddggtjd}| jt|ddddd d S )Nr;   r   r<   r3   r0   r0   r0   r   r   rg   Fr   )r   rF   rG   r   _32bit_integer_sparse_examplerL   r   r   r   test_read_32bit_integer_sparsep  r   z8TestMMIOReadLargeIntegers.test_read_32bit_integer_sparsec                 C   s4   t ddgddggtjd}| jt|ddddd	 d S )
Nr@   i   r   rC   r3   rE   TFr   )r   rF   rG   r   _64bit_integer_dense_examplerL   r   r   r   test_read_64bit_integer_densez  r   z7TestMMIOReadLargeIntegers.test_read_64bit_integer_densec                 C   s4   t ddgddggtjd}| jt|ddddd d S )	Nr@   rC   r   r3   )r0   r0   r1   r   r   r5   FTr   )r   rF   rG   r   %_64bit_integer_sparse_general_examplerL   r   r   r   &test_read_64bit_integer_sparse_general  r   z@TestMMIOReadLargeIntegers.test_read_64bit_integer_sparse_generalc                 C   s4   t ddgddggtjd}| jt|ddddd d S )	Nr@    rC   r3   )r0   r0   r1   r   r   rg   FTr   )r   rF   rG   r   '_64bit_integer_sparse_symmetric_examplerL   r   r   r   (test_read_64bit_integer_sparse_symmetric  r   zBTestMMIOReadLargeIntegers.test_read_64bit_integer_sparse_symmetricc                 C   s4   t ddgddggtjd}| jt|ddddd d S )	Nr@   r   rC   r3   )r0   r0   r1   r   r   rj   FTr   )r   rF   rG   r   "_64bit_integer_sparse_skew_examplerL   r   r   r   #test_read_64bit_integer_sparse_skew  r   z=TestMMIOReadLargeIntegers.test_read_64bit_integer_sparse_skewc                 C   s   | j td ddddd d S )NrE   Tr   )r    _over64bit_integer_dense_exampler   r   r   r   !test_read_over64bit_integer_dense     
z;TestMMIOReadLargeIntegers.test_read_over64bit_integer_densec                 C   s   | j td ddddd d S )Nr   FTr   )r   !_over64bit_integer_sparse_exampler   r   r   r   "test_read_over64bit_integer_sparse  r   z<TestMMIOReadLargeIntegers.test_read_over64bit_integer_sparseN)r   r   r   r   r%   r   r   r   r   r   r   r   r   r   r   r   r   r   r   R  s    





r   a&  %%MatrixMarket matrix coordinate real general
%=================================================================================
%
% This ASCII file represents a sparse MxN matrix with L
% nonzeros in the following Matrix Market format:
%
% +----------------------------------------------+
% |%%MatrixMarket matrix coordinate real general | <--- header line
% |%                                             | <--+
% |% comments                                    |    |-- 0 or more comment lines
% |%                                             | <--+
% |    M  N  L                                   | <--- rows, columns, entries
% |    I1  J1  A(I1, J1)                         | <--+
% |    I2  J2  A(I2, J2)                         |    |
% |    I3  J3  A(I3, J3)                         |    |-- L lines
% |        . . .                                 |    |
% |    IL JL  A(IL, JL)                          | <--+
% +----------------------------------------------+
%
% Indices are 1-based, i.e. A(1,1) is the first element.
%
%=================================================================================
  5  5  8
    1     1   1.000e+00
    2     2   1.050e+01
    3     3   1.500e-02
    1     4   6.000e+00
    4     2   2.505e+02
    4     4  -2.800e+02
    4     5   3.332e+01
    5     5   1.200e+01
a   %%MatrixMarket matrix coordinate complex hermitian
  5  5  7
    1     1     1.0      0
    2     2    10.5      0
    4     2   250.5     22.22
    3     3     1.5e-2   0
    4     4    -2.8e2    0
    5     5    12.       0
    5     4     0       33.32
z%%MatrixMarket matrix coordinate real skew-symmetric
  5  5  7
    1     1     1.0
    2     2    10.5
    4     2   250.5
    3     3     1.5e-2
    4     4    -2.8e2
    5     5    12.
    5     4     0
z%%MatrixMarket matrix coordinate real symmetric
  5  5  7
    1     1     1.0
    2     2    10.5
    4     2   250.5
    3     3     1.5e-2
    4     4    -2.8e2
    5     5    12.
    5     4     8
z%%MatrixMarket matrix coordinate pattern symmetric
  5  5  7
    1     1
    2     2
    4     2
    3     3
    4     4
    5     5
    5     4
a  %%MatrixMarket  MATRIX    Coordinate    Real General

   5  5         8

1 1  1.0
2 2       10.5
3 3             1.5e-2
4 4                     -2.8E2
5 5                              12.
     1      4      6
     4      2      250.5
     4      5      33.32

c                   @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#S )$TestMMIOCoordinatec                 C   r   r   r   r   r   r   r   r     r   zTestMMIOCoordinate.setup_methodc                 C   r    r!   r"   r   r   r   r   r%     r&   z"TestMMIOCoordinate.teardown_methodc                 C   sJ   t | jd}|| |  tt| j| t| j }t|| d S )Nr   )	r   r   r   closer   r   r   r   r	   )r   r   r(   r)   rm   r*   r   r   r   r      s   
zTestMMIOCoordinate.check_readc                 C   4   g dg dg dg dg dg}|  t|d d S N)r/   r   r   rX   r   )r         %@r   r   r   r   r   Q?r   r   )r        Po@r   )\@@r   r   r   r      rW   rW   rD   r   r[   r5   )r   _general_examplerL   r   r   r   test_read_general(     z$TestMMIOCoordinate.test_read_generalc                 C   r   )Nr/   r   r   r   r   )r   r   r   y     Po@Q86r   r   )r   y     Po@Q86@r   r   y       )\@)r   r   r   y        )\@@r   )rW   rW      r   re   rq   )r   _hermitian_examplerL   r   r   r   test_read_hermitian1  r   z&TestMMIOCoordinate.test_read_hermitianc                 C   r   )Nr   )r   r   r   g     Por   r   )r   r   r   r   r   r   )rW   rW   r   r   r[   rj   )r   _skew_examplerL   r   r   r   test_read_skew:  r   z!TestMMIOCoordinate.test_read_skewc                 C   r   )Nr   )r   r   r   r   r   r   )r   r   r   r   rD   )r   r   r   rD   r   )rW   rW   r   r   r[   rg   )r   _symmetric_examplerL   r   r   r   test_read_symmetricC  r   z&TestMMIOCoordinate.test_read_symmetricc                 C   r   )Nr   )r   r/   r   r/   r   )r   r   r/   r   r   )r   r/   r   r/   r/   )r   r   r   r/   r/   )rW   rW   r   r   r   rg   )r   _symmetric_pattern_examplerL   r   r   r   test_read_symmetric_patternL  r   z.TestMMIOCoordinate.test_read_symmetric_patternc                 C   r   r   )r   _empty_lines_examplerL   r   r   r   test_read_empty_linesU  r   z(TestMMIOCoordinate.test_read_empty_linesc                 C   sL   t jd}t| j| tt| jd | }t| j }t	|| d S )N)
   r   )r   r   r   r   r[   rg   )
r   r   
coo_matrixr   r   r   r   r   r   r	   )r   r*   r(   r   r   r   test_empty_write_read^  s   
z(TestMMIOCoordinate.test_empty_write_readc           
      C   s   zdd l }W n
 ty   Y d S w tg d}tg d}tg d}tjj|||ffdd}t| j| d| j }t| jd}|	|d	}|
|  |  W d    n1 s\w   Y  t| }	t|	|  d S )
Nr   r   r   r/   r0   r1   r1   r1   r2   r   r1   r/   r0   r/   r1   r2   r2   g      ?g      @r   r   r   g     qr   g      (@rW   rW   shapez%s.bz2rbwb)bz2ImportErrorr   r   r   r   r   r   r   BZ2Filer   readr   r   r   r	   )
r   r   IJVr*   Zfn_bzip2f_inf_outr(   r   r   r   test_bzip2_py3j  $   

z!TestMMIOCoordinate.test_bzip2_py3c           
      C   s   zdd l }W n
 ty   Y d S w tg d}tg d}tg d}tjj|||ffdd}t| j| d| j }t| jd}||d	}|	|
  |  W d    n1 s\w   Y  t| }	t|	|  d S )
Nr   r   r   r   r   r   z%s.gzr   r   )gzipr   r   r   r   r   r   r   r   r   r  r   r   r   r	   )
r   r	  r  r  r  r*   Zfn_gzipr  r  r(   r   r   r   test_gzip_py3  r  z TestMMIOCoordinate.test_gzip_py3c                 C   |   t g d}t g d}t g d}tjj|||ffdd}t| j| tt| jd | }t	| j }t
|| d S )Nr   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   test_real_write_read  s   
z'TestMMIOCoordinate.test_real_write_readc                 C   r  )Nr   r   y      ?      @y      @       @y      %@?yQ?y     Po@        y     q      @y)\@@@y      (@?r   r   )rW   rW   rD   r   re   r5   r  r  r   r   r   test_complex_write_read  s   
z*TestMMIOCoordinate.test_complex_write_readc                 C   s   |d }|   g }tg d}tg d}tg d}|tjj|||ffdd tg d}|tjj|||ffdd |D ]$}| }dD ]}	||	d	  }
t|
||	 t	|
 }t
|| qJqBd S )
NZsparse_formatsr   r   r   r   r   r  )ZcsrZcscZcooz.mtx)mkdirr   appendr   r   r   r   r   Zasformatr   r	   )r   tmp_pathr   Zmatsr  r  r  matexpectedfmtfnameresultr   r   r   test_sparse_formats  s$   z&TestMMIOCoordinate.test_sparse_formatsc                 C   s   t gdd tdddD  }tdd}|D ]M}|D ]H}d| d }tj||f}|||d |d f< t| j||d tj| j}t	|j
|d g t	|j|d g t|jtd	| | g qqd S )
Nc                 S   s   g | ]}d | qS )r   r   ).0ir   r   r   
<listcomp>  s    z5TestMMIOCoordinate.test_precision.<locals>.<listcomp>r   ir/   r   )	precisionz%%.%dg)r   ranger   r   Z
dok_matrixr   r   r   r   r   rowcolr   datafloat)r   Ztest_valuesZtest_precisionsvaluer  nAr   r   r   test_precision  s   
z!TestMMIOCoordinate.test_precisionc                 C   r~   )Na              %%MatrixMarket matrix coordinate real general
              5  5  8 999
                1     1   1.000e+00
                2     2   1.050e+01
                3     3   1.500e-02
                1     4   6.000e+00
                4     2   2.505e+02
                4     4  -2.800e+02
                4     5   3.332e+01
                5     5   1.200e+01
            r   znot of length 3r   r   r   r   r   r   +test_bad_number_of_coordinate_header_fields  s
   "z>TestMMIOCoordinate.test_bad_number_of_coordinate_header_fieldsN)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     s$    						r   c                   C   s   t td d S )Nzg%%MatrixMarket matrix coordinate complex symmetric
 1 1 1
1 1 -2.1846000000000e+02  0.0000000000000e+00)r   r   StringIOr   r   r   r   test_gh11389  s   r*  c                 C   sP   g d}| d }t |d}|| W d    n1 sw   Y  t| d S )N)z/ %%MatrixMarket matrix coordinate real general
z5 5 3
z2 3 1.0
z3 4 2.0
z3 5 3.0
ztest.mtxr   )r   
writelinesr   )r  linesZ	test_filerm   r   r   r   test_gh18123  s   r-  ).tempfiler   r   r   r#   r   numpyrF   r   r   r   Znumpy.testingr   r   r   r	   r   r
   rJ   Zscipy.sparser   Zscipy.ior   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   <module>   sJ    { 			a" ]