
    `iit                     @   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Z	ddgZ
ddgZd	Z ej        ed
          ZdZ ej        ed
d e
D                       ZdZ ej        ed
d eD                       Zd Zd ZddZd Zd ZddZddZ G d d          ZdS )    N)internal)get_typename)
csr_matrixdoublezthrust::complex<double>intz	long longa$  
#include <cupy/complex.cuh>
extern "C" {
__global__ void find_interval(
        const double* t, const double* x, long long* out,
        int k, int n, bool extrapolate, int total_x) {

    int idx = blockDim.x * blockIdx.x + threadIdx.x;
    if(idx >= total_x) {
        return;
    }

    double xp = *&x[idx];
    double tb = *&t[k];
    double te = *&t[n];

    if(isnan(xp)) {
        out[idx] = -1;
        return;
    }

    if((xp < tb || xp > te) && !extrapolate) {
        out[idx] = -1;
        return;
    }

    int left = k;
    int right = n;
    int mid;
    bool found = false;

    while(left < right && !found) {
        mid = ((right + left) / 2);
        if(xp > *&t[mid]) {
            left = mid + 1;
        } else if (xp < *&t[mid]) {
            right = mid - 1;
        } else {
            found = true;
        }
    }

    int default_value = left - 1 < k ? k : left - 1;
    int result = found ? mid + 1 : default_value + 1;

    while(result != n && xp >= *&t[result]) {
        result++;
    }

    out[idx] = result - 1;
}
}
)z
-std=c++11)codeoptionsaK	  
#include <cupy/complex.cuh>
#include <cupy/math_constants.h>
#define COMPUTE_LINEAR 0x1

template<typename T>
__global__ void d_boor(
        const double* t, const T* c, const int k, const int mu,
        const double* x, const long long* intervals, T* out,
        double* temp, int num_c, int mode, int num_x) {

    int idx = blockDim.x * blockIdx.x + threadIdx.x;

    if(idx >= num_x) {
        return;
    }

    double xp = *&x[idx];
    long long interval = *&intervals[idx];

    double* h = temp + idx * (2 * k + 1);
    double* hh = h + k + 1;

    int ind, j, n;
    double xa, xb, w;

    if(mode == COMPUTE_LINEAR && interval < 0) {
        for(j = 0; j < num_c; j++) {
            out[num_c * idx + j] = CUDART_NAN;
        }
        return;
    }

    /*
     * Perform k-m "standard" deBoor iterations
     * so that h contains the k+1 non-zero values of beta_{ell,k-m}(x)
     * needed to calculate the remaining derivatives.
     */
    h[0] = 1.0;
    for (j = 1; j <= k - mu; j++) {
        for(int p = 0; p < j; p++) {
            hh[p] = h[p];
        }
        h[0] = 0.0;
        for (n = 1; n <= j; n++) {
            ind = interval + n;
            xb = t[ind];
            xa = t[ind - j];
            if (xb == xa) {
                h[n] = 0.0;
                continue;
            }
            w = hh[n - 1]/(xb - xa);
            h[n - 1] += w*(xb - xp);
            h[n] = w*(xp - xa);
        }
    }

    /*
     * Now do m "derivative" recursions
     * to convert the values of beta into the mth derivative
     */
    for (j = k - mu + 1; j <= k; j++) {
        for(int p = 0; p < j; p++) {
            hh[p] = h[p];
        }
        h[0] = 0.0;
        for (n = 1; n <= j; n++) {
            ind = interval + n;
            xb = t[ind];
            xa = t[ind - j];
            if (xb == xa) {
                h[mu] = 0.0;
                continue;
            }
            w = ((double) j) * hh[n - 1]/(xb - xa);
            h[n - 1] -= w;
            h[n] = w;
        }
    }

    if(mode != COMPUTE_LINEAR) {
        return;
    }

    // Compute linear combinations
    for(j = 0; j < num_c; j++) {
        out[num_c * idx + j] = 0;
        for(n = 0; n < k + 1; n++) {
            out[num_c * idx + j] = (
                out[num_c * idx + j] +
                c[(interval + n - k) * num_c + j] * ((T) h[n]));
        }
    }

}
c                     g | ]}d | d	S )zd_boor<> ).0	type_names     t/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cupyx/scipy/interpolate/_bspline.py
<listcomp>r      s$    DDD,	,,,DDD    )r   r	   name_expressionsa=  
#include <cupy/complex.cuh>

template<typename U>
__global__ void compute_design_matrix(
        const int k, const long long* intervals, double* bspline_basis,
        double* data, U* indices, int num_intervals) {

    int idx = blockDim.x * blockIdx.x + threadIdx.x;
    if(idx >= num_intervals) {
        return;
    }

    long long interval = *&intervals[idx];

    double* work = bspline_basis + idx * (2 * k + 1);

    for(int j = 0; j <= k; j++) {
        int m = (k + 1) * idx + j;
        data[m] = work[j];
        indices[m] = (U) (interval - k + j);
    }
}
c                     g | ]}d | d	S )zcompute_design_matrix<r   r   )r   itypes     r   r   r      s3     . . . 8u777 . . .r   c                     d |D             }d                     |          }|r| d| dn|}|                     |          }|S )Nc                 6    g | ]}t          |j                  S r   )r   dtype)r   args     r   r   z$_get_module_func.<locals>.<listcomp>   s"    DDDs<	**DDDr   z, <r   )joinget_function)module	func_nametemplate_argsargs_dtypestemplatekernel_namekernels          r   _get_module_funcr#      s^    DDmDDDKyy%%H0=LY,,,,,,9K  --FMr   c                 p    t          j        | t           j                  rt           j        S t           j        S )z>Return np.complex128 for complex dtypes, np.float64 otherwise.)cupy
issubdtypecomplexfloatingcomplex_float_r   s    r   
_get_dtyper+      s)    ud233 }{r   Fc                     t          j        |           } t          | j                  }|                     |d          } |r5t          j        |                                           st          d          | S )z~Convert the input into a C contiguous float array.
    NB: Upcasts half- and single-precision floats to double precision.
    F)copyz$Array must not contain infs or nans.)r%   ascontiguousarrayr+   r   astypeisfiniteall
ValueError)xcheck_finitedtyps      r   _as_float_arrayr6      ss     	q!!AagD	E""A ADM!,,0022 A?@@@Hr   c                 F   | j         d         |z
  dz
  }t          j        |t          j                  }t	          t
          d          }	 |	|j         d         dz   dz
  dz  fd| ||||||j         d         f           t          t          j        |j         dd                             }
t          j	        |j         d         d|z  dz   z            }t	          t          d	|          } ||j         d         dz   dz
  dz  fd| ||||||||
d|j         d         f           dS )
a1  
    Evaluate a spline in the B-spline basis.

    Parameters
    ----------
    t : ndarray, shape (n+k+1)
        knots
    c : ndarray, shape (n, m)
        B-spline coefficients
    xp : ndarray, shape (s,)
        Points to evaluate the spline at.
    nu : int
        Order of derivative to evaluate.
    extrapolate : int, optional
        Whether to extrapolate to ouf-of-bounds points, or to return NaNs.
    out : ndarray, shape (s, m)
        Computed values of the spline at each of the input points.
        This argument is modified in-place.
    r      r*   find_interval   r:   N   d_boor)shaper%   
empty_likeint64r#   INTERVAL_MODULEr   npprodemptyD_BOOR_MODULE)tckxpnuextrapolateoutn	intervalsinterval_kernelnum_ctempd_boor_kernels                r   _evaluate_splinerS      s=   ( 	

QA$*555I 'HHOObhqkC'!+35vIq!["(1+FH H H $$%%E:bhqkQUQY/00D$]Ha@@MMBHQK#%)c13VaBIsD%8A; ! ! ! ! !r   c                    |j         d         |z
  dz
  }t          j        | t          j                  }t	          t
          d          } || j         d         dz   dz
  dz  fd|| ||||| j         d         f           t          j        | j         d         d|z  dz   z            }t	          t          d|           }	 |	| j         d         dz   dz
  dz  fd|d	|d| |d	|dd| j         d         f           t          j        | j         d         |dz   z  t          j	                  }
t	          t          d
|          } || j         d         dz   dz
  dz  fd||||
|| j         d         f           |
|fS )a  
    Returns a design matrix in CSR format.
    Note that only indices is passed, but not indptr because indptr is already
    precomputed in the calling Python function design_matrix.

    Parameters
    ----------
    x : array_like, shape (n,)
        Points to evaluate the spline at.
    t : array_like, shape (nt,)
        Sorted 1D array of knots.
    k : int
        B-spline degree.
    extrapolate : bool, optional
        Whether to extrapolate to ouf-of-bounds points.
    indices : ndarray, shape (n * (k + 1),)
        Preallocated indices of the final CSR array.
    Returns
    -------
    data
        The data array of a CSR array of the b-spline design matrix.
        In each row all the basis elements are evaluated at the certain point
        (first row - x[0], ..., last row - x[-1]).

    indices
        The indices array of a CSR array of the b-spline design matrix.
    r   r8   r*   r9   r:   r;   r<   r=   Ncompute_design_matrix)r>   r%   r?   r@   r#   rA   rD   rE   zerosfloat64DESIGN_MAT_MODULE)r3   rF   rH   rK   indicesrM   rN   rO   bspline_basisrR   datadesign_mat_kernels               r   _make_design_matrixr]     s   8 	

QA444I 'HHOOagaj3&*s24f9aKDF F F JqwqzQUQY788M$]Ha@@MMAGAJ$q(S02FdAq!YmQ71:      :agajAE*$,???D(2G= =
S(1,46)]D'wqz#$ $ $ =r   r8   c           	      r   |dk     rt          | |           S | \  }}}||k    rt          d|d| d         d          t          d          fdt          |j        dd                   z  z   }	 t          |          D ]}||dz   d	         |d| dz
           z
  }||         }|dd	|z
           |dd
|z
           z
  |z  |z  }t          j        |t          j	        |f|j        dd         z             f         }|dd	         }|dz  }n%# t          $ r}t          d|z            |d}~ww xY w|||fS )a  
    Compute the spline representation of the derivative of a given spline

    Parameters
    ----------
    tck : tuple of (t, c, k)
        Spline whose derivative to compute
    n : int, optional
        Order of derivative to evaluate. Default: 1

    Returns
    -------
    tck_der : tuple of (t2, c2, k2)
        Spline of order k2=k-n representing the derivative
        of the input spline.

    Notes
    -----
    .. seealso:: :class:`scipy.interpolate.splder`

    See Also
    --------
    splantider, splev, spalde
    r   zOrder of derivative (n = z") must be <= order of spline (k = r<   )NNr8   zIThe spline has internal repeated knots and is not differentiable %d times)
splantiderr2   slicelenr>   ranger%   r_rB   rV   FloatingPointError)	tckrM   rF   rG   rH   shjdtes	            r   splderrn   F  s   2 	1uu#r"""GAq!1uuj9:CFFFD E E 	E ++73qwqrr{#3#33	4BLq 	 	A
 1Q3r6Qq!AvY&BBB1RT6Qu1uX%*R/A 28QD17122;$67778A!B$AFAA	  L L L ?BCD E EJK	LL a7Ns   1BD 
D1D,,D1c                 <   |dk     rt          | |           S | \  }}}t          d          fdt          |j        dd                   z  z   }t	          |          D ]}||dz   d         |d| dz
           z
  }||         }t          j        |d| dz
           |z  d          |dz   z  }t
          j        t          j        d|j        dd         z             ||d         g|dz   z  f         }t
          j        |d         ||d         f         }|dz  }|||fS )	a  
    Compute the spline for the antiderivative (integral) of a given spline.

    Parameters
    ----------
    tck : tuple of (t, c, k)
        Spline whose antiderivative to compute
    n : int, optional
        Order of antiderivative to evaluate. Default: 1

    Returns
    -------
    tck_ader : tuple of (t2, c2, k2)
        Spline of order k2=k+n representing the antiderivative of the input
        spline.

    See Also
    --------
    splder, splev, spalde

    Notes
    -----
    The `splder` function is the inverse operation of this function.
    Namely, ``splder(splantider(tck))`` is identical to `tck`, modulo
    rounding error.

    .. seealso:: :class:`scipy.interpolate.splantider`
    r   Nr`   r8   )axisr8   ra   r<   )	rn   rd   re   r>   rf   r%   cumsumrg   rV   )ri   rM   rF   rG   rH   rj   rk   rl   s           r   rc   rc     s7   : 	1uucA2GAq! ++'#agabbk"2"22	2B1XX   qsttWq1"Q$xVK%A2a4%2A...!a%8GDJtagabbk122"w!A#' ( GAaD!QrUN#	Qa7Nr   c                       e Zd ZdZddZedd            Zed             Zedd            Z	edd	            Z
ddZd Zd ZddZddZddZd
S )BSplinea  Univariate spline in the B-spline basis.

    .. math::
        S(x) = \sum_{j=0}^{n-1} c_j  B_{j, k; t}(x)

    where :math:`B_{j, k; t}` are B-spline basis functions of degree `k`
    and knots `t`.

    Parameters
    ----------
    t : ndarray, shape (n+k+1,)
        knots
    c : ndarray, shape (>=n, ...)
        spline coefficients
    k : int
        B-spline degree
    extrapolate : bool or 'periodic', optional
        whether to extrapolate beyond the base interval, ``t[k] .. t[n]``,
        or to return nans.
        If True, extrapolates the first and last polynomial pieces of b-spline
        functions active on the base interval.
        If 'periodic', periodic extrapolation is used.
        Default is True.
    axis : int, optional
        Interpolation axis. Default is zero.

    Attributes
    ----------
    t : ndarray
        knot vector
    c : ndarray
        spline coefficients
    k : int
        spline degree
    extrapolate : bool
        If True, extrapolates the first and last polynomial pieces of b-spline
        functions active on the base interval.
    axis : int
        Interpolation axis.
    tck : tuple
        A read-only equivalent of ``(self.t, self.c, self.k)``

    Notes
    -----
    B-spline basis elements are defined via

    .. math::
        B_{i, 0}(x) = 1, \textrm{if $t_i \le x < t_{i+1}$, otherwise $0$,}

        B_{i, k}(x) = \frac{x - t_i}{t_{i+k} - t_i} B_{i, k-1}(x)
                 + \frac{t_{i+k+1} - x}{t_{i+k+1} - t_{i+1}} B_{i+1, k-1}(x)

    **Implementation details**

    - At least ``k+1`` coefficients are required for a spline of degree `k`,
      so that ``n >= k+1``. Additional coefficients, ``c[j]`` with
      ``j > n``, are ignored.

    - B-spline basis elements of degree `k` form a partition of unity on the
      *base interval*, ``t[k] <= x <= t[n]``.

    - Based on [1]_ and [2]_

    .. seealso:: :class:`scipy.interpolate.BSpline`

    References
    ----------
    .. [1] Tom Lyche and Knut Morken, Spline methods,
        http://www.uio.no/studier/emner/matnat/ifi/INF-MAT5340/v05/undervisningsmateriale/
    .. [2] Carl de Boor, A practical guide to splines, Springer, 2001.
    Tr   c                    t          j        |          | _        t          j        |          | _        t          j        |t          j                  | _        |dk    r|| _	        nt          |          | _	        | j        j        d         | j        z
  dz
  }t          j        || j        j                  }|| _        |dk    r t          j        | j        |d          | _        |dk     rt#          d          | j        j        dk    rt#          d          || j        dz   k     rt#          dd|z  dz   |fz            t          j        | j                  dk                                     rt#          d	          t)          t          j        | j        ||dz                                dk     rt#          d
          t          j        | j                                                  st#          d          | j        j        dk     rt#          d          | j        j        d         |k     rt#          d          t1          | j        j                  }t          j        | j        |          | _        d S )Nr*   periodicr   r8    Spline order cannot be negative.z$Knot vector must be one-dimensional.z$Need at least %d knots for degree %dr<   z(Knots must be in a non-decreasing order.z!Need at least two internal knots.z#Knots should not have nans or infs.z,Coefficients must be at least 1-dimensional.z0Knots, coefficients and degree are inconsistent.)operatorindexrH   r%   asarrayrG   r.   rW   rF   rK   boolr>   r   _normalize_axis_indexndimrp   moveaxisr2   diffanyre   uniquer0   r1   r+   r   )selfrF   rG   rH   rK   rp   rM   rl   s           r   __init__zBSpline.__init__  s?   ""a'>>>*$$*D#K00DFLOdf$q(-dDFK@@ 	199 ]46433DFq55?@@@6;!CDDDtvz>>CcAgq\* + + +Idf!&&(( 	IGHHHt{46!AaC%=))**Q..@AAA}TV$$((** 	DBCCC6;??KLLL6<?QBD D D %%'b999r   c                     t                               |           }|||c|_        |_        |_        ||_        ||_        |S )zConstruct a spline without making checks.
        Accepts same parameters as the regular constructor. Input arrays
        `t` and `c` must of correct shape and dtype.
        )object__new__rF   rG   rH   rK   rp   )clsrF   rG   rH   rK   rp   r   s          r   construct_fastzBSpline.construct_fast/  s?     ~~c""!"Aq&	r   c                 *    | j         | j        | j        fS )z@Equivalent to ``(self.t, self.c, self.k)`` (read-only).
        )rF   rG   rH   r   s    r   ri   zBSpline.tck;  s     vtvtv%%r   c                    t          |          dz
  }t          |          }t          j        |d         dz
  f|z  ||d         dz   f|z  f         }t          j        |          }d||<   |                     ||||          S )ao  Return a B-spline basis element ``B(x | t[0], ..., t[k+1])``.

        Parameters
        ----------
        t : ndarray, shape (k+2,)
            internal knots
        extrapolate : bool or 'periodic', optional
            whether to extrapolate beyond the base interval,
            ``t[0] .. t[k+1]``, or to return nans.
            If 'periodic', periodic extrapolation is used.
            Default is True.

        Returns
        -------
        basis_element : callable
            A callable representing a B-spline basis element for the knot
            vector `t`.

        Notes
        -----
        The degree of the B-spline, `k`, is inferred from the length of `t` as
        ``len(t)-2``. The knot vector is constructed by appending and
        prepending ``k+1`` elements to internal knots `t`.

        .. seealso:: :class:`scipy.interpolate.BSpline`
        r<   r   r8   ra   g      ?)re   r6   r%   rg   
