Skip to content

Commit

Permalink
FIX: Fix combine check
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Jun 7, 2024
1 parent be5a115 commit 108a774
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mne/stats/_adjacency.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def combine_adjacency(*structure):
structure = list(structure)
for di, dim in enumerate(structure):
name = f"structure[{di}]"
_validate_type(dim, ("int-like", np.ndarray, sparse.spmatrix), name)
_validate_type(dim, ("int-like", np.ndarray, "sparse"), name)
if isinstance(dim, int_like):
# Don't add the diagonal, because we explicitly remove it later
dim = sparse.dia_array(
Expand Down
3 changes: 2 additions & 1 deletion mne/stats/tests/test_cluster_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from scipy import linalg, sparse, stats

from mne import MixedSourceEstimate, SourceEstimate, SourceSpaces, VolSourceEstimate
from mne.fixes import _eye_array
from mne.stats import combine_adjacency, ttest_ind_no_p
from mne.stats.cluster_level import (
f_oneway,
Expand Down Expand Up @@ -382,7 +383,7 @@ def test_cluster_permutation_with_adjacency(numba_conditional, monkeypatch):
)
)
# nesting here is time then space:
adjacency_2a = combine_adjacency(np.eye(2), adjacency)
adjacency_2a = combine_adjacency(_eye_array(2), adjacency)
assert_array_equal(
adjacency_2.toarray().astype(bool), adjacency_2a.toarray().astype(bool)
)
Expand Down
8 changes: 8 additions & 0 deletions mne/utils/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from pathlib import Path

import numpy as np
from scipy import sparse

from ..defaults import HEAD_SIZE_DEFAULT, _handle_default
from ..fixes import _compare_version, _median_complex
Expand Down Expand Up @@ -533,13 +534,20 @@ def __instancecheck__(cls, other):
return callable(other)


class _Sparse:
@classmethod
def __instancecheck__(cls, other):
return sparse.issparse(other)


_multi = {
"str": (str,),
"numeric": (np.floating, float, int_like),
"path-like": path_like,
"int-like": (int_like,),
"callable": (_Callable(),),
"array-like": (list, tuple, set, np.ndarray),
"sparse": (_Sparse(),),
}


Expand Down
1 change: 1 addition & 0 deletions tutorials/stats-sensor-space/40_cluster_1samp_time_freq.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
# %%
# Set parameters
# --------------

data_path = sample.data_path()
meg_path = data_path / "MEG" / "sample"
raw_fname = meg_path / "sample_audvis_raw.fif"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
the possible interpretation of "significant" clusters.
For more information on cluster-based permutation testing in MNE-Python,
see also: :ref:`tut-cluster-one-samp-tfr`
see also: :ref:`tut-cluster-one-samp-tfr`.
"""
# Authors: Denis Engemann <[email protected]>
# Jona Sassenhagen <[email protected]>
Expand Down

0 comments on commit 108a774

Please sign in to comment.