-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from SciML/as/parameter-indexing-proxy
feat: add `ParameterIndexingProxy`
- Loading branch information
Showing
5 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ parameter_values | |
set_parameter! | ||
getp | ||
setp | ||
ParameterIndexingProxy | ||
``` | ||
|
||
### State indexing | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
""" | ||
struct ParameterIndexingProxy | ||
This struct wraps any struct implementing the symbolic indexing interface. It allows | ||
`getindex` and `setindex!` operations to get/set parameter values. Requires that the | ||
wrapped type support [`getp`](@ref) and [`setp`](@ref) for getting and setting | ||
parameter values respectively. | ||
""" | ||
struct ParameterIndexingProxy{T} | ||
wrapped::T | ||
end | ||
|
||
function Base.getindex(p::ParameterIndexingProxy, idx) | ||
return getp(p.wrapped, idx)(p.wrapped) | ||
end | ||
|
||
function Base.setindex!(p::ParameterIndexingProxy, val, idx) | ||
return setp(p.wrapped, idx)(p.wrapped, val) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters