
    e!h<              	       D   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
mZmZmZmZ ddlmZmZ ddlmZ ej(                  j+                         Zej/                  e       eeegZej2                  ej4                  ej6                  gZej:                  d        Zej:                  d        Zej@                  jC                  d	ee	e
eg      d
        Z"ej@                  jC                  d	eeee	e
eg      d        Z#ej@                  jC                  d	e       G d d             Z$y)z*Test of 1D aspects of sparse array classes    N)assert_equalassert_allclose)	bsr_array	csc_array	dia_array	lil_array	coo_array	csr_array	dok_array)supported_dtypesmatrix)ComplexWarningc                  2    t        j                  g dd      S )N)   r      r   d)nparray     h/var/www/html/diagnosisapp-backend/venv/lib/python3.12/site-packages/scipy/sparse/tests/test_common1d.pydat1dr      s    88L#&&r   c                     t         D ci c]  }|| j                  |       }}t        D ci c]/  }||j                         D cg c]  \  }}|| ||      f c}}1 c}}}S c c}w c c}}w c c}}}w N)math_dtypesastype
spcreatorsitems)r   dtype
dat_dtypes	spcreatordats        r   datsp_math_dtypesr#      s{    :EF%e,,FJF $  	:CSCSCUVZUCUC30VV  GVs   A'A2A,A2,A2r!   c                 x    t        j                  t        d      5   | g d       d d d        y # 1 sw Y   y xY w)Nzarrays don't support 1D inputmatchr   r      r   pytestraises
ValueErrorr!   s    r   test_no_1d_support_in_initr.   (   s.    	z)H	I  ,     s   09c                     t        j                  t        d      5   | t        j                  d             d d d        y # 1 sw Y   y xY w)Nzarrays don't.*support 3Dr%   )r   r(      )r*   r+   r,   r   onesr-   s    r   test_no_nd_support_in_initr2   0   s9     
z)C	D &"'')$%& & &s   AA
c                   ~   e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zej,                  j.                  ed               Zej,                  j.                  ed               Zej,                  j.                  ed               Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%d  Z&y!)"TestCommon1Dz5test common functionality shared by 1D sparse formatsc                     t         |d      j                         t        j                  d             t         |d      j                  d       t         |d      j                         d       y )Nr   r   r   )r   toarrayr   zerosnnzcount_nonzeroselfr!   s     r   test_create_emptyzTestCommon1D.test_create_empty=   sL    Yt_,,.<Yt_((!,Yt_224a8r   c                 t    t        j                  t        d      5   |d       d d d        y # 1 sw Y   y xY w)Nzelements cannot be negativer%   )r)   r;   s     r   test_invalid_shapesz TestCommon1D.test_invalid_shapesB   s.    ]]:-JK 	e	 	 	s   	.7c                 &    t         ||             y r   )reprr<   r!   r   s      r   	test_reprzTestCommon1D.test_reprF   s    Yur   c                 &    t         ||             y r   )strrC   s      r   test_strzTestCommon1D.test_strI   s    Ier   c                 x    t        j                  g dd      }t        |  ||       j                                y )N)r      r   r   r   r   r   r   r   r   r   r   r   r7   r<   r!   As      r   test_negzTestCommon1D.test_negL   s.    HH=sCaR9Q<-0023r   c                 :     |g d      }|j                   dk(  sJ y )Nr'   r   )ndimrN   s      r   test_1d_supported_initz#TestCommon1D.test_1d_supported_initP   s    l#vv{{r   c                     |g d      }|j                  dd      }g dg}t        |j                         |        ||      }|j                  d      }t        |j                         |d          |j                  d      }|j                  |j                  k(  sJ |j                  j                  d      }t        |j                         |d          y )Nr   r      r   r   r   r   r?   r   r   r      r      r   rX   )reshaper   r7   shapeT)r<   r!   xydesiredy2s         r   $test_reshape_1d_tofrom_row_or_columnz1TestCommon1D.test_reshape_1d_tofrom_row_or_columnT   s    ;<IIa89QYY['* gIIbMQYY['!*-YYuww"((""" CCKKOQYY['!*-r   c                 *    |g d      }|j                  d      }g dg dg dg dg}t        |j                         |       |j                  d      }||u sJ |j                  d      }t        |j                         |j                                y )	NrU   )r0   r   )r   r   rV   r   r   r   )r   r?   r   )r   r   rW   rY   rX   )rZ   r   r7   )r<   r!   r]   r^   r_   s        r   test_reshapezTestCommon1D.test_reshapef   su    ;<IIfiY?QYY['*IIeAvvIIbMQYY[!))+.r   c                 r   t         j                  j                  d       t        j                  g d      }t         j                  j	                  d      }t        j                  g       }t        j
                  d      }||||g}|D ]  } ||      }t        j                  d      5  t        j                  |j                               sJ t        |j                         |j                                t        |j                  d       |j                  d              t        |j                  d      |j                  d             t        |j                  d	      |j                  d	             d d d         j                  dt        j
                  d
             y # 1 sw Y   .xY w)Ni  )	r   r   r(   r   rL   rW   rV   	   rW   )(   ignore)overaxisr   rI   r   rl   out)
r   randomseedr   randr8   errstateisscalarsumr   )	r<   r!   dat_1dat_2dat_3dat_4arraysr"   datsps	            r   test_sumzTestCommon1D.test_sumr   sG   
		t67		q!u- 	FCcNE(+ F{{599;///	599;7T 2EII4I4HIQ1BCR 0%)))2DEF F	F 			qbhhrl	+F Fs   )CF,,F6	c                 ~   t        j                  d      }t        j                  g d      } ||      }t        j                  t
        d      5  |j                  d       d d d        t        j                  t        d      5  |j                  d       d d d        t        j                  t        d	      5  |j                  d
       d d d        t        j                  t
        d      5  |j                  d|       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   YxY w# 1 sw Y   y xY w)Nr6   r   r   r(   zaxis must be None, -1 or 0r%   r   rk   Tuples are not acceptedr   r   axis must be an integer      ?"output parameter.*wrong.*dimensionr   rm   )r   r8   r   r*   r+   r,   rt   	TypeErrorr<   r!   rn   r"   rz   s        r   test_sum_invalid_paramsz$TestCommon1D.test_sum_invalid_params   s    hhtnhhy!#]]:-IJ 	II1I	]]9,EF 	#II6I"	#]]9,EF 	 II3I	 ]]:-QR 	'II1#I&	' 	'	 		# 	#	  	 	' 	's0   DD<D'2D3DD$'D03D<c                     t        j                  g d      } ||      }t        j                  |      }t        j                  |      }t        ||       y Nr}   )r   r   rt   r   )r<   r!   r"   rz   dat_sum	datsp_sums         r   test_numpy_sumzTestCommon1D.test_numpy_sum   s=    hhy!#&&+FF5M	+r   c                    t        j                  g d      } ||      }t        |j                         |j                                t        j                  |j                  d             sJ t        |j                  d       |j                  d              t        |j                  d      |j                  d             t        |j                  d      |j                  d             t        j                  t        d      5  |j                  d       d d d        t        j                  t        d      5  |j                  d       d d d        y # 1 sw Y   @xY w# 1 sw Y   y xY w)	Nr}   rk   r   rI   rl   r%   r   )r   r   r   meanrs   r*   r+   r,   )r<   r!   r"   rz   s       r   	test_meanzTestCommon1D.test_mean   s   hhy!#
EJJL1{{5::4:0111d+UZZTZ-BCa(%**!**<=b)5::2:+>?]]:V4 	JJAJ	]]:V4 	 JJBJ	  	 	 		  	 s   E E, E),E5c                    t        j                  t        j                  d            }t        j                  g dg dg dg      } ||      }t	        j
                  t        d      5  |j                  d       d d d        t	        j
                  t        d	      5  |j                  d
       d d d        t	        j
                  t        d      5  |j                  d       d d d        t	        j
                  t        d      5  |j                  d|       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   YxY w# 1 sw Y   y xY w)N)r   r   r}   )r   rL   rW   )rf   rV   rg   zaxis out of ranger%   r   rk   r~   r   r   r   r   r   rm   )	r   asarrayr8   r   r*   r+   r,   r   r   r   s        r   test_mean_invalid_paramsz%TestCommon1D.test_mean_invalid_params   s   jj&)*hh	:z:;#]]:-@A 	JJAJ	]]9,EF 	$JJFJ#	$]]9,EF 	!JJCJ 	!]]:-QR 	(JJA3J'	( 	(	 		$ 	$	! 	!	( 	(s0   *D) D5EE)D25D>E
Ec                     t        j                  g d      } ||      }t        D ]R  }|j                  |      }|j                  |      }t	        ||       t        |j                  |j                         T y Nr}   r   )r   r   r   rt   r   r   r   )r<   r!   r"   rz   r   r   r   s          r   test_sum_dtypezTestCommon1D.test_sum_dtype   sd    hhy!#% 	9EggEg*G			.IGY/	8	9r   c                     t        j                  g d      } ||      }t        D ]R  }|j                  |      }|j                  |      }t	        ||       t        |j                  |j                         T y r   )r   r   r   r   r   r   r   )r<   r!   r"   rz   r   dat_mean
datsp_means          r   test_mean_dtypezTestCommon1D.test_mean_dtype   sf    hhy!#% 	;Exxex,H%0JHj1)9)9:	;r   c                    t        j                  g d      } ||      }t        j                  d      }t        j                  d      }|j                  |       |j                  |       t        ||       |j                  d|       |j                  d|       t        ||       t	        j
                  t        d      5  |j                  t        j                  dg             d d d        t	        j
                  t        d      5  |j                  t        j                  dgg             d d d        y # 1 sw Y   UxY w# 1 sw Y   y xY w)Nr}   r   rn   rm   zoutput parameter.*dimensionr%   )r   r   r   r   r*   r+   r,   )r<   r!   r"   rz   dat_out	datsp_outs         r   test_mean_outzTestCommon1D.test_mean_out   s   hhy!#((1+HHQK	W

y
!+aW%

y
)+]]:-JK 	*JJ288QC=J)	*]]:-JK 	,JJ288aSE?J+	, 	,	* 	*	, 	,s   'E(EEEc                     t        j                  g d      } ||      }t        j                  |      }t        j                  |      }t        ||       t	        |j
                  |j
                         y r   )r   r   r   r   r   r   )r<   r!   r"   rz   r   r   s         r   test_numpy_meanzTestCommon1D.test_numpy_mean   sQ    hhy!#773<WWU^
*-X^^Z%5%56r   c                 B   t        j                  g d      }t         ||      j                         |       t        j                  g d      }t         ||      j                         |       t         ||d      j                         |j	                  d             y N)r(   r   r0   y      ?      @r   rI   int16r   )r   r   r   r7   r   rN   s      r   test_from_arrayzTestCommon1D.test_from_array   sr     HHYYq\))+Q/HH&'Yq\))+Q/Yq088:AHHW<MNr   c                 B   g d}t         ||      j                         |       g d}t         ||      j                         t        j                  |             t         ||d      j                         t        j                  |      j	                  d             y r   )r   r7   r   r   r   rN   s      r   test_from_listzTestCommon1D.test_from_list   st     Yq\))+Q/Yq\))+RXXa[9aw'//1288A;3E3Eg3N	
r   c                 p   t        j                  g d      }t        |      }t         ||      j	                         |        ||      }t         ||      j	                         |       t        j                  g d      }t        |      }t         ||      j	                         |       t         ||d      j	                         |j                  d              ||      }t         ||      j	                         |       t         ||d      j	                         |j                  d             y )N)r   r   r   r   r   r   )r   r   r	   r   r7   r   r<   r!   DSs       r   test_from_sparsezTestCommon1D.test_from_sparse  s     HHYaLYq\))+Q/aLYq\))+Q/HH&'aLYq\))+Q/Yq088:AHHW<MNaLYq\))+Q/Yq088:AHHW<MNr   c                     ||      }|j                         }t        ||       |j                  j                  |j                  j                  k(  sJ |j                  d      }t        ||       |j                  j                  sJ |j                  j                  sJ |j                  d      }t        ||       |j                  j                  sJ |j                  j                  sJ t        j                  |j                  |j                        }|j                  |       t        ||       d|d<   |j                  |       t        ||       t        j                  g d      }t        j                  ||      }t        j                  ||j                               }t        ||       t        j                  g d      }	t        j                  ||	      }t        j                  |j                         |	      }t        ||        ||t              }
|j                  t              }t        |
j                         |       y )	NC)orderFr   r         ?.)r          @      @g      @)r7   r   flagsc_contiguousf_contiguousr   r8   r[   r   r   dotboolr   )r<   r!   r   rz   chkrn   adense_dot_densecheckbspboolarrbools               r   test_toarrayzTestCommon1D.test_toarray  s   % mmoS% yy%%)?)???? mm#m&S% yy%%%%yy%%%% mm#m&S% yy%%%%yy%%%% hhu{{%++6#S%  C#S%  HH)*&&E*q%--/*_e,HH)*&&*u}}*_e, 5-,,t$V^^%w/r   c                     ||   D ]g  \  }}}|j                         }d|d<   |}||z   }t        ||j                         |z          ||dd z   }t        ||j                         |d   z          i y )Nr   r   r   copyr   r7   	r<   r!   r#   r   r"   rz   r   r   cs	            r   test_addzTestCommon1D.test_addC  s}    !29!= 
	0E3
AAaDAAAAIIK!O, AaF
AAIIK!A$./
	0r   c                     ||   D ]?  \  }}}|j                         }d|d<   |}||z   }t        |||j                         z          A y )Nr   r   r   r   s	            r   	test_raddzTestCommon1D.test_raddP  sS    !29!= 	-E3
AAaDAAAA		O,	-r   c                 V   ||   D ]   \  }}}|t        j                  d      k(  r!t        ||z
  g d       t        ||z
  g d       t        d|z
  j                         |         |g dd      }t        ||z
  ||j                         z
         t        ||z
  |j                         |z
         t        |j                         |z
  |j                         |z
         t        ||j                         z
  ||j                         z
         t        |d d |z
  |d d |z
         # y )Nr   )r   r   r   r   r   )r   rL   r   r(   r   r   r   )r   r   r   r7   )r<   r!   r#   r   r"   rz   rO   s          r   	test_rsubzTestCommon1D.test_rsubX  s   !29!= 	9E3((#+5%#+5!e),,.5-s3A#'C!))+$56!c'AIIK#$56u,aiikC.?@,cAIIK.?@ Ra5#bq'C-8!	9r   c                    t        j                  g dg dg dg      }t        j                  g d      } ||      } ||      }t        ||z  j                         ||z         t        ||z  ||z         t        ||z  ||z         t        ||z  j                         ||z         t        ||z  ||z         t        ||z  ||z         t        ||z  ||z         t        ||z  ||z         t        ||z  ||z         t        ||z  j                         ||z         t        ||z  ||z         t        ||z  ||z         y )Nr(   r   r   rc   r}   r   r   r   rM   )r<   r!   rO   vAspvsps         r   test_matmul_basiczTestCommon1D.test_matmul_basick  s,   HHk9i89HHYll 	cCi((*AE2QWa!e$S1Wa!e$cCi((*AE2S1Wa!e$QWa!e$S3YA&QWa!e$S1Wa!e$cCi((*AE2QWa!e$S1Wa!e$r   c                 B   t        j                  g d      } ||      }t        j                  g dg      j                  }t        ||z  |j	                         |z         |t        j                  g d      z  j
                  dk(  sJ |t        j                  g d      z  dk(  sJ |t        j                  g d      z  j
                  dk(  sJ |t        j                  dgdgdgg      z  j
                  dk(  sJ t        |t        g dg      j                  z  t         j                        sJ t        j                  ddg      t        j                  g d	      t        j                  dgdgg      g}|D ]+  }t        j                  t        d
      5  ||z   d d d        - t        j                  |j	                         g d      }t        |t        j                  g d      z  |       t        |dgdgdggz  |j                         y # 1 sw Y   xY w)Nr   )r   r(   r   r      r   r(   r   )r   r   r(   r   r0   zdimension mismatchr%   )r   r   r\   r   r7   r[   
isinstancer   ndarrayr*   r+   r,   r   )r<   r!   rO   r   colbad_vecsr]   
dot_results           r   test_matveczTestCommon1D.test_matvec  s   HH[!lhh	{#%%c	3;;=3#67BHHY''.."444RXXi((B...bhhy))00B666bhhaS1#//66$>>>#	{ 3 5 55rzzBBB HHaV$bhh|&<bhhaSz>RS 	Az1EF a 	 VVCKKM95
bhhy11:>sQC!o-z||< s   HH	c                      ||      }t        g d|z  t        j                  g d|j                                      t        j                  g dg      }t        ||z  ||j                         z         y )Nr   )r   r   r   r7   r   )r<   r!   r   Mrows        r   test_rmatveczTestCommon1D.test_rmatvec  sU    eq("&&qyy{*KLhh~&aqyy{!23r   c                    |t        j                  g       fD ]l  } ||      }t        |j                         |       t        |j	                         j                         |       t        |j
                  |j
                         n y r   )r   r   r   r7   	transposer   )r<   r!   r   rO   Bs        r   test_transposezTestCommon1D.test_transpose  sb    "& 	+A!Aa(..0!4!''*		+r   c                 p    ||   D ].  \  }}}||z   }t        |||z          ||z   }t        |||z          0 y r   )r   )r<   r!   r#   r   r"   rz   sum1sum2s           r   test_add_dense_to_sparsez%TestCommon1D.test_add_dense_to_sparse  sK    !29!= 	*E3;DsSy)3;DsSy)		*r   c                     t        j                  d      } ||      }|j                  dvr!t        ||      D ]  \  }}t	        ||        y y )NrW   )coodiabsr)r   arangeformatzipr   )r<   r!   r   rO   r]   r^   s         r   test_iteratorzTestCommon1D.test_iterator  sM    IIaLaL8800Aq	 #1Q"# 1r   c                     t        j                  g d      } ||      }|j                  d      J t        |j	                         g d       |j                  d       t        |j	                         g d       y )N)r   r   r   r0   r6   r   )rW   )r   r   r   r   r   )r   r   resizer   r7   r   s       r   test_resizezTestCommon1D.test_resize  sX    HH\"aLxx~%%%QYY[),	QYY[/2r   N)'__name__
__module____qualname____doc__r=   r@   rD   rG   rP   rS   ra   rd   r{   r   r   r   r   r   r   r   r   r*   markthread_unsafesup_complexr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r4   r4   9   s   ?9
4.$
/,(', (	9	;,(7 [[O  O [[
  
 [[O  O,0\0-9&%*=64+*#3r   r4   )%r   r*   numpyr   numpy.testingr   r   scipy.sparser   r   r   r   r	   r
   r   scipy.sparse._sputilsr   r   scipy._lib._utilr   testingsuppress_warningsr   filterr   int64float64
complex128r   fixturer   r#   r   parametrizer.   r2   r4   r   r   r   <module>r     s1   0   7   ; + jj**,   > " I.
xxR]]3 ' '   y)Y	&RS  T  )Y	9iS&& j1E3 E3 2E3r   