Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow changing coefficient type in read_from_file #3801

Merged
merged 6 commits into from
Aug 8, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/file_formats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ function Base.write(
return
end

_value_type(model::MOI.Utilities.AbstractModelLike{T}) where {T} = T

# This fallback may not get the correct value type. However, since
# all models defined in `MOI.FileFormats` are created with
# `MOI.Utilities.@model` except `NL` which only supports `Float64`,
odow marked this conversation as resolved.
Show resolved Hide resolved
# this does the job for now.
_value_type(model::MOI.ModelLike) = Float64

"""
read_from_file(
filename::String;
Expand All @@ -107,12 +115,9 @@ function read_from_file(
format::MOI.FileFormats.FileFormat = MOI.FileFormats.FORMAT_AUTOMATIC,
kwargs...,
)
src =
MOI.FileFormats.Model(; format = format, filename = filename, kwargs...)
src = MOI.FileFormats.Model(; format, filename, kwargs...)
MOI.read_from_file(src, filename)
# TODO(odow): what number type to choose? Are there any non-Float64 file
# formats?
model = GenericModel{Float64}()
model = GenericModel{_value_type(model)}()
MOI.copy_to(model, src)
return model
end
Expand Down
Loading