Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scale function(_get_mean_var) updated for dense array, speedup upto ~4.65x #3280

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Merge branch 'main' of https://github.com/sanchit-misra/scanpy into s…

8f357fb
Select commit
Loading
Failed to load commit list.
Open

scale function(_get_mean_var) updated for dense array, speedup upto ~4.65x #3280

Merge branch 'main' of https://github.com/sanchit-misra/scanpy into s…
8f357fb
Select commit
Loading
Failed to load commit list.
Azure Pipelines / scverse.scanpy failed Jan 8, 2025 in 28m 16s

Build #20250108.1 had test failures

Details

Tests

  • Failed: 152 (1.39%)
  • Passed: 9,868 (90.32%)
  • Other: 905 (8.28%)
  • Total: 10,925
Code coverage

  • 9924 of 12990 line covered (76.40%)

Annotations

Check failure on line 4523 in Build log

See this annotation in the file changed.

@azure-pipelines azure-pipelines / scverse.scanpy

Build log #L4523

Bash exited with code '1'.

Check failure on line 4046 in Build log

See this annotation in the file changed.

@azure-pipelines azure-pipelines / scverse.scanpy

Build log #L4046

Bash exited with code '1'.

Check failure on line 4542 in Build log

See this annotation in the file changed.

@azure-pipelines azure-pipelines / scverse.scanpy

Build log #L4542

Bash exited with code '1'.

Check failure on line 3588 in Build log

See this annotation in the file changed.

@azure-pipelines azure-pipelines / scverse.scanpy

Build log #L3588

Bash exited with code '1'.

Check failure on line 1 in tests/test_rank_genes_groups.py::test_results[numpy_ndarray]

See this annotation in the file changed.

@azure-pipelines azure-pipelines / scverse.scanpy

tests/test_rank_genes_groups.py::test_results[numpy_ndarray]

array_type = <function asarray at 0x7fa771984f40>

    @pytest.mark.parametrize("array_type", ARRAY_TYPES_MEM)
    def test_results(array_type):
        seed(1234)
    
        adata = get_example_data(array_type)
        assert adata.raw is None  # Assumption for later checks
    
        (
            true_names_t_test,
            true_names_wilcoxon,
            true_scores_t_test,
            true_scores_wilcoxon,
        ) = get_true_scores()
    
        rank_genes_groups(adata, "true_groups", n_genes=20, method="t-test")
    
        adata.uns["rank_genes_groups"]["names"] = adata.uns["rank_genes_groups"][
            "names"
        ].astype(true_names_t_test.dtype)
    
        for name in true_scores_t_test.dtype.names:
>           assert np.allclose(
                true_scores_t_test[name], adata.uns["rank_genes_groups"]["scores"][name]
            )
E           assert False
E            +  where False = <function allclose at 0x7fa77be9a030>(array([ 0.88779753 ,  0.7680498  ,  0.57457656 ,  0.34870306 ,\n        0.26995564 ,  0.25511038 ,  0.11647039 ,  0.0773671  ,\n        0.030090872,  0.         , -0.020448448, -0.236924   ,\n       -0.9331775  , -1.5263917  , -1.5304459  , -2.0760367  ,\n       -2.3138392  , -2.3522618  , -2.7801418  , -2.8450732  ],\n      dtype=float32), array([ 0.845086   ,  0.729268   ,  0.54912335 ,  0.33181465 ,\n        0.2582014  ,  0.24294989 ,  0.110755555,  0.07385662 ,\n        0.028677907,  0.         , -0.01953408 , -0.22624032 ,\n       -0.9099657  , -1.494625   , -1.5004543  , -2.0644708  ,\n       -2.2684083  , -2.3391573  , -2.7646534  , -2.8130772  ],\n      dtype=float32))
E            +    where <function allclose at 0x7fa77be9a030> = np.allclose

tests/test_rank_genes_groups.py:105: AssertionError
Raw output
/home/vsts/work/1/s/tests/test_rank_genes_groups.py:105: assert False

Check failure on line 1 in tests/test_rank_genes_groups.py::test_results_layers[numpy_ndarray]

See this annotation in the file changed.

@azure-pipelines azure-pipelines / scverse.scanpy

tests/test_rank_genes_groups.py::test_results_layers[numpy_ndarray]

array_type = <function asarray at 0x7fa771984f40>

    @pytest.mark.parametrize("array_type", ARRAY_TYPES_MEM)
    def test_results_layers(array_type):
        seed(1234)
    
        adata = get_example_data(array_type)
        adata.layers["to_test"] = adata.X.copy()
        adata.X = elem_mul(adata.X, np.random.randint(0, 2, adata.shape, dtype=bool))
    
        _, _, true_scores_t_test, true_scores_wilcoxon = get_true_scores()
    
        # Wilcoxon
        rank_genes_groups(
            adata,
            "true_groups",
            method="wilcoxon",
            layer="to_test",
            n_genes=20,
        )
        assert adata.uns["rank_genes_groups"]["params"]["use_raw"] is False
        for name in true_scores_t_test.dtype.names:
            assert np.allclose(
                true_scores_wilcoxon[name][:7],
                adata.uns["rank_genes_groups"]["scores"][name][:7],
            )
    
        rank_genes_groups(adata, "true_groups", method="wilcoxon", n_genes=20)
        for name in true_scores_t_test.dtype.names:
            assert not np.allclose(
                true_scores_wilcoxon[name][:7],
                adata.uns["rank_genes_groups"]["scores"][name][:7],
            )
    
        # t-test
        rank_genes_groups(
            adata,
            "true_groups",
            method="t-test",
            layer="to_test",
            use_raw=False,
            n_genes=20,
        )
        for name in true_scores_t_test.dtype.names:
