
    Vpf                        U d dl mZmZ d dlZd dlZd dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZmZ d dlmZ dee         d	efd
Zdee         d	efdZdeded	efdZdeded	efdZd d d eedZeeeeegef         f         ed<   ded	efdZded	eeeef                  fdZ ded	eeeef                  fdZ! ej"        ej#        d          dedee         deded ed	efd!            Z$	 	 d%dedee         deded ef
d$Z%dS )&    )CallableSequenceN)api)util)lax)	ArrayLikeArray)safe_ziparrsreturnc                 @    t          j        t          j        |           S N)	functoolsreduceoperatormulr   s    V/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/jax/_src/scipy/ndimage.py_nonempty_prodr          		(,	-	--    c                 @    t          j        t          j        |           S r   )r   r   r   addr   s    r   _nonempty_sumr      r   r   indexsizec                 L    |dz
  }t          j        | |z   d|z  z  |z
            S )N      )jnpabs)r   r   ss      r   _mirror_index_fixerr#   "   s-    qA7EAI!a%(1,---r   c                 f    t          j        t          d| z  dz   d|z  dz             dz
  d          S )Nr   r   )r    floor_divider#   r   r   s     r   _reflect_index_fixerr'   '   s5    /%	1T6!8DDqH!LLLr   c                     | S r    r&   s     r   <lambda>r*   +   s    E r   c                 4    t          j        | d|dz
            S )Nr   r   )r    clipr&   s     r   r*   r*   ,   s    38E1dQh#?#? r   c                     | |z  S r   r)   r&   s     r   r*   r*   -   s
     r   )constantnearestwrapmirrorreflect_INDEX_FIXERSac                 v    t          j        | j        t           j                  r| nt	          j        |           S r   )r    
issubdtypedtypeintegerr   round)r4   s    r   _round_half_away_from_zeror:   3   s)    nQWck22	D	!Dr   
coordinatec                     t          |                               t          j                  }| j                            d          }||fgS Nr   )r:   astyper    int32r7   type)r;   r   weights      r   _nearest_indices_and_weightsrB   7   sB    
$Z
0
0
7
7	
B
B%  ##&&/	r   c                     t          j        |           }| |z
  }d|z
  }|                    t           j                  }||f|dz   |fgS r=   )r    floorr>   r?   )r;   lowerupper_weightlower_weightr   s        r   _linear_indices_and_weightsrH   =   sQ    
)J

