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
Gwenaël Samain
cython
Commits
ba7df0bd
Commit
ba7df0bd
authored
May 26, 2012
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'main/master'
parents
383f4776
28eebe43
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
14 deletions
+53
-14
Cython/Compiler/FusedNode.py
Cython/Compiler/FusedNode.py
+11
-0
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+5
-0
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+1
-1
tests/errors/fused_types.pyx
tests/errors/fused_types.pyx
+26
-13
tests/run/fused_types.pyx
tests/run/fused_types.pyx
+10
-0
No files found.
Cython/Compiler/FusedNode.py
View file @
ba7df0bd
...
...
@@ -32,6 +32,8 @@ class FusedCFuncDefNode(StatListNode):
specializations
code_object CodeObjectNode shared by all specializations and the
fused function
fused_compound_types All fused (compound) types (e.g. floating[:])
"""
__signatures__
=
None
...
...
@@ -76,6 +78,8 @@ class FusedCFuncDefNode(StatListNode):
[
arg
.
type
for
arg
in
self
.
node
.
args
if
arg
.
type
.
is_fused
])
permutations
=
PyrexTypes
.
get_all_specialized_permutations
(
fused_compound_types
)
self
.
fused_compound_types
=
fused_compound_types
if
self
.
node
.
entry
in
env
.
pyfunc_entries
:
env
.
pyfunc_entries
.
remove
(
self
.
node
.
entry
)
...
...
@@ -121,6 +125,7 @@ class FusedCFuncDefNode(StatListNode):
env
.
pyfunc_entries
.
remove
(
orig_py_func
.
entry
)
fused_types
=
self
.
node
.
type
.
get_fused_types
()
self
.
fused_compound_types
=
fused_types
for
cname
,
fused_to_specific
in
permutations
:
copied_node
=
copy
.
deepcopy
(
self
.
node
)
...
...
@@ -656,6 +661,12 @@ class FusedCFuncDefNode(StatListNode):
Analyse the expressions. Take care to only evaluate default arguments
once and clone the result for all specializations
"""
for
fused_compound_type
in
self
.
fused_compound_types
:
for
fused_type
in
fused_compound_type
.
get_fused_types
():
for
specialization_type
in
fused_type
.
types
:
if
specialization_type
.
is_complex
:
specialization_type
.
create_declaration_utility_code
(
env
)
if
self
.
py_func
:
self
.
__signatures__
.
analyse_expressions
(
env
)
self
.
py_func
.
analyse_expressions
(
env
)
...
...
Cython/Compiler/Nodes.py
View file @
ba7df0bd
...
...
@@ -1074,6 +1074,11 @@ class CVarDefNode(StatNode):
self
.
dest_scope
=
dest_scope
base_type
=
self
.
base_type
.
analyse
(
env
)
if
base_type
.
is_fused
and
not
self
.
in_pxd
and
(
env
.
is_c_class_scope
or
env
.
is_module_scope
):
error
(
self
.
pos
,
"Fused types not allowed here"
)
return
error_type
self
.
entry
=
None
visibility
=
self
.
visibility
...
...
Cython/Compiler/Parsing.py
View file @
ba7df0bd
...
...
@@ -2734,7 +2734,7 @@ def p_c_func_or_var_declaration(s, pos, ctx):
visibility
=
ctx
.
visibility
,
base_type
=
base_type
,
declarators
=
declarators
,
in_pxd
=
ctx
.
level
==
'module_pxd'
,
in_pxd
=
ctx
.
level
in
(
'module_pxd'
,
'c_class_pxd'
)
,
api
=
ctx
.
api
,
overridable
=
ctx
.
overridable
)
return
result
...
...
tests/errors/fused_types.pyx
View file @
ba7df0bd
...
...
@@ -38,6 +38,16 @@ def f(memslice_dtype_t[:, :] a):
lambda
cython
.
integral
i
:
i
cdef
cython
.
floating
x
cdef
class
Foo
(
object
):
cdef
cython
.
floating
attr
def
outer
(
cython
.
floating
f
):
def
inner
():
cdef
cython
.
floating
g
# This is all valid
dtype5
=
fused_type
(
int
,
long
,
float
)
dtype6
=
cython
.
fused_type
(
int
,
long
)
...
...
@@ -53,18 +63,21 @@ ctypedef fused fused2:
func
(
x
,
y
)
_ERRORS
=
u"""
fused_types.pyx:10:15: fused_type does not take keyword arguments
fused_types.pyx:15:38: Type specified multiple times
fused_types.pyx:17:33: Cannot fuse a fused type
fused_types.pyx:26:4: Invalid use of fused types, type cannot be specialized
fused_types.pyx:26:4: Not enough types specified to specialize the function, int2_t is still fused
fused_types.pyx:27:4: Invalid use of fused types, type cannot be specialized
fused_types.pyx:27:4: Not enough types specified to specialize the function, int2_t is still fused
fused_types.pyx:28:16: Call with wrong number of arguments (expected 2, got 1)
fused_types.pyx:29:16: Call with wrong number of arguments (expected 2, got 3)
fused_types.pyx:30:4: Invalid use of fused types, type cannot be specialized
fused_types.pyx:30:4: Keyword and starred arguments not allowed in cdef functions.
fused_types.pyx:36:6: Invalid base type for memoryview slice: int *
fused_types.pyx:39:0: Fused lambdas not allowed
10:15: fused_type does not take keyword arguments
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: 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: Not enough types specified to specialize the function, int2_t is still fused
28:16: Call with wrong number of arguments (expected 2, got 1)
29:16: Call with wrong number of arguments (expected 2, got 3)
30:4: Invalid use of fused types, type cannot be specialized
30:4: Keyword and starred arguments not allowed in cdef functions.
36:6: Invalid base type for memoryview slice: int *
39:0: Fused lambdas not allowed
42:5: Fused types not allowed here
45:9: Fused types not allowed here
"""
tests/run/fused_types.pyx
View file @
ba7df0bd
...
...
@@ -272,3 +272,13 @@ def test_fused_memslice_dtype(cython.floating[:] array):
cdef
cython
.
floating
[:]
otherarray
=
array
[
0
:
100
:
1
]
print
cython
.
typeof
(
array
),
cython
.
typeof
(
otherarray
),
\
array
[
5
],
otherarray
[
6
]
def
test_cython_numeric
(
cython
.
numeric
arg
):
"""
Test to see whether complex numbers have their utility code declared
properly.
>>> test_cython_numeric(10.0 + 1j)
double complex (10+1j)
"""
print
cython
.
typeof
(
arg
),
arg
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