Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backport] Fix ravel for strides 0 #5998

Merged
merged 1 commit into from Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion cupy/_core/core.pyx
Expand Up @@ -677,7 +677,8 @@ cdef class ndarray:
:meth:`numpy.ndarray.ravel`

"""
return _manipulation._ndarray_ravel(self, order)
return _internal_ascontiguousarray(
_manipulation._ndarray_ravel(self, order))

cpdef ndarray squeeze(self, axis=None):
"""Returns a view with size-one axes removed.
Expand Down
19 changes: 19 additions & 0 deletions tests/cupy_tests/manipulation_tests/test_shape.py
Expand Up @@ -170,6 +170,25 @@ def test_ravel3(self, xp, order):
a = xp.asfortranarray(a)
return a.ravel(order)

@testing.for_orders('CFA')
@testing.numpy_cupy_array_equal()
def test_ravel_non_contiguous(self, xp, order):
a = xp.arange(10)[::2]
assert not a.flags.c_contiguous and not a.flags.f_contiguous
b = a.ravel(order)
assert b.flags.c_contiguous
return b

@testing.for_orders('CFA')
@testing.numpy_cupy_array_equal()
def test_ravel_broadcasted(self, xp, order):
a = xp.array([1])
b = xp.broadcast_to(a, (10,))
assert not b.flags.c_contiguous and not b.flags.f_contiguous
b = b.ravel(order)
assert b.flags.c_contiguous
return b

@testing.numpy_cupy_array_equal()
def test_external_ravel(self, xp):
a = testing.shaped_arange((2, 3, 4), xp)
Expand Down