code: def grad_dist2(ls, x1, x2=None):
      if x2 is None:
          x2 = x1
  
      # Rescale.
      x1 = x1 / ls
      x2 = x2 / ls
  
      N = x1.shape[0]
      M = x2.shape[0]
      D = x1.shape[1]
      gX = np.zeros((x1.shape[0], x2.shape[0], x1.shape[1]))
  
      code = """
      for (int i=0; i<N; i++)
        for (int j=0; j<M; j++)
          for (int d=0; d<D; d++)
            gX(i,j,d) = (2/ls(d))*(x1(i,d) - x2(j,d));
      """
      try:
          scipy.weave.inline(
              code,
              ["x1", "x2", "gX", "ls", "M", "N", "D"],
              type_converters=scipy.weave.converters.blitz,
              compiler="gcc",
          )
      except:
          # The C code weave above is 10x faster than this:
          for i in range(0, x1.shape[0]):
              gX[i, :, :] = 2 * (x1[i, :] - x2[:, :]) * (1 / ls)
  
      return gX
  
file_path: auptimizer/src/aup/Proposer/spearmint/gp.py
imports: import numpy
  import scipy.linalg
  import scipy.optimize
  import scipy.io
label_desc: Use image node_id 2 for calling a global function with example usage: grad_dist2(ls, x1, x2) and returns: gX