def test_set_scalar_subset_X(matrix_type, subset_func):
    adata = ad.AnnData(matrix_type(np.zeros((10, 10))))
    orig_X_val = adata.X.copy()
    subset_idx = slice_subset(adata.obs_names)

    adata_subset = adata[subset_idx, :]

    adata_subset.X = 1

    assert adata_subset.is_view
    assert np.all(asarray(adata[subset_idx, :].X) == 1)

    assert asarray((orig_X_val != adata.X)).sum() == mul(*adata_subset.shape)
def _kindpatstoglobs(kindpats, recursive=False):
    """Attempt to convert 'kindpats' to glob patterns that can be used in a
    treematcher.

    kindpats should be already normalized to be relative to repo root.

    If recursive is True, `glob:a*` will match both `a1/b` and `a1`, otherwise
    `glob:a*` will only match `a1` but not `a1/b`.

    Return None if there are unsupported patterns (ex. regular expressions).
    """
    if not _usetreematcher:
        return None
    globs = []
    for kindpat in kindpats:
        kind, pat = kindpat[0:2]
        if kind == "re":
            # Attempt to convert the re pat to globs
            reglobs = _convertretoglobs(pat)
            if reglobs is not None:
                globs += reglobs
            else:
                return None
        elif kind == "glob":
            # The treematcher (man gitignore) does not support csh-style
            # brackets (ex. "{a,b,c}"). Expand the brackets to patterns.
            for subpat in pathmatcher.expandcurlybrackets(pat):
                normalized = pathmatcher.normalizeglob(subpat)
                if recursive:
                    normalized = _makeglobrecursive(normalized)
                globs.append(normalized)
        elif kind == "path":
            if pat == ".":
                # Special case. Comes from `util.normpath`.
                pat = ""
            else:
                pat = pathmatcher.plaintoglob(pat)
            pat = _makeglobrecursive(pat)
            globs.append(pat)
        else:
            return None
    return globs