Math wrappers
Note
The C++ API provides RAII wrappers around the C API. For detailed documentation including parameters, return values, and limitations, please refer to the corresponding C API documentation.
-
enum class RoundMode : int
Values:
-
enumerator NEAREST
-
enumerator DOWN
-
enumerator UP
-
enumerator ZERO
-
enumerator DEFAULT
-
enumerator NEAREST
- template<RoundMode RM, typename T, typename U, class = Require<(!std::is_same_v<T, U>)&&((NumComponents<T> == NumComponents<U>) || (NumComponents<T> == 0 && HasTypeTraits<U>))>> inline __host__ __device__ auto round (U u)
Metafunction to round all elements of the input.
This function rounds all elements of the input and returns the result with the same type as the input. Optionally, the base type of the result may be specified by the template argument type
T. For instance, a float4 can have its 4 elements rounded into a float4 result, or to a different result type, such as T=int or T=int4, where the result will be int4 with the rounded results (see example below). Also optionally, the round modeRMcan be specified, as one of RoundMode, e.g. RoundMode::DOWN. It is a requirement of round that the input source type has type traits and the optional result typeTis either a regular C type or has the same number of components as the input type.using FloatType = MakeType<float, 4>; FloatType res = ...; FloatType float_rounded = round(res); ConvertBaseTypeTo<int, FloatType> int_rounded = round<int>(res);
- Template Parameters:
RM – Optional round mode to be used, cf. RoundMode.
U – Type of the source value (with 1 to 4 elements) passed as (and inferred from) argument
u.T – Optional type that defines the result of the round.
- Parameters:
u – [in] Source value to round all elements with its same type or
T.- Returns:
The value with all elements rounded.
- template<typename T, typename U, class = Require<(!std::is_same_v<T, U>)&&((NumComponents<T> == NumComponents<U>) || (NumComponents<T> == 0 && HasTypeTraits<U>))>> inline __host__ __device__ auto round (U u)
Overload of round function.
It does specifies target round type
Tand uses default round mode RoundMode::DEFAULT.
- template<RoundMode RM, typename U> inline __host__ __device__ auto round (U u)
Overload of round function.
It does not specify target round type
T, using input source typeUinstead.
- template<typename U> inline __host__ __device__ auto round (U u)
Overload of round function.
It does not specify target round type
T, using input source typeUinstead, and uses default round mode RoundMode::DEFAULT.
- template<typename U, class = Require<HasTypeTraits<U>>> inline __host__ __device__ U min (U a, U b)
Metafunction to compute the minimum of two inputs per element.
This function finds the minimum of two inputs per element and returns the result with the same type as the input. For instance, two int4 inputs {1, 2, 3, 4} and {4, 3, 2, 1} yield the minimum {1, 2, 2, 1} as int4 as well (see example below). It is a requirement of min that the input source type has type traits.
using IntType = MakeType<int, 4>; IntType a = {1, 2, 3, 4}, b = {4, 3, 2, 1}; IntType ab_min = min(a, b); // = {1, 2, 2, 1}
- Template Parameters:
U – Type of the two source arguments and the return type.
- Parameters:
u – [in] Input value to compute \( min(x_a, x_b) \) where \( x_a \) ( \( x_b \)) is each element of \( a \) ( \( b \)).
- Returns:
The return value with one minimum per element.
- template<typename U, class = Require<HasTypeTraits<U>>> inline __host__ __device__ U max (U a, U b)
Metafunction to compute the maximum of two inputs per element.
This function finds the maximum of two inputs per element and returns the result with the same type as the input. For instance, two int4 inputs {1, 2, 3, 4} and {4, 3, 2, 1} yield the maximum {4, 3, 3, 4} as int4 as well (see example below). It is a requirement of max that the input source type has type traits.
using IntType = MakeType<int, 4>; IntType a = {1, 2, 3, 4}, b = {4, 3, 2, 1}; IntType ab_max = max(a, b); // = {4, 3, 3, 4}
- Template Parameters:
U – Type of the two source arguments and the return type.
- Parameters:
u – [in] Input value to compute \( max(x_a, x_b) \) where \( x_a \) ( \( x_b \)) is each element of \( a \) ( \( b \)).
- Returns:
The return value with maximums per element.
- template<typename U, typename S, class = Require<(NumComponents<U> == NumComponents<S>) || (HasTypeTraits<U> && NumComponents<S> == 0)>> inline __host__ __device__ U pow (U x, S y)
Metafunction to compute the power of all elements of the input.
This function computes the power of all elements of the input
xand returns the result with the same type as the input. It is a requirement of pow that the inputxhas the same number of components of the poweryoryis a scalar (and the type ofxhas type traits).- Template Parameters:
U – Type of the source argument
xand the return type.S – Type of the source argument
ypower (use a regular C type for scalar).
- Parameters:
x – [in] Input value to compute \( x^y \).
y – [in] Input power to compute \( x^y \).
- Returns:
The return value with all elements as the result of the power.
- template<typename U, class = Require<HasTypeTraits<U>>> inline __host__ __device__ U exp (U u)
Metafunction to compute the natural (base e) exponential of all elements of the input.
This function computes the natural (base e) exponential of all elements of the input and returns the result with the same type as the input. It is a requirement of exp that the input source type has type traits.
- Template Parameters:
U – Type of the source argument and the return type.
- Parameters:
u – [in] Input value to compute \( e^x \) where \( x \) is each element of \( u \).
- Returns:
The return value with all elements as the result of the natural (base e) exponential.
- template<typename U, class = Require<HasTypeTraits<U>>> inline __host__ __device__ U sqrt (U u)
Metafunction to compute the square root of all elements of the input.
This function computes the square root of all elements of the input and returns the result with the same type as the input. It is a requirement of sqrt that the input source type has type traits.
- Template Parameters:
U – Type of the source argument and the return type.
- Parameters:
u – [in] Input value to compute \( \sqrt{x} \) where \( x \) is each element of \( u \).
- Returns:
The return value with all elements as the result of the square root.
- template<typename U, class = Require<HasTypeTraits<U>>> inline __host__ __device__ U abs (U u)
Metafunction to compute the absolute value of all elements of the input.
This function computes the absolute value of all elements of the input and returns the result with the same type as the input. For instance, an int4 input {-1, 2, -3, 4} yields the absolute {1, 2, 3, 4} as int4 as well (see example below). It is a requirement of abs that the input source type has type traits.
using IntType = MakeType<int, 4>; IntType a = {-1, 2, -3, 4}; IntType a_abs = abs(a); // = {1, 2, 3, 4}
- Template Parameters:
U – Type of the source argument and the return type.
- Parameters:
u – [in] Input value to compute \( |x| \) where \( x \) is each element of \( u \).
- Returns:
The return value with the absolute of all elements.
- template<typename U, typename S, class = Require<(NumComponents<U> == NumComponents<S>) || (HasTypeTraits<U> && NumComponents<S> == 0)>> inline __host__ __device__ U clamp (U u, S lo, S hi)
Metafunction to clamp all elements of the input.
This function clamps all elements of the input
ubetweenloandhiand returns the result with the same type as the input. It is a requirement of clamp that the inputuhas the same number of components of the range valuesloandhior both are scalars (and the type ofuhas type traits).- Template Parameters:
U – Type of the source argument
uand the return type.S – Type of the source argument
loandhi(use a regular C type for scalar).
- Parameters:
u – [in] Input value to clamp.
lo – [in] Input clamp range low value.
hi – [in] Input clamp range high value.
- Returns:
The return value with all elements clamped.
-
NVCV_CUDA_BINARY_SIMD(TYPE_U, INTRINSIC)
-
NVCV_CUDA_UNARY_SIMD(TYPE_U, INTRINSIC)