code: def make_diagonal(D, offset=0, axis1=0, axis2=1):
      # Numpy doesn't offer a complement to np.diagonal: a function to create new
      # diagonal arrays with extra dimensions. We need such a function for the
      # gradient of np.diagonal and it's also quite handy to have. So here it is.
      if not (offset == 0 and axis1 == -1 and axis2 == -2):
          raise NotImplementedError(
              "Currently make_diagonal only supports offset=0, axis1=-1, axis2=-2"
          )
  
      # We use a trick: calling np.diagonal returns a view on the original array,
      # so we can modify it in-place. (only valid for numpy version >= 1.10.)
      new_array = _np.zeros(D.shape + (D.shape[-1],))
      new_array_diag = _np.diagonal(
          new_array, offset=0, axis1=-1, axis2=-2
      )
      new_array_diag.flags.writeable = True
      new_array_diag[:] = D
      return new_array
  
imports: from __future__ import absolute_import
  import types
  import warnings
  from autograd.extend import primitive, notrace_primitive
  import numpy
  import autograd.builtins
  from numpy.core.einsumfunc import _parse_einsum_input
label_desc: Use image node_id 13 for calling a global function with example usage: make_diagonal(D, offset, axis1, axis2) and returns: new_array