mirror of
https://github.com/fjosw/pyerrors.git
synced 2026-08-04 11:31:21 +02:00
[Fix] Also reject negative pos values
This commit is contained in:
parent
bb34f75376
commit
a1dc9c628e
2 changed files with 8 additions and 2 deletions
|
|
@ -31,8 +31,8 @@ class Covobs:
|
||||||
else:
|
else:
|
||||||
raise ValueError('Have to specify position of cov-element belonging to mean!')
|
raise ValueError('Have to specify position of cov-element belonging to mean!')
|
||||||
else:
|
else:
|
||||||
if pos >= self.N:
|
if pos < 0 or pos >= self.N:
|
||||||
raise ValueError(f'pos {pos} too large for covariance matrix with dimension {self.N}x{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 = np.zeros((self.N, 1))
|
||||||
self._grad[pos] = 1.
|
self._grad[pos] = 1.
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -115,3 +115,9 @@ def test_covobs_pos_too_large():
|
||||||
cov = [[1, 0], [0, 1]]
|
cov = [[1, 0], [0, 1]]
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
Covobs(1.0, cov, 'test', pos=2)
|
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…
Add table
Add a link
Reference in a new issue