{"action":"created","issue":{"url":"https://api.github.com/repos/convexopt/gpkit/issues/286","labels_url":"https://api.github.com/repos/convexopt/gpkit/issues/286/labels{/name}","comments_url":"https://api.github.com/repos/convexopt/gpkit/issues/286/comments","events_url":"https://api.github.com/repos/convexopt/gpkit/issues/286/events","html_url":"https://github.com/convexopt/gpkit/issues/286","id":93111324,"number":286,"title":"mutability differs between nomials and PosyArray","user":{"login":"whoburg","id":6042395,"avatar_url":"https://avatars.githubusercontent.com/u/6042395?v=3","gravatar_id":"","url":"https://api.github.com/users/whoburg","html_url":"https://github.com/whoburg","followers_url":"https://api.github.com/users/whoburg/followers","following_url":"https://api.github.com/users/whoburg/following{/other_user}","gists_url":"https://api.github.com/users/whoburg/gists{/gist_id}","starred_url":"https://api.github.com/users/whoburg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/whoburg/subscriptions","organizations_url":"https://api.github.com/users/whoburg/orgs","repos_url":"https://api.github.com/users/whoburg/repos","events_url":"https://api.github.com/users/whoburg/events{/privacy}","received_events_url":"https://api.github.com/users/whoburg/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-07-05T13:31:44Z","updated_at":"2015-07-16T12:46:54Z","closed_at":null,"body":"I'm seeing some unexpected behavior when using `+=`, `*=`, etc. In particular, nomials and PosyArray act differently.\r\n\r\nHere's a simple reference to a `Variable` (which inherits from `Signomial`). When we modify the reference, the original variable remains unchanged:\r\n\r\n```python\r\nIn [1]: from gpkit import Variable, VectorVariable\r\n\r\nIn [2]: x = Variable('x')\r\n\r\nIn [3]: x_ref = x\r\n\r\nIn [4]: x_ref += 5\r\n\r\nIn [5]: x\r\nOut[5]: gpkit.Variable(x)\r\n\r\nIn [6]: x_ref\r\nOut[6]: gpkit.Posynomial(5 + x)\r\n```\r\nWith a `VectorVariable` (which inherits from `PosyArray`), the behavior is completely different:\r\n\r\n```python\r\nIn [7]: y = VectorVariable(2, 'y')\r\n\r\nIn [8]: y_ref = y\r\n\r\nIn [9]: y_ref += 5\r\n\r\nIn [10]: y\r\nOut[10]: gpkit.PosyArray([5 + y_(0,), 5 + y_(1,)])\r\n\r\nIn [11]: y_ref\r\nOut[11]: gpkit.PosyArray([5 + y_(0,), 5 + y_(1,)])\r\n```\r\n\r\nBefore we change anything, I'd like to understand the current behavior -- what in our implementation is causing this difference?"},"comment":{"url":"https://api.github.com/repos/convexopt/gpkit/issues/comments/121947023","html_url":"https://github.com/convexopt/gpkit/issues/286#issuecomment-121947023","issue_url":"https://api.github.com/repos/convexopt/gpkit/issues/286","id":121947023,"user":{"login":"whoburg","id":6042395,"avatar_url":"https://avatars.githubusercontent.com/u/6042395?v=3","gravatar_id":"","url":"https://api.github.com/users/whoburg","html_url":"https://github.com/whoburg","followers_url":"https://api.github.com/users/whoburg/followers","following_url":"https://api.github.com/users/whoburg/following{/other_user}","gists_url":"https://api.github.com/users/whoburg/gists{/gist_id}","starred_url":"https://api.github.com/users/whoburg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/whoburg/subscriptions","organizations_url":"https://api.github.com/users/whoburg/orgs","repos_url":"https://api.github.com/users/whoburg/repos","events_url":"https://api.github.com/users/whoburg/events{/privacy}","received_events_url":"https://api.github.com/users/whoburg/received_events","type":"User","site_admin":false},"created_at":"2015-07-16T12:46:54Z","updated_at":"2015-07-16T12:46:54Z","body":"Well this simple numpy example agrees with you:\r\n\r\n```python\r\nIn [1]: import numpy as np\r\n\r\nIn [2]: x = np.arange(4)\r\n\r\nIn [3]: x_ref = x\r\n\r\nIn [4]: x += 2\r\n\r\nIn [5]: x\r\nOut[5]: array([2, 3, 4, 5])\r\n\r\nIn [6]: x_ref\r\nOut[6]: array([2, 3, 4, 5])\r\n```\r\nNote this behavior differs from that of int and float:\r\n\r\n```python\r\nIn [7]: t = 3.\r\n\r\nIn [8]: t_ref = t\r\n\r\nIn [9]: t_ref += 1\r\n\r\nIn [10]: print t, t_ref\r\n3.0 4.0\r\n```\r\nThis immutability explains why our current implementation of `+=` for `Variable` makes some sense.\r\n\r\nBut I'm convinced that the behavior should be the same for `Variable` and `VectorVariable` -- anything else seems overly confusing for a user.\r\n\r\nAnd I think I'm therefore ready to propose that a `Signomial` should be mutable. In other words, I'm suggesting that the behavior for the original example in this ticket should be (note: not implemented this way currently):\r\n\r\n```python\r\nIn [1]: from gpkit import Variable, VectorVariable\r\n\r\nIn [2]: x = Variable('x')\r\n\r\nIn [3]: x_ref = x\r\n\r\nIn [4]: x_ref += 5\r\n\r\nIn [5]: x\r\nOut[5]: gpkit.Posynomial(5 + x)\r\n\r\nIn [6]: x_ref\r\nOut[6]: gpkit.Posynomial(5 + x)\r\n\r\nIn [7]: x_ref is x\r\nOut[7]: True\r\n```\r\nThoughts?"}}