
    HR-e                     :    d Z ddlZddlmZ  G d de          ZdS )zConvolution Model.    N   )CompoundModelc                   f     e Zd ZdZd	 fd	Zd Z fdZed             Zed             Z	d Z
 xZS )
Convolutionas  
    Wrapper class for a convolution model.

    Parameters
    ----------
    operator: tuple
        The SPECIAL_OPERATORS entry for the convolution being used.
    model : Model
        The model for the convolution.
    kernel: Model
        The kernel model for the convolution.
    bounding_box : tuple
        A bounding box to define the limits of the integration
        approximation for the convolution.
    resolution : float
        The resolution for the approximation of the convolution.
    cache : bool, optional
        Allow convolution computation to be cached for reuse. This is
        enabled by default.

    Notes
    -----
    This is wrapper is necessary to handle the limitations of the
    pseudospectral convolution binary operator implemented in
    astropy.convolution under `~astropy.convolution.convolve_fft`. In this
    `~astropy.convolution.convolve_fft` it is assumed that the inputs ``array``
    and ``kernel`` span a sufficient portion of the support of the functions of
    the convolution. Consequently, the ``Compound`` created by the
    `~astropy.convolution.convolve_models` function makes the assumption that
    one should pass an input array that sufficiently spans this space. This means
    that slightly different input arrays to this model will result in different
    outputs, even on points of intersection between these arrays.

    This issue is solved by requiring a ``bounding_box`` together with a
    resolution so that one can pre-calculate the entire domain and then
    (by default) cache the convolution values. The function then just
    interpolates the results from this cache.
    Tc                     t                                          |||           || _        || _        || _        d | _        d | _        d S N)super__init__bounding_box_resolution_cache_convolution_kwargs_convolution)selfoperatormodelkernelr   
resolutioncache	__class__s          <lib/python3.11/site-packages/astropy/modeling/convolution.pyr
   zConvolution.__init__2   sL    5&111(%"'     c                 "    d| _         d| _        dS )z0
        Clears the cached convolution.
        N)r   r   )r   s    r   clear_cachezConvolution.clear_cache<   s      r   c                    | j         | j        |k    rn| j                            | j                  }t          j        | } t                      j        |i |}ddl	m
}  |||          }| j        r|| _        || _         n| j         }|S )Nr   )RegularGridInterpolator)r   r   r   domainr   npmeshgridr	   __call__scipy.interpolater   r   )r   kwargsr   meshdatar   convolutionr   s          r   _get_convolutionzConvolution._get_convolutionC   s    %4<6+A+A&--d.>??F;'D#577#T4V44DAAAAAA11&$??K& 0%$/! +Kr   c                  $    t          j        d  D                       d         }t          |          dk    rt          j                   dfS  |d                  j        t           fd|D                       st          d          g } D ]T}t          j        |          r)|                    t          j	        |                     ?|                    |           Ut          j
        |t          |          df          j        fS )Nc                 8    g | ]}t          j        |           S  )r   isscalar).0args     r   
<listcomp>z3Convolution._convolution_inputs.<locals>.<listcomp>X   s%    DDD2;s#3#33DDDr   r   )r   c              3   :   K   | ]}|         j         k    V  d S r   )shape)r+   indexargsoutput_shapes     r   	<genexpr>z2Convolution._convolution_inputs.<locals>.<genexpr>^   s/      QQUtE{(L8QQQQQQr   zValues have differing shapes)r   wherelenarrayr/   all
ValueErrorr*   appendfullreshapeT)r1   
not_scalarinputsr,   r2   s   `   @r   _convolution_inputszConvolution._convolution_inputsV   s   XDDtDDDEEaH
z??a8D>>4''
1.4LQQQQQjQQQQQ A !?@@@F ' ';s## 'MM"',"<"<====MM#&&&&:fs6{{B&788:LHHr   c                 ,    |                      |          S r   )r<   )outputsr2   s     r   _convolution_outputsz Convolution._convolution_outputsj   s    |,,,r   c                 x     | j         | \  }} | j        di |} ||          }|                     ||          S )Nr)   )r@   r&   rC   )r   r1   kwr?   r2   r%   rB   s          r   r    zConvolution.__call__n   sS    7t7>+d+11b11+f%%((,???r   )T)__name__
__module____qualname____doc__r
   r   r&   staticmethodr@   rC   r    __classcell__)r   s   @r   r   r   
   s        % %N! ! ! ! ! !! ! !    & I I \I& - - \-@ @ @ @ @ @ @r   r   )rI   numpyr   corer   r   r)   r   r   <module>rN      ss               i@ i@ i@ i@ i@- i@ i@ i@ i@ i@r   