@staticmethod
    def _tensAdd_check_automatrix(args):
        # check that all automatrix indices are the same.

        # if there are no addends, just return.
        if not args:
            return args

        # @type auto_left_types: set
        auto_left_types = set([])
        auto_right_types = set([])
        args_auto_left_types = []
        args_auto_right_types = []
        for i, arg in enumerate(args):
            arg_auto_left_types = set([])
            arg_auto_right_types = set([])
            for index in get_indices(arg):
                # @type index: TensorIndex
                if index in (index._tensortype.auto_left, -index._tensortype.auto_left):
                    auto_left_types.add(index._tensortype)
                    arg_auto_left_types.add(index._tensortype)
                if index in (index._tensortype.auto_right, -index._tensortype.auto_right):
                    auto_right_types.add(index._tensortype)
                    arg_auto_right_types.add(index._tensortype)
            args_auto_left_types.append(arg_auto_left_types)
            args_auto_right_types.append(arg_auto_right_types)
        for arg, aas_left, aas_right in zip(args, args_auto_left_types, args_auto_right_types):
            missing_left = auto_left_types - aas_left
            missing_right = auto_right_types - aas_right
            missing_intersection = missing_left & missing_right
            for j in missing_intersection:
                args[i] *= j.delta(j.auto_left, -j.auto_right)
            if missing_left != missing_right:
                raise ValueError("cannot determine how to add auto-matrix indices on some args")

        return args
dataset/ETHPy150Open sympy/sympy/sympy/tensor/tensor.py/TensAdd._tensAdd_check_automatrix/original