-
Notifications
You must be signed in to change notification settings - Fork 40
Add ComponentArraysExt to fix mixed index/property access on ComponentArrays (#1230) #1373
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
Merged
+143
−0
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
3f871cc
Add ComponentArraysExt to fix mixed index/property access
ArpanC6 7bbe5ba
Fix formatting
ArpanC6 226c065
Add ComponentArrays to test/Project.toml
ArpanC6 75b6f62
Add ComponentArrays to [extras] in Project.toml
ArpanC6 c23056d
fix: disable Aqua stale_deps check for ComponentArrays weakdep
ArpanC6 20f3706
fix: move ComponentArrays to weakdeps, add tests, revert Aqua change
ArpanC6 d9dac33
style: format ComponentArrays test with JuliaFormatter v1
ArpanC6 f805cd8
fix: remove make_leaf overload, use label2index, expand tests
ArpanC6 fc0e846
test: expand ComponentArrays tests with cross-access and array-valued…
ArpanC6 5317aa4
style: remove trailing newline
ArpanC6 18424f1
fix: use label2index and ComponentVector, remove make_leaf overload
ArpanC6 d8ed680
fix: use label2index and ComponentVector, remove make_leaf overload
ArpanC6 180e649
fix: restore ComponentArrays to weakdeps
ArpanC6 799b593
fix: add ComponentArrays to compat
ArpanC6 3799736
style: format ComponentArraysExt with JuliaFormatter v1
ArpanC6 61b66ca
fix: use parent(template) and String(S) in label2index call
ArpanC6 f617efc
fix: remove stray entries from .gitignore
ArpanC6 9631c58
fix: use S directly in label2index instead of String(S)
ArpanC6 7ed60b4
fix: use template directly in label2index, remove parent()
ArpanC6 1b26bed
fix: use pa.data in label2index call
ArpanC6 02adfc1
fix: use ComponentArrays.getaxes and ax[S].idx for property lookup
ArpanC6 4857977
style: add trailing newline
ArpanC6 28048c3
fix: use first(ax[S].idx) to extract integer from range
ArpanC6 84990d8
fix: remove invalid cross-access tests
ArpanC6 e261e53
fix: add _getindex_optic overload for Property optic on ComponentVect…
ArpanC6 8766066
style: reformat with JuliaFormatter v1
ArpanC6 159513b
fix: handle Property optic in make_leaf for ComponentVector
ArpanC6 7ebae5b
style: reformat with BlueStyle
ArpanC6 fd6392c
refactor: extract helper function, add property-first and MustNotOver…
ArpanC6 5c5fb92
style: format ext with JuliaFormatter v1
ArpanC6 6f12d3b
Merge remote-tracking branch 'origin/main' into fix/componentarrays-ext
penelopeysm 66004da
Bump patch
penelopeysm f9849d9
Use loops in tests
penelopeysm 841ffde
Add more tests
penelopeysm 0fbc196
test skeleton as well
penelopeysm 5e3a1ca
Merge remote-tracking branch 'origin/main' into fix/componentarrays-ext
penelopeysm 28a144f
Fix bad merge
penelopeysm 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -7,3 +7,4 @@ Manifest.toml | |
|
|
||
| benchmarks/*.json | ||
| LocalPreferences.toml | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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,64 @@ | ||
| module DynamicPPLComponentArraysExt | ||
| using DynamicPPL: DynamicPPL | ||
| using DynamicPPL.VarNamedTuples: | ||
| PartialArray, | ||
| AllowAll, | ||
| SetPermissions, | ||
| _setindex_optic!!, | ||
| _getindex_optic, | ||
| make_leaf, | ||
| make_leaf_singleindex, | ||
| _is_multiindex, | ||
| make_leaf_multiindex | ||
| using ComponentArrays: ComponentArrays, ComponentArray, ComponentVector | ||
| using AbstractPPL | ||
|
|
||
| # Helper: convert a Property optic label S to an integer Index optic | ||
| function _property_to_index( | ||
| template::ComponentVector, optic::AbstractPPL.Property{S} | ||
| ) where {S} | ||
| ax = ComponentArrays.getaxes(template)[1] | ||
| idx = first(ax[S].idx) | ||
| return AbstractPPL.Index((idx,), NamedTuple(), optic.child) | ||
| end | ||
|
|
||
| function DynamicPPL.VarNamedTuples.make_leaf( | ||
| value, optic::AbstractPPL.Property{S}, template::ComponentVector | ||
| ) where {S} | ||
| return if optic.child isa AbstractPPL.Iden | ||
| index_optic = _property_to_index(template, optic) | ||
| make_leaf(value, index_optic, template) | ||
| else | ||
| # This branch is needed to handle nested axes in ComponentArrays: the idea is that | ||
| # if x is e.g. ComponentArray(a=(b=1)) and we are trying to set `x.a.b`, then we | ||
| # first index into `x.a` to get the slice of the ComponentArray. The easiest way to | ||
| # handle this is to call the default method. | ||
| invoke( | ||
| make_leaf, | ||
| Tuple{Any,AbstractPPL.Property{S},AbstractArray}, | ||
| value, | ||
| optic, | ||
| template, | ||
| ) | ||
| end | ||
| end | ||
|
|
||
| function DynamicPPL.VarNamedTuples._setindex_optic!!( | ||
| pa::PartialArray{<:Any,<:Any,<:ComponentVector}, | ||
| value, | ||
| optic::AbstractPPL.Property{S}, | ||
| template, | ||
| permissions::SetPermissions=AllowAll(), | ||
| ) where {S} | ||
| index_optic = _property_to_index(pa.data, optic) | ||
| return _setindex_optic!!(pa, value, index_optic, template, permissions) | ||
|
penelopeysm marked this conversation as resolved.
|
||
| end | ||
|
penelopeysm marked this conversation as resolved.
|
||
|
|
||
| function DynamicPPL.VarNamedTuples._getindex_optic( | ||
| pa::PartialArray{<:Any,<:Any,<:ComponentVector}, optic::AbstractPPL.Property{S}, orig_vn | ||
| ) where {S} | ||
| index_optic = _property_to_index(pa.data, optic) | ||
| return _getindex_optic(pa, index_optic, orig_vn) | ||
| end | ||
|
|
||
| end | ||
This file contains hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.