code: def bernstein_companion(coeffs):
      r
      sigma_coeffs, degree, effective_degree = _get_sigma_coeffs(coeffs)
      if effective_degree == 0:
          return np.empty((0, 0), order="F"), degree, 0
  
      companion = np.zeros((effective_degree, effective_degree), order="F")
      companion.flat[
          effective_degree :: effective_degree + 1  # noqa: E203
      ] = 1.0
      companion[0, :] = -sigma_coeffs[::-1]
      return companion, degree, effective_degree
docs: r"""Compute a companion matrix for a polynomial in Bernstein basis.
  
      .. note::
  
         This assumes the caller passes in a 1D array but does not check.
  
      This takes the polynomial
  
      .. math::
  
         f(s) = \sum_{j = 0}^n b_{j, n} \cdot C_j.
  
      and uses the variable :math:`\sigma = \frac{s}{1 - s}` to rewrite as
  
      .. math::
  
         f(s) = (1 - s)^n \sum_{j = 0}^n \binom{n}{j} C_j \sigma^j.
  
      This converts the Bernstein coefficients :math:`C_j` into "generalized
      Bernstein" coefficients :math:`\widetilde{C_j} = \binom{n}{j} C_j`.
  
      Args:
          coeffs (numpy.ndarray): A 1D array of coefficients in
              the Bernstein basis.
  
      Returns:
          Tuple[numpy.ndarray, int, int]: A triple of
  
          * 2D NumPy array with the companion matrix.
          * the "full degree" based on the size of ``coeffs``
          * the "effective degree" determined by the number of leading zeros.