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
b297ae99
Commit
b297ae99
authored
Aug 11, 2009
by
Kurt Smith
Committed by
Mark Florisson
Sep 30, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
memoryviewslice .is_c_contig() and .is_f_contig() implementations
parent
088bf12c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
4 deletions
+80
-4
Cython/Compiler/MemoryView.py
Cython/Compiler/MemoryView.py
+53
-0
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+27
-4
No files found.
Cython/Compiler/MemoryView.py
View file @
b297ae99
...
...
@@ -180,6 +180,57 @@ def get_copy_contents_name(from_mvs, to_mvs):
mangle_dtype_name
(
dtype
)))
def
get_is_contig_func_name
(
c_or_f
):
return
"__Pyx_Buffer_is_%s_contiguous"
%
c_or_f
def
get_is_contiguous_func
(
c_or_f
):
func_name
=
get_is_contig_func_name
(
c_or_f
)
decl
=
"static int %s(const __Pyx_memviewslice); /* proto */
\
n
"
%
func_name
impl
=
"""
static int %s(const __Pyx_memviewslice mvs) {
/* returns 1 if mvs is the right contiguity, 0 otherwise */
int i, ndim = mvs.memview->view.ndim;
Py_ssize_t itemsize = mvs.memview->view.itemsize;
unsigned long size = 0;
"""
%
func_name
if
c_or_f
==
'fortran'
:
for_loop
=
"for(i=0; i<ndim; i++)"
elif
c_or_f
==
'c'
:
for_loop
=
"for(i=ndim-1; i>-1; i--)"
else
:
assert
False
impl
+=
"""
size = 1;
%(for_loop)s {
#ifdef DEBUG
printf("mvs.diminfo[i].suboffsets %%d
\
\
n", mvs.diminfo[i].suboffsets);
printf("mvs.diminfo[i].strides %%d
\
\
n", mvs.diminfo[i].strides);
printf("mvs.diminfo[i].shape %%d
\
\
n", mvs.diminfo[i].shape);
printf("size %%d
\
\
n", size);
printf("ndim %%d
\
\
n", ndim);
#endif
#undef DEBUG
if(mvs.diminfo[i].suboffsets >= 0) {
return 0;
}
if(size * itemsize != mvs.diminfo[i].strides) {
return 0;
}
size *= mvs.diminfo[i].shape;
}
return 1;
}"""
%
{
'for_loop'
:
for_loop
}
return
decl
,
impl
copy_template
=
'''
static __Pyx_memviewslice %(copy_name)s(const __Pyx_memviewslice from_mvs) {
...
...
@@ -754,6 +805,8 @@ static int __Pyx_init_memviewslice(
memviewslice->diminfo[i].shape = buf->shape[i];
if(buf->suboffsets) {
memviewslice->diminfo[i].suboffsets = buf->suboffsets[i];
} else {
memviewslice->diminfo[i].suboffsets = -1;
}
}
...
...
Cython/Compiler/PyrexTypes.py
View file @
b297ae99
...
...
@@ -394,15 +394,14 @@ class MemoryViewSliceType(PyrexType):
scope
.
declare_var
(
'_data'
,
c_char_ptr_type
,
None
,
cname
=
'data'
,
is_cdef
=
1
)
mangle_dtype
=
MemoryView
.
mangle_dtype_name
(
self
.
dtype
)
ndim
=
len
(
self
.
axes
)
to_axes_c
=
[(
'direct'
,
'contig'
)]
to_axes_f
=
[(
'direct'
,
'contig'
)]
if
ndim
-
1
:
to_axes_c
=
[(
'direct'
,
'follow'
)
*
(
ndim
-
1
)]
+
to_axes_c
to_axes_f
=
to_axes_f
+
[(
'direct'
,
'follow'
)
*
(
ndim
-
1
)]
to_axes_c
=
[(
'direct'
,
'follow'
)
]
*
(
ndim
-
1
)
+
to_axes_c
to_axes_f
=
to_axes_f
+
[(
'direct'
,
'follow'
)
]
*
(
ndim
-
1
)
to_memview_c
=
MemoryViewSliceType
(
self
.
dtype
,
to_axes_c
,
self
.
env
)
to_memview_f
=
MemoryViewSliceType
(
self
.
dtype
,
to_axes_f
,
self
.
env
)
...
...
@@ -473,7 +472,31 @@ static __Pyx_memviewslice %s(const __Pyx_memviewslice); /* proto */
if
not
f_copy_used
:
self
.
env
.
use_utility_code
(
f_copy_util_code
)
# ensure the right util code is used
# is_c_contiguous and is_f_contiguous functions
for
c_or_f
,
cython_name
in
((
'c'
,
'is_c_contig'
),
(
'fortran'
,
'is_f_contig'
)):
is_contig_name
=
MemoryView
.
get_is_contig_func_name
(
c_or_f
)
scope
.
declare_cfunction
(
cython_name
,
CFuncType
(
c_int_type
,
[
CFuncTypeArg
(
"memviewslice"
,
self
,
None
)]),
pos
=
None
,
defining
=
1
,
cname
=
is_contig_name
)
contig_decl
,
contig_impl
=
MemoryView
.
get_is_contiguous_func
(
c_or_f
)
contig_util_code
=
UtilityCode
(
proto
=
contig_decl
,
impl
=
contig_impl
)
contig_used
=
[
1
for
util_code
in
\
self
.
env
.
global_scope
().
utility_code_list
\
if
contig_decl
==
util_code
.
proto
]
if
not
contig_used
:
self
.
env
.
use_utility_code
(
contig_util_code
)
# use the supporting util code
MemoryView
.
use_cython_array
(
self
.
env
)
MemoryView
.
use_memview_util_code
(
self
.
env
)
...
...
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