# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import unittest import numpy as np # Assuming the following imports are correct based on your requirements from main import FLOAT, INT64, Identity class LoopOpTest(unittest.TestCase): def validate(self, func): """Placeholder for validation logic.""" # This method should validate the compiled function. # Normally, you'll implement this based on your framework requirements. pass def test_loop(self): """Basic loop test.""" @script() def sumprod(x: FLOAT["N"], N: INT64) -> (FLOAT["N"], FLOAT["N"]): sum_result = Identity(x) prod_result = Identity(x) for _ in range(N): sum_result = sum_result + x prod_result = prod_result * x return sum_result, prod_result self.validate(sumprod) x = np.array([2]) M = 3 sum_result, prod_result = sumprod(x, M) self.assertTrue(np.array_equal(sum_result, np.array([8]))) self.assertTrue(np.array_equal(prod_result, np.array([16]))) def test_loop_bound(self): """Test with an expression for loop bound.""" @script() def sumprod(x: FLOAT["N"], N: INT64) -> (FLOAT["N"], FLOAT["N"]): sum_result = Identity(x) prod_result = Identity(x) for _ in range(2 * N + 1): sum_result = sum_result + x prod_result = prod_result * x return sum_result, prod_result self.validate(sumprod) # Ensure the script runs if this module is executed if __name__ == "__main__": unittest.main()