Repository navigation
Conversation
Static strides were represented as integral_constant<std::size_t, ...>. A compile-time shift by a negative offset along such a dimension then evaluates stride * offset in unsigned arithmetic, which cannot be narrowed to int_t, so no sid::shift overload is viable and compilation fails. Represent static strides as integral_constant<std::ptrdiff_t, ...> and add a regression test. See GridTools/gt4py#3071. Co-Authored-By: Claude <noreply@anthropic.com>
Collaborator
|
Hi there, this is jenkins continuous integration... |
edopao
commented
Dec 3, 2026
| return gridtools::integral_constant<std::size_t, SpecValue>{}; | ||
| // A signed type is needed: with an unsigned static stride, a compile-time shift | ||
| // by a negative offset overflows and no `sid::shift` overload is viable. | ||
| return gridtools::integral_constant<std::ptrdiff_t, SpecValue>{}; |
Author
There was a problem hiding this comment.
I see above you defined array_size_t. Should I define a type like below?
#if NB_VERSION_MAJOR >= 2
using array_stride_t = nanobind::ssize_t;
#else
using array_stride_t = std::ptrdiff_t;
#endif
Author
|
cscs-ci run default |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
nanobind_adapter.hpprepresents static strides asintegral_constant<std::size_t, ...>. A compile-time shift by a negative offset along such a dimension computesstride * offsetin unsigned arithmetic insid::shift:The value cannot be narrowed to
int_t, so every compile-timeshiftoverload is discarded and the call fails withno matching function for call to 'shift'.This blocks gt4py from passing static unit strides on Cartesian grids: a backward neighbor access such as
a(I - 1)lowers to a shift byintegral_constant<int, -1>, see GridTools/gt4py#3071.Standalone reproducer, using only GridTools headers:
Fix
Represent static strides as
integral_constant<std::ptrdiff_t, ...>. Dynamic strides are unchanged.Test
New
NanobindAdapterStaticStridesNegativeShifttest: builds a SID withstride_spec<1, -1>, checks that the static stride type is signed, and shifts byintegral_constant<int, -1>. Without the fix it fails to compile with the error above; with the fix all nanobind adapter tests pass.Note: I ran the tests locally on macOS with
std::int64_tinstead ofstd::intptr_tfor the test strides. nanobind 2.1 takesconst int64_t *strides, andstd::intptr_t(long) does not convert to it on macOS. This affects the existing tests too; on Linux both are the same type.