def Gemm(onnx_node, ng_inputs): # type: (NodeWrapper, List[NgraphNode]) -> NgraphNode """Calculate general matrix multiplication Y = alpha * (A @ B) + beta * C. Support is currently limited to 2D matrices only. Higher dimensional tensors will be flattened to 2D before multiplication. """ input_a, input_b, input_c = ng_inputs alpha = onnx_node.get_attribute_value('alpha', 1) # Scalar multiplier for A @ B beta = onnx_node.get_attribute_value( 'beta', 1) # Scalar multiplier for input tensor C trans_a = onnx_node.get_attribute_value('transA', False) # Should A be transposed? trans_b = onnx_node.get_attribute_value('transB', False) # Should B be transposed? if trans_a: input_a = transpose(input_a) if trans_b: input_b = transpose(input_b) input_a, input_b = reshape_for_matmul(onnx_node, input_a, input_b) a_dot_b = ng.dot(input_a, input_b) if alpha != 1: a_dot_b = alpha * a_dot_b if beta != 1: input_c = beta * input_c _, input_c = numpy_style_broadcast_for_binary_operation( onnx_node, [a_dot_b, input_c]) return a_dot_b + input_c
def And(onnx_node, ng_inputs): # type: (NodeWrapper, List[NgraphNode]) -> NgraphNode """Perform the `and` logical operation elementwise on two input tensors with numpy-style broadcasting.""" left, right = numpy_style_broadcast_for_binary_operation( onnx_node, ng_inputs) left = ng.convert(ng.not_equal(left, 0), int) right = ng.convert(ng.not_equal(right, 0), int) return ng.convert(left * right, bool)
def Less(onnx_node, ng_inputs): # type: (NodeWrapper, List[NgraphNode]) -> NgraphNode """Perform the `less` logical operation elementwise on two input tensors with numpy-style broadcasting.""" left, right = numpy_style_broadcast_for_binary_operation( onnx_node, ng_inputs) return ng.less(left, right)
def Div(onnx_node, ng_inputs): # type: (NodeWrapper, List[NgraphNode]) -> NgraphNode """Perform element-wise binary division with numpy-style broadcasting.""" left, right = numpy_style_broadcast_for_binary_operation( onnx_node, ng_inputs) return ng.divide(left, right)
def Pow(onnx_node, ng_inputs): # type: (NodeWrapper, List[NgraphNode]) -> NgraphNode """Perform element-wise binary power with numpy-style broadcasting.""" base, exponent = numpy_style_broadcast_for_binary_operation( onnx_node, ng_inputs) return ng.power(base, exponent)