Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions pyerrors/covobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def __init__(self, mean, cov, name, pos=None, grad=None):
else:
raise ValueError('Have to specify position of cov-element belonging to mean!')
else:
if pos > self.N:
raise ValueError(f'pos {pos} too large for covariance matrix with dimension {self.N}x{self.N}!')
if pos < 0 or pos >= self.N:
raise ValueError(f'pos {pos} not valid for covariance matrix with dimension {self.N}x{self.N}!')
self._grad = np.zeros((self.N, 1))
self._grad[pos] = 1.
else:
Expand Down
13 changes: 13 additions & 0 deletions tests/covobs_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import autograd.numpy as np
import pyerrors as pe
import pytest
from pyerrors.covobs import Covobs

np.random.seed(0)

Expand Down Expand Up @@ -108,3 +109,15 @@ def test_covobs_exceptions():
covobs = pe.cov_Obs([1.5, 0.1], [[1., .2,], [.3, .5]] , 'test')
with pytest.raises(Exception):
covobs = pe.cov_Obs([1.5, 0.1], [[8, 4,], [4, -2]] , 'test')


def test_covobs_pos_too_large():
cov = [[1, 0], [0, 1]]
with pytest.raises(ValueError):
Covobs(1.0, cov, 'test', pos=2)


def test_covobs_pos_negative():
cov = [[1, 0], [0, 1]]
with pytest.raises(ValueError):
Covobs(1.0, cov, 'test', pos=-1)
Loading