From f928159ed6c25c4aec01adebf2c4d1211c3dc006 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Fri, 6 Dec 2024 18:10:01 +0100 Subject: [PATCH] PERF: Use `vnl_sparse_matrix::get` in ComputeJacobianTerms `vnl_sparse_matrix::get(r, c)` just returns when the entry isn't there, and it returns immediately when the row is empty. A performance improvement may not be noticeable, but it won't harm. --- Common/itkComputeJacobianTerms.hxx | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Common/itkComputeJacobianTerms.hxx b/Common/itkComputeJacobianTerms.hxx index ca890a883..abd9c203c 100644 --- a/Common/itkComputeJacobianTerms.hxx +++ b/Common/itkComputeJacobianTerms.hxx @@ -312,13 +312,10 @@ ComputeJacobianTerms::Compute() const -> Terms double TrC = 0.0; for (unsigned int p = 0; p < numberOfParameters; ++p) { - if (!cov.empty_row(p)) - { - // avoid creation of element if the row is empty - CovarianceValueType & covpp = cov(p, p); - TrC += covpp; - diagcov[p] = covpp; - } + // Do cov.get(p, p) instead of cov(p, p) to avoid creation of an entry that just has zero. + const CovarianceValueType covpp = cov.get(p, p); + TrC += covpp; + diagcov[p] = covpp; } /**