{"action":"created","issue":{"url":"https://api.github.com/repos/RobotLocomotion/drake/issues/1273","labels_url":"https://api.github.com/repos/RobotLocomotion/drake/issues/1273/labels{/name}","comments_url":"https://api.github.com/repos/RobotLocomotion/drake/issues/1273/comments","events_url":"https://api.github.com/repos/RobotLocomotion/drake/issues/1273/events","html_url":"https://github.com/RobotLocomotion/drake/issues/1273","id":102284057,"number":1273,"title":"what's the best way to template our dynamical system class hierarchy methods?","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},"labels":[{"url":"https://api.github.com/repos/RobotLocomotion/drake/labels/type:%20question","name":"type: question","color":"207de5"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2015-08-21T02:53:48Z","updated_at":"2015-08-24T23:47:51Z","closed_at":null,"body":"I'm working on an initial C++ version of our systems class hierarchy.  We have a lot of templates flying around, and this is a complicated use case.  I'd like to discuss here to make the right decision.\r\n\r\nConsider this example, which works fine:\r\n```\r\nclass DrakeSystem {\r\npublic:\r\n  virtual VectorXd dynamics(double t, const VectorXd& x, const VectorXd& u)\r\n};\r\n\r\nclass Pendulum : public DrakeSystem {\r\npublic:\r\n  virtual VectorXd dynamics(double t, const VectorXd& x, const VectorXd& u)\r\n};\r\n```\r\n\r\nNow I want to template it, so that it can \r\n- accept a `TrigPoly` and/or `AutoDiffScalar` type (eg, something like `Matrix<Scalar,Dynamic,1>`)\r\n- bonus: take in an `Map<VectorXd>` instead of the `VectorXd`\r\n\r\nI'm not 100% sure I understand the best solution even in the base case, but the fact that these are (at least conceptually) virtual methods complicates everything.  \r\n\r\nI've played a little with templating the class instead of the methods -- that might work for us and could even be relatively clean.\r\n\r\nIs there an obviously correct solution for this?"},"comment":{"url":"https://api.github.com/repos/RobotLocomotion/drake/issues/comments/134416889","html_url":"https://github.com/RobotLocomotion/drake/issues/1273#issuecomment-134416889","issue_url":"https://api.github.com/repos/RobotLocomotion/drake/issues/1273","id":134416889,"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},"created_at":"2015-08-24T23:47:51Z","updated_at":"2015-08-24T23:47:51Z","body":"The problem is that it's very dangerous to mix and match.  If you have a class that can be compiled in two slightly different ways by two different obj files that share pointers, that can be super hard to track down.  Twan knows that i fear this right down to my core.\n\n\n\n> On Aug 24, 2015, at 7:43 PM, John Carter <notifications@github.com> wrote:\n> \n> I also hate the explicit instantiations. Twan and I were really happy to be able to purge the mess in drakeGradientUtil after moving things into the header. It's not only cleaner but also solves the problem of the library not having a particular use case baked into it.\n> \n> Maybe there's an intermediate solution that lets us keep the big implementations (doKinematics) separated out while still retaining the benefits of header-only templates.\n> \n> —\n> Reply to this email directly or view it on GitHub.\n> \n"}}