Buffer support for complex numbers
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Thu, 14 May 2009 12:58:58 +0000 (14:58 +0200)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Thu, 14 May 2009 12:58:58 +0000 (14:58 +0200)
Cython/Compiler/Buffer.py
Cython/Compiler/PyrexTypes.py
tests/run/bufaccess.pyx

index e19fb3fbcca8c50fd8bbc4d539260f401d251a4d..d2788aa167239e02736d28f337cb01cb03e9157d 100644 (file)
@@ -635,7 +635,7 @@ def get_type_information_cname(code, dtype, maxdepth=None):
                 typegroup = 'U'
             else:
                 typegroup = 'I'
-        elif complex_possible:
+        elif complex_possible or dtype.is_complex:
             typegroup = 'C'
         elif dtype.is_float:
             typegroup = 'R'
index 54b81ad1c09a8792a49a7852d3cfbf5c3d6a2052..a106c3861b9ec3372b59c40d35a0da74353e8f7d 100644 (file)
@@ -142,7 +142,7 @@ class PyrexType(BaseType):
         return 1
 
     def is_simple_buffer_dtype(self):
-        return (self.is_int or self.is_float or self.is_pyobject or
+        return (self.is_int or self.is_float or self.is_complex or self.is_pyobject or
                 self.is_extension_type or self.is_ptr)
 
     def struct_nesting_depth(self):
index db65dcac1570b432e2d5cce5886808f0b3643e79..f1515d5ff1122da3013f78e447e93f99882cb7e1 100644 (file)
@@ -1333,10 +1333,31 @@ cdef class LongComplexMockBuffer(MockBuffer):
     cdef get_itemsize(self): return sizeof(LongComplex)
     cdef get_default_format(self): return b"Zg"
 
+#cdef extern from "complex.h":
+#    pass
+
+@testcase
+def complex_dtype(object[long double complex] buf):
+    """
+    >>> complex_dtype(LongComplexMockBuffer(None, [(0, -1)]))
+    -1j
+    """
+    print buf[0]
+
+@testcase
+def complex_inplace(object[long double complex] buf):
+    """
+    >>> complex_inplace(LongComplexMockBuffer(None, [(0, -1)]))
+    (1+1j)
+    """
+    buf[0] = buf[0] + 1 + 2j
+    print buf[0]
+
 @testcase
 def complex_struct_dtype(object[LongComplex] buf):
     """
-    Note that the format string is "Zg" rather than "2g"...
+    Note that the format string is "Zg" rather than "2g", yet a struct
+    is accessed.
     >>> complex_struct_dtype(LongComplexMockBuffer(None, [(0, -1)]))
     0.0 -1.0
     """