
    IR-e                     0    d dl mZ d dlZd Zd
dZdd	ZdS )    )	factorialNc                 P    dt          | dz
                                            z  S )z
    Find the bit (i.e. power of 2) immediately greater than or equal to N
    Note: this works for numbers up to 2 ** 64.
    Roughly equivalent to int(2 ** np.ceil(np.log2(N))).
       )int
bit_length)Ns    alib/python3.11/site-packages/astropy/timeseries/periodograms/lombscargle/implementations/utils.pybitceilr
      s%     AE

%%''''       c           	      ~   t          t          j        t          j        | |                    \  } }|*t	          t          j        |           d|z  z   dz             }t          j        ||j                  }| dz  dk    }t          j        	                    || |         
                    t                    ||                    | |          ||          }} t          j        | |dz  z
  
                    t                    d||z
            }|t          j        | |z
  t          j        |          ddt          j        f         z
  d          z  }t          |dz
            }t!          |          D ]H}	|	dk    r||	|	|z
  z  z  }||dz
  |	z
  z   }
t          j        	                    ||
||| |
z
  z  z             I|S )a  
    Extirpolate the values (x, y) onto an integer grid range(N),
    using lagrange polynomial weights on the M nearest points.

    Parameters
    ----------
    x : array-like
        array of abscissas
    y : array-like
        array of ordinates
    N : int
        number of integer bins to use. For best performance, N should be larger
        than the maximum of x
    M : int
        number of adjoining points on which to extirpolate.

    Returns
    -------
    yN : ndarray
        N extirpolated values associated with range(N)

    Examples
    --------
    >>> rng = np.random.default_rng(0)
    >>> x = 100 * rng.random(20)
    >>> y = np.sin(x)
    >>> y_hat = extirpolate(x, y)
    >>> x_hat = np.arange(len(y_hat))
    >>> f = lambda x: np.sin(x / 10)
    >>> np.allclose(np.sum(y * f(x)), np.sum(y_hat * f(x_hat)))
    True

    Notes
    -----
    This code is based on the C implementation of spread() presented in
    Numerical Recipes in C, Second Edition (Press et al. 1989; p.583).
    Ng      ?r   )dtyper      )mapnpravelbroadcast_arraysr   maxzerosr   addatastypeclipprodarangenewaxisr   range)xyr   Mresultintegersilo	numeratordenominatorjinds              r	   extirpolater(      s   L rx,Q2233DAqyq		C!G#a'(( Xaqw'''F 1uzHFIIfak((--q{;;;hY<H9qA
 '1qAv:%%c**Aq1u
5
5CBGAGbill111bj=&AA1EEEIAE""K1XX F Fq551A;&KQUQY
		&#yK1s7,CDEEEEMr   r      Tc	           	      `   ||z  }||z  }|dk    rt          d          t          t          j        t          j        | |                    \  } }|r#t          |          }|dk    rt          d          t          ||z            }	|                                 }
|dk    r-|t          j        dt          j	        z  |z  | |
z
  z            z  }| |
z
  |	z  |z  |	z  }t          |||	|          }t          j                            |          d|         }|
dk    rD||t          j        |          z  z   }|t          j        dt          j	        z  |
z  |z            z  }|	|j        z  }|	|j        z  }n||t          j        |          z  z   }t          j        |t          j        dt          j	        z  |z  | ddt          j        f         z                      }t          j        |t          j        dt          j	        z  |z  | ddt          j        f         z                      }||fS )a  Compute (approximate) trigonometric sums for a number of frequencies.

    This routine computes weighted sine and cosine sums::

        S_j = sum_i { h_i * sin(2 pi * f_j * t_i) }
        C_j = sum_i { h_i * cos(2 pi * f_j * t_i) }

    Where f_j = freq_factor * (f0 + j * df) for the values j in 1 ... N.
    The sums can be computed either by a brute force O[N^2] method, or
    by an FFT-based O[Nlog(N)] method.

    Parameters
    ----------
    t : array-like
        array of input times
    h : array-like
        array weights for the sum
    df : float
        frequency spacing
    N : int
        number of frequency bins to return
    f0 : float, optional
        The low frequency to use
    freq_factor : float, optional
        Factor which multiplies the frequency
    use_fft : bool
        if True, use the approximate FFT algorithm to compute the result.
        This uses the FFT with Press & Rybicki's Lagrangian extirpolation.
    oversampling : int (default = 5)
        oversampling freq_factor for the approximation; roughly the number of
        time samples across the highest-frequency sinusoid. This parameter
        contains the trade-off between accuracy and speed. Not referenced
        if use_fft is False.
    Mfft : int
        The number of adjacent points to use in the FFT approximation.
        Not referenced if use_fft is False.

    Returns
    -------
    S, C : ndarray
        summation arrays for frequencies f = df * np.arange(1, N + 1)
    r   zdf must be positivezMfft must be positivey               @Nr   )
ValueErrorr   r   r   r   r   r
   minexppir(   fftifftr   realimagdotcosr   sin)thdfr   f0freq_factoroversamplinguse_fftMfftNfftt0tnormgridfftgridfCSs                    r	   trig_sumrF   R   s   V +B+B	Qww.///rx,Q2233DAq @4yy1994555 q<'((UUWW66BF2:?a"f5666Ab&D2%-5!T400&++d##BQB'77R")A,,&&Arvb25j2o1222G7<7<bill""F1bfQY]Qqqq"*}-==>>??F1bfQY]Qqqq"*}-==>>??a4Kr   )Nr   )r   r   r)   Tr   )mathr   numpyr   r
   r(   rF    r   r	   <module>rJ      so             ( ( (@ @ @ @FM M M M M Mr   