-
Notifications
You must be signed in to change notification settings - Fork 4
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
Refactoring Expressions #43
Refactoring Expressions #43
Conversation
@@ -289,14 +347,22 @@ def basic_add_operation(type_) -> BasicAbelianOperation: | |||
return BasicAbelianOperation(operator.add, BasicConstant(0, type_), operator.neg) | |||
|
|||
|
|||
def BasicSummation(type_: type, index: Variable, constraint: Context, body: Expression) -> BasicQuantifierExpression: | |||
def basic_summation( |
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.
Renamed this and BasicIntegral
to follow the python convention of naming functions
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.
I reordered a lot of the functions to make the consistent throughout the file.
import neuralpp.symbolic.functions as functions | ||
|
||
|
||
class AmbiguousTypeError(TypeError, ValueError): |
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.
I moved all the error classes to a new folder. I realized that these files are hard to read because of how many things there are in the files.
super().__init__(f"{python_callable} is ambiguous.") | ||
|
||
|
||
def boolean_function_of_arity(arity: int) -> Callable: |
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.
I moved these extra functions that do not depend on Expression
to the util folder. I had to remove a function from that folder due to circular dependency.
@@ -50,6 +50,21 @@ def _symbolically_eliminate(operation: AbelianOperation, index: Variable, interv | |||
return None | |||
|
|||
|
|||
def _map_leaves_of_if_then_else(conditional_intervals: Expression, |
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.
Moved this from utils
due to circular dependency
@@ -181,6 +181,8 @@ def from_constraint(index: Variable, constraint: Context, context: Context, is_i | |||
For example, x > 0 and x <= 5 should return an interval [1, 5] | |||
More complicated cases will be added later | |||
""" | |||
if profiler is None: | |||
profiler = Profiler() |
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.
Added this for the interval test to pass
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.
Thanks, Winnie, it's great you did this!
Main Files Changed
In the
symbolic
folderexpression.py
basic_expression.py
sympy_expression.py
z3_expression.py
In the
util
foldercallable_util.py
symbolic_error_util.py
sympy_util.py
=> Xiang already had this andz3_util
z3_util.py
Linting
I downloaded
black
to lint the file (pip install black
) =>black file_name --fast
. I'm linting now, so the files are cleaner to read and to make it easier for us to switch to fbcode. I think this is the linter that phabriactor is based off.Organization
I moved all the extraneous files into a
util
file. I created 2 util files (symbolic_error_util
andcallable_util
)callable_util
sympy_util
symbolic_error_util
I made sure all of the import functions are used => removed any that are unused
I ordered the functions and classes the same along files.
Code
There is no new code!
Tests
I commented out a test in
normalizer_test
because it is failing in the main branchReviewing
I think it'll be easier to review this PR with the raw file, rather than going through the GitHub interface
Next Steps