Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
1d19ea12
Commit
1d19ea12
authored
May 14, 2009
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
real and imag attributes for complex
parent
e49d3c7a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
2 deletions
+34
-2
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+2
-0
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+10
-0
tests/run/complex_numbers_T305.pyx
tests/run/complex_numbers_T305.pyx
+22
-2
No files found.
Cython/Compiler/ExprNodes.py
View file @
1d19ea12
...
@@ -2913,6 +2913,8 @@ class AttributeNode(NewTempExprNode):
...
@@ -2913,6 +2913,8 @@ class AttributeNode(NewTempExprNode):
obj
.
type
.
vtabslot_cname
,
self
.
member
)
obj
.
type
.
vtabslot_cname
,
self
.
member
)
else
:
else
:
return
self
.
member
return
self
.
member
elif
obj
.
type
.
is_complex
:
return
"__Pyx_%s_PART(%s)"
%
(
self
.
member
.
upper
(),
obj_code
)
else
:
else
:
return
"%s%s%s"
%
(
obj_code
,
self
.
op
,
self
.
member
)
return
"%s%s%s"
%
(
obj_code
,
self
.
op
,
self
.
member
)
...
...
Cython/Compiler/PyrexTypes.py
View file @
1d19ea12
...
@@ -713,6 +713,8 @@ class CComplexType(CNumericType):
...
@@ -713,6 +713,8 @@ class CComplexType(CNumericType):
is_complex
=
1
is_complex
=
1
to_py_function
=
"__pyx_PyObject_from_complex"
to_py_function
=
"__pyx_PyObject_from_complex"
has_attributes
=
1
scope
=
None
def
__init__
(
self
,
real_type
):
def
__init__
(
self
,
real_type
):
self
.
real_type
=
real_type
self
.
real_type
=
real_type
...
@@ -736,6 +738,14 @@ class CComplexType(CNumericType):
...
@@ -736,6 +738,14 @@ class CComplexType(CNumericType):
return
(
src_type
.
is_complex
and
self
.
real_type
.
assignable_from_resolved_type
(
src_type
.
real_type
)
return
(
src_type
.
is_complex
and
self
.
real_type
.
assignable_from_resolved_type
(
src_type
.
real_type
)
or
src_type
.
is_numeric
and
self
.
real_type
.
assignable_from_resolved_type
(
src_type
)
or
src_type
.
is_numeric
and
self
.
real_type
.
assignable_from_resolved_type
(
src_type
)
or
src_type
is
error_type
)
or
src_type
is
error_type
)
def
attributes_known
(
self
):
if
self
.
scope
is
None
:
import
Symtab
self
.
scope
=
Symtab
.
StructOrUnionScope
(
self
.
specalization_name
())
self
.
scope
.
declare_var
(
"real"
,
self
.
real_type
,
None
,
"real"
)
self
.
scope
.
declare_var
(
"imag"
,
self
.
real_type
,
None
,
"imag"
)
return
True
def
create_declaration_utility_code
(
self
,
env
):
def
create_declaration_utility_code
(
self
,
env
):
# This must always be run, because a single CComplexType instance can be shared
# This must always be run, because a single CComplexType instance can be shared
...
...
tests/run/complex_numbers_T305.pyx
View file @
1d19ea12
...
@@ -44,10 +44,22 @@ __doc__ = u"""
...
@@ -44,10 +44,22 @@ __doc__ = u"""
>>> test_literal()
>>> test_literal()
(5j, (1-2.5j))
(5j, (1-2.5j))
>>> test_real_imag(1-3j)
(1.0, -3.0)
>>> test_real_imag(5)
(5.0, 0.0)
>>> test_real_imag(1.5j)
(0.0, 1.5)
>>> test_real_imag_assignment(1, 2)
(1+2j)
>>> test_real_imag_assignment(1.5, -3.5)
(1.5-3.5j)
"""
"""
#
cdef extern from "complex.h":
cdef
extern
from
"complex.h"
:
#
pass
pass
cimport
cython
cimport
cython
...
@@ -81,4 +93,12 @@ def test_compare_coerce(double complex a, int b):
...
@@ -81,4 +93,12 @@ def test_compare_coerce(double complex a, int b):
def
test_literal
():
def
test_literal
():
return
5j
,
1
-
2.5j
return
5j
,
1
-
2.5j
def
test_real_imag
(
double
complex
z
):
return
z
.
real
,
z
.
imag
def
test_real_imag_assignment
(
object
a
,
double
b
):
cdef
double
complex
z
z
.
real
=
a
z
.
imag
=
b
return
z
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment