diff --git a/pyopencl/array.py b/pyopencl/array.py index 402426a8241029f824df7d3aea50ebdee58da080..3a1f10905b1c825093e6a2acc3db1fe58da1e694 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -1759,9 +1759,9 @@ class Array: data=self.base_data, offset=self.offset, shape=shape, strides=tuple(newstrides)) - def ravel(self): + def ravel(self, order="C"): """Returns flattened array containing the same data.""" - return self.reshape(self.size) + return self.reshape(self.size, order=order) def view(self, dtype=None): """Returns view of array with the same data. If *dtype* is different diff --git a/test/test_array.py b/test/test_array.py index f03640f636eaa02f49f9ebb8e6daeecbc93ed644..9ff806e3a68dbe96d88a7f1e5a296a7647d614af 100644 --- a/test/test_array.py +++ b/test/test_array.py @@ -1583,6 +1583,26 @@ def test_slice_copy(ctx_factory): y.copy() +@pytest.mark.parametrize("order", ("C", "F")) +def test_ravel(ctx_factory, order): + ctx = ctx_factory() + cq = cl.CommandQueue(ctx) + + x = np.random.randn(10, 4) + + if order == "F": + x = np.asfortranarray(x) + elif order == "C": + pass + else: + raise AssertionError + + x_cl = cl.array.to_device(cq, x) + + np.testing.assert_allclose(x_cl.ravel(order=order).get(), + x.ravel(order=order)) + + if __name__ == "__main__": if len(sys.argv) > 1: exec(sys.argv[1])