def _convert_matmul(builder, node, graph, err):
    """
    convert to CoreML BatchedMatMul Layer:
    https://github.com/apple/coremltools/blob/655b3be5cc0d42c3c4fa49f0f0e4a93a26b3e492/mlmodel/format/NeuralNetwork.proto#L3473
    """
    weight_name = node.inputs[1]
    W = None
    weight_as_layer_parameter = False
    if weight_name in node.input_tensors:
        W = node.input_tensors[weight_name]
    if W is not None:
        if len(W.shape) != 2:
            builder.add_load_constant_nd(node.name + '_const_weight_input',
                weight_name, constant_value=W, shape=W.shape)
        else:
            weight_as_layer_parameter = True
    if weight_as_layer_parameter:
        builder.add_batched_mat_mul(name=node.name, input_names=[node.
            inputs[0]], output_name=node.outputs[0], weight_matrix_rows=W.
            shape[0], weight_matrix_columns=W.shape[1], W=W)
    else:
        builder.add_batched_mat_mul(name=node.name, input_names=[node.
            inputs[0], weight_name], output_name=node.outputs[0])
