private static void writeRowsWithScores()

in src/main/java/com/twitter/sbf/simclusters_app/Main.java [120:140]


  private static void writeRowsWithScores(
      SparseRealMatrix z,
      PrintWriter writer
  ) throws IOException {
    //Print first line
    writer.println(String.format("%d %d", z.getNumRows(), z.getNumCols()));
    //Print row-wise data
    for (int i = 0; i < z.getNumRows(); i++) {
      int[] rowWithIndices = z.getColIdsForRow(i);
      double[] rowWithScores = z.getValuesForRow(i);
      for (int j = 0; j < rowWithIndices.length; j++) {
        if (j > 0) {
          writer.print(" ");
        }
        // Add 1 to get back 1-indexing
        writer.print(String.format("%d:%.2g", rowWithIndices[j] + 1, rowWithScores[j]));
      }
      writer.println();
    }
    writer.close();
  }