o
    ٰit                     @  s   d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
 ddl	mZmZmZmZmZmZ e
dG d	d
 d
eeZddddZg dZdS )z%Tensor related objects and functions.    )annotations)Integral)Any   )_ffi_apicoreregistry)DeviceDLDeviceTypePyNativeObjectTensor_shape_obj_get_py_tuplefrom_dlpackz	ffi.Shapec                   @  s.   e Zd ZU dZded< dddZdd
dZdS )Shapea  Shape tuple that represents :cpp:class:`tvm::ffi::Shape` returned by an FFI call.

    Notes
    -----
    This class subclasses :class:`tuple` so it can be used in most places where
    :class:`tuple` is used in Python array APIs.

    Examples
    --------
    .. code-block:: python

        import numpy as np
        import tvm_ffi

        x = tvm_ffi.from_dlpack(np.arange(6, dtype="int32").reshape(2, 3))
        assert x.shape == (2, 3)

    r   _tvm_ffi_cached_objectcontenttuple[int, ...]returnc                 C  s>   t dd |D rtdt| |}|jtjg|R   |S )Nc                 s  s    | ]	}t |t V  qd S N)
isinstancer   ).0x r   C/home/ubuntu/.local/lib/python3.10/site-packages/tvm_ffi/_tensor.py	<genexpr>B   s    z Shape.__new__.<locals>.<genexpr>z!Shape must be a tuple of integers)any
ValueErrortuple__new__%__init_cached_object_by_constructor__r   r   )clsr   valr   r   r   r   A   s
   zShape.__new__objc                 C  s   t |}t| |}||_|S )z"Construct from a given tvm object.)r   r   r   r   )r    r"   r   r!   r   r   r   __from_tvm_ffi_object__I   s   zShape.__from_tvm_ffi_object__N)r   r   r   r   )r"   r   r   r   )__name__
__module____qualname____doc____annotations__r   r#   r   r   r   r   r   %   s
   
 
r   Ndevice_typestr | int | DLDeviceTypeindex
int | Noner   r	   c                 C  s   t | |S )a?  Construct a TVM FFI device with given device type and index.

    Parameters
    ----------
    device_type: str or int
        The device type or name.

    index: int, optional
        The device index.

    Returns
    -------
    device: tvm_ffi.Device

    Examples
    --------
    Device can be used to create reflection of device by
    string representation of the device type.

    .. code-block:: python

      import tvm_ffi

      assert tvm_ffi.device("cuda:0") == tvm_ffi.device("cuda", 0)
      assert tvm_ffi.device("cpu:0") == tvm_ffi.device("cpu", 0)

    )r   _CLASS_DEVICE)r)   r+   r   r   r   deviceQ   s   r.   )r
   r	   r   r.   r   r   )r)   r*   r+   r,   r   r	   )r'   
__future__r   numbersr   typingr    r   r   r   r	   r
   r   r   r   r   register_objectr   r   r.   __all__r   r   r   r   <module>   s    
+ 