%e#,\!,
,,sy
!
!%,
%!)\!:	;;r   )r         )static_argnumsinputcoordinatesordermodecvalc                 "   t          j        |           }d |D             }t          j        ||j                  }t          |          |j        k    r5t          d                    t          |          |j                            t                              |          }|5t          d                    |t          t                                        |dk    rd }nd }|dk    rt          }	n|dk    rt          }	nt          d	          g }
t          ||j                  D ]_\  }} |	|          }g }|D ]5\  }} |||          } |||          }|                    |||f           6|
                    |           `g }t!          j        |
 D ]}t%          j        |          \  }}}t)          d
 |D                       r	||         }n;t+          j        t.          j        |          }t          j        |||         |          }|                    t5          |          |z             t7          |          }t          j        |j        t           j                  rt=          |          }|                    |j                  S )Nc                 6    g | ]}t          j        |          S r)   )r    asarray).0cs     r   
<listcomp>z$_map_coordinates.<locals>.<listcomp>I   s     999S[^^999r   zAcoordinates must be a sequence of length input.ndim, but {} != {}zajax.scipy.ndimage.map_coordinates does not yet support mode {}. Currently supported modes are {}.r.   c                     d| k    | |k     z  S )Nr   r)   r&   s     r   r*   z"_map_coordinates.<locals>.<lambda>W   s    AJ54<#@ r   c                     dS )NTr)   r&   s     r   r*   z"_map_coordinates.<locals>.<lambda>Y   s    4 r   r   r   z=jax.scipy.ndimage.map_coordinates currently requires order<=1c              3      K   | ]}|d u V  	dS )TNr)   )rT   valids     r   	<genexpr>z#_map_coordinates.<locals>.<genexpr>p   s&      
1
1U5D=
1
1
1
1
1
1r   ) r    rS   r7   lenndim
ValueErrorformatr3   getNotImplementedErrorsetrB   rH   zipshapeappend	itertoolsproductr   unzip3allr   r   r   and_wherer   r   r6   r8   r:   r>   )rL   rM   rN   rO   rP   	input_arrcoordinate_arrsindex_fixeris_valid
interp_funvalid_1d_interpolationsr;   r   interp_nodesvalid_interpr   rA   fixed_indexrZ   outputsitemsindices
validitiesweightscontribution	all_validresults                              r   _map_coordinatesr}   E   s    k%  )99[999/	T9?	+	+$''
   &s;'7'7 H HJ J J !!$''+
	,,2F4]9K9K,L,LN N N 
Z@@HH''H
aZZ-JJzz,JJ
GI I I oy?? 1 1j$:j))LL% 8 8vKt,,khud##e;v67777""<0000' "9: ; ;e#';u#5#5 GZ

1
1j
1
1
111 Dw'll"8=*==iYy)G*<dCClNN>'**\9::::!!&^IOS[11 0'//F	y	'	''r   r.           c                 (    t          | ||||          S )ag  
  Map the input array to new coordinates using interpolation.

  JAX implementation of :func:`scipy.ndimage.map_coordinates`

  Given an input array and a set of coordinates, this function returns the
  interpolated values of the input array at those coordinates.

  Args:
    input: N-dimensional input array from which values are interpolated.
    coordinates: length-N sequence of arrays specifying the coordinates
      at which to evaluate the interpolated values
    order: The order of interpolation. JAX supports the following:

      * 0: Nearest-neighbor
      * 1: Linear

    mode: Points outside the boundaries of the input are filled according to the given mode.
      JAX supports one of ``('constant', 'nearest', 'mirror', 'wrap', 'reflect')``. Note the
      ``'wrap'`` mode in JAX behaves as ``'grid-wrap'`` mode in SciPy, and ``'constant'``
      mode in JAX behaves as ``'grid-constant'`` mode in SciPy. This discrepancy was caused
      by a former bug in those modes in SciPy (https://github.com/scipy/scipy/issues/2640),
      which was first fixed in JAX by changing the behavior of the existing modes, and later
      on fixed in SciPy, by adding modes with new names, rather than fixing the existing
      ones, for backwards compatibility reasons. Default is 'constant'.
    cval: Value used for points outside the boundaries of the input if ``mode='constant'``
      Default is 0.0.

  Returns:
    The interpolated values at the specified coordinates.

  Examples:
    >>> input = jnp.arange(12.0).reshape(3, 4)
    >>> input
    Array([[ 0.,  1.,  2.,  3.],
           [ 4.,  5.,  6.,  7.],
           [ 8.,  9., 10., 11.]], dtype=float32)
    >>> coordinates = [jnp.array([0.5, 1.5]),
    ...                jnp.array([1.5, 2.5])]
    >>> jax.scipy.ndimage.map_coordinates(input, coordinates, order=1)
    Array([3.5, 8.5], dtype=float32)

  Note:
    Interpolation near boundaries differs from the scipy function, because JAX
    fixed an outstanding bug; see https://github.com/google/jax/issues/11097.
    This function interprets the ``mode`` argument as documented by SciPy, but
    not as implemented by SciPy.
  )r}   )rL   rM   rN   rO   rP   s        r   map_coordinatesr      s    h 
%eT4	@	@@r   )r.   r~   )&collections.abcr   r   r   rf   r   jax._srcr   r   jaxr   	jax.numpynumpyr    jax._src.typingr   r	   jax._src.utilr
   rc   r   r   intr#   r'   r3   dictstr__annotations__r:   listtuplerB   rH   partialjitr}   r   r)   r   r   <module>r      s   / . . . . . . . .                                  , , , , , , , , ) ) ) ) ) ).% .U . . . .. .E . . . ..u .C .E . . . .
M MS MU M M M M *)??,,!#; ;tC5#,"5667   E% EE E E E EU tE%BR<S7T    <E <d5	AQ;R6S < < < < 3795554(I 4(HY4G 4(4('*4(2;4(@E4( 4( 4( 654(n /24A 4A4A#+I#64A?B4A
4A"+4A 4A 4A 4A 4A 4Ar   