Evaluate expression and return an array.
(ex, out=None, local_dict=None, global_dict=None, **kwargs)
| 80 | |
| 81 | |
| 82 | def evaluate(ex, out=None, local_dict=None, global_dict=None, **kwargs): |
| 83 | """Evaluate expression and return an array.""" |
| 84 | |
| 85 | # First, get the signature for the arrays in expression |
| 86 | context = ne.necompiler.getContext(kwargs) |
| 87 | names, _ = ne.necompiler.getExprNames(ex, context) |
| 88 | |
| 89 | # Get the arguments based on the names. |
| 90 | call_frame = sys._getframe(1) |
| 91 | if local_dict is None: |
| 92 | local_dict = call_frame.f_locals |
| 93 | if global_dict is None: |
| 94 | global_dict = call_frame.f_globals |
| 95 | arguments = [] |
| 96 | types = [] |
| 97 | for name in names: |
| 98 | try: |
| 99 | a = local_dict[name] |
| 100 | except KeyError: |
| 101 | a = global_dict[name] |
| 102 | arguments.append(a) |
| 103 | if hasattr(a, "atom"): |
| 104 | types.append(a.atom) |
| 105 | else: |
| 106 | types.append(a) |
| 107 | |
| 108 | # Create a signature |
| 109 | signature = [ |
| 110 | (name, ne.necompiler.getType(type_)) |
| 111 | for (name, type_) in zip(names, types) |
| 112 | ] |
| 113 | print("signature-->", signature) |
| 114 | |
| 115 | # Compile the expression |
| 116 | compiled_ex = ne.necompiler.NumExpr(ex, signature, **kwargs) |
| 117 | print("fullsig-->", compiled_ex.fullsig) |
| 118 | |
| 119 | _compute(out, compiled_ex, arguments) |
| 120 | |
| 121 | return |
| 122 | |
| 123 | |
| 124 | if __name__ == "__main__": |
no test coverage detected