[Fix] Fix off-by-one in Covobs pos bounds check (#288)

* [Fix] Fix off-by-one in Covobs pos bounds check

* [Fix] Also reject negative pos values
This commit is contained in:
Fabian Joswig 2026-07-15 09:34:10 +02:00 committed by GitHub
commit c58467aa11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 2 deletions

View file

@ -31,8 +31,8 @@ class Covobs:
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: