def build_quadratic_1d(J, g, s, diag=None, s0=None):
 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)

def build_quadratic_1d ( J , g , s , diag = None , s0 = None ) : 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 )
parameterize a multivariate quadratic function along a line .