Skip to content
New issue

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

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

Already on GitHub? # to your account

PERF: Speed up ComputeJacobianTerms access to vnl_sparse_matrix #959

Merged
merged 1 commit into from
Sep 1, 2023

Conversation

N-Dekker
Copy link
Member

@N-Dekker N-Dekker commented Sep 1, 2023

Added getCovariance lambda as a faster alternative to vnl_sparse_matrix::operator()(unsigned int, unsigned int). Replaced cov(r, c) calls with getCovariance(r, c).

getCovariance offers constant-time access to the back of each row. It adds a columns to the end of the row without having to iterate over the entire row. Moreover, when iteration over the entire row is really necessary, it has a simpler loop condition, compared to vnl_sparse_matrix::operator(): (it->first < c) rather than (ri != rw.end()) && ((*ri).first < c).

Comparison based on the vnl_sparse_matrix::operator() implementation at https://github.com/InsightSoftwareConsortium/ITK/blob/36d2c5ac368cf7917d8e73806c6eaa1f195b85c1/Modules/ThirdParty/VNL/src/vxl/core/vnl/vnl_sparse_matrix.hxx#L411-L426

Related pull request: vxl/vxl#926 "PERF: Speed up vnl_sparse_matrix::operator()"

Added `getCovariance` lambda as a faster alternative to `vnl_sparse_matrix::operator()(unsigned int, unsigned int)`. Replaced `cov(r, c)` calls with `getCovariance(r, c)`.

`getCovariance` offers constant-time access to the back of each row. It adds a columns to the end of the row without having to iterate over the entire row. Moreover, when iteration over the entire row is really necessary, it has a simpler loop condition, compared to `vnl_sparse_matrix::operator()`: `(it->first < c)` rather than `(ri != rw.end()) && ((*ri).first < c)`.

Comparison based on the `vnl_sparse_matrix::operator()` implementation at
https://github.com/InsightSoftwareConsortium/ITK/blob/36d2c5ac368cf7917d8e73806c6eaa1f195b85c1/Modules/ThirdParty/VNL/src/vxl/core/vnl/vnl_sparse_matrix.hxx#L411-L426

Related pull request: vxl/vxl#926 "PERF: Speed up `vnl_sparse_matrix::operator()`"
@N-Dekker
Copy link
Member Author

N-Dekker commented Sep 1, 2023

The CI failures seem unrelated to the code changes:

Error when uploading file: D:/a/elastix/elastix/Elastix-build/Testing/20230901-1317/Configure.xml
Error message was: Could not resolve host: my.cdash.org
Problems when submitting via HTTP

@N-Dekker N-Dekker merged commit 3979978 into main Sep 1, 2023
@N-Dekker N-Dekker deleted the Faster-Covariance branch September 1, 2023 16:50
N-Dekker added a commit to N-Dekker/ITKElastix that referenced this pull request Sep 15, 2023
Supports passing a transform retrieved by `GetCombinationTransform()` or
`GetNthTransform(n)` to `ConvertToItkTransform`, when an _external_ initial
transform was specified before running the registration.

Also including various performance improvements.

Including:

  pull request SuperElastix/elastix#946
  commit SuperElastix/elastix@7bcb2b3
  ENH: Write external initial transforms to ITK transform file

  pull request SuperElastix/elastix#949
  commit SuperElastix/elastix@601f465
  ENH: `ConvertToItkTransform` should support external initial transform

  pull request SuperElastix/elastix#950
  commit SuperElastix/elastix@7e883bf
  ENH: Add GetInitialTransform() and GetExternalInitialTransform()

  pull request SuperElastix/elastix#959
  commit SuperElastix/elastix@3979978
  PERF: Speed up ComputeJacobianTerms access to `vnl_sparse_matrix`

  pull request SuperElastix/elastix#960
  commit SuperElastix/elastix@4d028f7
  PERF: Speed up full, grid, sparse mask samplers by a local sampleVector
N-Dekker added a commit to N-Dekker/ITKElastix that referenced this pull request Sep 18, 2023
Supports passing a transform retrieved by `GetCombinationTransform()` or
`GetNthTransform(n)` to `ConvertToItkTransform`, when an _external_ initial
transform was specified before running the registration.

Also including various performance improvements.

Including:

  pull request SuperElastix/elastix#946
  commit SuperElastix/elastix@7bcb2b3
  ENH: Write external initial transforms to ITK transform file

  pull request SuperElastix/elastix#949
  commit SuperElastix/elastix@601f465
  ENH: `ConvertToItkTransform` should support external initial transform

  pull request SuperElastix/elastix#950
  commit SuperElastix/elastix@7e883bf
  ENH: Add GetInitialTransform() and GetExternalInitialTransform()

  pull request SuperElastix/elastix#959
  commit SuperElastix/elastix@3979978
  PERF: Speed up ComputeJacobianTerms access to `vnl_sparse_matrix`

  pull request SuperElastix/elastix#960
  commit SuperElastix/elastix@4d028f7
  PERF: Speed up full, grid, sparse mask samplers by a local sampleVector
dzenanz pushed a commit to InsightSoftwareConsortium/ITKElastix that referenced this pull request Sep 19, 2023
Supports passing a transform retrieved by `GetCombinationTransform()` or
`GetNthTransform(n)` to `ConvertToItkTransform`, when an _external_ initial
transform was specified before running the registration.

Also including various performance improvements.

Including:

  pull request SuperElastix/elastix#946
  commit SuperElastix/elastix@7bcb2b3
  ENH: Write external initial transforms to ITK transform file

  pull request SuperElastix/elastix#949
  commit SuperElastix/elastix@601f465
  ENH: `ConvertToItkTransform` should support external initial transform

  pull request SuperElastix/elastix#950
  commit SuperElastix/elastix@7e883bf
  ENH: Add GetInitialTransform() and GetExternalInitialTransform()

  pull request SuperElastix/elastix#959
  commit SuperElastix/elastix@3979978
  PERF: Speed up ComputeJacobianTerms access to `vnl_sparse_matrix`

  pull request SuperElastix/elastix#960
  commit SuperElastix/elastix@4d028f7
  PERF: Speed up full, grid, sparse mask samplers by a local sampleVector
N-Dekker added a commit that referenced this pull request Jul 2, 2024
- Now that pull request vxl/vxl#926 commit vxl/vxl@653919f "PERF: Speed up `vnl_sparse_matrix::operator()`" is merged, it appears no longer useful to maintain our own `getCovariance` alternative.

This reverts pull request #959 commit 3979978 "PERF: Speed up ComputeJacobianTerms access to `vnl_sparse_matrix`"
N-Dekker added a commit that referenced this pull request Jul 3, 2024
- Now that pull request vxl/vxl#926 commit vxl/vxl@653919f "PERF: Speed up `vnl_sparse_matrix::operator()`" is merged, it appears no longer useful to maintain our own `getCovariance` alternative.

This reverts pull request #959 commit 3979978 "PERF: Speed up ComputeJacobianTerms access to `vnl_sparse_matrix`"
N-Dekker added a commit that referenced this pull request Jul 3, 2024
- Now that pull request vxl/vxl#926 commit vxl/vxl@653919f "PERF: Speed up `vnl_sparse_matrix::operator()`" is merged, it appears no longer useful to maintain our own `getCovariance` alternative.

This reverts pull request #959 commit 3979978 "PERF: Speed up ComputeJacobianTerms access to `vnl_sparse_matrix`"
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant