o
    i                     @   s|   d dl Z d dlZdd Zdd Zdd Zdd	 ZdddZdd fddZdd Zdd Z	dd Z
		
dddZdd ZdS )    Nc                 C   s<   | d u r
|j jdv S t| tjr| j jdv S t | jdv S )Niu)dtypekind
isinstancecupyndarray)outputinput r
   V/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/cupyx/scipy/ndimage/_util.py_is_integer_output   s
   r   c                 C   s*   | dkr|rt |stdd S d S d S )Nconstantz@Non-finite cval is not supported for outputs with integer dtype.)r   isfiniteNotImplementedError)modecvalinteger_outputr
   r
   r   _check_cval   s   r   c                 C   s0   | j jdkrt| jj tjS t| jj tjS )zInitialize filter weights based on the input array.

    This helper is only used during initialization of some internal filters
    like prewitt and sobel to avoid costly double-precision computation.
    c)r   r   r   promote_typesreal	complex64float32)r	   r
   r
   r   _init_weights_dtype   s   r   c                 C   sN   |j jdks| j jdkrt| jj tjS |j jdv rtjS t| jj tjS )Nr   iub)r   r   r   r   r   r   float64r   )r	   weightsr
   r
   r   _get_weights_dtype   s
   r   Fc                 C   s   |d u r|j n|}| d u r$|rt|jtj}n|j}tj||d} | S t| ttjfrK|rBt| jdkrBt	
d t| tj} tj|| d} | S t| trit| } |r`| jdkr`tdtj|| d} | S | j |krrtd|r~| jjdkr~td| S )N)r   r   z+promoting specified output dtype to complexzoutput must have complex dtypezoutput shape not correct)shaper   r   r   r   emptyr   typer   warningswarnstrRuntimeError)r   r	   r   complex_output_dtyper
   r
   r   _get_output(   s0   




r'   c                 C   s   | S )Nr
   )xr
   r
   r   <lambda>A   s    r)   c                    sz   t | tr | g| S zt| } W n ty"    | g|  Y S w  fdd| D }t||kr;d|}t||S )Nc                    s   g | ]} |qS r
   r
   ).0r(   convr
   r   
<listcomp>H   s    z%_fix_sequence_arg.<locals>.<listcomp>z'{} must have length equal to input rank)r   r#   iter	TypeErrorlenformatr$   )argndimnamer,   lstmsgr
   r+   r   _fix_sequence_argA   s   

r7   c                 C   s4   t | } |d |  dk s|d |  |krtd| S )N   r   zinvalid origin)int
ValueError)originwidthr
   r
   r   _check_originO   s    r=   c                 C   s    | dvrd|  d}t || S )N)reflectr   nearestmirrorwrapgrid-mirror	grid-wrapzgrid-reflectz%boundary mode not supported (actual: ))r$   )r   r6   r
   r
   r   _check_modeV   s   rE   c                 C   s4   t dd t| j| jD | jj }|dk rdS dS )Nc                 s   s$    | ]\}}|d  t | V  qdS )   N)abs)r*   r(   strider
   r
   r   	<genexpr>c   s   " z_get_inttype.<locals>.<genexpr>l        r9   	ptrdiff_t)sumzipr   stridesr   itemsize)r	   nbytesr
   r
   r   _get_inttype^   s   rP   r9   c                 C   s   |rdnd}|r
dnd}| dv rdj |||d}|S | dkr(d	j |||d}|S | d
kr>dj |||||dkr8dndd}|S | dkrKdj ||d}|S | dkrYdj |||d}|S | dv rddj ||d}|S )Nfminminfmaxmax)r>   rB   z
        if ({ix} < 0) {{
            {ix} = - 1 -{ix};
        }}
        {ix} %= {xsize} * 2;
        {ix} = {min}({ix}, 2 * {xsize} - 1 - {ix});)ixxsizerR   r@   a  
        if ({xsize} == 1) {{
            {ix} = 0;
        }} else {{
            if ({ix} < 0) {{
                {ix} = -{ix};
            }}
            {ix} = 1 + ({ix} - 1) % (({xsize} - 1) * 2);
            {ix} = {min}({ix}, 2 * {xsize} - 2 - {ix});
        }}r?   zD
        {ix} = {min}({max}(({T}){ix}, ({T})0), ({T})({xsize} - 1));r9   z	long long)rU   rV   rR   rT   TrC   z]
        {ix} %= {xsize};
        while ({ix} < 0) {{
            {ix} += {xsize};
        }})rU   rV   rA   z
        if ({ix} < 0) {{
            {ix} += ({sz} - 1) * (({int_t})(-{ix} / ({sz} - 1)) + 1);
        }} else if ({ix} > ({sz} - 1)) {{
            {ix} -= ({sz} - 1) * ({int_t})({ix} / ({sz} - 1));
        }};)rU   szint_t)r   zgrid-constantzP
        if (({ix} < 0) || {ix} >= {xsize}) {{
            {ix} = -1;
        }}r1   )r   rU   rV   rY   float_ixmin_funcmax_funcopsr
   r
   r    _generate_boundary_condition_opsh   sF   +	#r_   c                    s@   d  fddt | d ddD }djd|d d	S )
Nz<{type} ind_{j} = _i % ysize_{j} - {offset}; _i /= ysize_{j};c                    s    g | ]} j || d qS ))r    joffsetrZ   )r*   r`   codeint_typeoffsetsr
   r   r-      s    z)_generate_indices_ops.<locals>.<listcomp>rF   r   z3{type} _i = i;
{body}
{type} ind_0 = _i - {offset};
)r    bodyra   )ranger1   join)r3   rd   re   rh   r
   rb   r   _generate_indices_ops   s   rk   )NF)r9   F)r!   r   r   r   r   r   r'   r7   r=   rE   rP   r_   rk   r
   r
   r
   r   <module>   s    
	

3