code: public static DMatrix convertChunksToDMatrix(DataInfo di,
                                                   Chunk[] chunks,
                                                   int response,
                                                   int weight,
                                                   int fold,
                                                   boolean sparse) throws XGBoostError {
          int nRows = chunks[0]._len;
  
          DMatrix trainMat;
  
          float[] resp = malloc4f(nRows);
          float[] weights = null;
          if(-1 != weight) {
              weights = malloc4f(nRows);
          }
          try {
              if (sparse) {
                  Log.debug("Treating matrix as sparse.");
                  // 1 0 2 0
                  // 4 0 0 3
                  // 3 1 2 0
                  boolean csc = false; //di._cats == 0;
  
                  // truly sparse matrix - no categoricals
                  // collect all nonzeros column by column (in parallel), then stitch together into final data structures
                  if (csc) {
                      trainMat = csc(chunks, weight, nRows, di, resp, weights);
                  } else {
                      trainMat = csr(chunks, weight, response, nRows, di, resp, weights);
                  }
              } else {
                  trainMat = dense(chunks, weight, di, response, resp, weights);
              }
          } catch (NegativeArraySizeException e) {
              throw new IllegalArgumentException(technote(11,
                  "Data is too large to fit into the 32-bit Java float[] array that needs to be passed to the XGBoost C++ backend. Use H2O GBM instead."));
          }
  
          int len = (int) trainMat.rowNum();
          resp = Arrays.copyOf(resp, len);
          trainMat.setLabel(resp);
          if (weight!=-1){
              weights = Arrays.copyOf(weights, len);
              trainMat.setWeight(weights);
          }
  //    trainMat.setGroup(null); //fold //FIXME - only needed if CV is internally done in XGBoost
          return trainMat;
      }
docs: convert a set of H2O chunks (representing a part of a vector) to a sparse DMatrix
  @param response name of the response column
  @param weight name of the weight column
  @param fold name of the fold assignment column
  @return DMatrix
  @throws XGBoostError