void addMatrixRow(MatDoub U, int row, MatDoub &out) {

    int dummy = -1000;

    for(int i=0; i<out.nrows(); i++) {
        out[i][row] = dummy;
        out[row][i] = dummy;
    }

    datain   = U.getMatrixArray();
    datainO  = out.getMatrixArray();
    int k            = 0;

    data     [out.nrows()*out.nrows()];

    for(int i=0; i < out.nrows()*out.ncols(); i++) {

        if( datainO[i] == dummy )
            data[i] = 0;
        else
            data[i] = datain[k++];

    }

    out = MatDoub( out.nrows(), out.nrows(), data );

}
void removeMatrixRow(int row, MatDoub &out) {

    int dummy = -1000;

    Rh.resize(Ri.nrows(),Ri.nrows());
    Rh = Ri;

    for(int i=0; i<Rh.nrows(); i++) {
        Rh[row][i] = dummy;
        Rh[i][row] = dummy;
    }

    datain = Rh.getMatrixArray();
    data   [Rh.nrows()*Rh.nrows()];
    int k=0;

    for(int i=0; i < Rh.nrows()*Rh.nrows(); i++) {

        double ele = datain[i];
        if(ele != dummy)
            data[k++] = ele;

    }

    out = MatDoub( out.nrows(), out.nrows(), data );


}
void removeMatrixRow( MatDoub Unr, MatDoub &outnr ) {

    int dummy = -1000;

    datain = Unr.getMatrixArray();
    data   [outnr.nrows()*outnr.nrows()];
    int k=0;

    for(int i=0; i < Unr.nrows()*Unr.nrows(); i++) {

        double ele = datain[i];
        if(ele != dummy)
            data[k++] = ele;

    }

    outnr = MatDoub( outnr.nrows(), outnr.nrows(), data );


}
void removeMatrixRow( MatDoub &out ) {

    int dummy = -1000;

    datain = Ri.getMatrixArray();
    data  [Ri.nrows()*Ri.nrows()];
    int k=0;

    for(int i=0; i < Ri.nrows()*Ri.ncols(); i++) {

        double ele = datain[i];
        if(ele != dummy)
            data[k++] = ele;

    }

    out = MatDoub( out.nrows(), out.nrows(), data );


}
/*
 Utility method used by RandomWalk algorithm to
 resize the Graph Laplacian for each community, com,
 within the network.
 */
void getSubMatrix(int com, vector<node> &Nodes) {

    int dummy = -1000;
    int rows  = 0;

    Rh.resize(R.nrows(), R.nrows());
    Rh = R;

    //--- NR style
    for( int i=0; i< C.size(); i++) {

        if( C[i] == com )
            Nodes.push_back(node(rows++,0.0,0.0));
        else {
            for( int k=0; k<Rh.nrows(); k++) {
                Rh[i][k] = dummy;
                Rh[k][i] = dummy;
            }
        }

    }

    datain = Rh.getMatrixArray();
    data   [Rh.nrows()*Rh.nrows()];
    int ind = 0;

    for(int i=0; i < Rh.nrows()*Rh.ncols(); i++) {

        double ele = datain[i];
        if(ele != dummy)
            data[ind++] = ele;

    }

    Ri.resize(rows,rows);
    Ri = MatDoub( rows, rows, data );

}