code: public static Matrix create(int rows, int cols, boolean isDense) {
          // Estimate the number of bytes that the matrix will take up based on
          // its maximum dimensions and its sparsity.
          long size = (isDense)
              ? (long)rows * (long)cols * BYTES_PER_DOUBLE
              : (long)(rows * (long)cols * (BYTES_PER_DOUBLE * SPARSE_DENSITY));
  
          Runtime r = Runtime.getRuntime();
          // REMINDER: possibly GC here?
          long available = r.freeMemory();
  
          // See if it will fit into memory given how much is currently left.
          if (size < available) {
              if (isDense) {
                  if (size > Integer.MAX_VALUE) {
                      LOGGER.finer("too big for ArrayMatrix; creating new " + 
                           "OnDiskMatrix");
                      return new OnDiskMatrix(rows, cols);
                  } else {
                      LOGGER.finer("creating new (in memory) ArrayMatrix");
                      return new ArrayMatrix(rows, cols);
                  }
              } else {
                  LOGGER.finer("can fit sparse in memory; creating " + 
                           "new SparseMatrix");
                  return new YaleSparseMatrix(rows, cols);
              }
          } else { 
              // won't fit into memory
              LOGGER.finer("cannot fit in memory; creating new OnDiskMatrix");
              return new OnDiskMatrix(rows, cols);
          }
      }
docs: Creates a matrix of the given dimensions and selects the matrix
  implementation by considering the size and density of the new matrix with
  respect to the available memory for the JVM.
  
  @param rows the number of rows in the matrix
  @param cols the number of columns in the matrix
  @param isDense whether the returned matrix will contain mostly non-zero
  elements