Skip to content

Model evaluation crashes if some inputs are scalars #10170

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions