Skip to content

Expressions

adjacent function

template <typename Fn, typename E1>
internal::expression_adjacent<Fn, E1> adjacent(Fn &&fn,
                                               E1 &&e1)

Returns template expression that returns the result of calling \(fn(x_i, x_{i-1})\)

Source code
template <typename Fn, typename E1>
KFR_INTRINSIC internal::expression_adjacent<Fn, E1> adjacent(Fn&& fn, E1&& e1)
{
    return internal::expression_adjacent<Fn, E1>(std::forward<Fn>(fn), std::forward<E1>(e1));
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/basic_expressions.hpp#L468

input_expression

input_expression class

input_expression

Base class of all input expressoins

Source code
struct input_expression
{
    KFR_MEM_INTRINSIC constexpr static size_t size() CMT_NOEXCEPT { return infinite_size; }

    constexpr static bool is_incremental = false;

    KFR_MEM_INTRINSIC constexpr void begin_block(cinput_t, size_t) const {}
    KFR_MEM_INTRINSIC constexpr void end_block(cinput_t, size_t) const {}
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/expression.hpp#L97

is_input_expression variable

template <typename E>
constexpr inline bool is_input_expression =
    is_base_of<input_expression, decay<E>>

Check if the type argument is an input expression

Source code
template <typename E>
constexpr inline bool is_input_expression = is_base_of<input_expression, decay<E>>

https://github.com/kfrlib/kfr/blob//include/kfr/base/expression.hpp#L120

is_input_expressions variable

template <typename... Es>
constexpr inline bool is_input_expressions =
    (is_base_of<input_expression, decay<Es>> || ...)

Check if the type arguments are an input expressions

Source code
template <typename... Es>
constexpr inline bool is_input_expressions = (is_base_of<input_expression, decay<Es>> || ...)

https://github.com/kfrlib/kfr/blob//include/kfr/base/expression.hpp#L124

is_numeric variable

template <typename T>
constexpr inline bool is_numeric =
    is_number<deep_subtype<T>>

Check if the type argument is a number or a vector of numbers

Source code
template <typename T>
constexpr inline bool is_numeric = is_number<deep_subtype<T>>

https://github.com/kfrlib/kfr/blob//include/kfr/base/expression.hpp#L136

is_numeric_args variable

template <typename... Ts>
constexpr inline bool is_numeric_args = (is_numeric<Ts> &&
                                         ...)

Check if the type arguments are a numbers or a vectors of numbers

Source code
template <typename... Ts>
constexpr inline bool is_numeric_args = (is_numeric<Ts> && ...)

https://github.com/kfrlib/kfr/blob//include/kfr/base/expression.hpp#L140

is_output_expression variable

template <typename E>
constexpr inline bool is_output_expression =
    is_base_of<output_expression, decay<E>>

Check if the type argument is an output expression

Source code
template <typename E>
constexpr inline bool is_output_expression = is_base_of<output_expression, decay<E>>

https://github.com/kfrlib/kfr/blob//include/kfr/base/expression.hpp#L128

is_output_expressions variable

template <typename... Es>
constexpr inline bool is_output_expressions =
    (is_base_of<output_expression, decay<Es>> || ...)

Check if the type arguments are an output expressions

Source code
template <typename... Es>
constexpr inline bool is_output_expressions = (is_base_of<output_expression, decay<Es>> || ...)

https://github.com/kfrlib/kfr/blob//include/kfr/base/expression.hpp#L132

linspace function

template <typename T1, typename T2, bool precise = false,
          typename TF = ftype<common_type<T1, T2>>>
internal::expression_linspace<TF, precise>
linspace(T1 start, T2 stop, size_t size,
         bool endpoint = false, bool truncate = false)

Returns evenly spaced numbers over a specified interval.


start The starting value of the sequence
stop The end value of the sequence. if endpoint is false, the last value is excluded
size Number of samples to generate
endpoint If true, stop is the last sample. Otherwise, it is not included
truncate If true, linspace returns exactly size elements, otherwise, returns infinite sequence

Source code
template <typename T1, typename T2, bool precise = false, typename TF = ftype<common_type<T1, T2>>>
KFR_INTRINSIC internal::expression_linspace<TF, precise> linspace(T1 start, T2 stop, size_t size,
                                                                  bool endpoint = false,
                                                                  bool truncate = false)
{
    return internal::expression_linspace<TF, precise>(start, stop, size, endpoint, truncate);
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/basic_expressions.hpp#L440

lockfree_ring_buffer

lockfree_ring_buffer class

template <typename T> lockfree_ring_buffer

Single producer single consumer lock-free ring buffer

Source code
template <typename T>
struct lockfree_ring_buffer
{
    lockfree_ring_buffer() : front(0), tail(0) {}

    size_t size() const
    {
        return tail.load(std::memory_order_relaxed) - front.load(std::memory_order_relaxed);
    }

    template <univector_tag Tag>
    size_t try_enqueue(const T* source, size_t size, univector<T, Tag>& buffer, bool partial = false)
    {
        const size_t cur_tail   = tail.load(std::memory_order_relaxed);
        const size_t avail_size = buffer.size() - (cur_tail - front.load(std::memory_order_relaxed));
        if (size > avail_size)
        {
            if (!partial)
                return 0;
            size = std::min(size, avail_size);
        }
        std::atomic_thread_fence(std::memory_order_acquire);

        const size_t real_tail  = cur_tail % buffer.size();
        const size_t first_size = std::min(buffer.size() - real_tail, size);
        builtin_memcpy(buffer.data() + real_tail, source, first_size * sizeof(T));
        builtin_memcpy(buffer.data(), source + first_size, (size - first_size) * sizeof(T));

        std::atomic_thread_fence(std::memory_order_release);

        tail.store(cur_tail + size, std::memory_order_relaxed);
        return size;
    }

    template <univector_tag Tag>
    size_t try_dequeue(T* dest, size_t size, const univector<T, Tag>& buffer, bool partial = false)
    {
        const size_t cur_front  = front.load(std::memory_order_relaxed);
        const size_t avail_size = tail.load(std::memory_order_relaxed) - cur_front;
        if (size > avail_size)
        {
            if (!partial)
                return 0;
            size = std::min(size, avail_size);
        }
        std::atomic_thread_fence(std::memory_order_acquire);

        const size_t real_front = cur_front % buffer.size();
        const size_t first_size = std::min(buffer.size() - real_front, size);
        builtin_memcpy(dest, buffer.data() + real_front, first_size * sizeof(T));
        builtin_memcpy(dest + first_size, buffer.data(), (size - first_size) * sizeof(T));

        std::atomic_thread_fence(std::memory_order_release);

        front.store(cur_front + size, std::memory_order_relaxed);
        return size;
    }

private:
    std::atomic<size_t> front;
    char cacheline_filler[64 - sizeof(std::atomic<size_t>)];
    std::atomic<size_t> tail;
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/univector.hpp#L535

make_univector function

template <typename T>
univector_ref<T> make_univector(T *data, size_t size)

Creates univector from data and size

Source code
template <typename T>
KFR_INTRINSIC univector_ref<T> make_univector(T* data, size_t size)
{
    return univector_ref<T>(data, size);
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/univector.hpp#L491

template <typename T>
univector_ref<const T> make_univector(const T *data,
                                      size_t size)

Creates univector from data and size

Source code
template <typename T>
KFR_INTRINSIC univector_ref<const T> make_univector(const T* data, size_t size)
{
    return univector_ref<const T>(data, size);
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/univector.hpp#L498

template <typename Container,
          KFR_ENABLE_IF(kfr::has_data_size<Container>),
          typename T = value_type_of<Container>>
univector_ref<const T>
make_univector(const Container &container)

Creates univector from a container (must have data() and size() methods)

Source code
template <typename Container, KFR_ENABLE_IF(kfr::has_data_size<Container>),
          typename T = value_type_of<Container>>
KFR_INTRINSIC univector_ref<const T> make_univector(const Container& container)
{
    return univector_ref<const T>(container.data(), container.size());
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/univector.hpp#L506

template <typename Container,
          KFR_ENABLE_IF(kfr::has_data_size<Container>),
          typename T = value_type_of<Container>>
univector_ref<T> make_univector(Container &container)

Creates univector from a container (must have data() and size() methods)

Source code
template <typename Container, KFR_ENABLE_IF(kfr::has_data_size<Container>),
          typename T = value_type_of<Container>>
KFR_INTRINSIC univector_ref<T> make_univector(Container& container)
{
    return univector_ref<T>(container.data(), container.size());
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/univector.hpp#L514

template <typename T, size_t N>
univector_ref<T> make_univector(T (&arr)[N])

Creates univector from a sized array

Source code
template <typename T, size_t N>
KFR_INTRINSIC univector_ref<T> make_univector(T (&arr)[N])
{
    return univector_ref<T>(arr, N);
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/univector.hpp#L521

template <typename T, size_t N>
univector_ref<const T> make_univector(const T (&arr)[N])

Creates univector from a sized array

Source code
template <typename T, size_t N>
KFR_INTRINSIC univector_ref<const T> make_univector(const T (&arr)[N])
{
    return univector_ref<const T>(arr, N);
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/univector.hpp#L528

output_expression

output_expression class

output_expression

Base class of all output expressoins

Source code
struct output_expression
{
    KFR_MEM_INTRINSIC constexpr static size_t size() CMT_NOEXCEPT { return infinite_size; }

    constexpr static bool is_incremental = false;

    KFR_MEM_INTRINSIC constexpr void begin_block(coutput_t, size_t) const {}
    KFR_MEM_INTRINSIC constexpr void end_block(coutput_t, size_t) const {}
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/expression.hpp#L108

padded function

template <typename E, typename T = value_type_of<E>>
internal::expression_padded<E>
padded(E &&e, const T &fill_value = T(0))

Returns infinite template expression that pads e with fill_value (default value = 0)

Source code
template <typename E, typename T = value_type_of<E>>
internal::expression_padded<E> padded(E&& e, const T& fill_value = T(0))
{
    static_assert(is_input_expression<E>, "E must be an input expression");
    return internal::expression_padded<E>(fill_value, std::forward<E>(e));
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/basic_expressions.hpp#L521

rebind function

template <typename Fn, typename... OldArgs,
          typename... NewArgs>
CMT_INTRINSIC internal::expression_function<Fn, NewArgs...>
rebind(
    const internal::expression_function<Fn, OldArgs...> &e,
    NewArgs &&... args)

Construct a new expression using the same function as in e and new arguments
e an expression
args new arguments for the function

Source code
template <typename Fn, typename... OldArgs, typename... NewArgs>
CMT_INTRINSIC internal::expression_function<Fn, NewArgs...> rebind(
    const internal::expression_function<Fn, OldArgs...>& e, NewArgs&&... args)
{
    return internal::expression_function<Fn, NewArgs...>(e.get_fn(), std::forward<NewArgs>(args)...);
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/expression.hpp#L420

render function

template <typename Expr, typename T = value_type_of<Expr>>
univector<T> render(Expr &&expr)

Converts an expression to univector

Source code
template <typename Expr, typename T = value_type_of<Expr>>
KFR_INTRINSIC univector<T> render(Expr&& expr)
{
    static_assert(!is_infinite<Expr>,
                  "render: Can't process infinite expressions. Pass size as a second argument to render.");
    univector<T> result;
    result.resize(expr.size());
    result = expr;
    return result;
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/univector.hpp#L609

template <typename Expr, typename T = value_type_of<Expr>>
univector<T> render(Expr &&expr, size_t size,
                    size_t offset = 0)

Converts an expression to univector

Source code
template <typename Expr, typename T = value_type_of<Expr>>
KFR_INTRINSIC univector<T> render(Expr&& expr, size_t size, size_t offset = 0)
{
    univector<T> result;
    result.resize(size);
    result = slice(expr, offset, size);
    return result;
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/univector.hpp#L621

template <typename Expr, size_t Size,
          typename T = value_type_of<Expr>>
univector<T, Size> render(Expr &&expr, csize_t<Size>)

Converts an expression to univector

Source code
template <typename Expr, size_t Size, typename T = value_type_of<Expr>>
KFR_INTRINSIC univector<T, Size> render(Expr&& expr, csize_t<Size>)
{
    univector<T, Size> result;
    result = expr;
    return result;
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/univector.hpp#L631

reverse function

template <typename E1,
          KFR_ENABLE_IF(is_input_expression<E1>)>
internal::expression_reverse<E1> reverse(E1 &&e1)

Returns the reversed expression

Source code
template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>)>
KFR_INTRINSIC internal::expression_reverse<E1> reverse(E1&& e1)
{
    static_assert(!is_infinite<E1>, "e1 must be a sized expression (use slice())");
    return internal::expression_reverse<E1>(std::forward<E1>(e1));
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/basic_expressions.hpp#L425

slice function

univector<T, 0> slice(size_t start = 0,
                      size_t size = max_size_t)

Returns subrange of the vector. If start is greater or equal to this->size, returns empty univector If requested size is greater than this->size, returns only available elements

Source code
univector<T, 0> slice(size_t start = 0, size_t size = max_size_t)
{
    T* data                = derived_cast<Class>(this)->data();
    const size_t this_size = derived_cast<Class>(this)->size();
    return array_ref<T>(data + start, std::min(size, start < this_size ? this_size - start : 0));
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/univector.hpp#L139

univector<const T, 0> slice(size_t start = 0,
                            size_t size = max_size_t) const

Returns subrange of the vector. If start is greater or equal to this->size, returns empty univector If requested size is greater than this->size, returns only available elements

Source code
univector<const T, 0> slice(size_t start = 0, size_t size = max_size_t) const
{
    const T* data          = derived_cast<Class>(this)->data();
    const size_t this_size = derived_cast<Class>(this)->size();
    return array_ref<const T>(data + start, std::min(size, start < this_size ? this_size - start : 0));
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/univector.hpp#L149

template <typename E1>
internal::expression_slice<E1>
slice(E1 &&e1, size_t start, size_t size = infinite_size)

Returns the subrange of the given expression

Source code
template <typename E1>
KFR_INTRINSIC internal::expression_slice<E1> slice(E1&& e1, size_t start, size_t size = infinite_size)
{
    return internal::expression_slice<E1>(std::forward<E1>(e1), start, size);
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/basic_expressions.hpp#L409

to_pointer function

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 code
template <typename E, typename T = value_type_of<E>>
KFR_INTRINSIC expression_pointer<T> to_pointer(E& expr)
{
    static_assert(is_input_expression<E>, "E must be an expression");
    return expression_pointer<T>(std::addressof(expr), internal::make_expression_vtable<T, E>());
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/pointer.hpp#L212

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 code
template <typename E, typename T = value_type_of<E>>
KFR_INTRINSIC expression_pointer<T> to_pointer(E&& expr)
{
    static_assert(is_input_expression<E>, "E must be an expression");
    std::shared_ptr<expression_resource> ptr = make_resource(std::move(expr));
    void* instance                           = ptr->instance();
    return expression_pointer<T>(instance, internal::make_expression_vtable<T, E>(), std::move(ptr));
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/pointer.hpp#L223

truncate function

univector<T, 0> truncate(size_t size = max_size_t)

Returns subrange of the vector starting from 0. If requested size is greater than this->size, returns only available elements

Source code
univector<T, 0> truncate(size_t size = max_size_t)
{
    T* data                = derived_cast<Class>(this)->data();
    const size_t this_size = derived_cast<Class>(this)->size();
    return array_ref<T>(data, std::min(size, this_size));
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/univector.hpp#L158

univector<const T, 0>
truncate(size_t size = max_size_t) const

Returns subrange of the vector starting from 0. If requested size is greater than this->size, returns only available elements

Source code
univector<const T, 0> truncate(size_t size = max_size_t) const
{
    const T* data          = derived_cast<Class>(this)->data();
    const size_t this_size = derived_cast<Class>(this)->size();
    return array_ref<const T>(data, std::min(size, this_size));
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/univector.hpp#L167

template <typename E1>
internal::expression_slice<E1> truncate(E1 &&e1,
                                        size_t size)

Returns the expression truncated to the given size

Source code
template <typename E1>
KFR_INTRINSIC internal::expression_slice<E1> truncate(E1&& e1, size_t size)
{
    return internal::expression_slice<E1>(std::forward<E1>(e1), 0, size);
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/basic_expressions.hpp#L417

univector

univector class

template <typename T,
          univector_tag Tag = tag_dynamic_vector>
univector

Class that represent data in KFR. Many KFR functions can take this class as an argument. Can inherit from std::vector, std::array or keep only reference to data and its size.

univector is inherited from std::vector univector is inherited from std::array univector contains only reference to data

To convert a plain pointer to univector, call make_univector:

double* buffer;
size_t size;
univector<double, 0> v = make_univector(buffer, size);
// or pass result vector directly to a function:
some_function(make_univector(buffer, size));

Source code
template <typename T, univector_tag Tag = tag_dynamic_vector>
struct univector

https://github.com/kfrlib/kfr/blob//include/kfr/base/univector.hpp#L88

univector

template <typename T, size_t Size> univector

Class that represent data in KFR. Many KFR functions can take this class as an argument. Can inherit from std::vector, std::array or keep only reference to data and its size.

univector is inherited from std::vector univector is inherited from std::array univector contains only reference to data

To convert a plain pointer to univector, call make_univector:

double* buffer;
size_t size;
univector<double, 0> v = make_univector(buffer, size);
// or pass result vector directly to a function:
some_function(make_univector(buffer, size));

Source code
template <typename T, size_t Size>
struct alignas(platform<>::maximum_vector_alignment) univector
    : std::array<T, Size>,
      univector_base<T, univector<T, Size>, is_vec_element<T>>
{
    using std::array<T, Size>::size;
    using size_type = size_t;
#if !defined CMT_COMPILER_MSVC || defined CMT_COMPILER_CLANG
    univector(univector& v) : univector(const_cast<const univector&>(v)) {}
#endif
    univector(const univector& v)   = default;
    univector(univector&&) noexcept = default;
    template <typename Input, KFR_ENABLE_IF(is_input_expression<Input>)>
    univector(Input&& input)
    {
        this->assign_expr(std::forward<Input>(input));
    }
    template <typename... Args>
    constexpr univector(const T& x, const Args&... args) CMT_NOEXCEPT
        : std::array<T, Size>{ { x, static_cast<T>(args)... } }
    {
    }

    constexpr univector() CMT_NOEXCEPT_SPEC(noexcept(std::array<T, Size>())) = default;
    constexpr univector(size_t, const T& value) { std::fill(this->begin(), this->end(), value); }
    constexpr static bool size_known   = true;
    constexpr static bool is_array     = true;
    constexpr static bool is_array_ref = false;
    constexpr static bool is_vector    = false;
    constexpr static bool is_aligned   = true;
    constexpr static bool is_pod       = kfr::is_pod<T>;
    using value_type                   = T;

    value_type get(size_t index, value_type fallback_value) const CMT_NOEXCEPT
    {
        return index < this->size() ? this->operator[](index) : fallback_value;
    }
    using univector_base<T, univector, is_vec_element<T>>::operator=;

    void resize(size_t) CMT_NOEXCEPT {}
}

https://github.com/kfrlib/kfr/blob//include/kfr/base/univector.hpp#L327

univector_base

univector_base class

template <typename T, typename Class, bool is_expression>
univector_base

Base class for all univector specializations.

Source code
template <typename T, typename Class, bool is_expression>
struct univector_base

https://github.com/kfrlib/kfr/blob//include/kfr/base/univector.hpp#L92

univector_dyn typedef

template <typename T>
univector_dyn = univector<T, tag_dynamic_vector>

Alias for univector<T, tag_dynamic_vector>;

Source code
template <typename T>
using univector_dyn = univector<T, tag_dynamic_vector>

https://github.com/kfrlib/kfr/blob//include/kfr/base/univector.hpp#L480

univector_dyn = univector<T, tag_dynamic_vector>

Alias for univector<T, tag_dynamic_vector>;

Source code
using univector_dyn = univector<T, tag_dynamic_vector>

https://github.com/kfrlib/kfr/blob//include/kfr/base/univector.hpp#L480

univector_ref typedef

template <typename T>
univector_ref = univector<T, tag_array_ref>

Alias for univector<T, tag_array_ref>;

Source code
template <typename T>
using univector_ref = univector<T, tag_array_ref>

https://github.com/kfrlib/kfr/blob//include/kfr/base/univector.hpp#L476

univector_ref = univector<T, tag_array_ref>

Alias for univector<T, tag_array_ref>;

Source code
using univector_ref = univector<T, tag_array_ref>

https://github.com/kfrlib/kfr/blob//include/kfr/base/univector.hpp#L476


Auto-generated from sources, Revision , https://github.com/kfrlib/kfr/blob//include/kfr/