Skip to content

Utilities.value_type can be incorrect for ScalarNonlinearFunction #2776

@klamike

Description

@klamike

I have no idea how you'd fix this besides removing value_type(T, ::Type{ScalarNonlinearFunction}), but currently it is misleading since it just returns T:

using MathOptInterface

# make a nonlinear function with a Float64 in it
model = MathOptInterface.Utilities.Model{Float64}()
x = MathOptInterface.add_variable(model)
expr = convert(MathOptInterface.ScalarNonlinearFunction, MathOptInterface.VariableIndex(1) + 2.0)

# ask jump what the type will be if we eval with Float32
VT = MathOptInterface.Utilities.value_type(Float32, typeof(expr))
# Float32

# check the real type
RT = typeof(MathOptInterface.Utilities.eval_variables(x -> 3.0f0, model, expr))
# Float64

@assert VT === RT 
# AssertionError: VT === RT

It would be nice to have a function that converts all the constants in a nonlinear function to a given type

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions