Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion tests/test_tensor_factors.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
cs_rank, cs_zscore,
delay, delta,
ewma,
ts_corr, ts_max, ts_mean, ts_min, ts_rank, ts_std, ts_sum,
ts_corr, ts_cov, ts_max, ts_mean, ts_min, ts_rank, ts_std, ts_sum,
)


Expand Down Expand Up @@ -84,6 +84,19 @@ def test_ts_rank_last_element_in_window():
assert torch.equal(out_mask, expected_mask)


def test_ts_cov_window_semantics():
x = torch.tensor([[1.0, 2.0], [2.0, 4.0], [3.0, 6.0], [4.0, 8.0]])
y = torch.tensor([[2.0, 1.0], [4.0, 2.0], [6.0, 3.0], [8.0, 4.0]])
mask = torch.ones_like(x, dtype=torch.bool)
out, out_mask = ts_cov(x, y, mask, 3)

expected = torch.tensor([[0.0, 0.0], [0.0, 0.0], [2.0, 2.0], [2.0, 2.0]])
expected_mask = torch.tensor([[False, False], [False, False], [True, True], [True, True]])

torch.testing.assert_close(out, expected)
assert torch.equal(out_mask, expected_mask)


def test_ts_corr_matches_pandas(random_panel_tensors):
x, mask = random_panel_tensors
rng = np.random.default_rng(1)
Expand Down