|
2 | 2 | # functions that can be diretcly applied over an array |
3 | 3 | functionspace = { |
4 | 4 | # directly build functions without dependencies |
5 | | - "elmcount": ("len(%(0)s)", None), |
| 5 | + "elmcount": ("len(%(0)s)", ()), |
6 | 6 |
|
7 | 7 | # directly build numpy based functions |
8 | | - "pi": ("np.pi", ("numpy",)), |
9 | | - "abs": ("np.abs(%(0)s)", ("numpy",)), |
10 | | - "power": ("np.power(%(0)s,%(1)s)", ("numpy",)), |
11 | | - "min": ("np.minimum(%(0)s, %(1)s)", ("numpy",)), |
12 | | - "max": ("np.maximum(%(0)s, %(1)s)", ("numpy",)), |
13 | | - "exp": ("np.exp(%(0)s)", ("numpy",)), |
14 | | - "sin": ("np.sin(%(0)s)", ("numpy",)), |
15 | | - "cos": ("np.cos(%(0)s)", ("numpy",)), |
16 | | - "tan": ("np.tan(%(0)s)", ("numpy",)), |
17 | | - "arcsin": ("np.arcsin(%(0)s)", ("numpy",)), |
18 | | - "arccos": ("np.arccos(%(0)s)", ("numpy",)), |
19 | | - "arctan": ("np.arctan(%(0)s)", ("numpy",)), |
20 | | - "sinh": ("np.sinh(%(0)s)", ("numpy",)), |
21 | | - "cosh": ("np.cosh(%(0)s)", ("numpy",)), |
22 | | - "tanh": ("np.tanh(%(0)s)", ("numpy",)), |
23 | | - "sqrt": ("np.sqrt(%(0)s)", ("numpy",)), |
24 | | - "ln": ("np.log(%(0)s)", ("numpy",)), |
25 | | - "log": ("(np.log(%(0)s)/np.log(%(1)s))", ("numpy",)), |
26 | | - # NUMPY: "invert_matrix": ("np.linalg.inv(%(0)s)", ("numpy",)), |
| 8 | + "pi": ("np.pi", (("numpy",),)), |
| 9 | + "abs": ("np.abs(%(0)s)", (("numpy",),)), |
| 10 | + "power": ("np.power(%(0)s,%(1)s)", (("numpy",),)), |
| 11 | + "min": ("np.minimum(%(0)s, %(1)s)", (("numpy",),)), |
| 12 | + "max": ("np.maximum(%(0)s, %(1)s)", (("numpy",),)), |
| 13 | + "exp": ("np.exp(%(0)s)", (("numpy",),)), |
| 14 | + "sin": ("np.sin(%(0)s)", (("numpy",),)), |
| 15 | + "cos": ("np.cos(%(0)s)", (("numpy",),)), |
| 16 | + "tan": ("np.tan(%(0)s)", (("numpy",),)), |
| 17 | + "arcsin": ("np.arcsin(%(0)s)", (("numpy",),)), |
| 18 | + "arccos": ("np.arccos(%(0)s)", (("numpy",),)), |
| 19 | + "arctan": ("np.arctan(%(0)s)", (("numpy",),)), |
| 20 | + "sinh": ("np.sinh(%(0)s)", (("numpy",),)), |
| 21 | + "cosh": ("np.cosh(%(0)s)", (("numpy",),)), |
| 22 | + "tanh": ("np.tanh(%(0)s)", (("numpy",),)), |
| 23 | + "sqrt": ("np.sqrt(%(0)s)", (("numpy",),)), |
| 24 | + "ln": ("np.log(%(0)s)", (("numpy",),)), |
| 25 | + "log": ("(np.log(%(0)s)/np.log(%(1)s))", (("numpy",),)), |
| 26 | + # NUMPY: "invert_matrix": ("np.linalg.inv(%(0)s)", (("numpy",),)), |
27 | 27 |
|
28 | 28 | # vector functions with axis to apply over |
29 | 29 | # NUMPY: |
30 | | - # "prod": "np.prod(%(0)s, axis=%(axis)s)", ("numpy",)), |
31 | | - # "sum": "np.sum(%(0)s, axis=%(axis)s)", ("numpy",)), |
32 | | - # "vmax": "np.max(%(0)s, axis=%(axis)s)", ("numpy", )), |
33 | | - # "vmin": "np.min(%(0)s, axis=%(axis)s)", ("numpy",)) |
34 | | - "prod": ("prod(%(0)s, dim=%(axis)s)", ("functions", "prod")), |
35 | | - "sum": ("sum(%(0)s, dim=%(axis)s)", ("functions", "sum")), |
36 | | - "vmax": ("vmax(%(0)s, dim=%(axis)s)", ("functions", "vmax")), |
37 | | - "vmin": ("vmin(%(0)s, dim=%(axis)s)", ("functions", "vmin")), |
38 | | - "vmax_xmile": ("vmax(%(0)s)", ("functions", "vmax")), |
39 | | - "vmin_xmile": ("vmin(%(0)s)", ("functions", "vmin")), |
| 30 | + # "prod": "np.prod(%(0)s, axis=%(axis)s)", (("numpy",),)), |
| 31 | + # "sum": "np.sum(%(0)s, axis=%(axis)s)", (("numpy",),)), |
| 32 | + # "vmax": "np.max(%(0)s, axis=%(axis)s)", ("numpy",),)), |
| 33 | + # "vmin": "np.min(%(0)s, axis=%(axis)s)", (("numpy",),)) |
| 34 | + "prod": ("prod(%(0)s, dim=%(axis)s)", (("functions", "prod"),)), |
| 35 | + "sum": ("sum(%(0)s, dim=%(axis)s)", (("functions", "sum"),)), |
| 36 | + "vmax": ("vmax(%(0)s, dim=%(axis)s)", (("functions", "vmax"),)), |
| 37 | + "vmin": ("vmin(%(0)s, dim=%(axis)s)", (("functions", "vmin"),)), |
| 38 | + "vmax_xmile": ("vmax(%(0)s)", (("functions", "vmax"),)), |
| 39 | + "vmin_xmile": ("vmin(%(0)s)", (("functions", "vmin"),)), |
40 | 40 | "vector_select": ( |
41 | 41 | "vector_select(%(0)s, %(1)s, %(axis)s, %(2)s, %(3)s, %(4)s)", |
42 | | - ("functions", "vector_select") |
| 42 | + (("functions", "vector_select"),) |
43 | 43 | ), |
44 | 44 |
|
45 | 45 | # functions defined in pysd.py_bakcend.functions |
46 | 46 | "active_initial": ( |
47 | 47 | "active_initial(__data[\"time\"].stage, lambda: %(0)s, %(1)s)", |
48 | | - ("functions", "active_initial")), |
| 48 | + (("functions", "active_initial"),)), |
49 | 49 | "if_then_else": ( |
50 | 50 | "if_then_else(%(0)s, lambda: %(1)s, lambda: %(2)s)", |
51 | | - ("functions", "if_then_else")), |
| 51 | + (("functions", "if_then_else"),)), |
52 | 52 | "integer": ( |
53 | 53 | "integer(%(0)s)", |
54 | | - ("functions", "integer")), |
| 54 | + (("functions", "integer"),)), |
55 | 55 | "invert_matrix": ( # NUMPY: remove |
56 | 56 | "invert_matrix(%(0)s)", |
57 | | - ("functions", "invert_matrix")), # NUMPY: remove |
| 57 | + (("functions", "invert_matrix"),)), # NUMPY: remove |
58 | 58 | "modulo": ( |
59 | 59 | "modulo(%(0)s, %(1)s)", |
60 | | - ("functions", "modulo")), |
| 60 | + (("functions", "modulo"),)), |
61 | 61 | "pulse": ( |
62 | 62 | "pulse(__data['time'], %(0)s, width=%(1)s)", |
63 | | - ("functions", "pulse")), |
| 63 | + (("functions", "pulse"),)), |
64 | 64 | "Xpulse": ( |
65 | 65 | "pulse(__data['time'], %(0)s, magnitude=%(1)s)", |
66 | | - ("functions", "pulse")), |
| 66 | + (("functions", "pulse"),)), |
67 | 67 | "pulse_train": ( |
68 | 68 | "pulse(__data['time'], %(0)s, repeat_time=%(1)s, width=%(2)s, "\ |
69 | 69 | "end=%(3)s)", |
70 | | - ("functions", "pulse")), |
| 70 | + (("functions", "pulse"),)), |
71 | 71 | "Xpulse_train": ( |
72 | 72 | "pulse(__data['time'], %(0)s, repeat_time=%(1)s, magnitude=%(2)s)", |
73 | | - ("functions", "pulse")), |
| 73 | + (("functions", "pulse"),)), |
74 | 74 | "get_time_value": ( |
75 | 75 | "get_time_value(__data['time'], %(0)s, %(1)s, %(2)s)", |
76 | | - ("functions", "get_time_value")), |
| 76 | + (("functions", "get_time_value"),)), |
77 | 77 | "quantum": ( |
78 | 78 | "quantum(%(0)s, %(1)s)", |
79 | | - ("functions", "quantum")), |
| 79 | + (("functions", "quantum"),)), |
80 | 80 | "Xramp": ( |
81 | 81 | "ramp(__data['time'], %(0)s, %(1)s)", |
82 | | - ("functions", "ramp")), |
| 82 | + (("functions", "ramp"),)), |
83 | 83 | "ramp": ( |
84 | 84 | "ramp(__data['time'], %(0)s, %(1)s, %(2)s)", |
85 | | - ("functions", "ramp")), |
| 85 | + (("functions", "ramp"),)), |
86 | 86 | "step": ( |
87 | 87 | "step(__data['time'], %(0)s, %(1)s)", |
88 | | - ("functions", "step")), |
| 88 | + (("functions", "step"),)), |
89 | 89 | "xidz": ( |
90 | 90 | "xidz(%(0)s, %(1)s, %(2)s)", |
91 | | - ("functions", "xidz")), |
| 91 | + (("functions", "xidz"),)), |
92 | 92 | "zidz": ( |
93 | 93 | "zidz(%(0)s, %(1)s)", |
94 | | - ("functions", "zidz")), |
| 94 | + (("functions", "zidz"),)), |
95 | 95 | "vector_sort_order": ( |
96 | 96 | "vector_sort_order(%(0)s, %(1)s)", |
97 | | - ("functions", "vector_sort_order")), |
| 97 | + (("functions", "vector_sort_order"),)), |
98 | 98 | "vector_reorder": ( |
99 | 99 | "vector_reorder(%(0)s, %(1)s)", |
100 | | - ("functions", "vector_reorder")), |
| 100 | + (("functions", "vector_reorder"),)), |
101 | 101 | "vector_rank": ( |
102 | 102 | "vector_rank(%(0)s, %(1)s)", |
103 | | - ("functions", "vector_rank")), |
| 103 | + (("functions", "vector_rank"),)), |
104 | 104 |
|
105 | 105 | # random functions must have the shape of the component subscripts |
106 | 106 | # most of them are shifted, scaled and truncated |
107 | | - # TODO: it is difficult to find same parametrization in Python, |
108 | | - # maybe build a new model |
109 | 107 | "random_0_1": ( |
110 | 108 | "np.random.uniform(0, 1, size=%(size)s)", |
111 | | - ("numpy",)), |
| 109 | + (("numpy",),)), |
112 | 110 | "random_uniform": ( |
113 | 111 | "np.random.uniform(%(0)s, %(1)s, size=%(size)s)", |
114 | | - ("numpy",)), |
| 112 | + (("numpy",),)), |
115 | 113 | "random_normal": ( |
116 | | - "stats.truncnorm.rvs(%(0)s, %(1)s, loc=%(2)s, scale=%(3)s," |
117 | | - " size=%(size)s)", |
118 | | - ("scipy", "stats")), |
| 114 | + "stats.truncnorm.rvs((%(0)s-%(2)s)/%(3)s, (%(1)s-%(2)s)/%(3)s," |
| 115 | + " loc=%(2)s, scale=%(3)s, size=%(size)s)", |
| 116 | + (("scipy", "stats"),)), |
| 117 | + "random_exponential": ( |
| 118 | + "stats.truncexpon.rvs((%(1)s-np.maximum(%(0)s, %(2)s))/%(3)s," |
| 119 | + " loc=np.maximum(%(0)s, %(2)s), scale=%(3)s, size=%(size)s)", |
| 120 | + (("scipy", "stats"), ("numpy",),)), |
119 | 121 | } |
0 commit comments