Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PERF: Fill jsj (JacobianOfSpatialJacobian) in-place and remove jsj1 #891

Merged
merged 1 commit into from
May 11, 2023

Conversation

N-Dekker
Copy link
Member

@N-Dekker N-Dekker commented May 11, 2023

Used modern C++ range-based for loops to iterate over the matrices of jsj, in both GetJacobianOfSpatialJacobianUseComposition overloads. Reduced dynamic memory usage by removing jsj1 in those two cases.

Follow-up to pull request #890 commit b9ea3a8


This commit appears to make the registration part of itkElastixRegistrationMethodTest ~5% faster, going from ~33 seconds to 32-31 seconds on my PC. Timeouts of itkElastixRegistrationMethodTest at the CI of ITKElastix are a showstopper right now.

Update: I just tested the very same registration with elastix 5.1.0 (released last January) as well and it's ~34 seconds, so slightly slower than the current revision from main. Which is cool 😃

Used modern C++ range-based `for` loops to iterate over the matrices of `jsj`, in both `GetJacobianOfSpatialJacobianUseComposition` overloads. Reduced dynamic memory usage by removing `jsj1` in those two cases.

Follow-up to pull request #890 commit b9ea3a8
@N-Dekker N-Dekker requested review from mstaring and stefanklein May 11, 2023 09:41
m_InitialTransform->GetSpatialJacobian(inputPoint, sj0);
m_CurrentTransform->GetJacobianOfSpatialJacobian(
m_InitialTransform->TransformPoint(inputPoint), jsj1, nonZeroJacobianIndices);
m_InitialTransform->TransformPoint(inputPoint), jsj, nonZeroJacobianIndices);

jsj.resize(nonZeroJacobianIndices.size());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This jsj.resize(nonZeroJacobianIndices.size()) may no longer be necessary, but it's hard for me decide, just by looking at those few lines of code.

@stefanklein
Copy link
Member

stefanklein commented May 11, 2023 via email

@N-Dekker
Copy link
Member Author

Sounds good, have you tested it in a case of B-spline transform with affine transform as initial transform, (in which case the matrix is quite big, so it is a good test case)?

Thanks @stefanklein I tested with the "default" sequence of parameter maps from ElastixRegistrationMethod, translation + affine + bspline:

defaultParameterObject->AddParameterMap(elx::ParameterObject::GetDefaultParameterMap("translation"));
defaultParameterObject->AddParameterMap(elx::ParameterObject::GetDefaultParameterMap("affine"));
defaultParameterObject->AddParameterMap(elx::ParameterObject::GetDefaultParameterMap("bspline"));
(Those default parameter maps are created by ParameterObject::GetDefaultParameterMap)

So I think it's a good test case indeed 😇 Although it is quite time consuming, even with this pull request.

@stefanklein
Copy link
Member

stefanklein commented May 11, 2023 via email

@N-Dekker N-Dekker merged commit ed15547 into main May 11, 2023
@N-Dekker N-Dekker deleted the Fill-jsj-in-place branch May 11, 2023 12:26
N-Dekker added a commit to N-Dekker/ITKElastix that referenced this pull request May 16, 2023
Including:

  pull request SuperElastix/elastix#891
  commit SuperElastix/elastix@ed15547
  "PERF: Fill `jsj` (JacobianOfSpatialJacobian) in-place and remove `jsj1`"

  pull request SuperElastix/elastix#890
  commit SuperElastix/elastix@b9ea3a8
  "PERF: Fill `jsh` (JacobianOfSpatialJacobian) in-place and remove `jsh1`"

  pull request SuperElastix/elastix#887
  commit SuperElastix/elastix@8298485
  PERF: Make EvaluateParzenValues calls faster, using raw buffer of values

  pull request SuperElastix/elastix#882
  commit SuperElastix/elastix@58e0a7b
  "ENH: Convert the input images to the user-specified internal pixel type"

  pull request SuperElastix/elastix#864
  commit SuperElastix/elastix@c3d478e
  "ENH: Upgrade elastix from C++14 to C++17"

  pull request SuperElastix/elastix#856
  commit SuperElastix/elastix@48c6458
  "ENH: Add SetInitialTransformParameterObject to ElastixRegistrationMethod"

  pull request SuperElastix/elastix#832
  commit SuperElastix/elastix@05d2b40
  ENH: Support "ShowProgressPercentage" parameter (`false` by default)

  pull request SuperElastix/elastix#815
  commit SuperElastix/elastix@c4ef707
  "ENH: Add `ElastixLogLevel` to the ITK interface"

Explicitly specified C++17 as standard for the compilation of ITKElastix.
N-Dekker added a commit to N-Dekker/ITKElastix that referenced this pull request May 16, 2023
Including:

  pull request SuperElastix/elastix#891
  commit SuperElastix/elastix@ed15547
  "PERF: Fill `jsj` (JacobianOfSpatialJacobian) in-place and remove `jsj1`"

  pull request SuperElastix/elastix#890
  commit SuperElastix/elastix@b9ea3a8
  "PERF: Fill `jsh` (JacobianOfSpatialJacobian) in-place and remove `jsh1`"

  pull request SuperElastix/elastix#887
  commit SuperElastix/elastix@8298485
  PERF: Make EvaluateParzenValues calls faster, using raw buffer of values

  pull request SuperElastix/elastix#882
  commit SuperElastix/elastix@58e0a7b
  "ENH: Convert the input images to the user-specified internal pixel type"

  pull request SuperElastix/elastix#864
  commit SuperElastix/elastix@c3d478e
  "ENH: Upgrade elastix from C++14 to C++17"

  pull request SuperElastix/elastix#856
  commit SuperElastix/elastix@48c6458
  "ENH: Add SetInitialTransformParameterObject to ElastixRegistrationMethod"

  pull request SuperElastix/elastix#832
  commit SuperElastix/elastix@05d2b40
  ENH: Support "ShowProgressPercentage" parameter (`false` by default)

  pull request SuperElastix/elastix#815
  commit SuperElastix/elastix@c4ef707
  "ENH: Add `ElastixLogLevel` to the ITK interface"

Explicitly specified C++17 as standard for the compilation of ITKElastix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants