← Back
Editing: tuple_to_shape.cpython-311.pyc
� cR�aW � � � d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl Z ed d ed d ed d ed d fZed d d fZd� Z d� Z G d� de� � ZdS )zH TupleToShap transforms some Tuple node into shape nodes when relevant. � )�Aliases)�MODULES)�Transformation)�pythran_builtin_attrN�numpy�full�ones�zeros�empty�ndarray�reshapec �6 � t | t j � � S )N)� isinstance�ast�Tuple)�nodes �F/usr/lib/python3/dist-packages/pythran/optimizations/tuple_to_shape.py�istupler s � ��d�C�I�&�&�&� c �V � t d� � }t j || j g � � S )N� make_shape)r r �Call�elts)r �bs r �toshaper s% � ��\�*�*�A��8�A�t�y�"�%�%�%r c �( � � e Zd ZdZ� fd�Zd� Z� xZS )�TupleToShapea� Replace tuple nodes by shape when relevant >>> import gast as ast >>> from pythran import passmanager, backend >>> node = ast.parse("def foo(n): import numpy; return numpy.ones((n,4))") >>> pm = passmanager.PassManager("test") >>> _, node = pm.apply(TupleToShape, node) >>> print(pm.dump(backend.Python, node)) def foo(n): import numpy return numpy.ones(builtins.pythran.make_shape(n, 4)) c �p �� d| _ t t | � � � t � � d S )NF)�update�superr �__init__r )�self� __class__s �r r! zTupleToShape.__init__* s. �� ���� �l�D�!�!�*�*�7�3�3�3�3�3r c �4 � | j � |j d � � }|��|� t � � rDt |j d � � r)d| _ t |j d � � |j d<