a
    Df                     @  s   d dl mZ d dlmZ d dlZd dlZd dlZd dlmZ d dl	Z
d dlZd dlZd dlmZmZ d dlmZ zd dlZd dlZW n ey   dZdZY n0 G dd deZdS )	    )annotations)VersionN)isnan)Exprngjit)expand_varargsc                   @  sx   e Zd ZdZdZedd Zedd Zedd Z	ee
d	d
 Zee
dd Zedd Zdd Zedd ZdS )GlyphzBase class for glyphs.Fc                 C  s
   t  dS )a  
        The number of dimensions required in the data structure this Glyph is
        constructed from. Or None if input data structure is irregular

        For example
         * ndims is 1 if glyph is constructed from a DataFrame
         * ndims is 2 if glyph is constructed from a 2D xarray DataArray
         * ndims is None if glyph is constructed from multiple DataFrames of
           different lengths
        N)NotImplementedError)self r   d/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/datashader/glyphs/glyph.pyndims   s    zGlyph.ndimsc                 C  sH   | \}}t |rt |s&d\}}n||kr@|d |d  }}||fS )N)g      g      ?   )npisfinite)Zboundsminvalmaxvalr   r   r   maybe_expand_bounds*   s    
zGlyph.maybe_expand_boundsc                 C  s   t r(t| t jr(|  } |  |  fS t| tjr@t| j	S t| t
jrtrvt| jtjrv|   |   fS t| j	 S n
t| S d S N)cudf
isinstanceZSeriesZnans_to_nullsminmaxpdr   _compute_bounds_numbavaluesxrZ	DataArraycpdataZndarrayitemZravel)sr   r   r   _compute_bounds3   s    zGlyph._compute_boundsc                 C  s@   t j}t j }| D ]$}t|s||k r*|}||kr|}q||fS r   )r   infr   )Zarrr   r   xr   r   r   r   B   s    zGlyph._compute_bounds_numbac                 C  sl   t j}t j }t| jd D ]F}t| jd D ]2}| | | }t |s.||k rT|}||kr.|}q.q||fS )Nr   r   )r   r"   rangeshaper   )valsr   r   ijvr   r   r   _compute_bounds_2dP   s    
zGlyph._compute_bounds_2dc                   s   t |trt|}t |trLt|tt|krLtj fdd|D ddS ttj	tdkrj | 
 S t |ts |  S  |  S d S )Nc                   s   g | ]}t  | qS r   )r   array).0cdfr   r   
<listcomp>i       z'Glyph.to_cupy_array.<locals>.<listcomp>r   )Zaxisz22.02)r   tuplelistlensetr   stackr   r   __version__Zto_cupyZto_gpu_arrayZas_gpu_matrix)r/   columnsr   r.   r   to_cupy_array`   s    

zGlyph.to_cupy_arrayc                 C  s   |  || j| jS )ai  
        Create a decorator that can be used on functions that accept
        *aggs_and_cols as a variable length argument. The decorator will
        replace *aggs_and_cols with a fixed number of arguments.

        The appropriate fixed number of arguments is calculated from the input
        append function.

        Rationale: When we know the fixed length of a variable length
        argument, replacing it with fixed arguments can help numba better
        optimize the the function.

        If this ever causes problems in the future, this decorator can be
        safely removed without changing the functionality of the decorated
        function.

        Parameters
        ----------
        append: function
            The append function for the current aggregator

        Returns
        -------
        function
            Decorator function
        )_expand_aggs_and_colsr   antialiased)r
   appendr   r   r   expand_aggs_and_colsr   s    zGlyph.expand_aggs_and_colsc              
   C  s   t jdd rdd S t P td zt| jj	}W n" t
tfy^   t| j	}Y n0 W d    n1 st0    Y  t|}d}|pd}|| | }|r|d8 }t|S )NZNUMBA_DISABLE_JITc                 S  s   | S r   r   )fnr   r   r   <lambda>   r1   z-Glyph._expand_aggs_and_cols.<locals>.<lambda>ignore   r   )osenvirongetwarningscatch_warningssimplefilterinspectgetfullargspecZpy_funcargs	TypeErrorAttributeErrorr4   r   )r<   r   r;   Zappend_argsZappend_arglenZ	xy_arglenZ
dim_arglenZaggs_and_cols_lenr   r   r   r:      s    

0zGlyph._expand_aggs_and_colsN)__name__
__module____qualname____doc__r;   propertyr   staticmethodr   r!   r   r   r*   r9   r=   r:   r   r   r   r   r      s&   



r   )
__future__r   Zpackaging.versionr   rH   rE   rB   mathr   numpyr   Zpandasr   Zxarrayr   Zdatashader.utilsr   r   Zdatashader.macrosr   r   Zcupyr   	Exceptionr   r   r   r   r   <module>   s"   
