def _filter_by_size_dynamic(indices, size_fn, max_positions, raise_exception=False):

    def compare_leq(a, b):
        return ((a <= b) if (not isinstance(a, tuple)) else (max(a) <= b))

    def check_size(idx):
        if (isinstance(max_positions, float) or isinstance(max_positions, int)):
            return (size_fn(idx) <= max_positions)
        elif isinstance(max_positions, dict):
            idx_size = size_fn(idx)
            assert isinstance(idx_size, dict)
            intersect_keys = (set(max_positions.keys()) & set(idx_size.keys()))
            return all((all((((a is None) or (b is None) or (a <= b)) for (a, b) in zip(idx_size[key], max_positions[key]))) for key in intersect_keys))
        else:
            if (not isinstance(size_fn(idx), Iterable)):
                return all(((size_fn(idx) <= b) for b in max_positions))
            return all((((a is None) or (b is None) or (a <= b)) for (a, b) in zip(size_fn(idx), max_positions)))
    ignored = []
    itr = collect_filtered(check_size, indices, ignored)
    indices = np.fromiter(itr, dtype=np.int64, count=(- 1))
    return (indices, ignored)
def _filter_by_size_dynamic(indices, size_fn, max_positions, raise_exception=False):

    def compare_leq(a, b):
        return ((a <= b) if (not isinstance(a, tuple)) else (max(a) <= b))

    def check_size(idx):
        if (isinstance(max_positions, float) or isinstance(max_positions, int)):
            return (size_fn(idx) <= max_positions)
        elif isinstance(max_positions, dict):
            idx_size = size_fn(idx)
            assert isinstance(idx_size, dict)
            intersect_keys = (set(max_positions.keys()) & set(idx_size.keys()))
            return all((all((((a is None) or (b is None) or (a <= b)) for (a, b) in zip(idx_size[key], max_positions[key]))) for key in intersect_keys))
        else:
            if (not isinstance(size_fn(idx), Iterable)):
                return all(((size_fn(idx) <= b) for b in max_positions))
            return all((((a is None) or (b is None) or (a <= b)) for (a, b) in zip(size_fn(idx), max_positions)))
    ignored = []
    itr = collect_filtered(check_size, indices, ignored)
    indices = np.fromiter(itr, dtype=np.int64, count=(- 1))
    return (indices, ignored)