Skip to content

Preprocessing (GPU)

The CPU twin is bixverse.pp.

pp

GPU sparse PCA.

Writes what bixverse.pp.calculate_pca writes: scores, loadings and the first no_pcs singular values to sc.cache, stamped "pca".

calculate_pca

calculate_pca(
    sc: SingleCells,
    no_pcs: int,
    *,
    pca_params: PcaParams | None = None,
    hvg: ndarray
    | Sequence[int]
    | Sequence[str]
    | None = None,
    seed: int = 42,
    verbose: Verbose = True,
    backend: Backend = "wgpu",
) -> None

Sparse PCA over the kept cells and the HVGs on the GPU.

Always sparse, so the data are never scaled into a dense matrix. svd_solver = "randomised" runs the randomised SVD, every other solver the exact block Lanczos; there is no GPU covariance path. No residual path either: use bixverse.pp.calculate_pca(..., residuals=True).

Parameters:

Name Type Description Default
sc SingleCells

The experiment.

required
no_pcs int

Number of components.

required
pca_params PcaParams | None

The PCA parameters. None uses the defaults.

None
hvg ndarray | Sequence[int] | Sequence[str] | None

0-based gene indices or gene ids to use instead of sc.map.hvg; they replace it.

None
seed int

Seed for the sketch or the Lanczos starting block.

42
verbose Verbose

0 (False) silent, 1 (True) progress, 2 extra detail where the method has it.

True
backend Backend

"wgpu" (any GPU), or "mlx" (Apple Silicon, needs a source build with the mlx feature; see mlx_available()).

'wgpu'

Raises:

Type Description
BixverseError

Without a GPU adapter, or with backend="mlx" on a build without the MLX twins.