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
34ab658b
Commit
34ab658b
authored
Jul 07, 2020
by
Clemens
Committed by
Stefan Behnel
Jul 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Always consider 0-sized arrays as C- and F-contiguous (GH-3728)
Fixes
https://github.com/cython/cython/issues/2093
parent
1910ad2b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
9 deletions
+35
-9
Cython/Utility/MemoryView_C.c
Cython/Utility/MemoryView_C.c
+13
-9
tests/memoryview/relaxed_strides.pyx
tests/memoryview/relaxed_strides.pyx
+22
-0
No files found.
Cython/Utility/MemoryView_C.c
View file @
34ab658b
...
...
@@ -347,18 +347,22 @@ static int __Pyx_ValidateAndInit_memviewslice(
}
/* Check axes */
for
(
i
=
0
;
i
<
ndim
;
i
++
)
{
spec
=
axes_specs
[
i
];
if
(
unlikely
(
!
__pyx_check_strides
(
buf
,
i
,
ndim
,
spec
)))
goto
fail
;
if
(
unlikely
(
!
__pyx_check_suboffsets
(
buf
,
i
,
ndim
,
spec
)))
if
(
buf
->
len
>
0
)
{
// 0-sized arrays do not undergo these checks since their strides are
// irrelevant and they are always both C- and F-contiguous.
for
(
i
=
0
;
i
<
ndim
;
i
++
)
{
spec
=
axes_specs
[
i
];
if
(
unlikely
(
!
__pyx_check_strides
(
buf
,
i
,
ndim
,
spec
)))
goto
fail
;
if
(
unlikely
(
!
__pyx_check_suboffsets
(
buf
,
i
,
ndim
,
spec
)))
goto
fail
;
}
/* Check contiguity */
if
(
unlikely
(
buf
->
strides
&&
!
__pyx_verify_contig
(
buf
,
ndim
,
c_or_f_flag
)))
goto
fail
;
}
/* Check contiguity */
if
(
unlikely
(
buf
->
strides
&&
!
__pyx_verify_contig
(
buf
,
ndim
,
c_or_f_flag
)))
goto
fail
;
/* Initialize */
if
(
unlikely
(
__Pyx_init_memviewslice
(
memview
,
ndim
,
memviewslice
,
new_memview
!=
NULL
)
==
-
1
))
{
...
...
tests/memoryview/relaxed_strides.pyx
View file @
34ab658b
...
...
@@ -62,3 +62,25 @@ def test_zero_sized(array):
"""
cdef
double
[::
1
]
a
=
array
return
a
def
test_zero_sized_multidim_ccontig
(
array
):
"""
>>> contig = np.ascontiguousarray(np.zeros((4,4,4))[::2, 2:2, ::2])
>>> _ = test_zero_sized_multidim_ccontig(contig)
>>> a = np.zeros((4,4,4))[::2, 2:2, ::2]
>>> if NUMPY_HAS_RELAXED_STRIDES: _ = test_zero_sized_multidim_ccontig(a)
"""
cdef
double
[:,
:,
::
1
]
a
=
array
return
a
def
test_zero_sized_multidim_fcontig
(
array
):
"""
>>> contig = np.ascontiguousarray(np.zeros((4,4,4))[::2, 2:2, ::2])
>>> _ = test_zero_sized_multidim_fcontig(contig)
>>> a = np.zeros((4,4,4))[::2, 2:2, ::2]
>>> if NUMPY_HAS_RELAXED_STRIDES: _ = test_zero_sized_multidim_fcontig(a)
"""
cdef
double
[::
1
,
:,
:]
a
=
array
return
a
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