Author: Brian Kearns <bdkea...@gmail.com>
Branch: 
Changeset: r69285:67f86a9b9918
Date: 2014-02-23 03:42 -0500
http://bitbucket.org/pypy/pypy/changeset/67f86a9b9918/

Log:    generalize numpy appbridge

diff --git a/pypy/module/micronumpy/appbridge.py 
b/pypy/module/micronumpy/appbridge.py
--- a/pypy/module/micronumpy/appbridge.py
+++ b/pypy/module/micronumpy/appbridge.py
@@ -4,28 +4,20 @@
     w__mean = None
     w__var = None
     w__std = None
-    w_module = None
     w_array_repr = None
     w_array_str = None
 
     def __init__(self, space):
-        self.w_import = space.appexec([], """():
-        def f():
-            import sys
-            __import__('numpy.core._methods')
-            return sys.modules['numpy.core._methods']
-        return f
-        """)
+        pass
 
-    @specialize.arg(2)
-    def call_method(self, space, name, w_obj, args):
-        w_meth = getattr(self, 'w_' + name)
-        if w_meth is None:
-            if self.w_module is None:
-                self.w_module = space.call_function(self.w_import)
-            w_meth = space.getattr(self.w_module, space.wrap(name))
-            setattr(self, 'w_' + name, w_meth)
-        return space.call_args(w_meth, args.prepend(w_obj))
+    @specialize.arg(3)
+    def call_method(self, space, path, name, args):
+        w_method = getattr(self, 'w_' + name)
+        if w_method is None:
+            w_method = space.appexec([space.wrap(path), space.wrap(name)],
+                "(path, name): return getattr(__import__(path, 
fromlist=[name]), name)")
+            setattr(self, 'w_' + name, w_method)
+        return space.call_args(w_method, args)
 
 def set_string_function(space, w_f, w_repr):
     cache = get_appbridge_cache(space)
diff --git a/pypy/module/micronumpy/interp_numarray.py 
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -969,13 +969,16 @@
                                  other_critical_dim)
 
     def descr_mean(self, space, __args__):
-        return get_appbridge_cache(space).call_method(space, '_mean', self, 
__args__)
+        return get_appbridge_cache(space).call_method(space,
+            'numpy.core._methods', '_mean', __args__.prepend(self))
 
     def descr_var(self, space, __args__):
-        return get_appbridge_cache(space).call_method(space, '_var', self, 
__args__)
+        return get_appbridge_cache(space).call_method(space,
+            'numpy.core._methods', '_var', __args__.prepend(self))
 
     def descr_std(self, space, __args__):
-        return get_appbridge_cache(space).call_method(space, '_std', self, 
__args__)
+        return get_appbridge_cache(space).call_method(space,
+            'numpy.core._methods', '_std', __args__.prepend(self))
 
     # ----------------------- reduce -------------------------------
 
diff --git a/pypy/module/micronumpy/test/test_appbridge.py 
b/pypy/module/micronumpy/test/test_appbridge.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/micronumpy/test/test_appbridge.py
@@ -0,0 +1,11 @@
+from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest
+
+class AppTestAppBridge(BaseNumpyAppTest):
+    def test_array_methods(self):
+        import numpy as np
+        a = np.array(1.5)
+        for op in [a.mean, a.var, a.std]:
+            try:
+                op()
+            except ImportError as e:
+                assert str(e) == 'No module named numpy.core'
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to