diff --git a/examples/demo_tdx.py b/examples/demo_tdx.py index dc2135c..12b9dea 100644 --- a/examples/demo_tdx.py +++ b/examples/demo_tdx.py @@ -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('计算结束') diff --git a/expr_codegen/_version.py b/expr_codegen/_version.py index 1f4c4d4..17c1a62 100644 --- a/expr_codegen/_version.py +++ b/expr_codegen/_version.py @@ -1 +1 @@ -__version__ = "0.10.1" +__version__ = "0.10.2" diff --git a/expr_codegen/codes.py b/expr_codegen/codes.py index 18d2f6d..8017106 100644 --- a/expr_codegen/codes.py +++ b/expr_codegen/codes.py @@ -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 @@ -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_ diff --git a/expr_codegen/expr.py b/expr_codegen/expr.py index c8e1266..1a75f67 100644 --- a/expr_codegen/expr.py +++ b/expr_codegen/expr.py @@ -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 # 预定义前缀,算子用前缀进行区分更方便。 # 当然也可以用是否在某容器中进行分类 @@ -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 diff --git a/expr_codegen/tool.py b/expr_codegen/tool.py index 91091b1..24fc467 100644 --- a/expr_codegen/tool.py +++ b/expr_codegen/tool.py @@ -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