/**
   * Constructor for FlexCompRowMatrix
   *
   * @param A Matrix to copy contents from
   * @param deep True for a deep copy, false for a reference copy. A reference copy can only be made
   *     of an <code>FlexCompRowMatrix</code>
   */
  public FlexCompRowMatrix(Matrix A, boolean deep) {
    super(A);
    rowD = new SparseVector[numRows];

    if (deep) {
      for (int i = 0; i < numRows; ++i) rowD[i] = new SparseVector(numColumns);
      set(A);
    } else {
      FlexCompRowMatrix Ar = (FlexCompRowMatrix) A;
      for (int i = 0; i < numRows; ++i) rowD[i] = Ar.getRow(i);
    }
  }
  /**
   * Important method used in compute CCA
   *
   * @param X
   * @return
   */
  public static FlexCompRowMatrix computeSparseInverseSqRoot(FlexCompRowMatrix X) {

    FlexCompRowMatrix diagInvEntries = new FlexCompRowMatrix(X.numRows(), X.numColumns());

    System.out.println("++Beginning Sparse Inverse Sq. Root++");

    for (MatrixEntry e : X) {
      if (e.row() == e.column() && e.get() != 0) {
        diagInvEntries.set(e.row(), e.column(), 1 / Math.sqrt(e.get()));
      }
      if (e.row() == e.column() && e.get() == 0) {
        diagInvEntries.set(e.row(), e.column(), 10000); // Some large
        // value

      }
    }

    System.out.println("++Finished Sparse Inverse Sq. Root++");

    return diagInvEntries;
  }
  public static FlexCompRowMatrix transform(FlexCompRowMatrix a) {

    Iterator<MatrixEntry> aIt = a.iterator(); // iterating over the elements
    // in the matrix
    double ent = 0;

    while (aIt.hasNext()) {
      MatrixEntry ment = aIt.next();
      ent = ment.get();
      if (true) ent = Math.log(ent); // log transform, a good thing to do I
      // guess
      if (true) ent = Math.sqrt(ent); // this is also a valid thing to do

      a.set(ment.row(), ment.column(), ent); // Performing tranforms on
      // the matrix
    }

    return a;
  }
 public void reset(int r, int c) {
   for (FlexCompRowMatrix cell : this.matrix) {
     cell.set(r, c, 0);
   }
 }