-
Notifications
You must be signed in to change notification settings - Fork 6
allow more Param types #39
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,6 @@ jobs: | |
| fail-fast: true | ||
| matrix: | ||
| version: | ||
| - '1.3' | ||
| - '1.5' | ||
| - 'nightly' | ||
| os: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -246,3 +246,28 @@ end | |
| @test isa(tuplegroups.A.i, Tuple) | ||
| @test isa(tuplegroups.B.j, Tuple) | ||
| end | ||
|
|
||
| struct FreeParam{T,P<:NamedTuple} <: AbstractParam{T} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're going to do this, then the macro to abstract away this boilerplate (and reduce chance of user error) should be included in this PR, I think. |
||
| parent::P | ||
| end | ||
| FreeParam(nt::NT) where {NT<:NamedTuple} = begin | ||
| ModelParameters._checkhasval(nt) | ||
| FreeParam{typeof(nt.val),NT}(nt) | ||
| end | ||
| FreeParam(val; kwargs...) = FreeParam((; val=val, kwargs...)) | ||
| FreeParam(; kwargs...) = FreeParam((; kwargs...)) | ||
|
|
||
| @testset "spefify param type" begin | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you seem to agree that the |
||
| sf = S2( | ||
| FreeParam(99), | ||
| FreeParam(7), | ||
| Param(100.0; bounds=(50.0, 150.0)) | ||
| ) | ||
| @test params(sf; select=FreeParam) == (FreeParam(99), FreeParam(7)) | ||
| m = Model(sf) | ||
| @test m[:val, select=Param] == (100.0,) | ||
| @test getindex(m, :val; select=FreeParam) == (99, 7) | ||
| m[:bounds, select=FreeParam] = ((1, 100), (1, 10)) | ||
| @test m[:bounds] == ((1, 100), (1, 10), (50.0, 150.0)) | ||
| end | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should
selectandignoremaybe have type bounds,Type{T} where {T<:AbstractParam}?