Skip to content

Commit

Permalink
[SymForce-External] Add Matrix.det()
Browse files Browse the repository at this point in the history
Add `Matrix.det()`

For #306

Topic: sf-matrix-det
Closes #307
GitOrigin-RevId: 5f4745faf9c56e6356ba075ed7866af5d0cfb52d
  • Loading branch information
aaron-skydio committed Mar 8, 2023
1 parent 7269521 commit d337809
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions symforce/geo/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,12 @@ def eye(cls: _T.Type[MatrixT], rows: int = None, cols: int = None) -> MatrixT:
mat[i, i] = sf.S.One
return mat

def det(self) -> _T.Scalar:
"""
Determinant of the matrix.
"""
return self.mat.det()

def inv(self: MatrixT, method: str = "LU") -> MatrixT:
"""
Inverse of the matrix.
Expand Down
5 changes: 4 additions & 1 deletion test/geo_matrix_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ def test_matrix_initialization(self) -> None:
def test_matrix_operations(self) -> None:
"""
Tests:
Matrix.Matrix_inverse
Matrix.inv()
Matrix.__add__ (scalar_like)
Matrix.__div__ (scalar_like)
Matrix.det()
"""

test_matrix = sf.Matrix([[2, 0], [0, 4]])
Expand All @@ -139,6 +140,8 @@ def test_matrix_operations(self) -> None:
self.assertEqual(sf.Matrix.eye(2), diag_matrix / 2)
self.assertEqual(sf.Matrix.eye(2), sf.Matrix(test_matrix / test_matrix))

self.assertEqual(diag_matrix.det(), 4)

def test_symbolic_operations(self) -> None:
"""
Tests:
Expand Down

0 comments on commit d337809

Please sign in to comment.