Coverage for skema/gromet/execution_engine/types/binary.py: 88%
195 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-30 17:15 +0000
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-30 17:15 +0000
1from typing import Union, Any
3from skema.gromet.execution_engine.types.defined_types import Field
6class Add(object):
7 source_language_name = {"Python": "Add", "GCC": "plus_expr", "CAST": "Add"}
8 inputs = [Field("augend", "Number"), Field("addend", "Number")]
9 outputs = [Field("sum", "Number")]
10 shorthand = "+"
11 documentation = "Add is the numerical addition operator. For a general addition operation (For example, the case of concatanation with +) see GenAdd."
13 @staticmethod # TODO: Look into if this is required. Only need @staticmethod if you intend to call the method from an instance of class
14 def exec(
15 augend: Union[int, float, complex], addend: Union[int, float, complex]
16 ) -> Union[int, float, complex]:
17 return augend + addend
20class GenAdd(object):
21 source_language_name = {"Python": "Add"}
22 inputs = [Field("operand1", "Any"), Field("operand2", "Any")]
23 outputs = [Field("result", "Any")]
24 shorthand = "g+"
25 documentation = ""
27 def exec(operand1: Any, operand2: Any) -> Any:
28 return operand1 + operand2
31class Sub(object):
32 source_language_name = {
33 "Python": "Sub",
34 "GCC": "minus_expr",
35 "CAST": "Sub",
36 }
37 inputs = [Field("minuend", "Number"), Field("subtrahend", "Number")]
38 outputs = [Field("difference", "Number")]
39 shorthand = "-"
40 documentation = "Sub is the numerical subtraction operator. For a general subtraction operation () see GenSub."
42 def exec(
43 minuend: Union[int, float, complex],
44 subtahend: Union[int, float, complex],
45 ) -> Union[int, float, complex]:
46 return minuend - subtahend
49class GenSub(object):
50 source_language_name = {"Python": "Sub"}
51 inputs = [Field("operand1", "Any"), Field("operand2", "Any")]
52 outputs = [Field("result", "Any")]
53 shorthand = "g-"
54 documentation = ""
56 def exec(operand1: Any, operand2: Any) -> Any:
57 return operand1 - operand2
60class Mult(object):
61 source_language_name = {
62 "Python": "Mult",
63 "GCC": "mult_expr",
64 "CAST": "Mult",
65 }
66 inputs = [Field("multiplier", "Number"), Field("multiplicand", "Number")]
67 outputs = [Field("product", "Number")]
68 shorthand = "*"
69 documentation = ""
71 def exec(
72 multiplier: Union[int, float, complex],
73 multiplicand: Union[int, float, complex],
74 ) -> Union[int, float, complex]:
75 return multiplier * multiplicand
78# TODO: Do we need a general operator for all overloadable operators in Python (https://www.programiz.com/python-programming/operator-overloading)?
81class Div(object):
82 source_language_name = {"Python": "Div", "GCC": "rdiv_expr", "CAST": "Div"}
83 inputs = [Field("dividend", "Number"), Field("divisor", "Number")]
84 outputs = [Field("quotient", "Number")]
85 shorthand = "/"
86 documentation = ""
88 def exec(
89 dividend: Union[int, float, complex],
90 divisor: Union[int, float, complex],
91 ) -> Union[int, float, complex]:
92 return dividend / divisor
95class FloorDiv(object):
96 source_language_name = {"Python": "FloorDiv", "CAST": "FloorDiv"}
97 inputs = [Field("dividend", "Number"), Field("divisor", "Number")]
98 outputs = [Field("quotient", "Number")]
99 shorthand = "//"
100 documentation = ""
102 def exec(
103 dividend: Union[int, float, complex],
104 divisor: Union[int, float, complex],
105 ) -> Union[int, float, complex]:
106 return dividend // divisor
109class Mod(object):
110 source_language_name = {
111 "Python": "Mod",
112 "GCC": "trunc_mod_expr",
113 "CAST": "Mod",
114 }
115 inputs = [Field("dividend", "Number"), Field("divisor", "Number")]
116 outputs = [Field("remainder", "Number")]
117 shorthand = "%"
118 documentation = ""
120 def exec(
121 dividend: Union[int, float, complex],
122 divisor: Union[int, float, complex],
123 ) -> Union[int, float, complex]:
124 return dividend % divisor
127class Pow(object):
128 source_language_name = {"Python": "Pow", "CAST": "Pow"}
129 inputs = [Field("base", "Number"), Field("exponent", "Number")]
130 outputs = [Field("power", "Number")]
131 shorthand = "**"
132 documentation = ""
134 def exec(
135 base: Union[int, float, complex], power: Union[int, float, complex]
136 ) -> Union[int, float, complex]:
137 return base**power
140class LShift(object):
141 source_language_name = {
142 "Python": "LShift",
143 "GCC": "lshift_expr",
144 "CAST": "LShift",
145 }
146 inputs = [Field("operand1", "Number"), Field("operand2", "Number")]
147 outputs = [Field("result", "Number")]
148 shorthand = "<<"
149 documentation = ""
151 def exec(
152 operand1: Union[int, float, complex],
153 operand2: Union[int, float, complex],
154 ) -> Union[int, float, complex]:
155 return operand1 << operand2
158class RShift(object):
159 source_language_name = {
160 "Python": "RShift",
161 "GCC": "rshift_expr",
162 "CAST": "RShift",
163 }
164 inputs = [Field("operand1", "Number"), Field("operand2", "Number")]
165 outputs = [Field("result", "Number")]
166 shorthand = ">>"
167 documentation = ""
169 def exec(
170 operand1: Union[int, float, complex],
171 operand2: Union[int, float, complex],
172 ) -> Union[int, float, complex]:
173 return operand1 >> operand2
176class BitOr(object):
177 source_language_name = {
178 "Python": "BitOr",
179 "GCC": "bit_ior_expr",
180 "CAST": "BitOr",
181 }
182 inputs = [Field("binary1", "Number"), Field("binary2", "Number")]
183 outputs = [Field("result", "Number")]
184 shorthand = "|"
185 documentation = ""
187 def exec(
188 binary1: Union[int, float, complex],
189 binary2: Union[int, float, complex],
190 ) -> Union[int, float, complex]:
191 return binary1 | binary2
194class BitXor(object):
195 source_language_name = {
196 "Python": "BitXor",
197 "GCC": "bit_xor_expr",
198 "CAST": "BitXor",
199 }
200 inputs = [Field("binary1", "Number"), Field("binary2", "Number")]
201 outputs = [Field("result", "Number")]
202 shorthand = "^"
203 documentation = ""
205 def exec(
206 binary1: Union[int, float, complex],
207 binary2: Union[int, float, complex],
208 ) -> Union[int, float, complex]:
209 return binary1 ^ binary2
212class BitAnd(object):
213 source_language_name = {
214 "Python": "BitAnd",
215 "GCC": "bit_and_expr",
216 "CAST": "BitAnd",
217 }
218 inputs = [Field("binary1", "Number"), Field("binary2", "Number")]
219 outputs = [Field("result", "Number")]
220 shorthand = "&"
221 documentation = ""
223 def exec(
224 binary1: Union[int, float, complex],
225 binary2: Union[int, float, complex],
226 ) -> Union[int, float, complex]:
227 return binary1 & binary2
230class And(object):
231 source_language_name = {
232 "Python": "And",
233 "GCC": "logical_and",
234 "CAST": "And",
235 }
236 inputs = [Field("logical1", "Boolean"), Field("logical2", "Boolean")]
237 outputs = [Field("result", "Boolean")]
238 shorthand = "and"
239 documentation = ""
241 def exec(logical1: bool, logical2: bool) -> bool:
242 return logical1 and logical2
245class Or(object):
246 source_language_name = {"Python": "Or", "GCC": "logical_or", "CAST": "Or"}
247 inputs = [Field("logical1", "Boolean"), Field("logical2", "Boolean")]
248 outputs = [Field("result", "Boolean")]
249 shorthand = "or"
250 documentation = ""
252 def exec(logical1: bool, logical2: bool) -> bool:
253 return logical1 or logical2
256class Eq(object):
257 source_language_name = {"Python": "Eq", "GCC": "eq_expr", "CAST": "Eq"}
258 inputs = [Field("operand1", "Any"), Field("operand2", "Any")]
259 outputs = [Field("result", "Boolean")]
260 shorthand = "=="
261 documentation = ""
263 def exec(operand1: Any, operand2: Any) -> bool:
264 return operand1 == operand2
267class NotEq(object):
268 source_language_name = {
269 "Python": "NotEq",
270 "GCC": "ne_expr",
271 "CAST": "NotEq",
272 }
273 inputs = [Field("operand1", "Any"), Field("operand2", "Any")]
274 outputs = [Field("result", "Boolean")]
275 shorthand = "!="
276 documentation = ""
278 def exec(operand1: Any, operand2: Any) -> bool:
279 return operand1 != operand2
282class Lt(object):
283 source_language_name = {"Python": "Lt", "GCC": "lt_expr", "CAST": "Lt"}
284 inputs = [Field("number1", "Number"), Field("number2", "Number")]
285 outputs = [Field("result", "Boolean")]
286 shorthand = "<"
287 documentation = ""
289 def exec(
290 number1: Union[int, float, complex],
291 number2: Union[int, float, complex],
292 ) -> bool:
293 return number1 < number2
296class Lte(object):
297 source_language_name = {
298 "Python": "Lte",
299 "GCC": "le_expr",
300 "CAST": "Lte",
301 } # TODO: Is it LtE or Lte for Python and CAST
302 inputs = [Field("number1", "Number"), Field("number2", "Number")]
303 outputs = [Field("result", "Boolean")]
304 shorthand = "<="
305 documentation = ""
307 def exec(
308 number1: Union[int, float, complex],
309 number2: Union[int, float, complex],
310 ) -> bool:
311 return number1 <= number2
314class Gt(object):
315 source_language_name = {"Python": "Gt", "GCC": "gt_expr", "CAST": "Gt"}
316 inputs = [Field("number1", "Number"), Field("number2", "Number")]
317 outputs = [Field("result", "Boolean")]
318 shorthand = ">"
319 documentation = ""
321 def exec(
322 number1: Union[int, float, complex],
323 number2: Union[int, float, complex],
324 ) -> bool:
325 return number1 > number2
328class Gte(object):
329 source_language_name = {"Python": "GtE", "GCC": "ge_expr", "CAST": "Gte"}
330 inputs = [Field("number1", "Number"), Field("number2", "Number")]
331 outputs = [Field("result", "Boolean")]
332 shorthand = ">="
333 documentation = ""
335 def exec(
336 number1: Union[int, float, complex],
337 number2: Union[int, float, complex],
338 ) -> bool:
339 return number1 >= number2
342class In(
343 object
344): # TODO: How should In and NotIn work? What is the difference between in, member, List_in?
345 source_language_name = {"Python": "In", "CAST": "In"}
346 inputs = [Field("container_input", "Any"), Field("value", "Any")]
347 outputs = [Field("result", "Boolean")]
348 shorthand = "in"
349 documentation = ""
351 def exec(container_input: Any, value: Any) -> bool:
352 return value in container_input
355class NotIn(
356 object
357): # TODO: How should In and NotIn work? What is the difference between in, member, List_in?
358 source_language_name = {"Python": "NotIn", "CAST": "NotIn"}
359 inputs = [Field("container_input", "Any"), Field("value", "Any")]
360 outputs = [Field("result", "Boolean")]
361 shorthand = "not in"
362 documentation = ""
364 def exec(container_input: Any, value: Any) -> bool:
365 return value not in container_input