>           assert np.allclose(
                true_scores_t_test[name][:7],
                adata.uns["rank_genes_groups"]["scores"][name][:7],
            )
E           assert False
E            +  where False = <function allclose at 0x7fa77be9a030>(array([0.88779753, 0.7680498 , 0.57457656, 0.34870306, 0.26995564,\n       0.25511038, 0.11647039], dtype=float32), array([0.845086   , 0.729268   , 0.54912335 , 0.33181465 , 0.2582014  ,\n       0.24294989 , 0.110755555], dtype=float32))
E            +    where <function allclose at 0x7fa77be9a030> = np.allclose

tests/test_rank_genes_groups.py:170: AssertionError
Raw output
/home/vsts/work/1/s/tests/test_rank_genes_groups.py:170: assert False

Check failure on line 1 in tests/test_preprocessing.py::test_mean_var[numpy_ndarray]

See this annotation in the file changed.

@azure-pipelines azure-pipelines / scverse.scanpy

tests/test_preprocessing.py::test_mean_var[numpy_ndarray]

array_type = <function asarray at 0x7fa771984f40>

    @pytest.mark.parametrize("array_type", ARRAY_TYPES)
    def test_mean_var(array_type):
        pbmc = pbmc3k()
        pbmc.X = array_type(pbmc.X)
    
        true_mean = np.mean(asarray(pbmc.X), axis=0)
        true_var = np.var(asarray(pbmc.X), axis=0, dtype=np.float64, ddof=1)
    
        means, variances = sc.pp._utils._get_mean_var(pbmc.X)
    
        np.testing.assert_allclose(true_mean, means)
>       np.testing.assert_allclose(true_var, variances)

tests/test_preprocessing.py:91: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

args = (<function assert_allclose.<locals>.compare at 0x7fa7345b8ae0>, array([0., 0., 0., ..., 0., 0., 0.]), array([0., 0., 0., ..., 0., 0., 0.]))
kwds = {'equal_nan': True, 'err_msg': '', 'header': 'Not equal to tolerance rtol=1e-07, atol=0', 'strict': False, ...}

    @wraps(func)
    def inner(*args, **kwds):
        with self._recreate_cm():
>           return func(*args, **kwds)
E           AssertionError: 
E           Not equal to tolerance rtol=1e-07, atol=0
E           
E           Mismatched elements: 16634 / 32738 (50.8%)
E           Max absolute difference among violations: 0.744234493
E           Max relative difference among violations: 0.0003703704
E            ACTUAL: array([0., 0., 0., ..., 0., 0., 0.])
E            DESIRED: array([0., 0., 0., ..., 0., 0., 0.])

/opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/contextlib.py:81: AssertionError
Raw output
/opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/contextlib.py:81: AssertionError:

Check failure on line 1 in tests/test_preprocessing.py::test_scale_matrix_types[None-False-numpy_ndarray]

See this annotation in the file changed.

@azure-pipelines azure-pipelines / scverse.scanpy

tests/test_preprocessing.py::test_scale_matrix_types[None-False-numpy_ndarray]

array_type = <function asarray at 0x7fa771984f40>, zero_center = False
max_value = None

    @pytest.mark.parametrize("array_type", ARRAY_TYPES)
    @pytest.mark.parametrize("zero_center", [True, False])
    @pytest.mark.parametrize("max_value", [None, 1.0])
    def test_scale_matrix_types(array_type, zero_center, max_value):
        adata = pbmc68k_reduced()
        adata.X = adata.raw.X
        adata_casted = adata.copy()
        adata_casted.X = array_type(adata_casted.raw.X)
        sc.pp.scale(adata, zero_center=zero_center, max_value=max_value)
        with maybe_dask_process_context():
            sc.pp.scale(adata_casted, zero_center=zero_center, max_value=max_value)
        X = adata_casted.X
        if "dask" in array_type.__name__:
            X = X.compute()
        if issparse(X):
            X = X.todense()
        if issparse(adata.X):
            adata.X = adata.X.todense()
>       assert_allclose(X, adata.X, rtol=1e-5, atol=1e-5)

tests/test_preprocessing.py:322: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

args = (<function assert_allclose.<locals>.compare at 0x7fa7335e44a0>, array([[0.       , 0.       , 0.       , ..., 0.      ...         ],
       [0.          , 0.          , 1.4205601126, ..., 0.          ,
        0.          , 0.          ]]))
kwds = {'equal_nan': True, 'err_msg': '', 'header': 'Not equal to tolerance rtol=1e-05, atol=1e-05', 'strict': False, ...}

    @wraps(func)
    def inner(*args, **kwds):
        with self._recreate_cm():
>           return func(*args, **kwds)
E           AssertionError: 
E           Not equal to tolerance rtol=1e-05, atol=1e-05
E           
E           Mismatched elements: 174400 / 535500 (32.6%)
E           Max absolute difference among violations: 0.012948173
E           Max relative difference among violations: 0.0007146004
E            ACTUAL: array([[0.      , 0.      , 0.      , ..., 0.      , 0.      , 3.337128],
E                  [2.378524, 0.      , 1.926703, ..., 0.      , 2.769665, 0.      ],
E                  [0.      , 0.      , 1.707929, ..., 0.      , 1.78579 , 0.      ],...
E            DESIRED: array([[0.      , 0.      , 0.      , ..., 0.      , 0.      , 3.339514],
E                  [2.380225, 0.      , 1.928081, ..., 0.      , 2.771645, 0.      ],
E                  [0.      , 0.      , 1.70915 , ..., 0.      , 1.787067, 0.      ],...

/opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/contextlib.py:81: AssertionError
Raw output
/opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/contextlib.py:81: AssertionError: