{"action":"created","issue":{"url":"https://api.github.com/repos/astropy/astropy/issues/4892","repository_url":"https://api.github.com/repos/astropy/astropy","labels_url":"https://api.github.com/repos/astropy/astropy/issues/4892/labels{/name}","comments_url":"https://api.github.com/repos/astropy/astropy/issues/4892/comments","events_url":"https://api.github.com/repos/astropy/astropy/issues/4892/events","html_url":"https://github.com/astropy/astropy/issues/4892","id":154703918,"number":4892,"title":"CompositeModel does not inherit n_models properly","user":{"login":"pllim","id":2090236,"avatar_url":"https://avatars.githubusercontent.com/u/2090236?v=3","gravatar_id":"","url":"https://api.github.com/users/pllim","html_url":"https://github.com/pllim","followers_url":"https://api.github.com/users/pllim/followers","following_url":"https://api.github.com/users/pllim/following{/other_user}","gists_url":"https://api.github.com/users/pllim/gists{/gist_id}","starred_url":"https://api.github.com/users/pllim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pllim/subscriptions","organizations_url":"https://api.github.com/users/pllim/orgs","repos_url":"https://api.github.com/users/pllim/repos","events_url":"https://api.github.com/users/pllim/events{/privacy}","received_events_url":"https://api.github.com/users/pllim/received_events","type":"User","site_admin":false},"labels":[{"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,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-05-13T12:47:48Z","updated_at":"2016-09-21T22:11:03Z","closed_at":null,"body":"This illustrates the problem:\r\n\r\n```python\r\n>>> from astropy.modeling import models\r\n>>> m1 = models.Box1D(amplitude=[1, 1], x_0=[5000, 6000], width=[10, 100], n_models=2)\r\n>>> m1._n_models\r\n2\r\n>>> m2 = models.Trapezoid1D(amplitude=[100, 100], x_0=[5000, 6000], width=[10, 100], slope=[1, 2], n_models=2)\r\n>>> m2._n_models\r\n2\r\n>>> m = m1 + m2\r\n>>> m\r\n<CompoundModel9(amplitude_0=[ 1., 1.], x_0_0=[ 5000., 6000.], width_0=[  10., 100.], amplitude_1=[ 100., 100.], x_0_1=[ 5000., 6000.], width_1=[  10., 100.], slope_1=[ 1., 2.])>\r\n>>> m._n_models\r\n1\r\n```\r\n\r\nAs a result, evaluation on the compound model breaks:\r\n```python\r\n>>> x = np.arange(3000, 7000)\r\n>>> m1(x, model_set_axis=False)\r\narray([[ 0.,  0.,  0., ...,  0.,  0.,  0.],\r\n       [ 0.,  0.,  0., ...,  0.,  0.,  0.]])\r\n>>> m2(x, model_set_axis=False)\r\narray([[ 0.,  0.,  0., ...,  0.,  0.,  0.],\r\n       [ 0.,  0.,  0., ...,  0.,  0.,  0.]])\r\n>>> m(x, model_set_axis=False)\r\n...\r\n.../astropy/modeling/core.py in __call__(self, x, model_set_axis)\r\n    383             args = ('self',) + inputs\r\n    384             new_call = make_function_with_signature(\r\n--> 385                     __call__, args, [('model_set_axis', None)])\r\n    386             update_wrapper(new_call, cls)\r\n    387             cls.__call__ = new_call\r\n\r\n.../astropy/modeling/core.pyc in __call__(self, *inputs, **kwargs)\r\n    379                 \"\"\"Evaluate this model on the supplied inputs.\"\"\"\r\n    380 \r\n--> 381                 return super(cls, self).__call__(*inputs, **kwargs)\r\n    382 \r\n    383             args = ('self',) + inputs\r\n\r\n.../astropy/modeling/core.pyc in __call__(self, *inputs, **kwargs)\r\n    682 \r\n--> 683         inputs, format_info = self.prepare_inputs(*inputs, **kwargs)\r\n    684         parameters = self._param_sets(raw=True)\r\n    685 \r\n\r\n.../astropy/modeling/core.pyc in prepare_inputs(self, *inputs, **kwargs)\r\n   1190         if n_models == 1:\r\n   1191             return _prepare_inputs_single_model(self, params, inputs,\r\n-> 1192                                                 **kwargs)\r\n   1193         else:\r\n   1194             return _prepare_inputs_model_set(self, params, inputs, n_models,\r\n\r\n.../astropy/modeling/core.pyc in _prepare_inputs_single_model(model, params, inputs, **kwargs)\r\n   2806                     \"broadcast with parameter {2!r} of shape \"\r\n   2807                     \"{3!r}.\".format(model.inputs[idx], input_shape,\r\n-> 2808                                     param.name, param.shape))\r\n   2809 \r\n   2810             if len(broadcast) > len(max_broadcast):\r\n\r\nValueError: Model input argument u'x' of shape (4000,) cannot be broadcast with parameter u'amplitude_0' of shape (2,).\r\n```"},"comment":{"url":"https://api.github.com/repos/astropy/astropy/issues/comments/248758076","html_url":"https://github.com/astropy/astropy/issues/4892#issuecomment-248758076","issue_url":"https://api.github.com/repos/astropy/astropy/issues/4892","id":248758076,"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":"2016-09-21T22:11:03Z","updated_at":"2016-09-21T22:11:03Z","body":"I think for simplicity and until we have a use case for it an error should be raised when `model._n_models != 1` for all child models."}}
{"actor":{"display_login":"nden"}}