{"action":"created","issue":{"url":"https://api.github.com/repos/tvatter/vinecopulib/issues/14","repository_url":"https://api.github.com/repos/tvatter/vinecopulib","labels_url":"https://api.github.com/repos/tvatter/vinecopulib/issues/14/labels{/name}","comments_url":"https://api.github.com/repos/tvatter/vinecopulib/issues/14/comments","events_url":"https://api.github.com/repos/tvatter/vinecopulib/issues/14/events","html_url":"https://github.com/tvatter/vinecopulib/issues/14","id":200678049,"number":14,"title":"Boost vs GSL","user":{"login":"tvatter","id":5273142,"avatar_url":"https://avatars.githubusercontent.com/u/5273142?v=3","gravatar_id":"","url":"https://api.github.com/users/tvatter","html_url":"https://github.com/tvatter","followers_url":"https://api.github.com/users/tvatter/followers","following_url":"https://api.github.com/users/tvatter/following{/other_user}","gists_url":"https://api.github.com/users/tvatter/gists{/gist_id}","starred_url":"https://api.github.com/users/tvatter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tvatter/subscriptions","organizations_url":"https://api.github.com/users/tvatter/orgs","repos_url":"https://api.github.com/users/tvatter/repos","events_url":"https://api.github.com/users/tvatter/events{/privacy}","received_events_url":"https://api.github.com/users/tvatter/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2017-01-13T17:05:18Z","updated_at":"2017-01-19T15:52:40Z","closed_at":null,"body":"Hi,\r\n\r\nSo I was thinking about GSL vs Boost for the pdf/cdf/quantile. To mix GSL and Eigen, we can do:\r\n```\r\n#include <gsl/gsl_cdf.h>\r\n#include <gsl/gsl_randist.h>\r\n\r\ntemplate<typename T> T dnorm_gsl(const T& x)\r\n{\r\n    return x.unaryExpr(std::ptr_fun(gsl_ran_ugaussian_pdf));\r\n};\r\ntemplate<typename T> T pnorm_gsl(const T& x)\r\n{\r\n    return x.unaryExpr(std::ptr_fun(gsl_cdf_ugaussian_P));\r\n};\r\ntemplate<typename T> T qnorm_gsl(const T& x)\r\n{\r\n    return x.unaryExpr(std::ptr_fun(gsl_cdf_ugaussian_Pinv));\r\n};\r\n```\r\nEquivalently, for boost, we can do:\r\n```\r\n#include <boost/bind.hpp>\r\n#include <boost/math/distributions.hpp>\r\n#include <boost/function.hpp>\r\n\r\ntemplate<typename T> T dnorm(const T& x)\r\n{\r\n    boost::math::normal std_normal;\r\n    return x.unaryExpr(boost::bind<double>(boost::math::pdf<boost::math::normal,double>, std_normal, _1));\r\n};\r\n\r\ntemplate<typename T> T pnorm(const T& x)\r\n{\r\n    boost::math::normal std_normal;\r\n    return x.unaryExpr(boost::bind<double>(boost::math::cdf<boost::math::normal,double>, std_normal, _1));\r\n};\r\n\r\ntemplate<typename T> T qnorm(const T& x)\r\n{\r\n    boost::math::normal std_normal;\r\n    return x.unaryExpr(boost::bind<double>(boost::math::quantile<boost::math::normal,double>, std_normal, _1));\r\n};\r\n```\r\nNote that the templates are used to include both matrices and vectors....\r\n\r\nAt first, I though that the drawback of the boost implementation was the instantiation of the distribution. However, when benchmarking for a sample size of 1e5, I noticed that GSL is simply faster (~4 times for the pdf and ~12 times for the cdf/quantile)."},"comment":{"url":"https://api.github.com/repos/tvatter/vinecopulib/issues/comments/273813306","html_url":"https://github.com/tvatter/vinecopulib/issues/14#issuecomment-273813306","issue_url":"https://api.github.com/repos/tvatter/vinecopulib/issues/14","id":273813306,"user":{"login":"tvatter","id":5273142,"avatar_url":"https://avatars.githubusercontent.com/u/5273142?v=3","gravatar_id":"","url":"https://api.github.com/users/tvatter","html_url":"https://github.com/tvatter","followers_url":"https://api.github.com/users/tvatter/followers","following_url":"https://api.github.com/users/tvatter/following{/other_user}","gists_url":"https://api.github.com/users/tvatter/gists{/gist_id}","starred_url":"https://api.github.com/users/tvatter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tvatter/subscriptions","organizations_url":"https://api.github.com/users/tvatter/orgs","repos_url":"https://api.github.com/users/tvatter/repos","events_url":"https://api.github.com/users/tvatter/events{/privacy}","received_events_url":"https://api.github.com/users/tvatter/received_events","type":"User","site_admin":false},"created_at":"2017-01-19T15:52:40Z","updated_at":"2017-01-19T15:52:40Z","body":"OK, so I changed the release flags (line 8 of `compilerDefOpt.cmake`) to use `-Ofast -march=native` instead of `-O3`:\r\n```\r\nBoost:Elapsed time: 1.16187 s\r\nGSL:  Elapsed time: 0.929747 s\r\n```\r\nWhen using the debug flags (line 7 of `compilerDefOpt.cmake`), namely `-g -O0 -DDEBUG -fsanitize=address -fno-omit-frame-pointer`, I get:\r\n```\r\nBoost:Elapsed time: 21.7116 s\r\nGSL:  Elapsed time: 4.15891 s\r\n```\r\nTurns out that: \r\n* I ran all my tests with the debug version.\r\n* Boost is still slower than GSL but it's not that bad."}}
{"actor":{"display_login":"tvatter"}}