Skip to content

Model evaluation crashes if some inputs are scalars #10170

Closed

Description

@chris-simpson

Edited

I originally posted this because I thought it was specific to fix_inputs, but it's more fundamental than that, this is a revised description.

Description

A model can be called with some inputs as scalars and some as arrays/lists, with the scalars being broadcasted to the same shape as the other inputs. After evaluation, the output is rebroadcast by prepare_outputs() but this checks the shapes of the outputs against the shapes of the inputs, and crashes if any of the first n_outputs inputs were scalars.

Expected behavior

I should get identical results from, but the first works and the second crashes.

>>> g = Gaussian2D(1, 2, 3, 4, 5)
>>> g([2.5,2.5], 1)
>>> g(2.5, [1,1])

Actual behavior

ValueError: can only convert an array of size 1 to a Python scalar

Steps to Reproduce

>>> from astropy.modeling.models import Gaussian2D
>>> g = Gaussian2D(1, 2, 3, 4, 5)
>>> g([2.5,2.5], 1)
array([0.9159326, 0.9159326])
>>> g(2.5, [1,1])  # should be the same
Traceback (most recent call last):
...
ValueError: can only convert an array of size 1 to a Python scalar

System Details

Python 3.7.6 (default, Jan 8 2020, 13:42:34)
[Clang 4.0.1 (tags/RELEASE_401/final)]
Numpy 1.18.1
astropy 4.0
Scipy 1.4.1

Activity

  1. changed the title [-]fix_inputs fails to expand value into array if other inputs are arrays[/-] [+]Model evaluation crashes if some inputs are scalars[/+] on Apr 20, 2020
  2. nden commented on Apr 20, 2020

    @nden
    Contributor

    Thanks for the report. I think this is related to #9953 and the first example works only by accident.

  3. astropy-bot commented on Apr 28, 2020

    @astropy-bot

    Hi humans 👋 - this issue was labeled as Close? approximately 7 days ago. If you think this issue should not be closed, a maintainer should remove the Close? label - otherwise, I will close this issue in a month.

    If you believe I commented on this issue incorrectly, please report this here

  4. removed
    Close?Tell stale bot that this issue/PR is stale
    on Apr 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions