Skip to content

Commit

Permalink
Correcting error in matrix_compare
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Feb 5, 2020
1 parent a8837d5 commit c94ed02
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
YEAR:2015
YEAR:2020
COPYRIGHT HOLDER:Thomas W. Valente
28 changes: 12 additions & 16 deletions src/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,41 +265,37 @@ arma::sp_mat matrix_compareCpp(

arma::sp_mat Bcpy(B);

std::vector< double > val(A.n_nonzero + B.n_nonzero);
std::vector< unsigned int > row(A.n_nonzero + B.n_nonzero),
col(A.n_nonzero + B.n_nonzero);
std::vector< double > val(0);
val.reserve(A.n_nonzero + B.n_nonzero);
std::vector< unsigned int > row(0), col(0);
row.reserve(A.n_nonzero + B.n_nonzero), col.reserve(A.n_nonzero + B.n_nonzero);

// Iterating through matrix A
unsigned int i = 0u;
for (spiter iter=A.begin(); iter!= A.end(); ++iter) {

row[i] = iter.row();
col[i] = iter.col();
row.push_back(iter.row());
col.push_back(iter.col());

// Filling the value
// ans.at(iter.row(), iter.col()) =
val[i++] = as< double >(fun(*iter, B.at(iter.row(), iter.col()) ));
val.push_back(
as< double >(fun(*iter, B.at(iter.row(), iter.col()) ))
);
Bcpy.at(iter.row(), iter.col()) = 0;

}

// Iterating throught matrix B
for (spiter iter=Bcpy.begin(); iter!= Bcpy.end(); ++iter) {

row[i] = iter.row();
col[i] = iter.col();
row.push_back(iter.row());
col.push_back(iter.col());

// Filling the value
// ans.at(iter.row(), iter.col()) =
val[i++] = as< double >(fun(A.at(iter.row(), iter.col()), *iter));
val.push_back(as< double >(fun(A.at(iter.row(), iter.col()), *iter)));
}

--i;

row.erase(row.begin() + i, row.end());
col.erase(col.begin() + i, col.end());
val.erase(val.begin() + i, val.end());

// Batch constructor
arma::sp_mat ans(
arma::join_cols(
Expand Down

0 comments on commit c94ed02

Please sign in to comment.