Skip to content

Commit 3af4373

Browse files
committed
Review suggestion: check smaller minors first
1 parent 5d0d23a commit 3af4373

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/numerics/type_tensor.C

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,22 @@ bool TypeTensor<T>::is_hpd(Real rel_tol) const
9797
// and all principal minors are real-valued. Since we already
9898
// checked that the matrix is Hermitian above, we don't bother to
9999
// check the complex parts are also zero now.
100-
if (std::real(A.det()) < -abs_tol)
100+
101+
// For 3x3 and 2x2, check the 1x1 determinant
102+
#if LIBMESH_DIM > 1
103+
if (std::real(A(0,0)) < -abs_tol)
101104
return false;
105+
#endif
102106

103-
// For 3x3, also check the upper 2x2 determinant
107+
// For 3x3, check the upper 2x2 determinant
104108
#if LIBMESH_DIM > 2
105109
if (std::real(A(0,0)*A(1,1) - A(0,1)*A(1,0)) < -abs_tol)
106110
return false;
107111
#endif
108112

109-
// For 3x3 and 2x2, also check the 1x1 determinant
110-
#if LIBMESH_DIM > 1
111-
if (std::real(A(0,0)) < -abs_tol)
113+
// Finally, check the full determinant
114+
if (std::real(A.det()) < -abs_tol)
112115
return false;
113-
#endif
114116

115117
// If we made it here, then the matrix is Hermitian
116118
// positive-definite.

0 commit comments

Comments
 (0)