Create a mask for indexing with a fill-value.

    Parameters
    ----------
    indexer : ExplicitIndexer
        Indexer with -1 in integer or ndarray value to indicate locations in
        the result that should be masked.
    shape : tuple
        Shape of the array being indexed.
    chunks_hint : tuple, optional
        Optional tuple indicating desired chunks for the result. If provided,
        used as a hint for chunks on the resulting dask. Must have a hint for
        each dimension on the result array.

    Returns
    -------
    mask : bool, np.ndarray or dask.array.Array with dtype=bool
        Dask array if chunks_hint is provided, otherwise a NumPy array. Has the
        same shape as the indexing result.

def create_mask(indexer, shape, chunks_hint=None):
    """Create a mask for indexing with a fill-value.

    Parameters
    ----------
    indexer : ExplicitIndexer
        Indexer with -1 in integer or ndarray value to indicate locations in
        the result that should be masked.
    shape : tuple
        Shape of the array being indexed.
    chunks_hint : tuple, optional
        Optional tuple indicating desired chunks for the result. If provided,
        used as a hint for chunks on the resulting dask. Must have a hint for
        each dimension on the result array.

    Returns
    -------
    mask : bool, np.ndarray or dask.array.Array with dtype=bool
        Dask array if chunks_hint is provided, otherwise a NumPy array. Has the
        same shape as the indexing result.
    """
    if isinstance(indexer, OuterIndexer):
        key = _outer_to_vectorized_indexer(indexer, shape).tuple
        assert not any(isinstance(k, slice) for k in key)
        mask = _masked_result_drop_slice(key, chunks_hint)

    elif isinstance(indexer, VectorizedIndexer):
        key = indexer.tuple
        base_mask = _masked_result_drop_slice(key, chunks_hint)
        slice_shape = tuple(np.arange(*k.indices(size)).size
                            for k, size in zip(key, shape)
                            if isinstance(k, slice))
        expanded_mask = base_mask[
            (Ellipsis,) + (np.newaxis,) * len(slice_shape)]
        mask = duck_array_ops.broadcast_to(
            expanded_mask, base_mask.shape + slice_shape)

    elif isinstance(indexer, BasicIndexer):
        mask = any(k == -1 for k in indexer.tuple)

    else:
        raise TypeError('unexpected key type: {}'.format(type(indexer)))

    return mask