
    `it                        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
j        d           G d	 d
ee                      Z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                  .    e Zd ZU dZded<   ddZ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                    t          d |D                       rt          d          t                              | |          } |j        t
          j        g|R   |S )Nc              3  B   K   | ]}t          |t                     V  d S N)
isinstancer   ).0xs     c/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/tvm_ffi/_tensor.py	<genexpr>z Shape.__new__.<locals>.<genexpr>B   s/      <<q:a***<<<<<<    z!Shape must be a tuple of integers)any
ValueErrortuple__new__%__init_cached_object_by_constructor__r   r   )clsr   vals      r   r"   zShape.__new__A   sf    <<G<<<<< 	B@AAA]]30011(.K7KKKK
r   objc                h    t          |          }t                              | |          }||_        |S )z"Construct from a given tvm object.)r   r!   r"   r   )r$   r&   r   r%   s       r   __from_tvm_ffi_object__zShape.__from_tvm_ffi_object__I   s/    )#..]]300%("
r   N)r   r   r   r   )r&   r   r   r   )__name__
__module____qualname____doc____annotations__r"   r(    r   r   r   r   %   sV          &          r   r   Ndevice_typestr | int | DLDeviceTypeindex
int | Noner   r
   c                ,    t          j        | |          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/   r1   s     r   devicer5   Q   s    : k5111r   )r   r
   r   r5   r   r   )r/   r0   r1   r2   r   r
   )r,   
__future__r   numbersr   typingr    r   r   r	   r
   r   r   r   r   r   register_objectr!   r   r5   __all__r.   r   r   <module>r<      s&  " , + " " " " " "             & & & & & & & & & &                +&&( ( ( ( (E> ( ( '&(V2 2 2 2 2@ H
G
Gr   