U
    ZÊ¹jeJ  ã                   @   sÂ   d dl mZ d dlmZmZ d dlmZ d dlmZm	Z	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lZd dlmZ G dd„ deƒZG dd„ deƒZG dd„ deeƒZd
S )é    )ÚBasic)ÚDictÚTuple)ÚExpr)ÚKindÚ
NumberKindÚUndefinedKind)ÚInteger)ÚS)Úsympify)Ú
SYMPY_INTS)Ú	PrintableN)ÚIterablec                       s>   e Zd ZdZef‡ fdd„	Zdd„ Zed dœdd„ƒZ‡  Z	S )	Ú	ArrayKindaÉ  
    Kind for N-dimensional array in SymPy.

    This kind represents the multidimensional array that algebraic
    operations are defined. Basic class for this kind is ``NDimArray``,
    but any expression representing the array can have this.

    Parameters
    ==========

    element_kind : Kind
        Kind of the element. Default is :obj:NumberKind `<sympy.core.kind.NumberKind>`,
        which means that the array contains only numbers.

    Examples
    ========

    Any instance of array class has ``ArrayKind``.

    >>> from sympy import NDimArray
    >>> NDimArray([1,2,3]).kind
    ArrayKind(NumberKind)

    Although expressions representing an array may be not instance of
    array class, it will have ``ArrayKind`` as well.

    >>> from sympy import Integral
    >>> from sympy.tensor.array import NDimArray
    >>> from sympy.abc import x
    >>> intA = Integral(NDimArray([1,2,3]), x)
    >>> isinstance(intA, NDimArray)
    False
    >>> intA.kind
    ArrayKind(NumberKind)

    Use ``isinstance()`` to check for ``ArrayKind` without specifying
    the element kind. Use ``is`` with specifying the element kind.

    >>> from sympy.tensor.array import ArrayKind
    >>> from sympy.core import NumberKind
    >>> boolA = NDimArray([True, False])
    >>> isinstance(boolA.kind, ArrayKind)
    True
    >>> boolA.kind is ArrayKind(NumberKind)
    False

    See Also
    ========

    shape : Function to return the shape of objects with ``MatrixKind``.

    c                    s   t ƒ  | |¡}||_|S ©N)ÚsuperÚ__new__Úelement_kind)Úclsr   Úobj©Ú	__class__© ú\/var/www/html/bwave/python/venv/lib/python3.8/site-packages/sympy/tensor/array/ndim_array.pyr   D   s    zArrayKind.__new__c                 C   s
   d| j  S )NzArrayKind(%s))r   ©Úselfr   r   r   Ú__repr__I   s    zArrayKind.__repr__)Úreturnc                 C   s.   dd„ |D ƒ}t |ƒdkr"|\}nt}t|ƒS )Nc                 S   s   h | ]
}|j ’qS r   )Úkind©Ú.0Úer   r   r   Ú	<setcomp>N   s     z#ArrayKind._union.<locals>.<setcomp>é   )Úlenr   r   )r   ÚkindsZ
elem_kindsZelemkindr   r   r   Ú_unionL   s
    zArrayKind._union)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   Úclassmethodr&   Ú__classcell__r   r   r   r   r      s
   4r   c                   @   s\  e Zd ZdZdZdZdQdd„Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ Zedd„ ƒZedRdd„ƒZdd„ Z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d)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Z d7d8„ Z!d9d:„ Z"d;d<„ Z#d=d>„ Z$d?d@„ Z%dAdB„ Z&dCdD„ Z'dEdF„ Z(dGdH„ Z)dIdJ„ Z*dKdL„ Z+edMdN„ ƒZ,dOdP„ Z-dS )SÚ	NDimArraya½  N-dimensional array.

    Examples
    ========

    Create an N-dim array of zeros:

    >>> from sympy import MutableDenseNDimArray
    >>> a = MutableDenseNDimArray.zeros(2, 3, 4)
    >>> a
    [[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]]

    Create an N-dim array from a list;

    >>> a = MutableDenseNDimArray([[2, 3], [4, 5]])
    >>> a
    [[2, 3], [4, 5]]

    >>> b = MutableDenseNDimArray([[[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10], [11, 12]]])
    >>> b
    [[[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10], [11, 12]]]

    Create an N-dim array from a flat list with dimension shape:

    >>> a = MutableDenseNDimArray([1, 2, 3, 4, 5, 6], (2, 3))
    >>> a
    [[1, 2, 3], [4, 5, 6]]

    Create an N-dim array from a matrix:

    >>> from sympy import Matrix
    >>> a = Matrix([[1,2],[3,4]])
    >>> a
    Matrix([
    [1, 2],
    [3, 4]])
    >>> b = MutableDenseNDimArray(a)
    >>> b
    [[1, 2], [3, 4]]

    Arithmetic operations on N-dim arrays

    >>> a = MutableDenseNDimArray([1, 1, 1, 1], (2, 2))
    >>> b = MutableDenseNDimArray([4, 4, 4, 4], (2, 2))
    >>> c = a + b
    >>> c
    [[5, 5], [5, 5]]
    >>> a - b
    [[-3, -3], [-3, -3]]

    TFNc                 K   s   ddl m} |||f|ŽS )Nr   )ÚImmutableDenseNDimArray)Úsympy.tensor.arrayr.   )r   ÚiterableÚshapeÚkwargsr.   r   r   r   r   Ž   s    zNDimArray.__new__c                 C   s   t dƒ‚d S )Nz4A subclass of NDimArray should implement __getitem__©ÚNotImplementedError©r   Úindexr   r   r   Ú__getitem__’   s    zNDimArray.__getitem__c                 C   sÈ   t |ttfƒr$|| jkr tdƒ‚|S | jdkr6tdƒ‚t|ƒ| jkrLtdƒ‚d}t| jƒD ]h}|| | j| ks„|| | j|  k r˜tdt	|ƒ d ƒ‚|| dk r¬|d7 }|| j|  ||  }qZ|S )NzOnly a tuple index is acceptedr   z#Index not valid with an empty arrayzWrong number of array axeszIndex z out of borderr#   )
Ú
isinstancer   r	   Ú
_loop_sizeÚ
ValueErrorr$   Ú_rankÚranger1   Ústr)r   r6   Z
real_indexÚir   r   r   Ú_parse_index•   s     

&zNDimArray._parse_indexc                 C   s:   g }t | jƒD ]}| || ¡ || }q| ¡  t|ƒS r   )Úreversedr1   ÚappendÚreverseÚtuple)r   Zinteger_indexr6   Úshr   r   r   Ú_get_tuple_index¬   s    
zNDimArray._get_tuple_indexc                 C   sz   t |tƒr|n|f}tdd„ |D ƒƒrvt|| jƒD ](\}}|dk dksR||kdkr2tdƒ‚q2ddlm} || f|žŽ S d S )Nc                 s   s    | ]}t |tƒo|j V  qd S r   )r8   r   Z	is_number©r    r>   r   r   r   Ú	<genexpr>·   s     z2NDimArray._check_symbolic_index.<locals>.<genexpr>r   Tzindex out of range)ÚIndexed)r8   rC   ÚanyÚzipr1   r:   Zsympy.tensorrH   )r   r6   Ztuple_indexr>   Znth_dimrH   r   r   r   Ú_check_symbolic_index´   s    
zNDimArray._check_symbolic_indexc                 C   s$   ddl m} t|t|tfƒr t‚d S )Nr   ©Ú
MatrixBase)Úsympy.matrices.matrixbaserM   r8   r   r-   r4   )r   ÚvaluerM   r   r   r   Ú_setter_iterable_check¿   s    z NDimArray._setter_iterable_checkc                    s   ‡ fdd„‰ ˆ |ƒS )Nc                    sˆ   t | tƒs| gdfS t| ƒdkr(g dfS g }t‡ fdd„| D ƒŽ \}}tt|ƒƒdkr^tdƒ‚|D ]}| |¡ qb|t|ƒf|d  fS )Nr   r   ©r   c                    s   g | ]}ˆ |ƒ‘qS r   r   rF   ©Úfr   r   Ú
<listcomp>Î   s     z=NDimArray._scan_iterable_shape.<locals>.f.<locals>.<listcomp>r#   z'could not determine shape unambiguously)r8   r   r$   rJ   Úsetr:   Úextend)ZpointerÚresultZelemsZshapesr>   rR   r   r   rS   Æ   s    

z)NDimArray._scan_iterable_shape.<locals>.fr   )r   r0   r   rR   r   Ú_scan_iterable_shapeÄ   s    zNDimArray._scan_iterable_shapec                 K   s@  ddl m} ddlm} |d kr�|d kr2d}d}n^t||ƒrH|j|jfS t|tƒrZ|j}n6t|t	ƒrt|  
|¡\}}nt||ƒr†|j}n
d}|f}t|ttfƒ�r|d k	�r| ¡ }|D ]J}t|ttfƒr¶d}t|ƒD ]\}	}
|||	  |
 }qÔ|| ||< ||= q¶t|ttfƒ�r|f}tdd„ |D ƒƒ�s4tdƒ‚t|ƒ|fS )Nr   rL   ©ÚSparseNDimArrayr   c                 s   s   | ]}t |ttfƒV  qd S r   )r8   r   r	   )r    Údimr   r   r   rG     s     z<NDimArray._handle_ndarray_creation_inputs.<locals>.<genexpr>z#Shape should contain integers only.)rN   rM   r/   rZ   r8   Ú_shapeÚ_sparse_arrayr-   r1   r   rX   r   ÚdictÚcopyrC   r   Ú	enumerater   r	   ÚallÚ	TypeError)r   r0   r1   r2   rM   rZ   Znew_dictÚkZnew_keyr>   Úidxr   r   r   Ú_handle_ndarray_creation_inputs×   s<    



z)NDimArray._handle_ndarray_creation_inputsc                 C   s   | j S )a-  Overload common function len(). Returns number of elements in array.

        Examples
        ========

        >>> from sympy import MutableDenseNDimArray
        >>> a = MutableDenseNDimArray.zeros(3, 3)
        >>> a
        [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
        >>> len(a)
        9

        )r9   r   r   r   r   Ú__len__  s    zNDimArray.__len__c                 C   s   | j S )zà
        Returns array shape (dimension).

        Examples
        ========

        >>> from sympy import MutableDenseNDimArray
        >>> a = MutableDenseNDimArray.zeros(3, 3)
        >>> a.shape
        (3, 3)

        )r\   r   r   r   r   r1     s    zNDimArray.shapec                 C   s   | j S )z×
        Returns rank of array.

        Examples
        ========

        >>> from sympy import MutableDenseNDimArray
        >>> a = MutableDenseNDimArray.zeros(3,4,5,6,3)
        >>> a.rank()
        5

        )r;   r   r   r   r   Úrank&  s    zNDimArray.rankc                 O   s,   ddl m} | dd¡ ||  ¡ f|ž|ŽS )a5  
        Calculate the derivative of each element in the array.

        Examples
        ========

        >>> from sympy import ImmutableDenseNDimArray
        >>> from sympy.abc import x, y
        >>> M = ImmutableDenseNDimArray([[x, y], [1, x*y]])
        >>> M.diff(x)
        [[1, 0], [0, y]]

        r   )ÚArrayDerivativeÚevaluateT)Z$sympy.tensor.array.array_derivativesrh   Ú
setdefaultÚas_immutable)r   Úargsr2   rh   r   r   r   Údiff5  s    zNDimArray.diffc                    s   |   ‡ fdd„¡S )Nc                    s
   ˆ   | ¡S r   )rm   )Úx©Úbaser   r   Ú<lambda>I  ó    z,NDimArray._eval_derivative.<locals>.<lambda>)Ú	applyfunc)r   rp   r   ro   r   Ú_eval_derivativeG  s    zNDimArray._eval_derivativec                 C   s   t  | ||¡S r   )r   Ú_eval_derivative_n_times)r   ÚsÚnr   r   r   ru   K  s    z"NDimArray._eval_derivative_n_timesc                    sn   ddl m} ddlm} t| |ƒrTˆ tjƒdkrTt| ƒ‡ fdd„| j 	¡ D ƒ| j
ƒS t| ƒtˆ || ƒƒ| j
ƒS )a[  Apply a function to each element of the N-dim array.

        Examples
        ========

        >>> from sympy import ImmutableDenseNDimArray
        >>> m = ImmutableDenseNDimArray([i*2+j for i in range(2) for j in range(2)], (2, 2))
        >>> m
        [[0, 1], [2, 3]]
        >>> m.applyfunc(lambda i: 2*i)
        [[0, 2], [4, 6]]
        r   rY   ©ÚFlattenc                    s&   i | ]\}}ˆ |ƒd kr|ˆ |ƒ“qS rQ   r   ©r    rc   ÚvrR   r   r   Ú
<dictcomp>_  s       z'NDimArray.applyfunc.<locals>.<dictcomp>)r/   rZ   Úsympy.tensor.array.arrayopry   r8   r
   ÚZeroÚtyper]   Úitemsr1   Úmap)r   rS   rZ   ry   r   rR   r   rs   N  s
    $zNDimArray.applyfuncc                    s>   ‡ ‡‡fdd„‰ ˆ  ¡ dkr*ˆ ˆd ¡S ˆ ˆjˆjdˆjƒS )Nc                    sn   t ˆƒdkr4dd ‡‡fdd„tˆ |ƒD ƒ¡ d S ˆˆd  ‰dd ‡‡ ‡‡fdd„tˆd ƒD ƒ¡ d S )	Nr#   ú[z, c                    s    g | ]}ˆ   ˆˆ |¡ ¡‘qS r   )Ú_printrE   r   )Úprinterr   r   r   rT   f  s     z2NDimArray._sympystr.<locals>.f.<locals>.<listcomp>ú]r   c              	      s6   g | ].}ˆ ˆˆd d… ˆ|ˆ  ˆ|d  ˆ  ƒ‘qS )r#   Nr   r   )rS   r>   rD   Ú
shape_leftr   r   rT   i  s     )r$   Újoinr<   )rD   r†   r>   Új©rS   r„   r   )r>   rD   r†   r   rS   d  s    (zNDimArray._sympystr.<locals>.fr   r   )rg   rƒ   r9   r1   )r   r„   r   r‰   r   Ú	_sympystrc  s    zNDimArray._sympystrc                    s"   ‡ ‡fdd„‰ ˆ ˆj ˆjdˆj ƒS )a?  
        Converting MutableDenseNDimArray to one-dim list

        Examples
        ========

        >>> from sympy import MutableDenseNDimArray
        >>> a = MutableDenseNDimArray([1, 2, 3, 4], (2, 2))
        >>> a
        [[1, 2], [3, 4]]
        >>> b = a.tolist()
        >>> b
        [[1, 2], [3, 4]]
        c              
      sz   t |ƒdkr$‡fdd„t||ƒD ƒS g }| |d  } t|d ƒD ]4}| ˆ | |dd … |||   ||d |   ƒ¡ q@|S )Nr#   c                    s   g | ]}ˆ ˆ   |¡ ‘qS r   )rE   r   r   r   r   rT   ‚  s     z/NDimArray.tolist.<locals>.f.<locals>.<listcomp>r   )r$   r<   rA   )rD   r†   r>   rˆ   rW   r!   ©rS   r   r   r   rS   €  s    2zNDimArray.tolist.<locals>.fr   )r9   r1   r   r   r‹   r   Útolistp  s    	zNDimArray.tolistc                 C   sZ   ddl m} t|tƒstS | j|jkr.tdƒ‚dd„ t|| ƒ||ƒƒD ƒ}t| ƒ|| jƒS )Nr   rx   úarray shape mismatchc                 S   s   g | ]\}}|| ‘qS r   r   ©r    r>   rˆ   r   r   r   rT   “  s     z%NDimArray.__add__.<locals>.<listcomp>©	r}   ry   r8   r-   ÚNotImplementedr1   r:   rJ   r   ©r   Úotherry   Úresult_listr   r   r   Ú__add__‹  s    
zNDimArray.__add__c                 C   sZ   ddl m} t|tƒstS | j|jkr.tdƒ‚dd„ t|| ƒ||ƒƒD ƒ}t| ƒ|| jƒS )Nr   rx   r�   c                 S   s   g | ]\}}|| ‘qS r   r   rŽ   r   r   r   rT   Ÿ  s     z%NDimArray.__sub__.<locals>.<listcomp>r�   r‘   r   r   r   Ú__sub__—  s    
zNDimArray.__sub__c                    s®   ddl m} ddlm} ddlm} tˆ tt|fƒr<t	dƒ‚t
ˆ ƒ‰ t| |ƒrˆˆ jrdt| ƒi | jƒS t| ƒ‡ fdd„| j ¡ D ƒ| jƒS ‡ fdd	„|| ƒD ƒ}t| ƒ|| jƒS )
Nr   rL   rY   rx   ú=scalar expected, use tensorproduct(...) for tensorial productc                    s   i | ]\}}|ˆ | “qS r   r   rz   ©r’   r   r   r|   ¯  s      z%NDimArray.__mul__.<locals>.<dictcomp>c                    s   g | ]}|ˆ  ‘qS r   r   rF   r—   r   r   rT   ±  s     z%NDimArray.__mul__.<locals>.<listcomp>©rN   rM   r/   rZ   r}   ry   r8   r   r-   r:   r   Úis_zeror   r1   r]   r€   ©r   r’   rM   rZ   ry   r“   r   r—   r   Ú__mul__£  s    
$zNDimArray.__mul__c                    s®   ddl m} ddlm} ddlm} tˆ tt|fƒr<t	dƒ‚t
ˆ ƒ‰ t| |ƒrˆˆ jrdt| ƒi | jƒS t| ƒ‡ fdd„| j ¡ D ƒ| jƒS ‡ fdd	„|| ƒD ƒ}t| ƒ|| jƒS )
Nr   rL   rY   rx   r–   c                    s   i | ]\}}|ˆ | “qS r   r   rz   r—   r   r   r|   À  s      z&NDimArray.__rmul__.<locals>.<dictcomp>c                    s   g | ]}ˆ | ‘qS r   r   rF   r—   r   r   rT   Â  s     z&NDimArray.__rmul__.<locals>.<listcomp>r˜   rš   r   r—   r   Ú__rmul__´  s    
$zNDimArray.__rmul__c                    s¢   ddl m} ddlm} ddlm} tˆ tt|fƒr<t	dƒ‚t
ˆ ƒ‰ t| |ƒr|ˆ tjkr|t| ƒ‡ fdd„| j ¡ D ƒ| jƒS ‡ fdd	„|| ƒD ƒ}t| ƒ|| jƒS )
Nr   rL   rY   rx   zscalar expectedc                    s   i | ]\}}||ˆ  “qS r   r   rz   r—   r   r   r|   Ï  s      z)NDimArray.__truediv__.<locals>.<dictcomp>c                    s   g | ]}|ˆ  ‘qS r   r   rF   r—   r   r   rT   Ñ  s     z)NDimArray.__truediv__.<locals>.<listcomp>)rN   rM   r/   rZ   r}   ry   r8   r   r-   r:   r   r
   r~   r   r]   r€   r1   rš   r   r—   r   Ú__truediv__Å  s    $zNDimArray.__truediv__c                 C   s   t dƒ‚d S )Nz"unsupported operation on NDimArrayr3   ©r   r’   r   r   r   Ú__rtruediv__Ô  s    zNDimArray.__rtruediv__c                 C   sd   ddl m} ddlm} t| |ƒrBt| ƒdd„ | j ¡ D ƒ| jƒS dd„ || ƒD ƒ}t| ƒ|| jƒS )Nr   rY   rx   c                 S   s   i | ]\}}|| “qS r   r   rz   r   r   r   r|   Ü  s      z%NDimArray.__neg__.<locals>.<dictcomp>c                 S   s   g | ]
}| ‘qS r   r   rF   r   r   r   rT   Þ  s     z%NDimArray.__neg__.<locals>.<listcomp>)	r/   rZ   r}   ry   r8   r   r]   r€   r1   )r   rZ   ry   r“   r   r   r   Ú__neg__×  s    
 zNDimArray.__neg__c                    s   ‡ fdd„}|ƒ S )Nc                  3   s4   ˆ j r&tˆ j d ƒD ]} ˆ |  V  qn
ˆ d V  d S )Nr   r   )r\   r<   )r>   r   r   r   Úiteratorâ  s    z$NDimArray.__iter__.<locals>.iteratorr   )r   r¡   r   r   r   Ú__iter__á  s    zNDimArray.__iter__c                 C   sb   ddl m} t|tƒsdS | j|jks*dS t| |ƒrRt||ƒrRt| jƒt|jƒkS t| ƒt|ƒkS )aê  
        NDimArray instances can be compared to each other.
        Instances equal if they have same shape and data.

        Examples
        ========

        >>> from sympy import MutableDenseNDimArray
        >>> a = MutableDenseNDimArray.zeros(2, 3)
        >>> b = MutableDenseNDimArray.zeros(2, 3)
        >>> a == b
        True
        >>> c = a.reshape(3, 2)
        >>> c == b
        False
        >>> a[0,0] = 1
        >>> b[0,0] = 2
        >>> a == b
        False
        r   rY   F)r/   rZ   r8   r-   r1   r^   r]   Úlist)r   r’   rZ   r   r   r   Ú__eq__ë  s    
zNDimArray.__eq__c                 C   s
   | |k S r   r   rž   r   r   r   Ú__ne__  s    zNDimArray.__ne__c                 C   s*   |   ¡ dkrtdƒ‚ddlm} || dƒS )Né   zarray rank not 2r#   )Úpermutedims)r#   r   )rg   r:   Zarrayopr§   )r   r§   r   r   r   Ú_eval_transpose  s    zNDimArray._eval_transposec                 C   s   |   ¡ S r   )r¨   r   r   r   r   Ú	transpose  s    zNDimArray.transposec                 C   s(   ddl m} |  dd„ || ƒD ƒ| j¡S )Nr   rx   c                 S   s   g | ]}|  ¡ ‘qS r   )Ú	conjugaterF   r   r   r   rT     s     z-NDimArray._eval_conjugate.<locals>.<listcomp>)r}   ry   Úfuncr1   )r   ry   r   r   r   Ú_eval_conjugate  s    zNDimArray._eval_conjugatec                 C   s   |   ¡ S r   )r¬   r   r   r   r   rª     s    zNDimArray.conjugatec                 C   s   |   ¡  ¡ S r   )r©   rª   r   r   r   r   Ú_eval_adjoint   s    zNDimArray._eval_adjointc                 C   s   |   ¡ S r   )r­   r   r   r   r   Úadjoint#  s    zNDimArray.adjointc                    s@   t |tƒs|fS | |¡\‰ }‰‡ ‡fdd„t|ˆ  ˆ ƒD ƒS )Nc                    s   g | ]}ˆ |ˆ  ‘qS r   r   rF   ©ÚstartÚstepr   r   rT   *  s     z+NDimArray._slice_expand.<locals>.<listcomp>)r8   ÚsliceÚindicesr<   )r   rv   r[   Ústopr   r¯   r   Ú_slice_expand&  s    
zNDimArray._slice_expandc                    s,   ‡ fdd„t |ˆ jƒD ƒ}tj|Ž }||fS )Nc                    s   g | ]\}}ˆ   ||¡‘qS r   )rµ   )r    r>   r[   r   r   r   rT   -  s     z>NDimArray._get_slice_data_for_array_access.<locals>.<listcomp>)rJ   r1   Ú	itertoolsÚproduct)r   r6   Ú
sl_factorsÚeindicesr   r   r   Ú _get_slice_data_for_array_access,  s    
z*NDimArray._get_slice_data_for_array_accessc                 C   s<   t |tƒst| ƒ|ƒ}|  |¡\}}dd„ |D ƒ}|||fS )Nc                 S   s"   g | ]}t |tƒrt|ƒnd ‘qS r   )r8   r£   ÚminrF   r   r   r   rT   5  s     zBNDimArray._get_slice_data_for_array_assignment.<locals>.<listcomp>)r8   r-   r   rº   )r   r6   rO   r¸   r¹   Zslice_offsetsr   r   r   Ú$_get_slice_data_for_array_assignment1  s
    
z.NDimArray._get_slice_data_for_array_assignmentc                 C   s<   |dkrt |ƒdkrtdƒ‚|dkr8t |ƒdkr8tdƒ‚d S )Nr   r#   z*arrays without shape need one scalar valuerQ   r   z/if array shape is (0,) there cannot be elements)r$   r:   )r   Z	flat_listr1   r   r   r   Ú_check_special_bounds9  s    zNDimArray._check_special_boundsc                 C   sj   t |tttfƒr|f}t|ƒ|  ¡ k rNt|ƒtdd„ tt|ƒ|  ¡ ƒD ƒƒ }t|ƒ|  ¡ krftdƒ‚|S )Nc                 s   s   | ]}t d ƒV  qd S r   )r²   rF   r   r   r   rG   F  s     z5NDimArray._check_index_for_getitem.<locals>.<genexpr>z-Dimension of index greater than rank of array)	r8   r   r	   r²   r$   rg   rC   r<   r:   r5   r   r   r   Ú_check_index_for_getitem@  s    ÿz"NDimArray._check_index_for_getitem)N)NN).r'   r(   r)   r*   Z	_diff_wrtZ	is_scalarr   r7   r?   rE   rK   rP   r+   rX   re   rf   Úpropertyr1   rg   rm   rt   ru   rs   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   r-   V   sZ   4

.


!
r-   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚImmutableNDimArrayg      &@c                 C   s
   t  | ¡S r   )r   Ú__hash__r   r   r   r   rÁ   Q  s    zImmutableNDimArray.__hash__c                 C   s   | S r   r   r   r   r   r   rk   T  s    zImmutableNDimArray.as_immutablec                 C   s   t dƒ‚d S )Nzabstract methodr3   r   r   r   r   Ú
as_mutableW  s    zImmutableNDimArray.as_mutableN)r'   r(   r)   Z_op_priorityrÁ   rk   rÂ   r   r   r   r   rÀ   N  s   rÀ   )Zsympy.core.basicr   Zsympy.core.containersr   r   Zsympy.core.exprr   Zsympy.core.kindr   r   r   Zsympy.core.numbersr	   Zsympy.core.singletonr
   Zsympy.core.sympifyr   Zsympy.external.gmpyr   Zsympy.printing.defaultsr   r¶   Úcollections.abcr   r   r-   rÀ   r   r   r   r   Ú<module>   s    G   {