def create_simple_if_with_two_outputs(condition_val): condition = ng.constant(condition_val, dtype=np.bool) # then_body X_t = ng.parameter([], np.float32, "X") Y_t = ng.parameter([], np.float32, "Y") Z_t = ng.parameter([], np.float32, "Z") add_t = ng.add(X_t, Y_t) mul_t = ng.multiply(Y_t, Z_t) then_body_res_1 = ng.result(add_t) then_body_res_2 = ng.result(mul_t) then_body = GraphBody([X_t, Y_t, Z_t], [then_body_res_1, then_body_res_2]) then_body_inputs = [ TensorIteratorInvariantInputDesc(1, 0), TensorIteratorInvariantInputDesc(2, 1), TensorIteratorInvariantInputDesc(3, 2) ] then_body_outputs = [ TensorIteratorBodyOutputDesc(0, 0), TensorIteratorBodyOutputDesc(1, 1) ] # else_body X_e = ng.parameter([], np.float32, "X") Z_e = ng.parameter([], np.float32, "Z") W_e = ng.parameter([], np.float32, "W") add_e = ng.add(X_e, W_e) pow_e = ng.power(W_e, Z_e) else_body_res_1 = ng.result(add_e) else_body_res_2 = ng.result(pow_e) else_body = GraphBody([X_e, Z_e, W_e], [else_body_res_1, else_body_res_2]) else_body_inputs = [ TensorIteratorInvariantInputDesc(1, 0), TensorIteratorInvariantInputDesc(3, 1), TensorIteratorInvariantInputDesc(4, 2) ] else_body_outputs = [ TensorIteratorBodyOutputDesc(0, 0), TensorIteratorBodyOutputDesc(1, 1) ] X = ng.constant(15.0, dtype=np.float32) Y = ng.constant(-5.0, dtype=np.float32) Z = ng.constant(4.0, dtype=np.float32) W = ng.constant(2.0, dtype=np.float32) if_node = ng.if_op(condition, [X, Y, Z, W], (then_body, else_body), (then_body_inputs, else_body_inputs), (then_body_outputs, else_body_outputs)) return if_node
def binary_op(op_str, a, b): if op_str == '+': return a + b elif op_str == 'Add': return ng.add(a, b) elif op_str == '-': return a - b elif op_str == 'Sub': return ng.subtract(a, b) elif op_str == '*': return a * b elif op_str == 'Mul': return ng.multiply(a, b) elif op_str == '/': return a / b elif op_str == 'Div': return ng.divide(a, b) elif op_str == 'Dot': return Dot(a, b) elif op_str == 'Equal': return ng.equal(a, b) elif op_str == 'Greater': return ng.greater(a, b) elif op_str == 'GreaterEq': return ng.greater_equal(a, b) elif op_str == 'Less': return ng.less(a, b) elif op_str == 'LessEq': return ng.less_equal(a, b) elif op_str == 'Maximum': return ng.maximum(a, b) elif op_str == 'Minimum': return ng.minimum(a, b) elif op_str == 'NotEqual': return ng.not_equal(a, b) elif op_str == 'Power': return ng.power(a, b)
def binary_op(op_str, a, b): if op_str == "+": return a + b elif op_str == "Add": return ng.add(a, b) elif op_str == "-": return a - b elif op_str == "Sub": return ng.subtract(a, b) elif op_str == "*": return a * b elif op_str == "Mul": return ng.multiply(a, b) elif op_str == "/": return a / b elif op_str == "Div": return ng.divide(a, b) elif op_str == "Equal": return ng.equal(a, b) elif op_str == "Greater": return ng.greater(a, b) elif op_str == "GreaterEq": return ng.greater_equal(a, b) elif op_str == "Less": return ng.less(a, b) elif op_str == "LessEq": return ng.less_equal(a, b) elif op_str == "Maximum": return ng.maximum(a, b) elif op_str == "Minimum": return ng.minimum(a, b) elif op_str == "NotEqual": return ng.not_equal(a, b) elif op_str == "Power": return ng.power(a, b)
def Pow(onnx_node, ng_inputs): # type: (NodeWrapper, List[NgraphNode]) -> NgraphNode """Perform element-wise binary power.""" base, exponent = broadcast_for_binary_operation(onnx_node, ng_inputs) return ng.power(base, exponent)