Livt packages

Livt.ML

Version 1.6.1

Fixed-size quantized inference, tensor storage, attention, and transformer building blocks for Livt.

Published files (132)

src/classifier/StreamingArgMax.lvt

namespace Livt.ML.Classifier

/**
 * Computes ArgMax over an arbitrary scalar stream without storing logits.
 */
component StreamingArgMax
{
	// Best candidate and whether the current reduction has accepted a value.
	bestIndex: int
	bestValue: int
	seen: bool

	/**
	 * Clears the previous stream result.
	 */
	public fn Reset()
	{
		bestIndex = 0
		bestValue = 0
		seen = false
	}

	/**
	 * Consumes one indexed score; the lowest index wins exact ties.
	 */
	public fn Accept(index: int, value: int)
	{
		if (!seen || value > bestValue || (value == bestValue && index < bestIndex)) {
			bestIndex = index
			bestValue = value
			seen = true
		}
	}

	/**
	 * Returns whether at least one score has been accepted.
	 */
	public fn HasValue() bool
	{
		return seen
	}

	/**
	 * Returns the winning index, or zero for an empty stream.
	 */
	public fn GetIndex() int
	{
		return bestIndex
	}

	/**
	 * Returns the winning value, or zero for an empty stream.
	 */
	public fn GetValue() int
	{
		return bestValue
	}
}