Skip to content

Commit d78a0da

Browse files
authored
Merge pull request #3505 from JoeZiminski/fix_whitening_regression
Whitening fix - compute covariance matrix in float
2 parents 151947a + 7b8d0a2 commit d78a0da

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/spikeinterface/preprocessing/whiten.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class WhitenRecording(BasePreprocessor):
1919
recording : RecordingExtractor
2020
The recording extractor to be whitened.
2121
dtype : None or dtype, default: None
22+
Datatype of the output recording (covariance matrix estimation
23+
and whitening are performed in float32).
2224
If None the the parent dtype is kept.
2325
For integer dtype a int_scale must be also given.
2426
mode : "global" | "local", default: "global"
@@ -74,7 +76,9 @@ def __init__(
7476
dtype_ = fix_dtype(recording, dtype)
7577

7678
if dtype_.kind == "i":
77-
assert int_scale is not None, "For recording with dtype=int you must set dtype=float32 OR set a int_scale"
79+
assert (
80+
int_scale is not None
81+
), "For recording with dtype=int you must set the output dtype to float OR set a int_scale"
7882

7983
if W is not None:
8084
W = np.asarray(W)
@@ -124,7 +128,7 @@ def __init__(self, parent_recording_segment, W, M, dtype, int_scale):
124128
def get_traces(self, start_frame, end_frame, channel_indices):
125129
traces = self.parent_recording_segment.get_traces(start_frame, end_frame, slice(None))
126130
traces_dtype = traces.dtype
127-
# if uint --> force int
131+
# if uint --> force float
128132
if traces_dtype.kind == "u":
129133
traces = traces.astype("float32")
130134

@@ -185,6 +189,7 @@ def compute_whitening_matrix(
185189
186190
"""
187191
random_data = get_random_data_chunks(recording, concatenated=True, return_scaled=False, **random_chunk_kwargs)
192+
random_data = random_data.astype(np.float32)
188193

189194
regularize_kwargs = regularize_kwargs if regularize_kwargs is not None else {"method": "GraphicalLassoCV"}
190195

0 commit comments

Comments
 (0)