template <typename value_type_>
struct outputs Fields
value | value_type_ | The answer, which the call writes in place. |
|---|
Ask your coding agent about this page, or add the docs server to it
curl -s 'https://www.unum.cloud/docs/uform/cpp/encoding.md' | claude -p "How would this fit my code?"One verb per input form, each spelled as in C, and each taking its inputs, the encode_outputs_t to keep, a config, and last the arena:
text_encode(texts, ..) takes UTF-8 texts as a tape_view<char>, a byte per token, since models are tokenizer-free.image_encode(files, ..) takes JPEG, PNG or WebP files as a tape_view<std::uint8_t>.image_encode_pixels(pixels, heights, widths, ..) takes interleaved 8-bit RGB, heights[i] rows of widths[i] pixels per item.video_encode(files, ..) takes MP4 or WebM clips.audio_encode(files, ..) takes WAV, FLAC, MP3 or Opus recordings.audio_encode_samples(samples, sample_rate, ..) takes mono float samples as a tape_view<float>.A tape_view is the elements and count + 1 offsets, which the library reads without a copy once the SDK checks the offsets stay inside the elements.
Separate items gather into memory the caller owns with one copy, through gathered<char>(items, offsets, elements), which answers the view every verb takes, or status_code_t::invalid_argument_k when either span is too short:
std::string_view const joined = "first documentthe second";
std::size_t const offsets[] = {0, 14, 24};
auto [encoded, status] = model.text_encode({joined, offsets}, uf::encode_outputs_t::states_k, uform_scalar_bf16_k, arena);
std::span<std::size_t const> const items = encoded.states.offsets(); // item `i` spans rows `items[i]` up to `items[i + 1]`
uf::written_rows_t const second = encoded.states.item(1); // the rows of one itemencode_outputs_t::embeddings_k, states_k and token_vectors_k join with |, and a surface left out answers an empty view and costs nothing past the final norm.
Token vectors are the token head’s unit rows, one per state, which late-interaction rerankers score; a model without the head answers status_code_t::unsupported_k.
A bare uform_scalar_t converts into the verb’s config, the scalar every output lands as; the config’s other fields reach the knobs:
uform_text_encode_stats_t stats {};
auto handler = [](std::size_t completed, std::size_t total) noexcept {
return completed * 2 < total ? uform_continue_k : uform_cancel_k;
};
uf::text_encode_config_t const config {uform_scalar_f32_k, {handler}, &stats};
auto [encoded, status] = model.text_encode(texts, uf::encode_outputs_t::embeddings_k, config, arena);written_rows_t holds the C view, its stride, columns and scalar, beside the rows written, and row<float>(i) reads one row, empty when the rows hold another scalar type. written_rows_tape_t adds the offsets() and an item(i) per input.
A handler answering uform_cancel_k stops the call, which fails with status_code_t::cancelled_k and publishes nothing.
outputsWhere a call writes what value_type_ is made of.template <typename value_type_>
struct outputs value | value_type_ | The answer, which the call writes in place. |
|---|
outputs< void >A call that outputs nothing but its status.template <>
struct outputs< void > value | void | The answer, which the call writes in place. |
|---|
bf16_tBit containers for the formats C++ has no arithmetic type for, so a call can still name them.written_rows_tRows a call wrote packed into its arena, one per item, readable until the arena's next call; host code may read them only from a RAM arena.struct written_rows_t view | uform_rows_view_t | The rows as the call wrote them. |
|---|---|---|
written | std::size_t | Rows written, one per item along the call's batch axis; zero for a surface the call did not keep. |
written_rows_tape_tA ragged run of rows a call wrote into its arena, item i spanning rows offsets()[i] up to offsets()[i+1]; readable until the arena's next call.struct written_rows_tape_t view | uform_rows_tape_view_t | The rows and offsets as the call wrote them. |
|---|---|---|
written | std::size_t | Items written along the call's batch axis; zero for a surface the call did not keep. |
encode_outputs_tThe surfaces an encode verb keeps from its one forward, named after the C fields they fill; operator| joins them.enum encode_outputs_t embeddings_k | 1 | One pooled embedding per item, past the attention pool and the projection head. |
|---|---|---|
states_k | 2 | One final-norm state per token left after truncation. |
token_vectors_k | 4 | One unit vector of the token head per token left after truncation; a model without the head fails the call with status_code_t::unsupported_k. |
encoded_tWhat an encode verb wrote into the arena it was given: the surfaces its encode_outputs_t named, each empty when left out, and none normalized.struct encoded_t embeddings | written_rows_t | One pooled embedding of the model's dimensions per item. |
|---|---|---|
states | written_rows_tape_t | One final-norm state per token left after truncation, item by item. |
token_vectors | written_rows_tape_t | One unit vector of the model's token width per token left after truncation, item by item. |
encode_configThe knobs of an encode verb reporting stats_type_: the scalar every output lands as, which a bare uform_scalar_t converts into, a handler, and a report.template <typename stats_type_>
struct encode_config outputs_scalar | uform_scalar_t | The scalar type every output lands as. |
|---|---|---|
progress | progress_t | Hears the items encoded, and may cancel the call. |
stats | stats_type_ * | The report the call overwrites; nullptr skips it. |
outputs< tape_view< float > >Where text_choose writes one probability per choice: the C tape and its count, from which the answer assembles a tape_view over the arena.template <>
struct outputs< tape_view< float > > written | uform_tape_view_t | |
|---|---|---|
count | std::size_t | |
value | tape_view<float> | The answer, which the call writes in place. |
tape_viewA ragged batch of element_type_ laid out as Apache Arrow lays one out: elements end to end, and one more offset than entries, entry i spanning two consecutive offsets.3template <an_element element_type_>
struct tape_view The caller owns both spans: as an input, it keeps them alive until the call is final; as an output, it reads the call's arena until the arena's next call.
countEntries along the batch axis, one fewer than the offsets.std::size_t count() const noexcept; entryThe elements of the entry at position, below count.std::span<element_type_ const> entry(
std::size_t position) const noexcept; checkRefuses what only the binding sees: no offsets, or a last one past the elements.status_t check() const noexcept; bytes_viewViews text as the unterminated run of bytes every path, buffer and name arrives in.uform_bytes_view_t bytes_view(std::string_view text) noexcept; uform_bytes_view_t bytes_view(
std::span<std::uint8_t const> bytes) noexcept; Views bytes as the caller's run every checkpoint buffer arrives in.
gatheredGathers separate items of element_type_ into one tape laid out in the caller's offsets and elements, for callers whose items are not laid end to end already.template <an_element element_type_, std::ranges::sized_range items_type_>
expected<tape_view<element_type_>> gathered(
items_type_ const & items,
std::span<std::size_t> offsets,
std::span<element_type_> elements) noexcept; Gathering copies every element once, which a caller already holding a tape skips by passing its tape_view directly. The answer views both spans, so they outlive every call it is passed to.
containsWhether every surface surface names is kept by outputs.bool contains(
encode_outputs_t outputs,
encode_outputs_t surface) noexcept; scalar_ofThe scalar kind a C++ element type names, or uform_scalar_unknown_k for none.uform_scalar_t scalar_of; values_per_elementValues one element packs: eight for bit sets, two for nibbles, one otherwise.std::size_t values_per_element;