Commits

Alex Gaynor committed dfe5d22

progress via-hacks.

Comments (0)

Files changed (2)

pypy/module/micronumpy/compile.py

             return IntObject(obj)
         raise Exception
 
+    def newcomplex(self, realval, imagval):
+        return ComplexObject(realval, imagval)
+
     def float(self, w_obj):
         assert isinstance(w_obj, FloatObject)
         return w_obj
     def __init__(self, intval):
         self.intval = intval
 
+class ComplexObject(W_Root):
+    def __init__(self, realval, imagval):
+        self.realval = realval
+        self.imagval = imagval
+
 
 space = FakeSpace()
 

pypy/module/micronumpy/interp_dtype.py

         return space.newtuple([])
 
 
+class UnsupportedOperation(Exception):
+    pass
+
 class BaseBox(object):
     pass
 
 VOID_TP = lltype.Ptr(lltype.Array(lltype.Void, hints={'nolength': True, "uncast_on_llgraph": True}))
 
-def create_low_level_dtype(num, kind, name, aliases, applevel_types, T, valtype,
-    expected_size=None):
+def create_low_level_dtype(num, kind, name, aliases, applevel_types, T,
+    valtype, expected_size=None, exclude_methods=[]):
 
     class Box(BaseBox):
         def __init__(self, val):
                 track_allocation=False, add_memory_pressure=True
             ))
 
-        def getitem(self, storage, i):
-            return self.box(self.unerase(storage)[i])
+        if "getitem" not in exclude_methods:
+            def getitem(self, storage, i):
+                return self.box(self.unerase(storage)[i])
 
         def setitem(self, storage, i, item):
             self.unerase(storage)[i] = self.unbox(item)
         def setitem_w(self, space, storage, i, w_item):
             self.setitem(storage, i, self.unwrap(space, w_item))
 
-        @specialize.argtype(1)
-        def adapt_val(self, val):
-            return self.box(rffi.cast(TP.TO.OF, val))
+        if "adapt_val" not in exclude_methods:
+            @specialize.argtype(1)
+            def adapt_val(self, val):
+                if isinstance(val, tuple):
+                    raise UnsupportedOperation("Can't convert a complex to a %s" % self.name)
+                return self.box(rffi.cast(TP.TO.OF, val))
 
     W_LowLevelDtype.__name__ = "W_%sDtype" % name.capitalize()
     W_LowLevelDtype.num = num
     T = ComplexDouble,
     valtype = (float, float),
     expected_size = 16,
+    exclude_methods = ["adapt_val", "getitem"],
 )
 class W_Complex128Dtype(W_Complex128Dtype):
     @specialize.argtype(1)
         self.unerase(storage)[i].imag = val[1]
 
     def getitem(self, storage, i):
-        return (
+        return self.box((
             self.unerase(storage)[i].real,
             self.unerase(storage)[i].imag,
-        )
+        ))
 
 
 ALL_DTYPES = [