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
Make count_ops() work with logic operations by creating a binary tree. #7303
Changes from 1 commit
cefd428
5389065
7000d9e
3c5ba38
07168de
25a9686
d5abbd7
366f864
00604b1
d374ed5
d277512
dc6cf28
ee126ac
b49c02c
2f7d1de
e1c8ea4
7adde66
cc74cd8
80fd37a
912c0fd
9549f0b
37ba49b
4fbde7b
9771a86
5d3950d
189c659
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2323,6 +2323,18 @@ def count_ops(expr, visual=False): | |
ops = [count_ops(i, visual=visual) for i in expr] | ||
elif not isinstance(expr, Basic): | ||
ops = [] | ||
elif expr.is_Boolean: | ||
ops = [] | ||
args = [expr] | ||
while args: | ||
a = args.pop() | ||
o = C.Symbol(a.func.__name__.upper()) | ||
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. I may not wonder if 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. Its for the condition when two or more args of the |
||
ops.append(o*(len(a.args)-1)) | ||
args_len = len(a.args) | ||
aargs = list(a.args) | ||
for i in range(args_len): | ||
if aargs[i].is_Boolean: | ||
args.append(aargs[i]) | ||
else: # it's Basic not isinstance(expr, Expr): | ||
if not isinstance(expr, Basic): | ||
raise TypeError("Invalid type of expr") | ||
|
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.
Why not just do this in the else block.
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 think it should be. should i?