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
c430314b
Commit
c430314b
authored
May 30, 2015
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow composite fused types.
parent
49b732d4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
4 deletions
+22
-4
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+0
-2
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+7
-1
tests/errors/fused_types.pyx
tests/errors/fused_types.pyx
+0
-1
tests/run/fused_types.pyx
tests/run/fused_types.pyx
+15
-0
No files found.
Cython/Compiler/Nodes.py
View file @
c430314b
...
@@ -1215,8 +1215,6 @@ class FusedTypeNode(CBaseTypeNode):
...
@@ -1215,8 +1215,6 @@ class FusedTypeNode(CBaseTypeNode):
if
type
in
types
:
if
type
in
types
:
error
(
type_node
.
pos
,
"Type specified multiple times"
)
error
(
type_node
.
pos
,
"Type specified multiple times"
)
elif
type
.
is_fused
:
error
(
type_node
.
pos
,
"Cannot fuse a fused type"
)
else
:
else
:
types
.
append
(
type
)
types
.
append
(
type
)
...
...
Cython/Compiler/PyrexTypes.py
View file @
c430314b
...
@@ -1339,7 +1339,13 @@ class FusedType(CType):
...
@@ -1339,7 +1339,13 @@ class FusedType(CType):
exception_check
=
0
exception_check
=
0
def
__init__
(
self
,
types
,
name
=
None
):
def
__init__
(
self
,
types
,
name
=
None
):
self
.
types
=
types
# Use list rather than set to preserve order.
flattened_types
=
[
t
for
t
in
types
if
not
t
.
is_fused
]
subtypes
=
sum
([
t
.
types
for
t
in
types
if
t
.
is_fused
],
[])
for
type
in
subtypes
:
if
type
not
in
flattened_types
:
flattened_types
.
append
(
type
)
self
.
types
=
flattened_types
self
.
name
=
name
self
.
name
=
name
def
declaration_code
(
self
,
entity_code
,
for_display
=
0
,
def
declaration_code
(
self
,
entity_code
,
for_display
=
0
,
...
...
tests/errors/fused_types.pyx
View file @
c430314b
...
@@ -67,7 +67,6 @@ func(x, y)
...
@@ -67,7 +67,6 @@ func(x, y)
_ERRORS
=
u"""
_ERRORS
=
u"""
10:15: fused_type does not take keyword arguments
10:15: fused_type does not take keyword arguments
15:38: Type specified multiple times
15:38: Type specified multiple times
17:33: Cannot fuse a fused type
26:4: Invalid use of fused types, type cannot be specialized
26:4: Invalid use of fused types, type cannot be specialized
26:4: Not enough types specified to specialize the function, int2_t is still fused
26:4: Not enough types specified to specialize the function, int2_t is still fused
27:4: Invalid use of fused types, type cannot be specialized
27:4: Invalid use of fused types, type cannot be specialized
...
...
tests/run/fused_types.pyx
View file @
c430314b
...
@@ -19,6 +19,7 @@ other_t = cython.fused_type(int, double)
...
@@ -19,6 +19,7 @@ other_t = cython.fused_type(int, double)
ctypedef
double
*
p_double
ctypedef
double
*
p_double
ctypedef
int
*
p_int
ctypedef
int
*
p_int
fused_type3
=
cython
.
fused_type
(
int
,
double
)
fused_type3
=
cython
.
fused_type
(
int
,
double
)
fused_composite
=
cython
.
fused_type
(
fused_type2
,
fused_type3
)
def
test_pure
():
def
test_pure
():
"""
"""
...
@@ -349,3 +350,17 @@ def test_index_fused_args(cython.floating f, ints_t i):
...
@@ -349,3 +350,17 @@ def test_index_fused_args(cython.floating f, ints_t i):
double int
double int
"""
"""
_test_index_fused_args
[
cython
.
floating
,
ints_t
](
f
,
i
)
_test_index_fused_args
[
cython
.
floating
,
ints_t
](
f
,
i
)
def
test_composite
(
fused_composite
x
):
"""
>>> test_composite('a')
'a'
>>> test_composite(3)
6
>>> test_composite(3.0)
6.0
"""
if
fused_composite
is
string_t
:
return
x
else
:
return
2
*
x
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