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 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ BugFix ] Fix PaddleDetection bugs (#235)
- Loading branch information
1 parent
019b846
commit 90da495
Showing
7 changed files
with
164 additions
and
20 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
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
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
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,69 @@ | ||
import unittest | ||
|
||
from test_case_base import TestCaseBase | ||
|
||
import paddle | ||
|
||
patched = lambda self, x: x * self.a | ||
|
||
patched2 = lambda self, x: x * self.a + 3 | ||
|
||
|
||
class A: | ||
def __init__(self, a): | ||
self.a = a | ||
|
||
def __call__(self, x): | ||
return self.add(x) | ||
|
||
def add(self, x): | ||
return x + self.a | ||
|
||
multi = patched | ||
|
||
|
||
class B: | ||
def __init__(self, a): | ||
self.a = A(a) | ||
|
||
def __call__(self, x, func): | ||
return getattr(self.a, func)(x) | ||
|
||
def self_call(self, x, func): | ||
return getattr(self.a, func)(self.a, x) | ||
|
||
|
||
def foo_1(a, x): | ||
return a(x) | ||
|
||
|
||
def foo_2(a, x): | ||
return a.multi(x) | ||
|
||
|
||
def foo_3(b, x): | ||
return b(x, "multi") | ||
|
||
|
||
def foo_4(b, x): | ||
return b(x, "add") | ||
|
||
|
||
def foo_5(b, x): | ||
return b.self_call(x, "multi") | ||
|
||
|
||
class TestExecutor(TestCaseBase): | ||
def test_simple(self): | ||
c = B(13) | ||
c.a.multi = patched2 | ||
self.assert_results(foo_1, A(13), paddle.to_tensor(2)) | ||
self.assert_results(foo_2, A(13), paddle.to_tensor(2)) | ||
self.assert_results(foo_3, B(13), paddle.to_tensor(2)) | ||
self.assert_results(foo_4, B(13), paddle.to_tensor(2)) | ||
self.assert_results(foo_5, c, paddle.to_tensor(2)) | ||
self.assert_results(foo_4, c, paddle.to_tensor(2)) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |