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

Use string literals in fixed_point release_asserts #7303

Merged
merged 5 commits into from
Feb 4, 2021
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
34 changes: 8 additions & 26 deletions cpp/include/cudf/fixed_point/fixed_point.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, NVIDIA CORPORATION.
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,6 +25,7 @@
#include <cuda/std/type_traits> // add cuda namespace

#include <algorithm>
#include <cassert>
#include <cmath>
#include <string>

Expand Down Expand Up @@ -550,22 +551,6 @@ class fixed_point {
}
}; // namespace numeric

/** @brief Function that converts Rep to `std::string`
*
* @tparam Rep Representation type
* @return String-ified Rep
*/
template <typename Rep>
std::string print_rep()
{
if (cuda::std::is_same<Rep, int32_t>::value)
return "int32_t";
else if (cuda::std::is_same<Rep, int64_t>::value)
return "int64_t";
else
return "unknown type";
}

/** @brief Function for identifying integer overflow when adding
*
* @tparam Rep Type of integer to check for overflow on
Expand Down Expand Up @@ -641,8 +626,8 @@ CUDA_HOST_DEVICE_CALLABLE fixed_point<Rep1, Rad1> operator+(fixed_point<Rep1, Ra

#if defined(__CUDACC_DEBUG__)

release_assert(!addition_overflow<Rep1>(lhs.rescaled(scale)._value, rhs.rescaled(scale)._value) &&
"fixed_point overflow of underlying representation type " + print_rep<Rep1>());
assert(!addition_overflow<Rep1>(lhs.rescaled(scale)._value, rhs.rescaled(scale)._value) &&
"fixed_point overflow");

#endif

Expand All @@ -659,9 +644,8 @@ CUDA_HOST_DEVICE_CALLABLE fixed_point<Rep1, Rad1> operator-(fixed_point<Rep1, Ra

#if defined(__CUDACC_DEBUG__)

release_assert(
!subtraction_overflow<Rep1>(lhs.rescaled(scale)._value, rhs.rescaled(scale)._value) &&
"fixed_point overflow of underlying representation type " + print_rep<Rep1>());
assert(!subtraction_overflow<Rep1>(lhs.rescaled(scale)._value, rhs.rescaled(scale)._value) &&
"fixed_point overflow");

#endif

Expand All @@ -675,8 +659,7 @@ CUDA_HOST_DEVICE_CALLABLE fixed_point<Rep1, Rad1> operator*(fixed_point<Rep1, Ra
{
#if defined(__CUDACC_DEBUG__)

release_assert(!multiplication_overflow<Rep1>(lhs._value, rhs._value) &&
"fixed_point overflow of underlying representation type " + print_rep<Rep1>());
assert(!multiplication_overflow<Rep1>(lhs._value, rhs._value) && "fixed_point overflow");

#endif

Expand All @@ -691,8 +674,7 @@ CUDA_HOST_DEVICE_CALLABLE fixed_point<Rep1, Rad1> operator/(fixed_point<Rep1, Ra
{
#if defined(__CUDACC_DEBUG__)

release_assert(!division_overflow<Rep1>(lhs._value, rhs._value) &&
"fixed_point overflow of underlying representation type " + print_rep<Rep1>());
assert(!division_overflow<Rep1>(lhs._value, rhs._value) && "fixed_point overflow");

#endif

Expand Down