Skip to content

Commit

Permalink
Fix the problem in slot "p" in "dgCMatrix". close RcppCore#149
Browse files Browse the repository at this point in the history
  • Loading branch information
Qiang Kou committed Jul 23, 2017
1 parent a0b57c5 commit 5aa51cb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions inst/include/RcppArmadilloWrap.h
Expand Up @@ -86,6 +86,7 @@ namespace Rcpp{
Vector<RTYPE> x(sm.values, sm.values + sm.n_nonzero ) ;
IntegerVector i(sm.row_indices, sm.row_indices + sm.n_nonzero);
IntegerVector p(sm.col_ptrs, sm.col_ptrs + sm.n_cols+1 ) ;
if (p[sm.n_cols] == 0) p[sm.n_cols] = p[sm.n_cols - 1];

std::string klass ;
switch( RTYPE ){
Expand Down
5 changes: 5 additions & 0 deletions inst/unitTests/cpp/sparse.cpp
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
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(4, 5)
SM2 <- sparseMatrix(i = c(1:4), j = c(1:4), x = 1, dims = c(4,5))
checkEquals(SM, SM2, msg="speye")
SM <- speye(5, 4)
SM2 <- sparseMatrix(i = c(1:4), j = c(1:4), x = 1, dims = c(5, 4))
checkEquals(SM, SM2, msg="speye")
}
}

0 comments on commit 5aa51cb

Please sign in to comment.