Updated math_commands
function that allows to use math functions in eval
@@ -6,7 +6,6 @@ import os
from subprocess import Popen, PIPE
import io
import numpy as np
-import math
from collections import OrderedDict
from madminer import __version__
@@ -144,16 +143,17 @@ def load_and_check(filename, warning_threshold=1.e9):
return data
def math_commands():
- """ Provides OrderedDict() with math commands - for some reason I need this when using eval """
-
- math_commands_collection = OrderedDict()
- math_commands_collection['exp']=math.exp
- math_commands_collection['sin']=math.sin
- math_commands_collection['cos']=math.cos
- math_commands_collection['tan']=math.tan
- math_commands_collection['acos']=math.acos
- math_commands_collection['asin']=math.asin
- math_commands_collection['atan']=math.atan
-
- return math_commands_collection
+ """ Provides list with math commands - we need this when using eval """
+
+ from math import acos, asin, atan, atan2, ceil, cos, cosh, exp, floor, log, pi, pow, sin, sinh, sqrt, tan, tanh
+
+ functions = ['acos', 'asin', 'atan', 'atan2', 'ceil', 'cos',
+ 'cosh', 'exp', 'floor', 'log', 'pi', 'pow', 'sin', 'sinh', 'sqrt',
+ 'tan', 'tanh']
+
+ mathdefinitions = {}
+ for function in functions:
+ mathdefinitions[function] = locals().get(function, None)
+
+ return mathdefinitions
