-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
feat: support indexing Tuple parameters, add tests #63
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
de8b19b
feat: support indexing Tuple parameters, add tests
AayushSabharwal f4b1bc3
fix: fix `remake_buffer` bug
AayushSabharwal 1339885
fix: add `getname(::Symbol)` method
AayushSabharwal 0c78100
refactor: promote types in `remake_buffer` instead of `Union`
AayushSabharwal b70f98f
fix: export `finalize_parameters_hook!`
AayushSabharwal 30b4759
feat: implement `remake_buffer` for `Tuple`s
AayushSabharwal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -4,12 +4,14 @@ authors = ["Aayush Sabharwal <[email protected]> and contributors"] | |
version = "0.3.13" | ||
|
||
[deps] | ||
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" | ||
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9" | ||
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" | ||
RuntimeGeneratedFunctions = "7e49a35a-f44a-4d26-94aa-eba1b4ca6b47" | ||
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" | ||
|
||
[compat] | ||
Accessors = "0.1.36" | ||
Aqua = "0.8" | ||
ArrayInterface = "7.9" | ||
MacroTools = "0.5.13" | ||
|
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -6,8 +6,8 @@ | |||||||||
values in `vals` may not match the types of values stored at the corresponding indexes in | ||||||||||
the buffer, in which case the type of the buffer should be promoted accordingly. In | ||||||||||
general, this method should attempt to preserve the types of values stored in `vals` as | ||||||||||
much as possible. The returned buffer should be of the same type (ignoring type-parameters) | ||||||||||
as `oldbuffer`. | ||||||||||
much as possible. Types can be promoted for type-stability, to maintain performance. The | ||||||||||
returned buffer should be of the same type (ignoring type-parameters) as `oldbuffer`. | ||||||||||
|
||||||||||
This method is already implemented for | ||||||||||
`remake_buffer(sys, oldbuffer::AbstractArray, vals::Dict)` and supports static arrays | ||||||||||
|
@@ -19,14 +19,30 @@ | |||||||||
if ArrayInterface.ismutable(oldbuffer) && !isa(oldbuffer, MArray) | ||||||||||
elT = Union{} | ||||||||||
for val in values(vals) | ||||||||||
elT = Union{elT, typeof(val)} | ||||||||||
elT = promote_type(elT, typeof(val)) | ||||||||||
end | ||||||||||
|
||||||||||
newbuffer = similar(oldbuffer, elT) | ||||||||||
setu(sys, keys(vals))(newbuffer, values(vals)) | ||||||||||
setu(sys, collect(keys(vals)))(newbuffer, elT.(values(vals))) | ||||||||||
else | ||||||||||
mutbuffer = remake_buffer(sys, collect(oldbuffer), vals) | ||||||||||
newbuffer = similar_type(oldbuffer, eltype(mutbuffer))(mutbuffer) | ||||||||||
end | ||||||||||
return newbuffer | ||||||||||
end | ||||||||||
|
||||||||||
mutable struct TupleRemakeWrapper | ||||||||||
t::Tuple | ||||||||||
Comment on lines
+34
to
+35
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.
Suggested change
? |
||||||||||
end | ||||||||||
|
||||||||||
function set_parameter!(sys::TupleRemakeWrapper, val, idx) | ||||||||||
tp = sys.t | ||||||||||
@reset tp[idx] = val | ||||||||||
sys.t = tp | ||||||||||
end | ||||||||||
|
||||||||||
function remake_buffer(sys, oldbuffer::Tuple, vals::Dict) | ||||||||||
wrap = TupleRemakeWrapper(oldbuffer) | ||||||||||
setu(sys, collect(keys(vals)))(wrap, values(vals)) | ||||||||||
return wrap.t | ||||||||||
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This won't infer, Tuple isn't concrete
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.
The type of the tuple can change, which is why it's not fully typed