Skip to content

WIP: ENH: Added type hints for wrapped Python classes and methods.#3

Closed
kian-weimer wants to merge 31 commits intohjmjohnson:masterfrom
kian-weimer:master
Closed

WIP: ENH: Added type hints for wrapped Python classes and methods.#3
kian-weimer wants to merge 31 commits intohjmjohnson:masterfrom
kian-weimer:master

Conversation

@kian-weimer
Copy link

This PR is a work in progress designed to produce class, method, and parameter type typehints for all ITK classes (or as many as possible).

While the current implementation works in general, there are many edge cases that are not yet covered.

This PR currently includes several ITK commits that have occurred recently.

N-Dekker and others added 30 commits September 5, 2021 11:13
Equivalent to the existing `BSplineKernelFunction::Evaluate(u)` member
function. Allows writing faster code, because it is non-virtual, and
because it does not require the creation of a `BSplineKernelFunction`
object.
Removed the dynamically allocated `m_Kernel` data member from
`BSplineInterpolationWeightFunction` and replaced the virtual function
call `m_Kernel->Evaluate(x)` by a faster static member function call, to
the newly added `BSplineKernelFunction::FastEvaluate` member function.

May significantly improve the performance of
`BSplineInterpolationWeightFunction`.
…neKernelFunction-FastEvaluate

PERF: `BSplineKernelFunction::FastEvaluate(u)`: a faster way to evaluate BSplineKernelFunction
Co-authored-by: Gabriel A. Devenyi <gdevenyi@gmail.com>
Code extracted from:

    https://github.com/dzenanz/zlib-ng.git

at commit 547e8bc10654c89d3c41e1b0201fdaee35250606 (develop).
# By Zlib-ng Upstream
* upstream-zlib-ng:
  zlib-ng 2021-09-07 (547e8bc1)
Community discussion and voting converged TransformGeometryImageFilter
is a more accurate name for the operation.
…sformGeometryImageFilter

ENH: Rename ResampleInPlaceImage to TransformGeometryImageFilter
…e-bump

COMP: Bump KWStyle to address Boost warnings with GCC 11.2
Replaced `static_cast<TRealValueType>(x)` by `TRealValueType{ x }`,
following C++ Core Guidelines, August 19, 2021, "Don’t use static_cast
for arithmetic types", from
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-type-arithmeticcast

The syntax `TRealValueType{ x }` is more type-safe than
`static_cast<TRealValueType>(x)`, as it prevents against accidental
narrowing (lossy) conversions.

Also replaced `ZeroValue()` and `OneValue()` calls by the corresponding
`TRealValueType{ x }` syntax.
Replaced `itk::Array2D` by `itk::FixedArray`, used as private `TableType`
of `BSplineInterpolationWeightFunction`. This is the type of a table,
used internally by its `Evaluate` member function.

Declared this table `const`, and initialized the table by an in-class
default-member-initializer. Defaulted the default-constructor.

Follow-up to pull request InsightSoftwareConsortium#2712
commit bc7c5df
"PERF: Use FixedArray for BSplineBaseTransform ParameterIndexArrayType"
commit 9bf745b
"PERF: Use FixedArray for BSplineInterpolationWeightFunction OutputType"
It should be replaced by std::enable_if from STL.
…rapping

Avoid build errors when we wrap for 4-D images.
…ray-dimensions-4

BUG: Improve dimension-dependent BSplineInterpolationWeightFunction wrapping
GCC is not resolving `object->Superclass` in some cases even though the
definition is available and other compilers are resolving the
definition.

xref InsightSoftwareConsortium#2676
Add named pipeline inputs of InputImage and RigidTransform and use
macro to provide standard class methods from named inputs.

Removed unneeded m_OutputImage member variable.
The TransformGeometryImageFilter::GenerateData method was refactored
for correct pipeline behavior. The output Image's meta-data is
correctly modifed in the GenerateOutputInformation method, so that
down stream filters can uses the information. The composite pipeline
is not isolated from the inputs and output using the double graft
convention. However, only the bulk data pointer and buffered region
are copied to the output, as not to change the geometry information
previously set.
Enable not copying the input image's bulk pixel data by default.
Replace TransformGeometryImageFilter::SetRigidTransform with
SetTransform, while adding support for generic linear transform. The
Transform::ApplyToImageMetadata method is re-used for computation.
…geometry-superclass

COMP: Avoid Superclass type alias GCC compile errors
Some functionality has been moved to the igenerator.py file.
This code will add typehinting for all methods ran through the `generate_method` method.
Several C++ types are converted to their Python equavelent but many more still need to be converted.
@kian-weimer
Copy link
Author

