create_functions.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 from function import *
4 
5 def save(arg):
6  if type(arg) is str:
7  print arg
8  def wrapper(func):
9  func.__name__ = arg
10  func.save(func.get_name())
11  return func
12  return wrapper
13  else:
14  func = arg
15  func.save(func.get_name())
16  return func
17 
18 
19 
20 SIGNED = [ "int64",
21  "uint64",
22  "uint32",
23  "int32",
24  "uint",
25  "ulong",
26  "int",
27  "long",
28  "float",
29  "float32",
30  "float64" ]
31 
32 SIGNED_ARRAY = ["int64[]",
33  "uint64[]",
34  "uint32[]",
35  "int32[]",
36  "uint[]",
37  "ulong[]",
38  "int[]",
39  "long[]",
40  "float[]",
41  "float32[]",
42  "float64[]" ]
43 
44 
45 UNSIGNED = [
46  "int64",
47  "int32",
48  "int",
49  "long",
50  "float",
51  "float32",
52  "float64" ]
53 
54 UNSIGNED_ARRAY = ["int64[]",
55  "int32[]",
56  "int[]",
57  "long[]",
58  "float[]",
59  "float32[]",
60  "float64[]" ]
61 
62 
63 CALLABLE = ["function", "builtin_function_or_method", "builtin_function", "type"]
64 
65 
66 
67 @save
68 @accept('duration', [], [['Time','time'], 'duration'], 'duration', [])
69 @accept([['Time','time'], 'duration'], 'duration', [])
70 @accept('duration', [], [['Time','time'], 'duration'])
71 @accept([SIGNED, SIGNED_ARRAY], [SIGNED, SIGNED_ARRAY], [])
72 @Resolver
73 def ADD(*nums):
74  sum_all = None
75  for num in nums:
76  if sum_all != None:
77  sum_all = sum_all + num
78  else:
79  sum_all = num
80 
81  return sum_all
82 
83 @save
84 @accept([SIGNED, SIGNED_ARRAY], [SIGNED, SIGNED_ARRAY], [])
85 @Resolver
86 def MULT(*nums):
87  mult_all = None
88  for num in nums:
89  if mult_all != None:
90  mult_all = mult_all * num
91  else:
92  mult_all = num
93 
94  return mult_all
95 
96 @save
97 @accept(['Time','time'], ['Time','time'], [])
98 @accept([SIGNED, SIGNED_ARRAY], [SIGNED, SIGNED_ARRAY])
99 @Resolver
100 def SUB(a, b):
101  return a-b
102 
103 
104 @save
105 @accept([UNSIGNED, UNSIGNED_ARRAY])
106 @Resolver
107 def NEG(x):
108  return -x
109 
110 
111 @save
112 @accept([CALLABLE])
113 @accept([CALLABLE], "*", [])
114 @Resolver
115 def CALL(func, *args, **kwargs):
116 
117  def CALL(func, *args, **kwargs):
118  print "calling {0} with {1} and {2}".format(func, args, kwargs)
119 
120  if len(args)>0 and type(args[0]).__name__ in ["function", "builtin_function_or_method", "builtin_function", "type"]:
121  args = CALL(args[0], *args[1:], **kwargs)
122  if type(args) is not tuple:
123  args = [args]
124  return func(*args, **kwargs)
125 
126  return CALL(func, *args, **kwargs)
127 
128 
129 @save
130 @accept([SIGNED, SIGNED_ARRAY], [])
131 @Resolver
132 def MEAN(*nums):
133  if len(nums)==1:
134  nums = nums[0]
135 
136  sum_all = None
137  for num in nums:
138  if sum_all != None:
139  sum_all = sum_all + num
140  else:
141  sum_all = num
142 
143  return sum_all/len(nums)
144 
145 
146 @save
147 @accept([SIGNED, SIGNED_ARRAY])
148 @Resolver
149 def ABS(x):
150  return abs(x)
151 
152 @save
153 @accept([SIGNED, SIGNED_ARRAY])
154 @Resolver
155 def SUM(x):
156  return sum(x)
157 
158 
def accept(args)
Definition: function.py:107
def CALL(func, args, kwargs)


dyn_tune
Author(s):
autogenerated on Mon Jun 10 2019 13:03:17