Skip to content

Improve error in objective function arithmetic #110

Description

@santisoler

If we try to add an int with an objective function we get the following error:

from tests.utils import Dummy

phi = Dummy(3)
1 + phi
ValueError: Cannot add objective function 'φ(m)' with '1'. Objective functions cannot be added to integers other than zero.

But if we try to do the same with a float, we get something not so straight forward:

1.0 + phi
AttributeError: 'float' object has no attribute 'n_params'

We should improve this error by adding another check in the __add__ and __radd__ of the ii.base.Objective class.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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