Download onnxscript/modified_testcases/loop_test.py from Dorothydu/gitrepo_top_sample_50: direct link, hf CLI and curl.
- Browser
- Download file 1.69 kB
-
https://huggingface.co/datasets/Dorothydu/gitrepo_top_sample_50/resolve/main/onnxscript/modified_testcases/loop_test.py
- Command line
-
hf download hf://datasets/Dorothydu/gitrepo_top_sample_50/onnxscript/modified_testcases/loop_test.py
-
curl -L -o loop_test.py https://huggingface.co/datasets/Dorothydu/gitrepo_top_sample_50/resolve/main/onnxscript/modified_testcases/loop_test.py
1.69 kB
| # 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.""" | |
| 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.""" | |
| 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() |