
    (phx                        S r Sr/ SQrSSKJr  SSKrSSKJr  SSK	J
r
  SS	KJrJr  SS
KJr  SSKJrJrJrJr  SSKJrJrJrJrJrJr  SSKJr  SSKJrJrJ r J!r!J"r"J#r#J$r$   " S S\\5      r%S r& " S S\%\5      r' " S S\
\%5      r(g)z"Compressed Block Sparse Row formatzrestructuredtext en)	bsr_array
bsr_matrixisspmatrix_bsr    )warnN)copy_if_needed   )spmatrix)_data_matrix_minmax_mixin)
_cs_matrix)issparse_formats_spbasesparray)isshapegetdtypegetdata	to_nativeupcastcheck_shape)_sparsetools)
bsr_matvecbsr_matvecscsr_matmat_maxnnz
bsr_matmatbsr_transposebsr_sort_indices	bsr_tocsrc                      \ rS rSrSr  S!SS.S jjrS"S jr\S\4S j5       r	S#S	 jr
\R                  R                  \
l        S#S
 jr\R                  R                  \l        S rS$S jr\R                  R                  \l        S rS rS rS rS rS rS%S jrS&S jr\R.                  R                  \l        S&S jr\R0                  R                  \l        S"S jrS'S jr\R4                  R                  \l        S%S jr\R6                  R                  \l        S rS rS rS rS'S jr S"S jr!S&S jr"S r#g)(	_bsr_base   bsrNmaxprintc                   [         R                  " XUS9  [        U5      (       a  UR                  U R                  :X  a  U(       a  UR	                  5       nOUR                  US9nUR                  UR                  UR                  UR                  4u  U l        U l        U l        U l	        GO[        U[        5      (       Ga  [        U5      (       a  [        U5      U l	        U R                  u  pxUc  SnO)[        U5      (       d  [        SU 35      e[        U5      n[         R"                  " SU-   [%        U[&        S95      U l        Uu  pXy-  S:w  d  X-  S:w  a  [        S5      eU R)                  [+        Xy-  X-  X5      S	9n[         R"                  " SUS
9U l        [         R"                  " Xy-  S-   US
9U l        GO[-        U5      S:X  ah  U R/                  XUS9nUR                  US9nUR                  UR                  UR                  UR                  4u  U l        U l        U l        U l	        GO[-        U5      S:X  Ga<  Uu  pnSnUb  [+        U5      nUb  [+        U[+        U5      5      nU R)                  UU4USS9nU(       d  [0        n[         R2                  " XUS9U l        [         R2                  " UXKS9U l        [5        XUS9U l        U R                  R6                  S:w  a"  [        SU R                  R                   35      eUbl  [        U5      (       d  [        SU 35      e[        U5      U R                  R                  SS  :w  a(  [        SU SU R                  R                  SS   35      eO[        S5      e [         R8                  " U5      n[        U [<        5      (       a)  UR6                  S:w  a  [        SUR6                   S35      eU R/                  XS
9R                  US9nUR                  UR                  UR                  UR                  4u  U l        U l        U l        U l	        Ub  [        U5      U l	        OgU R                  cZ   [-        U R                  5      S-
  nU R                  R+                  5       S-   nU R>                  u  p[        Xy-  X-  45      U l	        U R                  c  Uc  [        S5      e[        U5      U l	        Ub2  U R                  RA                  [%        X0R                  5      SS9U l        U RC                  SS9  g ! [:         a  n[        SU R                   S35      UeS nAff = f! [:         a  n[        S5      UeS nAff = f)Nr#   	blocksize)r   r   zinvalid blocksize=r   )defaultr   z#shape must be multiple of blocksizemaxvaldtyper      )r-   shape   T)r+   check_contents)copyr-   z*BSR data must be 3-dimensional, got shape=zmismatching blocksize=z vs z(unrecognized bsr_array constructor usagezunrecognized form for z_matrix constructorzBSR arrays don't support zD input. Use 2Dz!unable to infer matrix dimensionszneed to infer shapeFr2   )
full_check)"r
   __init__r   formatr2   tobsrindptrindicesdata_shape
isinstancetupler   r   r/   
ValueErrornpzerosr   float_get_index_dtypemaxlen_coo_containerr   arrayr   ndimasarray	Exceptionr   r'   astypecheck_format)selfarg1r/   r-   r2   r'   r$   MNRC	idx_dtypecoor"   r:   r9   r8   r+   es                      D/var/www/html/venv/lib/python3.13/site-packages/scipy/sparse/_bsr.pyr5   _bsr_base.__init__   s   d8<D>>{{dkk)dyy{zzIz6T\\499dkkA=DKty$+ U##t}})$/jj$ %I"9--(+=i[)IJJ %i 0IHHTI%5xu7UV	Ea<AEa<$%JKK !11QT149N1O	!xx; hhqtaxyATa))$5)Iii)i4JJSXXszzEAT\49dk Ta*.' $ ZF( Y8F 117F2CFAE 2 G	)D!xx)L hhvDJ#D5A	99>>Q&$DTYY__DUV  ("9--(+=i[)IJJY'499??12+>>(4YK"499??12#6"79 
 !!KLLMzz$' $((TYY!^ #<TYYK!WXX&&t&9??)?TDT\\499dkkA=DKty$+ %e,DKzz!9DKK(1,A((*Q.A ..CA"-qs13i"8DK::} !677)%0		((%)C%(PDIU+E  M !9$(KK=0C"E FKLMM$ ! Q$%HIqPQs0   T7 .5U# 7
U UU #
U>-U99U>c                    U R                   u  p#U R                  u  pEU R                  R                  R                  S:w  a,  [        SU R                  R                  R                   S3SS9  U R                  R                  R                  S:w  a,  [        SU R                  R                  R                   S3SS9  U R                  R                  S:w  d  U R                  R                  S:w  a  [        S5      eU R                  R                  S	:w  a  [        S
5      e[        U R                  5      X$-  S-   :w  a(  [        S[        U R                  5      X$-  S-   4-  5      eU R                  S   S:w  a  [        S5      e[        U R                  5      [        U R                  5      :w  a  [        S5      eU R                  S   [        U R                  5      :  a  [        S5      eU R                  5         U(       GaJ  U R                  S:  a  U R                  R                  5       X5-  :  a*  [        SX5-  U R                  R                  5       4-  5      eU R                  R                  5       S:  a  [        S5      e[         R"                  " U R                  5      R                  5       S:  a  [        S5      eU R%                  U R                  U R                  45      n[         R&                  " U R                  US9U l        [         R&                  " U R                  US9U l        [)        U R                  5      U l
        gg)a  Check whether the array/matrix respects the BSR format.

Parameters
----------
full_check : bool, optional
    If `True`, run rigorous check, scanning arrays for valid values.
    Note that activating those check might copy arrays for casting,
    modifying indices and index pointers' inplace.
    If `False`, run basic checks on attributes. O(1) operations.
    Default is `True`.
iz$indptr array has non-integer dtype ()r.   )
stacklevelz%indices array has non-integer dtype (r   z!indices, and indptr should be 1-Dr0   zdata should be 3-Dz&index pointer size (%d) should be (%d)r   z!index pointer should start with 0z*indices and data should have the same sizezQLast value of index pointer should be less than the size of index and data arraysz-column index values must be < %d (now max %d)z column index values must be >= 0z8index pointer values must form a non-decreasing sequencer,   N)r/   r'   r8   r-   kindr   namer9   rG   r>   r:   rD   prunennzrC   minr?   diffrB   rH   r   )rL   r4   rN   rO   rP   rQ   rR   s          rU   rK   _bsr_base.check_format   s    jjnn ;;!!S(78I8I8N8N7OqQ<<""c)89K9K9P9P8QQRS <<!T[[%5%5%:@AA99>>Q122 q(E!$T[[!114!8 <= > >KKNa@AA TYY/IJJKKOc$,,// D E E 	

xx!|<<##%-$%T()dll.>.>.@'A&B C C<<##%)$%GHH774;;'++-1$ &B C C --t||T[[.IJI**T[[	BDK::dll)DDL!$)),DI     returnc                 4    U R                   R                  SS $ )zBlock size of the matrix.r   N)r:   r/   )rL   s    rU   r'   _bsr_base.blocksize   s     yyqr""rc   c                 v    Ub  [        S5      eU R                  u  p#[        U R                  S   5      U-  U-  $ )Nz6_getnnz over an axis is not implemented for BSR formatr[   )NotImplementedErrorr'   intr8   )rL   axisrP   rQ   s       rU   _getnnz_bsr_base._getnnz   sB    % '7 8 8~~4;;r?#a'!++rc   c                 f    Ub  [        S5      e[        R                  " U R                  5       5      $ )Nz:count_nonzero over axis is not implemented for BSR format.)rh   r?   count_nonzero_deduped_data)rL   rj   s     rU   rn   _bsr_base.count_nonzero   s4    %L   2 2 455rc   c                    [         U R                     u  p[        U [        5      (       a  SOSnSR	                  S U R
                   5       5      nSU SU SU R                   SU R                   S	U S
U R                   S3$ )NrF   matrixxc              3   8   #    U  H  n[        U5      v   M     g 7fN)str).0rs   s     rU   	<genexpr>%_bsr_base.__repr__.<locals>.<genexpr>   s     4^SVV^s   <z sparse z of dtype 'z'
	with z stored elements (blocksize=z) and shape >)	r   r6   r<   r   joinr'   r-   r_   r/   )rL   _fmt
sparse_clsbs        rU   __repr___bsr_base.__repr__   s    $++& *4 9 9Wx
HH4T^^44uHZLDJJ< @hhZ;A3l4::,VWY	
rc   c                    U R                   u  p#X* ::  d  X:  a)  [        R                  " SU R                  R                  S9$ U R
                  u  pE[        R                  " [        U[        US5      -   U[        US5      -
  5      [        U R                  5      S9n[        R                  " XU-  X5-  XEU R                  U R                  [        R                  " U R                  5      U5	        U$ Nr   r,   )r/   r?   emptyr:   r-   r'   r@   r`   rC   r   r   bsr_diagonalr8   r9   ravel)rL   krowscolsrP   rQ   ys          rU   diagonal_bsr_base.diagonal   s    ZZ
:88ATYY__55~~HHSAq	)4#a)+;<!$**-/!!!QY	1"&++t||"$((499"5q	: rc   c                     [         eru   rh   )rL   keys     rU   __getitem___bsr_base.__getitem__      !!rc   c                     [         eru   r   )rL   r   vals      rU   __setitem___bsr_base.__setitem__  r   rc   c                 >    U R                  SS9R                  U5      $ NFr3   )tocoo
_add_dense)rL   others     rU   r   _bsr_base._add_dense  s    zzuz%0077rc   c                 @   U R                   u  p#U R                  u  pE[        R                  " U R                   S   [	        U R
                  UR
                  5      S9n[        X$-  X5-  XEU R                  U R                  U R                  R                  5       X5	        U$ r   )r/   r'   r?   r@   r   r-   r   r8   r9   r:   r   )rL   r   rN   rO   rP   rQ   results          rU   _matmul_vector_bsr_base._matmul_vector  su    jjnn$**Q-vdjj%++/NO14qKKtyy'8	 rc   c                    U R                   u  p#U R                  u  pEUR                  S   n[        R                  " XF4[	        U R
                  UR
                  5      S9n[        XB-  XS-  XbUU R                  U R                  U R                  R                  5       UR                  5       UR                  5       5
        U$ )Nr   r,   )r'   r/   r?   r@   r   r-   r   r8   r9   r:   r   )rL   r   rP   rQ   rN   rO   n_vecsr   s           rU   _matmul_multivector_bsr_base._matmul_multivector  s    nnjjQ1*F4::ekk,JKAD!$1T\\499??+<v||~	/ rc   c                    U R                   u  p#UR                   u  pEU R                  u  pgUR                  S:X  a  UR                  S   nOSnUR                  S:X  a  US:X  a  UR                  Xx4SS9nOUR                  Xx4S9nU R	                  U R
                  U R                  UR
                  UR                  45      n	[        X&-  XX-  U R
                  R                  U	5      U R                  R                  U	5      UR
                  R                  U	5      UR                  R                  U	5      5      n
U R	                  U R
                  U R                  UR
                  UR                  4U
S9n	[        R                  " U R
                  R                   U	S9n[        R                  " XS9n[        R                  " Xh-  U
-  [        U R                  UR                  5      S9n[        XU-  XX-  XhUU R
                  R                  U	5      U R                  R                  U	5      [        R                  " U R                  5      UR
                  R                  U	5      UR                  R                  U	5      [        R                  " UR                  5      UUU5        UR!                  S	Xh5      nU R#                  XU4X%4Xh4S
9$ )Nr"   r   csrF)r'   r2   r&   r*   r,   r[   )r/   r'   )r/   r'   r6   r7   rB   r8   r9   r   rJ   r?   r   r   r-   r   r   r:   reshape_bsr_container)rL   r   rN   K1K2rO   rP   nrQ   rR   bnnzr8   r9   r:   s                 rU   _matmul_sparse_bsr_base._matmul_sparse)  sT   

nn <<5 "AA<<5 Q!VKK1%eK<EKK1%K0E))4;;+0<<+H I	 !qt!%!3!3I!>!%!4!4Y!?!&!4!4Y!?!&!5!5i!@	B ))4;;+0<<+H15 * 7	 $++++9=((41xxDtzz%++(FG4AqtQ1;;%%i0<<&&y188DII&<<&&y1==''	288EJJ'		 ||Bq# ""F#A6aV # 
 	
rc   c                     USU R                   4;  a  U R                  5       R                  US9$ U(       a  U R                  5       $ U $ )a  Convert this array/matrix into Block Sparse Row Format.

With copy=False, the data/indices may be shared between this
array/matrix and the resultant bsr_array/bsr_matrix.

If blocksize=(R, C) is provided, it will be used for determining
block size of the bsr_array/bsr_matrix.
Nr&   )r'   tocsrr7   r2   )rL   r'   r2   s      rU   r7   _bsr_base.tobsra  sC     T4>>22::<%%	%::99;Krc   c                 2   U R                   u  p#U R                  u  pEU R                  nU R                  U R                  U R
                  4[        Xc5      S9n[        R                  " US-   US9n[        R                  " XgS9n	[        R                  " U[        U R                  5      S9n
[        X$-  X5-  XEU R                  R                  USS9U R
                  R                  USS9U R                  UU	U
5
        U R                  XU4U R                   S9$ )Nr*   r   r,   Fr3   r/   )r/   r'   r_   rB   r8   r9   rC   r?   r   r   r-   r   rJ   r:   _csr_container)rL   r2   rN   rO   rP   rQ   r_   rR   r8   r9   r:   s              rU   r   _bsr_base.tocsrq  s    zz~~hh))4;;*E14S * >	!a%y1((30xx6$**#56!&&++$$YU$;,,%%ie%<))	 ""D6#:$**"MMrc   c                 :    U R                  SS9R                  US9$ r   )r   tocsc)rL   r2   s     rU   r   _bsr_base.tocsc  s!    zzuz%+++66rc   c                    U R                   u  p#U R                  u  pE[        R                  " U R                  5      nUR
                  R                  [        R
                  " [        R                  5      R                  :  aI  UR                  [        R                  5      n[        R                  " Xv:g  5      (       a  [        S5      eUnU R                  [        X#5      S9nU[        R                  " X$-  US9-  R                  U5      n	U	R                  XE-  5      R                  SXE5      n	U	[        R                   " [        R                  " XHS9R                  SS5      SU45      -  n	U	R                  S5      n	XPR"                  -  R                  USS9R                  XE-  5      R                  SXE5      n
U
[        R                   " [        R                  " XXS9US45      -  n
U
R                  S5      n
U R$                  R                  S5      nU(       a  UR'                  5       nU R)                  XU
44U R                   S9$ )	zConvert this array/matrix to COOrdinate format.

When copy=False the data array will be shared between
this array/matrix and the resultant coo_array/coo_matrix.
zMatrix too big to convertr*   r,   r[   r   Fr3   r   )r/   r'   r?   ra   r8   r-   itemsizeintprJ   anyr>   rB   rC   arangerepeatr   tiler9   r:   r2   rE   )rL   r2   rN   rO   rP   rQ   indptr_diffindptr_diff_limitedrR   rowcolr:   s               rU   r   _bsr_base.tocoo  s    jjnnggdkk*%%(9(B(BB"-"4"4RWW"=vv)899 !<==-K))Q);	299QT33;;KHjjo%%b-rwwryy4<<RBQqEJJkk"oLL (((?qsGGBqO 	rwwryy4qe<<kk"oyy  $99;D"":djj # 
 	
rc   c                 :    U R                  SS9R                  XS9$ )NFr3   )orderout)r   toarray)rL   r   r   s      rU   r   _bsr_base.toarray  s!    zzuz%--E-CCrc   c                    Ub  US:w  a  [        S5      eU R                  u  p4U R                  u  pVU R                  X4-  -  nU R                  S:X  a  U R	                  Xe4XC4U R
                  US9$ [        R                  " Xd-  S-   U R                  R
                  S9n[        R                  " XpR                  R
                  S9n	[        R                  " XtU4U R                  R
                  S9n
[        XS-  Xd-  X4U R                  U R                  U R                  R                  5       XU
R                  5       5
        U R	                  XU4Xe4US9$ )N)r   r   zoSparse matrices do not support an 'axes' parameter because swapping dimensions is the only logical permutation.r   )r'   r-   r2   r   r,   )r/   r2   )r>   r'   r/   r_   r   r-   r?   r   r8   r9   r:   r   r   )rL   axesr2   rP   rQ   rN   rO   NBLKr8   r9   r:   s              rU   	transpose_bsr_base.transpose  s5    L M M ~~zzxx!#88q=&&v!-1ZZd ' D D !$($++*;*;<((4||'9'9:xx!DIIOO<adAD!kk4<<1Btzz|	5 ""D6#:*+d # < 	<rc   c                    U R                   (       d  gU R                  u  pU R                  u  p4U R                  S:g  R	                  SX-  5      R                  SS9nUR                  5       S   nU R                  U   U R                  S[        U5      & [        R                  " X1-  XB-  U R                  U R                  U5        U R                  5         g)zRemove zero elements in-place.Nr   r[   r   )rj   )r_   r'   r/   r:   r   sumnonzerorD   r   csr_eliminate_zerosr8   r9   r^   )rL   rP   rQ   rN   rO   masknonzero_blockss          rU   eliminate_zeros_bsr_base.eliminate_zeros  s     xxnnjj		Q''13/333;**.))N*C		&3~&' 	((qtT[[)-t	=

rc   c                 \   U R                   (       a  gU R                  5         U R                  u  pU R                  u  p4X1-  nSnSn[	        U5       H  nUn	U R
                  US-      nX:  a  U R                  U	   n
U R                  U	   nU	S-  n	X:  aC  U R                  U	   U
:X  a0  XR                  U	   -  nU	S-  n	X:  a  U R                  U	   U
:X  a  M0  XR                  U'   XR                  U'   US-  nX:  a  M  X`R
                  US-   '   M     U R                  5         SU l         g)zaEliminate duplicate array/matrix entries by adding them together

The is an *in place* operation
Nr   r   T)	has_canonical_formatsort_indicesr'   r/   ranger8   r9   r:   r^   )rL   rP   rQ   rN   rO   n_rowr_   row_endrX   jjjrs   s               rU   sum_duplicates_bsr_base.sum_duplicates  s&   
 $$~~zz uABkk!A#&G,LL$IIbMalt||B'71'<2&A!GB lt||B'71'< %&S!!"		#q ,  #KK!  	

$(!rc   c           
          U R                   (       a  gU R                  u  pU R                  u  p4[        X1-  XB-  XU R                  U R
                  U R                  R                  5       5        SU l         g)z9Sort the indices of this array/matrix *in place*
        NT)has_sorted_indicesr'   r/   r   r8   r9   r:   r   )rL   rP   rQ   rN   rO   s        rU   r   _bsr_base.sort_indices  sW     ""nnjjqtQ4;;diiooFWX"&rc   c                    U R                   u  pU R                  u  p4[        U R                  5      X1-  S-   :w  a  [	        S5      eU R                  S   n[        U R
                  5      U:  a  [	        S5      e[        U R                  5      U:  a  [	        S5      eU R                  SU U l        U R
                  SU U l        g)z8Remove empty space after all non-zero elements.
        r   z index pointer has invalid lengthr[   z"indices array has too few elementszdata array has too few elementsN)r'   r/   rD   r8   r>   r9   r:   )rL   rP   rQ   rN   rO   r   s         rU   r^   _bsr_base.prune  s     nnjjt{{qtax'?@@{{2t||t#ABBtyy>D >??IIet$	||ET*rc   c                    U R                  XR                  S9n[        [        U R                  U-   U R                  -   5      nU R                  u  pg[        U R                  5      [        UR                  5      -   nU R                  U R                  U R                  UR                  UR                  4US9n	[        R                  " U R                  R                  U	S9n
[        R                  " XS9n/ SQnX,;   a)  [        R                  " Xg-  U-  [        R                  S9nO8[        R                  " Xg-  U-  [        U R                  UR                  5      S9nU" U R                  S   U-  U R                  S   U-  XgU R                  R!                  U	5      U R                  R!                  U	5      U R                  UR                  R!                  U	5      UR                  R!                  U	5      [        R"                  " UR                  5      U
UU5        U
S   nUSU nUSXg-  U-   nXS	-  :  a   UR%                  5       nUR%                  5       nUR'                  SXg5      nU R                  XU
4U R                  S
9$ )z5Apply the binary operation fn to two sparse matrices.r&   r*   r,   )_ne__lt__gt__le__ge_r   r   r[   Nr.   r   )	__class__r'   getattrr   r6   rD   r:   rB   r8   r9   r?   r   r/   bool_r   r-   rJ   r   r2   r   )rL   r   opin_shape	out_shapefnrP   rQ   max_bnnzrR   r8   r9   bool_opsr:   actual_bnnzs                  rU   _binopt_bsr_base._binopt.  s   
 u? \4;;#3dkk#ABnntyy>C

O3))4;;+0<<+H19 * ;	 $++++9=((85;>88ACL9D88ACLtzz%++0NOD
4::a=!TZZ]A-q;;i(<<y)99<<y)==	*88EJJ		 Rj,;'$QS_%!#llnG99;D||Bq#~~tf5TZZ~HHrc   c                 4   U(       aW  U R                  XR                  R                  5       U R                  R                  5       4U R                  UR
                  S9$ U R                  XR                  U R                  4U R                  UR
                  S9$ )zReturns a matrix with the same sparsity structure as self,
but with different data.  By default the structure arrays
(i.e. .indptr and .indices) are copied.
)r/   r-   )r   r9   r2   r8   r/   r-   )rL   r:   r2   s      rU   
_with_data_bsr_base._with_data_  s    
 >>4(9(9(;DKK<L<L<N"O)-$** " F F >>4T[["A)-$** " F Frc   c                 0    [         R                  " XU5      $ ru   )r   _broadcast_to)rL   r/   r2   s      rU   r   _bsr_base._broadcast_tor  s    $$T$77rc   )r;   r:   r   r   r9   r8   )NNFN)Tru   r(   )NF)F)NN)$__name__
__module____qualname____firstlineno___formatr5   rK   propertyr=   r'   rk   r   __doc__rn   r   r   r   r   r   r   r   r   r7   r   r   r   r   r   r   r   r   r^   r   r   r   __static_attributes__ rc   rU   r    r       sG   G:?s,-1s,j<-B #5 # #, oo--GO6 $1199M

 ''//H""8
2
p N* MM))EM7 MM))EM$
LD oo--GO<2  ))11I()B'+*.Ib
F&8rc   r    c                 "    [        U [        5      $ )a  Is `x` of a bsr_matrix type?

Parameters
----------
x
    object to check for being a bsr matrix

Returns
-------
bool
    True if `x` is a bsr matrix, False otherwise

Examples
--------
>>> from scipy.sparse import bsr_array, bsr_matrix, csr_matrix, isspmatrix_bsr
>>> isspmatrix_bsr(bsr_matrix([[5]]))
True
>>> isspmatrix_bsr(bsr_array([[5]]))
False
>>> isspmatrix_bsr(csr_matrix([[5]]))
False
)r<   r   )rs   s    rU   r   r   v  s    . a$$rc   c                       \ rS rSrSrSrg)r   i  a  
Block Sparse Row format sparse array.

This can be instantiated in several ways:
    bsr_array(D, [blocksize=(R,C)])
        where D is a 2-D ndarray.

    bsr_array(S, [blocksize=(R,C)])
        with another sparse array or matrix S (equivalent to S.tobsr())

    bsr_array((M, N), [blocksize=(R,C), dtype])
        to construct an empty sparse array with shape (M, N)
        dtype is optional, defaulting to dtype='d'.

    bsr_array((data, ij), [blocksize=(R,C), shape=(M, N)])
        where ``data`` and ``ij`` satisfy ``a[ij[0, k], ij[1, k]] = data[k]``

    bsr_array((data, indices, indptr), [shape=(M, N)])
        is the standard BSR representation where the block column
        indices for row i are stored in ``indices[indptr[i]:indptr[i+1]]``
        and their corresponding block values are stored in
        ``data[ indptr[i]: indptr[i+1] ]``. If the shape parameter is not
        supplied, the array dimensions are inferred from the index arrays.

Attributes
----------
dtype : dtype
    Data type of the array
shape : 2-tuple
    Shape of the array
ndim : int
    Number of dimensions (this is always 2)
nnz
size
data
    BSR format data array of the array
indices
    BSR format index array of the array
indptr
    BSR format index pointer array of the array
blocksize
    Block size
has_sorted_indices : bool
    Whether indices are sorted
has_canonical_format : bool
T

Notes
-----
Sparse arrays can be used in arithmetic operations: they support
addition, subtraction, multiplication, division, and matrix power.

**Summary of BSR format**

The Block Sparse Row (BSR) format is very similar to the Compressed
Sparse Row (CSR) format. BSR is appropriate for sparse matrices with dense
sub matrices like the last example below. Such sparse block matrices often
arise in vector-valued finite element discretizations. In such cases, BSR is
considerably more efficient than CSR and CSC for many sparse arithmetic
operations.

**Blocksize**

The blocksize (R,C) must evenly divide the shape of the sparse array (M,N).
That is, R and C must satisfy the relationship ``M % R = 0`` and
``N % C = 0``.

If no blocksize is specified, a simple heuristic is applied to determine
an appropriate blocksize.

**Canonical Format**

In canonical format, there are no duplicate blocks and indices are sorted
per row.

**Limitations**

Block Sparse Row format sparse arrays do not support slicing.

Examples
--------
>>> import numpy as np
>>> from scipy.sparse import bsr_array
>>> bsr_array((3, 4), dtype=np.int8).toarray()
array([[0, 0, 0, 0],
       [0, 0, 0, 0],
       [0, 0, 0, 0]], dtype=int8)

>>> row = np.array([0, 0, 1, 2, 2, 2])
>>> col = np.array([0, 2, 2, 0, 1, 2])
>>> data = np.array([1, 2, 3 ,4, 5, 6])
>>> bsr_array((data, (row, col)), shape=(3, 3)).toarray()
array([[1, 0, 2],
       [0, 0, 3],
       [4, 5, 6]])

>>> indptr = np.array([0, 2, 3, 6])
>>> indices = np.array([0, 2, 2, 0, 1, 2])
>>> data = np.array([1, 2, 3, 4, 5, 6]).repeat(4).reshape(6, 2, 2)
>>> bsr_array((data,indices,indptr), shape=(6, 6)).toarray()
array([[1, 1, 0, 0, 2, 2],
       [1, 1, 0, 0, 2, 2],
       [0, 0, 0, 0, 3, 3],
       [0, 0, 0, 0, 3, 3],
       [4, 4, 5, 5, 6, 6],
       [4, 4, 5, 5, 6, 6]])

r  Nr   r   r  r  r  r  r  rc   rU   r   r         krc   r   c                       \ rS rSrSrSrg)r   i   a  
Block Sparse Row format sparse matrix.

This can be instantiated in several ways:
    bsr_matrix(D, [blocksize=(R,C)])
        where D is a 2-D ndarray.

    bsr_matrix(S, [blocksize=(R,C)])
        with another sparse array or matrix S (equivalent to S.tobsr())

    bsr_matrix((M, N), [blocksize=(R,C), dtype])
        to construct an empty sparse matrix with shape (M, N)
        dtype is optional, defaulting to dtype='d'.

    bsr_matrix((data, ij), [blocksize=(R,C), shape=(M, N)])
        where ``data`` and ``ij`` satisfy ``a[ij[0, k], ij[1, k]] = data[k]``

    bsr_matrix((data, indices, indptr), [shape=(M, N)])
        is the standard BSR representation where the block column
        indices for row i are stored in ``indices[indptr[i]:indptr[i+1]]``
        and their corresponding block values are stored in
        ``data[ indptr[i]: indptr[i+1] ]``. If the shape parameter is not
        supplied, the matrix dimensions are inferred from the index arrays.

Attributes
----------
dtype : dtype
    Data type of the matrix
shape : 2-tuple
    Shape of the matrix
ndim : int
    Number of dimensions (this is always 2)
nnz
size
data
    BSR format data array of the matrix
indices
    BSR format index array of the matrix
indptr
    BSR format index pointer array of the matrix
blocksize
    Block size
has_sorted_indices : bool
    Whether indices are sorted
has_canonical_format : bool
T

Notes
-----
Sparse matrices can be used in arithmetic operations: they support
addition, subtraction, multiplication, division, and matrix power.

**Summary of BSR format**

The Block Sparse Row (BSR) format is very similar to the Compressed
Sparse Row (CSR) format. BSR is appropriate for sparse matrices with dense
sub matrices like the last example below. Such sparse block matrices often
arise in vector-valued finite element discretizations. In such cases, BSR is
considerably more efficient than CSR and CSC for many sparse arithmetic
operations.

**Blocksize**

The blocksize (R,C) must evenly divide the shape of the sparse matrix (M,N).
That is, R and C must satisfy the relationship ``M % R = 0`` and
``N % C = 0``.

If no blocksize is specified, a simple heuristic is applied to determine
an appropriate blocksize.

**Canonical Format**

In canonical format, there are no duplicate blocks and indices are sorted
per row.

**Limitations**

Block Sparse Row format sparse matrices do not support slicing.

Examples
--------
>>> import numpy as np
>>> from scipy.sparse import bsr_matrix
>>> bsr_matrix((3, 4), dtype=np.int8).toarray()
array([[0, 0, 0, 0],
       [0, 0, 0, 0],
       [0, 0, 0, 0]], dtype=int8)

>>> row = np.array([0, 0, 1, 2, 2, 2])
>>> col = np.array([0, 2, 2, 0, 1, 2])
>>> data = np.array([1, 2, 3 ,4, 5, 6])
>>> bsr_matrix((data, (row, col)), shape=(3, 3)).toarray()
array([[1, 0, 2],
       [0, 0, 3],
       [4, 5, 6]])

>>> indptr = np.array([0, 2, 3, 6])
>>> indices = np.array([0, 2, 2, 0, 1, 2])
>>> data = np.array([1, 2, 3, 4, 5, 6]).repeat(4).reshape(6, 2, 2)
>>> bsr_matrix((data,indices,indptr), shape=(6, 6)).toarray()
array([[1, 1, 0, 0, 2, 2],
       [1, 1, 0, 0, 2, 2],
       [0, 0, 0, 0, 3, 3],
       [0, 0, 0, 0, 3, 3],
       [4, 4, 5, 5, 6, 6],
       [4, 4, 5, 5, 6, 6]])

r  Nr
  r  rc   rU   r   r      r  rc   r   ))r  __docformat____all__warningsr   numpyr?   scipy._lib._utilr   _matrixr	   _datar
   r   _compressedr   _baser   r   r   r   _sputilsr   r   r   r   r   r    r   r   r   r   r   r   r   r   r    r   r   r   r  rc   rU   <module>r     s}    (%
7   +  . # 7 7$ $ & & &
[	8
M [	8|%6l	7 l^l9 lrc   