def diagflat(v, k=0):
 if isinstance(v, cupy.ndarray):
  return cupy.diag(v.ravel(), k)
 else:
  return cupy.diag(numpy.ndarray(v).ravel(), k)

def diagflat ( v , k = 0 ) : if isinstance ( v , cupy . ndarray ) : return cupy . diag ( v . ravel ( ) , k ) else : return cupy . diag ( numpy . ndarray ( v ) . ravel ( ) , k )
creates a diagonal array from the flattened input .