From 5fe01237ea325dcdfe2190ad72c5d1d15094b5a7 Mon Sep 17 00:00:00 2001 From: thatdudegrantt Date: Mon, 18 May 2026 18:44:10 -0400 Subject: [PATCH 1/2] fix: guard size_t template specializations for Win64 On 64-bit Windows, size_t and uint64_t are the same underlying type, causing duplicate explicit template specialization errors when building the MATLAB wrapper. Guard both wrap and unwrap with #if !defined(_WIN64) || defined(__CUDACC__). this is because gtsam/wrap inherits from the wrap repository. Successfully locally tested the change in gtsam/wrap/matlab.h, and then migrating to truly make the change. I will be more careful about this in the future. --- matlab.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/matlab.h b/matlab.h index 5c7cf7a..61c786c 100644 --- a/matlab.h +++ b/matlab.h @@ -159,13 +159,15 @@ mxArray* wrap(const bool& value) { return result; } -// specialization to size_t +// specialization to size_t but skip Win64 size check & CUDACC check +#if !defined(_WIN64) || defined(__CUDACC__) template<> mxArray* wrap(const size_t& value) { mxArray *result = scalar(mxUINT32OR64_CLASS); *(size_t*)mxGetData(result) = value; return result; } +#endif // specialization to int template<> @@ -345,12 +347,14 @@ uint64_t unwrap(const mxArray* array) { return myGetScalar(array); } -// specialization to size_t +// specialization to size_t but skip Win64 size check (size_t == uint64_t) & CUDACC check +#if !defined(_WIN64) || defined(__CUDACC__) template<> size_t unwrap(const mxArray* array) { checkScalar(array, "unwrap"); return myGetScalar(array); } +#endif // specialization to double template<> From b330797beb5861e81f3c789812250bcb5043186a Mon Sep 17 00:00:00 2001 From: Grant Polazzo Date: Fri, 22 May 2026 13:54:24 -0400 Subject: [PATCH 2/2] Updating comments on copilot's suggestion Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- matlab.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/matlab.h b/matlab.h index 61c786c..e7d7df9 100644 --- a/matlab.h +++ b/matlab.h @@ -347,7 +347,9 @@ uint64_t unwrap(const mxArray* array) { return myGetScalar(array); } -// specialization to size_t but skip Win64 size check (size_t == uint64_t) & CUDACC check +// specialization to size_t; omit it on Win64 because size_t is uint64_t there +// and would duplicate unwrap. The __CUDACC__ case intentionally +// bypasses the Win64 guard when compiling with CUDA. #if !defined(_WIN64) || defined(__CUDACC__) template<> size_t unwrap(const mxArray* array) {