code: def lombscargle(
      x,
      y,
      freqs,
      precenter=False,
      normalize=False,
  ):
      """
      lombscargle(x, y, freqs)
      Computes the Lomb-Scargle periodogram.
      The Lomb-Scargle periodogram was developed by Lomb [1]_ and further
      extended by Scargle [2]_ to find, and test the significance of weak
      periodic signals with uneven temporal sampling.
      When *normalize* is False (default) the computed periodogram
      is unnormalized, it takes the value ``(A**2) * N/4`` for a harmonic
      signal with amplitude A for sufficiently large N.
      When *normalize* is True the computed periodogram is normalized by
      the residuals of the data around a constant reference model (at zero).
      Input arrays should be one-dimensional and will be cast to float64.
  
      Parameters
      ----------
      x : array_like
          Sample times.
      y : array_like
          Measurement values.
      freqs : array_like
          Angular frequencies for output periodogram.
      precenter : bool, optional
          Pre-center amplitudes by subtracting the mean.
      normalize : bool, optional
          Compute normalized periodogram.
  
      Returns
      -------
      pgram : array_like
          Lomb-Scargle periodogram.
  
      Raises
      ------
      ValueError
          If the input arrays `x` and `y` do not have the same shape.
  
      Notes
      -----
      This subroutine calculates the periodogram using a slightly
      modified algorithm due to Townsend [3]_ which allows the
      periodogram to be calculated using only a single pass through
      the input arrays for each frequency.
      The algorithm running time scales roughly as O(x * freqs) or O(N^2)
      for a large number of samples and frequencies.
  
      References
      ----------
      .. [1] N.R. Lomb "Least-squares frequency analysis of unequally spaced
             data", Astrophysics and Space Science, vol 39, pp. 447-462, 1976
      .. [2] J.D. Scargle "Studies in astronomical time series analysis. II -
             Statistical aspects of spectral analysis of unevenly spaced data",
             The Astrophysical Journal, vol 263, pp. 835-853, 1982
      .. [3] R.H.D. Townsend, "Fast calculation of the Lomb-Scargle
             periodogram using graphics processing units.", The Astrophysical
             Journal Supplement Series, vol 191, pp. 247-253, 2010
  
      See Also
      --------
      istft: Inverse Short Time Fourier Transform
      check_COLA: Check whether the Constant OverLap Add (COLA) constraint is met
      welch: Power spectral density by Welch's method
      spectrogram: Spectrogram by Welch's method
      csd: Cross spectral density by Welch's method
  
      Examples
      --------
      >>> import cusignal
      >>> import cupy as cp
      >>> import matplotlib.pyplot as plt
      First define some input parameters for the signal:
      >>> A = 2.
      >>> w = 1.
      >>> phi = 0.5 * cp.pi
      >>> nin = 1000
      >>> nout = 100000
      >>> frac_points = 0.9 # Fraction of points to select
      Randomly select a fraction of an array with timesteps:
      >>> r = cp.random.rand(nin)
      >>> x = cp.linspace(0.01, 10*cp.pi, nin)
      >>> x = x[r >= frac_points]
      Plot a sine wave for the selected times:
      >>> y = A * cp.sin(w*x+phi)
      Define the array of frequencies for which to compute the periodogram:
      >>> f = cp.linspace(0.01, 10, nout)
      Calculate Lomb-Scargle periodogram:
      >>> pgram = cusignal.lombscargle(x, y, f, normalize=True)
      Now make a plot of the input data:
      >>> plt.subplot(2, 1, 1)
      >>> plt.plot(cp.asnumpy(x), cp.asnumpy(y), 'b+')
      Then plot the normalized periodogram:
      >>> plt.subplot(2, 1, 2)
      >>> plt.plot(cp.asnumpy(f), cp.asnumpy(pgram))
      >>> plt.show()
      """
  
      x = cp.asarray(x, dtype=cp.float64)
      y = cp.asarray(y, dtype=cp.float64)
      freqs = cp.asarray(freqs, dtype=cp.float64)
      pgram = cp.empty(freqs.shape[0], dtype=cp.float64)
  
      assert x.ndim == 1
      assert y.ndim == 1
      assert freqs.ndim == 1
  
      # Check input sizes
      if x.shape[0] != y.shape[0]:
          raise ValueError("Input arrays do not have the same size.")
  
      y_dot = cp.zeros(1, dtype=cp.float64)
      if normalize:
          cp.dot(y, y, out=y_dot)
  
      if precenter:
          y_in = y - y.mean()
      else:
          y_in = y
  
      _lombscargle(x, y_in, freqs, pgram, y_dot)
  
      return pgram
  
file_path: cusignal/python/cusignal/spectral_analysis/spectral.py
imports: import warnings
  import cupy
  from ..filtering import filtering
  from ..utils.arraytools import _as_strided, _const_ext, _even_ext, _odd_ext, _zero_ext
  from ..windows.windows import get_window
  from ._spectral_cuda import _lombscargle
label_desc: Use image node_id 1 for calling a global function with example usage: lombscargle(x, y, freqs, precenter, normalize) and returns: pgram