code: public static double[][] unitMatrix(final int dim) {
      final double[][] e = new double[dim][dim];
      for(int i = 0; i < dim; i++) {
        e[i][i] = 1;
      }
      return e;
    }
docs: Returns the unit / identity / "eye" matrix of the specified dimension.
  
  @param dim the dimensionality of the unit matrix
  @return the unit matrix of the specified dimension