Skip to content

WIP: PERF: Call tensorstoreToITKComponentType at compile-time, by constexpr (supersedes #68) - #81

Draft
hjmjohnson wants to merge 5 commits into
InsightSoftwareConsortium:mainfrom
hjmjohnson:takeover-68-constexpr
Draft

hjmjohnson wants to merge 5 commits into
InsightSoftwareConsortium:mainfrom
hjmjohnson:takeover-68-constexpr

Conversation

@hjmjohnson

@hjmjohnson hjmjohnson commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Blocked: this does not compile with the TensorStore pinned on main (a 2023 commit). GCC reports tensorstore::dtype_v<T> as "not usable in a constant expression" (MakeDataTypeOperations<...>::operations), so the Ubuntu build fails. It needs a newer TensorStore, which is why #74 was opened as "triggered by #68". Not to be merged until that update lands.

Evaluates the conversion of each supported pixel type to an ITK component type at compile-time, with constexpr. This takes over #68 by Niels Dekker, updated for the TypeList code that replaced the macros his second commit edited. The branch includes the commits of #78, which it builds on.

What changes
  • tensorstoreToITKComponentType and itkToTensorstoreComponentType are declared constexpr (Niels Dekker's first commit, unchanged).
  • A variable template toITKComponentType<T> forces compile-time evaluation, and ReadFromStoreIfTypesMatch and WriteToStoreIfTypesMatch use it instead of calling the function with tensorstore::dtype_v<TPixel> on each attempt. His second commit did the same inside the READ_ELEMENT_IF and ELEMENT_WRITE macros, which no longer exist on main.
  • The runtime call in ReadArrayMetadata, where the dtype comes from the file, is unchanged.
Testing

Built and ran locally on macOS arm64 (Release) against a TensorStore updated to v0.1.86: the module builds and its 15 tests pass. CI on the TensorStore pin from main fails on GCC, as described above; that is the expected outcome of this change on that pin. The file is clean under the repository's clang-format.

AI assistance
  • Tool: Claude Code (claude-opus-5-5)
  • Role: ported the second commit to the current code, rebased the branch, and built and ran the tests. A person reviewed the result.

GitHub retired the macos-13 runner image and retires macos-14 on
November 2, 2026 (actions/runner-images#13518). Use macos-15-intel and
macos-15 with Xcode 16.2, matching ITKRemoteModuleBuildTestPackageAction;
the Xcode 14.3.1 and 15.0.1 selections do not exist on those images.

Xcode 16 reports new ranlib and ld warnings for the bundled third-party
libraries, and the dashboard script fails on any warning, so add them to
the warning exceptions.
hjmjohnson and others added 4 commits November 3, 2026 15:51
The prebuilt ITK 5.4.0 Python build that the macOS wheel jobs download
was made on Xcode 15.0.1, and its build.ninja names that SDK's
libiconv.tbd, which the macos-15 image does not have. The 5.4.7 build
and ITKPythonPackage scripts exist, and later 5.4 releases build with
Xcode 16.2 in ITKRemoteModuleBuildTestPackageAction, so move the ITK
checkout, the wheel build, and the packaging scripts together.

The 5.4.7 wheels cover Python 3.9 to 3.11 only, so drop 3.8 from the
Linux and Windows wheel matrices, remove the macOS steps that skipped
3.8, and require Python 3.9.
GitHub is forcing the Node 20 actions onto Node 24. Use the versions that
ITKRemoteModuleBuildTestPackageAction uses for checkout, setup-python,
get-cmake, upload-artifact, and download-artifact.
Following Scott Meyers, Effective Modern C++, 2014, "Use `constexpr` whenever possible".
A variable template makes the compiler evaluate the conversion of each
supported pixel type to an ITK component type at compile-time, instead
of calling the function each time a read or write tries a pixel type.
@hjmjohnson
hjmjohnson force-pushed the takeover-68-constexpr branch from cd1f4c7 to 0828703 Compare November 3, 2026 21:51
@hjmjohnson hjmjohnson changed the title PERF: Call tensorstoreToITKComponentType at compile-time, by constexpr (supersedes #68) WIP: PERF: Call tensorstoreToITKComponentType at compile-time, by constexpr (supersedes #68) Nov 3, 2026
@hjmjohnson

Copy link
Copy Markdown
Member Author

Marked WIP: build-test-cxx (ubuntu-22.04) fails because tensorstore::dtype_v<T> is not usable in a constant expression with the TensorStore pinned on main. The change compiled locally only against a newer TensorStore, which is a correction to the testing note I first wrote. It stays blocked until the module moves to a TensorStore where dtype_v is constexpr.

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