code: def taylor_approx(target, stencil, values):
      """Use taylor series to approximate up to second order derivatives.
  
      Args:
        target: An array of shape (..., n), a batch of n-dimensional points
          where one wants to approximate function value and derivatives.
        stencil: An array of shape broadcastable to (..., k, n), for each target
          point a set of k = triangle(n + 1) points to use on its approximation.
        values: An array of shape broadcastable to (..., k), the function value at
          each of the stencil points.
  
      Returns:
        An array of shape (..., k), for each target point the approximated
        function value, gradient and hessian evaluated at that point (flattened
        and in the same order as returned by derivative_names).
      """
      # Broadcast arrays to their required shape.
      batch_shape, ndim = target.shape[:-1], target.shape[-1]
      stencil = np.broadcast_to(
          stencil, batch_shape + (triangular(ndim + 1), ndim)
      )
      values = np.broadcast_to(values, stencil.shape[:-1])
  
      # Subtract target from each stencil point.
      delta_x = stencil - np.expand_dims(target, axis=-2)
      delta_xy = np.matmul(
          np.expand_dims(delta_x, axis=-1),
          np.expand_dims(delta_x, axis=-2),
      )
      i = np.arange(ndim)
      j, k = np.triu_indices(ndim, k=1)
  
      # Build coefficients for the Taylor series equations, namely:
      #   f(stencil) = coeffs @ [f(target), df/d0(target), ...]
      coeffs = np.concatenate(
          [
              np.ones(delta_x.shape[:-1] + (1,)),  # f(target)
              delta_x,  # df/di(target)
              delta_xy[..., i, i] / 2,  # d^2f/di^2(target)
              delta_xy[..., j, k],  # d^2f/{dj dk}(target)
          ],
          axis=-1,
      )
  
      # Then: [f(target), df/d0(target), ...] = coeffs^{-1} @ f(stencil)
      return np.squeeze(
          np.matmul(np.linalg.inv(coeffs), values[..., np.newaxis]),
          axis=-1,
      )
  
file_path: tf-quant-finance/tf_quant_finance/experimental/finite_difference/methods.py
imports: from autograd import elementwise_grad
  import autograd.numpy
  import pandas
  import sobol_seq
label_desc: Use image node_id 8 for calling a global function with example usage: taylor_approx(target, stencil, values) and returns: np