A new PR was created from a different branch.

hjmjohnson pushed a commit that referenced this pull request Nov 7, 2021
…n metric

Fix uninitialized variable use in `ANTS` neighborhood correlation metric:
ensure that `fixedImageGradient` and `movingImageGradient` have valid
values before assigning them to the `scanMem` struct that scans over
images.

Fixes:
```
Run-Time Check Failure #3 - The variable 'fixedImageGradient' is being
used without being initialized.
```

The bug was affecting a number of tests in the
`ITKRegistrationMethodsv4Test` module.

Signaled at
https://open.cdash.org/viewTest.php?onlyfailed&buildid=7067466
and
https://open.cdash.org/viewTest.php?onlyfailed&buildid=7069241
hjmjohnson pushed a commit that referenced this pull request Nov 11, 2024
Found with thread sanitizer (TSan) running the `itkANTSNeighborhoodCorrelationImageToImageRegistrationTest` unit test.

There was already a `m_ANTSAssociateOnceFlag` flag for use with `std::call_once`, so I just used that in this place too (it's already used elsewhere).

Partial backtrace from TSan:

```
WARNING: ThreadSanitizer: data race (pid=79176)
  Write of size 8 at 0x000108f02240 by thread T2:
    #0 void itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader<itk::ThreadedIndexedContainerPartitioner, itk::ImageToImageMetricv4<itk::Image<double, 2u>, itk::Image<double, 2u>, itk::Image<double, 2u>, double, itk::DefaultImageToImageMetricTraitsv4<itk::Image<double, 2u>, itk::Image<double, 2u>, itk::Image<double, 2u>, double>>, itk::ANTSNeighborhoodCorrelationImageToImageMetricv4<itk::Image<double, 2u>, itk::Image<double, 2u>, itk::Image<double, 2u>, double, itk::DefaultImageToImageMetricTraitsv4<itk::Image<double, 2u>, itk::Image<double, 2u>, itk::Image<double, 2u>, double>>>::ThreadedExecution_impl<itk::ThreadedIndexedContainerPartitioner>(itk::IdentityHelper<itk::ThreadedIndexedContainerPartitioner>, itk::Index<2u> const&, unsigned int) itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.hxx:118 (ITKMetricsv4TestDriver:arm64+0x1004bfe50)
    #1 itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader<itk::ThreadedIndexedContainerPartitioner, itk::ImageToImageMetricv4<itk::Image<double, 2u>, itk::Image<double, 2u>, itk::Image<double, 2u>, double, itk::DefaultImageToImageMetricTraitsv4<itk::Image<double, 2u>, itk::Image<double, 2u>, itk::Image<double, 2u>, double>>, itk::ANTSNeighborhoodCorrelationImageToImageMetricv4<itk::Image<double, 2u>, itk::Image<double, 2u>, itk::Image<double, 2u>, double, itk::DefaultImageToImageMetricTraitsv4<itk::Image<double, 2u>, itk::Image<double, 2u>, itk::Image<double, 2u>, double>>>::ThreadedExecution(itk::Index<2u> const&, unsigned int) itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:235 (ITKMetricsv4TestDriver:arm64+0x1004bf9c0)
    #2 itk::DomainThreader<itk::ThreadedIndexedContainerPartitioner, itk::ImageToImageMetricv4<itk::Image<double, 2u>, itk::Image<double, 2u>, itk::Image<double, 2u>, double, itk::DefaultImageToImageMetricTraitsv4<itk::Image<double, 2u>, itk::Image<double, 2u>, itk::Image<double, 2u>, double>>>::ThreaderCallback(void*) itkDomainThreader.hxx:123 (ITKMetricsv4TestDriver:arm64+0x100259b6c)
    #3 std::__1::future<std::__1::invoke_result<void* (*&)(void*), itk::PoolMultiThreader::ThreadPoolInfoStruct*>::type> itk::ThreadPool::AddWork<void* (*&)(void*), itk::PoolMultiThreader::ThreadPoolInfoStruct*>(void* (*&)(void*), itk::PoolMultiThreader::ThreadPoolInfoStruct*&&)::'lambda'()::operator()() const itkThreadPool.h:92 (ITKMetricsv4TestDriver:arm64+0x1007d3228)
    #4 decltype(std::declval<void* (*&)(void*)>()(std::declval<itk::PoolMultiThreader::ThreadPoolInfoStruct*>())) std::__1::__invoke[abi:v160006]<std::__1::future<std::__1::invoke_result<void* (*&)(void*), itk::PoolMultiThreader::ThreadPoolInfoStruct*>::type> itk::ThreadPool::AddWork<void* (*&)(void*), itk::PoolMultiThreader::ThreadPoolInfoStruct*>(void* (*&)(void*), itk::PoolMultiThreader::ThreadPoolInfoStruct*&&)::'lambda'()&>(void* (*&)(void*), itk::PoolMultiThreader::ThreadPoolInfoStruct*&&) invoke.h:394 (ITKMetricsv4TestDriver:arm64+0x1007d31a4)

  Previous write of size 8 at 0x000108f02240 by thread T14:
    #0 void itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader<itk::ThreadedIndexedContainerPartitioner, itk::ImageToImageMetricv4<itk::Image<double, 2u>, itk::Image<double, 2u>, itk::Image<double, 2u>, double, itk::DefaultImageToImageMetricTraitsv4<itk::Image<double, 2u>, itk::Image<double, 2u>, itk::Image<double, 2u>, double>>, itk::ANTSNeighborhoodCorrelationImageToImageMetricv4<itk::Image<double, 2u>, itk::Image<double, 2u>, itk::Image<double, 2u>, double, itk::DefaultImageToImageMetricTraitsv4<itk::Image<double, 2u>, itk::Image<double, 2u>, itk::Image<double, 2u>, double>>>::ThreadedExecution_impl<itk::ThreadedIndexedContainerPartitioner>(itk::IdentityHelper<itk::ThreadedIndexedContainerPartitioner>, itk::Index<2u> const&, unsigned int) itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.hxx:118 (ITKMetricsv4TestDriver:arm64+0x1004bfe50)
    #1 itk::ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader<itk::ThreadedIndexedContainerPartitioner, itk::ImageToImageMetricv4<itk::Image<double, 2u>, itk::Image<double, 2u>, itk::Image<double, 2u>, double, itk::DefaultImageToImageMetricTraitsv4<itk::Image<double, 2u>, itk::Image<double, 2u>, itk::Image<double, 2u>, double>>, itk::ANTSNeighborhoodCorrelationImageToImageMetricv4<itk::Image<double, 2u>, itk::Image<double, 2u>, itk::Image<double, 2u>, double, itk::DefaultImageToImageMetricTraitsv4<itk::Image<double, 2u>, itk::Image<double, 2u>, itk::Image<double, 2u>, double>>>::ThreadedExecution(itk::Index<2u> const&, unsigned int) itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h:235 (ITKMetricsv4TestDriver:arm64+0x1004bf9c0)
    #2 itk::DomainThreader<itk::ThreadedIndexedContainerPartitioner, itk::ImageToImageMetricv4<itk::Image<double, 2u>, itk::Image<double, 2u>, itk::Image<double, 2u>, double, itk::DefaultImageToImageMetricTraitsv4<itk::Image<double, 2u>, itk::Image<double, 2u>, itk::Image<double, 2u>, double>>>::ThreaderCallback(void*) itkDomainThreader.hxx:123 (ITKMetricsv4TestDriver:arm64+0x100259b6c)
    #3 std::__1::future<std::__1::invoke_result<void* (*&)(void*), itk::PoolMultiThreader::ThreadPoolInfoStruct*>::type> itk::ThreadPool::AddWork<void* (*&)(void*), itk::PoolMultiThreader::ThreadPoolInfoStruct*>(void* (*&)(void*), itk::PoolMultiThreader::ThreadPoolInfoStruct*&&)::'lambda'()::operator()() const itkThreadPool.h:92 (ITKMetricsv4TestDriver:arm64+0x1007d3228)
    #4 decltype(std::declval<void* (*&)(void*)>()(std::declval<itk::PoolMultiThreader::ThreadPoolInfoStruct*>())) std::__1::__invoke[abi:v160006]<std::__1::future<std::__1::invoke_result<void* (*&)(void*), itk::PoolMultiThreader::ThreadPoolInfoStruct*>::type> itk::ThreadPool::AddWork<void* (*&)(void*), itk::PoolMultiThreader::ThreadPoolInfoStruct*>(void* (*&)(void*), itk::PoolMultiThreader::ThreadPoolInfoStruct*&&)::'lambda'()&>(void* (*&)(void*), itk::PoolMultiThreader::ThreadPoolInfoStruct*&&) invoke.h:394 (ITKMetricsv4TestDriver:arm64+0x1007d31a4)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants