Skip to content

Commit

Permalink
Merge pull request #5998 from chainer-ci/bp-5978-v9-fix-ravel
Browse files Browse the repository at this point in the history
[backport] Fix `ravel` for strides 0
  • Loading branch information
emcastillo committed Nov 8, 2021
2 parents e41a707 + 5d37283 commit f2d2622
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
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

0 comments on commit f2d2622

Please sign in to comment.