Skip to content

Commit 32ed99d

Browse files
feat: Add BatchCorr for batch-wise correlation calculation
1 parent 833aea9 commit 32ed99d

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

batchstats/stats/corr.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import numpy as np
22

3-
from .._misc import NoValidSamplesError, UnequalSamplesNumber, any_nan
3+
from .._misc import (
4+
DifferentAxisError,
5+
DifferentShapesError,
6+
DifferentStatsError,
7+
NoValidSamplesError,
8+
UnequalSamplesNumber,
9+
any_nan,
10+
)
411
from ..base import BatchStat
512
from .cov import BatchCov
613
from .var import BatchVar
@@ -126,7 +133,14 @@ def __add__(self, other):
126133
"""
127134
Merge two BatchCorr objects.
128135
"""
129-
self.merge_test(other)
136+
if type(self) != type(other):
137+
raise DifferentStatsError()
138+
if self.axis != other.axis:
139+
raise DifferentAxisError()
140+
141+
if self.cov.cov is not None and other.cov.cov is not None:
142+
if self.cov.cov.shape != other.cov.cov.shape:
143+
raise DifferentShapesError()
130144

131145
if self.n_samples == 0:
132146
return other

tests/test_merge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import numpy as np
22
import pytest
33

4-
from batchstats import BatchCov, BatchMax, BatchMean, BatchMin, BatchPeakToPeak, BatchStd, BatchSum, BatchVar
4+
from batchstats import BatchCorr, BatchCov, BatchMax, BatchMean, BatchMin, BatchPeakToPeak, BatchStd, BatchSum, BatchVar
55

66

77
@pytest.fixture
@@ -13,7 +13,7 @@ def data():
1313
def test_merge(data):
1414
data1, data2 = data
1515
data0 = np.concatenate([data1, data2])
16-
for stat in (BatchCov, BatchMax, BatchMean, BatchMin, BatchPeakToPeak, BatchStd, BatchSum, BatchVar):
16+
for stat in (BatchCorr, BatchCov, BatchMax, BatchMean, BatchMin, BatchPeakToPeak, BatchStd, BatchSum, BatchVar):
1717
s0 = stat().update_batch(data0)
1818
s1 = stat().update_batch(data1)
1919
s2 = stat().update_batch(data2)

0 commit comments

Comments
 (0)