code: def build_quadratic_1d(J, g, s, diag=None, s0=None):
      """Parameterize a multivariate quadratic function along a line.
  
      The resulting univariate quadratic function is given as follows:
      ::
          f(t) = 0.5 * (s0 + s*t).T * (J.T*J + diag) * (s0 + s*t) +
                 g.T * (s0 + s*t)
  
      Parameters
      ----------
      J : ndarray, sparse matrix or LinearOperator shape (m, n)
          Jacobian matrix, affects the quadratic term.
      g : ndarray, shape (n,)
          Gradient, defines the linear term.
      s : ndarray, shape (n,)
          Direction vector of a line.
      diag : None or ndarray with shape (n,), optional
          Addition diagonal part, affects the quadratic term.
          If None, assumed to be 0.
      s0 : None or ndarray with shape (n,), optional
          Initial point. If None, assumed to be 0.
  
      Returns
      -------
      a : float
          Coefficient for t**2.
      b : float
          Coefficient for t.
      c : float
          Free term. Returned only if `s0` is provided.
      """
      v = J.dot(s)
      a = np.dot(v, v)
      if diag is not None:
          a += np.dot(s * diag, s)
      a *= 0.5
  
      b = np.dot(g, s)
  
      if s0 is not None:
          u = J.dot(s0)
          b += np.dot(u, v)
          c = 0.5 * np.dot(u, u) + np.dot(g, s0)
          if diag is not None:
              b += np.dot(s0 * diag, s)
              c += 0.5 * np.dot(s0 * diag, s0)
          return a, b, c
      else:
          return a, b
  
imports: from math import copysign
  import numpy
  from numpy.linalg import norm
  from scipy.linalg import cho_factor, cho_solve, LinAlgError
  from scipy.sparse import issparse
  from scipy.sparse.linalg import LinearOperator, aslinearoperator
label_desc: Use image node_id 5 for calling a global function with example usage: build_quadratic_1d(J, g, s, diag, s0) and returns: a,  b,  c, a,  b