{"action":"created","comment":{"url":"https://api.github.com/repos/RobotLocomotion/drake/pulls/comments/45545285","id":45545285,"diff_hunk":"@@ -8,89 +8,194 @@\n #include <functional>\n #include <sstream>\n #include <stdexcept>\n-#include \"mex.h\"\n #include \"drakeMexUtil.h\"\n \n-class MexToCppConversionError : public std::runtime_error {\n-public:\n-  MexToCppConversionError(const std::string& msg) : std::runtime_error(msg) { };\n-\n-  MexToCppConversionError(const char *msg) : std::runtime_error(msg) { };\n-};\n+#if defined(_MSC_VER) && (_MSC_VER < 1900)\n+#define NOEXCEPT\n+#else\n+#define NOEXCEPT noexcept\n+#endif\n \n /**\n- * fromMex\n+ * Functions that make it easy to create a mex file that calls a std::function.","path":"drake/util/mexify.h","position":21,"original_position":21,"commit_id":"700cd40d2713a95746b40b44176373fda94f8f36","original_commit_id":"700cd40d2713a95746b40b44176373fda94f8f36","user":{"login":"RussTedrake","id":6442292,"avatar_url":"https://avatars.githubusercontent.com/u/6442292?v=3","gravatar_id":"","url":"https://api.github.com/users/RussTedrake","html_url":"https://github.com/RussTedrake","followers_url":"https://api.github.com/users/RussTedrake/followers","following_url":"https://api.github.com/users/RussTedrake/following{/other_user}","gists_url":"https://api.github.com/users/RussTedrake/gists{/gist_id}","starred_url":"https://api.github.com/users/RussTedrake/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RussTedrake/subscriptions","organizations_url":"https://api.github.com/users/RussTedrake/orgs","repos_url":"https://api.github.com/users/RussTedrake/repos","events_url":"https://api.github.com/users/RussTedrake/events{/privacy}","received_events_url":"https://api.github.com/users/RussTedrake/received_events","type":"User","site_admin":false},"body":"i like it","created_at":"2015-11-21T12:01:59Z","updated_at":"2015-11-21T12:01:59Z","html_url":"https://github.com/RobotLocomotion/drake/pull/1434#discussion_r45545285","pull_request_url":"https://api.github.com/repos/RobotLocomotion/drake/pulls/1434","_links":{"self":{"href":"https://api.github.com/repos/RobotLocomotion/drake/pulls/comments/45545285"},"html":{"href":"https://github.com/RobotLocomotion/drake/pull/1434#discussion_r45545285"},"pull_request":{"href":"https://api.github.com/repos/RobotLocomotion/drake/pulls/1434"}}},"pull_request":{"url":"https://api.github.com/repos/RobotLocomotion/drake/pulls/1434","id":48095333,"html_url":"https://github.com/RobotLocomotion/drake/pull/1434","diff_url":"https://github.com/RobotLocomotion/drake/pull/1434.diff","patch_url":"https://github.com/RobotLocomotion/drake/pull/1434.patch","issue_url":"https://api.github.com/repos/RobotLocomotion/drake/issues/1434","number":1434,"state":"open","locked":false,"title":"Use AutoDiffScalar gradients in mex RBM method calls","user":{"login":"tkoolen","id":2585880,"avatar_url":"https://avatars.githubusercontent.com/u/2585880?v=3","gravatar_id":"","url":"https://api.github.com/users/tkoolen","html_url":"https://github.com/tkoolen","followers_url":"https://api.github.com/users/tkoolen/followers","following_url":"https://api.github.com/users/tkoolen/following{/other_user}","gists_url":"https://api.github.com/users/tkoolen/gists{/gist_id}","starred_url":"https://api.github.com/users/tkoolen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tkoolen/subscriptions","organizations_url":"https://api.github.com/users/tkoolen/orgs","repos_url":"https://api.github.com/users/tkoolen/repos","events_url":"https://api.github.com/users/tkoolen/events{/privacy}","received_events_url":"https://api.github.com/users/tkoolen/received_events","type":"User","site_admin":false},"body":"Instead of using user gradients, use AutoDiffScalar gradients in all relevant RBM mex functions.\r\n\r\nNote that the current implementation will try to call method instantiations with a fixed maximum size derivative vector (with a max size up to 73, the number of states of a quat-parameterized Atlas) if possible, before gracefully falling back to true dynamic size derivative vectors. See https://github.com/RobotLocomotion/drake/issues/1199 for the performance comparison that inspired this choice.\r\n\r\nI made it so that TaylorVar inputs to the functions also call mex functions.\r\n\r\nIn the process:\r\n* added some more functionality to mexify:\r\n * added mexTryToCallFunctions, a function to which you can pass a bunch of std::functions, which will be tried in order until one sticks in the sense that the Matlab arguments passed in can be converted to the correct types required by the function ~~without a MexToCPPConversionError being thrown~~. I'm using this to switch between the three current options of double, auto diff fixed max size, and auto diff dynamic max size\r\n * a small infrastructure improvement regarding the number of outputs of the function\r\n * mex conversions to general std::vectors and std::pairs\r\n * improved conversion to AutoDiffScalar\r\n * moved conversion functions to standardMexConversions.h and rigidBodyManipulatorMexConversions.h\r\n * added some documentation\r\n* mexified contactConstraintsmex\r\n* fixed some more 'scalar correctness' issues in RBM (places where we were wrongly assuming doubles)\r\n* implemented a (necessarily imperfect) make_function function that works for all of our use cases so far, and use it to clean up rbmMexFunctions\r\n* fixed an issue in the gradients of FixedAxisOneDoFJoint frictionTorque gradients that was present both in Matlab and in C++\r\n* added a Matlab sparse matrix to Eigen sparse conversion\r\n\r\n~~This isn't quite ready to go in yet, but I wanted to get test results and to get a discussion started:~~\r\nReady to go after review and build servers say OK (MSVC might have trouble again).\r\n\r\n1. ~~the mexTryToCallFunctions approach looks like it may have too much overhead when gradient output is required. I'll do some more benchmarking to make sure. Any ideas on clean alternatives or ways to improve performance?~~ **rewrote mexTryToCallFunctions without try/catch; much less overhead.**\r\n1. The current return type of AutoDiffScalar methods is a TaylorVar matrix. Is that a good idea, or should I convert to a series of matrices? **returning TaylorVar is quite expensive due to the mexCallMatlabSafe call. Should probably return a bunch of matrices instead, but in a future iteration. Not a major concern.**\r\n1. ~~This currently increases compilation time quite a bit due to the two extra sets of explicit RBM method instantiations. We could just completely switch to AutoDiff gradients and get rid of the user gradients to offset this, but I didn't want to make this pull request too big before discussing. What do you think?~~ **got rid of user gradients**\r\n1. ~~More of a note to self: I have to make sure that all of the gradient tests still make sense, since gradients obtained by requesting more output arguments for a function and TaylorVar gradients are now computed by calling the exact same code.~~ **seems to be OK. Tests either don't use mex for TaylorVar gradient checks, or they use numerical gradients.**","created_at":"2015-10-19T16:34:48Z","updated_at":"2015-11-21T12:01:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2dbf55753e7cc7b041ff7c9bc47a63bce4f3651f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/RobotLocomotion/drake/pulls/1434/commits","review_comments_url":"https://api.github.com/repos/RobotLocomotion/drake/pulls/1434/comments","review_comment_url":"https://api.github.com/repos/RobotLocomotion/drake/pulls/comments{/number}","comments_url":"https://api.github.com/repos/RobotLocomotion/drake/issues/1434/comments","statuses_url":"https://api.github.com/repos/RobotLocomotion/drake/statuses/700cd40d2713a95746b40b44176373fda94f8f36","head":{"label":"tkoolen:tk-mex-try-call-functions","ref":"tk-mex-try-call-functions","sha":"700cd40d2713a95746b40b44176373fda94f8f36","user":{"login":"tkoolen","id":2585880,"avatar_url":"https://avatars.githubusercontent.com/u/2585880?v=3","gravatar_id":"","url":"https://api.github.com/users/tkoolen","html_url":"https://github.com/tkoolen","followers_url":"https://api.github.com/users/tkoolen/followers","following_url":"https://api.github.com/users/tkoolen/following{/other_user}","gists_url":"https://api.github.com/users/tkoolen/gists{/gist_id}","starred_url":"https://api.github.com/users/tkoolen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tkoolen/subscriptions","organizations_url":"https://api.github.com/users/tkoolen/orgs","repos_url":"https://api.github.com/users/tkoolen/repos","events_url":"https://api.github.com/users/tkoolen/events{/privacy}","received_events_url":"https://api.github.com/users/tkoolen/received_events","type":"User","site_admin":false},"repo":{"id":18049528,"name":"drake","full_name":"tkoolen/drake","owner":{"login":"tkoolen","id":2585880,"avatar_url":"https://avatars.githubusercontent.com/u/2585880?v=3","gravatar_id":"","url":"https://api.github.com/users/tkoolen","html_url":"https://github.com/tkoolen","followers_url":"https://api.github.com/users/tkoolen/followers","following_url":"https://api.github.com/users/tkoolen/following{/other_user}","gists_url":"https://api.github.com/users/tkoolen/gists{/gist_id}","starred_url":"https://api.github.com/users/tkoolen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tkoolen/subscriptions","organizations_url":"https://api.github.com/users/tkoolen/orgs","repos_url":"https://api.github.com/users/tkoolen/repos","events_url":"https://api.github.com/users/tkoolen/events{/privacy}","received_events_url":"https://api.github.com/users/tkoolen/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tkoolen/drake","description":"A planning, control, and analysis toolbox for nonlinear dynamical systems.  Please see the WIKI for documentation.","fork":true,"url":"https://api.github.com/repos/tkoolen/drake","forks_url":"https://api.github.com/repos/tkoolen/drake/forks","keys_url":"https://api.github.com/repos/tkoolen/drake/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tkoolen/drake/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tkoolen/drake/teams","hooks_url":"https://api.github.com/repos/tkoolen/drake/hooks","issue_events_url":"https://api.github.com/repos/tkoolen/drake/issues/events{/number}","events_url":"https://api.github.com/repos/tkoolen/drake/events","assignees_url":"https://api.github.com/repos/tkoolen/drake/assignees{/user}","branches_url":"https://api.github.com/repos/tkoolen/drake/branches{/branch}","tags_url":"https://api.github.com/repos/tkoolen/drake/tags","blobs_url":"https://api.github.com/repos/tkoolen/drake/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tkoolen/drake/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tkoolen/drake/git/refs{/sha}","trees_url":"https://api.github.com/repos/tkoolen/drake/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tkoolen/drake/statuses/{sha}","languages_url":"https://api.github.com/repos/tkoolen/drake/languages","stargazers_url":"https://api.github.com/repos/tkoolen/drake/stargazers","contributors_url":"https://api.github.com/repos/tkoolen/drake/contributors","subscribers_url":"https://api.github.com/repos/tkoolen/drake/subscribers","subscription_url":"https://api.github.com/repos/tkoolen/drake/subscription","commits_url":"https://api.github.com/repos/tkoolen/drake/commits{/sha}","git_commits_url":"https://api.github.com/repos/tkoolen/drake/git/commits{/sha}","comments_url":"https://api.github.com/repos/tkoolen/drake/comments{/number}","issue_comment_url":"https://api.github.com/repos/tkoolen/drake/issues/comments{/number}","contents_url":"https://api.github.com/repos/tkoolen/drake/contents/{+path}","compare_url":"https://api.github.com/repos/tkoolen/drake/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tkoolen/drake/merges","archive_url":"https://api.github.com/repos/tkoolen/drake/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tkoolen/drake/downloads","issues_url":"https://api.github.com/repos/tkoolen/drake/issues{/number}","pulls_url":"https://api.github.com/repos/tkoolen/drake/pulls{/number}","milestones_url":"https://api.github.com/repos/tkoolen/drake/milestones{/number}","notifications_url":"https://api.github.com/repos/tkoolen/drake/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tkoolen/drake/labels{/name}","releases_url":"https://api.github.com/repos/tkoolen/drake/releases{/id}","created_at":"2014-03-24T02:31:26Z","updated_at":"2015-08-26T05:27:33Z","pushed_at":"2015-11-10T06:58:47Z","git_url":"git://github.com/tkoolen/drake.git","ssh_url":"git@github.com:tkoolen/drake.git","clone_url":"https://github.com/tkoolen/drake.git","svn_url":"https://github.com/tkoolen/drake","homepage":"https://github.com/RobotLocomotion/drake/wiki","size":189328,"stargazers_count":0,"watchers_count":0,"language":"Matlab","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"body-wrench-in-qp"}},"base":{"label":"RobotLocomotion:master","ref":"master","sha":"f2437b93e3f9ada13f4b048a8543f64a01b377db","user":{"login":"RobotLocomotion","id":6496345,"avatar_url":"https://avatars.githubusercontent.com/u/6496345?v=3","gravatar_id":"","url":"https://api.github.com/users/RobotLocomotion","html_url":"https://github.com/RobotLocomotion","followers_url":"https://api.github.com/users/RobotLocomotion/followers","following_url":"https://api.github.com/users/RobotLocomotion/following{/other_user}","gists_url":"https://api.github.com/users/RobotLocomotion/gists{/gist_id}","starred_url":"https://api.github.com/users/RobotLocomotion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RobotLocomotion/subscriptions","organizations_url":"https://api.github.com/users/RobotLocomotion/orgs","repos_url":"https://api.github.com/users/RobotLocomotion/repos","events_url":"https://api.github.com/users/RobotLocomotion/events{/privacy}","received_events_url":"https://api.github.com/users/RobotLocomotion/received_events","type":"Organization","site_admin":false},"repo":{"id":16256144,"name":"drake","full_name":"RobotLocomotion/drake","owner":{"login":"RobotLocomotion","id":6496345,"avatar_url":"https://avatars.githubusercontent.com/u/6496345?v=3","gravatar_id":"","url":"https://api.github.com/users/RobotLocomotion","html_url":"https://github.com/RobotLocomotion","followers_url":"https://api.github.com/users/RobotLocomotion/followers","following_url":"https://api.github.com/users/RobotLocomotion/following{/other_user}","gists_url":"https://api.github.com/users/RobotLocomotion/gists{/gist_id}","starred_url":"https://api.github.com/users/RobotLocomotion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RobotLocomotion/subscriptions","organizations_url":"https://api.github.com/users/RobotLocomotion/orgs","repos_url":"https://api.github.com/users/RobotLocomotion/repos","events_url":"https://api.github.com/users/RobotLocomotion/events{/privacy}","received_events_url":"https://api.github.com/users/RobotLocomotion/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/RobotLocomotion/drake","description":"A planning, control, and analysis toolbox for nonlinear dynamical systems.  Please see the WIKI for documentation.","fork":false,"url":"https://api.github.com/repos/RobotLocomotion/drake","forks_url":"https://api.github.com/repos/RobotLocomotion/drake/forks","keys_url":"https://api.github.com/repos/RobotLocomotion/drake/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RobotLocomotion/drake/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RobotLocomotion/drake/teams","hooks_url":"https://api.github.com/repos/RobotLocomotion/drake/hooks","issue_events_url":"https://api.github.com/repos/RobotLocomotion/drake/issues/events{/number}","events_url":"https://api.github.com/repos/RobotLocomotion/drake/events","assignees_url":"https://api.github.com/repos/RobotLocomotion/drake/assignees{/user}","branches_url":"https://api.github.com/repos/RobotLocomotion/drake/branches{/branch}","tags_url":"https://api.github.com/repos/RobotLocomotion/drake/tags","blobs_url":"https://api.github.com/repos/RobotLocomotion/drake/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RobotLocomotion/drake/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RobotLocomotion/drake/git/refs{/sha}","trees_url":"https://api.github.com/repos/RobotLocomotion/drake/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RobotLocomotion/drake/statuses/{sha}","languages_url":"https://api.github.com/repos/RobotLocomotion/drake/languages","stargazers_url":"https://api.github.com/repos/RobotLocomotion/drake/stargazers","contributors_url":"https://api.github.com/repos/RobotLocomotion/drake/contributors","subscribers_url":"https://api.github.com/repos/RobotLocomotion/drake/subscribers","subscription_url":"https://api.github.com/repos/RobotLocomotion/drake/subscription","commits_url":"https://api.github.com/repos/RobotLocomotion/drake/commits{/sha}","git_commits_url":"https://api.github.com/repos/RobotLocomotion/drake/git/commits{/sha}","comments_url":"https://api.github.com/repos/RobotLocomotion/drake/comments{/number}","issue_comment_url":"https://api.github.com/repos/RobotLocomotion/drake/issues/comments{/number}","contents_url":"https://api.github.com/repos/RobotLocomotion/drake/contents/{+path}","compare_url":"https://api.github.com/repos/RobotLocomotion/drake/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RobotLocomotion/drake/merges","archive_url":"https://api.github.com/repos/RobotLocomotion/drake/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RobotLocomotion/drake/downloads","issues_url":"https://api.github.com/repos/RobotLocomotion/drake/issues{/number}","pulls_url":"https://api.github.com/repos/RobotLocomotion/drake/pulls{/number}","milestones_url":"https://api.github.com/repos/RobotLocomotion/drake/milestones{/number}","notifications_url":"https://api.github.com/repos/RobotLocomotion/drake/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RobotLocomotion/drake/labels{/name}","releases_url":"https://api.github.com/repos/RobotLocomotion/drake/releases{/id}","created_at":"2014-01-26T16:11:05Z","updated_at":"2015-11-21T07:47:47Z","pushed_at":"2015-11-21T11:25:33Z","git_url":"git://github.com/RobotLocomotion/drake.git","ssh_url":"git@github.com:RobotLocomotion/drake.git","clone_url":"https://github.com/RobotLocomotion/drake.git","svn_url":"https://github.com/RobotLocomotion/drake","homepage":"https://github.com/RobotLocomotion/drake/wiki","size":191621,"stargazers_count":307,"watchers_count":307,"language":"Matlab","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":198,"mirror_url":null,"open_issues_count":144,"forks":198,"open_issues":144,"watchers":307,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/RobotLocomotion/drake/pulls/1434"},"html":{"href":"https://github.com/RobotLocomotion/drake/pull/1434"},"issue":{"href":"https://api.github.com/repos/RobotLocomotion/drake/issues/1434"},"comments":{"href":"https://api.github.com/repos/RobotLocomotion/drake/issues/1434/comments"},"review_comments":{"href":"https://api.github.com/repos/RobotLocomotion/drake/pulls/1434/comments"},"review_comment":{"href":"https://api.github.com/repos/RobotLocomotion/drake/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/RobotLocomotion/drake/pulls/1434/commits"},"statuses":{"href":"https://api.github.com/repos/RobotLocomotion/drake/statuses/700cd40d2713a95746b40b44176373fda94f8f36"}}}}