code: def eye(N, M=None, dtype=hl.tfloat64):
      """
      Construct a 2-D :class:`.NDArrayExpression` with ones on the *main* diagonal
      and zeros elsewhere.
  
      Examples
      --------
      >>> hl.eval(hl.nd.eye(3))
      array([[1., 0., 0.],
             [0., 1., 0.],
             [0., 0., 1.]])
      >>> hl.eval(hl.nd.eye(2, 5, dtype=hl.tint32))
      array([[1, 0, 0, 0, 0],
             [0, 1, 0, 0, 0]], dtype=int32)
  
      Parameters
      ----------
      N : :class:`.NumericExpression` or Python number
        Number of rows in the output.
      M : :class:`.NumericExpression` or Python number, optional
        Number of columns in the output. If None, defaults to `N`.
      dtype : numeric :class:`.HailType`, optional
        Element type of the returned array. Defaults to :py:data:`.tfloat64`
  
      Returns
      -------
      :class:`.NDArrayExpression`
          An (N, M) matrix with ones on the main diagonal, zeros elsewhere.
  
      See Also
      --------
      :func:`.identity`
      :func:`.diagonal`
  
      """
  
      n_row = hl.int32(N)
      if M is None:
          n_col = n_row
      else:
          n_col = hl.int32(M)
  
      return hl.nd.array(
          hl.range(0, n_row * n_col).map(
              lambda i: hl.if_else(
                  (i // n_col) == (i % n_col),
                  hl.literal(1, dtype),
                  hl.literal(0, dtype),
              )
          )
      ).reshape((n_row, n_col))
  
imports: from functools import reduce
  import hail
  from hail.expr.functions import _ndarray
  from hail.expr.functions import array
  from hail.expr.types import HailType, tfloat64, tfloat32, ttuple, tndarray
  from hail.typecheck import typecheck, nullable, oneof, tupleof, sequenceof
  from hail.expr.expressions import expr_int32, expr_int64, expr_tuple, expr_any, expr_array, expr_ndarray, expr_numeric, Int64Expression, cast_expr, construct_expr, expr_bool, unify_all
  from hail.expr.expressions.typed_expressions import NDArrayNumericExpression
  from hail.ir import NDArrayQR, NDArrayInv, NDArrayConcat, NDArraySVD, NDArrayEigh, Apply
label_desc: Use image node_id 16 for calling a global function with example usage: eye(N, M, dtype) and returns: hl