Skip to content

Commit

Permalink
Merge pull request #14 from mhauru/mhauru/fix-getindex-metricproblem
Browse files Browse the repository at this point in the history
Make getindex on MetricProblem return a MetricProblem
  • Loading branch information
ReubenJ authored Oct 29, 2024
2 parents 4073698 + 0ab8b4b commit f1e4a30
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/problem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ end
Overwrite `Base.getindex` to allow for slicing of input/output-based problems.
"""
Base.getindex(p::Problem{Vector{IOExample}}, indices) = Problem(p.spec[indices])
Base.getindex(p::MetricProblem{Vector{IOExample}}, indices) = Problem(p.spec[indices])
Base.getindex(p::MetricProblem{Vector{IOExample}}, indices) = MetricProblem(p.cost_function, p.spec[indices])


3 changes: 2 additions & 1 deletion test/test_ioproblem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ end

# Test getindex
submetric = metric2[1:2]
@test isa(submetric, Problem)
@test isa(submetric, MetricProblem)
@test submetric.spec == spec[1:2]
@test submetric.name == ""
@test submetric.cost_function === cost_function
end

0 comments on commit f1e4a30

Please sign in to comment.