o
    ְi                     @   sH   d dl Z d dlmZ d dlmZ d dlmZ dd ZG dd deZdS )	    N)_core)
_interface)_cuda_typesc                 C   s2   t | trdS t | trdS t | trdS | jjS )NldD)
isinstanceintfloatcomplexdtypechar)arg r   N/home/ubuntu/.local/lib/python3.10/site-packages/cupy/_functional/vectorize.py_get_input_type   s   


r   c                   @   s2   e Zd ZdZ		d
ddZedd Zdd	 ZdS )	vectorizezKGeneralized function class.

    .. seealso:: :class:`numpy.vectorize`
    NFc                 C   sr   || _ |p|j| _|| _|| _|| _i | _d| _|dur'ddd |D | _|dur/td|dur7tddS )ab  
        Args:
            pyfunc (callable): The target python function.
            otypes (str or list of dtypes, optional): The output data type.
            doc (str or None): The docstring for the function.
            excluded: Currently not supported.
            cache: Currently Ignored.
            signature: Currently not supported.
        N c                 S   s   g | ]}t |jqS r   )numpyr   r   .0tr   r   r   
<listcomp>.   s    z&vectorize.__init__.<locals>.<listcomp>z<cupy.vectorize does not support `excluded` option currently.z=cupy.vectorize does not support `signature` option currently.)	pyfunc__doc__excludedcache	signature_kernel_cacheotypesjoinNotImplementedError)selfr   r   docr   r   r   r   r   r   __init__   s$   zvectorize.__init__c                 C   s   t | tjr| jg}d| d}n>t | tjrHg }d| d}t| jD ]"\}}t |tjs5td|  ||j |d| d| d7 }q$ntd|  d	d
 t|D }d	||fS )Nzout0 = ;zauto out = z;
zInvalid return type: outz = STD::get<z>(out);
c                 S   s   g | ]\}}| d | qS )z outr   )r   ir   r   r   r   r   J   s    z'vectorize._get_body.<locals>.<listcomp>, )
r   r   Scalarr   Tuple	enumeratetypes	TypeErrorappendr    )return_typecalldtypescoder'   r   
out_paramsr   r   r   	_get_body9   s   zvectorize._get_bodyc                 G   s   d dd |D }| j|d }|d u rqdd |D }d }| jd ur%ttj| jddd}|||}d d	d
 t	|D }d dd t
t|D }	|j d|	 d}
| |j|
\}}tj|||d|jdd}|| j|< || S )Nr   c                 S   s   g | ]}t |qS r   )r   )r   xr   r   r   r   N   s    z&vectorize.__call__.<locals>.<listcomp>c                 S   s   g | ]}t |qS r   )r   r)   r   r   r   r   r   R       r   T)devicer(   c                 s   s$    | ]\}}|j  d | V  qdS )z inN)r   )r   r'   r   r   r   r   	<genexpr>Z   s    
z%vectorize.__call__.<locals>.<genexpr>c                 S   s   g | ]}d | qS )inr   )r   r'   r   r   r   r   \   r6   ()cupy_vectorize)z-DCUPY_JIT_MODEz--std=c++17)preambleoptions)r    r   getr   r!   r   _CudaFunctionr   _emit_code_from_typesr+   rangelen	func_namer4   r/   r   ElementwiseKernelr2   )r"   argsitypeskernin_typesret_typefuncresult	in_paramsin_argsr0   r3   bodyr   r   r   __call__M   s,   


zvectorize.__call__)NNNFN)__name__
__module____qualname__r   r$   staticmethodr4   rP   r   r   r   r   r      s    
!
r   )	r   cupyr   	cupyx.jitr   r   r   objectr   r   r   r   r   <module>   s    
