From 0e6370db4f1280e27b44bac7a050e3844fb0afc4 Mon Sep 17 00:00:00 2001
From: Tianqi Chen <tqchen@users.noreply.github.com>
Date: Fri, 2 Mar 2018 15:19:13 -0800
Subject: [PATCH] explicit import testing (#956)

* explicit import testing

* Enable init api for extension modules
---
 python/tvm/_ffi/function.py                   | 20 +++++++++++++------
 topi/tests/python/test_topi_conv2d.py         |  1 +
 topi/tests/python/test_topi_conv2d_hwcn.py    |  1 +
 topi/tests/python/test_topi_conv2d_nhwc.py    |  1 +
 .../python/test_topi_conv2d_transpose_nchw.py |  1 +
 topi/tests/python/test_topi_dense.py          |  1 +
 .../python/test_topi_depthwise_conv2d.py      |  1 +
 .../test_topi_depthwise_conv2d_back_input.py  |  1 +
 .../test_topi_depthwise_conv2d_back_weight.py |  1 +
 topi/tests/python/test_topi_math.py           |  1 +
 10 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/python/tvm/_ffi/function.py b/python/tvm/_ffi/function.py
index 526d972f6..90a0c18de 100644
--- a/python/tvm/_ffi/function.py
+++ b/python/tvm/_ffi/function.py
@@ -280,15 +280,23 @@ def _get_api(f):
         return flocal(*args)
     return my_api_func
 
-def _init_api(namespace):
+def _init_api(namespace, target_module_name=None):
     """Initialize api for a given module name
 
-    mod : str
-       The name of the module.
+    namespace : str
+       The namespace of the source registry
+
+    target_module_name : str
+       The target module name if different from namespace
     """
-    assert namespace.startswith("tvm.")
-    prefix = namespace[4:]
-    _init_api_prefix(namespace, prefix)
+    target_module_name = (
+        target_module_name if target_module_name else namespace)
+    if namespace.startswith("tvm."):
+        prefix = namespace[4:]
+        _init_api_prefix(target_module_name, namespace[4:])
+    else:
+        _init_api_prefix(target_module_name, namespace)
+
 
 def _init_api_prefix(module_name, prefix):
     module = sys.modules[module_name]
diff --git a/topi/tests/python/test_topi_conv2d.py b/topi/tests/python/test_topi_conv2d.py
index 3e6978752..e7ea956ee 100644
--- a/topi/tests/python/test_topi_conv2d.py
+++ b/topi/tests/python/test_topi_conv2d.py
@@ -3,6 +3,7 @@ import os
 import numpy as np
 import tvm
 import topi
+import topi.testing
 from tvm.contrib.pickle_memoize import memoize
 from topi.util import get_const_tuple
 
diff --git a/topi/tests/python/test_topi_conv2d_hwcn.py b/topi/tests/python/test_topi_conv2d_hwcn.py
index 7761a90a0..84962a0b4 100644
--- a/topi/tests/python/test_topi_conv2d_hwcn.py
+++ b/topi/tests/python/test_topi_conv2d_hwcn.py
@@ -3,6 +3,7 @@ import os
 import numpy as np
 import tvm
 import topi
+import topi.testing
 from tvm.contrib.pickle_memoize import memoize
 from topi.util import get_const_tuple
 
diff --git a/topi/tests/python/test_topi_conv2d_nhwc.py b/topi/tests/python/test_topi_conv2d_nhwc.py
index 7fc5b8419..40aa3e550 100644
--- a/topi/tests/python/test_topi_conv2d_nhwc.py
+++ b/topi/tests/python/test_topi_conv2d_nhwc.py
@@ -3,6 +3,7 @@ import os
 import numpy as np
 import tvm
 import topi
+import topi.testing
 from tvm.contrib.pickle_memoize import memoize
 from topi.util import get_const_tuple
 
diff --git a/topi/tests/python/test_topi_conv2d_transpose_nchw.py b/topi/tests/python/test_topi_conv2d_transpose_nchw.py
index 712f64ca2..dcdddca91 100644
--- a/topi/tests/python/test_topi_conv2d_transpose_nchw.py
+++ b/topi/tests/python/test_topi_conv2d_transpose_nchw.py
@@ -2,6 +2,7 @@
 import numpy as np
 import tvm
 import topi
+import topi.testing
 from tvm.contrib.pickle_memoize import memoize
 from topi.util import get_const_tuple
 
diff --git a/topi/tests/python/test_topi_dense.py b/topi/tests/python/test_topi_dense.py
index cbae2055a..779e1af1f 100644
--- a/topi/tests/python/test_topi_dense.py
+++ b/topi/tests/python/test_topi_dense.py
@@ -2,6 +2,7 @@
 import numpy as np
 import tvm
 import topi
+import topi.testing
 from topi.util import get_const_tuple
 from tvm.contrib.pickle_memoize import memoize
 
diff --git a/topi/tests/python/test_topi_depthwise_conv2d.py b/topi/tests/python/test_topi_depthwise_conv2d.py
index 8ecfdd063..5a12d7abb 100644
--- a/topi/tests/python/test_topi_depthwise_conv2d.py
+++ b/topi/tests/python/test_topi_depthwise_conv2d.py
@@ -1,5 +1,6 @@
 import tvm
 import topi
+import topi.testing
 import numpy as np
 from scipy import signal
 from topi.util import get_const_tuple
diff --git a/topi/tests/python/test_topi_depthwise_conv2d_back_input.py b/topi/tests/python/test_topi_depthwise_conv2d_back_input.py
index 4280e92bd..663364c53 100644
--- a/topi/tests/python/test_topi_depthwise_conv2d_back_input.py
+++ b/topi/tests/python/test_topi_depthwise_conv2d_back_input.py
@@ -5,6 +5,7 @@ from tvm.contrib.pickle_memoize import memoize
 from scipy import signal
 from topi.util import get_const_tuple
 from topi.nn.util import get_pad_tuple
+import topi.testing
 from topi.cuda.depthwise_conv2d import schedule_depthwise_conv2d_backward_input_nhwc
 
 
diff --git a/topi/tests/python/test_topi_depthwise_conv2d_back_weight.py b/topi/tests/python/test_topi_depthwise_conv2d_back_weight.py
index 5aa65d2c4..25d08e1b1 100644
--- a/topi/tests/python/test_topi_depthwise_conv2d_back_weight.py
+++ b/topi/tests/python/test_topi_depthwise_conv2d_back_weight.py
@@ -1,5 +1,6 @@
 import tvm
 import topi
+import topi.testing
 import numpy as np
 from tvm.contrib.pickle_memoize import memoize
 from scipy import signal
diff --git a/topi/tests/python/test_topi_math.py b/topi/tests/python/test_topi_math.py
index 2c31d0fea..dc3c015d4 100644
--- a/topi/tests/python/test_topi_math.py
+++ b/topi/tests/python/test_topi_math.py
@@ -1,6 +1,7 @@
 import numpy as np
 import tvm
 import topi
+import topi.testing
 from topi import util
 
 
-- 
GitLab