KFR

Other Base functions

abs

template<typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)>
T1 abs(const T1 &x)

Returns the absolute value of x.

Source:

template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)>
KFR_INTRIN T1 abs(const T1& x)
template<typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)>
internal::expression_function<fn::abs, E1> abs(E1 &&x)

Returns template expression that returns the absolute value of x.

Source:

template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)>
KFR_INTRIN internal::expression_function<fn::abs, E1> abs(E1&& x)

gamma

template<typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)>
flt_type<T1> gamma(const T1 &x)

Returns the approximate gamma function of an argument

Source:

template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)>
KFR_FUNC flt_type<T1> gamma(const T1& x)
template<typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)>
internal::expression_function<fn::gamma, E1> gamma(E1 &&x)

Creates expression that returns the approximate gamma function of an argument

Source:

template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)>
KFR_FUNC internal::expression_function<fn::gamma, E1> gamma(E1&& x)

factorial_approx

template<typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)>
flt_type<T1> factorial_approx(const T1 &x)

Returns the approximate factorial of an argument

Source:

template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)>
KFR_FUNC flt_type<T1> factorial_approx(const T1& x)
template<typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)>
internal::expression_function<fn::factorial_approx, E1> factorial_approx(E1 &&x)

Creates expression that returns the approximate factorial of an argument

Source:

template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)>
KFR_FUNC internal::expression_function<fn::factorial_approx, E1> factorial_approx(E1&& x)

hadd

template<typename T, size_t N>
T hadd(const vec<T, N> &value)

Sum all elements of the vector

Source:

template <typename T, size_t N>
CMT_INLINE T hadd(const vec<T, N>& value)

hmul

template<typename T, size_t N>
T hmul(const vec<T, N> &value)

Multiply all elements of the vector

Source:

template <typename T, size_t N>
CMT_INLINE T hmul(const vec<T, N>& value)

dot

template<typename T, size_t N>
T dot(const vec<T, N> &x, const vec<T, N> &y)

Calculate the Dot-Product of two vectors

Source:

template <typename T, size_t N>
CMT_INLINE T dot(const vec<T, N>& x, const vec<T, N>& y)

avg

template<typename T, size_t N>
T avg(const vec<T, N> &value)

Calculate the Arithmetic mean of all elements in the vector

Source:

template <typename T, size_t N>
CMT_INLINE T avg(const vec<T, N>& value)

rms

template<typename T, size_t N>
T rms(const vec<T, N> &value)

Calculate the RMS of all elements in the vector

Source:

template <typename T, size_t N>
CMT_INLINE T rms(const vec<T, N>& value)

all

template<typename T, size_t N>
bool all(const mask<T, N> &x)

Returns x[0] && x[1] && … && x[N-1]

Source:

template <typename T, size_t N>
KFR_SINTRIN bool all(const mask<T, N>& x)

any

template<typename T, size_t N>
bool any(const mask<T, N> &x)

Returns x[0] || x[1] || … || x[N-1]

Source:

template <typename T, size_t N>
KFR_SINTRIN bool any(const mask<T, N>& x)

aligned_allocate

template<typename T = void, size_t alignment = platform<>::native_cache_alignment>
T *aligned_allocate(size_t size = 1)

Allocates aligned memory

Source:

template <typename T = void, size_t alignment = platform<>::native_cache_alignment>
CMT_INLINE T* aligned_allocate(size_t size = 1)
{
    T* ptr = static_cast<T*>(CMT_ASSUME_ALIGNED(
        internal::aligned_malloc(std::max(alignment, size * details::elementsize<T>()), alignment),
        alignment));
    return ptr;
}

aligned_deallocate

template<typename T = void>
void aligned_deallocate(T *ptr)

Deallocates aligned memory

Source:

template <typename T = void>
CMT_INLINE void aligned_deallocate(T* ptr)
{
    return internal::aligned_free(ptr);
}

allocator

template<typename T>
class allocator

Aligned allocator

add

template<typename T1, typename T2, typename ...Ts, KFR_ENABLE_IF(is_numeric_args<T1, T2, Ts...>::value)>
inline constexpr common_type<T1, T2, Ts...> add(const T1 &x, const T2 &y, const Ts&... rest)

Returns sum of all the arguments passed to a function.

Source:

template <typename T1, typename T2, typename... Ts, KFR_ENABLE_IF(is_numeric_args<T1, T2, Ts...>::value)>
constexpr inline common_type<T1, T2, Ts...> add(const T1& x, const T2& y, const Ts&... rest)
{
    return x + add(y, rest...);
}
template <typename... E, KFR_ENABLE_IF((is_input_expressions<E...>::value) && true)> internal::expression_function<fn::add, E...> add(E&&... x)

