def validate_vector_lengths(vector_lengths, iterator_mapping):
    """
    Assert that vector lengths are valid and consistent.
    """
    # All fields must be vectorized if they access the innermost dimension,
    # and cannot be vectorized if they don't
    expected = max(vector_lengths.values())
    for field_name, vector_length in vector_lengths.items():
        dim_mask = iterator_mapping[field_name]
        if dim_mask[-1] == True:
            if vector_length != expected:
                raise ValueError(f"Field {field_name} has vectorization width "
                                 f"{vector_length}, expected {expected}.")
        else:
            if vector_length != 1:
                raise ValueError(f"Field {field_name} cannot be vectorized, "
                                 "because it doesn't read the innermost dimension.")
    return expected