File: test_gpu.py

package info (click to toggle)
python-anndata 0.12.6-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,876 kB
  • sloc: python: 21,429; makefile: 23
file content (42 lines) | stat: -rw-r--r-- 920 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from __future__ import annotations

import pytest
from scipy import sparse

from anndata import AnnData, Raw

pytest.importorskip("cupy")


@pytest.mark.gpu
def test_gpu():
    """
    For testing that the gpu mark works
    """
    import cupy  # This test shouldn't run if cupy isn't installed

    cupy.ones(1)


@pytest.mark.gpu
def test_adata_raw_gpu():
    import cupy as cp
    from cupyx.scipy import sparse as cupy_sparse

    adata = AnnData(
        X=cupy_sparse.random(500, 50, density=0.01, format="csr", dtype=cp.float32)
    )
    adata.raw = adata.copy()
    assert isinstance(adata.raw.X, sparse.csr_matrix)


@pytest.mark.gpu
def test_raw_gpu():
    import cupy as cp
    from cupyx.scipy import sparse as cupy_sparse

    adata = AnnData(
        X=cupy_sparse.random(500, 50, density=0.01, format="csr", dtype=cp.float32)
    )
    araw = Raw(adata)
    assert isinstance(araw.X, sparse.csr_matrix)