Returns template expression that returns sum of all the arguments passed to a function.

Source:

template <typename... E, KFR_ENABLE_IF((is_input_expressions<E...>::value) && true)>
CMT_INLINE internal::expression_function<fn::add, E...> add(E&&... x)

mul

template<typename T1, typename T2, typename ...Ts>
inline constexpr common_type<T1, T2, Ts...> mul(const T1 &x, const T2 &y, const Ts&... rest)

Returns product of all the arguments passed to a function.

Source:

template <typename T1, typename T2, typename... Ts>
constexpr inline common_type<T1, T2, Ts...> mul(const T1& x, const T2& y, const Ts&... rest)
{
    return x * mul(y, rest...);
}
template<typename ...E, KFR_ENABLE_IF(is_input_expressions<E...>::value)>
internal::expression_function<fn::mul, E...> mul(E&&... x)

Returns template expression that returns product of all the arguments passed to a function.

Source:

template <typename... E, KFR_ENABLE_IF(is_input_expressions<E...>::value)>
CMT_INLINE internal::expression_function<fn::mul, E...> mul(E&&... x)

sqr

template<typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)>
inline constexpr T1 sqr(const T1 &x)

Returns square of x.

Source:

template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)>
constexpr inline T1 sqr(const T1& x)
{
    return x * x;
}
template<typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)>
internal::expression_function<fn::sqr, E1> sqr(E1 &&x)

Returns template expression that returns square of x.

Source:

template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)>
CMT_INLINE internal::expression_function<fn::sqr, E1> sqr(E1&& x)

cub

template<typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)>
inline constexpr T1 cub(const T1 &x)

Returns cube of x.

Source:

template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)>
constexpr inline T1 cub(const T1& x)
{
    return sqr(x) * x;
}
template<typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)>
internal::expression_function<fn::cub, E1> cub(E1 &&x)

Returns template expression that returns cube of x.

Source:

template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)>
CMT_INLINE internal::expression_function<fn::cub, E1> cub(E1&& x)

ipow

template<typename T>
inline constexpr T ipow(const T &x, int base)

Raise x to the power base \(x^{base}\)

CHECK( ipow( 10, 3 ) == 1000 );
CHECK( ipow( 0.5, 2 ) == 0.25 );

Source:

template <typename T>
constexpr inline T ipow(const T& x, int base)
{
    T xx     = x;
    T result = T(1);
    while (base)
    {
        if (base & 1)
            result *= xx;
        base >>= 1;
        xx *= xx;
    }
    return result;
}

sqrsum

template<typename T1, typename ...Ts>
inline constexpr common_type<T1, Ts...> sqrsum(const T1 &x, const Ts&... rest)

Return square of the sum of all arguments

CHECK(sqrsum(1,2,3) == 36);

Source:

template <typename T1, typename... Ts>
constexpr inline common_type<T1, Ts...> sqrsum(const T1& x, const Ts&... rest)
{
    return sqr(add(x, rest...));
}

div

template<typename T1, typename T2, typename Tout = common_type<T1, T2>>
Tout div(const T1 &x, const T2 &y)

Division

Source:

template <typename T1, typename T2, typename Tout = common_type<T1, T2>>
CMT_INLINE Tout div(const T1& x, const T2& y)

rem

template<typename T1, typename T2, typename Tout = common_type<T1, T2>>
Tout rem(const T1 &x, const T2 &y)

Remainder

Source:

template <typename T1, typename T2, typename Tout = common_type<T1, T2>>
CMT_INLINE Tout rem(const T1& x, const T2& y)

neg

template<typename T1>
inline T1 neg(const T1 &x)

Negation

Source:

template <typename T1>
inline T1 neg(const T1& x)

fmadd

template<typename T1, typename T2, typename T3>
constexpr common_type<T1, T2, T3> fmadd(const T1 &x, const T2 &y, const T3 &z)

Fused Multiply-Add

Source:

template <typename T1, typename T2, typename T3>
KFR_INTRIN constexpr common_type<T1, T2, T3> fmadd(const T1& x, const T2& y, const T3& z)
{
    return x * y + z;
}

fmsub

template<typename T1, typename T2, typename T3>
constexpr common_type<T1, T2, T3> fmsub(const T1 &x, const T2 &y, const T3 &z)

Fused Multiply-Sub

Source:

template <typename T1, typename T2, typename T3>
KFR_INTRIN constexpr common_type<T1, T2, T3> fmsub(const T1& x, const T2& y, const T3& z)
{
    return x * y - z;
}

mix

template<typename T1, typename T2, typename T3, KFR_ENABLE_IF(is_numeric_args<T1, T2, T3>::value)>
constexpr common_type<T1, T2, T3> mix(const T1 &c, const T2 &x, const T3 &y)

Linear blend of x and y (c must be in the range 0…+1)

Returns x + ( y - x ) * c

Source:

template <typename T1, typename T2, typename T3, KFR_ENABLE_IF(is_numeric_args<T1, T2, T3>::value)>
KFR_INTRIN constexpr common_type<T1, T2, T3> mix(const T1& c, const T2& x, const T3& y)
{
    return fmadd(c, y - x, x);
}

mixs

template<typename T1, typename T2, typename T3, KFR_ENABLE_IF(is_numeric_args<T1, T2, T3>::value)>
constexpr common_type<T1, T2, T3> mixs(const T1 &c, const T2 &x, const T3 &y)

Linear blend of x and y (c must be in the range -1…+1)

Source:

template <typename T1, typename T2, typename T3, KFR_ENABLE_IF(is_numeric_args<T1, T2, T3>::value)>
KFR_INTRIN constexpr common_type<T1, T2, T3> mixs(const T1& c, const T2& x, const T3& y)
{
    return mix(fmadd(c, 0.5, 0.5), x, y);
}

horner

template<typename T1, typename ...Ts, KFR_ENABLE_IF(is_numeric_args<T1, Ts...>::value)>
constexpr common_type<T1, Ts...> horner(const T1 &x, const Ts&... c)

Calculate polynomial using Horner’s method

horner(x, 1, 2, 3) is equivalent to (3x^2 + 2x + 1)

Source:

template <typename T1, typename... Ts, KFR_ENABLE_IF(is_numeric_args<T1, Ts...>::value)>
constexpr CMT_INLINE common_type<T1, Ts...> horner(const T1& x, const Ts&... c)
{
    return internal::horner(x, c...);
}

horner_even

template<typename T1, typename ...Ts, KFR_ENABLE_IF(is_numeric_args<T1, Ts...>::value)>
constexpr common_type<T1, Ts...> horner_even(const T1 &x, const Ts&... c)

Calculate polynomial using Horner’s method (even powers)

horner_even(x, 1, 2, 3) is equivalent to (3x^4 + 2x^2 + 1)

Source:

template <typename T1, typename... Ts, KFR_ENABLE_IF(is_numeric_args<T1, Ts...>::value)>
constexpr CMT_INLINE common_type<T1, Ts...> horner_even(const T1& x, const Ts&... c)
{
    return internal::horner_even(x, c...);
}

horner_odd

template<typename T1, typename ...Ts, KFR_ENABLE_IF(is_numeric_args<T1, Ts...>::value)>
constexpr common_type<T1, Ts...> horner_odd(const T1 &x, const Ts&... c)

Calculate polynomial using Horner’s method (odd powers)

horner_odd(x, 1, 2, 3) is equivalent to (3x^5 + 2x^3 + 1x)

Source:

template <typename T1, typename... Ts, KFR_ENABLE_IF(is_numeric_args<T1, Ts...>::value)>
constexpr CMT_INLINE common_type<T1, Ts...> horner_odd(const T1& x, const Ts&... c)
{
    return internal::horner_odd(x, c...);
}

reciprocal

template<typename T>
constexpr T reciprocal(const T &x)

Calculate Multiplicative Inverse of x

Returns 1/x

Source:

template <typename T>
constexpr CMT_INLINE T reciprocal(const T& x)
{
    static_assert(std::is_floating_point<subtype<T>>::value, "T must be floating point type");
    return subtype<T>(1) / x;
}

swapbyteorder

template <typename T, size_t N, KFR_ENABLE_IF(sizeof(vec<T, N>) > 8)> vec<T, N> swapbyteorder(const vec<T, N>& x)

Swap byte order

Source:

template <typename T, size_t N, KFR_ENABLE_IF(sizeof(vec<T, N>) > 8)>
CMT_INLINE vec<T, N> swapbyteorder(const vec<T, N>& x)

cpu_t

enum cpu_t

An enumeration representing cpu instruction set

cpu_name

static const char *cpu_name(cpu_t set)

Returns name of the cpu instruction set

Source:

CMT_UNUSED static const char* cpu_name(cpu_t set)
{
#ifdef CMT_ARCH_X86
    static const char* names[] = { "common", "sse2", "sse3", "ssse3", "sse41", "sse42", "avx1", "avx2", "avx512" };
#endif
#ifdef CMT_ARCH_ARM
    static const char* names[] = { "common", "neon", "neon64" };
#endif
    if (set >= cpu_t::lowest && set <= cpu_t::highest)
        return names[static_cast<size_t>(set)];
    return "-";
}

vector_width

static constexpr size_t vector_width = (const_max(size_t(1), typeclass<T> == datatype::f ? native_float_vector_size / sizeof(T) : native_int_vector_size / sizeof(T)))

SIMD vector width for the given cpu instruction set

Source:

constexpr static size_t vector_width =
    (const_max(size_t(1), typeclass<T> == datatype::f ? native_float_vector_size / sizeof(T)
                                                      : native_int_vector_size / sizeof(T)))

to_pointer

template<typename E, typename T = value_type_of<E>>
expression_pointer<T> to_pointer(E &expr)

Converts the given expression into an opaque object.

This overload takes reference to the expression.

Warning

Use with caution with local variables.

Source:

template <typename E, typename T = value_type_of<E>>
CMT_INLINE expression_pointer<T> to_pointer(E& expr)
template<typename E, typename T = value_type_of<E>>
expression_pointer<T> to_pointer(E &&expr)

Converts the given expression into an opaque object.

This overload takes ownership of the expression (Move semantics).

Note

Use std::move to force use of this overload.

Source:

template <typename E, typename T = value_type_of<E>>
CMT_INLINE expression_pointer<T> to_pointer(E&& expr)

sort

template<typename T, size_t N>
vec<T, N> sort(const vec<T, N> &x)

Sort the elements in the vector in ascending order

Parameters:x – input vector
Returns:sorted vector
CHECK(sort(make_vector(1000, 1, 2, -10)) == make_vector(-10, 1, 2, 1000));

Source:

template <typename T, size_t N>
CMT_INLINE vec<T, N> sort(const vec<T, N>& x)

sortdesc

template<typename T, size_t N>
vec<T, N> sortdesc(const vec<T, N> &x)

Sort the elements in the vector in descending order

Parameters:x – input vector
Returns:sorted vector
CHECK(sort(make_vector(1000, 1, 2, -10)) == make_vector(1000, 2, 1, -10));

Source:

template <typename T, size_t N>
CMT_INLINE vec<T, N> sortdesc(const vec<T, N>& x)

sqrt

template<typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)>
flt_type<T1> sqrt(const T1 &x)

Returns the positive square root of the x. \(\sqrt{x}\)

Source:

template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)>
KFR_INTRIN flt_type<T1> sqrt(const T1& x)
template<typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)>
internal::expression_function<fn::sqrt, E1> sqrt(E1 &&x)

Returns template expression that returns the positive square root of the x. \(\sqrt{x}\)

Source:

template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)>
KFR_INTRIN internal::expression_function<fn::sqrt, E1> sqrt(E1&& x)

f32

using f32 = float

Short names for common types

Source:

using f32  = float

fbase

using fbase = f64

Floating point type used by default

Source:

using fbase = f64

range

template<typename T1>
class range

An enumeration representing data type

datatype

enum datatype

An enumeration representing data type

pass_through

using pass_through = cometa::fn_pass_through

@copybrief cometa::pass_through

Source:

using pass_through = cometa::fn_pass_through

noop

using noop = cometa::fn_noop

@copybrief cometa::noop

Source:

using noop = cometa::fn_noop

get_first

using get_first = cometa::fn_get_first

@copybrief cometa::get_first

Source:

using get_first = cometa::fn_get_first

get_second

using get_second = cometa::fn_get_second

@copybrief cometa::get_second

Source:

using get_second = cometa::fn_get_second

get_third

using get_third = cometa::fn_get_third

@copybrief cometa::get_third

Source:

using get_third = cometa::fn_get_third

returns

template<typename T>
using returns = cometa::fn_returns<T>

@copybrief cometa::returns

Source:

template <typename T>
using returns = cometa::fn_returns<T>
using returns = cometa::fn_returns<T>

@copybrief cometa::returns

Source:

using returns = cometa::fn_returns<T>

zeroize

template<typename T1>
void zeroize(T1 &value)

Fills a value with zeros

Source:

template <typename T1>
CMT_INLINE void zeroize(T1& value)

initialvalue

template<typename T>
class initialvalue

Used to determine the initial value for reduce functions

make_vector

template<typename Type = void, typename Arg, typename ...Args, size_t N = (sizeof...(Args) + 1), typename SubType = conditional<is_void<Type>::value, common_type<Arg, Args...>, Type>>
constexpr vec<SubType, N> make_vector(const Arg &x, const Args&... rest)

Create vector from scalar values

CHECK( make_vector( 1, 2, 3, 4 ) == i32x4{1, 2, 3, 4} );

Source:

template <typename Type = void, typename Arg, typename... Args, size_t N = (sizeof...(Args) + 1),
          typename SubType = conditional<is_void<Type>::value, common_type<Arg, Args...>, Type>>
constexpr CMT_INLINE vec<SubType, N> make_vector(const Arg& x, const Args&... rest)
{
    return internal::make_vector_impl<SubType>(cvalseq_t<size_t, N>(), static_cast<SubType>(x),
                                               static_cast<SubType>(rest)...);
}