code: def square(t, duty=0.5):
      """
      Return a periodic square-wave waveform.
  
      The square wave has a period ``2*pi``, has value +1 from 0 to
      ``2*pi*duty`` and -1 from ``2*pi*duty`` to ``2*pi``. `duty` must be in
      the interval [0,1].
  
      Note that this is not band-limited.  It produces an infinite number
      of harmonics, which are aliased back and forth across the frequency
      spectrum.
  
      Parameters
      ----------
      t : array_like
          The input time array.
      duty : array_like, optional
          Duty cycle.  Default is 0.5 (50% duty cycle).
          If an array, causes wave shape to change over time, and must be the
          same length as t.
  
      Returns
      -------
      y : ndarray
          Output array containing the square waveform.
  
      Examples
      --------
      A 5 Hz waveform sampled at 500 Hz for 1 second:
  
      >>> from scipy import signal
      >>> import matplotlib.pyplot as plt
      >>> t = np.linspace(0, 1, 500, endpoint=False)
      >>> plt.plot(t, signal.square(2 * np.pi * 5 * t))
      >>> plt.ylim(-2, 2)
  
      A pulse-width modulated sine wave:
  
      >>> plt.figure()
      >>> sig = np.sin(2 * np.pi * t)
      >>> pwm = signal.square(2 * np.pi * 30 * t, duty=(sig + 1)/2)
      >>> plt.subplot(2, 1, 1)
      >>> plt.plot(t, sig)
      >>> plt.subplot(2, 1, 2)
      >>> plt.plot(t, pwm)
      >>> plt.ylim(-1.5, 1.5)
  
      """
      t, w = asarray(t), asarray(duty)
      w = asarray(w + (t - t))
      t = asarray(t + (w - w))
      if t.dtype.char in ["fFdD"]:
          ytype = t.dtype.char
      else:
          ytype = "d"
  
      y = zeros(t.shape, ytype)
  
      # width must be between 0 and 1 inclusive
      mask1 = (w > 1) | (w < 0)
      place(y, mask1, nan)
  
      # on the interval 0 to duty*2*pi function is 1
      tmod = mod(t, 2 * pi)
      mask2 = (1 - mask1) & (tmod < w * 2 * pi)
      place(y, mask2, 1)
  
      # on the interval duty*2*pi to 2*pi function is
      #  (pi*(w+1)-tmod) / (pi*(1-w))
      mask3 = (1 - mask1) & (1 - mask2)
      place(y, mask3, -1)
      return y
  
file_path: catboost/contrib/python/scipy/py3/scipy/signal/waveforms.py
imports: import numpy
  from numpy import asarray, zeros, place, nan, mod, pi, extract, log, sqrt, exp, cos, sin, polyval, polyint
label_desc: Use image node_id 2 for calling a global function with example usage: square(t, duty) and returns: y