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
a099ddbe
Commit
a099ddbe
authored
Mar 14, 2012
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use signature string of fused subtype instead of compound type for def functions
parent
480f6687
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
4 deletions
+62
-4
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+5
-2
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+4
-0
tests/run/fused_types.pyx
tests/run/fused_types.pyx
+38
-1
tests/run/numpy_test.pyx
tests/run/numpy_test.pyx
+15
-1
No files found.
Cython/Compiler/Nodes.py
View file @
a099ddbe
...
...
@@ -2296,9 +2296,12 @@ class FusedCFuncDefNode(StatListNode):
Create a copy of the original def or lambda function for specialized
versions.
"""
fused_types
=
PyrexTypes
.
unique
(
fused_
compound_
types
=
PyrexTypes
.
unique
(
[
arg
.
type
for
arg
in
self
.
node
.
args
if
arg
.
type
.
is_fused
])
permutations
=
PyrexTypes
.
get_all_specialized_permutations
(
fused_types
)
permutations
=
PyrexTypes
.
get_all_specialized_permutations
(
fused_compound_types
)
fused_types
=
[
fused_type
for
fused_compound_type
in
fused_compound_types
for
fused_type
in
fused_compound_type
.
get_fused_types
()]
if
self
.
node
.
entry
in
env
.
pyfunc_entries
:
env
.
pyfunc_entries
.
remove
(
self
.
node
.
entry
)
...
...
Cython/Compiler/PyrexTypes.py
View file @
a099ddbe
...
...
@@ -780,6 +780,10 @@ class BufferType(BaseType):
def
__repr__
(
self
):
return
"<BufferType %r>"
%
self
.
base
def
__str__
(
self
):
cast_str
=
', cast=True'
if
self
.
cast
else
''
return
"%s[%s, ndim=%d%s]"
%
(
self
.
base
,
self
.
dtype
,
self
.
ndim
,
cast_str
)
class
PyObjectType
(
PyrexType
):
#
...
...
tests/run/fused_types.pyx
View file @
a099ddbe
# mode: run
cimport
cython
from
cython.view
cimport
array
from
cython
cimport
integral
from
cpython
cimport
Py_INCREF
from
Cython
import
Shadow
as
pure_cython
ctypedef
char
*
string_t
# floating = cython.fused_type(float, double) floating
...
...
@@ -249,3 +249,40 @@ def test_sizeof_fused_type(fused_type1 b):
"""
t
=
sizeof
(
b
),
sizeof
(
fused_type1
),
sizeof
(
double
)
assert
t
[
0
]
==
t
[
1
]
==
t
[
2
],
t
def
get_array
(
itemsize
,
format
):
result
=
array
((
10
,),
itemsize
,
format
)
result
[
5
]
=
5.0
result
[
6
]
=
6.0
return
result
def
test_fused_memslice_dtype
(
cython
.
floating
[:]
array
):
"""
Note: the np.ndarray dtype test is in numpy_test
>>> import cython
>>> sorted(test_fused_memslice_dtype.__signatures__)
['double', 'float']
>>> test_fused_memslice_dtype[cython.double](get_array(8, 'd'))
double[:] double[:] 5.0 6.0
>>> test_fused_memslice_dtype[cython.float](get_array(4, 'f'))
float[:] float[:] 5.0 6.0
"""
cdef
cython
.
floating
[:]
otherarray
=
array
[
0
:
100
:
1
]
print
cython
.
typeof
(
array
),
cython
.
typeof
(
otherarray
),
\
array
[
5
],
otherarray
[
6
]
# FIXME: broken
#from libcpp.vector cimport vector
#def test_cpp_specialization(cython.floating element):
# """
# >>> import cython
# >>> test_cpp_specialization[cython.float](10.0)
# vector<float> * float 10.0
# >>> test_cpp_specialization[cython.double](10.0)
# vector<double> * double 10.0
# """
# cdef vector[cython.floating] *v = new vector[cython.floating]()
# v.push_back(element)
# print cython.typeof(v), cython.typeof(element), v.at(0)
tests/run/numpy_test.pyx
View file @
a099ddbe
...
...
@@ -2,6 +2,7 @@
# cannot be named "numpy" in order to not clash with the numpy module!
cimport
numpy
as
np
cimport
cython
def
little_endian
():
cdef
int
endian_detector
=
1
...
...
@@ -35,7 +36,7 @@ try:
[[ 16. 17. 18. 19.]
[ 20. 21. 22. 23.]]]
6.0 0.0 13.0 8.0
>>> obj_array()
[a 1 {}]
a 1 {}
...
...
@@ -502,4 +503,17 @@ def test_point_record():
test
[
i
].
y
=
-
i
print
repr
(
test
).
replace
(
'<'
,
'!'
).
replace
(
'>'
,
'!'
)
def
test_fused_ndarray_dtype
(
np
.
ndarray
[
cython
.
floating
,
ndim
=
1
]
a
):
"""
>>> import cython
>>> sorted(test_fused_ndarray_dtype.__signatures__)
['double', 'float']
>>> test_fused_ndarray_dtype[cython.double](np.arange(10, dtype=np.float64))
ndarray[double, ndim=1] ndarray[double, ndim=1] 5.0 6.0
>>> test_fused_ndarray_dtype[cython.float](np.arange(10, dtype=np.float32))
ndarray[float, ndim=1] ndarray[float, ndim=1] 5.0 6.0
"""
cdef
np
.
ndarray
[
cython
.
floating
,
ndim
=
1
]
b
=
a
print
cython
.
typeof
(
a
),
cython
.
typeof
(
b
),
a
[
5
],
b
[
6
]
include
"numpy_common.pxi"
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