{"action":"created","issue":{"url":"https://api.github.com/repos/astropy/astropy/issues/3297","labels_url":"https://api.github.com/repos/astropy/astropy/issues/3297/labels{/name}","comments_url":"https://api.github.com/repos/astropy/astropy/issues/3297/comments","events_url":"https://api.github.com/repos/astropy/astropy/issues/3297/events","html_url":"https://github.com/astropy/astropy/pull/3297","id":54372584,"number":3297,"title":"fix Mapping.inverse","user":{"login":"nden","id":1110361,"avatar_url":"https://avatars.githubusercontent.com/u/1110361?v=3","gravatar_id":"","url":"https://api.github.com/users/nden","html_url":"https://github.com/nden","followers_url":"https://api.github.com/users/nden/followers","following_url":"https://api.github.com/users/nden/following{/other_user}","gists_url":"https://api.github.com/users/nden/gists{/gist_id}","starred_url":"https://api.github.com/users/nden/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nden/subscriptions","organizations_url":"https://api.github.com/users/nden/orgs","repos_url":"https://api.github.com/users/nden/repos","events_url":"https://api.github.com/users/nden/events{/privacy}","received_events_url":"https://api.github.com/users/nden/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/astropy/astropy/labels/Affects-dev","name":"Affects-dev","color":"eb6420"},{"url":"https://api.github.com/repos/astropy/astropy/labels/Bug","name":"Bug","color":"eb6420"},{"url":"https://api.github.com/repos/astropy/astropy/labels/modeling","name":"modeling","color":"c7def8"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/astropy/astropy/milestones/15","labels_url":"https://api.github.com/repos/astropy/astropy/milestones/15/labels","id":643887,"number":15,"title":"v1.0.0","description":"","creator":{"login":"astrofrog","id":314716,"avatar_url":"https://avatars.githubusercontent.com/u/314716?v=3","gravatar_id":"","url":"https://api.github.com/users/astrofrog","html_url":"https://github.com/astrofrog","followers_url":"https://api.github.com/users/astrofrog/followers","following_url":"https://api.github.com/users/astrofrog/following{/other_user}","gists_url":"https://api.github.com/users/astrofrog/gists{/gist_id}","starred_url":"https://api.github.com/users/astrofrog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astrofrog/subscriptions","organizations_url":"https://api.github.com/users/astrofrog/orgs","repos_url":"https://api.github.com/users/astrofrog/repos","events_url":"https://api.github.com/users/astrofrog/events{/privacy}","received_events_url":"https://api.github.com/users/astrofrog/received_events","type":"User","site_admin":false},"open_issues":28,"closed_issues":188,"state":"open","created_at":"2014-04-29T16:03:02Z","updated_at":"2015-01-15T15:38:50Z","due_on":"2015-01-23T05:00:00Z","closed_at":null},"comments":1,"created_at":"2015-01-14T20:31:53Z","updated_at":"2015-01-15T15:47:54Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/astropy/astropy/pulls/3297","html_url":"https://github.com/astropy/astropy/pull/3297","diff_url":"https://github.com/astropy/astropy/pull/3297.diff","patch_url":"https://github.com/astropy/astropy/pull/3297.patch"},"body":"`Mapping.inverse` is incorrect when duplicating inputs:\r\n\r\n```\r\nm = Mapping((0, 1, 0))\r\nm.inverse.n_inputs\r\n2\r\nm.inverse.n_outputs\r\n2\r\n```\r\nThis causes the inverse of compound models to fail because the inputs don't match the outputs any more.\r\n\r\n```\r\nmodel = Shift(1) & Shift(2) | m | (Scale(1) & Scale(2) & Scale(3)\r\n```\r\n\r\nThis PR provides a fix for this problem, although in somewhat kludgy way. The problem is that `Mapping` accepts arbitrary number of inputs. And there's no way to initialize a model by specifying how many inputs will be passed.\r\n\r\nThis PR also adds docstrings and changes the two models in such a way that now a `name` argument can be passed in when a model is initialized.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/astropy/astropy/issues/comments/70105705","html_url":"https://github.com/astropy/astropy/pull/3297#issuecomment-70105705","issue_url":"https://api.github.com/repos/astropy/astropy/issues/3297","id":70105705,"user":{"login":"nden","id":1110361,"avatar_url":"https://avatars.githubusercontent.com/u/1110361?v=3","gravatar_id":"","url":"https://api.github.com/users/nden","html_url":"https://github.com/nden","followers_url":"https://api.github.com/users/nden/followers","following_url":"https://api.github.com/users/nden/following{/other_user}","gists_url":"https://api.github.com/users/nden/gists{/gist_id}","starred_url":"https://api.github.com/users/nden/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nden/subscriptions","organizations_url":"https://api.github.com/users/nden/orgs","repos_url":"https://api.github.com/users/nden/repos","events_url":"https://api.github.com/users/nden/events{/privacy}","received_events_url":"https://api.github.com/users/nden/received_events","type":"User","site_admin":false},"created_at":"2015-01-15T15:47:54Z","updated_at":"2015-01-15T15:47:54Z","body":"@embray As you requested I split the original PR in two. This one has only a fix for the problems with inverse and tests for classes in mappings.py The other one (coming shortly) will have the docstrings and changes of `name` and `__repr__`. While writing the tests I ran into another problem with inverse involving `Identity` and `Rotation2D` and scalar inputs. \r\n```\r\nident1 = Identity(1)\r\nshift = Shift(1)\r\nrotation = Rotation2D(angle=60)\r\nmodel = ident1 & shift | rotation\r\nmodel(1, 2)\r\n```\r\n I am posting the traceback because it may be indicative of a subtle problem with inputs to compound models. The shapes of `ident1(1)` and `shift(2)` when joined and sent as input to a `|` operation are indeed different, `()`, and `(1,)`, as the results are `1` and `[3]`. I don't know why the two models evaluate a scalar to a result with a different shape. A workaround is to remove the check for the shape of the inputs in `Rotation2D` (which I did in this PR) but I'm wondering if this shows a real problem.\r\n\r\n```\r\n---------------------------------------------------------------------------\r\nValueError                                Traceback (most recent call last)\r\n<ipython-input-6-caf5237bbd81> in <module>()\r\n----> 1 model(1,2)\r\n\r\n/internal/1/astropy/embray-compound-mdboom-gwcs3/lib/python2.7/site-packages/astropy-1.0.dev11388-py2.7-linux-x86_64.egg/astropy/modeling/core.py in __call__(self, x0, x, model_set_axis)\r\n    312             args = ('self',) + inputs\r\n    313             new_call = make_function_with_signature(\r\n--> 314                     __call__, args, [('model_set_axis', None)])\r\n    315             update_wrapper(new_call, cls)\r\n    316             cls.__call__ = new_call\r\n\r\n/internal/1/astropy/embray-compound-mdboom-gwcs3/lib/python2.7/site-packages/astropy-1.0.dev11388-py2.7-linux-x86_64.egg/astropy/modeling/core.pyc in __call__(self, *inputs, **kwargs)\r\n    308                 \"\"\"Evaluate this model on the supplied inputs.\"\"\"\r\n    309 \r\n--> 310                 return super(cls, self).__call__(*inputs, **kwargs)\r\n    311 \r\n    312             args = ('self',) + inputs\r\n\r\n/internal/1/astropy/embray-compound-mdboom-gwcs3/lib/python2.7/site-packages/astropy-1.0.dev11388-py2.7-linux-x86_64.egg/astropy/modeling/core.pyc in __call__(self, *inputs, **kwargs)\r\n    569         parameters = self._param_sets(raw=True)\r\n    570 \r\n--> 571         outputs = self.evaluate(*chain(inputs, parameters))\r\n    572 \r\n    573         if self.n_outputs == 1:\r\n\r\n/internal/1/astropy/embray-compound-mdboom-gwcs3/lib/python2.7/site-packages/astropy-1.0.dev11388-py2.7-linux-x86_64.egg/astropy/modeling/core.pyc in evaluate(self, *args)\r\n   1959     @sharedmethod\r\n   1960     def evaluate(self, *args):\r\n-> 1961         return self.__class__.evaluate(*args)\r\n   1962 \r\n   1963     # TODO: The way this works is highly inefficient--the inverse is created by\r\n\r\n/internal/1/astropy/embray-compound-mdboom-gwcs3/lib/python2.7/site-packages/astropy-1.0.dev11388-py2.7-linux-x86_64.egg/astropy/modeling/core.pyc in evaluate(cls, *args)\r\n   1534         inputs = args[:cls.n_inputs]\r\n   1535         params = iter(args[cls.n_inputs:])\r\n-> 1536         result = cls._evaluate(inputs, params)\r\n   1537 \r\n   1538         if cls.n_outputs == 1:\r\n\r\n/internal/1/astropy/embray-compound-mdboom-gwcs3/lib/python2.7/site-packages/astropy-1.0.dev11388-py2.7-linux-x86_64.egg/astropy/modeling/core.pyc in <lambda>(inputs, params)\r\n   1355     #\r\n   1356     # and similarly for g\r\n-> 1357     return (lambda inputs, params: g[0](f[0](inputs, params), params),\r\n   1358             f[1], g[2])\r\n   1359 \r\n\r\n/internal/1/astropy/embray-compound-mdboom-gwcs3/lib/python2.7/site-packages/astropy-1.0.dev11388-py2.7-linux-x86_64.egg/astropy/modeling/core.pyc in <lambda>(inputs, params)\r\n   1917             else:\r\n   1918                 f = lambda inputs, params: \\\r\n-> 1919                     evaluate(*chain(inputs, islice(params, n_params)))\r\n   1920 \r\n   1921         return (f, n_inputs, n_outputs)\r\n\r\n/internal/1/astropy/embray-compound-mdboom-gwcs3/lib/python2.7/site-packages/astropy-1.0.dev11388-py2.7-linux-x86_64.egg/astropy/modeling/rotations.py in evaluate(cls, x, y, angle)\r\n    189         print('x,y', x, y, x.shape, y.shape)\r\n    190         if x.shape != y.shape:\r\n--> 191             raise ValueError(\"Expected input arrays to have the same shape\")\r\n    192 \r\n    193         # Note: If the original shape was () (an array scalar) convert to a\r\n\r\nValueError: Expected input arrays to have the same shape\r\n```"}}