zeros_liker   )r   rF   rK   rH   rG   s        r   basis_elementzBSpline.basis_elementA  s    8 FFQJAGQqT!VIM1quQwj1n45OA!!!!Q;777r   Fc                 \   t          |d          }t          |d          }|dk    rt          |          }|dk     rt          d          |j        dk    s(t	          j        |dd         |dd         k               rt          d| d	          t          |          d
|z  d
z   k     rt          d| d	          |dk    r6|j        |z
  dz
  }||         |||         z
  ||         ||         z
  z  z   }d}nX|sVt          |          ||         k     s*t          |          ||j
        d         |z
  dz
           k    rt          d| d	          |j
        d         }||dz   z  }|t          j        t          j                  j	        k     rt          j        }nt          j        }t          j        ||dz   z  |          }t          j        d|dz   |dz   z  |dz   |          }	t#          |||||          \  }
}t%          |
||	f|j
        d         |j
        d         |z
  dz
  f          S )a  
        Returns a design matrix as a CSR format sparse array.

        Parameters
        ----------
        x : array_like, shape (n,)
            Points to evaluate the spline at.
        t : array_like, shape (nt,)
            Sorted 1D array of knots.
        k : int
            B-spline degree.
        extrapolate : bool or 'periodic', optional
            Whether to extrapolate based on the first and last intervals
            or raise an error. If 'periodic', periodic extrapolation is used.
            Default is False.

        Returns
        -------
        design_matrix : `csr_matrix` object
            Sparse matrix in CSR format where each row contains all the basis
            elements of the input row (first row = basis elements of x[0],
            ..., last row = basis elements x[-1]).

        Notes
        -----
        In each row of the design matrix all the basis elements are evaluated
        at the certain point (first row - x[0], ..., last row - x[-1]).
        `nt` is a length of the vector of knots: as far as there are
        `nt - k - 1` basis elements, `nt` should be not less than `2 * k + 2`
        to have at least `k + 1` basis element.

        Out of bounds `x` raises a ValueError.

        .. note::
            This method returns a `csr_matrix` instance as CuPy still does not
            have `csr_array`.

        .. seealso:: :class:`scipy.interpolate.BSpline`
        Trv   r   rw   r8   Nra   z2Expect t to be a 1-D sorted array_like, but got t=.r<   zLength t is not enough for k=FzOut of bounds w/ x = r*   )r>   )r6   r{   r2   r}   rB   r   re   sizeminmaxr>   r%   iinfoint32r@   rD   aranger]   r   )r   r3   rF   rH   rK   rM   nnz	int_dtyperY   indptrr[   s              r   design_matrixzBSpline.design_matrixd  sl   R At$$At$$*$${++Kq55?@@@6Q;;"&1223B300; +&'+ + + , , , q66AEAIAQAAABBB*$$ 
QA!AaDQqTAaD[11AKK 	;VVad]]A171:>A+=)> > > 9Q999::: GAJ1q5kDJ''+++
II
I*Q!a%[	:::QQ1q5 11q5	JJJ ,q!['
 
g 7F#71:qwqzA~12
 
 
 	
r   Nc           
         || j         }t          j        |          }|j        |j        }}t          j        t          j        |          t          j                  }|dk    rb| j        j	        | j
        z
  dz
  }| j        | j
                 || j        | j
                 z
  | j        |         | j        | j
                 z
  z  z   }d}t          j        t          |          t          t          j        | j        j        dd                             f| j        j                  }|                     ||||           |                    || j        j        dd         z             }| j        dk    rft+          t-          |j                            }|||| j        z            |d|         z   ||| j        z   d         z   }|                    |          }|S )a  
        Evaluate a spline function.

        Parameters
        ----------
        x : array_like
            points to evaluate the spline at.
        nu : int, optional
            derivative to evaluate (default is 0).
        extrapolate : bool or 'periodic', optional
            whether to extrapolate based on the first and last intervals
            or return nans. If 'periodic', periodic extrapolation is used.
            Default is `self.extrapolate`.

        Returns
        -------
        y : array_like
            Shape is determined by replacing the interpolation axis
            in the coefficient array with the shape of `x`.
        Nr*   rv   r8   Fr   )rK   r%   rz   r>   r}   r.   ravelrW   rF   r   rH   rD   re   r   rB   rC   rG   r   	_evaluatereshaperp   listrf   	transpose)	r   r3   rJ   rK   x_shapex_ndimrM   rL   	dim_orders	            r   __call__zBSpline.__call__  s   * *KLOO'16"4:a==EEE *$$df$q(Atv!dfTVn"49=:H "I IAKjVVSabb!122334DFLJ J J 	q"k3///kk'DFL$44559>>U38__--I&	!112'6'"#&*++,-  --	**C
r   c                     | j         j        j        s| j                                         | _         | j        j        j        s | j                                        | _        d S d S r`   )rF   flagsc_contiguousr-   rG   r   s    r   _ensure_c_contiguouszBSpline._ensure_c_contiguous  sP    v|( 	#V[[]]DFv|( 	#V[[]]DFFF	# 	#r   c           	          t          | j        | j                            | j        j        d         d          | j        ||||           d S )Nr   ra   )rS   rF   rG   r   r>   rH   )r   rI   rJ   rK   rL   s        r   r   zBSpline._evaluate  sI    Q!D!DRc	; 	; 	; 	; 	;r   r8   c                 <   | j         }t          | j                  t          |          z
  }|dk    r7t          j        |t          j        |f|j        dd         z             f         }t          | j        || j        f|          } | j	        || j
        | j        dS )al  
        Return a B-spline representing the derivative.

        Parameters
        ----------
        nu : int, optional
            Derivative order.
            Default is 1.

        Returns
        -------
        b : BSpline object
            A new instance representing the derivative.

        See Also
        --------
        splder, splantider
        r   r8   NrK   rp   )rG   re   rF   r%   rg   rV   r>   rn   rH   r   rK   rp   )r   rJ   rG   ctri   s        r   
derivativezBSpline.derivative  s    & F[[3q66!664:reagabbk&9:::;Adfa("--"t"CT5E(,	3 3 3 	3r   c                 \   | j         }t          | j                  t          |          z
  }|dk    r7t          j        |t          j        |f|j        dd         z             f         }t          | j        || j        f|          }| j	        dk    rd}n| j	        } | j
        ||| j        dS )a  
        Return a B-spline representing the antiderivative.

        Parameters
        ----------
        nu : int, optional
            Antiderivative order. Default is 1.

        Returns
        -------
        b : BSpline object
            A new instance representing the antiderivative.

        Notes
        -----
        If antiderivative is computed and ``self.extrapolate='periodic'``,
        it will be set to False for the returned instance. This is done because
        the antiderivative is no longer periodic and its correct evaluation
        outside of the initially given x interval is difficult.

        See Also
        --------
        splder, splantider
        r   r8   Nrv   Fr   )rG   re   rF   r%   rg   rV   r>   rc   rH   rK   r   rp   )r   rJ   rG   r   ri   rK   s         r   antiderivativezBSpline.antiderivative  s    2 F[[3q66!664:reagabbk&9:::;A$&!TV,b11z))KK*K"t"C[(,	3 3 3 	3r   c           
         || j         }|                                  d}||k     r||}}d}| j        j        | j        z
  dz
  }|dk    ra|s_t          || j        | j                                                           }t          || j        |                                                   }t          j	        dt          t          j        | j        j        dd                             f| j        j                  }| j        }t!          | j                  t!          |          z
  }|dk    r7t          j        |t          j        |f|j        dd         z             f         }t'          | j        || j        fd          \  }	}
}|dk    r_| j        | j                 | j        |         }}||z
  }||z
  }t)          ||          \  }}|dk    rmt          j        ||gt          j                  }t/          |	|
                    |
j        d         d          ||dd|           |d         |d         z
  }||z  }nSt          j        dt          t          j        | j        j        dd                             f| j        j                  }|||z
  |z  z   }||z   }||k    rlt          j        ||gt          j                  }t/          |	|
                    |
j        d         d          ||dd|           ||d         |d         z
  z  }nBt          j        ||gt          j                  }t/          |	|
                    |
j        d         d          ||dd|           ||d         |d         z
  z  }t          j        |||z   |z
  gt          j                  }t/          |	|
                    |
j        d         d          ||dd|           ||d         |d         z
  z  }ngt          j        ||gt          j                  }t/          |	|
                    |
j        d         d          ||d||           |d         |d         z
  }||z  }|                    |
j        dd                   S )	a  
        Compute a definite integral of the spline.

        Parameters
        ----------
        a : float
            Lower limit of integration.
        b : float
            Upper limit of integration.
        extrapolate : bool or 'periodic', optional
            whether to extrapolate beyond the base interval,
            ``t[k] .. t[-k-1]``, or take the spline to be zero outside of the
            base interval. If 'periodic', periodic extrapolation is used.
            If None (default), use `self.extrapolate`.

        Returns
        -------
        I : array_like
            Definite integral of the spline over the interval ``[a, b]``.
        Nr8   ra   rv   r<   r*   r   F)rK   r   rF   r   rH   r   itemr   r%   rD   r   rB   rC   rG   r>   r   re   rg   rV   rc   divmodrz   rW   rS   r   )r   abrK   signrM   rL   rG   r   tacakatsteperiodinterval	n_periodsleftr3   integrals                       r   	integratezBSpline.integrateB  sY   * *K 	!!### q55aqADFK$& 1$*$$[$Atvdf~**,,--AAtvay~~''((A jBGDFL,--../tv|E E E F[[3q66!664:reagabbk&9:::;ADF 3Q77
B*$$ VDF^TVAYB"WF1uH$Xv66OIt1}}L"b>>> RZZR%@%@!#Q5#7 7 7q6CF?I%:q#bgdfl1226F.G.G*H*H&I,0FL: : : a"f&&ADA BwwL!Qt|<<< RZZR%@%@!#Q5#7 7 7CFSVO+L!R=== RZZR%@%@!#Q5#7 7 7CFSVO+L"b1frk!2$,GGG RZZR%@%@!#Q5#7 7 7CFSVO+ aV4<888ARBHQK!<!<A{C9 9 91vAHD---r   )Tr   )TF)r   Nrq   r`   )__name__
__module____qualname____doc__r   classmethodr   propertyri   r   r   r   r   r   r   r   r   r   r   r   rt   rt     s-       F FP,: ,: ,: ,:\ 	 	 	 [	 & & X&
  8  8  8 [ 8D Y
 Y
 Y
 [Y
v2 2 2 2h# # #; ; ;3 3 3 38&3 &3 &3 &3Ph. h. h. h. h. h.r   rt   r   rq   )rx   r%   
cupy._corer   cupy._core._scalarr   cupyx.scipy.sparser   numpyrB   TYPES	INT_TYPESINTERVAL_KERNEL	RawModulerA   D_BOOR_KERNELrE   DESIGN_MAT_KERNELrX   r#   r+   r6   rS   r]   rn   rc   rt   r   r   r   <module>r      s           + + + + + + ) ) ) ) ) )    	,-K 	4l !$.	/4 4 4
`D 	DDeDDDF F F
 2 #DN	O. .#,. . ./ / /     	 	 	 	"! "! "!J2 2 2j9 9 9 9x3 3 3 3lr. r. r. r. r. r. r. r. r. r.r   