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
Kirill Smelkov
cython
Commits
6b1193e9
Commit
6b1193e9
authored
Jun 16, 2017
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reduce call overhead of functions with fused types (especially when using numpy arrays)
parent
9db5c060
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
9 deletions
+45
-9
Cython/Compiler/FusedNode.py
Cython/Compiler/FusedNode.py
+9
-9
Cython/Utility/ImportExport.c
Cython/Utility/ImportExport.c
+36
-0
No files found.
Cython/Compiler/FusedNode.py
View file @
6b1193e9
...
@@ -453,11 +453,7 @@ class FusedCFuncDefNode(StatListNode):
...
@@ -453,11 +453,7 @@ class FusedCFuncDefNode(StatListNode):
pyx_code
.
imports
.
put_chunk
(
pyx_code
.
imports
.
put_chunk
(
u"""
u"""
cdef type ndarray
cdef type ndarray
try:
ndarray = __Pyx_ImportNumPyArrayTypeIfAvailable()
import numpy
ndarray = numpy.ndarray
except (ImportError, AttributeError, TypeError):
ndarray = None
"""
)
"""
)
seen_int_dtypes
=
set
()
seen_int_dtypes
=
set
()
...
@@ -514,7 +510,7 @@ class FusedCFuncDefNode(StatListNode):
...
@@ -514,7 +510,7 @@ class FusedCFuncDefNode(StatListNode):
# PROCESSING ARGUMENT {{arg_tuple_idx}}
# PROCESSING ARGUMENT {{arg_tuple_idx}}
if {{arg_tuple_idx}} < len(<tuple>args):
if {{arg_tuple_idx}} < len(<tuple>args):
arg = (<tuple>args)[{{arg_tuple_idx}}]
arg = (<tuple>args)[{{arg_tuple_idx}}]
elif '{{arg.name}}' in <dict>kwargs:
elif
kwargs is not None and
'{{arg.name}}' in <dict>kwargs:
arg = (<dict>kwargs)['{{arg.name}}']
arg = (<dict>kwargs)['{{arg.name}}']
else:
else:
{{if arg.default}}
{{if arg.default}}
...
@@ -549,6 +545,7 @@ class FusedCFuncDefNode(StatListNode):
...
@@ -549,6 +545,7 @@ class FusedCFuncDefNode(StatListNode):
u"""
u"""
cdef extern from *:
cdef extern from *:
void __pyx_PyErr_Clear "PyErr_Clear" ()
void __pyx_PyErr_Clear "PyErr_Clear" ()
type __Pyx_ImportNumPyArrayTypeIfAvailable()
"""
)
"""
)
decl_code
.
indent
()
decl_code
.
indent
()
...
@@ -564,8 +561,8 @@ class FusedCFuncDefNode(StatListNode):
...
@@ -564,8 +561,8 @@ class FusedCFuncDefNode(StatListNode):
dest_sig = [None] * {{n_fused}}
dest_sig = [None] * {{n_fused}}
if kwargs is
None
:
if kwargs is
not None and not kwargs
:
kwargs =
{}
kwargs =
None
cdef Py_ssize_t i
cdef Py_ssize_t i
...
@@ -623,13 +620,16 @@ class FusedCFuncDefNode(StatListNode):
...
@@ -623,13 +620,16 @@ class FusedCFuncDefNode(StatListNode):
if
all_buffer_types
:
if
all_buffer_types
:
self
.
_buffer_declarations
(
pyx_code
,
decl_code
,
all_buffer_types
)
self
.
_buffer_declarations
(
pyx_code
,
decl_code
,
all_buffer_types
)
env
.
use_utility_code
(
Code
.
UtilityCode
.
load_cached
(
"Import"
,
"ImportExport.c"
))
env
.
use_utility_code
(
Code
.
UtilityCode
.
load_cached
(
"Import"
,
"ImportExport.c"
))
env
.
use_utility_code
(
Code
.
UtilityCode
.
load_cached
(
"ImportNumPyArray"
,
"ImportExport.c"
))
pyx_code
.
put_chunk
(
pyx_code
.
put_chunk
(
u"""
u"""
candidates = []
candidates = []
for sig in <dict>signatures:
for sig in <dict>signatures:
match_found = False
match_found = False
for src_type, dst_type in zip(sig.strip('()').split('|'), dest_sig):
src_sig = sig.strip('()').split('|')
for i in range(len(dest_sig)):
src_type, dst_type = src_sig[i], dest_sig[i]
if dst_type is not None:
if dst_type is not None:
if src_type == dst_type:
if src_type == dst_type:
match_found = True
match_found = True
...
...
Cython/Utility/ImportExport.c
View file @
6b1193e9
...
@@ -661,3 +661,39 @@ bad:
...
@@ -661,3 +661,39 @@ bad:
Py_XDECREF
(
ob
);
Py_XDECREF
(
ob
);
return
NULL
;
return
NULL
;
}
}
/////////////// ImportNumPyArray.proto ///////////////
static
PyObject
*
__Pyx_ImportNumPyArrayTypeIfAvailable
(
void
);
/*proto*/
/////////////// ImportNumPyArray.cleanup ///////////////
Py_CLEAR
(
__pyx_numpy_ndarray
);
/////////////// ImportNumPyArray ///////////////
//@requires: ImportExport.c::Import
static
PyObject
*
__pyx_numpy_ndarray
=
NULL
;
static
PyObject
*
__Pyx__ImportNumPyArray
(
void
)
{
PyObject
*
numpy_module
,
*
ndarray_object
=
NULL
;
numpy_module
=
__Pyx_Import
(
PYIDENT
(
"numpy"
),
NULL
,
0
);
if
(
likely
(
numpy_module
))
{
ndarray_object
=
PyObject_GetAttrString
(
numpy_module
,
"ndarray"
);
if
(
unlikely
(
!
ndarray_object
))
{
PyErr_Clear
();
}
}
if
(
unlikely
(
!
ndarray_object
||
!
PyObject_TypeCheck
(
ndarray_object
,
&
PyType_Type
)))
{
Py_XDECREF
(
ndarray_object
);
Py_INCREF
(
Py_None
);
ndarray_object
=
Py_None
;
}
return
ndarray_object
;
}
static
CYTHON_INLINE
PyObject
*
__Pyx_ImportNumPyArrayTypeIfAvailable
(
void
)
{
if
(
unlikely
(
!
__pyx_numpy_ndarray
))
{
__pyx_numpy_ndarray
=
__Pyx__ImportNumPyArray
();
}
return
__pyx_numpy_ndarray
;
}
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