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

Add support for dtCMatrix&dsCMatrix #135

Merged
merged 8 commits into from
Jun 18, 2017
Merged

Add support for dtCMatrix&dsCMatrix #135

merged 8 commits into from
Jun 18, 2017

Conversation

binxiangni
Copy link
Contributor

Now I just add codes for the conversion of dtCMatrix and dsCMatrix here in order to partially solve the issue#17 and issue#114. More conversion of sparse matrix would be added soon. Please do me a favor to check the code style or anything else important.


// Setting the sentinel
arma::access::rw(res.col_ptrs[(unsigned) dims[1] + 1]) =
arma::access::rw(res.col_ptrs[static_cast<unsigned>(ncol + 1)]) =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for the static_cast usage.

std::copy(x.begin(), x.end(), arma::access::rwp(res.values));
// Get the type of sparse matrix
std::string type = Rcpp::as<std::string>(mat.slot("class"));
if (type == "dgCMatrix"){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stylistically... @eddelbuettel will complain that you did not put a space between ) and {.

@coatless
Copy link
Contributor

Could you add unit tests that verify your assertion?

https://github.com/RcppCore/RcppArmadillo/blob/master/inst/unitTests/runit.sparse.R
https://github.com/RcppCore/RcppArmadillo/blob/master/inst/unitTests/cpp/sparse.cpp

@eddelbuettel
Copy link
Member

Nice! And don't worry too about indentation -- following what is in the other files in the repo is a good plan.

@binxiangni
Copy link
Contributor Author

binxiangni commented Jun 15, 2017

I am curious about the meaning of the first dot and triple colons in the following codes:

    .setUp <- RcppArmadillo:::unit_test_setup("sparse.cpp") 

@coatless
Copy link
Contributor

Generally, the . preceding a function or variable name is meant to hide it from users in a way that is similar to how dotfiles are hidden on most file systems. Basically, these functions and variables are to be considered internal components of the package that shouldn't be modified.

Regarding the :::, this relates to package namespaces. When you call library(pkgname), you are loading all of the packages exported functions and variables into the search path. If you do not, one way to access a package's function is to prefix it with the package name and two colons, e.g. pkgname::function(). Now, you might have components that are not exported because they are internal components as mentioned above. To access these internal values, you can add one additional colon after the package name but before a function or variable, e.g. RcppArmadillo:::unit_test_setup, and viola you have access to it outside the package.

You might want to glance at Double Colon and Triple Colon Operators help doc article for more.

@@ -77,7 +77,9 @@ namespace traits {
private:
MATRIX mat ;
};


// 14 June 2017
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't have time in other place, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just followed the style of the source code. There are also dates there

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't matter. Let's focus on the unit test.

std::copy(p.begin(), p.end(), arma::access::rwp(res.col_ptrs));
std::copy(x.begin(), x.end(), arma::access::rwp(res.values));
// Get the type of sparse matrix
std::string type = Rcpp::as<std::string>(mat.slot("class"));
Copy link
Member

@thirdwing thirdwing Jun 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can print some message when converting the matrix type?

Like "Converting dgCMatrix into Armadillo type".

What is your opinion? @coatless

@eddelbuettel
Copy link
Member

IIRC the sample() code by Christian has dates in it. I am with you that it is somewhat redundant given the commit logs. But hey, documentation is good.

As for printing message: Hm. Maybe if and only if a verbose flag or option is set?

@coatless
Copy link
Contributor

Perhaps a set of debug macros similar to what Rcpp does for some of the String and general conversions?

c.f.

https://github.com/RcppCore/Rcpp/blob/8f2a101789b29e572bf3abe5115d9ddb48c1b0c7/inst/include/Rcpp/String.h#L30-L41

https://github.com/RcppCore/Rcpp/blob/6f81b4684481dbd9bb554dd95e66725fc3b63a8c/inst/include/Rcpp/vector/converter.h#L50

So, we would have

#define DEBUG_RCPPARMADILLO_SPARSE

Then something print status of conversion to console with Rprintf() instead of Rcpp::Rcout?

@eddelbuettel
Copy link
Member

eddelbuettel commented Jun 15, 2017

Let's not get distracted. This is Binxiang's issue ticket on something different.

We can always print some debug text during development and clean up before releases. No biggie either way.

@eddelbuettel
Copy link
Member

@binxiangni The pull request looks really good. Two more suggestions / requests

  1. Tests would be excellent, and if you look at the existing directory it should become clear how to add them. If it is not, well then we can merge this as is and open a new branch just for tests. They are important and a key part of how we do things.

  2. ChangeLog entries would be nice. That gets autoformatted if you use Emacs, it is pretty easy to do by hand as well. Date, name and email with two spaces, then a bullet point for each changed file with a summary.

Can we add that?

@binxiangni
Copy link
Contributor Author

@eddelbuettel Sorry for delay. I'll do that ASAP. Please do not merge for now. I understand the importance of test.

As I mentioned before, my broken laptop quite let me down. Yesterday I tried to use Ubuntu Server in the digitalocean as KK suggests and set up a GUI for further working environment, but GUI didn't work. I'll go to a local dealer to get a new laptop today. After that, I can go back to the right track. Apologize again!

@eddelbuettel
Copy link
Member

No worry, you are doing great. We could do it as two PRs as well but may as well have you expand this one.

@eddelbuettel
Copy link
Member

eddelbuettel commented Jun 16, 2017

Oh, and sorry about the hardware troubles.

@coatless Any way a student can access a proper and current dev env on campus? Isn't that what the VM pool is for? But not outside of classes?

@binxiangni
Copy link
Contributor Author

binxiangni commented Jun 16, 2017

The local dealer also tells me that I can get the laptop after 10 days. 😭
Now I try to install Rstudio in the ubuntu server in the digitalocean. There is a step not making sense to me

RStudio can be access through port 8787.

Do you have any idea?

@eddelbuettel
Copy link
Member

Sure. Standard RStudio Server use via a webbrowser. See eg https://support.rstudio.com/hc/en-us/articles/200552306-Accessing-RStudio-Server-Open-Source

Really no resources on campus?

@binxiangni
Copy link
Contributor Author

I can access the computer in the computer lab, but have no admin right to install package like Armadillo. But for now, I have an old laptop from my friend and at least it can run the build check in the RStudio. Previously, I think I have to install C++ Armadillo library. Maybe I am wrong. Only if the build check runs and no error occurs, that means it passes the test, right?

@eddelbuettel
Copy link
Member

Also, you could just use GitHub and Travis CI. If you clone RcppArmadillo you have a working .travis.yml. So you just need to turn on Travis CI for your account as everything else is already there. (For what it is worth, the first Google hit was this tutorial.)

@coatless
Copy link
Contributor

Just to give a heads up, I've put in a request to get @binxiangni access to a linux machine on campus. I'll let you know what happens. (It likely won't be until Monday since it's almost 5 o'clock.)

@eddelbuettel
Copy link
Member

Thanks for adding tests. Looks like one failed ... but I am about to cook dinner so can't check now.

I am sure we'll get it sorted out.

@binxiangni
Copy link
Contributor Author

binxiangni commented Jun 17, 2017

I find where the bug is:
'S4' was not declared in this scope
I just fixed apparent bugs but don't know how to include S4 in the scope.

int nrow = dims[0];
int ncol = dims[1];

// Creating an empty SpMat
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what we want to test is arma::sp_mat res = Rcpp::as<arma::sp_mat>(S);

The converting code has been added into the as implementation and we want to test.

@binxiangni
Copy link
Contributor Author

I did unit test locally and it shows R CMD check succeeded, which I guess means that the unit tests pass. But there is a warning: Problems with news in 'inst/NEWS.Rd':. Anyone can give me a hint?

@eddelbuettel
Copy link
Member

Problems with news in 'inst/NEWS.Rd'

That usually means a closing } is missing or in the wrong. And as you didn't touch the file, not your problem :)

I can take a look in a bit. Just in a from a long run...

@eddelbuettel
Copy link
Member

Passes with flying colors for me too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants