+
    h                         ^ RI Ht ^ RIHtHt ^ RIHt ^ RIHt ^ RI	H
t
 ^ RIHtHt ^ RIHt ^ RIt ! R	 R
]4      t ! R R]]4      t ! R R]
]4      tR# )    )Basic)DictTuple)S)_sympify)MutableNDimArray)	NDimArrayImmutableNDimArray)flattenNc                   H   a  ] tR t^t o R tR t]R 4       tR tR t	Rt
V tR# )SparseNDimArrayc                    \        V/ VB # NImmutableSparseNDimArray)selfargskwargss   &*,F/usr/lib/python3/dist-packages/sympy/tensor/array/sparse_ndim_array.py__new__SparseNDimArray.__new__   s    '888    c                   V P                  V4      pVe   V# V P                  V4      p\        V\        4      '       d   \        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       d   V P                  V4      w  r4V Uu. uF;  qPP                  P                  V P                  V4      \        P                  4      NK=  	  pp\        V4       UUu. uF.  w  rW\        W,          \        4      '       g   K#  \        V4      NK0  	  ppp\        V 4      ! Wh4      # V P                  V4      pV P                  P                  V\        P                  4      # u upi u uppi )a  
Get an element from a sparse N-dim array.

Examples
========

>>> from sympy import MutableSparseNDimArray
>>> a = MutableSparseNDimArray(range(4), (2, 2))
>>> a
[[0, 1], [2, 3]]
>>> a[0, 0]
0
>>> a[1, 1]
3
>>> a[0]
[0, 1]
>>> a[1]
[2, 3]

Symbolic indexing:

>>> from sympy.abc import i, j
>>> a[i, j]
[[0, 1], [2, 3]][i, j]

Replace `i` and `j` to get element `(0, 0)`:

>>> a[i, j].subs({i: 0, j: 0})
0

c              3   B   "   T F  p\        V\        4      x  K  	  R # 5ir   
isinstanceslice.0is   & r   	<genexpr>.SparseNDimArray.__getitem__.<locals>.<genexpr>7        +P%QJq%,@,@%   TF)_check_symbolic_index_check_index_for_getitemr   tupleany _get_slice_data_for_array_access_sparse_arrayget_parse_indexr   Zero	enumerater   lentype)	r   indexsyindex
sl_factorseindicesr    arrayelnshapes	   &&       r   __getitem__SparseNDimArray.__getitem__   s   @ ,,U3N--e4 eU##+P%+P+P%+P(P(P#'#H#H#O JS[\S[a''++D,=,=a,@!&&IS[E\+4Z+@`+@%!JuxY^D_gc"g+@F`:e,,%%e,E%%))%88 ]`s   AE$! E)E)c                    V ! / V4      # )z'
Return a sparse N-dim array of zeros.
 )clsshapes   &*r   zerosSparseNDimArray.zeros@   s    
 2u~r   c                   ^ RI Hp V P                  4       ^8w  d   \        R4      h/ pV P                  P                  4        F  w  r4WBV P                  V4      &   K  	  V! V P                  ^ ,          V P                  ^,          V4      # )a%  
Converts MutableDenseNDimArray to Matrix. Can convert only 2-dim array, else will raise error.

Examples
========

>>> from sympy import MutableSparseNDimArray
>>> a = MutableSparseNDimArray([1 for i in range(9)], (3, 3))
>>> b = a.tomatrix()
>>> b
Matrix([
[1, 1, 1],
[1, 1, 1],
[1, 1, 1]])
)SparseMatrixzDimensions must be of size of 2)sympy.matricesrA   rank
ValueErrorr*   items_get_tuple_indexr=   )r   rA   
mat_sparsekeyvalues   &    r   tomatrixSparseNDimArray.tomatrixG   su      	099;!>??
,,224JC5:t,,S12 5 DJJqM4::a=*EEr   c                    \         P                  ! R  V4      pW P                  8w  d   \        RV,           4      h\	        V 4      ! V P
                  V4      # )c                     W,          # r   r;   xys   &&r   <lambda>)SparseNDimArray.reshape.<locals>.<lambda>b   s    acr   zInvalid reshape parameters )	functoolsreduce
_loop_sizerD   r0   r*   )r   newshapenew_total_sizes   &* r   reshapeSparseNDimArray.reshapea   sF    "))/8D__,:XEFFDz$,,h77r   r;   N)__name__
__module____qualname____firstlineno__r   r8   classmethodr>   rJ   rX   __static_attributes____classdictcell____classdict__s   @r   r   r      s4     9.9`  F48 8r   r   c                   6   a  ] tR t^ht o RR ltR tR tRtV tR# )r   Nc                   V P                   ! W3/ VB w  r$\        \        \        V4      !  pV P	                  WB4       V'       d   \
        P                  ! R  V4      M
\        V4      p\        V\        \        34      '       d   \        V4      pM5/ p\        \        V4      4       F  w  rxV^ 8w  g   K  \        V4      Wg&   K  	  \        V4      p\        P                  ! WV3/ VB p	W)n        \        V4      V	n        WYn        Win        V	# )c                     W,          # r   r;   rN   s   &&r   rQ   2ImmutableSparseNDimArray.__new__.<locals>.<lambda>n   s    r   )_handle_ndarray_creation_inputsr   mapr   _check_special_boundsrS   rT   r/   r   dictr   r.   r   r   r   _shape_rankrU   r*   )
r<   iterabler=   r   	flat_list	loop_sizesparse_arrayr    r6   r   s
   &&&,      r   r    ImmutableSparseNDimArray.__new__j   s    >>xYRXYs8U+,!!)3@EI$$_e<3y>	 i$..	?LL"79#567&.rlLO 7 L)}}S@@Z
#)r   c                    \        R 4      h)zimmutable N-dim array)	TypeError)r   r1   rI   s   &&&r   __setitem__$ImmutableSparseNDimArray.__setitem__   s    /00r   c                    \        V 4      # r   )MutableSparseNDimArrayr   s   &r   
as_mutable#ImmutableSparseNDimArray.as_mutable   s    %d++r   rU   rl   rk   r*   NN)	rZ   r[   r\   r]   r   rt   ry   r_   r`   ra   s   @r   r   r   h   s     21, ,r   r   c                   F   a  ] tR t^t o RR ltR tR t]R 4       tRt	V t
R# )rw   Nc                   V P                   ! W3/ VB w  r$\        P                  V 4      pW%n        \	        V4      Vn        V'       d   \        P                  ! R  V4      M
\	        V4      Vn        \        V\        \        34      '       d   \        V4      Vn        V# / Vn        \        \        V4      4       F&  w  rgV^ 8w  g   K  \        V4      VP                  V&   K(  	  V# )c                     W,          # r   r;   rN   s   &&r   rQ   0MutableSparseNDimArray.__new__.<locals>.<lambda>   s    qsr   )rg   objectr   rk   r/   rl   rS   rT   rU   r   rj   r   r*   r.   r   r   )r<   rm   r=   r   rn   r   r    r6   s   &&&,    r   r   MutableSparseNDimArray.__new__   s    >>xYRXY~~c"Z
FK)**?EBQTU^Q_ i$..!%iDKwy12EAQw(0""1% 3 r   c                   \        V\        4      '       d   \        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       d   V P                  W4      w  r#pV F  p\	        WT4       UUu. uF  w  rgVf   K  Wg,
          NK  	  pppW(,          p	V P                  V4      p
V	^ 8w  d   WP                  V
&   K]  WP                  9   g   Ko  V P                  P                  V
4       K  	  R# V P                  V4      p\        V4      pV^ 8X  d.   WP                  9   d   V P                  P                  V4       R# W P                  V&   R# u uppi )zAllows to set items to MutableDenseNDimArray.

Examples
========

>>> from sympy import MutableSparseNDimArray
>>> a = MutableSparseNDimArray.zeros(2, 2)
>>> a[0, 0] = 1
>>> a[1, 1] = 1
>>> a
[[1, 0], [0, 1]]
c              3   B   "   T F  p\        V\        4      x  K  	  R # 5ir   r   r   s   & r   r!   5MutableSparseNDimArray.__setitem__.<locals>.<genexpr>   r#   r$   TFN)	r   r'   r(   $_get_slice_data_for_array_assignmentzipr,   r*   popr   )r   r1   rI   r4   slice_offsetsr    indjother_iother_valuecomplete_indexs   &&&        r   rt   "MutableSparseNDimArray.__setitem__   s    eU##+P%+P+P%+P(P(P-1-V-VW\-d*E]14Q1FX1Fvs!73771FX#n!%!2!21!5!#9D&&~6#'9'99&&**>:  %%e,EUOEze'9'99""&&u-,1""5) Ys   8EEc                    \        V 4      # r   r   rx   s   &r   as_immutable#MutableSparseNDimArray.as_immutable   s    '--r   c                    V P                   P                  4        UUu0 uF  qP                   F  q"kK  	  K  	  upp# u uppi r   )r*   valuesfree_symbols)r   r   r    s   &  r   r   #MutableSparseNDimArray.free_symbols   s5    --446O6a16OOOs   >r{   r|   )rZ   r[   r\   r]   r   rt   r   propertyr   r_   r`   ra   s   @r   rw   rw      s*     (2>. P Pr   rw   )sympy.core.basicr   sympy.core.containersr   r   sympy.core.singletonr   sympy.core.sympifyr   %sympy.tensor.array.mutable_ndim_arrayr   sympy.tensor.array.ndim_arrayr	   r
   sympy.utilities.iterablesr   rS   r   r   rw   r;   r   r   <module>r      sM    " / " ' B G - [8i [8z,0B ,D:P- :Pr   