Repository navigation
Description
Description
When building nav2_mppi_controller from source on macOS (Tahoe, Apple Silicon ARM64) for the ROS 2 Humble distribution, the build fails during compilation of optimizer.cpp and related motion model files.
The issue is triggered by the interaction between xtensor v0.25.0 and Apple Clang (17.0+), resulting in ambiguous template specialization errors.
The Problem
The core failure originates in xtensor's internal template metaprogramming, specifically when rebinding internal storage containers such as xt::svector.
Apple Clang cannot distinguish between long and unsigned long during partial template specialization, resulting in:
Upstream Reference (Ongoing Issue)
This build failure appears to be related to an existing xtensor issue concerning ambiguous partial template specializations on Apple Clang:
The Error
clang++: warning: argument unused during compilation: '-msse4.2' [-Wunused-command-line-argument]
In file included from <workspace>/src/navigation2/nav2_mppi_controller/src/optimizer.cpp:15:
In file included from <workspace>/src/navigation2/nav2_mppi_controller/include/nav2_mppi_controller/optimizer.hpp:21:
In file included from <install>/include/xtensor/xtensor.hpp:19:
In file included from <install>/include/xtensor/xbuffer_adaptor.hpp:21:
In file included from <install>/include/xtensor/xstorage.hpp:23:
In file included from <install>/include/xtensor/xtensor_simd.hpp:17:
<install>/include/xtensor/xutils.hpp:896:31: error: ambiguous partial specializations of 'rebind_container<long, xt::svector<unsigned long>>'
using type = typename rebind_container<std::ptrdiff_t, S>::type;
^
<install>/include/xtensor/xutils.hpp:883:12: note: partial specialization matches [with X = long, C = xt::svector, T = unsigned long, N = 4]
struct rebind_container<X, C<T, N>>
^
<install>/include/xtensor/xstorage.hpp:1415:12: note: partial specialization matches [with X = long, T = unsigned long, N = 4, A = std::allocator<unsigned long>, B = true]
struct rebind_container<X, svector<T, N, A, B>>
^
[...]
<install>/include/xtensor/xiterable.hpp:45:50: error: no type named 'stepper' in
'xt::xiterable_inner_types<
xt::xarray_container<
xt::uvector<float, xsimd::aligned_allocator<float>>,
xt::layout_type::row_major,
xt::svector<unsigned long>
>
>'
<install>/include/xtensor/xcontainer.hpp:140:15: error: using declaration refers into
'accessible_base::', which is not a base class of
'xcontainer<
xt::xarray_container<
xt::uvector<float, xsimd::aligned_allocator<float>>,
xt::layout_type::row_major,
xt::svector<unsigned long>
>
>'
[...]
<install>/include/xtensor/xmath.hpp:2288:16: note: in instantiation of function template specialization
'xt::accumulate<...>' requested here
<src>/navigation2/nav2_mppi_controller/src/optimizer.cpp:344:9: note:
in instantiation of function template specialization
'xt::cumsum<void, xt::xfunction<...>>' requested here
xt::cumsum(state.wz * settings_.model_dt, 1) + initial_yaw;
^
<src>/navigation2/nav2_mppi_controller/src/optimizer.cpp:364:5: error: no matching function for call to 'cumsum'
xt::cumsum(dx * settings_.model_dt, 1);
^
<src>/navigation2/nav2_mppi_controller/src/optimizer.cpp:366:5: error: no matching function for call to 'cumsum'
xt::cumsum(dy * settings_.model_dt, 1);
^
14 errors generated.
make[2]: *** [CMakeFiles/mppi_controller.dir/src/optimizer.cpp.o] Error 1
make[1]: *** [CMakeFiles/mppi_controller.dir/all] Error 2
make: *** [all] Error 2
make: INTERNAL: Exiting with 9 jobserver tokens available; should be 8!Affected Components
xt::cumsum- Fails during trajectory integration.
xt::masked_view- Breaks in vehicle constraint applications.
xt::xarray- Recursive template instantiation failures due to dynamic rank deduction.
Root Cause Analysis
1️⃣ Type Ambiguity on macOS
On Darwin systems, size_t may resolve to types that match multiple template specializations simultaneously (long vs unsigned long).
2️⃣ Dynamic Rank Complexity
xt::xarray relies on runtime dimensionality tracking, increasing template recursion depth and exposing Clang’s strict specialization resolution behavior.
3️⃣ Apple Clang Strictness
Apple Clang enforces stricter template specialization resolution compared to GCC, exposing ambiguity in xtensor 0.25.0.
Temp Solution
Commit: idesign0@edce854
Environment
- ROS 2 Distro: Humble
- OS: macOS 26.3 (25D125) — Apple Silicon (ARM64)
- Compiler: Apple Clang 17.0.0 (clang-1700.6.4.2)
- Target: arm64-apple-darwin25.3.0
- Toolchain: XcodeDefault.xctoolchain
- xtensor Version: 0.25.0
Activity
[-][Humble] Build Failure in nav2_mppi_controller on macOS (Apple Clang xtensor template ambiguity)[/-][+][Humble][macOS] Build Failure in nav2_mppi_controller on macOS (Apple Clang xtensor template ambiguity)[/+]SteveMacenski commentedon Mar 4, 2026
Thanks for the report. Sounds like it may have been fixed in xtensor-stack/xtensor#2833 but I assume that's not the apt version (nor going to be released on your OS? Not sure).
In terms of your fixes: have you done apples to apples benchmark to see what the impact on performance is?
What I'd suggest, if you need this on Apple hardware:
nav2_mppi_controller/include/nav2_mppi_controller/motion_models.hppchecking for apple -- unless your method is actually faster either way (then we can just convert to yours)nav2_mppi_controller/include/nav2_mppi_controller/tools/utils.hpp, which I assume are negligible. If so, we can keep those suggested changes.That would be the least intrusive solution in my opinion :-)
idesign0 commentedon Mar 4, 2026
@SteveMacenski
Thank you for the detailed suggestions.
I haven’t performed any performance benchmarking yet, so I can’t comment on the performance impact of the changes at this stage. I’ll incorporate the modifications as you suggested.
I haven’t done structured performance benchmarking in this context before, so any guidance on recommended tools, metrics, or benchmarking methodology for nav2_mppi_controller would be greatly appreciated.
I’ll get back to you with results and further observations.
SteveMacenski commentedon Mar 4, 2026
If you add some timers for individual functions that can help. Otherwise full optimization run timers are builtin and just need to uncomment this line https://github.com/ros-navigation/navigation2/blob/main/nav2_mppi_controller/src/controller.cpp#L20 to print results (still need to capture/get some statistics from them though).
This is highly optimized on the compiler, so doing debug mode with gdb will not yield meaningful metrics. Calling your version and the default version in a loop of 1000000 times and recording the times is as good as anything.
idesign0 commentedon Mar 5, 2026
@SteveMacenski
Update: Performance Benchmarks and Refactored Implementation
Following the suggestion for a "least intrusive" fix, I have refactored the temp solution to isolate Apple-specific workarounds and verified the performance impact.
Commit: idesign0@87f9c4d
Summary of Changes
apple_utils.hppcontaining manualcumsumimplementations to bypass thextensortemplate ambiguity on macOS.#ifdef __APPLE__inoptimizer.cpp,motion_models.hpp, andutils.hpp. This ensures the Linux/GCC build remains completely untouched, maintaining the originalxarrayandxt::cumsumpaths for non-Apple systems.utils.hpp, I applied fixed-rankxtensor<float, 1>strictly for Apple builds to assist the Clang compiler with type deduction, while keepingxarrayfor all other platforms.Performance Results (macOS ARM64)
I ran an "apples-to-apples" micro-benchmark comparing the manual implementation against
xt::cumsumusing a 100-step horizon over 1,000,000 iterations in Release mode (-O3).On the Apple Clang compiler, the manual loops significantly outperform the library templates:
xtensorBenchmark Compilation & Script
The benchmark was compiled using the following command:
clang++ -O3 -std=c++17 benchmark.cpp \ -I ~/humble-ros2/install/include \ -I ./include \ -o benchThe following script was used to generate these metrics:
SteveMacenski commentedon Mar 6, 2026
You may simply change to use
<float, 1>if it improves / remains the same performance (which I suspect one of the two is the case). You don't need to make it apple-specific.Can you move into the header of the optimizer a typedef for cumsum where we set one vs the other to use, rather than putting this into the code itself (in many places)?
Otherwise, can you open a PR for all of this? I tihnk that's it and I can merge that 👍
How did you test it if it doesn't compile on macOS?
idesign0 commentedon Mar 7, 2026
@SteveMacenski
Thanks for the suggestions; I will make the changes.
Regarding testing, you are correct—the full project does not compile with xt::cumsum on macOS. I obtained the original benchmark figures using an isolated script that bypasses the complex template headers of the full Nav2 environment. You can review the details under the Benchmark Compilation & Script section of my previous response.
i will make the PR and Target the humble branch soon.
SteveMacenski commentedon Mar 7, 2026
It needs to target the main branch as well if you want this reflected in new ROS distros over time. Its OK to also have humble, but main’s important as well
idesign0 commentedon Mar 7, 2026
@SteveMacenski
Thanks for the clarification.
From looking at the code, it seems the part I’m modifying (related to the xtensor dependency) isn’t present in newer distros like Kilted. As I also manage Kilted for macOS, I don’t see any issue there with nav2_mppi_controller.
I did try targeting main, but GitHub showed a “merge not possible” message in the PR dialog. I’ll check main again and see what adjustments are needed so it can be targeted there as well.
SteveMacenski commentedon Mar 9, 2026
Oh got it - for the MPPI changes we use Eigen now so that may not be required at all then.