Skip to content

Allow changing coefficient type in FileFormats.Model #2532

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

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
31 changes: 16 additions & 15 deletions src/FileFormats/FileFormats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,39 +64,40 @@
function Model(;
format::FileFormat = FORMAT_AUTOMATIC,
filename::Union{Nothing,String} = nothing,
coefficient_type::Type = Float64,
kwargs...,
)
if format == FORMAT_CBF
return CBF.Model(; kwargs...)
return CBF.Model{coefficient_type}(; kwargs...)

Check warning on line 71 in src/FileFormats/FileFormats.jl

View check run for this annotation

Codecov / codecov/patch

src/FileFormats/FileFormats.jl#L71

Added line #L71 was not covered by tests
elseif format == FORMAT_LP
return LP.Model(; kwargs...)
return LP.Model{coefficient_type}(; kwargs...)

Check warning on line 73 in src/FileFormats/FileFormats.jl

View check run for this annotation

Codecov / codecov/patch

src/FileFormats/FileFormats.jl#L73

Added line #L73 was not covered by tests
elseif format == FORMAT_MOF
return MOF.Model(; kwargs...)
return MOF.Model{coefficient_type}(; kwargs...)

Check warning on line 75 in src/FileFormats/FileFormats.jl

View check run for this annotation

Codecov / codecov/patch

src/FileFormats/FileFormats.jl#L75

Added line #L75 was not covered by tests
elseif format == FORMAT_MPS
return MPS.Model(; kwargs...)
return MPS.Model{coefficient_type}(; kwargs...)

Check warning on line 77 in src/FileFormats/FileFormats.jl

View check run for this annotation

Codecov / codecov/patch

src/FileFormats/FileFormats.jl#L77

Added line #L77 was not covered by tests
elseif format == FORMAT_NL
return NL.Model(; kwargs...)
return NL.Model{coefficient_type}(; kwargs...)

Check warning on line 79 in src/FileFormats/FileFormats.jl

View check run for this annotation

Codecov / codecov/patch

src/FileFormats/FileFormats.jl#L79

Added line #L79 was not covered by tests
elseif format == FORMAT_REW
return MPS.Model(; generic_names = true, kwargs...)
return MPS.Model{coefficient_type}(; generic_names = true, kwargs...)

Check warning on line 81 in src/FileFormats/FileFormats.jl

View check run for this annotation

Codecov / codecov/patch

src/FileFormats/FileFormats.jl#L81

Added line #L81 was not covered by tests
elseif format == FORMAT_SDPA
return SDPA.Model(; kwargs...)
return SDPA.Model{coefficient_type}(; kwargs...)

Check warning on line 83 in src/FileFormats/FileFormats.jl

View check run for this annotation

Codecov / codecov/patch

src/FileFormats/FileFormats.jl#L83

Added line #L83 was not covered by tests
else
@assert format == FORMAT_AUTOMATIC
if filename === nothing
error("When `format==FORMAT_AUTOMATIC` you must pass a `filename`.")
end
for (ext, model) in [
(".cbf", CBF.Model),
(".lp", LP.Model),
(".mof.json", MOF.Model),
(".mps", MPS.Model),
(".cbf", CBF.Model{coefficient_type}),
(".lp", LP.Model{coefficient_type}),
(".mof.json", MOF.Model{coefficient_type}),
(".mps", MPS.Model{coefficient_type}),
(
".rew",
(; kwargs...) -> MPS.Model(; generic_names = true, kwargs...),
(; kwargs...) -> MPS.Model{coefficient_type}(; generic_names = true, kwargs...),

Check warning on line 96 in src/FileFormats/FileFormats.jl

View check run for this annotation

Codecov / codecov/patch

src/FileFormats/FileFormats.jl#L96

Added line #L96 was not covered by tests
),
(".nl", NL.Model),
(".dat-s", SDPA.Model),
(".sdpa", SDPA.Model),
(".nl", NL.Model{coefficient_type}),
(".dat-s", SDPA.Model{coefficient_type}),
(".sdpa", SDPA.Model{coefficient_type}),
]
if endswith(filename, ext) || occursin("$(ext).", filename)
return model(; kwargs...)
Expand Down
Loading