Class anira::RingView#

class RingView#

A non-owning view of an anira_ring, the ring of a Streamed tensor as a phase callback of a Processor gets it from ProcessorContext::input_ring / output_ring: the anira_ring accessors of anira/abi/processor.h, one C call per method, the element type T mapped onto its anira_dtype at compile time (float, double, bool and the fixed-width integers; anything else is a compiler error).

Nothing converts: T’s dtype must be dtype(). A call with another one moves nothing, returns 0 and records ANIRA_ERROR_CONFIG in the handler’s anira_handler_rt_error with one latched record, as the C entry does. A view of no ring (what a refused input_ring / output_ring leaves) is false, and every call on it returns 0. The view is valid until the callback returns.

[driver-thread] [callback-safe], nonblocking: every method is noexcept, allocates nothing and returns the count the C entry returns.

Public Functions

RingView() noexcept = default#

A view of no ring.

inline explicit RingView(anira_ring *ring) noexcept#

Wraps a ring of the processor context; NULL is a view of no ring.

inline explicit operator bool() const noexcept#

Whether the slot has a ring in this phase.

inline DType dtype() const noexcept#

anira_ring_dtype: the element type the ring stores, the ring dtype of the Hard contract (the spec’s dtype when none was declared); 0 for a view of no ring.

inline uint32_t num_channels() const noexcept#

anira_ring_num_channels: the extent of the tensor’s Channel axis, 1 without one.

inline std::size_t available(uint32_t channel) const noexcept#

anira_ring_available: the unread elements of one channel.

inline std::size_t available_past(uint32_t channel) const noexcept#

anira_ring_available_past: the consumed elements of one channel the ring still holds as history, what peek_past_block can address.

template<class T>
inline std::size_t pop_block(uint32_t channel, std::span<T> out) noexcept#

anira_ring_pop_block: pops out.size() elements of one channel, oldest first; elements beyond the available ones are zero.

Returns:

out.size(), or 0 with nothing popped.

template<class T>
inline std::size_t peek_past_block(uint32_t channel, std::span<T> out) const noexcept#

anira_ring_peek_past_block: copies the out.size() most recently consumed elements of one channel without popping, oldest first (the receptive field of a window longer than its hop).

Returns:

out.size(), or 0 with nothing written.

template<class T>
inline std::size_t push_block(uint32_t channel, std::span<T> in) noexcept#

anira_ring_push_block: pushes in.size() elements into one channel.

Returns:

in.size(), or 0 with nothing pushed.

template<class T>
inline std::size_t push_fill(uint32_t channel, const T &value, std::size_t count) noexcept#

anira_ring_push_fill: pushes count copies of one element into one channel.

Returns:

count, or 0 with nothing pushed.

inline std::size_t discard(uint32_t channel, std::size_t count) noexcept#

anira_ring_discard: drops up to count unread elements of one channel (they become history); no element crosses the call, so it takes no element type.

Returns:

the elements dropped.

template<class T>
inline std::size_t pop_windows(uint32_t channel, std::span<T> out, std::size_t num_new, std::size_t num_old, std::size_t offset, uint32_t num_batches) noexcept#

anira_ring_pop_windows: pops num_batches overlapping windows of one channel, window b at out[offset + b * (num_new + num_old)], each num_old elements of history followed by num_new freshly popped ones. The span is the whole destination: one too short for offset + num_batches * (num_new + num_old) elements is refused here (0, nothing popped, nothing recorded).

Returns:

the elements written, or 0.

inline anira_ring *native() const noexcept#