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/linear/DotProductTest.lvt

namespace Livt.ML.Tests.Linear

using Livt.ML.Linear

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

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

	/**
	 * Checks that Compute s zero vector.
	 */
	@Test
	fn ComputesZeroVector()
	{
		var a: int[8]
		var b: int[8] = [1, 1, 1, 1, 1, 1, 1, 1]

		assert dp.Compute(a, b) == 0
	}

	/**
	 * Checks that Compute s weighted sum.
	 */
	@Test
	fn ComputesWeightedSum()
	{
		var a: int[8] = [1, 2, 3, 4, 5, 6, 7, 8]
		var b: int[8] = [8, 7, 6, 5, 4, 3, 2, 1]

		assert dp.Compute(a, b) == 120
	}

	/**
	 * Checks that the component saturates large accumulation.
	 */
	@Test
	fn SaturatesLargeAccumulation()
	{
		var a: int[8] = [200, 200, 200, 0, 0, 0, 0, 0]
		var b: int[8] = [200, 200, 200, 0, 0, 0, 0, 0]

		assert dp.Compute(a, b) == DotProduct.ACC_MAX
	}
}