code: public double[][] toArray() {
          int m = data.size();
          double[][] a = new double[m][ncols()];
          
          for (int i = 0; i < m; i++) {
              for (SparseArray.Entry item : get(i).x) {
                  a[i][item.i] = item.x;
              }
          }
          
          return a;
      }
docs: Returns a dense two-dimensional array containing the whole matrix in
  this dataset in proper sequence.
  
  @return a dense two-dimensional array containing the whole matrix in
  this dataset in proper sequence.