Livt packages

Livt.ML

Version 1.6.1

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

Published files (132)

tests/embedding/FixedTokenEmbeddingTest.lvt

namespace Livt.ML.Tests.Embedding

using Livt.ML.Embedding

/**
 * Exercises FixedTokenEmbedding with a shared fixture instance. Each scenario establishes
 * the inputs and state it needs.
 */
@Test
component FixedTokenEmbeddingTest
{
	// Shared fixture instances, signals, and observation state.
	embedding: FixedTokenEmbedding

	/**
	 * Creates the shared fixture instances (FixedTokenEmbedding). Tests initialize the state
	 * required by their scenario.
	 */
	new()
	{
		embedding = new FixedTokenEmbedding()
	}

	/**
	 * Checks the defaults to zero vector case.
	 */
	@Test
	fn DefaultsToZeroVector()
	{
		embedding.Embed(3)

		assert embedding.GetOutput(0) == 0
		assert embedding.GetOutput(7) == 0
	}

	/**
	 * Checks that Embed s configured token.
	 */
	@Test
	fn EmbedsConfiguredToken()
	{
		embedding.SetValue(2, 1, 256)
		embedding.SetValue(2, 7, 128)
		embedding.Embed(2)

		assert embedding.GetOutput(0) == 0
		assert embedding.GetOutput(1) == 256
		assert embedding.GetOutput(7) == 128
		assert embedding.GetValue(2, 1) == 256
	}

	/**
	 * Checks that the component ignores out of range access.
	 */
	@Test
	fn IgnoresOutOfRangeAccess()
	{
		embedding.SetValue(99, 1, 256)
		embedding.SetValue(1, 99, 256)
		embedding.Embed(99)

		assert embedding.GetOutput(0) == 0
		assert embedding.GetOutput(8) == 0
		assert embedding.GetValue(99, 1) == 0
	}
}