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

Add conversion & unit tests for pMatrix & ddiMatrix #140

Merged
merged 1 commit into from Jun 23, 2017

Conversation

Projects
None yet
4 participants
@binxiangni
Contributor

binxiangni commented Jun 20, 2017

In order to solve #17 and #114 . Now the conversion for all the numeric sparse matrices is done. @thirdwing @eddelbuettel When doing unit tests, I found some bugs in the package Matrix. But there is only a read-only repo on the GitHub so that I cannot open a pull request. Do you have any idea where I can contribute?

@eddelbuettel

This comment has been minimized.

Show comment
Hide comment
@eddelbuettel

eddelbuettel Jun 20, 2017

Member

I think Matrix lives here as an SVN repo on R-Forge. That is consistent with its DESCRIPTION file.

Member

eddelbuettel commented Jun 20, 2017

I think Matrix lives here as an SVN repo on R-Forge. That is consistent with its DESCRIPTION file.

// Calculate i
for(std::map<int, int>::iterator tmp = colrow.begin(); tmp != colrow.end(); tmp++){
i.push_back(tmp -> second);

This comment has been minimized.

@coatless

coatless Jun 21, 2017

Contributor

Using .push_back is problematic on IntegerVector because Rcpp objects are proxy models that serve as shallow wrappers around R objects. Thus, each time you add an element, there is a significant overhead associated with copying the existing vector to a new vector. It would be much better in this case to directly use std::vector<int> and then cast at the end to IntegerVector.

@coatless

coatless Jun 21, 2017

Contributor

Using .push_back is problematic on IntegerVector because Rcpp objects are proxy models that serve as shallow wrappers around R objects. Thus, each time you add an element, there is a significant overhead associated with copying the existing vector to a new vector. It would be much better in this case to directly use std::vector<int> and then cast at the end to IntegerVector.

std::copy(x.begin(), x.end(), arma::access::rwp(res.values));
}
else if (type == "ddiMatrix") {
IntegerVector i(ncol);

This comment has been minimized.

@coatless

coatless Jun 21, 2017

Contributor

This also needs to be tweaked slightly as it does not take into account N or U classes of the ddiMatrix.

e.g.

(d_U <- Diagonal(n = 3))
# 3 x 3 diagonal matrix of class "ddiMatrix"
#     [,1] [,2] [,3]
# [1,]    1    .    .
# [2,]    .    1    .
# [3,]    .    .    1
str(d_U)
# Formal class 'ddiMatrix' [package "Matrix"] with 4 slots
#  ..@ diag    : chr "U"
#  ..@ Dim     : int [1:2] 3 3
#  ..@ Dimnames:List of 2
#  .. ..$ : NULL
#  .. ..$ : NULL
#  ..@ x       : num(0) 
(d_N <- Diagonal(x = c(10,1)))
# 2 x 2 diagonal matrix of class "ddiMatrix"
#      [,1] [,2]
# [1,]   10    .
# [2,]    .    1
str(d_N)
# Formal class 'ddiMatrix' [package "Matrix"] with 4 slots
#  ..@ diag    : chr "N"
#  ..@ Dim     : int [1:2] 2 2
#  ..@ Dimnames:List of 2
#  .. ..$ : NULL
#  .. ..$ : NULL
#  ..@ x       : num [1:2] 10 1
@coatless

coatless Jun 21, 2017

Contributor

This also needs to be tweaked slightly as it does not take into account N or U classes of the ddiMatrix.

e.g.

(d_U <- Diagonal(n = 3))
# 3 x 3 diagonal matrix of class "ddiMatrix"
#     [,1] [,2] [,3]
# [1,]    1    .    .
# [2,]    .    1    .
# [3,]    .    .    1
str(d_U)
# Formal class 'ddiMatrix' [package "Matrix"] with 4 slots
#  ..@ diag    : chr "U"
#  ..@ Dim     : int [1:2] 3 3
#  ..@ Dimnames:List of 2
#  .. ..$ : NULL
#  .. ..$ : NULL
#  ..@ x       : num(0) 
(d_N <- Diagonal(x = c(10,1)))
# 2 x 2 diagonal matrix of class "ddiMatrix"
#      [,1] [,2]
# [1,]   10    .
# [2,]    .    1
str(d_N)
# Formal class 'ddiMatrix' [package "Matrix"] with 4 slots
#  ..@ diag    : chr "N"
#  ..@ Dim     : int [1:2] 2 2
#  ..@ Dimnames:List of 2
#  .. ..$ : NULL
#  .. ..$ : NULL
#  ..@ x       : num [1:2] 10 1
@eddelbuettel

This comment has been minimized.

Show comment
Hide comment
@eddelbuettel

eddelbuettel Jun 23, 2017

Member

I think I can merge this now. Any objections?

Member

eddelbuettel commented Jun 23, 2017

I think I can merge this now. Any objections?

@coatless

This comment has been minimized.

Show comment
Hide comment
@coatless

coatless Jun 23, 2017

Contributor

Sorry for not seeing this earlier.

Everything looks to be in a better state.

Contributor

coatless commented Jun 23, 2017

Sorry for not seeing this earlier.

Everything looks to be in a better state.

@eddelbuettel eddelbuettel merged commit 31ce005 into RcppCore:master Jun 23, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment