mirror of
https://github.com/fjosw/pyerrors.git
synced 2026-08-04 11:31:21 +02:00
[Fix] Fix off-by-one in Covobs pos bounds check
This commit is contained in:
parent
470e2c57fc
commit
bb34f75376
2 changed files with 8 additions and 1 deletions
|
|
@ -31,7 +31,7 @@ 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 >= self.N:
|
||||||
raise ValueError(f'pos {pos} too large for covariance matrix with dimension {self.N}x{self.N}!')
|
raise ValueError(f'pos {pos} too large 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.
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import autograd.numpy as np
|
import autograd.numpy as np
|
||||||
import pyerrors as pe
|
import pyerrors as pe
|
||||||
import pytest
|
import pytest
|
||||||
|
from pyerrors.covobs import Covobs
|
||||||
|
|
||||||
np.random.seed(0)
|
np.random.seed(0)
|
||||||
|
|
||||||
|
|
@ -108,3 +109,9 @@ def test_covobs_exceptions():
|
||||||
covobs = pe.cov_Obs([1.5, 0.1], [[1., .2,], [.3, .5]] , 'test')
|
covobs = pe.cov_Obs([1.5, 0.1], [[1., .2,], [.3, .5]] , 'test')
|
||||||
with pytest.raises(Exception):
|
with pytest.raises(Exception):
|
||||||
covobs = pe.cov_Obs([1.5, 0.1], [[8, 4,], [4, -2]] , 'test')
|
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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue