def ravel_multi_index(indices, dims):
    """
    See `np.ravel_multi_index`.

    Note this version accepts negative indices without raising.
    """
    ndim = len(dims)
    assert len(indices) == ndim
    acc = indices[-1].copy()
    stride = dims[-1]
    for i in range(ndim - 2, -1, -1):
        acc += indices[i] * stride
        stride *= dims[i]
    return acc