Skip to content

Commit

Permalink
缓解布尔运算化简反而变复炸的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
wukan1986 committed Nov 26, 2024
1 parent 82bbdc7 commit 75baad4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/demo_tdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def _code_block_2():
# =====================================
logger.info('计算开始')
t1 = time.perf_counter()
df = codegen_exec(df, _code_block_1, _code_block_2)
df = codegen_exec(df, _code_block_1, _code_block_2, output_file=sys.stdout)
t2 = time.perf_counter()
print(t2 - t1)
logger.info('计算结束')
Expand Down
2 changes: 1 addition & 1 deletion expr_codegen/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.10.1"
__version__ = "0.10.2"
4 changes: 3 additions & 1 deletion expr_codegen/codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
from ast import expr

from sympy import Add, Mul, Pow, Eq
from sympy import Add, Mul, Pow, Eq, Not, Xor

from expr_codegen.expr import register_symbols, dict_to_exprs

Expand Down Expand Up @@ -372,6 +372,8 @@ def _add_default_type(globals_):
globals_['Mul'] = Mul
globals_['Pow'] = Pow
globals_['Eq'] = Eq
globals_['Not'] = Not
globals_['Xor'] = Xor
return globals_


Expand Down
5 changes: 4 additions & 1 deletion expr_codegen/expr.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from functools import reduce

from sympy import Mul, preorder_traversal, symbols, Function, simplify, Add, Basic, Symbol, sympify
from sympy import Mul, preorder_traversal, symbols, Function, simplify, Add, Basic, Symbol, sympify, FunctionClass

# 预定义前缀,算子用前缀进行区分更方便。
# 当然也可以用是否在某容器中进行分类
Expand All @@ -23,6 +23,9 @@ def is_symbol(x, globals_):
if type(s) is type:
# Eq
return issubclass(s, Basic)
if isinstance(s, FunctionClass):
# Not
return True
return False


Expand Down
7 changes: 4 additions & 3 deletions expr_codegen/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,12 @@ def reduce(self, repl, redu):

exprs_dict = {}

# 不做改动,直接生成
# cse前简化一次,cse后不再简化
# (~开盘涨停 & 昨收涨停) | (~收盘涨停 & 最高涨停)
for variable, expr in repl:
exprs_dict[variable] = simplify2(expr)
exprs_dict[variable] = expr
for variable, expr in redu:
exprs_dict[variable] = simplify2(expr)
exprs_dict[variable] = expr

return exprs_dict

Expand Down

0 comments on commit 75baad4

Please sign in to comment.