Skip to main content

Module weighted

Module weighted 

Source
Expand description

Convenience weighted output selection nodes.

These are “fat” convenience nodes that combine alias sampling with value lookup in one step. They parse an inline spec string at init time and perform weighted selection at cycle time.

  • WeightedStrings / WeightedU64 — the spec parser runs once at construction via a #[poly_const] setup function, producing a derived WeightedStrCache / WeightedU64Cache (parallel value+alias-table). The eval body does a constant-time lookup.
  • WeightedPick — the same spec-string surface as weighted_u64: weighted_pick(input, "v0:w0;v1:w1;..."). The compiled_u64/jit_constants overrides feed the JIT extern (jit_weighted_pick), which reads a 5-u64 (values_ptr, biases_ptr, primaries_ptr, aliases_ptr, n) constants slice.
  • DynamicWeightedSelect — takes its spec on a Config<T> wire (the Wire trait’s WIRE_COST = Config const flows through Config<Arc<str>> to the slot’s WireCost::Config annotation, so the compiler warns when the spec is bound to a cycle-time source). The evaluating kernel state memoizes the last spec parsed and its alias table in its own scratch, so repeated evaluations with the same spec do no parsing; only a spec change re-parses.

Structs§

DynamicWeightedMemo
The memo DynamicWeightedSelect keeps per kernel state: the last spec it parsed, with the value list and alias table built from it. table is None when the spec named no values.
DynamicWeightedSelect
Dynamic weighted selection where the weight spec is a wire input.
WeightedPick
The weighted_pick node.
WeightedPickState
Derived state for WeightedPick: parsed values, weights, and the alias table, built once at construction from the spec string and read on every cycle (both in the eval path and the compiled closure). weights is retained alongside values so FusedNode::decomposed can reconstruct the equivalent weighted_u64 spec string.
WeightedStrCache
Derived state for WeightedStrings: the parsed value list and the alias table, computed once at construction from the spec string and read on every cycle.
WeightedStrings
Weighted string selection from an inline spec.
WeightedU64
Weighted u64 selection from an inline spec.
WeightedU64Cache
Derived state for WeightedU64: the parsed value list and the alias table, computed once at construction from the spec string and read on every cycle.