Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for C4146 Error in CPUNegElementKernel with Unsigned Types #6534

Merged
merged 2 commits into from
Dec 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions cpp/open3d/core/kernel/UnaryEWCPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,20 @@ static void CPUCosElementKernel(const void* src, void* dst) {
static_cast<scalar_t>(std::cos(*static_cast<const scalar_t*>(src)));
}

template <typename scalar_t>
template <typename scalar_t,
typename std::enable_if<std::is_integral<scalar_t>::value,
int>::type = 0>
static void CPUNegElementKernel(const void* src, void* dst) {
*static_cast<scalar_t*>(dst) =
static_cast<scalar_t>(-*static_cast<const scalar_t*>(src));
using signed_scalar_t = std::make_signed_t<scalar_t>;
*static_cast<scalar_t*>(dst) = static_cast<scalar_t>(
-static_cast<signed_scalar_t>(*static_cast<const scalar_t*>(src)));
}

template <typename scalar_t,
typename std::enable_if<!std::is_integral<scalar_t>::value,
int>::type = 0>
static void CPUNegElementKernel(const void* src, void* dst) {
*static_cast<scalar_t*>(dst) = -*static_cast<const scalar_t*>(src);
}

template <typename scalar_t>
Expand Down