{"action":"created","issue":{"url":"https://api.github.com/repos/stan-dev/stan/issues/1605","labels_url":"https://api.github.com/repos/stan-dev/stan/issues/1605/labels{/name}","comments_url":"https://api.github.com/repos/stan-dev/stan/issues/1605/comments","events_url":"https://api.github.com/repos/stan-dev/stan/issues/1605/events","html_url":"https://github.com/stan-dev/stan/pull/1605","id":105055325,"number":1605,"title":"Feature/issue 1565 sparse multiply","user":{"login":"bob-carpenter","id":3383807,"avatar_url":"https://avatars.githubusercontent.com/u/3383807?v=3","gravatar_id":"","url":"https://api.github.com/users/bob-carpenter","html_url":"https://github.com/bob-carpenter","followers_url":"https://api.github.com/users/bob-carpenter/followers","following_url":"https://api.github.com/users/bob-carpenter/following{/other_user}","gists_url":"https://api.github.com/users/bob-carpenter/gists{/gist_id}","starred_url":"https://api.github.com/users/bob-carpenter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bob-carpenter/subscriptions","organizations_url":"https://api.github.com/users/bob-carpenter/orgs","repos_url":"https://api.github.com/users/bob-carpenter/repos","events_url":"https://api.github.com/users/bob-carpenter/events{/privacy}","received_events_url":"https://api.github.com/users/bob-carpenter/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/stan-dev/stan/milestones/17","html_url":"https://github.com/stan-dev/stan/milestones/v2.8.0","labels_url":"https://api.github.com/repos/stan-dev/stan/milestones/17/labels","id":1143351,"number":17,"title":"v2.8.0","description":"Next version after 2.7.0.","creator":{"login":"syclik","id":425751,"avatar_url":"https://avatars.githubusercontent.com/u/425751?v=3","gravatar_id":"","url":"https://api.github.com/users/syclik","html_url":"https://github.com/syclik","followers_url":"https://api.github.com/users/syclik/followers","following_url":"https://api.github.com/users/syclik/following{/other_user}","gists_url":"https://api.github.com/users/syclik/gists{/gist_id}","starred_url":"https://api.github.com/users/syclik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/syclik/subscriptions","organizations_url":"https://api.github.com/users/syclik/orgs","repos_url":"https://api.github.com/users/syclik/repos","events_url":"https://api.github.com/users/syclik/events{/privacy}","received_events_url":"https://api.github.com/users/syclik/received_events","type":"User","site_admin":false},"open_issues":5,"closed_issues":35,"state":"open","created_at":"2015-06-01T16:58:07Z","updated_at":"2015-09-05T23:15:25Z","due_on":null,"closed_at":null},"comments":12,"created_at":"2015-09-05T23:15:25Z","updated_at":"2015-09-07T15:28:20Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/stan-dev/stan/pulls/1605","html_url":"https://github.com/stan-dev/stan/pull/1605","diff_url":"https://github.com/stan-dev/stan/pull/1605.diff","patch_url":"https://github.com/stan-dev/stan/pull/1605.patch"},"body":"#### Summary:\r\n\r\nAdd sparse matrix by vector multiplication function into Stan language with tests nd doc.\r\n\r\n#### Intended Effect:\r\n\r\nAllow faster sparse multiplies with less memory.\r\n\r\n#### How to Verify:\r\n\r\nUnit tests for model compilation.  Rea doc.\r\n\r\nUnit tests and doc already in stan-dev/math to support this.\r\n\r\n#### Side Effects:\r\n\r\nNone.\r\n\r\n#### Documentation:\r\n\r\nYes, new chapter to manual.\r\n\r\n#### Reviewer Suggestions:\r\n\r\nanyone."},"comment":{"url":"https://api.github.com/repos/stan-dev/stan/issues/comments/138325433","html_url":"https://github.com/stan-dev/stan/pull/1605#issuecomment-138325433","issue_url":"https://api.github.com/repos/stan-dev/stan/issues/1605","id":138325433,"user":{"login":"sakrejda","id":508137,"avatar_url":"https://avatars.githubusercontent.com/u/508137?v=3","gravatar_id":"","url":"https://api.github.com/users/sakrejda","html_url":"https://github.com/sakrejda","followers_url":"https://api.github.com/users/sakrejda/followers","following_url":"https://api.github.com/users/sakrejda/following{/other_user}","gists_url":"https://api.github.com/users/sakrejda/gists{/gist_id}","starred_url":"https://api.github.com/users/sakrejda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sakrejda/subscriptions","organizations_url":"https://api.github.com/users/sakrejda/orgs","repos_url":"https://api.github.com/users/sakrejda/repos","events_url":"https://api.github.com/users/sakrejda/events{/privacy}","received_events_url":"https://api.github.com/users/sakrejda/received_events","type":"User","site_admin":false},"created_at":"2015-09-07T15:28:20Z","updated_at":"2015-09-07T15:28:20Z","body":"Yeah. Maybe just that. For consistency I had one that used the Stan math\nlibrary extractors (pasted below).  You can take an R sparse matrix (Matrix\npackage) in row major format, pass it through Rcpp as an Eigen sparse\nmatrix without making any copies, and then use the extractors  with sparse\nEigen matrix signatures from the Stan math library.\n\nThe alternative is to make an R function that plays with the Matrix package\nobject slots directly (they're close to what we extract) but then we're\ndepending on Matrix keeping it's implementation the same. It'll probably\nstay, so your choice, but I'd rather take a path that will be similar\nenough in the different interfaces\nJust for reference I had a function like this in rstan/R/sparse.R\n\nextract_sparse_parts <- function(A, type='CSC') {\n  if (class(A) == 'matrix') {\n    A <- Matrix(A, sparse=TRUE)\n  }\n  if (type == 'CSR') {\n    A <- t(A)\n  }\n  if (class(A) == 'dgCMatrix') {\n    o <- .Call(\"extract_sparse_components\",A)\n  } else {\n    stop(\"Argument 'x' must either be of class 'matrix' or 'dgCMatrix'.\")\n  }\n  o[['type']] <- type\n  return(o)\n}\n\nThen in rstan/src/aaa_sparse_extractors.cpp I added:\n\n#include <stan/math/prim/mat/fun/sparse_extractors.hpp>\n\n#include <Rcpp.h>\n#include <RcppEigen.h>\n\nRcppExport SEXP extract_sparse_components(SEXP A) {\n  Eigen::SparseMatrix<double> AA(Rcpp::as<Eigen::SparseMatrix<double> >(A));\n  Eigen::Matrix<double, Eigen::Dynamic,1> w = stan::math::extract_w(AA);\n  std::vector<double> ww(w.size());\n  for (unsigned int i=0; i < w.size(); ++i)\n    ww[i] = w(i);\n\n  std::vector<int> v = stan::math::extract_v(AA);\n  std::vector<int> u = stan::math::extract_u(AA);\n  std::vector<int> z = stan::math::extract_z(AA);\n\n  return Rcpp::List::create(\n      Rcpp::Named(\"w\") = ww,\n      Rcpp::Named(\"v\") = v,\n      Rcpp::Named(\"u\") = u,\n      Rcpp::Named(\"z\") = z\n  );\n\n}\n\nand exposed that through init.cpp so it could be called from R.  That's\nit.  Let me know if you want me to figure out what this would look like for\nthe current rstan (the above was vs. 2.6.2, I think).\n\nKrzysztof\n\n\nOn Sep 6, 2015 11:32 PM, \"bgoodri\" <notifications@github.com> wrote:\n\n> Allright, let's merge this before it breaks again. @sakrejda\n> <https://github.com/sakrejda> Do we need something for rstan? I was\n> thinking that a csr_extract() function that took a matrix and returned a\n> list of w, u, and v would be nice.\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/stan-dev/stan/pull/1605#issuecomment-138171531>.\n>\n"}}