-
Notifications
You must be signed in to change notification settings - Fork 124
Implement hash consing for Sym
#658
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
Merged
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d50294b
Add WeakValueDicts
bowenszhu 7a3d8ba
Import `WeakValueDict`
bowenszhu e9e702b
Construct SymbolicUtils internal `WeakValueDict`
bowenszhu 62403b9
Change `BasicSymbolic` types to `mutable` due to Julia finalizer
bowenszhu 7e93ca4
Define hash extension function for incorporating symtype
bowenszhu 9be3d03
Hash consing for `Sym`
bowenszhu 93c2837
Merge remote-tracking branch 'origin/master' into hash-consing
bowenszhu f1a9a93
Test hash consing for `Sym` with different symtypes
bowenszhu 70de918
Feat: Incorporate `metadata` into `BasicSymbolic` hash computation
bowenszhu 2dac2a3
Apply hash consing also when there is metadata
bowenszhu c2d85c3
Create flyweight factory for `BasicSymbolic`
bowenszhu 8957290
Add `isequal2` function for checking metadata comparison
bowenszhu 2779856
Handle hash collision with customized `isequal2`
bowenszhu d36198f
Call outer constructor for `Sym` in `ConstructionBase.setproperties`
bowenszhu cf937b0
Test hash consing for `Sym` with metadata
bowenszhu 765293a
Add docstring for the flyweight factory function
bowenszhu 84a0596
Add docstring for `hash2`
bowenszhu 187ce45
Add comment explaining why calling outer constructor in `setproperties`
bowenszhu 55ca2ec
Refactor: Make `wvd` a constant global
bowenszhu 13b642b
Rename the `isequal2` function to `isequal_with_metadata` for clarity.
bowenszhu 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 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
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,26 @@ | ||
| using SymbolicUtils, Test | ||
|
|
||
| struct Ctx1 end | ||
| struct Ctx2 end | ||
|
|
||
| @testset "Sym" begin | ||
| x1 = only(@syms x) | ||
| x2 = only(@syms x) | ||
| @test x1 === x2 | ||
| x3 = only(@syms x::Float64) | ||
| @test x1 !== x3 | ||
| x4 = only(@syms x::Float64) | ||
| @test x1 !== x4 | ||
| @test x3 === x4 | ||
| x5 = only(@syms x::Int) | ||
| x6 = only(@syms x::Int) | ||
| @test x1 !== x5 | ||
| @test x3 !== x5 | ||
| @test x5 === x6 | ||
|
|
||
| xm1 = setmetadata(x1, Ctx1, "meta_1") | ||
| xm2 = setmetadata(x1, Ctx1, "meta_1") | ||
| @test xm1 === xm2 | ||
| xm3 = setmetadata(x1, Ctx2, "meta_2") | ||
| @test xm1 !== xm3 | ||
| 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
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.