Commit d125223d authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

Buffer support for complex numbers

parent f8e7386d
...@@ -635,7 +635,7 @@ def get_type_information_cname(code, dtype, maxdepth=None): ...@@ -635,7 +635,7 @@ def get_type_information_cname(code, dtype, maxdepth=None):
typegroup = 'U' typegroup = 'U'
else: else:
typegroup = 'I' typegroup = 'I'
elif complex_possible: elif complex_possible or dtype.is_complex:
typegroup = 'C' typegroup = 'C'
elif dtype.is_float: elif dtype.is_float:
typegroup = 'R' typegroup = 'R'
......
...@@ -142,7 +142,7 @@ class PyrexType(BaseType): ...@@ -142,7 +142,7 @@ class PyrexType(BaseType):
return 1 return 1
def is_simple_buffer_dtype(self): 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) self.is_extension_type or self.is_ptr)
def struct_nesting_depth(self): def struct_nesting_depth(self):
......
...@@ -1333,10 +1333,31 @@ cdef class LongComplexMockBuffer(MockBuffer): ...@@ -1333,10 +1333,31 @@ cdef class LongComplexMockBuffer(MockBuffer):
cdef get_itemsize(self): return sizeof(LongComplex) cdef get_itemsize(self): return sizeof(LongComplex)
cdef get_default_format(self): return b"Zg" 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 @testcase
def complex_struct_dtype(object[LongComplex] buf): 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)])) >>> complex_struct_dtype(LongComplexMockBuffer(None, [(0, -1)]))
0.0 -1.0 0.0 -1.0
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment