Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the problem in slot "p" in "dgCMatrix". close #149 #150

Merged
merged 1 commit into from
Aug 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions inst/include/armadillo_bits/SpMat_meat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3392,6 +3392,12 @@ SpMat<eT>::eye(const uword in_rows, const uword in_cols)

for(uword i = 0; i <= N; ++i) { access::rw(col_ptrs[i]) = i; }

// take into account non-square matrices
for(uword i = (N+1); i <= in_cols; ++i)
{
access::rw(col_ptrs[i]) += col_ptrs[i - 1];
}

access::rw(n_nonzero) = N;

return *this;
Expand Down
5 changes: 5 additions & 0 deletions inst/unitTests/cpp/sparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,8 @@ Rcpp::List sparseList(Rcpp::List l) {

return Rcpp::List::create(mat1, mat2);
}

// [[Rcpp::export]]
arma::sp_mat speye(int nrow, int ncol) {
return arma::speye(nrow, ncol);
}
12 changes: 12 additions & 0 deletions inst/unitTests/runit.sparse.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,16 @@ if (.runThisTest) {
l <- list(SM, SM)
checkEquals(l, sparseList(l), msg="sparseList")
}

test.speye <- function() {
SM <- speye(4, 4)
SM2 <- sparseMatrix(i = c(1:4), j = c(1:4), x = 1)
checkEquals(SM, SM2, msg="speye")
SM <- speye(3, 5)
SM2 <- sparseMatrix(i = c(1:3), j = c(1:3), x = 1, dims = c(3, 5))
checkEquals(SM, SM2, msg="speye")
SM <- speye(5, 3)
SM2 <- sparseMatrix(i = c(1:3), j = c(1:3), x = 1, dims = c(5, 3))
checkEquals(SM, SM2, msg="speye")
}
}