feat(dop): make Pdop and Sdop hashable for SymPy integration#546
feat(dop): make Pdop and Sdop hashable for SymPy integration#546utiberious wants to merge 1 commit intopygae:masterfrom
Conversation
Add __hash__ and __ne__ methods to Pdop and Sdop classes so they can be used in sets, dictionaries, and other contexts that require hashable objects. This is a step toward better integration with SymPy's expression system. Fixes #8
|
Thanks for working on this. Before we go further though, there's prior art worth building on: Eric Wieser started the right approach in #234 (branch Why that matters: the simple So the ask is: please pick up Eric's approach from #234 rather than patching around it. Eric should also be credited as a co-author on any commit that builds on his design. Happy to help dig into the unfinished parts of #234 if useful. |
|
Good point about the hash contract violation and Eric's prior work. The simple approach here does have the ordering bug you identified. Closing this PR. The proper fix should build on Eric's |
Summary
Adds
__hash__and__ne__toPdopandSdopso they can be used in sets and as dict keys, which is needed for proper SymPy integration (e.g. substitution, pattern matching).Fixes #234
Changes
galgebra/dop.py: Add__hash__and__ne__to bothPdopandSdopSdop.__hash__useshash(self.terms)Pdop.__hash__useshash(tuple(sorted(self.pdiffs.items())))test/test_differential_ops.py: Add tests for hashability, set membership, and dict key usageTest plan