Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/pyrecest/tracking/ellipse_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def symmetrize(matrix):
"""Return the symmetric part of ``matrix``."""

matrix = asarray(matrix)
return 0.5 * (matrix + matrix.T)
return 0.5 * matrix + 0.5 * matrix.T


def project_symmetric_covariance(covariance, minimum_eigenvalue=0.0):
Expand Down
28 changes: 28 additions & 0 deletions tests/tracking/test_ellipse_geometry_integer_overflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from __future__ import annotations

import numpy as np
import numpy.testing as npt
from pyrecest.tracking import project_symmetric_covariance


def test_covariance_projection_avoids_integer_overflow() -> None:
covariance = np.array(
[
[120, 100],
[80, 110],
],
dtype=np.int8,
)

projected = np.asarray(project_symmetric_covariance(covariance))

npt.assert_allclose(
projected,
np.array(
[
[120.0, 90.0],
[90.0, 110.0],
]
),
)
assert np.issubdtype(projected.dtype, np.floating)
Loading