{"action":"created","issue":{"url":"https://api.github.com/repos/brian-team/brian2/issues/534","labels_url":"https://api.github.com/repos/brian-team/brian2/issues/534/labels{/name}","comments_url":"https://api.github.com/repos/brian-team/brian2/issues/534/comments","events_url":"https://api.github.com/repos/brian-team/brian2/issues/534/events","html_url":"https://github.com/brian-team/brian2/pull/534","id":99321461,"number":534,"title":"[MRG] Loop-invariant optimisations for expressions with booleans","user":{"login":"thesamovar","id":2903870,"avatar_url":"https://avatars.githubusercontent.com/u/2903870?v=3","gravatar_id":"","url":"https://api.github.com/users/thesamovar","html_url":"https://github.com/thesamovar","followers_url":"https://api.github.com/users/thesamovar/followers","following_url":"https://api.github.com/users/thesamovar/following{/other_user}","gists_url":"https://api.github.com/users/thesamovar/gists{/gist_id}","starred_url":"https://api.github.com/users/thesamovar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thesamovar/subscriptions","organizations_url":"https://api.github.com/users/thesamovar/orgs","repos_url":"https://api.github.com/users/thesamovar/repos","events_url":"https://api.github.com/users/thesamovar/events{/privacy}","received_events_url":"https://api.github.com/users/thesamovar/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/brian-team/brian2/labels/in%20progress","name":"in progress","color":"ededed"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-08-05T23:33:56Z","updated_at":"2015-09-30T09:49:25Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/brian-team/brian2/pulls/534","html_url":"https://github.com/brian-team/brian2/pull/534","diff_url":"https://github.com/brian-team/brian2/pull/534.diff","patch_url":"https://github.com/brian-team/brian2/pull/534.patch"},"body":"Started work on this (not ready to merge yet). There are going to be some issues to discuss.\r\n\r\nFirstly, there's an issue with the current code in that it won't pull out, e.g. ``exp(y)`` where ``y`` is a scalar because the sympy op count for ``exp(y)`` is 1, but it's very much worth pulling out. I think the logic of this bit of code was not to pull out really trivial things like ``-y`` but we need a more sophisticated way of checking it. A related problem is that even an operation like ``y*y*y`` doesn't get pulled out because sympy simplifies it to ``y**3`` which is one operation, but then we use the unsimplified version ``y*y*y``.\r\n\r\nSecondly, if you run the current example it transforms the vector code ``x += exp(y*b)`` where y is scalar and b is boolean to the following:\r\n\r\n```\r\nSCALAR\r\n    _lio_const_1 := exp(y * 0.0) (constant)\r\n    _lio_const_2 := exp(y * 1.0) (constant)\r\nVECTOR\r\n    x += (_lio_const_1*(1-b)+_lio_const_2*b) (in-place)\r\n```\r\n\r\nI wonder if it's worth simplifying the expressions for the LIO constants? Possibly not since they're scalar expressions so they're only evaluated once per call, compared to the vector operations. However, it might still be worth thinking about this because if one of the two has the value 0 then we could replace the vector operation by something simpler.\r\n\r\nThings still to do include:\r\n* Improve the op count checker\r\n* Testing whether or not it's worth applying the boolean replacement LIO with the modified op count check\r\n* Think about using sympy simplifications? (What are the issues here?)\r\n\r\nFixes #394 "},"comment":{"url":"https://api.github.com/repos/brian-team/brian2/issues/comments/144342572","html_url":"https://github.com/brian-team/brian2/pull/534#issuecomment-144342572","issue_url":"https://api.github.com/repos/brian-team/brian2/issues/534","id":144342572,"user":{"login":"mstimberg","id":1381982,"avatar_url":"https://avatars.githubusercontent.com/u/1381982?v=3","gravatar_id":"","url":"https://api.github.com/users/mstimberg","html_url":"https://github.com/mstimberg","followers_url":"https://api.github.com/users/mstimberg/followers","following_url":"https://api.github.com/users/mstimberg/following{/other_user}","gists_url":"https://api.github.com/users/mstimberg/gists{/gist_id}","starred_url":"https://api.github.com/users/mstimberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mstimberg/subscriptions","organizations_url":"https://api.github.com/users/mstimberg/orgs","repos_url":"https://api.github.com/users/mstimberg/repos","events_url":"https://api.github.com/users/mstimberg/events{/privacy}","received_events_url":"https://api.github.com/users/mstimberg/received_events","type":"User","site_admin":false},"created_at":"2015-09-30T09:49:25Z","updated_at":"2015-09-30T09:49:25Z","body":"All the tests pass and the examples run fine as well. Anything you'd still like to add (tests/documentation/...)? "}}