Skip to content

Commit

Permalink
Merge pull request #16 from Herb-AI/fix_name_problem_index
Browse files Browse the repository at this point in the history
name also passed to subproblem when indexing the vector of IOExamples
  • Loading branch information
ReubenJ authored Nov 14, 2024
2 parents f1e4a30 + 1382891 commit eef2222
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "HerbSpecification"
uuid = "6d54aada-062f-46d8-85cf-a1ceaf058a06"
authors = ["Tilman Hinnerichs <[email protected]>"]
version = "0.1.0"
version = "0.1.1"

[deps]

Expand Down
4 changes: 2 additions & 2 deletions src/problem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ 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) = MetricProblem(p.cost_function, p.spec[indices])
Base.getindex(p::Problem{Vector{IOExample}}, indices) = Problem(p.name, p.spec[indices])
Base.getindex(p::MetricProblem{Vector{IOExample}}, indices) = MetricProblem(p.name, p.cost_function, p.spec[indices])


29 changes: 22 additions & 7 deletions test/test_ioproblem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ end
@test problem1.name == ""
@test problem1.spec === spec

if spec isa Vector{<:IOExample}
# Test getindex
subproblem = problem1[1:2]
@test isa(subproblem, Problem)
@test subproblem.spec == spec[1:2]
@test subproblem.name == ""
end

# Test constructor with a name
problem_name = "Test Problem"
problem2 = Problem(problem_name, spec)
Expand All @@ -39,7 +47,7 @@ end
subproblem = problem2[1:2]
@test isa(subproblem, Problem)
@test subproblem.spec == spec[1:2]
@test subproblem.name == ""
@test subproblem.name == problem_name
end
end
end
Expand Down Expand Up @@ -67,10 +75,17 @@ end
@test metric2.spec === spec
@test metric2.cost_function === cost_function

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

# Test getindex with name
submetric2 = metric2[2:3]
@test isa(submetric2, MetricProblem)
@test submetric2.spec == spec[2:3]
@test submetric2.name == name
@test submetric2.cost_function === cost_function
end

2 comments on commit eef2222

@ReubenJ
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/119386

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.1 -m "<description of version>" eef22224dfcc3f6d624a4aa55df67a02dae8b141
git push origin v0.1.1

Please sign in to comment.