This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* change project links to `PaddlePaddle/PaddleSOT` * bump black to 2023 style * change project name * `symbolic_opcode_translator` -> `sot` * guard all outputs
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from __future__ import annotations | ||
|
||
import unittest | ||
|
||
from test_case_base import ( | ||
TestCaseBase, | ||
test_instruction_translator_cache_context, | ||
) | ||
|
||
import paddle | ||
|
||
|
||
def non_operator_related_fn(x: int, y: int): | ||
return x + y | ||
|
||
|
||
def partial_non_operator_related_fn(x: paddle.Tensor, y: paddle.Tensor, z: int): | ||
a = x + y | ||
return [a, z + z] | ||
|
||
|
||
class TestGuardOutputs(TestCaseBase): | ||
def test_non_operator_related_fn(self): | ||
with test_instruction_translator_cache_context() as ctx: | ||
self.assert_results(non_operator_related_fn, 1, 2) | ||
self.assertEqual(ctx.translate_count, 1) | ||
self.assert_results(non_operator_related_fn, 3, 4) | ||
self.assertEqual(ctx.translate_count, 2) | ||
|
||
def test_partial_non_operator_related_fn(self): | ||
with test_instruction_translator_cache_context() as ctx: | ||
self.assert_results( | ||
partial_non_operator_related_fn, | ||
paddle.to_tensor(1), | ||
paddle.to_tensor(2), | ||
3, | ||
) | ||
self.assertEqual(ctx.translate_count, 1) | ||
self.assert_results( | ||
partial_non_operator_related_fn, | ||
paddle.to_tensor(4), | ||
paddle.to_tensor(5), | ||
6, | ||
) | ||
self.assertEqual(ctx.translate_count, 2) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |