def check_input_and_output_numbers()

in onnxconverter_common/utils.py [0:0]


def check_input_and_output_numbers(operator, input_count_range=None, output_count_range=None):
    '''
    Check if the number of input(s)/output(s) is correct

    :param operator: A Operator object
    :param input_count_range: A list of two integers or an integer. If it's a list the first/second element is the
    minimal/maximal number of inputs. If it's an integer, it is equivalent to specify that number twice in a list. For
    infinite ranges like 5 to infinity, you need to use [5, None].
    :param output_count_range: A list of two integers or an integer. See input_count_range for its format.
    '''
    if isinstance(input_count_range, list):
        min_input_count = input_count_range[0]
        max_input_count = input_count_range[1]
    elif isinstance(input_count_range, int) or input_count_range is None:
        min_input_count = input_count_range
        max_input_count = input_count_range
    else:
        raise RuntimeError('input_count_range must be a list or an integer')

    if isinstance(output_count_range, list):
        min_output_count = output_count_range[0]
        max_output_count = output_count_range[1]
    elif isinstance(output_count_range, int) or output_count_range is None:
        min_output_count = output_count_range
        max_output_count = output_count_range
    else:
        raise RuntimeError('output_count_range must be a list or an integer')

    if min_input_count is not None and len(operator.inputs) < min_input_count:
        raise RuntimeError(
            'For operator %s (type: %s), at least %s input(s) is(are) required but we got %s input(s) which are %s'
            % (operator.full_name, operator.type, min_input_count, len(operator.inputs), operator.input_full_names))

    if max_input_count is not None and len(operator.inputs) > max_input_count:
        raise RuntimeError(
            'For operator %s (type: %s), at most %s input(s) is(are) supported but we got %s input(s) which are %s'
            % (operator.full_name, operator.type, max_input_count, len(operator.inputs), operator.input_full_names))

    if min_output_count is not None and len(operator.outputs) < min_output_count:
        raise RuntimeError(
            'For operator %s (type: %s), at least %s output(s) is(are) produced but we got %s output(s) which are %s'
            % (operator.full_name, operator.type, min_output_count, len(operator.outputs), operator.output_full_names))

    if max_output_count is not None and len(operator.outputs) > max_output_count:
        raise RuntimeError(
            'For operator %s (type: %s), at most %s outputs(s) is(are) supported but we got %s output(s) which are %s'
            % (operator.full_name, operator.type, max_output_count, len(operator.outputs), operator.output_full_names))