← Back
Editing: test_dlpack.cpython-311.pyc
� ���c� � �H � d dl Z d dlZd dlZd dlmZmZ G d� d� � ZdS )� N)�assert_array_equal�IS_PYPYc �" � e Zd Zej � ed�� � d� � � Zd� Zd� Z ej � ed�� � d� � � Z ej � dej ej ej ej ej ej ej ej ej ej ej ej ej g � � d� � � Zd � Zd � Zd� Zej � d ed � � � � d� � � Zd� Z d� Z!d� Z"d� Z#d� Z$d� Z%dS )� TestDLPackzPyPy can't get refcounts.)�reasonc � � t j d� � }|� � � }t j |� � dk sJ �~t j |� � dk sJ �d S �N� � � )�np�arange� __dlpack__�sys�getrefcount��self�x�ys �>/usr/lib/python3/dist-packages/numpy/core/tests/test_dlpack.py�test_dunder_dlpack_refcountz&TestDLPack.test_dunder_dlpack_refcount s[ � ��I�a�L�L�� �L�L�N�N����q�!�!�Q�&�&�&�&� ���q�!�!�Q�&�&�&�&�&�&� c �� � t j d� � }|� d �� � t j t � � 5 |� d�� � d d d � � d S # 1 swxY w Y d S )Nr )�stream� )r r r �pytest�raises�RuntimeError�r r s r �test_dunder_dlpack_streamz$TestDLPack.test_dunder_dlpack_stream s� � ��I�a�L�L�� ���D��!�!�!� �]�<� (� (� #� #� �L�L��L�"�"�"� #� #� #� #� #� #� #� #� #� #� #� #���� #� #� #� #� #� #s �A(�(A,�/A,c �* � t j dt j fdt j fg� � }t j d|�� � }|d }t j t � � 5 t j |� � d d d � � d S # 1 swxY w Y d S )N�int�char)r ��dtype) r r% �int32�int8�zerosr r �BufferError�from_dlpack)r �dtr �zs r �%test_strides_not_multiple_of_itemsizez0TestDLPack.test_strides_not_multiple_of_itemsize s� � � �X��r�x�(�6�2�7�*;�<� =� =���H�T��$�$�$�� �e�H�� �]�;� '� '� � ��N�1���� � � � � � � � � � � � ���� � � � � � s �&B�B�Bc � � t j d� � }t j |� � }t j |� � dk sJ �~t j |� � dk sJ �d S r )r r r* r r r s r �test_from_dlpack_refcountz$TestDLPack.test_from_dlpack_refcount s] � ��I�a�L�L���N�1������q�!�!�Q�&�&�&�&� ���q�!�!�Q�&�&�&�&�&�&r r% c � � t j d|�� � }t j |� � }|j |j k sJ �t ||� � d S )Nr r$ )r r r* r% r )r r% r r s r �test_dtype_passthroughz!TestDLPack.test_dtype_passthrough( sR � � �I�a�u�%�%�%���N�1�����w�!�'�!�!�!�!��1�a� � � � � r c �� � t j t j d� � � � }t j t � � 5 t j |� � d d d � � d S # 1 swxY w Y d S )Nz 2021-05-27)r �asarray� datetime64r r r) r* r s r �test_invalid_dtypezTestDLPack.test_invalid_dtype5 s� � ��J�r�}�\�2�2�3�3�� �]�;� '� '� � ��N�1���� � � � � � � � � � � � ���� � � � � � s � A"�"A&�)A&c � � t j d� � � � � }t j d|�� � }t j t � � 5 t j |� � d d d � � d S # 1 swxY w Y d S )Nz=i8r r$ )r r% �newbyteorderr r r r) r* )r r+ r s r �test_invalid_byte_swappingz%TestDLPack.test_invalid_byte_swapping; s� � � �X�e�_�_� )� )� +� +���I�a�r�"�"�"�� �]�;� '� '� � ��N�1���� � � � � � � � � � � � ���� � � � � � s �A8�8A<�?A<c �D � t j d� � � d� � }|d }t |t j |� � � � |d d �df }t |t j |� � � � |dd d �f }t |t j |� � � � |d }t |t j |� � � � t j |� � � � � }t |t j |� � � � d S )N� )r r r r )r r �reshaper r* �diagonal�copy)r r �y1�y2�y3�y4�y5s r �test_non_contiguouszTestDLPack.test_non_contiguousB s� � ��I�b�M�M�!�!�&�)�)�� �q�T���2�r�~�b�1�1�2�2�2� �q�q�q�!�t�W���2�r�~�b�1�1�2�2�2� �q�!�!�!�t�W���2�r�~�b�1�1�2�2�2� �q�T���2�r�~�b�1�1�2�2�2� �[��^�^� � � "� "���2�r�~�b�1�1�2�2�2�2�2r �ndim�! c � � d|z }t j |t j �� � }|t j |� � j k sJ �d S )N)r r$ )r r( �float64r* �shape)r rD rH r s r �test_higher_dimszTestDLPack.test_higher_dimsT sE � ��t����H�U�"�*�-�-�-�����q�)�)�/�/�/�/�/�/�/r c � � t j d� � }|� � � dk sJ �t j |� � }|� � � dk sJ �|d d d� }|� � � dk sJ �d S )Nr )r r r )r r �__dlpack_device__r* )r r r r, s r �test_dlpack_devicezTestDLPack.test_dlpack_device[ s� � ��I�a�L�L���"�"�$�$��.�.�.�.��N�1�����"�"�$�$��.�.�.�.� �c�c��c�F���"�"�$�$��.�.�.�.�.�.r c �` � t j d� � }|� � � }t �)Nr )r r r r )r r �_s r �dlpack_deleter_exceptionz#TestDLPack.dlpack_deleter_exceptionc s"