B
    ˜‘[Q  ã               @   s\   d dl mZmZ ddlmZ d dlmZmZ d dlm	Z	 d dl
mZmZ G dd„ deƒZd	S )
é    )Úprint_functionÚdivisioné   )Ú
MatrixExpr)ÚBasicÚsympify)ÚMatrix)ÚreÚimc               @   sH   e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZdd	„ Zd
d„ Z	dd„ Z
dS )ÚFunctionMatrixa"  
    Represents a Matrix using a function (Lambda)

    This class is an alternative to SparseMatrix

    >>> from sympy import FunctionMatrix, symbols, Lambda, MatMul, Matrix
    >>> i, j = symbols('i,j')
    >>> X = FunctionMatrix(3, 3, Lambda((i, j), i + j))
    >>> Matrix(X)
    Matrix([
    [0, 1, 2],
    [1, 2, 3],
    [2, 3, 4]])

    >>> Y = FunctionMatrix(1000, 1000, Lambda((i, j), i + j))

    >>> isinstance(Y*Y, MatMul) # this is an expression object
    True

    >>> (Y**2)[10,10] # So this is evaluated lazily
    342923500
    c             C   s"   t |ƒt |ƒ }}t | |||¡S )N)r   r   Ú__new__)ÚclsZrowsZcolsÚlamda© r   úDlib/python3.7/site-packages/sympy/matrices/expressions/funcmatrix.pyr      s    zFunctionMatrix.__new__c             C   s   | j dd… S )Nr   é   )Úargs)Úselfr   r   r   Úshape#   s    zFunctionMatrix.shapec             C   s
   | j d S )Nr   )r   )r   r   r   r   r   '   s    zFunctionMatrix.lamdac             C   s   |   ||¡S )N)r   )r   ÚiÚjr   r   r   Ú_entry+   s    zFunctionMatrix._entryc             C   s   ddl m} | || ƒ¡ ¡ S )Nr   )ÚTrace)Z sympy.matrices.expressions.tracer   Z_eval_rewrite_as_SumZdoit)r   r   r   r   r   Ú_eval_trace.   s    zFunctionMatrix._eval_tracec             C   s   t t| ƒƒtt| ƒƒfS )N)r	   r   r
   )r   r   r   r   Úas_real_imag2   s    zFunctionMatrix.as_real_imagN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r   r   r   r   r   r   r   r   r      s   r   N)Z
__future__r   r   Zmatexprr   Zsympyr   r   Zsympy.matricesr   Z$sympy.functions.elementary.complexesr	   r
   r   r   r   r   r   Ú<module>   s
   